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