root / trunk / libraries / libUIComponent_praster / src / org / gvsig / gui / beans / buttonBar / ButtonBarContainer.java @ 8026
History | View | Annotate | Download (4.54 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
package org.gvsig.gui.beans.buttonBar; |
20 |
|
21 |
import java.awt.FlowLayout; |
22 |
import java.util.ArrayList; |
23 |
|
24 |
import javax.swing.ImageIcon; |
25 |
import javax.swing.JButton; |
26 |
|
27 |
import org.gvsig.gui.beans.BaseComponent; |
28 |
|
29 |
public class ButtonBarContainer extends BaseComponent { |
30 |
|
31 |
|
32 |
private int wComp = 400, hComp = 26; |
33 |
private String pathToImages = "images/"; |
34 |
private ArrayList buttons = new ArrayList(); |
35 |
private boolean disableAllControls = false; |
36 |
private boolean[] buttonsState = null; |
37 |
|
38 |
/**
|
39 |
* This is the default constructor
|
40 |
*/
|
41 |
public ButtonBarContainer() {
|
42 |
super();
|
43 |
initialize(); |
44 |
} |
45 |
|
46 |
/**
|
47 |
* This method initializes this
|
48 |
*
|
49 |
* @return void
|
50 |
*/
|
51 |
private void initialize() { |
52 |
FlowLayout flowLayout = new FlowLayout(); |
53 |
flowLayout.setHgap(0);
|
54 |
flowLayout.setVgap(0);
|
55 |
this.setLayout(flowLayout);
|
56 |
this.setSize(wComp, hComp);
|
57 |
} |
58 |
|
59 |
|
60 |
/**
|
61 |
* A?ade un boton al ArrayList de los botones.
|
62 |
*
|
63 |
* @param iconName: nombre del icono asignado al boton. La imagen tendr?a que
|
64 |
* estar dentro de la carpeta "images/"
|
65 |
* @param tip: tip del boton;
|
66 |
* @param order: orden que ocupar? el boton dentro del control
|
67 |
*/
|
68 |
public void addButton(String iconName, String tip, int order){ |
69 |
JButton bt = new JButton(); |
70 |
|
71 |
bt.setPreferredSize(new java.awt.Dimension(22, 22)); |
72 |
try{
|
73 |
if (iconName != null) |
74 |
bt.setIcon(new ImageIcon(getClass().getResource(pathToImages + iconName))); |
75 |
}catch(NullPointerException exc){ |
76 |
//El icono no existe -> No se a?ade ninguno
|
77 |
} |
78 |
|
79 |
if(tip != null) |
80 |
bt.setToolTipText(tip); |
81 |
|
82 |
buttons.add(order, bt); |
83 |
addList(); |
84 |
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Elimina el bot?n correspondiente al indice que le pasamos.
|
89 |
* @param index
|
90 |
*/
|
91 |
public void delButton(int index){ |
92 |
buttons.remove(index); |
93 |
this.removeAll();
|
94 |
addList(); |
95 |
} |
96 |
|
97 |
/**
|
98 |
* A?ade en el panel los botones que tenemos en el ArrayList.
|
99 |
*
|
100 |
*/
|
101 |
public void addList(){ |
102 |
for(int i = 0 ; i < buttons.size() ; i++){ |
103 |
this.add((JButton)buttons.get(i)); |
104 |
} |
105 |
} |
106 |
|
107 |
|
108 |
/**
|
109 |
* Esta funci?n deshabilita todos los controles y guarda sus valores
|
110 |
* de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
|
111 |
* se vuelvan a quedar como estaba
|
112 |
*/
|
113 |
public void disableAllControls(){ |
114 |
if(!disableAllControls){
|
115 |
disableAllControls = true;
|
116 |
|
117 |
buttonsState = new boolean[buttons.size()]; |
118 |
|
119 |
|
120 |
|
121 |
for (int i = 0 ; i < buttons.size() ; i++){ |
122 |
|
123 |
//Salvamos los estados
|
124 |
buttonsState[i] = ((JButton)buttons.get(i)).isEnabled();
|
125 |
//Desactivamos controles
|
126 |
((JButton)buttons.get(i)).setEnabled(false); |
127 |
} |
128 |
} |
129 |
} |
130 |
|
131 |
/**
|
132 |
* Esta funci?n deja los controles como estaban al ejecutar la funci?n
|
133 |
* disableAllControls
|
134 |
*/
|
135 |
public void restoreControlsValue(){ |
136 |
if(disableAllControls){
|
137 |
disableAllControls = false;
|
138 |
|
139 |
for(int i = 0 ; i < buttons.size() ; i++){ |
140 |
((JButton)buttons.get(i)).setEnabled(buttonsState[i]);
|
141 |
} |
142 |
} |
143 |
} |
144 |
|
145 |
/**
|
146 |
* M?todo para acceder a los botones del control;
|
147 |
* @param index
|
148 |
* @return
|
149 |
*/
|
150 |
public JButton getButton(int index){ |
151 |
return (JButton)buttons.get(index); |
152 |
} |
153 |
|
154 |
/**
|
155 |
* M?todo para establecer la posici?n de los botones dentro del control.
|
156 |
* @param align: "left" o "right"
|
157 |
*/
|
158 |
public void setButtonAlignment(String align){ |
159 |
FlowLayout layout = new FlowLayout(); |
160 |
layout.setHgap(2);
|
161 |
layout.setVgap(0);
|
162 |
|
163 |
if (align.equals("right")) |
164 |
layout.setAlignment(FlowLayout.RIGHT);
|
165 |
else
|
166 |
layout.setAlignment(FlowLayout.LEFT);
|
167 |
|
168 |
this.setLayout(layout);
|
169 |
} |
170 |
|
171 |
public void setComponentBorder(boolean br){ |
172 |
if(br)
|
173 |
this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
174 |
if(!br)
|
175 |
this.setBorder(javax.swing.BorderFactory.createEmptyBorder());
|
176 |
} |
177 |
|
178 |
} |