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