gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.main / src / main / java / org / gvsig / tools / main / Main.java @ 501
History | View | Annotate | Download (3.15 KB)
1 |
package org.gvsig.tools.main; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
|
8 |
import javax.swing.JButton; |
9 |
import javax.swing.JFrame; |
10 |
import javax.swing.JMenu; |
11 |
import javax.swing.JMenuBar; |
12 |
import javax.swing.JMenuItem; |
13 |
import javax.swing.JTabbedPane; |
14 |
import javax.swing.JToolBar; |
15 |
import javax.swing.WindowConstants; |
16 |
|
17 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
18 |
import org.gvsig.tools.main.dynobject.DynObjectComponentAction; |
19 |
import org.gvsig.tools.main.dynobject.DynObjectSetComponentAction; |
20 |
import org.gvsig.tools.main.dynobject.TestDynObject; |
21 |
import org.gvsig.tools.main.taskstatus.JTaskStatusAction; |
22 |
import org.gvsig.tools.main.usability.UsabilityAction; |
23 |
|
24 |
/**
|
25 |
* @author 2010- C?sar Ordi?ana - gvSIG team
|
26 |
*/
|
27 |
public class Main { |
28 |
|
29 |
private JTabbedPane tabbedPane; |
30 |
private JMenuBar menuBar; |
31 |
private JToolBar toolBar; |
32 |
|
33 |
public static void main(String args[]) { |
34 |
new DefaultLibrariesInitializer().fullInitialize();
|
35 |
DynObjectComponentAction.registerDynObjects(); |
36 |
Main main = new Main();
|
37 |
main.show(); |
38 |
} |
39 |
|
40 |
public void show() { |
41 |
|
42 |
final JFrame frame = new JFrame("Tools swing components test app"); |
43 |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
44 |
|
45 |
// Add a tabbed pane as a content pane
|
46 |
tabbedPane = new JTabbedPane(); |
47 |
tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
|
48 |
frame.getContentPane().add(tabbedPane); |
49 |
|
50 |
// Create application actions
|
51 |
MainAction[] actions = createActions();
|
52 |
|
53 |
// Create the menu bar.
|
54 |
menuBar = new JMenuBar(); |
55 |
|
56 |
// Build the menu.
|
57 |
JMenu menuFile = new JMenu("File"); |
58 |
JMenuItem menuItemExit = new JMenuItem("Exit"); |
59 |
menuItemExit.addActionListener(new ActionListener() { |
60 |
|
61 |
public void actionPerformed(ActionEvent e) { |
62 |
frame.dispose(); |
63 |
System.exit(0); |
64 |
} |
65 |
}); |
66 |
menuFile.add(menuItemExit); |
67 |
menuBar.add(menuFile); |
68 |
|
69 |
// Add all actions to the menu bar
|
70 |
JMenu menuDemo = new JMenu("Tools components"); |
71 |
for (int i = 0; i < actions.length; i++) { |
72 |
menuDemo.add(new JMenuItem(actions[i])); |
73 |
} |
74 |
menuBar.add(menuDemo); |
75 |
|
76 |
// Build the toolbar
|
77 |
toolBar = new JToolBar("Main toolbar"); |
78 |
|
79 |
// Add all actions to the toolbar
|
80 |
for (int i = 0; i < actions.length; i++) { |
81 |
toolBar.add(new JButton(actions[i])); |
82 |
} |
83 |
|
84 |
frame.setPreferredSize(new Dimension(800, 600)); |
85 |
|
86 |
frame.setJMenuBar(menuBar); |
87 |
frame.add(toolBar, BorderLayout.PAGE_START);
|
88 |
|
89 |
// Display the window.
|
90 |
frame.pack(); |
91 |
frame.setVisible(true);
|
92 |
} |
93 |
|
94 |
private MainAction[] createActions() { |
95 |
return new MainAction[] { |
96 |
new DynObjectComponentAction(tabbedPane, TestDynObject.TESTDYNOBJECT_NAME),
|
97 |
new DynObjectComponentAction(tabbedPane, TestDynObject.TESTDYNOBJECTREADONLY_NAME),
|
98 |
new DynObjectSetComponentAction(tabbedPane),
|
99 |
new UsabilityAction(tabbedPane),
|
100 |
new JTaskStatusAction(tabbedPane)
|
101 |
}; |
102 |
} |
103 |
|
104 |
} |