1 | package com.algomagic.atn; |
---|
2 | |
---|
3 | import att.grappa.*; |
---|
4 | |
---|
5 | import java.util.*; |
---|
6 | import java.io.*; |
---|
7 | |
---|
8 | import java.awt.*; |
---|
9 | import java.awt.event.*; |
---|
10 | import java.awt.geom.*; |
---|
11 | import javax.swing.*; |
---|
12 | import javax.swing.border.*; |
---|
13 | import javax.swing.event.*; |
---|
14 | |
---|
15 | |
---|
16 | public class Visualization extends JFrame |
---|
17 | implements VisualizationConstants { |
---|
18 | |
---|
19 | private Properties _properties; |
---|
20 | private VisualizationPanel[] _visPanels; |
---|
21 | |
---|
22 | private ControlPanel _controls; |
---|
23 | private ProgressPanel _progress; |
---|
24 | |
---|
25 | private String[] _names = new String[2]; |
---|
26 | private Collection[] _policies = new Collection[2]; |
---|
27 | |
---|
28 | public void setName( String name, int side ) { |
---|
29 | _names[side] = name; |
---|
30 | } |
---|
31 | |
---|
32 | public void setPolicies( Collection pol, int side ) { |
---|
33 | _policies[side] = pol; |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | public void setAutoRaise( boolean state ) { |
---|
39 | _visPanels[LEFT_SIDE].setAutoRaise( state ); |
---|
40 | if( _visPanels[RIGHT_SIDE] != null ) { |
---|
41 | _visPanels[RIGHT_SIDE].setAutoRaise( state ); |
---|
42 | } |
---|
43 | |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | public Visualization( String log1, String log2 ) { |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | addWindowListener( new WindowAdapter( ) { |
---|
52 | public void windowClosing( WindowEvent we ) { |
---|
53 | Window w = we.getWindow( ); |
---|
54 | w.setVisible( false ); |
---|
55 | w.dispose( ); |
---|
56 | System.exit( 0 ); |
---|
57 | } |
---|
58 | }); |
---|
59 | |
---|
60 | |
---|
61 | loadProperties( ); |
---|
62 | initializeFrame( log2 != null ); |
---|
63 | |
---|
64 | LogParser parser = null; |
---|
65 | |
---|
66 | try { |
---|
67 | parser = |
---|
68 | (LogParser)Class.forName( _properties.getProperty( PARSER_PROP, |
---|
69 | PARSER_DEFAULT ) ).newInstance( ); |
---|
70 | } catch( Exception e ) { |
---|
71 | e.printStackTrace( ); |
---|
72 | System.exit( 1 ); |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | java.util.List updates = parser.parse( this, log1, log2 ); |
---|
77 | |
---|
78 | updates = _visPanels[LEFT_SIDE].initialize( updates ); |
---|
79 | _visPanels[LEFT_SIDE].addCredentials( _policies[LEFT_SIDE], 2 ); |
---|
80 | _visPanels[LEFT_SIDE].setName( _names[LEFT_SIDE] ); |
---|
81 | |
---|
82 | |
---|
83 | // System.out.println( _policies[LEFT_SIDE] ); |
---|
84 | // System.out.println( _policies[RIGHT_SIDE] ); |
---|
85 | |
---|
86 | |
---|
87 | if( log2 != null ) { |
---|
88 | updates = _visPanels[RIGHT_SIDE].initialize( updates ); |
---|
89 | _visPanels[RIGHT_SIDE].addCredentials( _policies[RIGHT_SIDE], 2 ); |
---|
90 | _visPanels[RIGHT_SIDE].setName( _names[RIGHT_SIDE] ); |
---|
91 | |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | java.util.List l = new ArrayList( ); |
---|
97 | |
---|
98 | for( Iterator i = updates.iterator( ); i.hasNext( ); ) { |
---|
99 | Update u = (Update)i.next( ); |
---|
100 | PanelUpdate pu = null;; |
---|
101 | |
---|
102 | if( u.getSide( ) == LEFT_SIDE ) { |
---|
103 | pu = _visPanels[LEFT_SIDE].apply( u ); |
---|
104 | } else if( log2 != null ) { |
---|
105 | pu = _visPanels[RIGHT_SIDE].apply( u ); |
---|
106 | } |
---|
107 | |
---|
108 | if( !pu.isEmpty( ) ) { |
---|
109 | l.add( pu ); |
---|
110 | } |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | // _visPanels[LEFT_SIDE].reset( updates ); |
---|
116 | // if( log2 != null ) { |
---|
117 | // _visPanels[RIGHT_SIDE].reset( updates ); |
---|
118 | // } |
---|
119 | |
---|
120 | |
---|
121 | PlayBackController pbc = new PlayBackController( l, _properties ); |
---|
122 | pbc.addObserver( _progress ); |
---|
123 | pbc.addObserver( _visPanels[LEFT_SIDE] ); |
---|
124 | _visPanels[LEFT_SIDE].hideGraph( ); |
---|
125 | |
---|
126 | if( log2 != null ) { |
---|
127 | pbc.addObserver( _visPanels[RIGHT_SIDE] ); |
---|
128 | _visPanels[RIGHT_SIDE].hideGraph( ); |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | _progress.setMax( l.size( ) ); |
---|
133 | _controls.addObserver( pbc ); |
---|
134 | |
---|
135 | |
---|
136 | // // Object[] o = getKeyListeners( ); |
---|
137 | // for( int i = 0; o != null && i<o.length; i++ ) { |
---|
138 | // removeKeyListener( (KeyListener)o[i] ); |
---|
139 | // } |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | // addKeyListener( new KeyListener( ) { |
---|
144 | // public void keyTyped( KeyEvent e ) { |
---|
145 | // System.out.println( "typed: " + e ); |
---|
146 | // } |
---|
147 | |
---|
148 | // public void keyPressed( KeyEvent e ) { |
---|
149 | // System.out.println( "pressed: " + e ); |
---|
150 | // } |
---|
151 | |
---|
152 | // public void keyReleased( KeyEvent e ) { |
---|
153 | // System.out.println( "released: " + e ); |
---|
154 | // } |
---|
155 | |
---|
156 | |
---|
157 | // }); |
---|
158 | |
---|
159 | |
---|
160 | // addFocusListener( new FocusListener( ) { |
---|
161 | // public void focusGained( FocusEvent e ) { |
---|
162 | // System.out.println( "focus gained: " + e ); |
---|
163 | // } |
---|
164 | |
---|
165 | // public void focusLost( FocusEvent e ) { |
---|
166 | // System.out.println( "focus lost: " + e ); |
---|
167 | // // requestFocus( ); |
---|
168 | // } |
---|
169 | |
---|
170 | |
---|
171 | // }); |
---|
172 | |
---|
173 | |
---|
174 | |
---|
175 | show( ); |
---|
176 | // requestFocus( true ); |
---|
177 | |
---|
178 | } |
---|
179 | |
---|
180 | private void initializeFrame( boolean twoSided ) { |
---|
181 | JPanel mainPanel = new JPanel( ); |
---|
182 | mainPanel.setLayout( new BoxLayout( mainPanel, BoxLayout.X_AXIS ) ); |
---|
183 | |
---|
184 | _visPanels = new VisualizationPanel[2]; |
---|
185 | _visPanels[LEFT_SIDE] = new VisualizationPanel( LEFT_SIDE, _properties ); |
---|
186 | mainPanel.add( _visPanels[LEFT_SIDE] ); |
---|
187 | |
---|
188 | if( twoSided ) { |
---|
189 | _visPanels[RIGHT_SIDE] = new VisualizationPanel( RIGHT_SIDE, _properties ); |
---|
190 | mainPanel.add( Box.createHorizontalStrut( 10 ) ); |
---|
191 | mainPanel.add( _visPanels[RIGHT_SIDE] ); |
---|
192 | } |
---|
193 | |
---|
194 | _controls = new ControlPanel( _properties, this ); |
---|
195 | _progress = new ProgressPanel( ); |
---|
196 | |
---|
197 | JPanel toolPanel = new JPanel( ); |
---|
198 | |
---|
199 | toolPanel.setMaximumSize( new Dimension( 2000, 50 ) ); |
---|
200 | toolPanel.setPreferredSize( new Dimension( 2000, 50 ) ); |
---|
201 | |
---|
202 | |
---|
203 | toolPanel.setLayout( new BoxLayout( toolPanel, BoxLayout.X_AXIS ) ); |
---|
204 | toolPanel.add( _controls ); |
---|
205 | toolPanel.add( _progress ); |
---|
206 | |
---|
207 | Container contentPane = getContentPane( ); |
---|
208 | contentPane.setLayout( new BoxLayout( contentPane, BoxLayout.Y_AXIS ) ); |
---|
209 | contentPane.add( mainPanel ); |
---|
210 | contentPane.add( toolPanel ); |
---|
211 | |
---|
212 | setTitle( _properties.getProperty( WINDOW_TITLE_PROP, WINDOW_TITLE_DEFAULT ) ); |
---|
213 | setSize( Integer.parseInt( _properties.getProperty( WINDOW_WIDTH_PROP, WINDOW_WIDTH_DEFAULT ) ), |
---|
214 | Integer.parseInt( _properties.getProperty( WINDOW_HEIGHT_PROP, WINDOW_HEIGHT_DEFAULT ) ) ); |
---|
215 | |
---|
216 | } |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | private void loadProperties( ) { |
---|
221 | String propsFileName = System.getProperty( CONFIG_FILE_PROP, CONFIG_FILE_DEFAULT ); |
---|
222 | File file = new File( propsFileName ); |
---|
223 | |
---|
224 | _properties = new Properties( ); |
---|
225 | |
---|
226 | if( file.exists( ) ) { |
---|
227 | try { |
---|
228 | _properties.load( new FileInputStream( file ) ); |
---|
229 | } catch( Exception e ) { } |
---|
230 | } |
---|
231 | |
---|
232 | } |
---|
233 | |
---|
234 | |
---|
235 | public static void main( String[] args ) { |
---|
236 | Visualization vis = null; |
---|
237 | |
---|
238 | if( args.length == 1 ) { |
---|
239 | vis = new Visualization( args[0], null ); |
---|
240 | } else if ( args.length == 2 ) { |
---|
241 | vis = new Visualization( args[0], args[1] ); |
---|
242 | } else { |
---|
243 | System.err.println( "usage: Visualization <log file> [<log file>]" ); |
---|
244 | System.exit( 1 ); |
---|
245 | } |
---|
246 | |
---|
247 | } |
---|
248 | |
---|
249 | |
---|
250 | } |
---|