|
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; import javax.swing.text.*; import javax.swing.*; import java.awt.Dialog; import org.openide.DialogDescriptor; import org.openide.util.NbBundle; import org.netbeans.modules.vcscore.util.Debug; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import org.netbeans.lib.cvsclient.connection.AuthenticationException; import org.openide.*; import org.netbeans.modules.javacvs.commands.FileSystemCommand; import org.netbeans.lib.cvsclient.command.CommandException; import org.netbeans.lib.cvsclient.command.CommandAbortedException; import javax.accessibility.*; import java.util.ResourceBundle; import org.openide.DialogDisplayer; import org.openide.awt.StatusDisplayer; /** * * @author mkleint * @version */ public class ErrorLogPanel extends DefaultInfoPanel implements ActionListener { private Debug E=new Debug("ErrorLogPanel", false); // NOI18N private Debug D=E; private boolean expanded; private StyledDocument logListing; private StringBuffer buff; private String commandLineForm; private DialogDescriptor dd; private boolean noLogAvailable; private java.awt.Dimension bigDim; private java.awt.Dimension smallDim; private FileSystemCommand command; private String commandDisplayName; private boolean noDialogs; private Dialog dialog; /** Creates new form ErrorLogPanel */ public ErrorLogPanel(FileSystemCommand comm) { // initComponents (); dd = null; command = comm; commandDisplayName = null; noDialogs = false; } public ErrorLogPanel(FileSystemCommand comm, boolean showErrorDialogs) { this(comm); noDialogs = showErrorDialogs; } public void setCommandDisplayName(String name) { commandDisplayName = name; } /** 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; spLogList = new javax.swing.JScrollPane(); tpLogList = new javax.swing.JTextPane(); pnlMessage = new javax.swing.JPanel(); lblMessage = new javax.swing.JLabel(); lblCommand = new javax.swing.JLabel(); setLayout(new java.awt.GridBagLayout()); spLogList.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); spLogList.setPreferredSize(new java.awt.Dimension(150, 100)); tpLogList.setPreferredSize(new java.awt.Dimension(6, 6)); spLogList.setViewportView(tpLogList); 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, 11, 11); add(spLogList, gridBagConstraints); pnlMessage.setLayout(new java.awt.GridBagLayout()); lblMessage.setLabelFor(lblCommand); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0); pnlMessage.add(lblMessage, gridBagConstraints); lblCommand.setLabelFor(tpLogList); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; pnlMessage.add(lblCommand, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new java.awt.Insets(12, 12, 5, 11); add(pnlMessage, gridBagConstraints); }//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextPane tpLogList; private javax.swing.JLabel lblCommand; private javax.swing.JScrollPane spLogList; private javax.swing.JPanel pnlMessage; private javax.swing.JLabel lblMessage; // End of variables declaration//GEN-END:variables private void initAccessibility() { ResourceBundle bundle = NbBundle.getBundle(ErrorLogPanel.class); AccessibleContext context = this.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_ErrorLogPanel")); } public boolean showLog() { if (expanded) { expanded = false; bigDim = dialog.getSize(); spLogList.setVisible(false); dialog.setSize(smallDim); dialog.validate(); dialog.repaint(); return false; } else { if (logListing == null) { loadDocument(); } expanded = true; smallDim = dialog.getSize(); spLogList.setVisible(true); dialog.setSize(bigDim); dialog.validate(); dialog.repaint(); return true; } } private void loadDocument() { if (buff == null) return; logListing = new DefaultStyledDocument(); AttributeSet defaultAttrSet = new SimpleAttributeSet(); try { logListing.insertString(0, buff.toString(), defaultAttrSet); tpLogList.setDocument(logListing); spLogList.getVerticalScrollBar().setValue(spLogList.getVerticalScrollBar().getMaximum()); } catch (BadLocationException exc) { //TODO catch what to do?? E.err("error while loading logs"); // NOI18N } } public void setDialogDescriptor(DialogDescriptor dialogDesc) { dd = dialogDesc; } public void actionPerformed(ActionEvent evt) { if (dd == null) return; //sanity check - dialog descriptor needs to be set after creating the dialog descriptor - in FileSystemCommand Object button = evt.getSource(); if (button.equals(btnClose)) { // NOI18N return; } boolean showing = showLog(); initDialogButtons(dd, showing); } private JButton btnClose; private JButton btnLog; public void initDialogButtons(DialogDescriptor dd, boolean showing) { int size = 1; Object[] options = new Object[size]; btnClose = new JButton(NbBundle.getBundle(ErrorLogPanel.class).getString("ErrorLogPanel.closeButton")); // NOI18N btnClose.setMnemonic (NbBundle.getBundle(ErrorLogPanel.class).getString("ErrorLogPanel.closeButton.mnemonic").charAt (0)); // NOI18N options[0] = btnClose; // NOI18N dd.setValue(btnClose); dd.setOptions(options); dd.setClosingOptions(options); // all are closing if (!noLogAvailable) { if (showing) { btnLog = new JButton(NbBundle.getBundle(ErrorLogPanel.class).getString("ErrorLogPanel.hideButton")); // NOI18N btnLog.setMnemonic (NbBundle.getBundle(ErrorLogPanel.class).getString("ErrorLogPanel.hideButton.mnemonic").charAt (0)); // NOI18N } else { btnLog = new JButton(NbBundle.getBundle(ErrorLogPanel.class).getString("ErrorLogPanel.logButton")); // NOI18N btnLog.setMnemonic (NbBundle.getBundle(ErrorLogPanel.class).getString("ErrorLogPanel.logButton.mnemonic").charAt (0)); // NOI18N } dd.setAdditionalOptions(new Object[] {btnLog}); } } /** * this method is called after library's commands execution */ public void showAfterEachExecute() { super.showAfterEachExecute(); } /** * This is the last method to be called in the displayer. * Is called when the execution finishes. Any filan touchups can be made here. */ public void showFinishedCommand() { super.showFinishedCommand(); if (commandDisplayName != null) { String status = NbBundle.getMessage(ErrorLogPanel.class, "FileSystemCommand.finish", commandDisplayName); // NOI18N StatusDisplayer.getDefault().setStatusText(status); } else { String status = NbBundle.getMessage(ErrorLogPanel.class, "FileSystemCommand.finish", command.getName()); // NOI18N StatusDisplayer.getDefault().setStatusText(status); } } /** * this one is called when the command's execution fails for any reason. */ public void showExecutionFailed(Exception exception) { if (noDialogs) { if (commandDisplayName != null) { String status = NbBundle.getMessage(ErrorLogPanel.class, "FileSystemCommand.failed", commandDisplayName); // NOI18N StatusDisplayer.getDefault().setStatusText(status); } else { String status = NbBundle.getMessage(ErrorLogPanel.class, "FileSystemCommand.failed", command.getName()); // NOI18N StatusDisplayer.getDefault().setStatusText(status); } return; } if (commandDisplayName != null) { String status = NbBundle.getMessage(ErrorLogPanel.class, "FileSystemCommand.stop", commandDisplayName); // NOI18N StatusDisplayer.getDefault().setStatusText(status); } else { String status = NbBundle.getMessage(ErrorLogPanel.class, "FileSystemCommand.stop", command.getName()); // NOI18N StatusDisplayer.getDefault().setStatusText(status); } if (exception == null) { return; } final Exception exc = exception; if (exception instanceof CommandAbortedException) { return; } if (exception instanceof AuthenticationException) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { String message = exc.getLocalizedMessage(); NotifyDescriptor.Message excMess = new NotifyDescriptor.Message(message, NotifyDescriptor.WARNING_MESSAGE); DialogDisplayer.getDefault().notify(excMess); // new NotifyDescriptor.Exception(exc, exc.getLocalizedMessage())); } }); return; } if (exception instanceof CommandException) { CommandException comExc = (CommandException)exc; if (comExc.getUnderlyingException() != null) { //TEMPORARY // comExc.getUnderlyingException().printStackTrace(); } } initComponents(); initAccessibility(); lblMessage.setText(exception.getLocalizedMessage()); spLogList.setVisible(false); expanded = false; logListing = null; buff = new StringBuffer(getCurrentCommandLog()); // buff.append("\n\n" + exception.getLocalizedMessage()); // NOI18N if (buff == null) noLogAvailable = true; else noLogAvailable = false; commandLineForm = command.getName() + " " + command.getCVSArguments(); // NOI18N lblCommand.setText("( " + commandLineForm + " )"); // NOI18N if (dd == null) { bigDim = new java.awt.Dimension(400, 250); smallDim = new java.awt.Dimension(400, 150); showErrorPanel(); } else { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { dialog = DialogDisplayer.getDefault().createDialog(dd); dialog.show(); } }); } } /** * This method is the first one that is called during execution. * Here any initial setup of the displayer can be made. */ public void showStartCommand() { super.showStartCommand(); if (commandDisplayName != null) { String status = NbBundle.getMessage(ErrorLogPanel.class, "FileSystemCommand.start", commandDisplayName); // NOI18N StatusDisplayer.getDefault().setStatusText(status); } else { String status = NbBundle.getMessage(ErrorLogPanel.class, "FileSystemCommand.start", command.getName()); // NOI18N StatusDisplayer.getDefault().setStatusText(status); } } /** * When the library command's builder generates a FileInfoContainer object, the * Displayer is notified. * @param info - the generated information object */ public void showFileInfoGenerated(org.netbeans.lib.cvsclient.command.FileInfoContainer info) { super.showFileInfoGenerated(info); } /** * 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); } private void showErrorPanel() { String title = NbBundle.getBundle(ErrorLogPanel.class).getString("FileSystemCommand.errorMessage.title"); // NOI18N final DialogDescriptor ddesc = new DialogDescriptor(this, title); setDialogDescriptor(ddesc); initDialogButtons(ddesc, false); ddesc.setButtonListener(this); ddesc.setModal(false); javax.swing.SwingUtilities.invokeLater(new Runnable () { public void run () { dialog = DialogDisplayer.getDefault().createDialog(ddesc); dialog.show(); } }); } /** Get the help context for this component. * Subclasses should generally override this to return specific help. * @return the help context */ public org.openide.util.HelpCtx getHelpCtx() { // return new HelpCtx(ErrorLogPanel.class); return null; } } |
... 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.