31
31
import org .graphstream .ui .swingViewer .ViewerPipe ;
32
32
33
33
34
-
34
+ /**
35
+ * UI Class that contains all the UI functions
36
+ * @author brandon
37
+ *
38
+ */
35
39
public class ControlUI extends JFrame implements ActionListener {
36
40
37
41
38
42
// Logic Variables
39
- MainLogic MLogic ;
40
- File graph_file = null ;
41
- File anim_file = null ;
43
+ private MainLogic MLogic ;
44
+ private File graph_file = null ;
45
+ private File anim_file = null ;
42
46
43
- GraphUIProperty gUIProp ;
47
+ private GraphUIProperty gUIProp ;
44
48
45
49
// UI Components
46
50
47
- int frm_width , frm_height ;
48
- int ctrl_width , ctrl_height ;
51
+ private int frm_width , frm_height ;
52
+ private int ctrl_width , ctrl_height ;
49
53
50
- JFileChooser fc ;
51
- JFrame jfrm ;
54
+ private JFileChooser fc ;
55
+ private JFrame jfrm ;
52
56
53
- JLabel lbl_header ;
54
- JLabel lbl_graphPath ;
55
- JButton btn_chooseGraph ;
57
+ private JLabel lbl_header ;
58
+ private JLabel lbl_graphPath ;
59
+ private JButton btn_chooseGraph ;
56
60
57
- JButton btn_loadGraph ;
61
+ private JButton btn_loadGraph ;
58
62
59
- JPanel ctrl_panel ;
63
+ private JPanel ctrl_panel ;
60
64
61
- JTextField txt_highlight ;
62
- JButton btn_highlight ;
65
+ private JTextField txt_highlight ;
66
+ private JButton btn_highlight ;
63
67
64
- View vw =null ;
68
+ private View vw =null ;
65
69
66
70
// Set % of span
67
- double btn_chooseGraph_h = .1 ;
68
-
71
+ private double btn_chooseGraph_h = .1 ;
69
72
70
73
74
+ /**
75
+ * Constructor, inits and starts UI
76
+ */
71
77
public ControlUI ()
72
78
{
73
79
init ();
74
80
startUI ();
75
81
76
82
}
77
83
84
+ /**
85
+ * initializes height, width variables, etc.
86
+ * and creates main logic object for use by UI
87
+ */
78
88
private void init ()
79
89
{
80
90
@@ -95,9 +105,12 @@ private void init ()
95
105
gUIProp .posx = 0 ;
96
106
gUIProp .posy = 0 ;
97
107
98
- MLogic = new MainLogic (gUIProp );
108
+ MLogic = new MainLogic ();
99
109
}
100
110
111
+ /**
112
+ * Adds objects to UI, prepares UI window
113
+ */
101
114
private void startUI (){
102
115
103
116
jfrm = new JFrame ();
@@ -135,13 +148,11 @@ private void startUI(){
135
148
ctrl_panel .add (btn_loadGraph );
136
149
btn_loadGraph .addActionListener (this );
137
150
138
- /* Features to add
151
+ // Features to add
139
152
// Block Label
140
153
JLabel lbl_div1 = new JLabel ("-----------------------------------" );
141
154
ctrl_panel .add (lbl_div1 );
142
155
143
-
144
-
145
156
// Highlight filter Text Field and button
146
157
txt_highlight = new JTextField ();
147
158
ctrl_panel .add (txt_highlight );
@@ -154,7 +165,7 @@ public void actionPerformed(ActionEvent e) {
154
165
}
155
166
});
156
167
ctrl_panel .add (btn_highlight );
157
- */
168
+
158
169
159
170
jfrm .setVisible (true );
160
171
@@ -168,102 +179,18 @@ public void actionPerformed(ActionEvent e) {
168
179
//fromViewer.addViewerListener((ViewerListener) new NodeClickListener());
169
180
//fromViewer.addSink(graph);
170
181
171
-
172
- /*
173
-
174
-
175
- // Initialize Frame + set default behaviors
176
- jfrm=new JFrame("VisualProPPR Control");
177
- jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
178
- jfrm.setLayout(new BorderLayout());
179
-
180
-
181
- // Set width height and location
182
- Dimension screen_dim = Toolkit.getDefaultToolkit().getScreenSize();
183
-
184
- jfrm.setSize(frm_width,frm_height);
185
-
186
- jfrm.setLocation(screen_dim.width - ctrl_width, 0);
187
-
188
-
189
-
190
-
191
-
192
-
193
- // Label
194
- lbl_header=new JLabel("Welcome to VisualProPPR");
195
- jfrm.add(lbl_header);
196
-
197
-
198
- // Choose graph button
199
-
200
- //button dims
201
- int btn_width = (int)((double)ctrl_width * 0.8);
202
- int btn_height = (int)((double)ctrl_height * btn_chooseGraph_h);
203
- btn_chooseGraph = new JButton("Graph Button Chooser");
204
- btn_chooseGraph.setVerticalTextPosition(AbstractButton.CENTER);
205
- btn_chooseGraph.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
206
- btn_chooseGraph.addActionListener(this);
207
- btn_chooseGraph.setLocation(frm_width-ctrl_width, 0);
208
- btn_chooseGraph.setSize(btn_width, btn_height);
209
- jfrm.add(btn_chooseGraph,BorderLayout.LINE_END);
210
-
211
- // Chosen Graph Label
212
- lbl_graphPath =new JLabel("");
213
- lbl_graphPath.setText("< No Graph Chosen >");
214
- // Get location offset
215
- //btn_chooseGraph.getLocation() + btn_chooseGraph.getSize();
216
- lbl_graphPath.setLocation(frm_width - ctrl_width, 50);
217
-
218
- jfrm.add(lbl_graphPath, BorderLayout.LINE_END);
219
-
220
-
221
-
222
-
223
- // File Chooser Component
224
- //Create a file chooser
225
- fc = new JFileChooser();
226
- //In response to a button click:
227
- //fc.showOpenDialog(jfrm);
228
-
229
-
230
- // Load graph button
231
- btn_width = (int)((double)ctrl_width * 0.8);
232
- btn_height = (int)((double)ctrl_height * btn_chooseGraph_h);
233
- btn_loadGraph = new JButton("Load Graph");
234
- btn_loadGraph.setVerticalTextPosition(AbstractButton.CENTER);
235
- btn_loadGraph.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
236
- btn_loadGraph.addActionListener(this);
237
- btn_loadGraph.setLocation(frm_width-ctrl_width, 100);
238
- //btn_loadGraph.setSize(btn_width, btn_height);
239
- btn_loadGraph.setSize(100, 100);
240
- jfrm.add(btn_loadGraph,BorderLayout.LINE_END);
241
-
242
- //int returnVal = fc.showOpenDialog(null);
243
-
244
-
245
- // Add components
246
- jfrm.setVisible(true);
247
-
248
- */
249
- /*
250
- * // Set it so program doesnt abort when close window
251
- vwr.setCloseFramePolicy(Viewer.CloseFramePolicy.CLOSE_VIEWER);
252
- org.graphstream.ui.swingViewer.View vw = vwr.getDefaultView();
253
- vw.setSize(width,height);
254
- vw.setLocation(posx, posy);
255
-
256
- */
182
+
257
183
}
258
184
259
185
260
186
261
187
262
-
188
+ /**
189
+ * Action listener for click of buttons
190
+ */
263
191
public void actionPerformed (ActionEvent e ) {
264
192
Object source = e .getSource ();
265
- System .out .println ("Event:" + e );
266
- System .out .println ("Source:" + source );
193
+
267
194
268
195
if (source == btn_chooseGraph )
269
196
{
@@ -285,6 +212,9 @@ public void actionPerformed(ActionEvent e) {
285
212
}
286
213
287
214
215
+ /**
216
+ * Function to laod graph and create graph listener
217
+ */
288
218
NodeClickListener clisten =null ;
289
219
private void loadGraph ()
290
220
{
@@ -308,13 +238,11 @@ private void loadGraph()
308
238
vw = vwr .addDefaultView (false );
309
239
310
240
311
- System .out .println (gUIProp .width );
312
- System .out .println (gUIProp .height );
313
241
vw .setSize (gUIProp .width ,gUIProp .height );
314
242
vw .setLocation (gUIProp .posx , gUIProp .posy );
315
243
316
244
317
- /* Features to add
245
+ // Features to add
318
246
// We connect back the viewer to the graph,
319
247
// the graph becomes a sink for the viewer.
320
248
// We also install us as a viewer listener to
@@ -323,7 +251,7 @@ private void loadGraph()
323
251
clisten = new NodeClickListener (fromViewer , vw , MLogic .getGraph ());
324
252
fromViewer .addViewerListener ((ViewerListener ) clisten );
325
253
326
- */
254
+
327
255
328
256
// Add in frame
329
257
jfrm .add (vw ,BorderLayout .LINE_START );
0 commit comments