Revision 11004 trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/GraphicContainer.java

View differences:

GraphicContainer.java
18 18
 */
19 19
package org.gvsig.gui.beans.graphic;
20 20

  
21
import java.awt.FlowLayout;
21
import java.awt.BorderLayout;
22 22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.event.ComponentEvent;
25
import java.awt.event.ComponentListener;
23
import java.util.ArrayList;
24
import java.util.Iterator;
26 25

  
27
import javax.swing.JButton;
26
import javax.swing.JComponent;
28 27
import javax.swing.JPanel;
29
import javax.swing.JTextField;
30 28

  
31
import org.gvsig.gui.beans.graphic.listeners.GraphicListener;
29
import org.gvsig.gui.beans.doubleslider.DoubleSlider;
30
import org.gvsig.gui.beans.doubleslider.DoubleSliderEvent;
31
import org.gvsig.gui.beans.doubleslider.DoubleSliderListener;
32
import org.gvsig.gui.beans.textincreaser.TextIncreaserEvent;
33
import org.gvsig.gui.beans.textincreaser.TextIncreaserListener;
32 34

  
33 35
/**
34 36
 * Control para el manejo de un gr?fico.
......
36 38
 * @author Nacho Brodin (brodin_ign@gva.es)
37 39
 *
38 40
 */
