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 @ 270

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

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

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

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

    
37
    public void show() {
38

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

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

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

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

    
53
        // Build the menu.
54
        JMenu menuFile = new JMenu("File");
55
        JMenuItem menuItemExit = new JMenuItem("Exit");
56
        menuItemExit.addActionListener(new ActionListener() {
57

    
58
            public void actionPerformed(ActionEvent e) {
59
                frame.dispose();
60
                System.exit(0);
61
            }
62
        });
63
        menuFile.add(menuItemExit);
64
        menuBar.add(menuFile);
65

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

    
73
        // Build the toolbar
74
        toolBar = new JToolBar("Main toolbar");
75

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

    
81
        frame.setPreferredSize(new Dimension(800, 600));
82

    
83
        frame.setJMenuBar(menuBar);
84
        frame.add(toolBar, BorderLayout.PAGE_START);
85

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

    
91
    private MainAction[] createActions() {
92
        return new MainAction[] { new DynObjectComponentAction(tabbedPane),
93
            new DynObjectSetComponentAction(tabbedPane),
94
            new UsabilityAction(tabbedPane) };
95
    }
96

    
97
}