Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.main / src / main / java / org / gvsig / tools / main / Main.java @ 100

History | View | Annotate | Download (2.36 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.usability.UsabilityAction;
20

    
21
/**
22
 * @author 2010- C?sar Ordi?ana - gvSIG team
23
 */
24
public class Main {
25

    
26
        private JTabbedPane tabbedPane;
27
        private JMenuBar menuBar;
28
        private JToolBar toolBar;
29

    
30
        public static void main(String args[]) {
31
                new DefaultLibrariesInitializer().fullInitialize();
32
                Main main = new Main();
33
                main.show();
34
        }
35

    
36
        public void show() {
37

    
38
                final JFrame frame = new JFrame("Tools swing components test app");
39
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
40

    
41
                // Add a tabbed pane as a content pane
42
                tabbedPane = new JTabbedPane();
43
                tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
44
                frame.getContentPane().add(tabbedPane);
45

    
46
                // Create application actions
47
                MainAction[] actions = createActions();
48

    
49
                // Create the menu bar.
50
                menuBar = new JMenuBar();
51

    
52
                // Build the menu.
53
                JMenu menuFile = new JMenu("File");
54
                JMenuItem menuItemExit = new JMenuItem("Exit");
55
                menuItemExit.addActionListener(new ActionListener() {
56
                        public void actionPerformed(ActionEvent e) {
57
                                frame.dispose();
58
                                System.exit(0);
59
                        }
60
                });
61
                menuFile.add(menuItemExit);
62
                menuBar.add(menuFile);
63

    
64
                // Add all actions to the menu bar
65
                JMenu menuDemo = new JMenu("Tools components");
66
                for (int i = 0; i < actions.length; i++) {
67
                        menuDemo.add(new JMenuItem(actions[i]));
68
                }
69
                menuBar.add(menuDemo);
70

    
71
                // Build the toolbar
72
                toolBar = new JToolBar("Main toolbar");
73

    
74
                // Add all actions to the toolbar
75
                for (int i = 0; i < actions.length; i++) {
76
                        toolBar.add(new JButton(actions[i]));
77
                }
78

    
79
                frame.setPreferredSize(new Dimension(800, 600));
80

    
81
                frame.setJMenuBar(menuBar);
82
                frame.add(toolBar, BorderLayout.PAGE_START);
83

    
84
                // Display the window.
85
                frame.pack();
86
                frame.setVisible(true);
87
        }
88

    
89
        private MainAction[] createActions() {
90
                return new MainAction[] { new DynObjectComponentAction(tabbedPane),
91
                                new UsabilityAction(tabbedPane) };
92
        }
93

    
94
}