svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / defaultbuttonspanel / DefaultButtonsPanel.java @ 42249
History | View | Annotate | Download (5.95 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui.beans.defaultbuttonspanel; |
25 |
|
26 |
/* gvSIG. Geographic Information System of the Valencian Government
|
27 |
*
|
28 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
29 |
* of the Valencian Government (CIT)
|
30 |
*
|
31 |
* This program is free software; you can redistribute it and/or
|
32 |
* modify it under the terms of the GNU General Public License
|
33 |
* as published by the Free Software Foundation; either version 2
|
34 |
* of the License, or (at your option) any later version.
|
35 |
*
|
36 |
* This program is distributed in the hope that it will be useful,
|
37 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
38 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
39 |
* GNU General Public License for more details.
|
40 |
*
|
41 |
* You should have received a copy of the GNU General Public License
|
42 |
* along with this program; if not, write to the Free Software
|
43 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
44 |
* MA 02110-1301, USA.
|
45 |
*
|
46 |
*/
|
47 |
|
48 |
import java.awt.Component; |
49 |
import java.awt.Container; |
50 |
import java.awt.LayoutManager; |
51 |
import java.awt.Window; |
52 |
|
53 |
import javax.swing.JPanel; |
54 |
|
55 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
56 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
57 |
|
58 |
/**
|
59 |
* <code>DefaultButtonsPanel</code> es un Panel que hereda de <code>JPanel</code> con
|
60 |
* el a?adido de poder definir una botonera por defecto.
|
61 |
*
|
62 |
* @version 20/08/2008
|
63 |
*
|
64 |
* @author BorSanZa - Borja Sanchez Zamorano (borja.sanchez@iver.es)
|
65 |
*/
|
66 |
public class DefaultButtonsPanel extends JPanel { |
67 |
private static final long serialVersionUID = 1536590395737700551L; |
68 |
ButtonsPanel bp = null;
|
69 |
JPanel content = null; |
70 |
private int margin = 4; |
71 |
|
72 |
/**
|
73 |
* Crea el <code>DefaultButtonsPanel</code> con los botones por defecto.
|
74 |
*/
|
75 |
public DefaultButtonsPanel() {
|
76 |
super.setLayout(new java.awt.BorderLayout(0, 0)); |
77 |
getButtonsPanel().addApply(); |
78 |
getButtonsPanel().addAccept(); |
79 |
getButtonsPanel().addCancel(); |
80 |
super.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
|
81 |
super.add(getContent(), java.awt.BorderLayout.CENTER);
|
82 |
this.setBorder(javax.swing.BorderFactory.createEmptyBorder(margin, margin, margin, margin));
|
83 |
} |
84 |
|
85 |
/**
|
86 |
* Crea el <code>DialogPanel</code> con los botones que definamos de la clase
|
87 |
* <code>ButtonsPanel</code>
|
88 |
*
|
89 |
* @param buttons Constante para definir que botones se crear?n
|
90 |
*/
|
91 |
public DefaultButtonsPanel(int buttons) { |
92 |
super.setLayout(new java.awt.BorderLayout(0, 0)); |
93 |
bp = new ButtonsPanel(buttons);
|
94 |
super.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
|
95 |
super.add(getContent(), java.awt.BorderLayout.CENTER);
|
96 |
this.setBorder(javax.swing.BorderFactory.createEmptyBorder(margin, margin, margin, margin));
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Obtener el objeto <code>ButtonsPanel</code> del <code>DialogPanel</code>.
|
101 |
* En caso de no estar creado, lo crear?.
|
102 |
*
|
103 |
* @return El componente bp
|
104 |
*/
|
105 |
public ButtonsPanel getButtonsPanel() {
|
106 |
if (bp == null) |
107 |
bp = new ButtonsPanel();
|
108 |
return bp;
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* Obtener el contenido del <code>DialogPanel</code>. En caso de no estar creado,
|
113 |
* lo crear?.
|
114 |
*
|
115 |
* @return El componente content
|
116 |
*/
|
117 |
public JPanel getContent() { |
118 |
if (content == null) |
119 |
content = new JPanel(); |
120 |
return content;
|
121 |
} |
122 |
|
123 |
public void addButtonPressedListener(ButtonsPanelListener listener) { |
124 |
getButtonsPanel().addButtonPressedListener(listener); |
125 |
} |
126 |
|
127 |
public void removeButtonPressedListener(ButtonsPanelListener listener) { |
128 |
getButtonsPanel().removeButtonPressedListener(listener); |
129 |
} |
130 |
|
131 |
/*
|
132 |
* (non-Javadoc)
|
133 |
* @see java.awt.Container#getLayout()
|
134 |
*/
|
135 |
public LayoutManager getLayout() { |
136 |
return getContent().getLayout();
|
137 |
} |
138 |
|
139 |
/*
|
140 |
* (non-Javadoc)
|
141 |
* @see java.awt.Container#setLayout(java.awt.LayoutManager)
|
142 |
*/
|
143 |
public void setLayout(LayoutManager mgr) { |
144 |
getContent().setLayout(mgr); |
145 |
} |
146 |
|
147 |
/**
|
148 |
* Devuelve el Window que contiene dicha ventana o null en caso de que no sea
|
149 |
* asi
|
150 |
* @return
|
151 |
*/
|
152 |
public Window getWindow() { |
153 |
Container container = getParent();
|
154 |
while (container != null) { |
155 |
if (container instanceof Window) |
156 |
return (Window) container; |
157 |
container = container.getParent(); |
158 |
} |
159 |
return null; |
160 |
} |
161 |
|
162 |
/*
|
163 |
* (non-Javadoc)
|
164 |
* @see java.awt.Container#add(java.awt.Component)
|
165 |
*/
|
166 |
public Component add(Component comp) { |
167 |
return getContent().add(comp);
|
168 |
} |
169 |
|
170 |
/*
|
171 |
* (non-Javadoc)
|
172 |
* @see java.awt.Container#add(java.awt.Component, int)
|
173 |
*/
|
174 |
public Component add(Component comp, int index) { |
175 |
return getContent().add(comp, index);
|
176 |
} |
177 |
|
178 |
/*
|
179 |
* (non-Javadoc)
|
180 |
* @see java.awt.Container#add(java.awt.Component, java.lang.Object)
|
181 |
*/
|
182 |
public void add(Component comp, Object constraints) { |
183 |
getContent().add(comp, constraints); |
184 |
} |
185 |
|
186 |
/*
|
187 |
* (non-Javadoc)
|
188 |
* @see java.awt.Container#add(java.awt.Component, java.lang.Object, int)
|
189 |
*/
|
190 |
public void add(Component comp, Object constraints, int index) { |
191 |
getContent().add(comp, constraints, index); |
192 |
} |
193 |
|
194 |
/*
|
195 |
* (non-Javadoc)
|
196 |
* @see java.awt.Container#add(java.lang.String, java.awt.Component)
|
197 |
*/
|
198 |
public Component add(String name, Component comp) { |
199 |
return getContent().add(name, comp);
|
200 |
} |
201 |
} |