39
public class GraphicContainer extends JPanel implements  ComponentListener {
41
public class GraphicContainer extends JPanel implements DoubleSliderListener, TextIncreaserListener {
40 42
	private static final long serialVersionUID = -6230083498345786500L;
41
	private static final int		INTERNAL_MARGIN = 4;
42
	private int						HEIGHT_DOUBLESLIDER = 25;
43
	private static final int		HEIGHT_BOXES = 30;
44 43
	
45 44
	private JPanel 					pGeneral = null;
46 45
	private GraphicChartPanel 		pGraphic = null;
47
	private JPanel 					pDoubleSlider = null;
46
	private JPanel 					panelSlider = null;
48 47
	private BoxesPanel 				pBoxes = null;
49
	private GraphicListener 		graphicListener = null;
50
	/**
51
	 * Variable que estar? a true si se desea que se muestre el control de barra deslizadora
52
	 */
53
	private	boolean 				showSlider = true;
48
	private DoubleSlider multiSlider;
49
	
50
	private ArrayList actionCommandListeners = new ArrayList();
51
	private boolean bDoCallListeners = true;
52
	static private int eventId = Integer.MIN_VALUE;
54 53

  
55 54
	public GraphicContainer() {
56
		graphicListener = new GraphicListener(this);
57 55
		initialize();
58 56
	}
59 57
	
60 58
	public GraphicContainer(boolean showSlider) {
61
		this.showSlider = showSlider;
62
		if (!showSlider)
63
			HEIGHT_DOUBLESLIDER = 0;
64
		graphicListener = new GraphicListener(this);
59
		getPDoubleSlider().setVisible(showSlider);
65 60
		initialize();
66 61
	}
67 62
	
68 63

  
69 64
	private void initialize() {
70
		FlowLayout layout = new FlowLayout();
71
		layout.setHgap(0);
72
		layout.setVgap(0);
73
		this.setLayout(layout);
74
		this.add(getPGeneral(), null);
75
		this.addComponentListener(this);
65
		this.setLayout(new BorderLayout(0, 4));
66
		this.add(getPGraphic(), BorderLayout.CENTER);
67
		this.add(getPGeneral(), BorderLayout.SOUTH);
76 68
	}
77 69
	
78 70
	/**
......
95 87
			gridBagConstraints.insets = new java.awt.Insets(0,0,0,0);
96 88
			gridBagConstraints.gridx = 0;
97 89
			pGeneral = new JPanel();
98
			pGeneral.setLayout(new GridBagLayout());
99
			pGeneral.add(getPGraphic(), gridBagConstraints);
100
			if(showSlider)
101
				pGeneral.add(getPDoubleSlider(), gridBagConstraints3);
102
			pGeneral.add(getPBoxes(), gridBagConstraints4);
90
			pGeneral.setLayout(new BorderLayout(0, 2));
91
			pGeneral.add(getPDoubleSlider(), BorderLayout.NORTH);
92
			pGeneral.add(getPBoxes(), BorderLayout.SOUTH);
103 93
		}
104 94
		return pGeneral;
105 95
	}
......
111 101
	 */
112 102
	public GraphicChartPanel getPGraphic() {
113 103
		if (pGraphic == null) {
114
			pGraphic = new GraphicChartPanel(this.getWidth() - INTERNAL_MARGIN, this.getHeight() - HEIGHT_BOXES - HEIGHT_DOUBLESLIDER);
104
			pGraphic = new GraphicChartPanel();
115 105
		}
116 106
		return pGraphic;
117 107
	}
......
121 111
	 * 	
122 112
	 * @return javax.swing.JPanel	
123 113
	 */
124
	private JPanel getPDoubleSlider() {
125
		if (pDoubleSlider == null) {
126
			pDoubleSlider = new DoubleSliderControlPanel(this.getWidth() - INTERNAL_MARGIN, HEIGHT_DOUBLESLIDER, graphicListener);
114
	private JComponent getPDoubleSlider() {
115
		if (panelSlider == null) {
116
			panelSlider = new JPanel();
117
			multiSlider = new DoubleSlider();
118
			multiSlider.addValueChangedListener(this);
119
			panelSlider.setLayout(new BorderLayout());
120
			panelSlider.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
121
//			panelSlider.setBorder(javax.swing.BorderFactory.createEtchedBorder());
122
			panelSlider.add(multiSlider, BorderLayout.CENTER);
127 123
		}
128
		return pDoubleSlider;
124
		return panelSlider;
129 125
	}
130 126

  
131 127
	/**
......
135 131
	 */
136 132
	private BoxesPanel getPBoxes() {
137 133
		if (pBoxes == null) {
138
			pBoxes = new BoxesPanel(this.getWidth() - INTERNAL_MARGIN, HEIGHT_BOXES);
134
			pBoxes = new BoxesPanel();
135
			pBoxes.getControlLeft().addValueChangedListener(this);
136
			pBoxes.getControlRight().addValueChangedListener(this);
139 137
		}
140 138
		return pBoxes;
141 139
	}
142 140
	
143
	/**
144
	 * Asigna el tama?o del componente
145
	 * @param w Nuevo ancho del componente padre
146
	 * @param h Nuevo alto del componente padre
147
	 */
148
	public void setComponentSize(int w, int h){
149
    setPreferredSize(new java.awt.Dimension(w, h));
150
		getPGraphic().setComponentSize(w - INTERNAL_MARGIN, h - HEIGHT_BOXES - HEIGHT_DOUBLESLIDER);
151
		if(this.showSlider){
152
			getPDoubleSlider().setPreferredSize(new java.awt.Dimension(w - INTERNAL_MARGIN, HEIGHT_DOUBLESLIDER));
153
		}
154
		((BoxesPanel)getPBoxes()).setComponentSize(w - INTERNAL_MARGIN, HEIGHT_BOXES);
155
		this.updateUI();
156
	}
157
	
158 141
	//****************************************************
159 142
	//M?TODOS DEL CONTROL
160 143

  
161
	/**
162
	 * Obtiene el valor de los controles. 
163
	 * @return Array con los valores de ambos controles. El primer valor del array es el control de la derecha
164
	 * y el segundo el de la izquierda.  
165
	 */
166
	public double[] getBoxesValues(){
167
		return getPBoxes().getBoxesValues();
144
	public double getX1() {
145
		return getPBoxes().getControlLeft().getValue();
168 146
	}
169
	
170
	/**
171
	 * Obtiene el bot?n de incremento del control izquierdo
172
	 * @return JButton. Bot?n de incremento del control izquierdo
173
	 */
174
	public JButton getPlusButtonControlLeft(){
175
		return this.getPBoxes().getControlLeft().getBmas();
176
	}
177
	
178
	/**
179
	 * Obtiene el bot?n de decremento del control izquierdo
180
	 * @return JButton. Bot?n de decremento del control izquierdo
181
	 */
182
	public JButton getLessButtonControlLeft(){
183
		return this.getPBoxes().getControlLeft().getBmenos();
184
	}
185
	
186
	/**
187
	 * Obtiene el bot?n de incremento del control derecho
188
	 * @return JButton. Bot?n de incremento del control derecho
189
	 */
190
	public JButton getPlusButtonControlRight(){
191
		return this.getPBoxes().getControlRight().getBmas();
192
	}
193
	
194
	/**
195
	 * Obtiene el bot?n de decremento del control derecho
196
	 * @return JButton. Bot?n de decremento del control derecho
197
	 */
198
	public JButton getLessButtonControlRight(){
199
		return this.getPBoxes().getControlRight().getBmenos();
200
	}
201
	
202
	/**
203
	 * Obtiene el JTextField de control derecho
204
	 * @return JTextField de control derecho
205
	 */
206
	public JTextField getTextControlRight(){
207
		return this.getPBoxes().getControlRight().getTText();
208
	}
209
	
210
	/**
211
	 * Obtiene el JTextField de control izquierdo
212
	 * @return JTextField de control izquierdo
213
	 */
214
	public JTextField getTextControlLeft(){
215
		return this.getPBoxes().getControlLeft().getTText();
216
	}
217 147

  
218
	public void componentResized(ComponentEvent e) {
219
		this.setComponentSize(this.getWidth(), this.getHeight());
148
	public double getX2() {
149
		return getPBoxes().getControlRight().getValue();
220 150
	}
221 151

  
222
	public void componentHidden(ComponentEvent e) {
223
		// TODO Auto-generated method stub
152
	public void actionValueChanged(DoubleSliderEvent e) {
153
		getPBoxes().getControlLeft().setValue(((DoubleSlider) e.getSource()).getX1());
154
		getPBoxes().getControlRight().setValue(((DoubleSlider) e.getSource()).getX2());
155
		callValueChangedListeners();
224 156
	}
225 157

  
226
	public void componentMoved(ComponentEvent e) {
227
		// TODO Auto-generated method stub	
158
	public void actionValueChanged(TextIncreaserEvent e) {
159
		if (e.getSource() == getPBoxes().getControlLeft()) {
160
			if (getPBoxes().getControlLeft().getValue() > getPBoxes().getControlRight().getValue())
161
				getPBoxes().getControlRight().setValue(getPBoxes().getControlLeft().getValue());
162
		}
163
		if (e.getSource() == getPBoxes().getControlRight()) {
164
			if (getPBoxes().getControlRight().getValue() < getPBoxes().getControlLeft().getValue())
165
				getPBoxes().getControlLeft().setValue(getPBoxes().getControlRight().getValue());
166
		}
167
		multiSlider.setX1((int) getPBoxes().getControlLeft().getValue());
168
		multiSlider.setX2((int) getPBoxes().getControlRight().getValue());
169
		callValueChangedListeners();
228 170
	}
171
	
172
	public void addValueChangedListener(GraphicListener listener) {
173
		if (!actionCommandListeners.contains(listener))
174
			actionCommandListeners.add(listener);
175
	}
229 176

  
230
	public void componentShown(ComponentEvent e) {
231
		// TODO Auto-generated method stub
177
	public void removeValueChangedListener(GraphicListener listener) {
178
		actionCommandListeners.remove(listener);
232 179
	}
180
	
181
	private void callValueChangedListeners() {
182
		if (!bDoCallListeners)
183
			return;
184
		Iterator acIterator = actionCommandListeners.iterator();
185
		while (acIterator.hasNext()) {
186
			GraphicListener listener = (GraphicListener) acIterator.next();
187
			listener.actionValueChanged(new GraphicEvent(this));
188
		}
189
		eventId++;
190
	}
191
	
233 192
}

Also available in: Unified diff