View Javadoc

1   package net.sourceforge.pmd.util.viewer.gui;
2   
3   import net.sourceforge.pmd.util.viewer.util.NLS;
4   
5   import javax.swing.*;
6   import java.awt.*;
7   import java.awt.event.ActionEvent;
8   import java.awt.event.ActionListener;
9   
10  
11  /***
12   * handles parsing exceptions
13   *
14   * @author Boris Gruschko ( boris at gruschko.org )
15   * @version $Id: ParseExceptionHandler.java,v 1.3 2004/04/15 18:21:58 tomcopeland Exp $
16   */
17  public class ParseExceptionHandler
18    extends JDialog
19    implements ActionListener
20  {
21    private Exception exc;
22    private JTextArea errorArea;
23    private JButton   okBtn;
24  
25    /***
26     * creates the dialog
27     *
28     * @param parent dialog's parent
29     * @param exc exception to be handled
30     */
31    public ParseExceptionHandler( JFrame parent, Exception exc )
32    {
33      super( parent, NLS.nls( "COMPILE_ERROR.DIALOG.TITLE" ), true );
34  
35      this.exc = exc;
36  
37      init(  );
38    }
39  
40    private void init(  )
41    {
42      errorArea = new JTextArea(  );
43      errorArea.setEditable( false );
44      errorArea.setText( exc.getMessage(  ) + "\n" );
45  
46      getContentPane(  ).setLayout( new BorderLayout(  ) );
47  
48      JPanel messagePanel = new JPanel( new BorderLayout(  ) );
49  
50      messagePanel.setBorder(
51        BorderFactory.createCompoundBorder(
52          BorderFactory.createRaisedBevelBorder(  ),
53          BorderFactory.createTitledBorder(
54            BorderFactory.createEtchedBorder(  ),
55            NLS.nls( "COMPILE_ERROR.PANEL.TITLE" ) ) ) );
56  
57      messagePanel.add( new JScrollPane( errorArea ), BorderLayout.CENTER );
58  
59      getContentPane(  ).add( messagePanel, BorderLayout.CENTER );
60  
61      JPanel btnPane = new JPanel( new FlowLayout( FlowLayout.RIGHT ) );
62  
63      okBtn = new JButton( NLS.nls( "COMPILE_ERROR.OK_BUTTON.CAPTION" ) );
64  
65      okBtn.addActionListener( this );
66  
67      btnPane.add( okBtn );
68  
69      getRootPane(  ).setDefaultButton( okBtn );
70  
71      getContentPane(  ).add( btnPane, BorderLayout.SOUTH );
72  
73      pack(  );
74  
75      setLocationRelativeTo( getParent(  ) );
76  
77      setVisible( true );
78    }
79  
80    /***
81     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
82     */
83    public void actionPerformed( ActionEvent e )
84    {
85      if ( e.getSource(  ) == okBtn )
86      {
87        dispose(  );
88      }
89    }
90  }
91  
92  
93  /*
94   * $Log: ParseExceptionHandler.java,v $
95   * Revision 1.3  2004/04/15 18:21:58  tomcopeland
96   * Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
97   *
98   * Revision 1.2  2003/09/23 20:51:06  tomcopeland
99   * Cleaned up imports
100  *
101  * Revision 1.1  2003/09/23 20:32:42  tomcopeland
102  * Added Boris Gruschko's new AST/XPath viewer
103  *
104  * Revision 1.1  2003/09/24 01:33:03  bgr
105  * moved to a new package
106  *
107  * Revision 1.2  2003/09/24 00:40:35  bgr
108  * evaluation results browsing added
109  *
110  * Revision 1.1  2003/09/22 05:21:54  bgr
111  * initial commit
112  *
113  */