|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.cvsclient.commands.update; import org.netbeans.lib.cvsclient.command.FileInfoContainer; import javax.swing.table.TableColumn; import javax.swing.table.JTableHeader; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellRenderer; import org.openide.util.NbBundle; import org.netbeans.lib.cvsclient.command.DefaultFileInfoContainer; import org.netbeans.lib.cvsclient.event.MessageEvent; import org.netbeans.lib.cvsclient.event.EnhancedMessageEvent; import org.openide.DialogDescriptor; import org.netbeans.modules.cvsclient.commands.*; import org.netbeans.modules.javacvs.commands.ClientProvider; import javax.accessibility.*; //import org.netbeans.modules.vcscore.util.FileEditorSupport; import java.util.ResourceBundle; import java.awt.Dialog; import java.lang.reflect.Method; import org.netbeans.modules.vcscore.util.table.*; import org.netbeans.modules.javacvs.commands.FileSystemCommand; public class UpdateInfoPanel extends DefaultInfoPanel { private static final int MAX_SCROLLBAR_GAP = 50; GrowingTableInfoModel model; FileSystemCommand command; long currentTimeStamp; long firedTimeStamp = 0; int addedCount = 0; int totalCount = 0; int lastSelection = -1; int lastHBar = 0; private String labelString; private boolean wasSending; // private JButton btnStop = null; private java.io.File sendingDir = null; private org.netbeans.lib.cvsclient.command.Command currentCom; private ActionListener stopActionListener; /** Creates new form UpdateInfoPanel */ public UpdateInfoPanel(FileSystemCommand comm) { super(); initComponents(); initAccessibility(); btnStop.setText(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.stopButton")); // NOI18N btnStop.setMnemonic(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.stopButton.mnemonic").charAt(0)); //NOI18N btnViewLog.setText(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.logButton")); // NOI18N btnViewLog.setMnemonic(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.logButton.mnemonic").charAt(0)); // NOI18N btnStop.setDefaultCapable(true); command = comm; setPreferredSize(new java.awt.Dimension(450, 200)); setMinimumSize(new java.awt.Dimension(450, 200)); labelString = NbBundle.getBundle(UpdateInfoPanel.class). getString("UpdateInfoPanel.lblSending.text"); // NOI18N // setting the model.... model = new GrowingTableInfoModel(); Class classa = DefaultFileInfoContainer.class; String column1 = NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateTableInfoModel.type"); // NOI18N String column2 = NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateTableInfoModel.fileName"); // NOI18N String column3 = NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateTableInfoModel.path"); // NOI18N try { Method method1 = classa.getMethod("getType", null); // NOI18N Method method2 = classa.getMethod("getFile", null); // NOI18N model.setColumnDefinition(0, column1, method1, true, new TypeComparator()); ClientProvider prov = comm.getClientProvider(); model.setColumnDefinition(1, column2, method2, true, new FileComparator()); model.setColumnDefinition(2, column3, method2, true, new PathComparator(prov.getLocalPath())); } catch (NoSuchMethodException exc) { Thread.dumpStack(); } catch (SecurityException exc2) { Thread.dumpStack(); } TableCellRenderer renderer = new ColoringUpdateRenderer(model); tblUpdates.setDefaultRenderer(tblUpdates.getColumnClass(0), renderer); tblUpdates.setDefaultRenderer(tblUpdates.getColumnClass(1), renderer); tblUpdates.setDefaultRenderer(tblUpdates.getColumnClass(2), renderer); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents() {//GEN-BEGIN:initComponents java.awt.GridBagConstraints gridBagConstraints; lblSending = new javax.swing.JLabel(); spCentral = new javax.swing.JScrollPane(); tblUpdates = new javax.swing.JTable(); pnlButtons = new javax.swing.JPanel(); btnViewLog = new javax.swing.JButton(); btnStop = new javax.swing.JButton(); setLayout(new java.awt.GridBagLayout()); lblSending.setText(" "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(12, 12, 2, 11); add(lblSending, gridBagConstraints); spCentral.setPreferredSize(new java.awt.Dimension(250, 60)); tblUpdates.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); spCentral.setViewportView(tblUpdates); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 11); add(spCentral, gridBagConstraints); pnlButtons.setLayout(new java.awt.GridBagLayout()); btnViewLog.setText(org.openide.util.NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.logButton")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.weightx = 0.5; gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0); pnlButtons.add(btnViewLog, gridBagConstraints); btnStop.setText(org.openide.util.NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.stopButton")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0); pnlButtons.add(btnStop, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new java.awt.Insets(17, 12, 11, 11); add(pnlButtons, gridBagConstraints); }//GEN-END:initComponents private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed }//GEN-LAST:event_btnEditActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnViewLog; private javax.swing.JTable tblUpdates; private javax.swing.JScrollPane spCentral; private javax.swing.JButton btnStop; private javax.swing.JLabel lblSending; private javax.swing.JPanel pnlButtons; // End of variables declaration//GEN-END:variables private static final ResourceBundle bundle = NbBundle.getBundle(UpdateInfoPanel.class); // NOI18N private void initAccessibility() { AccessibleContext context = this.getAccessibleContext(); context.setAccessibleName(bundle.getString("ACSD_UpdateInfoPanel")); context = btnViewLog.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_UpdateInfoPanel.btnViewLog")); context = btnStop.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_UpdateInfoPanel.btnStop")); context = tblUpdates.getAccessibleContext(); context.setAccessibleName(bundle.getString("ACSN_UpdateInfoPanel.tblUpdates")); context.setAccessibleDescription(bundle.getString("ACSD_UpdateInfoPanel.tblUpdates")); } /** this method should be used with Choosers to display the dialog.. * then later the displayOutputData will just present the datat gotten from server * Reason: to have something displayer right away.. * This method is to be called when creating the command and Chooser. */ public void displayFrameWork() { tblUpdates.setModel(model); TableColumn col = tblUpdates.getColumnModel().getColumn(0); col.setMaxWidth(40); // HACK to set the width of column at desired size // String title = NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.dialogTitle") + " " + command.getName(); // setName(title); setName(command.getName()); stopActionListener = new StopActionListener(); btnStop.addActionListener(stopActionListener); btnViewLog.setEnabled(false); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { open(); } }); /* dd = new DialogDescriptor(this, title); Object[] options = new Object[1]; btnStop = new JButton(); btnStop.setText(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.stopButton")); options[0] = btnStop; dd.setOptions(options); Object[] empty = new Object[1]; dd.setClosingOptions(empty); // none are closing dd.setButtonListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { shutDownCommand(); } }); javax.swing.SwingUtilities.invokeLater(new Runnable () { public void run () { Dialog dial = TopManager.getDefault().createDialog(dd); dial.setModal(false); dial.show(); } }); */ } protected void shutDownCommand() { // we can do that because it's running from other thread then command and won't kill itself if (btnStop != null) { btnStop.setText(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.stopping")); // NOI18N btnStop.setEnabled(false); } command.hardCommandStop(); // displayOutputData(); } /** Does the actual display - docking into the javacvs Mode, * displaying as single Dialog.. whatever. */ public void displayOutputData() { // forces the NbPresenter to keep the user's resizing. /* if (!isOpened()) { return; } */ btnStop.setText(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.closeButton")); // NOI18N btnStop.setMnemonic(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.closeButton.mnemonic").charAt(0)); //NOI18N AccessibleContext context = btnStop.getAccessibleContext(); context.setAccessibleName(NbBundle.getBundle(UpdateInfoPanel.class).getString("ACSD_UpdateInfoPanel.btnClose")); btnStop.setEnabled(true); btnStop.removeActionListener(stopActionListener); btnStop.addActionListener(new CloseActionListener()); btnViewLog.addActionListener(new ViewLogActionListener(btnViewLog)); btnViewLog.setEnabled(true); /* Object[] options = new Object[2]; JButton btnClose = new JButton(); btnClose.setText(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.closeButton")); btnClose.setDefaultCapable(true); options[1] = btnClose; dd.setValue(btnClose); final String log = NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.logButton"); options[0] = log; Object[] closing = new Object[1]; closing[0] = options[1]; dd.setOptions(options); dd.setClosingOptions(closing); // all are closing dd.setButtonListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (evt.getActionCommand().equals(log)) { doShowCommandLog(); } } }); */ JTableHeader head = tblUpdates.getTableHeader(); head.setUpdateTableInRealTime(true); ColumnSortListener listen = new ColumnSortListener(tblUpdates); head.addMouseListener(listen); } public void showExecutionFailed(Exception exception) { if (wasSending) { lblSending.setText(" "); // NOI18N wasSending = false; } // if (isOpened()) { displayOutputData(); // } } public void showFinishedCommand() { if (wasSending) { lblSending.setText(" "); // NOI18N wasSending = false; } displayOutputData(); } public void showStartCommand() { displayFrameWork(); } public void showFileInfoGenerated(FileInfoContainer info) { if (wasSending) { lblSending.setText(" "); // NOI18N wasSending = false; } if (info instanceof DefaultFileInfoContainer) { model.addElement(info); currentTimeStamp = System.currentTimeMillis(); addedCount = addedCount + 1; totalCount = totalCount + 1; long tpDiff = currentTimeStamp - firedTimeStamp; if (totalCount < 100 || (addedCount > 5 && tpDiff > 500)) { /* javax.swing.JScrollBar hBar = this.spCentral.getVerticalScrollBar(); if (lastHBar != 0 && lastSelection != -1) { // for other then default values, do.. if (hBar != null) { if (hBar.getValueIsAdjusting()) { System.out.println("adjusting"); return; } int gap = Math.abs(hBar.getValue() + hBar.getVisibleAmount() - hBar.getMaximum()); System.out.println("gap=" + gap); boolean differentSelection = tblUpdates.getSelectedRow() != lastSelection; if (gap > MAX_SCROLLBAR_GAP && differentSelection) { System.out.println("EEEEEE- skipping.."); return; } else { lastSelection = tblUpdates.getSelectedRow(); System.out.println("trying to recover.."); } } } */ javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { // if (lastSelection == -1 || tblUpdates.getSelectedRow() == lastSelection) { tblUpdates.changeSelection(model.getRowCount(), 0, false, false); // } // lastSelection = tblUpdates.getSelectedRow(); // lastHBar = spCentral.getVerticalScrollBar().getValue(); } }); firedTimeStamp = System.currentTimeMillis(); addedCount = 0; } } } /** * When the server generates a line of output/error, the displayer is notified. * @param message - the string to be displayed, be it error/message (E/M response) */ public void messageGenerated(MessageEvent message) { super.messageGenerated(message); if (message instanceof EnhancedMessageEvent) { EnhancedMessageEvent ev = (EnhancedMessageEvent)message; if (ev.getKey().equals(ev.FILE_SENDING)) { java.io.File file = (java.io.File)ev.getValue(); if (sendingDir == null || (!sendingDir.equals(file.getParentFile()))) { sendingDir = file.getParentFile(); String lbl = sendingDir.getAbsolutePath().substring(currentCom.getLocalDirectory().length()); lblSending.setText(java.text.MessageFormat.format(labelString, new Object[] {lbl})); lblSending.setDisplayedMnemonic(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.lblSending.mnemonic").charAt(0)); //NOI18N lblSending.setLabelFor(tblUpdates); } wasSending = true; } if (ev.getKey().equals(ev.REQUESTS_SENT)) { lblSending.setText(NbBundle.getBundle(UpdateInfoPanel.class).getString("UpdateInfoPanel.All_Requests_Sent")); // NOI18N wasSending = true; } } } /** * this method is called before any of the library's commands * that is stored in the queue in FileSystemCommand, is run. * @param currentCommand shows the command that will be executed. */ public void showBeforeEachExecute(org.netbeans.lib.cvsclient.command.Command currentCommand) { super.showBeforeEachExecute(currentCommand); currentCom = currentCommand; } private class ColoringUpdateRenderer extends DefaultTableCellRenderer { private TableInfoModel tableModel; public ColoringUpdateRenderer(TableInfoModel mod) { super(); tableModel = mod; } public java.awt.Component getTableCellRendererComponent(javax.swing.JTable jTable, java.lang.Object obj, boolean isSelected, boolean hasFocus, int row, int column) { java.awt.Component retValue; retValue = super.getTableCellRendererComponent(jTable, obj, isSelected, hasFocus, row, column); if ((isSelected) != true) { DefaultFileInfoContainer info = (DefaultFileInfoContainer)tableModel.getElementAt(row); String type = info.getType(); if (type.equals("C")) { // NOI18N retValue.setForeground(java.awt.Color.red); } else if (type.equals("A") || type.equals("R") || // NOI18N type.equals("M") || type.equals("G")) { // NOI18N retValue.setForeground(java.awt.Color.blue); } else { retValue.setForeground(java.awt.Color.black); } } return retValue; } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.