Statistics
| Revision:

root / trunk / applications / appgvSIG / src-test / com / iver / cit / gvsig / panelGroup / Test4ButtonsPanel.java @ 15734

History | View | Annotate | Download (5.83 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19

    
20
package com.iver.cit.gvsig.panelGroup;
21

    
22
import java.awt.Dimension;
23
import java.awt.event.ComponentAdapter;
24
import java.awt.event.ComponentEvent;
25

    
26
import javax.swing.JFrame;
27

    
28
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
29
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
30
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
31
import org.gvsig.gui.beans.panelGroup.PanelGroupManager;
32
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
33
import org.gvsig.gui.beans.panelGroup.treePanel.TreePanel;
34

    
35
import com.iver.andami.ui.mdiManager.WindowInfo;
36
import com.iver.cit.gvsig.panelGroup.PanelGroupDialog;
37
import com.iver.cit.gvsig.panelGroup.loaders.PanelGroupLoaderFromExtensionPoint;
38
import com.iver.cit.gvsig.panelGroup.samples.Sample_ExtensionPointsOfIPanels;
39

    
40
/**
41
 * <p>Tests {@link PanelGroupDialog PanelGroupDialog}.</p>
42
 * <p>Tests {@link PanelGroupManager PanelGroupManager}, {@link PanelGroupLoaderFromExtensionPoint PanelGroupLoaderFromExtensionPoint}, 
43
 *  {@link TreePanel TreePanel}, and a resizable {@link PanelGroupDialog PanelGroupDialog}.</p>
44
 * 
45
 * @version 22/10/2007
46
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) 
47
 */
48
public class Test4ButtonsPanel {
49
        /**
50
         * <p>Element for the interface.</p>
51
         */
52
        private static JFrame jFrame;
53
        private static TreePanel panelGroup;
54

    
55
        /**
56
         * <p>Test method for the Test4ButtonsPanel.</p>
57
         * <p>Tests {@link PanelGroupManager PanelGroupManager}, {@link PanelGroupLoaderFromExtensionPoint PanelGroupLoaderFromExtensionPoint}, 
58
         *  {@link TreePanel TreePanel}, and a resizable {@link PanelGroupDialog PanelGroupDialog}.</p>
59
         * 
60
         * @param args optional arguments
61
         */
62
        public static void main(String[] args) {
63
                try {
64
                        // Objects creation
65
                        jFrame = new JFrame();
66

    
67
                        Sample_ExtensionPointsOfIPanels.loadSample();
68

    
69
                        PanelGroupManager manager = PanelGroupManager.getManager();
70
                        manager.setDefaultType(TreePanel.class);
71

    
72
                        panelGroup = (TreePanel) manager.getPanelGroup(Sample_ExtensionPointsOfIPanels.REFERENCE1);
73

    
74
                        PanelGroupLoaderFromExtensionPoint loader = new PanelGroupLoaderFromExtensionPoint(Sample_ExtensionPointsOfIPanels.EXTENSIONPOINT1_NAME);
75
                        AbstractPanel[] panels = loader.loadPanels();
76

    
77
                        // Begin: Initialise sample classes
78
                        int i = 0;
79
                        
80
                        while (i < panels.length) {
81
                                panels[i].setPreferredSize(new Dimension(Sample_ExtensionPointsOfIPanels.PANELS_DEFAULT_WIDTH, Sample_ExtensionPointsOfIPanels.PANELS_DEFAULT_HEIGHT));
82
                                panels[i].setReference(Sample_ExtensionPointsOfIPanels.REFERENCE1);
83
                                
84
                                panels[i].setID(Sample_ExtensionPointsOfIPanels.PANELS1_IDS[i]);
85
                                panels[i].setLabel(Sample_ExtensionPointsOfIPanels.PANELS1_LABELS[i]);
86
                                panels[i].setLabelGroup(Sample_ExtensionPointsOfIPanels.PANELS1_LABELGROUPS[i]);
87
                                
88
                                panelGroup.addPanel(panels[i++]);
89
                        }
90
                        // End: Initialise sample classes
91

    
92
                        // Creates the IWindow
93
                        PanelGroupDialog panelGroupDialog = new PanelGroupDialog(Sample_ExtensionPointsOfIPanels.REFERENCE1_NAME, "Panel with Buttons", 800, 800, (byte)WindowInfo.RESIZABLE, panelGroup);
94

    
95
                        panelGroupDialog.addButtonPressedListener(new ButtonsPanelListener() {
96
                                /*
97
                                 * @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
98
                                 */
99
                                public void actionButtonPressed(ButtonsPanelEvent e) {
100
                                        switch (e.getButton()) {
101
                                                case ButtonsPanel.BUTTON_ACCEPT:
102
                                                        System.out.println("Accept Button pressed.");
103
                                                        hideJFrame();
104
                                                        System.exit(0);
105
                                                        break;
106
                                                case ButtonsPanel.BUTTON_CANCEL:
107
                                                        System.out.println("Cancel Button pressed.");
108
                                                        hideJFrame();
109
                                                        System.exit(0);
110
                                                        break;
111
                                                case ButtonsPanel.BUTTON_APPLY:
112
                                                        System.out.println("Apply Button pressed.");
113
                                                        break;
114
                                        }
115
                                }
116
                        });
117

    
118
                        jFrame.setTitle("Test resizable PanelGroupDialog with tree and using PanelGroupLoaderFromExtensionPoint");
119
                    jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
120
                    jFrame.setSize(panelGroupDialog.getPreferredSize());
121
                    jFrame.getContentPane().add(panelGroupDialog);
122
                    
123
                        jFrame.setVisible(true);
124
                        
125
                        // Resize listenings
126
                        panelGroup.addComponentListener(new ComponentAdapter() {
127
                                /*
128
                                 * (non-Javadoc)
129
                                 * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
130
                                 */
131
                                public void componentResized(ComponentEvent e) {
132
                                        updateFrameSize();
133
                                }
134
                        });
135
                        
136
                        jFrame.addComponentListener(new ComponentAdapter() {
137
                                /*
138
                                 * (non-Javadoc)
139
                                 * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
140
                                 */
141
                                public void componentResized(ComponentEvent e) {
142
                                        panelGroup.setPreferredSize(jFrame.getSize());
143
                                }
144
                        });
145
                } catch (Exception e) {
146
                        e.printStackTrace();
147
                }
148
        }
149
        
150
        /**
151
         * <p>Hides the {@link JFrame JFrame}, hiding the graphical interface.</p>
152
         */
153
        private static void hideJFrame() {
154
                jFrame.setVisible(false);
155
        }
156
        
157
        /**
158
         * <p>Updates the test Frame when its components are resized.</p>
159
         */
160
        private static void updateFrameSize() {
161
                        jFrame.setSize(panelGroup.getPreferredSize());
162
        }
163
}