gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / dynclass / DefaultJModeler.java @ 1754
History | View | Annotate | Download (6.73 KB)
1 |
package org.gvsig.tools.swing.impl.dynclass; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.Image; |
6 |
import java.awt.event.ActionEvent; |
7 |
import java.awt.event.ComponentEvent; |
8 |
import java.awt.event.ComponentListener; |
9 |
import java.io.File; |
10 |
import javax.swing.AbstractAction; |
11 |
import javax.swing.Action; |
12 |
import javax.swing.ImageIcon; |
13 |
import javax.swing.JComponent; |
14 |
import javax.swing.JDesktopPane; |
15 |
import javax.swing.JInternalFrame; |
16 |
import javax.swing.JLabel; |
17 |
import javax.swing.JPanel; |
18 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
19 |
import org.gvsig.tools.swing.api.Component; |
20 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
21 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
22 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
23 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
24 |
import org.gvsig.tools.swing.impl.windowmanager.DefaultDialog; |
25 |
import org.slf4j.Logger; |
26 |
import org.slf4j.LoggerFactory; |
27 |
|
28 |
public class DefaultJModeler extends JPanel implements Component, WindowManager_v2 { |
29 |
|
30 |
private static final long serialVersionUID = 6461465381374648630L; |
31 |
private static final Logger logger = LoggerFactory.getLogger(DefaultJModeler.class); |
32 |
|
33 |
public static void main(String args[]) { |
34 |
new DefaultLibrariesInitializer().fullInitialize();
|
35 |
DefaultJModeler modeler = new DefaultJModeler();
|
36 |
WindowManager windowManager = ToolsSwingLocator.getWindowManager(); |
37 |
windowManager.showWindow(modeler.asJComponent(), "Modeler", WindowManager.MODE.WINDOW);
|
38 |
} |
39 |
private JDesktopPane desktop; |
40 |
private JPanel status; |
41 |
private JLabel message; |
42 |
private MenuBarHelper menuBar;
|
43 |
|
44 |
private final DefaultModeler modeler; |
45 |
|
46 |
int frameCount = 0; |
47 |
static final int xOffset = 30, yOffset = 30; |
48 |
|
49 |
public DefaultJModeler() {
|
50 |
modeler = new DefaultModeler();
|
51 |
this.initComponents();
|
52 |
} |
53 |
|
54 |
public void addAction(String menuEntry, Action action) { |
55 |
this.menuBar.add(menuEntry,action);
|
56 |
} |
57 |
|
58 |
public void addAction(String menuEntry) { |
59 |
this.menuBar.add(menuEntry,null); |
60 |
} |
61 |
|
62 |
private void initComponents() { |
63 |
this.menuBar = new MenuBarHelper(); |
64 |
this.desktop = new JDesktopPane(); |
65 |
|
66 |
this.addAction("File"); |
67 |
this.addAction("File", new LoadModelAction()); |
68 |
this.addAction("File", new ShowClassesAction()); |
69 |
|
70 |
this.addAction("File/-"); |
71 |
this.addAction("File", new ExitAction()); |
72 |
|
73 |
this.status = new JPanel(); |
74 |
this.status.setLayout(new BorderLayout()); |
75 |
this.message = new JLabel(); |
76 |
this.status.add(this.message, BorderLayout.WEST); |
77 |
|
78 |
this.setLayout(new BorderLayout()); |
79 |
this.add(this.menuBar.asJComponent(), BorderLayout.NORTH); |
80 |
this.add(this.desktop, BorderLayout.CENTER); |
81 |
this.add(this.status, BorderLayout.SOUTH); |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public JComponent asJComponent() { |
86 |
return this; |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public Dimension getPreferredSize() { |
91 |
return new Dimension(800, 600); |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public void showWindow(JComponent component, String tittle, MODE mode) { |
96 |
this.showWindow(component, tittle, mode, null, 0); |
97 |
} |
98 |
|
99 |
@Override
|
100 |
public void showWindow(JComponent component, String tittle, MODE mode, Image icon) { |
101 |
this.showWindow(component, tittle, mode, icon, 0); |
102 |
} |
103 |
|
104 |
@Override
|
105 |
public void showWindow(JComponent component, String tittle, MODE mode, Image icon, int flags) { |
106 |
final JInternalFrame frame = new JInternalFrame(tittle, true, true, true, true); |
107 |
frameCount++; |
108 |
frame.setLocation(xOffset * frameCount, yOffset * frameCount); |
109 |
frame.setVisible(true);
|
110 |
frame.setContentPane(component); |
111 |
if (icon != null) { |
112 |
frame.setFrameIcon(new ImageIcon(icon)); |
113 |
} |
114 |
Dimension d = component.getPreferredSize();
|
115 |
frame.pack(); |
116 |
frame.setSize(d); |
117 |
component.addComponentListener(new ComponentListener() { |
118 |
@Override
|
119 |
public void componentResized(ComponentEvent e) { |
120 |
} |
121 |
@Override
|
122 |
public void componentMoved(ComponentEvent e) { |
123 |
} |
124 |
@Override
|
125 |
public void componentShown(ComponentEvent e) { |
126 |
frame.toFront(); |
127 |
} |
128 |
@Override
|
129 |
public void componentHidden(ComponentEvent e) { |
130 |
frame.setVisible(false);
|
131 |
} |
132 |
}); |
133 |
|
134 |
this.desktop.add(frame);
|
135 |
} |
136 |
|
137 |
private class ModelerDialog extends DefaultDialog { |
138 |
private static final long serialVersionUID = 9102998033789035805L; |
139 |
|
140 |
public ModelerDialog(JComponent contents, String title, String header, int buttons) { |
141 |
super(contents, title, header, buttons);
|
142 |
} |
143 |
|
144 |
@Override
|
145 |
protected WindowManager getWindowManager() {
|
146 |
return DefaultJModeler.this;
|
147 |
} |
148 |
} |
149 |
|
150 |
@Override
|
151 |
public Dialog createDialog(JComponent component, String title, String header, int buttons) { |
152 |
DefaultDialog dialog = new ModelerDialog(component, title, header, buttons);
|
153 |
return dialog;
|
154 |
} |
155 |
|
156 |
public void showListOfClasses() { |
157 |
DynClassesPanel panel = new DynClassesPanel(this); |
158 |
panel.set(this.modeler.getClasses());
|
159 |
this.showWindow(panel, "Entities", MODE.WINDOW); |
160 |
} |
161 |
|
162 |
private class LoadModelAction extends AbstractAction { |
163 |
|
164 |
private static final long serialVersionUID = -4619684474066026298L; |
165 |
|
166 |
public LoadModelAction() {
|
167 |
this.putValue(Action.NAME, "Load model"); |
168 |
} |
169 |
|
170 |
@Override
|
171 |
public void actionPerformed(ActionEvent e) { |
172 |
File[] f = ToolsSwingLocator.getThreadSafeDialogsManager().showOpenFileDialog("Select model", null); |
173 |
if (f == null || f.length == 0) { |
174 |
return;
|
175 |
} |
176 |
modeler.loadModel(f[0]);
|
177 |
showListOfClasses(); |
178 |
} |
179 |
} |
180 |
|
181 |
private class ShowClassesAction extends AbstractAction { |
182 |
|
183 |
private static final long serialVersionUID = -4619684474066026298L; |
184 |
|
185 |
public ShowClassesAction() {
|
186 |
this.putValue(Action.NAME, "Show classes"); |
187 |
} |
188 |
|
189 |
// @Override
|
190 |
// public boolean isEnabled() {
|
191 |
// if( dynClasses == null ) {
|
192 |
// return false;
|
193 |
// }
|
194 |
// return ! dynClasses.isEmpty();
|
195 |
// }
|
196 |
@Override
|
197 |
public void actionPerformed(ActionEvent e) { |
198 |
showListOfClasses(); |
199 |
} |
200 |
} |
201 |
|
202 |
private class ExitAction extends AbstractAction { |
203 |
|
204 |
private static final long serialVersionUID = -4619684474066026298L; |
205 |
|
206 |
public ExitAction() {
|
207 |
this.putValue(Action.NAME, "Exit"); |
208 |
} |
209 |
|
210 |
@Override
|
211 |
public void actionPerformed(ActionEvent e) { |
212 |
setVisible(false);
|
213 |
} |
214 |
} |
215 |
|
216 |
} |