Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libUIComponent / src / org / gvsig / gui / beans / defaultbuttonspanel / DefaultButtonsPanel.java @ 39402

History | View | Annotate | Download (5.01 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
 */
43
public class DefaultButtonsPanel extends JPanel {
44
        private static final long serialVersionUID = 1536590395737700551L;
45
        ButtonsPanel              bp               = null;
46
        JPanel                    content          = null;
47
        private int               margin           = 4;
48
        
49
        /**
50
         * Crea el <code>DefaultButtonsPanel</code> con los botones por defecto.
51
         */
52
        public DefaultButtonsPanel() {
53
                super.setLayout(new java.awt.BorderLayout(0, 0));
54
                getButtonsPanel().addAccept();
55
                getButtonsPanel().addCancel();
56
                getButtonsPanel().addApply();
57
                super.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
58
                super.add(getContent(), java.awt.BorderLayout.CENTER);
59
                this.setBorder(javax.swing.BorderFactory.createEmptyBorder(margin, margin, margin, margin));
60
        }
61

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

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

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

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

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

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

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

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

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

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

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

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

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