| .. | .. |
|---|
| 1 | 1 | package timeflow.app; |
|---|
| 2 | 2 | |
|---|
| 3 | +import java.net.URL; |
|---|
| 3 | 4 | import timeflow.app.ui.*; |
|---|
| 4 | 5 | import timeflow.app.actions.*; |
|---|
| 5 | 6 | import timeflow.app.ui.filter.*; |
|---|
| .. | .. |
|---|
| 25 | 26 | |
|---|
| 26 | 27 | public class TimeflowApp extends JFrame |
|---|
| 27 | 28 | { |
|---|
| 28 | | - |
|---|
| 29 | | - public TFModel model = new TFModel(); |
|---|
| 29 | + public TimeflowModel model = new TimeflowModel(); |
|---|
| 30 | 30 | public JFileChooser fileChooser; |
|---|
| 31 | 31 | AboutWindow splash; |
|---|
| 32 | 32 | String[][] examples; |
|---|
| .. | .. |
|---|
| 36 | 36 | public JMenu filterMenu; |
|---|
| 37 | 37 | JMenuItem save = new JMenuItem("Save"); |
|---|
| 38 | 38 | FilterControlPanel filterControlPanel; |
|---|
| 39 | | - LinkTabPane leftPanel; |
|---|
| 39 | + //LinkTabPane |
|---|
| 40 | + JTabbedPane leftPanel; |
|---|
| 40 | 41 | TFListener filterMenuMaker = new TFListener() |
|---|
| 41 | 42 | { |
|---|
| 42 | | - |
|---|
| 43 | 43 | @Override |
|---|
| 44 | 44 | public void note(TFEvent e) |
|---|
| 45 | 45 | { |
|---|
| .. | .. |
|---|
| 70 | 70 | } |
|---|
| 71 | 71 | }; |
|---|
| 72 | 72 | |
|---|
| 73 | | - void splash(boolean visible) |
|---|
| 73 | + public JMenuBar TimeFlowWindow(Container container) throws HeadlessException |
|---|
| 74 | 74 | { |
|---|
| 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 | | - |
|---|
| 102 | 75 | // read example directory |
|---|
| 103 | | - String[] ex = getVisibleFiles("settings/examples"); |
|---|
| 76 | + String[] ex = getVisibleFiles("timeflow/settings/examples"); |
|---|
| 104 | 77 | int n = ex.length; |
|---|
| 105 | 78 | examples = new String[n][2]; |
|---|
| 106 | 79 | for (int i = 0; i < n; i++) |
|---|
| .. | .. |
|---|
| 110 | 83 | if (dot >= 0 && dot < s.length() - 1); |
|---|
| 111 | 84 | s = s.substring(0, dot); |
|---|
| 112 | 85 | examples[i][0] = s; |
|---|
| 113 | | - examples[i][1] = "settings/examples/" + ex[i]; |
|---|
| 86 | + examples[i][1] = "timeflow/settings/examples/" + ex[i]; |
|---|
| 114 | 87 | } |
|---|
| 115 | | - templates = getVisibleFiles("settings/templates"); |
|---|
| 88 | + |
|---|
| 89 | + templates = getVisibleFiles("timeflow/settings/templates"); |
|---|
| 116 | 90 | fileChooser = new JFileChooser(state.getCurrentFile()); |
|---|
| 117 | 91 | |
|---|
| 118 | | - getContentPane().setLayout(new BorderLayout()); |
|---|
| 92 | + container.setLayout(new BorderLayout()); |
|---|
| 119 | 93 | |
|---|
| 120 | 94 | // left tab area, with vertical gray divider. |
|---|
| 121 | 95 | JPanel leftHolder = new JPanel(); |
|---|
| 122 | | - getContentPane().add(leftHolder, BorderLayout.WEST); |
|---|
| 96 | + container.add(leftHolder, BorderLayout.EAST); // WEST); |
|---|
| 123 | 97 | |
|---|
| 124 | 98 | leftHolder.setLayout(new BorderLayout()); |
|---|
| 125 | 99 | JPanel pad = new Pad(3, 3); |
|---|
| 126 | 100 | pad.setBackground(Color.gray); |
|---|
| 127 | 101 | leftHolder.add(pad, BorderLayout.EAST); |
|---|
| 128 | 102 | |
|---|
| 129 | | - leftPanel = new LinkTabPane();//JTabbedPane(); |
|---|
| 103 | + leftPanel = new //LinkTabPane(); |
|---|
| 104 | + JTabbedPane(); |
|---|
| 130 | 105 | leftHolder.add(leftPanel, BorderLayout.CENTER); |
|---|
| 131 | 106 | |
|---|
| 132 | 107 | JPanel configPanel = new JPanel(); |
|---|
| .. | .. |
|---|
| 141 | 116 | configPanel.add(legend, BorderLayout.CENTER); |
|---|
| 142 | 117 | legend.add(new SizeLegendPanel(model), BorderLayout.NORTH); |
|---|
| 143 | 118 | legend.add(new ColorLegendPanel(model), BorderLayout.CENTER); |
|---|
| 144 | | - leftPanel.addTab(configPanel, "Display", true); |
|---|
| 119 | + leftPanel.add(configPanel, "Display"); //, true); |
|---|
| 145 | 120 | |
|---|
| 146 | | - leftPanel.addTab(filterControlPanel, "Filter", true); |
|---|
| 121 | + leftPanel.add(filterControlPanel, "Filter"); //, true); |
|---|
| 147 | 122 | |
|---|
| 148 | 123 | // center tab area |
|---|
| 149 | 124 | |
|---|
| 150 | 125 | final LinkTabPane center = new LinkTabPane(); |
|---|
| 151 | | - getContentPane().add(center, BorderLayout.CENTER); |
|---|
| 126 | + container.add(center, BorderLayout.CENTER); |
|---|
| 152 | 127 | |
|---|
| 153 | 128 | center.addPropertyChangeListener(new PropertyChangeListener() |
|---|
| 154 | 129 | { |
|---|
| 155 | | - |
|---|
| 156 | 130 | @Override |
|---|
| 157 | 131 | public void propertyChange(PropertyChangeEvent evt) |
|---|
| 158 | 132 | { |
|---|
| .. | .. |
|---|
| 165 | 139 | AbstractView[] views = |
|---|
| 166 | 140 | { |
|---|
| 167 | 141 | timeline, |
|---|
| 168 | | - new CalendarView(model), |
|---|
| 142 | + //new CalendarView(model), |
|---|
| 169 | 143 | new ListView(model), |
|---|
| 170 | 144 | new TableView(model), |
|---|
| 171 | 145 | new BarGraphView(model), |
|---|
| 172 | | - intro, |
|---|
| 173 | | - new DescriptionView(model), |
|---|
| 146 | + //intro, |
|---|
| 174 | 147 | new SummaryView(model), |
|---|
| 148 | + new DescriptionView(model), |
|---|
| 175 | 149 | }; |
|---|
| 176 | 150 | |
|---|
| 177 | 151 | for (int i = 0; i < views.length; i++) |
|---|
| 178 | 152 | { |
|---|
| 179 | | - center.addTab(views[i], views[i].getName(), i < 5); |
|---|
| 153 | + center.addTab(views[i], views[i].getName(), true); // i < 5); |
|---|
| 180 | 154 | displayPanel.addLocalControl(views[i].getName(), views[i].getControls()); |
|---|
| 181 | 155 | } |
|---|
| 182 | 156 | |
|---|
| .. | .. |
|---|
| 187 | 161 | // but then, once data is loaded, switch directly to the timeline view. |
|---|
| 188 | 162 | model.addListener(new TFListener() |
|---|
| 189 | 163 | { |
|---|
| 190 | | - |
|---|
| 191 | 164 | @Override |
|---|
| 192 | 165 | public void note(TFEvent e) |
|---|
| 193 | 166 | { |
|---|
| .. | .. |
|---|
| 203 | 176 | }); |
|---|
| 204 | 177 | |
|---|
| 205 | 178 | JMenuBar menubar = new JMenuBar(); |
|---|
| 206 | | - setJMenuBar(menubar); |
|---|
| 179 | + |
|---|
| 180 | + // frame.setJMenuBar(menubar); |
|---|
| 207 | 181 | |
|---|
| 208 | 182 | JMenu fileMenu = new JMenu("File"); |
|---|
| 209 | 183 | menubar.add(fileMenu); |
|---|
| 210 | 184 | |
|---|
| 211 | | - fileMenu.add(new NewDataAction(this)); |
|---|
| 185 | + TimeflowAction tlAction = new NewDataAction(this); |
|---|
| 186 | + fileMenu.add(tlAction); |
|---|
| 187 | + tlAction.actionPerformed(null); |
|---|
| 212 | 188 | fileMenu.add(new CopySchemaAction(this)); |
|---|
| 213 | 189 | |
|---|
| 214 | 190 | JMenu templateMenu = new JMenu("New From Template"); |
|---|
| .. | .. |
|---|
| 231 | 207 | |
|---|
| 232 | 208 | fileMenu.addSeparator(); |
|---|
| 233 | 209 | |
|---|
| 234 | | - |
|---|
| 235 | 210 | JMenuItem open = new JMenuItem("Open..."); |
|---|
| 236 | 211 | fileMenu.add(open); |
|---|
| 237 | 212 | open.addActionListener(new ActionListener() |
|---|
| 238 | 213 | { |
|---|
| 239 | | - |
|---|
| 240 | 214 | @Override |
|---|
| 241 | 215 | public void actionPerformed(ActionEvent e) |
|---|
| 242 | 216 | { |
|---|
| .. | .. |
|---|
| 254 | 228 | fileMenu.add(impDel); |
|---|
| 255 | 229 | impDel.addActionListener(new ActionListener() |
|---|
| 256 | 230 | { |
|---|
| 257 | | - |
|---|
| 258 | 231 | @Override |
|---|
| 259 | 232 | public void actionPerformed(ActionEvent e) |
|---|
| 260 | 233 | { |
|---|
| .. | .. |
|---|
| 273 | 246 | save.setEnabled(false); |
|---|
| 274 | 247 | save.addActionListener(new ActionListener() |
|---|
| 275 | 248 | { |
|---|
| 276 | | - |
|---|
| 277 | 249 | @Override |
|---|
| 278 | 250 | public void actionPerformed(ActionEvent e) |
|---|
| 279 | 251 | { |
|---|
| .. | .. |
|---|
| 283 | 255 | }); |
|---|
| 284 | 256 | model.addListener(new TFListener() |
|---|
| 285 | 257 | { |
|---|
| 286 | | - |
|---|
| 287 | 258 | @Override |
|---|
| 288 | 259 | public void note(TFEvent e) |
|---|
| 289 | 260 | { |
|---|
| .. | .. |
|---|
| 295 | 266 | fileMenu.add(saveAs); |
|---|
| 296 | 267 | saveAs.addActionListener(new ActionListener() |
|---|
| 297 | 268 | { |
|---|
| 298 | | - |
|---|
| 299 | 269 | @Override |
|---|
| 300 | 270 | public void actionPerformed(ActionEvent e) |
|---|
| 301 | 271 | { |
|---|
| .. | .. |
|---|
| 309 | 279 | fileMenu.add(exportTSV); |
|---|
| 310 | 280 | exportTSV.addActionListener(new ActionListener() |
|---|
| 311 | 281 | { |
|---|
| 312 | | - |
|---|
| 313 | 282 | @Override |
|---|
| 314 | 283 | public void actionPerformed(ActionEvent e) |
|---|
| 315 | 284 | { |
|---|
| .. | .. |
|---|
| 320 | 289 | fileMenu.add(exportCSV); |
|---|
| 321 | 290 | exportCSV.addActionListener(new ActionListener() |
|---|
| 322 | 291 | { |
|---|
| 323 | | - |
|---|
| 324 | 292 | @Override |
|---|
| 325 | 293 | public void actionPerformed(ActionEvent e) |
|---|
| 326 | 294 | { |
|---|
| .. | .. |
|---|
| 331 | 299 | fileMenu.add(exportHTML); |
|---|
| 332 | 300 | exportHTML.addActionListener(new ActionListener() |
|---|
| 333 | 301 | { |
|---|
| 334 | | - |
|---|
| 335 | 302 | @Override |
|---|
| 336 | 303 | public void actionPerformed(ActionEvent e) |
|---|
| 337 | 304 | { |
|---|
| 338 | 305 | exportHtml(); |
|---|
| 339 | 306 | } |
|---|
| 340 | 307 | }); |
|---|
| 341 | | - fileMenu.addSeparator(); |
|---|
| 342 | | - fileMenu.add(quitAction); |
|---|
| 308 | +// fileMenu.addSeparator(); |
|---|
| 309 | +// fileMenu.add(quitAction); |
|---|
| 343 | 310 | |
|---|
| 344 | 311 | JMenu editMenu = new JMenu("Edit"); |
|---|
| 345 | 312 | menubar.add(editMenu); |
|---|
| .. | .. |
|---|
| 370 | 337 | final String file = examples[i][1]; |
|---|
| 371 | 338 | example.addActionListener(new ActionListener() |
|---|
| 372 | 339 | { |
|---|
| 373 | | - |
|---|
| 374 | 340 | @Override |
|---|
| 375 | 341 | public void actionPerformed(ActionEvent e) |
|---|
| 376 | 342 | { |
|---|
| .. | .. |
|---|
| 380 | 346 | } |
|---|
| 381 | 347 | |
|---|
| 382 | 348 | JMenu helpMenu = new JMenu("Help"); |
|---|
| 383 | | - menubar.add(helpMenu); |
|---|
| 349 | + //menubar.add(helpMenu); |
|---|
| 384 | 350 | |
|---|
| 385 | 351 | helpMenu.add(new WebDocAction(this)); |
|---|
| 386 | 352 | |
|---|
| .. | .. |
|---|
| 388 | 354 | helpMenu.add(about); |
|---|
| 389 | 355 | about.addActionListener(new ActionListener() |
|---|
| 390 | 356 | { |
|---|
| 391 | | - |
|---|
| 392 | 357 | @Override |
|---|
| 393 | 358 | public void actionPerformed(ActionEvent e) |
|---|
| 394 | 359 | { |
|---|
| .. | .. |
|---|
| 398 | 363 | |
|---|
| 399 | 364 | model.addListener(new TFListener() |
|---|
| 400 | 365 | { |
|---|
| 401 | | - |
|---|
| 402 | 366 | @Override |
|---|
| 403 | 367 | public void note(TFEvent e) |
|---|
| 404 | 368 | { |
|---|
| .. | .. |
|---|
| 414 | 378 | } |
|---|
| 415 | 379 | } |
|---|
| 416 | 380 | }); |
|---|
| 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); |
|---|
| 417 | 416 | } |
|---|
| 418 | 417 | |
|---|
| 419 | 418 | void makeRecentFileMenu() |
|---|
| .. | .. |
|---|
| 556 | 555 | } |
|---|
| 557 | 556 | try |
|---|
| 558 | 557 | { |
|---|
| 559 | | - final File f = new File(fileName); |
|---|
| 558 | + final File f = new File(TimeflowApp.class.getClassLoader().getResource(fileName).toURI()); |
|---|
| 560 | 559 | ActDB db = importer.importFile(f); |
|---|
| 561 | 560 | model.setDB(db, fileName, readOnly, TimeflowApp.this); |
|---|
| 562 | 561 | if (!readOnly) |
|---|
| .. | .. |
|---|
| 695 | 694 | |
|---|
| 696 | 695 | static String[] getVisibleFiles(String dir) |
|---|
| 697 | 696 | { |
|---|
| 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 |
|---|
| 701 | 699 | { |
|---|
| 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++) |
|---|
| 703 | 705 | { |
|---|
| 704 | | - real.add(s[i]); |
|---|
| 706 | + if (!s[i].startsWith(".")) |
|---|
| 707 | + { |
|---|
| 708 | + real.add(s[i]); |
|---|
| 709 | + } |
|---|
| 705 | 710 | } |
|---|
| 711 | + return (String[]) real.toArray(new String[0]); |
|---|
| 706 | 712 | } |
|---|
| 707 | | - return (String[]) real.toArray(new String[0]); |
|---|
| 713 | + catch (Exception e) |
|---|
| 714 | + { |
|---|
| 715 | + e.printStackTrace(); |
|---|
| 716 | + return new String[0]; |
|---|
| 717 | + } |
|---|
| 708 | 718 | } |
|---|
| 709 | 719 | } |
|---|