1 package net.sourceforge.pmd.util.viewer.gui;
2
3 import net.sourceforge.pmd.ast.ParseException;
4 import net.sourceforge.pmd.util.viewer.model.ViewerModel;
5 import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
6 import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
7 import net.sourceforge.pmd.util.viewer.util.NLS;
8
9 import javax.swing.JButton;
10 import javax.swing.JFrame;
11 import javax.swing.JPanel;
12 import javax.swing.JSplitPane;
13 import java.awt.BorderLayout;
14 import java.awt.FlowLayout;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17
18
19 /***
20 * viewer's main frame
21 *
22 * @author Boris Gruschko ( boris at gruschko.org )
23 * @version $Id: MainFrame.java,v 1.2 2003/09/23 20:51:06 tomcopeland Exp $
24 */
25 public class MainFrame
26 extends JFrame
27 implements ActionListener, ActionCommands, ViewerModelListener
28 {
29 private ViewerModel model;
30 private SourceCodePanel sourcePanel;
31 private ASTPanel astPanel;
32 private XPathPanel xPathPanel;
33 private JButton compileBtn;
34 private JButton evalBtn;
35
36 /***
37 * constructs and shows the frame
38 */
39 public MainFrame( )
40 {
41 super( NLS.nls( "MAIN.FRAME.TITLE" ) );
42
43 init( );
44 }
45
46 private void init( )
47 {
48 model = new ViewerModel( );
49
50 model.addViewerModelListener( this );
51
52 sourcePanel = new SourceCodePanel( model );
53 astPanel = new ASTPanel( model );
54 xPathPanel = new XPathPanel( model );
55
56 getContentPane( ).setLayout( new BorderLayout( ) );
57
58 JSplitPane editingPane =
59 new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, sourcePanel, astPanel );
60 editingPane.setResizeWeight( 0.5d );
61
62 JPanel interactionsPane = new JPanel( new BorderLayout( ) );
63
64 interactionsPane.add( xPathPanel, BorderLayout.SOUTH );
65 interactionsPane.add( editingPane, BorderLayout.CENTER );
66
67 getContentPane( ).add( interactionsPane, BorderLayout.CENTER );
68
69 compileBtn = new JButton( NLS.nls( "MAIN.FRAME.COMPILE_BUTTON.TITLE" ) );
70 compileBtn.setActionCommand( COMPILE_ACTION );
71 compileBtn.addActionListener( this );
72
73 evalBtn = new JButton( NLS.nls( "MAIN.FRAME.EVALUATE_BUTTON.TITLE" ) );
74 evalBtn.setActionCommand( EVALUATE_ACTION );
75 evalBtn.addActionListener( this );
76 evalBtn.setEnabled( false );
77
78 JPanel btnPane = new JPanel( new FlowLayout( FlowLayout.LEFT ) );
79
80 btnPane.add( compileBtn );
81 btnPane.add( evalBtn );
82
83 getContentPane( ).add( btnPane, BorderLayout.SOUTH );
84
85 setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
86
87 pack( );
88 setSize( 800, 600 );
89
90 setVisible( true );
91 }
92
93 /***
94 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
95 */
96 public void actionPerformed( ActionEvent e )
97 {
98 String command = e.getActionCommand( );
99
100 if ( command.equals( COMPILE_ACTION ) )
101 {
102 try
103 {
104 model.commitSource( sourcePanel.getSourceCode( ) );
105 }
106 catch ( ParseException exc )
107 {
108 new ParseExceptionHandler( this, exc );
109 }
110 }
111 else if ( command.equals( EVALUATE_ACTION ) )
112 {
113 try
114 {
115 model.evaluateXPathExpression( xPathPanel.getXPathExpression( ), this );
116 }
117 catch ( Exception exc )
118 {
119 new ParseExceptionHandler( this, exc );
120 }
121 }
122 }
123
124 /***
125 * @see org.gruschko.pmd.viewer.model.ViewerModelListener#viewerModelChanged(org.gruschko.pmd.viewer.model.ViewerModelEvent)
126 */
127 public void viewerModelChanged( ViewerModelEvent e )
128 {
129 evalBtn.setEnabled( model.hasCompiledTree( ) );
130 }
131 }
132
133
134 /*
135 * $Log: MainFrame.java,v $
136 * Revision 1.2 2003/09/23 20:51:06 tomcopeland
137 * Cleaned up imports
138 *
139 * Revision 1.1 2003/09/23 20:32:42 tomcopeland
140 * Added Boris Gruschko's new AST/XPath viewer
141 *
142 * Revision 1.1 2003/09/24 01:33:03 bgr
143 * moved to a new package
144 *
145 * Revision 1.2 2003/09/24 00:40:35 bgr
146 * evaluation results browsing added
147 *
148 * Revision 1.1 2003/09/22 05:21:54 bgr
149 * initial commit
150 *
151 */
This page was automatically generated by Maven