Menu

[r27]: / GraphScript / trunk / ls / graph / ui / MainWindow.java  Maximize  Restore  History

Download this file

184 lines (158 with data), 5.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package ls.graph.ui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;
import ls.script.ConfigurableScriptEngine;
import ls.script.ExecuteScriptJob;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.random.generators.GraphGenerator;
import edu.uci.ics.jung.random.generators.SimpleRandomGenerator;
import edu.uci.ics.jung.visualization.FRLayout;
import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
import edu.uci.ics.jung.visualization.Layout;
import edu.uci.ics.jung.visualization.PluggableRenderer;
import edu.uci.ics.jung.visualization.Renderer;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.contrib.CircleLayout;
public class MainWindow extends JFrame
{
private static final long serialVersionUID = 1L;
private Graph graph = null;
private Layout graphLayout = null;
private JTextPane txtScript;
/**
* Get the list of files to be included
* @return
*/
private List<File> getScriptIncludes()
{
//for now, hard coded
File f = new File("C:\\programming\\workspace\\GraphScript\\scripts\\util.js");
List<File> l = new LinkedList<File>();
l.add(f);
return l;
}
private final class ExecuteAction extends AbstractAction
{
private static final long serialVersionUID = 1L;
ExecuteAction()
{
putValue(NAME, "Execute");
}
public void actionPerformed(ActionEvent event)
{
//JOptionPane.showMessageDialog(null, "Execute event");
String scriptText = txtScript.getText();
ExecuteScriptJob job = new ExecuteScriptJob(scriptText,scriptEngine, getScriptIncludes());
Thread t = new Thread(job);
t.start();
}
} //end of ExecuteAction class
private final class ExitAction extends AbstractAction
{
private static final long serialVersionUID = 1L;
ExitAction()
{
putValue(NAME, "Exit");
}
public void actionPerformed(ActionEvent e)
{
MainWindow.this.setVisible(false);
MainWindow.this.dispose();
}
}
private ConfigurableScriptEngine scriptEngine = null;
public MainWindow(ConfigurableScriptEngine engine,Graph g)
{
super();
this.graph = g;
// loadGraph();
initUI();
this.scriptEngine = engine;
setLocation(200,200);
setPreferredSize(new Dimension(400,600));
setSize(600, 400);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
// private void loadGraph()
// {
// GraphGenerator gGen = new SimpleRandomGenerator(5,4);
// this.graph = (Graph)gGen.generateGraph();
// }
private JComponent getGraphComponent()
{
graphLayout = new CircleLayout(this.graph);
Dimension d = new Dimension(400,400);
graphLayout.initialize(d);
Renderer r = new PluggableRenderer();
VisualizationViewer vv = new VisualizationViewer(graphLayout,r);
//vv.setSize(d);
// GraphZoomScrollPane zoomPane = new GraphZoomScrollPane(vv);
JScrollPane zoomPane = new JScrollPane(vv);
return zoomPane;
//return vv;
}
private void initUI()
{
setTitle("Graph Script");
getContentPane().setLayout(new BorderLayout());
JSplitPane spltMain =
new JSplitPane(JSplitPane.VERTICAL_SPLIT,
this.getGraphComponent(),
createScriptPane());
spltMain.setDividerLocation(200);
spltMain.setResizeWeight(0.5);
getContentPane().add(spltMain,BorderLayout.CENTER);
getContentPane().add(createControlPane(),BorderLayout.SOUTH);
this.addComponentListener(new ComponentListener()
{
public void componentHidden(ComponentEvent evt){}
public void componentMoved(ComponentEvent evt) {}
public void componentResized(ComponentEvent evt)
{
//graphLayout.resize(evt.getComponent().getSize());
}
public void componentShown(ComponentEvent evt) {}
});
}
private JPanel createScriptPane()
{
JPanel scriptPane = new JPanel();
scriptPane.setLayout(new BorderLayout());
txtScript = new JTextPane();
txtScript.setEditable(true);
txtScript.setEnabled(true);
txtScript.setAlignmentY(0.0f);
scriptPane.add(txtScript,BorderLayout.CENTER);
return scriptPane;
}
private JPanel createControlPane()
{
JPanel controlPane = new JPanel();
controlPane.setLayout(new FlowLayout());
JButton btnExecute = new JButton(new ExecuteAction());
JButton btnExit = new JButton(new ExitAction());
controlPane.add(btnExecute);
controlPane.add(btnExit);
return controlPane;
}
}
MongoDB Logo MongoDB