1 package org.catacomb.dataview.gui;
2
3 import java.io.File;
4
5 import org.catacomb.dataview.formats.DataHandler;
6 import org.catacomb.dataview.formats.DataHandlerFactory;
7 import org.catacomb.dataview.formats.MeshSummary;
8 import org.catacomb.druid.dialog.Dialoguer;
9 import org.catacomb.druid.gui.edit.DruMenu;
10 import org.catacomb.interlish.annotation.ControlPoint;
11 import org.catacomb.interlish.annotation.IOPoint;
12 import org.catacomb.interlish.structure.Controller;
13 import org.catacomb.report.E;
14 import org.catacomb.util.FileUtil;
15
16
17 public class CCVizController implements Controller {
18
19
20 @IOPoint(xid="ViewMenu")
21 public DruMenu viewMenu;
22
23 @ControlPoint(xid="basicController")
24 public BasicPlotController basicController;
25
26 @ControlPoint(xid="mesh2Controller")
27 public Mesh2plusTimeController mesh2Controller;
28
29
30
31 private DataHandler dataHandler;
32
33
34 public CCVizController() {
35
36 }
37
38
39 public void open() {
40 File f = Dialoguer.getFile("CCViz");
41 if (f != null) {
42 open(f);
43 }
44 }
45
46 public void open(File f) {
47 String s = FileUtil.readFirstLine(f);
48
49 dataHandler = DataHandlerFactory.getHandler(s);
50 if (dataHandler == null) {
51 int[] xy = {500, 500};
52 Dialoguer.message(xy, "unrecognized file - cant plot " + s);
53 } else {
54 dataHandler.read(f);
55
56 syncOptions();
57
58 int ic = dataHandler.getContentStyle();
59 if (ic == DataHandler.STATIC) {
60 basicController.setDataHandler(dataHandler);
61
62 } else if (ic == DataHandler.FRAMES2D) {
63 mesh2Controller.setDataHandler(dataHandler);
64
65 DataHandler dh = dataHandler.getCoHandler();
66 if (dh != null && dh.getContentStyle() == DataHandler.STATIC && dh.hasData()) {
67 basicController.setDataHandler(dh);
68
69 } else {
70 basicController.setDataHandler(new MeshSummary(dataHandler));
71 }
72
73 } else {
74 E.missing();
75 }
76
77 }
78 }
79
80 public void requestClose() {
81 exit();
82 }
83
84
85 public void reload() {
86 E.info("time to reload...");
87 }
88
89
90 public void requestExit() {
91 exit();
92 }
93
94
95 public void exit() {
96 System.exit(0);
97 }
98
99
100 public void syncOptions() {
101 String[] sa = new String[0];
102 if (dataHandler != null) {
103 sa = dataHandler.getViewOptions();
104 }
105 viewMenu.setOptions(sa);
106 }
107
108
109 public void setViewStyle(String s) {
110
111 if (dataHandler != null) {
112 dataHandler.setViewStyle(s);
113 }
114
115 basicController.repaint();
116 mesh2Controller.repaint();
117 }
118
119
120 public void attached() {
121
122
123 }
124
125 }