Normand Briere
2019-08-06 b3ae4e889872ca0b9ca76f1d17b2f0b961226729
timeflow/app/TimeflowApp.java
....@@ -1,5 +1,6 @@
11 package timeflow.app;
22
3
+import java.net.URL;
34 import timeflow.app.ui.*;
45 import timeflow.app.actions.*;
56 import timeflow.app.ui.filter.*;
....@@ -25,8 +26,7 @@
2526
2627 public class TimeflowApp extends JFrame
2728 {
28
-
29
- public TFModel model = new TFModel();
29
+ public TimeflowModel model = new TimeflowModel();
3030 public JFileChooser fileChooser;
3131 AboutWindow splash;
3232 String[][] examples;
....@@ -36,10 +36,10 @@
3636 public JMenu filterMenu;
3737 JMenuItem save = new JMenuItem("Save");
3838 FilterControlPanel filterControlPanel;
39
- LinkTabPane leftPanel;
39
+ //LinkTabPane
40
+ JTabbedPane leftPanel;
4041 TFListener filterMenuMaker = new TFListener()
4142 {
42
-
4343 @Override
4444 public void note(TFEvent e)
4545 {
....@@ -70,37 +70,10 @@
7070 }
7171 };
7272
73
- void splash(boolean visible)
73
+ public JMenuBar TimeFlowWindow(Container container) throws HeadlessException
7474 {
75
- splash.setVisible(visible);
76
- }
77
-
78
- public void init() throws Exception
79
- {
80
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
81
- setBounds(0, 0, Math.min(d.width, 1200), Math.min(d.height, 900));
82
- setTitle(Display.version());
83
- setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
84
- final QuitAction quitAction = new QuitAction(this, model);
85
- addWindowListener(new WindowAdapter()
86
- {
87
-
88
- @Override
89
- public void windowClosing(WindowEvent e)
90
- {
91
- quitAction.quit();
92
- }
93
-
94
- public void windowStateChanged(WindowEvent e)
95
- {
96
- repaint();
97
- }
98
- });
99
- Image icon = Toolkit.getDefaultToolkit().getImage("images/icon.gif");
100
- setIconImage(icon);
101
-
10275 // read example directory
103
- String[] ex = getVisibleFiles("settings/examples");
76
+ String[] ex = getVisibleFiles("timeflow/settings/examples");
10477 int n = ex.length;
10578 examples = new String[n][2];
10679 for (int i = 0; i < n; i++)
....@@ -110,23 +83,25 @@
11083 if (dot >= 0 && dot < s.length() - 1);
11184 s = s.substring(0, dot);
11285 examples[i][0] = s;
113
- examples[i][1] = "settings/examples/" + ex[i];
86
+ examples[i][1] = "timeflow/settings/examples/" + ex[i];
11487 }
115
- templates = getVisibleFiles("settings/templates");
88
+
89
+ templates = getVisibleFiles("timeflow/settings/templates");
11690 fileChooser = new JFileChooser(state.getCurrentFile());
11791
118
- getContentPane().setLayout(new BorderLayout());
92
+ container.setLayout(new BorderLayout());
11993
12094 // left tab area, with vertical gray divider.
12195 JPanel leftHolder = new JPanel();
122
- getContentPane().add(leftHolder, BorderLayout.WEST);
96
+ container.add(leftHolder, BorderLayout.EAST); // WEST);
12397
12498 leftHolder.setLayout(new BorderLayout());
12599 JPanel pad = new Pad(3, 3);
126100 pad.setBackground(Color.gray);
127101 leftHolder.add(pad, BorderLayout.EAST);
128102
129
- leftPanel = new LinkTabPane();//JTabbedPane();
103
+ leftPanel = new //LinkTabPane();
104
+ JTabbedPane();
130105 leftHolder.add(leftPanel, BorderLayout.CENTER);
131106
132107 JPanel configPanel = new JPanel();
....@@ -141,18 +116,17 @@
141116 configPanel.add(legend, BorderLayout.CENTER);
142117 legend.add(new SizeLegendPanel(model), BorderLayout.NORTH);
143118 legend.add(new ColorLegendPanel(model), BorderLayout.CENTER);
144
- leftPanel.addTab(configPanel, "Display", true);
119
+ leftPanel.add(configPanel, "Display"); //, true);
145120
146
- leftPanel.addTab(filterControlPanel, "Filter", true);
121
+ leftPanel.add(filterControlPanel, "Filter"); //, true);
147122
148123 // center tab area
149124
150125 final LinkTabPane center = new LinkTabPane();
151
- getContentPane().add(center, BorderLayout.CENTER);
126
+ container.add(center, BorderLayout.CENTER);
152127
153128 center.addPropertyChangeListener(new PropertyChangeListener()
154129 {
155
-
156130 @Override
157131 public void propertyChange(PropertyChangeEvent evt)
158132 {
....@@ -165,18 +139,18 @@
165139 AbstractView[] views =
166140 {
167141 timeline,
168
- new CalendarView(model),
142
+ //new CalendarView(model),
169143 new ListView(model),
170144 new TableView(model),
171145 new BarGraphView(model),
172
- intro,
173
- new DescriptionView(model),
146
+ //intro,
174147 new SummaryView(model),
148
+ new DescriptionView(model),
175149 };
176150
177151 for (int i = 0; i < views.length; i++)
178152 {
179
- center.addTab(views[i], views[i].getName(), i < 5);
153
+ center.addTab(views[i], views[i].getName(), true); // i < 5);
180154 displayPanel.addLocalControl(views[i].getName(), views[i].getControls());
181155 }
182156
....@@ -187,7 +161,6 @@
187161 // but then, once data is loaded, switch directly to the timeline view.
188162 model.addListener(new TFListener()
189163 {
190
-
191164 @Override
192165 public void note(TFEvent e)
193166 {
....@@ -203,12 +176,15 @@
203176 });
204177
205178 JMenuBar menubar = new JMenuBar();
206
- setJMenuBar(menubar);
179
+
180
+ // frame.setJMenuBar(menubar);
207181
208182 JMenu fileMenu = new JMenu("File");
209183 menubar.add(fileMenu);
210184
211
- fileMenu.add(new NewDataAction(this));
185
+ TimeflowAction tlAction = new NewDataAction(this);
186
+ fileMenu.add(tlAction);
187
+ tlAction.actionPerformed(null);
212188 fileMenu.add(new CopySchemaAction(this));
213189
214190 JMenu templateMenu = new JMenu("New From Template");
....@@ -231,12 +207,10 @@
231207
232208 fileMenu.addSeparator();
233209
234
-
235210 JMenuItem open = new JMenuItem("Open...");
236211 fileMenu.add(open);
237212 open.addActionListener(new ActionListener()
238213 {
239
-
240214 @Override
241215 public void actionPerformed(ActionEvent e)
242216 {
....@@ -254,7 +228,6 @@
254228 fileMenu.add(impDel);
255229 impDel.addActionListener(new ActionListener()
256230 {
257
-
258231 @Override
259232 public void actionPerformed(ActionEvent e)
260233 {
....@@ -273,7 +246,6 @@
273246 save.setEnabled(false);
274247 save.addActionListener(new ActionListener()
275248 {
276
-
277249 @Override
278250 public void actionPerformed(ActionEvent e)
279251 {
....@@ -283,7 +255,6 @@
283255 });
284256 model.addListener(new TFListener()
285257 {
286
-
287258 @Override
288259 public void note(TFEvent e)
289260 {
....@@ -295,7 +266,6 @@
295266 fileMenu.add(saveAs);
296267 saveAs.addActionListener(new ActionListener()
297268 {
298
-
299269 @Override
300270 public void actionPerformed(ActionEvent e)
301271 {
....@@ -309,7 +279,6 @@
309279 fileMenu.add(exportTSV);
310280 exportTSV.addActionListener(new ActionListener()
311281 {
312
-
313282 @Override
314283 public void actionPerformed(ActionEvent e)
315284 {
....@@ -320,7 +289,6 @@
320289 fileMenu.add(exportCSV);
321290 exportCSV.addActionListener(new ActionListener()
322291 {
323
-
324292 @Override
325293 public void actionPerformed(ActionEvent e)
326294 {
....@@ -331,15 +299,14 @@
331299 fileMenu.add(exportHTML);
332300 exportHTML.addActionListener(new ActionListener()
333301 {
334
-
335302 @Override
336303 public void actionPerformed(ActionEvent e)
337304 {
338305 exportHtml();
339306 }
340307 });
341
- fileMenu.addSeparator();
342
- fileMenu.add(quitAction);
308
+// fileMenu.addSeparator();
309
+// fileMenu.add(quitAction);
343310
344311 JMenu editMenu = new JMenu("Edit");
345312 menubar.add(editMenu);
....@@ -370,7 +337,6 @@
370337 final String file = examples[i][1];
371338 example.addActionListener(new ActionListener()
372339 {
373
-
374340 @Override
375341 public void actionPerformed(ActionEvent e)
376342 {
....@@ -380,7 +346,7 @@
380346 }
381347
382348 JMenu helpMenu = new JMenu("Help");
383
- menubar.add(helpMenu);
349
+ //menubar.add(helpMenu);
384350
385351 helpMenu.add(new WebDocAction(this));
386352
....@@ -388,7 +354,6 @@
388354 helpMenu.add(about);
389355 about.addActionListener(new ActionListener()
390356 {
391
-
392357 @Override
393358 public void actionPerformed(ActionEvent e)
394359 {
....@@ -398,7 +363,6 @@
398363
399364 model.addListener(new TFListener()
400365 {
401
-
402366 @Override
403367 public void note(TFEvent e)
404368 {
....@@ -414,6 +378,41 @@
414378 }
415379 }
416380 });
381
+
382
+ return menubar;
383
+ }
384
+
385
+ void splash(boolean visible)
386
+ {
387
+ splash.setVisible(visible);
388
+ }
389
+
390
+ public void init() throws Exception
391
+ {
392
+ Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
393
+ setBounds(0, 0, Math.min(d.width, 1200), Math.min(d.height, 900));
394
+ setTitle(Display.version());
395
+ setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
396
+// final QuitAction quitAction = new QuitAction(this, model);
397
+// addWindowListener(new WindowAdapter()
398
+// {
399
+// @Override
400
+// public void windowClosing(WindowEvent e)
401
+// {
402
+// quitAction.quit();
403
+// }
404
+//
405
+// public void windowStateChanged(WindowEvent e)
406
+// {
407
+// repaint();
408
+// }
409
+// });
410
+ Image icon = Toolkit.getDefaultToolkit().getImage("images/icon.gif");
411
+ setIconImage(icon);
412
+
413
+ Container container = getContentPane();
414
+
415
+ TimeFlowWindow(container);
417416 }
418417
419418 void makeRecentFileMenu()
....@@ -556,7 +555,7 @@
556555 }
557556 try
558557 {
559
- final File f = new File(fileName);
558
+ final File f = new File(TimeflowApp.class.getClassLoader().getResource(fileName).toURI());
560559 ActDB db = importer.importFile(f);
561560 model.setDB(db, fileName, readOnly, TimeflowApp.this);
562561 if (!readOnly)
....@@ -695,15 +694,26 @@
695694
696695 static String[] getVisibleFiles(String dir)
697696 {
698
- String[] s = new File(dir).list();
699
- ArrayList<String> real = new ArrayList<String>();
700
- for (int i = 0; i < s.length; i++)
697
+ System.out.println("getVisibleFiles = " + dir);
698
+ try
701699 {
702
- if (!s[i].startsWith("."))
700
+ final URL resource = TimeflowApp.class.getClassLoader().getResource(dir);
701
+ System.out.println("resource = " + resource);
702
+ String[] s = new File(resource.toURI()).list();
703
+ ArrayList<String> real = new ArrayList<String>();
704
+ for (int i = 0; i < s.length; i++)
703705 {
704
- real.add(s[i]);
706
+ if (!s[i].startsWith("."))
707
+ {
708
+ real.add(s[i]);
709
+ }
705710 }
711
+ return (String[]) real.toArray(new String[0]);
706712 }
707
- return (String[]) real.toArray(new String[0]);
713
+ catch (Exception e)
714
+ {
715
+ e.printStackTrace();
716
+ return new String[0];
717
+ }
708718 }
709719 }