Debian Codegraph @

src/dr/app/mapper/application/MapperFrameOld.java

raw symbols SCIP
1 /*
2 * MapperFrameOld.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.mapper.application;
27
28 import com.lowagie.text.Document;
29 import com.lowagie.text.DocumentException;
30 import com.lowagie.text.pdf.DefaultFontMapper;
31 import com.lowagie.text.pdf.PdfContentByte;
32 import com.lowagie.text.pdf.PdfTemplate;
33 import com.lowagie.text.pdf.PdfWriter;
34 import dr.app.gui.FileDrop;
35 import dr.app.gui.table.TableEditorStopper;
36 import dr.app.gui.util.LongTask;
37 import dr.app.mapper.application.mapper.Layer;
38 import dr.app.mapper.application.mapper.MapperPanel;
39 import dr.inference.trace.*;
40 import jam.framework.DocumentFrame;
41 import jam.panels.ActionPanel;
42 import jam.table.TableRenderer;
43
44 import javax.swing.*;
45 import javax.swing.border.Border;
46 import javax.swing.event.ListSelectionEvent;
47 import javax.swing.event.ListSelectionListener;
48 import javax.swing.filechooser.FileNameExtensionFilter;
49 import javax.swing.plaf.BorderUIResource;
50 import javax.swing.table.AbstractTableModel;
51 import javax.swing.table.JTableHeader;
52 import java.awt.*;
53 import java.awt.event.*;
54 import java.awt.geom.Rectangle2D;
55 import java.io.*;
56 import java.util.ArrayList;
57 import java.util.List;
58
59 /**
60 * @author Andrew Rambaut
61 * @version $Id$
62 */
63 public class MapperFrameOld extends DocumentFrame {
64 private final String[] columnToolTips = {"", "", ""};
65
66 private MapperPanel mapperPanel = null;
67
68 private JTable traceTable = null;
69 private TraceTableModel traceTableModel = null;
70 private JSplitPane splitPane1 = null;
71 private JPanel topPanel = null;
72
73 private JTable layerTable = null;
74 private LayerTableModel layerTableModel = null;
75
76
77 private JScrollPane scrollPane1;
78
79 private JLabel progressLabel;
80 private JProgressBar progressBar;
81
82 private final List<LogFileTraces> traceLists = new ArrayList<LogFileTraces>();
83 private final List<Layer> layers = new ArrayList<Layer>();
84
85 String message = "";
86 private int dividerLocation = -1;
87
88 public MapperFrameOld(String title) {
89 super();
90
91 setTitle(title);
92
93 getOpenAction().setEnabled(false);
94 getSaveAction().setEnabled(false);
95 getSaveAsAction().setEnabled(false);
96
97 getCutAction().setEnabled(false);
98 getCopyAction().setEnabled(false);
99 getPasteAction().setEnabled(false);
100 getDeleteAction().setEnabled(false);
101 getSelectAllAction().setEnabled(false);
102 getFindAction().setEnabled(false);
103
104 getZoomWindowAction().setEnabled(false);
105
106 AbstractAction importAction = new AbstractAction("Import Trace File...") {
107 public void actionPerformed(ActionEvent ae) {
108 doImport();
109 }
110 };
111 setImportAction(importAction);
112 setExportAction(exportDataAction);
113
114 setAnalysesEnabled(false);
115 }
116
117 public void initializeComponents() {
118
119 setSize(new java.awt.Dimension(1200, 800));
120
121 mapperPanel = new MapperPanel(this);
122 mapperPanel.setBorder(new BorderUIResource.EmptyBorderUIResource(new java.awt.Insets(12, 6, 12, 12)));
123
124 traceTableModel = new TraceTableModel();
125 traceTable = new JTable(traceTableModel);
126 TableRenderer renderer = new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4));
127 traceTable.getColumnModel().getColumn(0).setCellRenderer(renderer);
128 traceTable.getColumnModel().getColumn(1).setPreferredWidth(50);
129 traceTable.getColumnModel().getColumn(1).setCellRenderer(renderer);
130 traceTable.getColumnModel().getColumn(2).setPreferredWidth(50);
131 traceTable.getColumnModel().getColumn(2).setCellRenderer(renderer);
132 traceTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
133
134 traceTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
135 public void valueChanged(ListSelectionEvent evt) {
136 traceTableSelectionChanged();
137 }
138 });
139
140 scrollPane1 = new JScrollPane(traceTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
141 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
142
143 ActionPanel actionPanel1 = new ActionPanel(false);
144 actionPanel1.setAddAction(getImportAction());
145 actionPanel1.setRemoveAction(getRemoveTraceAction());
146 getRemoveTraceAction().setEnabled(false);
147
148 JPanel controlPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
149 controlPanel1.add(actionPanel1);
150
151 topPanel = new JPanel(new BorderLayout(0, 0));
152 topPanel.setBorder(new BorderUIResource.EmptyBorderUIResource(new java.awt.Insets(0, 0, 6, 0)));
153 topPanel.add(new JLabel("Trace Files:"), BorderLayout.NORTH);
154 topPanel.add(scrollPane1, BorderLayout.CENTER);
155 topPanel.add(controlPanel1, BorderLayout.SOUTH);
156
157 layerTableModel = new LayerTableModel();
158 layerTable = new JTable(layerTableModel) {
159 //Implement table header tool tips.
160 protected JTableHeader createDefaultTableHeader() {
161 return new JTableHeader(columnModel) {
162 public String getToolTipText(MouseEvent e) {
163 java.awt.Point p = e.getPoint();
164 int index = columnModel.getColumnIndexAtX(p.x);
165 int realIndex = columnModel.getColumn(index).getModelIndex();
166 return columnToolTips[realIndex];
167 }
168 };
169 }
170 };
171 layerTable.getColumnModel().getColumn(0).setPreferredWidth(150);
172 layerTable.getColumnModel().getColumn(0).setCellRenderer(renderer);
173 layerTable.getColumnModel().getColumn(1).setPreferredWidth(70);
174 layerTable.getColumnModel().getColumn(1).setCellRenderer(renderer);
175 // layerTable.getColumnModel().getColumn(2).setPreferredWidth(70);
176 // layerTable.getColumnModel().getColumn(2).setCellRenderer(renderer);
177 // ComboBoxRenderer comboBoxRenderer = new ComboBoxRenderer(TraceFactory.TraceType.values());
178 // comboBoxRenderer.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
179 // layerTable.getColumnModel().getColumn(3).setPreferredWidth(20);
180 // layerTable.getColumnModel().getColumn(3).setCellRenderer(renderer);
181 layerTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
182
183 layerTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
184 public void valueChanged(ListSelectionEvent evt) {
185 layerTableSelectionChanged();
186 }
187 });
188
189 TableEditorStopper.ensureEditingStopWhenTableLosesFocus(layerTable);
190
191 JScrollPane scrollPane2 = new JScrollPane(layerTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
192 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
193
194 JPanel bottomPanel = new JPanel(new BorderLayout(0, 0));
195 bottomPanel.add(new JLabel("Layers:"), BorderLayout.NORTH);
196 bottomPanel.add(scrollPane2, BorderLayout.CENTER);
197
198 JPanel leftPanel = new JPanel(new BorderLayout(0, 0));
199 leftPanel.setPreferredSize(new Dimension(400, 300));
200 splitPane1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, topPanel, bottomPanel);
201 splitPane1.setBorder(null);
202
203 JPanel progressPanel = new JPanel(new BorderLayout(0, 0));
204 progressLabel = new JLabel("");
205 progressBar = new JProgressBar();
206 progressPanel.add(progressLabel, BorderLayout.NORTH);
207 progressPanel.add(progressBar, BorderLayout.CENTER);
208 progressPanel.setBorder(new BorderUIResource.EmptyBorderUIResource(new java.awt.Insets(6, 0, 0, 0)));
209
210 leftPanel.add(splitPane1, BorderLayout.CENTER);
211 leftPanel.add(progressPanel, BorderLayout.SOUTH);
212 leftPanel.setBorder(new BorderUIResource.EmptyBorderUIResource(new java.awt.Insets(12, 12, 12, 6)));
213
214 JSplitPane splitPane2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, leftPanel, mapperPanel);
215 splitPane2.setBorder(null);
216 splitPane2.setDividerLocation(350);
217
218 Color focusColor = UIManager.getColor("Focus.color");
219 Border focusBorder = BorderFactory.createMatteBorder(2, 2, 2, 2, focusColor);
220 splitPane1.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
221 new FileDrop(null, splitPane1, focusBorder, new FileDrop.Listener() {
222 public void filesDropped(java.io.File[] files) {
223 importFiles(files);
224 } // end filesDropped
225 }); // end FileDrop.Listener
226
227 getContentPane().setLayout(new java.awt.BorderLayout(0, 0));
228 getContentPane().add(splitPane2, BorderLayout.CENTER);
229
230 splitPane1.setDividerLocation(2000);
231
232 }
233
234 public void setVisible(boolean b) {
235 super.setVisible(b);
236 setupDividerLocation();
237 }
238
239 private void setupDividerLocation() {
240
241 if (dividerLocation == -1 || dividerLocation == splitPane1.getDividerLocation()) {
242 int h0 = topPanel.getHeight();
243 int h1 = scrollPane1.getViewport().getHeight();
244 int h2 = traceTable.getPreferredSize().height;
245 dividerLocation = h2 + h0 - h1;
246
247 // int h0 = topPanel.getHeight() - scrollPane1.getViewport().getHeight();
248 // dividerLocation = traceTable.getPreferredSize().height + h0;
249
250 if (dividerLocation > 400) dividerLocation = 400;
251 splitPane1.setDividerLocation(dividerLocation);
252 }
253 }
254
255 public void setAnalysesEnabled(boolean enabled) {
256 getExportAction().setEnabled(enabled);
257 getExportDataAction().setEnabled(enabled);
258 getExportPDFAction().setEnabled(enabled);
259 getCopyAction().setEnabled(true);
260 }
261
262 public void addTraceList(LogFileTraces traceList) {
263
264 int[] selRows = traceTable.getSelectedRows();
265
266 traceLists.add(traceList);
267
268 setAnalysesEnabled(true);
269
270 traceTableModel.fireTableDataChanged();
271
272 int newRow = traceLists.size() - 1;
273 traceTable.getSelectionModel().setSelectionInterval(newRow, newRow);
274 if (selRows.length > 1) {
275 for (int row : selRows) {
276 if (row == traceLists.size() - 1) {
277 row = traceLists.size();
278 }
279 traceTable.getSelectionModel().addSelectionInterval(row, row);
280 }
281 }
282
283 setupDividerLocation();
284 }
285
286 private void removeTraceList() {
287 int[] selRows = traceTable.getSelectedRows();
288
289 LogFileTraces[] tls = new LogFileTraces[selRows.length];
290 int i = 0;
291 for (int row : selRows) {
292 tls[i] = traceLists.get(row);
293 i++;
294 }
295 for (LogFileTraces tl : tls) {
296 traceLists.remove(tl);
297 }
298
299 traceTableModel.fireTableDataChanged();
300 layerTableModel.fireTableDataChanged();
301
302 if (traceLists.size() == 0) {
303 getRemoveTraceAction().setEnabled(false);
304
305 setAnalysesEnabled(false);
306
307 layerTableModel.fireTableDataChanged();
308 }
309
310
311 if (traceLists.size() > 0) {
312 int row = selRows[0];
313 if (row >= traceLists.size()) {
314 row = traceLists.size() - 1;
315 }
316 traceTable.getSelectionModel().addSelectionInterval(row, row);
317 }
318 setupDividerLocation();
319 }
320
321 public void setBurnIn(int index, int burnIn) {
322 LogFileTraces trace = traceLists.get(index);
323 trace.setBurnIn(burnIn);
324 analyseTraceList(trace);
325 updateTraceTables();
326 }
327
328 public void updateTraceTables() {
329 int[] selectedTraces = traceTable.getSelectedRows();
330 int[] selectedStatistics = layerTable.getSelectedRows();
331
332 traceTableModel.fireTableDataChanged();
333 layerTableModel.fireTableDataChanged();
334
335 traceTable.getSelectionModel().clearSelection();
336 for (int row : selectedTraces) {
337 traceTable.getSelectionModel().addSelectionInterval(row, row);
338 }
339
340 layerTable.getSelectionModel().clearSelection();
341 for (int row : selectedStatistics) {
342 layerTable.getSelectionModel().addSelectionInterval(row, row);
343 }
344 }
345
346 public void traceTableSelectionChanged() {
347 int[] selRows = traceTable.getSelectedRows();
348
349 if (selRows.length == 0) {
350 getRemoveTraceAction().setEnabled(false);
351 setAnalysesEnabled(false);
352 return;
353 }
354
355 setAnalysesEnabled(true);
356
357 getRemoveTraceAction().setEnabled(true);
358
359 int[] rows = layerTable.getSelectedRows();
360 layerTableModel.fireTableDataChanged();
361
362 if (rows.length > 0) {
363 for (int row : rows) {
364 layerTable.getSelectionModel().addSelectionInterval(row, row);
365 }
366 } else {
367 layerTable.getSelectionModel().setSelectionInterval(0, 0);
368 }
369 }
370
371
372 public void layerTableSelectionChanged() {
373
374 }
375
376 public void analyseTraceList(TraceList job) {
377
378 if (analyseTask == null) {
379 analyseTask = new AnalyseTraceTask();
380
381 javax.swing.Timer timer = new javax.swing.Timer(1000, new ActionListener() {
382 public void actionPerformed(ActionEvent evt) {
383 progressBar.setMaximum(analyseTask.getLengthOfTask());
384 progressBar.setValue(analyseTask.getCurrent());
385 }
386 });
387
388 analyseTask.go();
389 timer.start();
390 }
391
392 analyseTask.add(job);
393 }
394
395 AnalyseTraceTask analyseTask = null;
396
397 class AnalyseTraceTask extends LongTask {
398
399 class AnalysisStack<T> {
400 private final java.util.List<T> jobs = new ArrayList<T>();
401
402 public synchronized void add(T job) {
403 jobs.add(job);
404 }
405
406 public synchronized int getCount() {
407 return jobs.size();
408 }
409
410 public synchronized T get(int index) {
411 return jobs.get(index);
412 }
413
414 public synchronized void remove(int index) {
415 jobs.remove(index);
416 }
417 }
418
419 private final AnalysisStack<TraceList> analysisStack = new AnalysisStack<TraceList>();
420
421 public AnalyseTraceTask() {
422 }
423
424 public void add(TraceList job) {
425 analysisStack.add(job);
426 current = 0;
427 }
428
429 public int getCurrent() {
430 return current;
431 }
432
433 public int getLengthOfTask() {
434 int count = 0;
435 for (int i = 0; i < analysisStack.getCount(); i++) {
436 count += analysisStack.get(i).getTraceCount();
437 }
438 return count;
439 }
440
441 public void stop() {
442 }
443
444 public boolean done() {
445 return false;
446 }
447
448 public String getDescription() {
449 return "Analysing Trace File...";
450 }
451
452 public String getMessage() {
453 return null;
454 }
455
456 public Object doWork() {
457
458 current = 0;
459 boolean textCleared = true;
460
461 do {
462 if (analysisStack.getCount() > 0) {
463 Object job = analysisStack.get(0);
464 TraceList tl = (TraceList) job;
465
466 try {
467 for (int i = 0; i < tl.getTraceCount(); i++) {
468 progressLabel.setText("Analysing " + tl.getName() + ":");
469 textCleared = false;
470 tl.analyseTrace(i);
471 repaint();
472 current += 1;
473 }
474 } catch (final Exception ex) {
475 // do nothing. An exception is sometimes fired when burnin is changed whilst in the
476 // middle of an analysis. This doesn't seem to matter as the analysis is restarted.
477
478 ex.printStackTrace();
479 // EventQueue.invokeLater (
480 // new Runnable () {
481 // public void run () {
482 // JOptionPane.showMessageDialog(TracerFrame.this, "Fatal exception: " + ex.getMessage(),
483 // "Error reading file",
484 // JOptionPane.ERROR_MESSAGE);
485 // }
486 // });
487 }
488 analysisStack.remove(0);
489 } else {
490 if (!textCleared) {
491 progressLabel.setText("");
492 textCleared = true;
493 }
494 try {
495 Thread.sleep(500);
496 } catch (InterruptedException ie) {
497 // do nothing
498 }
499 }
500 } while (true);
501 }
502
503 //private int lengthOfTask = 0;
504 private int current = 0;
505 //private String message;
506 }
507
508 public final void doExportData() {
509
510 FileDialog dialog = new FileDialog(this,
511 "Export Data...",
512 FileDialog.SAVE);
513
514 dialog.setVisible(true);
515 if (dialog.getFile() != null) {
516 File file = new File(dialog.getDirectory(), dialog.getFile());
517
518 try {
519 FileWriter writer = new FileWriter(file);
520 writer.write(mapperPanel.getExportText());
521 writer.close();
522
523
524 } catch (IOException ioe) {
525 JOptionPane.showMessageDialog(this, "Unable to write file: " + ioe,
526 "Unable to write file",
527 JOptionPane.ERROR_MESSAGE);
528 }
529 }
530
531 }
532
533 public final void doExportPDF() {
534 FileDialog dialog = new FileDialog(this,
535 "Export PDF Image...",
536 FileDialog.SAVE);
537
538 dialog.setVisible(true);
539 if (dialog.getFile() != null) {
540 File file = new File(dialog.getDirectory(), dialog.getFile());
541
542 Rectangle2D bounds = mapperPanel.getExportableComponent().getBounds();
543 Document document = new Document(new com.lowagie.text.Rectangle((float) bounds.getWidth(), (float) bounds.getHeight()));
544 try {
545 // step 2
546 PdfWriter writer;
547 writer = PdfWriter.getInstance(document, new FileOutputStream(file));
548 // step 3
549 document.open();
550 // step 4
551 PdfContentByte cb = writer.getDirectContent();
552 PdfTemplate tp = cb.createTemplate((float) bounds.getWidth(), (float) bounds.getHeight());
553 Graphics2D g2d = tp.createGraphics((float) bounds.getWidth(), (float) bounds.getHeight(), new DefaultFontMapper());
554 mapperPanel.getExportableComponent().print(g2d);
555 g2d.dispose();
556 cb.addTemplate(tp, 0, 0);
557 }
558 catch (DocumentException de) {
559 JOptionPane.showMessageDialog(this, "Error writing PDF file: " + de,
560 "Export PDF Error",
561 JOptionPane.ERROR_MESSAGE);
562 }
563 catch (FileNotFoundException e) {
564 JOptionPane.showMessageDialog(this, "Error writing PDF file: " + e,
565 "Export PDF Error",
566 JOptionPane.ERROR_MESSAGE);
567 }
568 document.close();
569 }
570 }
571
572
573 public final void doImport() {
574 final JFileChooser chooser = new JFileChooser(openDefaultDirectory);
575 chooser.setMultiSelectionEnabled(true);
576
577 FileNameExtensionFilter filter = new FileNameExtensionFilter("BEAST log (*.log) Files", "log", "txt");
578 chooser.setFileFilter(filter);
579
580 final int returnVal = chooser.showOpenDialog(this);
581 if (returnVal == JFileChooser.APPROVE_OPTION) {
582 File[] files = chooser.getSelectedFiles();
583 importFiles(files);
584 }
585 }
586
587 private void importFiles(File[] files) {
588 LogFileTraces[] traces = new LogFileTraces[files.length];
589
590 for (int i = 0; i < files.length; i++) {
591 traces[i] = new LogFileTraces(files[i].getName(), files[i]);
592 }
593
594 processTraces(traces);
595 }
596
597 private File openDefaultDirectory = null;
598
599 private void setDefaultDir(File file) {
600 final String s = file.getAbsolutePath();
601 String p = s.substring(0, s.length() - file.getName().length());
602 openDefaultDirectory = new File(p);
603 if (!openDefaultDirectory.isDirectory()) {
604 openDefaultDirectory = null;
605 }
606 }
607
608 protected void processTraces(final LogFileTraces[] tracesArray) {
609
610 final JFrame frame = this;
611
612 // set default dir to directory of last file
613 setDefaultDir(tracesArray[tracesArray.length - 1].getFile());
614
615 if (tracesArray.length == 1) {
616 try {
617 final LogFileTraces traces = tracesArray[0];
618
619 final String fileName = traces.getName();
620 final ProgressMonitorInputStream in = new ProgressMonitorInputStream(
621 this,
622 "Reading " + fileName,
623 new FileInputStream(traces.getFile()));
624 in.getProgressMonitor().setMillisToDecideToPopup(0);
625 in.getProgressMonitor().setMillisToPopup(0);
626
627 // final Reader reader = new InputStreamReader(in);
628
629 Thread readThread = new Thread() {
630 public void run() {
631 try {
632 traces.loadTraces(in);
633
634 EventQueue.invokeLater(
635 new Runnable() {
636 public void run() {
637 analyseTraceList(traces);
638 addTraceList(traces);
639 }
640 });
641
642 } catch (final TraceException te) {
643 EventQueue.invokeLater(
644 new Runnable() {
645 public void run() {
646 JOptionPane.showMessageDialog(frame, "Problem with trace file: " + te.getMessage(),
647 "Problem with tree file",
648 JOptionPane.ERROR_MESSAGE);
649 }
650 });
651 } catch (final InterruptedIOException iioex) {
652 // The cancel dialog button was pressed - do nothing
653 } catch (final IOException ioex) {
654 EventQueue.invokeLater(
655 new Runnable() {
656 public void run() {
657 JOptionPane.showMessageDialog(frame, "File I/O Error: " + ioex.getMessage(),
658 "File I/O Error",
659 JOptionPane.ERROR_MESSAGE);
660 }
661 });
662 // } catch (final Exception ex) {
663 // EventQueue.invokeLater (
664 // new Runnable () {
665 // public void run () {
666 // JOptionPane.showMessageDialog(frame, "Fatal exception: " + ex.getMessage(),
667 // "Error reading file",
668 // JOptionPane.ERROR_MESSAGE);
669 // }
670 // });
671 }
672
673 }
674 };
675 readThread.start();
676
677 } catch (FileNotFoundException fnfe) {
678 JOptionPane.showMessageDialog(this, "Unable to open file: File not found",
679 "Unable to open file",
680 JOptionPane.ERROR_MESSAGE);
681 } catch (IOException ioex) {
682 JOptionPane.showMessageDialog(this, "File I/O Error: " + ioex,
683 "File I/O Error",
684 JOptionPane.ERROR_MESSAGE);
685 } catch (Exception ex) {
686 JOptionPane.showMessageDialog(this, "Fatal exception: " + ex,
687 "Error reading file",
688 JOptionPane.ERROR_MESSAGE);
689 }
690
691 } else {
692 Thread readThread = new Thread() {
693 public void run() {
694 try {
695 for (final LogFileTraces traces : tracesArray) {
696 // final Reader reader = new FileReader(traces.getFile());
697 traces.loadTraces();
698
699 EventQueue.invokeLater(
700 new Runnable() {
701 public void run() {
702 analyseTraceList(traces);
703 addTraceList(traces);
704 }
705 });
706 }
707
708 } catch (final TraceException te) {
709 EventQueue.invokeLater(
710 new Runnable() {
711 public void run() {
712 JOptionPane.showMessageDialog(frame, "Problem with trace file: " + te.getMessage(),
713 "Problem with tree file",
714 JOptionPane.ERROR_MESSAGE);
715 }
716 });
717 } catch (final InterruptedIOException iioex) {
718 // The cancel dialog button was pressed - do nothing
719 } catch (final IOException ioex) {
720 EventQueue.invokeLater(
721 new Runnable() {
722 public void run() {
723 JOptionPane.showMessageDialog(frame, "File I/O Error: " + ioex.getMessage(),
724 "File I/O Error",
725 JOptionPane.ERROR_MESSAGE);
726 }
727 });
728 // } catch (final Exception ex) {
729 // EventQueue.invokeLater (
730 // new Runnable () {
731 // public void run () {
732 // JOptionPane.showMessageDialog(frame, "Fatal exception: " + ex.getMessage(),
733 // "Error reading file",
734 // JOptionPane.ERROR_MESSAGE);
735 // }
736 // });
737 }
738
739 }
740 };
741 readThread.start();
742
743 }
744 }
745
746 protected boolean readFromFile(File file) throws IOException {
747 throw new RuntimeException("Cannot read file - use import instead");
748 }
749
750 protected boolean writeToFile(File file) {
751 throw new RuntimeException("Cannot write file - this is a read-only application");
752 }
753
754 public void doCopy() {
755 mapperPanel.doCopy();
756 }
757
758
759 public JComponent getExportableComponent() {
760 return mapperPanel.getExportableComponent();
761 }
762
763 class TraceTableModel extends AbstractTableModel {
764 final String[] columnNames = {"Trace File", "States", "Burn-In"};
765
766 public int getColumnCount() {
767 return columnNames.length;
768 }
769
770 public int getRowCount() {
771 int n = traceLists.size();
772 if (n == 0) n++;
773 return n;
774 }
775
776 public String getColumnName(int col) {
777 return columnNames[col];
778 }
779
780 public Object getValueAt(int row, int col) {
781 TraceList traceList;
782
783 if (traceLists.size() == 0) {
784 switch (col) {
785 case 0:
786 return "No files loaded";
787 case 1:
788 return "";
789 case 2:
790 return "";
791 }
792 } else {
793 traceList = traceLists.get(row);
794 switch (col) {
795 case 0:
796 return traceList.getName();
797 case 1:
798 return traceList.getMaxState();
799 case 2:
800 return traceList.getBurnIn();
801 }
802 }
803
804 return null;
805 }
806
807 public void setValueAt(Object value, int row, int col) {
808 if (col == 2) {
809 setBurnIn(row, (Integer) value);
810 }
811 }
812
813 public Class getColumnClass(int c) {
814 return getValueAt(0, c).getClass();
815 }
816
817 public boolean isCellEditable(int row, int col) {
818 return col == 2 && row < traceLists.size();
819 }
820 }
821
822 class LayerTableModel extends AbstractTableModel {
823 final String[] columnNames = {"Layer", "Type"};
824
825 public int getColumnCount() {
826 return columnNames.length;
827 }
828
829 public int getRowCount() {
830 return layers.size();
831 }
832
833 public String getColumnName(int col) {
834 return columnNames[col];
835 }
836
837 public Object getValueAt(int row, int col) {
838 Layer layer = layers.get(row);
839
840 if (col == 0) return layer.getName();
841 if (col == 1) return layer.getType().toString();
842
843 return "";
844 }
845
846 public boolean isCellEditable(int row, int col) {
847 return true;
848
849 }
850
851 public Class getColumnClass(int c) {
852 if (getRowCount() == 0) {
853 return Object.class;
854 }
855 return getValueAt(0, c).getClass();
856 }
857 }
858
859 public Action getExportDataAction() {
860 return exportDataAction;
861 }
862
863 public Action getExportPDFAction() {
864 return exportPDFAction;
865 }
866
867
868 public Action getRemoveTraceAction() {
869 return removeTraceAction;
870 }
871
872 private final AbstractAction removeTraceAction = new AbstractAction() {
873 public void actionPerformed(ActionEvent ae) {
874 removeTraceList();
875 }
876 };
877
878 private final AbstractAction exportDataAction = new AbstractAction("Export Data...") {
879 public void actionPerformed(ActionEvent ae) {
880 doExportData();
881 }
882 };
883
884 private final AbstractAction exportPDFAction = new AbstractAction("Export PDF...") {
885 public void actionPerformed(ActionEvent ae) {
886 doExportPDF();
887 }
888 };
889
890 }