Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libUIComponent / src / org / gvsig / gui / beans / defaultbuttonspanel / DefaultButtonsPanel.java @ 31952

History | View | Annotate | Download (4.93 KB)

1
package org.gvsig.gui.beans.defaultbuttonspanel;
2

    
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

    
25
import java.awt.Component;
26
import java.awt.Container;
27
import java.awt.LayoutManager;
28
import java.awt.Window;
29

    
30
import javax.swing.JPanel;
31

    
32
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
33
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
34

    
35
/**
36
 * <code>DefaultButtonsPanel</code> es un Panel que hereda de <code>JPanel</code> con
37
 * el a?adido de poder definir una botonera por defecto.
38
 *
39
 * @version 20/08/2008
40
 *
41
 * @author BorSanZa - Borja Sanchez Zamorano (borja.sanchez@iver.es)
42
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
43
 */
44
public class DefaultButtonsPanel extends JPanel {
45
        private static final long serialVersionUID = 1536590395737700551L;
46

    
47
        ButtonsPanel bp = null;
48
        JPanel content = null;
49

    
50
        /**
51
         * Crea el <code>DefaultButtonsPanel</code> con los botones por defecto.
52
         */
53
        public DefaultButtonsPanel() {
54
                super.setLayout(new java.awt.BorderLayout(0, 0));
55
                getButtonsPanel().addAccept();
56
                getButtonsPanel().addCancel();
57
                getButtonsPanel().addApply();
58
                super.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
59
                super.add(getContent(), java.awt.BorderLayout.CENTER);
60
                this.setBorder(javax.swing.BorderFactory.createEmptyBorder(11, 11, 11, 11));
61
        }
62

    
63
        /**
64
         * Crea el <code>DialogPanel</code> con los botones que definamos de la clase
65
         * <code>ButtonsPanel</code>
66
         *
67
         * @param buttons Constante para definir que botones se crear?n
68
         */
69
        public DefaultButtonsPanel(int buttons) {
70
                super.setLayout(new java.awt.BorderLayout(0, 0));
71
                bp = new ButtonsPanel(buttons);
72
                super.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
73
                super.add(getContent(), java.awt.BorderLayout.CENTER);
74
                this.setBorder(javax.swing.BorderFactory.createEmptyBorder(11, 11, 11, 11));
75
        }
76

    
77
        /**
78
         * Obtener el objeto <code>ButtonsPanel</code> del <code>DialogPanel</code>.
79
         * En caso de no estar creado, lo crear?.
80
         *
81
         * @return El componente bp
82
         */
83
        public ButtonsPanel getButtonsPanel() {
84
                if (bp == null)
85
                        bp = new ButtonsPanel();
86
                return bp;
87
        }
88

    
89
        /**
90
         * Obtener el contenido del <code>DialogPanel</code>. En caso de no estar creado,
91
         * lo crear?.
92
         *
93
         * @return El componente content
94
         */
95
        public JPanel getContent() {
96
                if (content == null)
97
                        content = new JPanel();
98
                return content;
99
        }
100

    
101
        public void addButtonPressedListener(ButtonsPanelListener listener) {
102
                getButtonsPanel().addButtonPressedListener(listener);
103
        }
104

    
105
        public void removeButtonPressedListener(ButtonsPanelListener listener) {
106
                getButtonsPanel().removeButtonPressedListener(listener);
107
        }
108

    
109
        /*
110
         * (non-Javadoc)
111
         * @see java.awt.Container#getLayout()
112
         */
113
        public LayoutManager getLayout() {
114
                return getContent().getLayout();
115
        }
116

    
117
        /*
118
         * (non-Javadoc)
119
         * @see java.awt.Container#setLayout(java.awt.LayoutManager)
120
         */
121
        public void setLayout(LayoutManager mgr) {
122
                getContent().setLayout(mgr);
123
        }
124

    
125
        /**
126
         * Devuelve el Window que contiene dicha ventana o null en caso de que no sea
127
         * asi
128
         * @return
129
         */
130
        public Window getWindow() {
131
                Container container = getParent();
132
                while (container != null) {
133
                        if (container instanceof Window)
134
                                return (Window) container;
135
                        container = container.getParent();
136
                }
137
                return null;
138
        }
139

    
140
        /*
141
         * (non-Javadoc)
142
         * @see java.awt.Container#add(java.awt.Component)
143
         */
144
        public Component add(Component comp) {
145
                return getContent().add(comp);
146
        }
147

    
148
        /*
149
         * (non-Javadoc)
150
         * @see java.awt.Container#add(java.awt.Component, int)
151
         */
152
        public Component add(Component comp, int index) {
153
                return getContent().add(comp, index);
154
        }
155

    
156
        /*
157
         * (non-Javadoc)
158
         * @see java.awt.Container#add(java.awt.Component, java.lang.Object)
159
         */
160
        public void add(Component comp, Object constraints) {
161
                getContent().add(comp, constraints);
162
        }
163

    
164
        /*
165
         * (non-Javadoc)
166
         * @see java.awt.Container#add(java.awt.Component, java.lang.Object, int)
167
         */
168
        public void add(Component comp, Object constraints, int index) {
169
                getContent().add(comp, constraints, index);
170
        }
171

    
172
        /*
173
         * (non-Javadoc)
174
         * @see java.awt.Container#add(java.lang.String, java.awt.Component)
175
         */
176
        public Component add(String name, Component comp) {
177
                return getContent().add(name, comp);
178
        }
179
}