Revision 12107 trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/buttonbar/ButtonBarContainer.java

View differences:

ButtonBarContainer.java
26 26
import javax.swing.JPanel;
27 27

  
28 28
public class ButtonBarContainer extends JPanel {
29
	private static final long serialVersionUID = -2556987128553063939L;
30
	private int							wComp = 400, hComp = 26;
31
	private String 						pathToImages = "images/";
32
	private ArrayList 					buttons = new ArrayList();
33
	private boolean 					disableAllControls = false;
34
	private boolean[] 					buttonsState = null;
35
	
29
	private static final long  serialVersionUID   = -2556987128553063939L;
30
	private int                wComp              = 400;
31
	private int                hComp              = 26;
32
	private String             pathToImages       = "images/";
33
	private ArrayList<JButton> buttons            = new ArrayList<JButton>();
34
	private boolean            disableAllControls = false;
35
	private boolean[]          buttonsState       = null;
36

  
36 37
	/**
37 38
	 * This is the default constructor
38 39
	 */
......
54 55
		this.setSize(wComp, hComp);
55 56
		}
56 57

  
57
	
58

  
58 59
	/**
59 60
	 * A?ade un boton al ArrayList de los botones.
60 61
	 * 
......
65 66
	 */
66 67
	public void addButton(String iconName, String tip, int order){
67 68
		JButton bt = new JButton();
68
		
69

  
69 70
		bt.setPreferredSize(new java.awt.Dimension(22, 22));
70 71
		try{
71 72
			if (iconName != null)
......
73 74
		}catch(NullPointerException exc){
74 75
			//El icono no existe -> No se a?ade ninguno
75 76
		}
76
		
77

  
77 78
		if(tip != null)
78 79
			bt.setToolTipText(tip);
79
		
80

  
80 81
		buttons.add(order, bt);
81 82
		addList();
82
		
83

  
83 84
	}
84
		
85

  
85 86
	/**
86 87
	 * Elimina el bot?n correspondiente al indice que le pasamos.
87 88
	 * @param index
......
91 92
		this.removeAll();
92 93
		addList();
93 94
	}
94
	
95

  
95 96
	/**
96 97
	 * A?ade en el panel los botones que tenemos en el ArrayList.
97 98
	 *
......
101 102
			this.add((JButton)buttons.get(i));
102 103
		}
103 104
	}
104
	
105
	
105

  
106

  
106 107
	/**
107 108
	 * Esta funci?n deshabilita todos los controles y guarda sus valores
108 109
	 * de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
......
111 112
	public void disableAllControls(){
112 113
		if(!disableAllControls){
113 114
			disableAllControls = true;
114
			
115

  
115 116
			buttonsState = new boolean[buttons.size()];
116
			
117
			
118
			
117

  
118

  
119

  
119 120
			for (int i = 0 ; i < buttons.size() ; i++){
120
				
121

  
121 122
				//Salvamos los estados
122 123
				buttonsState[i] = ((JButton)buttons.get(i)).isEnabled();
123 124
				//Desactivamos controles
......
125 126
			}
126 127
		}
127 128
	}
128
	
129

  
129 130
	/**
130 131
	 * Esta funci?n deja los controles como estaban al ejecutar la funci?n 
131 132
	 * disableAllControls
......
133 134
	public void restoreControlsValue(){
134 135
		if(disableAllControls){
135 136
			disableAllControls = false;
136
			
137

  
137 138
			for(int i = 0 ; i < buttons.size() ; i++){
138 139
				((JButton)buttons.get(i)).setEnabled(buttonsState[i]);
139 140
			}
140 141
		}
141 142
	}
142
	
143

  
143 144
	/**
144 145
	 * M?todo para acceder a los botones del control;
145 146
	 * @param index
......
157 158
		FlowLayout layout = new FlowLayout();
158 159
		layout.setHgap(2);
159 160
		layout.setVgap(0);
160
		
161

  
161 162
		if (align.equals("right"))
162 163
			layout.setAlignment(FlowLayout.RIGHT);
163 164
		else
164 165
			layout.setAlignment(FlowLayout.LEFT);
165
		
166

  
166 167
		this.setLayout(layout);
167 168
	}
168
	
169

  
169 170
	public void setComponentBorder(boolean br){
170 171
		if(br)
171 172
			this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
172 173
		if(!br)
173
			this.setBorder(javax.swing.BorderFactory.createEmptyBorder());		
174
			this.setBorder(javax.swing.BorderFactory.createEmptyBorder());
174 175
	}
175
	
176

  
176 177
}

Also available in: Unified diff