Revision 11004
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/doubleslider/TestDoubleSlider.java | ||
---|---|---|
1 |
package org.gvsig.gui.beans.doubleslider; |
|
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.Dimension; |
|
5 |
|
|
6 |
import javax.swing.JButton; |
|
7 |
import javax.swing.JFrame; |
|
8 |
import javax.swing.JPanel; |
|
9 |
|
|
10 |
import org.gvsig.gui.beans.doubleslider.DoubleSlider; |
|
11 |
|
|
12 |
public class TestDoubleSlider { |
|
13 |
|
|
14 |
private JFrame jFrame = new JFrame(); |
|
15 |
private DoubleSlider doubleSlider = null; |
|
16 |
private JPanel jPanel = null; |
|
17 |
|
|
18 |
public TestDoubleSlider() { |
|
19 |
jFrame = new JFrame(); |
|
20 |
jFrame.getContentPane().setLayout(new BorderLayout()); |
|
21 |
jFrame.setSize(new Dimension(498, 267)); |
|
22 |
jFrame.setContentPane(getJPanel()); |
|
23 |
jFrame.show(); |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* This method initializes multiSlider |
|
28 |
* |
|
29 |
* @return borsanza.src.multislider.MultiSlider |
|
30 |
*/ |
|
31 |
private DoubleSlider getMultiSlider() { |
|
32 |
if (doubleSlider == null) { |
|
33 |
doubleSlider = new DoubleSlider(); |
|
34 |
doubleSlider.setMinimum(0); |
|
35 |
doubleSlider.setMaximum(255); |
|
36 |
} |
|
37 |
return doubleSlider; |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* This method initializes jPanel |
|
42 |
* |
|
43 |
* @return javax.swing.JPanel |
|
44 |
*/ |
|
45 |
private JPanel getJPanel() { |
|
46 |
if (jPanel == null) { |
|
47 |
jPanel = new JPanel(); |
|
48 |
jPanel.setLayout(new BorderLayout()); |
|
49 |
jPanel.add(getMultiSlider(), BorderLayout.CENTER); |
|
50 |
} |
|
51 |
return jPanel; |
|
52 |
} |
|
53 |
|
|
54 |
public static void main(String[] args) { |
|
55 |
new TestDoubleSlider(); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
0 | 59 |
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/graphic/TestGraphic.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
6 | 6 |
|
7 |
public class TestGraphic { |
|
7 |
public class TestGraphic implements GraphicListener {
|
|
8 | 8 |
private JFrame frame=new JFrame(); |
9 | 9 |
private GraphicContainer graphic = null; |
10 | 10 |
|
11 | 11 |
public TestGraphic() throws NotInitializeException{ |
12 | 12 |
graphic = new GraphicContainer(true); |
13 |
graphic.addValueChangedListener(this); |
|
13 | 14 |
frame.getContentPane().add(graphic); |
14 | 15 |
frame.setSize(500, 300); |
15 | 16 |
frame.show(); |
... | ... | |
22 | 23 |
System.out.println("Tabla no inicializada"); |
23 | 24 |
} |
24 | 25 |
} |
26 |
|
|
27 |
public void actionValueChanged(GraphicEvent e) { |
|
28 |
System.out.println(graphic.getX1() + ":" + graphic.getX2()); |
|
29 |
} |
|
25 | 30 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/incrementabletask/IncrementableEvent.java | ||
---|---|---|
30 | 30 |
public IncrementableEvent(Object source) { |
31 | 31 |
super(source); |
32 | 32 |
} |
33 |
|
|
34 |
} |
|
33 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/doubleslider/DoubleSliderListener.java | ||
---|---|---|
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.doubleslider; |
|
20 |
|
|
21 |
import java.util.EventListener; |
|
22 |
|
|
23 |
public interface DoubleSliderListener extends EventListener { |
|
24 |
public void actionValueChanged(DoubleSliderEvent e); |
|
25 |
} |
|
0 | 26 |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/doubleslider/DoubleSlider.java | ||
---|---|---|
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.doubleslider; |
|
20 |
|
|
21 |
import java.awt.Color; |
|
22 |
import java.awt.Dimension; |
|
23 |
import java.awt.Graphics; |
|
24 |
import java.awt.Image; |
|
25 |
import java.awt.event.MouseEvent; |
|
26 |
import java.awt.event.MouseListener; |
|
27 |
import java.awt.event.MouseMotionListener; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Iterator; |
|
30 |
|
|
31 |
import javax.swing.JComponent; |
|
32 |
|
|
33 |
public class DoubleSlider extends JComponent implements MouseMotionListener, MouseListener { |
|
34 |
private static final long serialVersionUID = 663355422780987493L; |
|
35 |
|
|
36 |
Image bufferImage = null; |
|
37 |
int width, height = 0; |
|
38 |
Graphics bufferGraphics; |
|
39 |
int x1 = 0; |
|
40 |
int x2 = 100; |
|
41 |
|
|
42 |
int minimum = 0; |
|
43 |
int maximum = 100; |
|
44 |
|
|
45 |
private ArrayList actionCommandListeners = new ArrayList(); |
|
46 |
private boolean bDoCallListeners = true; |
|
47 |
static private int eventId = Integer.MIN_VALUE; |
|
48 |
|
|
49 |
public DoubleSlider() { |
|
50 |
this.setPreferredSize(new Dimension(100, 21)); |
|
51 |
} |
|
52 |
|
|
53 |
public void setMaximum(int value) { |
|
54 |
maximum = value; |
|
55 |
validateValues(); |
|
56 |
refreshImage(); |
|
57 |
} |
|
58 |
|
|
59 |
public void setMinimum(int value) { |
|
60 |
minimum = value; |
|
61 |
validateValues(); |
|
62 |
refreshImage(); |
|
63 |
} |
|
64 |
|
|
65 |
public void addNotify() { |
|
66 |
super.addNotify(); |
|
67 |
|
|
68 |
addMouseMotionListener(this); |
|
69 |
addMouseListener(this); |
|
70 |
|
|
71 |
refreshImage(); |
|
72 |
} |
|
73 |
|
|
74 |
private Graphics getBufferGraphics() { |
|
75 |
int width2=getBounds().width; |
|
76 |
int height2=getBounds().height; |
|
77 |
if (width2<=0) width2=1; |
|
78 |
if (height2<=0) height2=1; |
|
79 |
|
|
80 |
if ((width!=width2) || (height!=height2)) { |
|
81 |
bufferImage = createImage(width2, height2); |
|
82 |
if (bufferImage == null) return null; |
|
83 |
bufferGraphics = bufferImage.getGraphics(); |
|
84 |
} |
|
85 |
|
|
86 |
width = width2; |
|
87 |
height = height2; |
|
88 |
|
|
89 |
return bufferGraphics; |
|
90 |
} |
|
91 |
|
|
92 |
public void redrawBuffer() { |
|
93 |
if (getBufferGraphics() == null) return; |
|
94 |
getBufferGraphics().setColor(this.getBackground()); |
|
95 |
|
|
96 |
getBufferGraphics().fillRect(0,0,width,height); |
|
97 |
|
|
98 |
int color = 0; |
|
99 |
for (int i=1; i<=(width-1); i++) { |
|
100 |
color = (i*255)/width; |
|
101 |
getBufferGraphics().setColor(new Color(color,color,color)); |
|
102 |
getBufferGraphics().drawLine(i,1,i,12); |
|
103 |
} |
|
104 |
|
|
105 |
drawTriangle(valuetopixel(x1), Color.BLACK); |
|
106 |
drawTriangle(valuetopixel(x2), Color.WHITE); |
|
107 |
} |
|
108 |
|
|
109 |
private void drawTriangle(int x, Color color) { |
|
110 |
getBufferGraphics().setColor(color); |
|
111 |
getBufferGraphics().drawLine(x, 14, x, 18); |
|
112 |
getBufferGraphics().drawLine(x-1, 16, x-1, 18); |
|
113 |
getBufferGraphics().drawLine(x+1, 16, x+1, 18); |
|
114 |
getBufferGraphics().drawLine(x-2, 18, x-2, 18); |
|
115 |
getBufferGraphics().drawLine(x+2, 18, x+2, 18); |
|
116 |
|
|
117 |
getBufferGraphics().setColor(Color.BLACK); |
|
118 |
getBufferGraphics().drawLine(x, 12, x-3, 19); |
|
119 |
getBufferGraphics().drawLine(x, 12, x+3, 19); |
|
120 |
getBufferGraphics().drawLine(x-3, 19, x+3, 19); |
|
121 |
} |
|
122 |
|
|
123 |
public void refreshImage() { |
|
124 |
redrawBuffer(); |
|
125 |
if (bufferImage != null) |
|
126 |
getGraphics().drawImage(bufferImage, 0, 0, this); |
|
127 |
super.paint(getGraphics()); |
|
128 |
} |
|
129 |
|
|
130 |
private int valuetopixel(int value) { |
|
131 |
return ((value-minimum)*(width-3)/(maximum-minimum)) + 1; |
|
132 |
} |
|
133 |
|
|
134 |
private int pixeltovalue(int value) { |
|
135 |
return (((value-1)*(maximum-minimum))/(width-3))+minimum; |
|
136 |
} |
|
137 |
|
|
138 |
public void paint(Graphics g) { |
|
139 |
redrawBuffer(); |
|
140 |
g.drawImage(bufferImage, 0, 0, this); |
|
141 |
super.paint(g); |
|
142 |
} |
|
143 |
|
|
144 |
int valuePressed = 0; |
|
145 |
|
|
146 |
public void mousePressed(MouseEvent e) { |
|
147 |
if (e.getButton() != MouseEvent.BUTTON1) return; |
|
148 |
|
|
149 |
int aux = pixeltovalue(e.getX()+1); |
|
150 |
int aux2 = aux - x1; |
|
151 |
int aux3 = x2 - aux; |
|
152 |
if (aux3 < aux2) |
|
153 |
valuePressed = 2; |
|
154 |
else |
|
155 |
valuePressed = 1; |
|
156 |
|
|
157 |
changeValue(e.getX()); |
|
158 |
} |
|
159 |
|
|
160 |
public void mouseReleased(MouseEvent e) { |
|
161 |
valuePressed = 0; |
|
162 |
} |
|
163 |
|
|
164 |
private void validateValues() { |
|
165 |
if (x1 < minimum) x1 = minimum; |
|
166 |
if (x1 > maximum) x1 = maximum; |
|
167 |
if (x2 < minimum) x2 = minimum; |
|
168 |
if (x2 > maximum) x2 = maximum; |
|
169 |
} |
|
170 |
|
|
171 |
public void setX1(int value) { |
|
172 |
x1 = value; |
|
173 |
if (x1 > x2) x2 = x1; |
|
174 |
validateValues(); |
|
175 |
refreshImage(); |
|
176 |
} |
|
177 |
|
|
178 |
public void setX2(int value) { |
|
179 |
x2 = value; |
|
180 |
if (x2 < x1) x1 = x2; |
|
181 |
validateValues(); |
|
182 |
refreshImage(); |
|
183 |
} |
|
184 |
|
|
185 |
public int getX1() { |
|
186 |
return x1; |
|
187 |
} |
|
188 |
|
|
189 |
public int getX2() { |
|
190 |
return x2; |
|
191 |
} |
|
192 |
|
|
193 |
private void changeValue(int pos) { |
|
194 |
if (valuePressed == 0) return; |
|
195 |
|
|
196 |
int aux = pixeltovalue(pos + 1); |
|
197 |
|
|
198 |
if (valuePressed == 1) setX1(aux); |
|
199 |
if (valuePressed == 2) setX2(aux); |
|
200 |
callValueChangedListeners(); |
|
201 |
// System.out.println(x1 + ":" + x2); |
|
202 |
} |
|
203 |
|
|
204 |
public void mouseDragged(MouseEvent arg0) { |
|
205 |
changeValue(arg0.getX()); |
|
206 |
} |
|
207 |
|
|
208 |
public void mouseMoved(MouseEvent e) { |
|
209 |
} |
|
210 |
public void mouseClicked(MouseEvent e) { |
|
211 |
} |
|
212 |
public void mouseEntered(MouseEvent e) { |
|
213 |
} |
|
214 |
public void mouseExited(MouseEvent e) { |
|
215 |
} |
|
216 |
|
|
217 |
public void addValueChangedListener(DoubleSliderListener listener) { |
|
218 |
if (!actionCommandListeners.contains(listener)) |
|
219 |
actionCommandListeners.add(listener); |
|
220 |
} |
|
221 |
|
|
222 |
public void removeValueChangedListener(DoubleSliderListener listener) { |
|
223 |
actionCommandListeners.remove(listener); |
|
224 |
} |
|
225 |
|
|
226 |
private void callValueChangedListeners() { |
|
227 |
if (!bDoCallListeners) |
|
228 |
return; |
|
229 |
Iterator acIterator = actionCommandListeners.iterator(); |
|
230 |
while (acIterator.hasNext()) { |
|
231 |
DoubleSliderListener listener = (DoubleSliderListener) acIterator.next(); |
|
232 |
listener.actionValueChanged(new DoubleSliderEvent(this)); |
|
233 |
} |
|
234 |
eventId++; |
|
235 |
} |
|
236 |
|
|
237 |
} |
|
0 | 238 |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/doubleslider/DoubleSliderEvent.java | ||
---|---|---|
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.doubleslider; |
|
20 |
|
|
21 |
import java.util.EventObject; |
|
22 |
|
|
23 |
public class DoubleSliderEvent extends EventObject { |
|
24 |
private static final long serialVersionUID = -684281519921935004L; |
|
25 |
|
|
26 |
public DoubleSliderEvent(Object source) { |
|
27 |
super(source); |
|
28 |
} |
|
29 |
} |
|
0 | 30 |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/DoubleSliderControlPanel.java | ||
---|---|---|
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.graphic; |
|
20 |
|
|
21 |
import java.awt.Color; |
|
22 |
import java.awt.FlowLayout; |
|
23 |
|
|
24 |
import javax.swing.JLabel; |
|
25 |
import javax.swing.JPanel; |
|
26 |
|
|
27 |
import org.gvsig.gui.beans.graphic.listeners.GraphicListener; |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
* Nacho Brodin (brodin_ign@gva.es) |
|
32 |
*/ |
|
33 |
|
|
34 |
public class DoubleSliderControlPanel extends JPanel { |
|
35 |
private static final long serialVersionUID = -6123036808118349791L; |
|
36 |
private int width = 300, height = 25; |
|
37 |
private JLabel lLeft = null; |
|
38 |
private JLabel lRight = null; |
|
39 |
private GraphicListener graphicListener = null; |
|
40 |
private JPanel pRight = null; |
|
41 |
private JPanel pLeft = null; |
|
42 |
|
|
43 |
public DoubleSliderControlPanel(int width, int height, GraphicListener graphicListener) { |
|
44 |
super(); |
|
45 |
this.width = width; |
|
46 |
this.height = height; |
|
47 |
this.graphicListener = graphicListener; |
|
48 |
initialize(); |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* This method initializes this |
|
53 |
* |
|
54 |
*/ |
|
55 |
private void initialize() { |
|
56 |
FlowLayout flowLayout = new FlowLayout(); |
|
57 |
flowLayout.setHgap(0); |
|
58 |
flowLayout.setAlignment(java.awt.FlowLayout.LEFT); |
|
59 |
flowLayout.setVgap(0); |
|
60 |
|
|
61 |
/*lRight = new JLabel(); |
|
62 |
lRight.setForeground(Color.RED); |
|
63 |
lRight.setText("T"); |
|
64 |
lRight.setPreferredSize(new java.awt.Dimension(15,25)); |
|
65 |
|
|
66 |
lLeft = new JLabel(); |
|
67 |
lLeft.setForeground(Color.BLUE); |
|
68 |
lLeft.setText("T"); |
|
69 |
lLeft.setPreferredSize(new java.awt.Dimension(15,25)); |
|
70 |
this.setLayout(flowLayout); |
|
71 |
|
|
72 |
lRight.addMouseListener(graphicListener); |
|
73 |
lRight.addMouseMotionListener(graphicListener); |
|
74 |
lLeft.addMouseListener(graphicListener); |
|
75 |
lLeft.addMouseMotionListener(graphicListener); |
|
76 |
graphicListener.setLabels(lLeft, lRight);*/ |
|
77 |
|
|
78 |
this.setLayout(flowLayout); |
|
79 |
this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1)); |
|
80 |
this.setSize(new java.awt.Dimension(width, height)); |
|
81 |
this.setPreferredSize(new java.awt.Dimension(width, height)); |
|
82 |
|
|
83 |
this.add(getPLeft(), null); |
|
84 |
this.add(getPRight(), null); |
|
85 |
graphicListener.setLabels(lLeft, lRight); |
|
86 |
|
|
87 |
//lLeft.setLocation(28, 4); |
|
88 |
//lRight.setLocation(470, 4); |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* This method initializes jPanel |
|
94 |
* |
|
95 |
* @return javax.swing.JPanel |
|
96 |
*/ |
|
97 |
private JPanel getPRight() { |
|
98 |
if (pRight == null) { |
|
99 |
FlowLayout flowLayout1 = new FlowLayout(); |
|
100 |
flowLayout1.setHgap(0); |
|
101 |
flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT); |
|
102 |
flowLayout1.setVgap(0); |
|
103 |
lRight = new JLabel(); |
|
104 |
lRight.setText("T"); |
|
105 |
lRight.setForeground(Color.RED); |
|
106 |
lRight.setPreferredSize(new java.awt.Dimension(15,22)); |
|
107 |
pRight = new JPanel(); |
|
108 |
pRight.setLayout(flowLayout1); |
|
109 |
pRight.setPreferredSize(new java.awt.Dimension((width >> 1) - 2,20)); |
|
110 |
pRight.setSize(width >> 1,20); |
|
111 |
pRight.add(lRight, null); |
|
112 |
lRight.addMouseListener(graphicListener); |
|
113 |
lRight.addMouseMotionListener(graphicListener); |
|
114 |
} |
|
115 |
return pRight; |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* This method initializes jPanel1 |
|
120 |
* |
|
121 |
* @return javax.swing.JPanel |
|
122 |
*/ |
|
123 |
private JPanel getPLeft() { |
|
124 |
if (pLeft == null) { |
|
125 |
FlowLayout flowLayout1 = new FlowLayout(); |
|
126 |
flowLayout1.setHgap(28); |
|
127 |
flowLayout1.setAlignment(java.awt.FlowLayout.LEFT); |
|
128 |
flowLayout1.setVgap(0); |
|
129 |
lLeft = new JLabel(); |
|
130 |
lLeft.setText("T"); |
|
131 |
lLeft.setForeground(Color.BLUE); |
|
132 |
lLeft.setPreferredSize(new java.awt.Dimension(15,22)); |
|
133 |
pLeft = new JPanel(); |
|
134 |
pLeft.setLayout(flowLayout1); |
|
135 |
pLeft.setPreferredSize(new java.awt.Dimension((width >> 1) - 2,20)); |
|
136 |
pLeft.setSize(width >> 1,20); |
|
137 |
pLeft.add(lLeft, null); |
|
138 |
lLeft.addMouseListener(graphicListener); |
|
139 |
lLeft.addMouseMotionListener(graphicListener); |
|
140 |
} |
|
141 |
return pLeft; |
|
142 |
} |
|
143 |
|
|
144 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/BoxesPanel.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.gui.beans.graphic; |
20 | 20 |
|
21 |
import java.awt.BorderLayout; |
|
21 | 22 |
import java.awt.FlowLayout; |
22 | 23 |
|
23 | 24 |
import javax.swing.JPanel; |
... | ... | |
31 | 32 |
|
32 | 33 |
public class BoxesPanel extends JPanel { |
33 | 34 |
private static final long serialVersionUID = -4117483555280497312L; |
34 |
private int width = 300, height = 30; |
|
35 | 35 |
private JPanel pLeft = null; |
36 | 36 |
private JPanel pRight = null; |
37 | 37 |
private TextIncreaserContainer controlLeft = null; |
38 | 38 |
private TextIncreaserContainer controlRight = null; |
39 |
public BoxesPanel(int width, int height) {
|
|
39 |
public BoxesPanel() { |
|
40 | 40 |
super(); |
41 |
this.width = width; |
|
42 |
this.height = height; |
|
43 | 41 |
initialize(); |
44 | 42 |
} |
45 | 43 |
|
... | ... | |
48 | 46 |
* |
49 | 47 |
*/ |
50 | 48 |
private void initialize() { |
51 |
FlowLayout flowLayout = new FlowLayout(); |
|
52 |
flowLayout.setHgap(0); |
|
53 |
flowLayout.setVgap(0); |
|
54 |
this.setLayout(flowLayout); |
|
55 |
this.setSize(new java.awt.Dimension(width, height)); |
|
56 |
this.setPreferredSize(new java.awt.Dimension(width, height)); |
|
57 |
this.add(getPLeft(), null); |
|
58 |
this.add(getPRight(), null); |
|
59 |
|
|
49 |
this.setLayout(new BorderLayout()); |
|
50 |
this.add(getPLeft(), BorderLayout.WEST); |
|
51 |
this.add(getPRight(), BorderLayout.EAST); |
|
60 | 52 |
} |
61 | 53 |
|
62 | 54 |
/** |
... | ... | |
73 | 65 |
pLeft = new JPanel(); |
74 | 66 |
pLeft.setLayout(flowLayout1); |
75 | 67 |
pLeft.add(getControlLeft(), null); |
76 |
pLeft.setSize(new java.awt.Dimension(width >> 1, height)); |
|
77 |
pLeft.setPreferredSize(new java.awt.Dimension(width >> 1, height)); |
|
68 |
pLeft.setPreferredSize(new java.awt.Dimension(100, 30)); |
|
78 | 69 |
} |
79 | 70 |
return pLeft; |
80 | 71 |
} |
... | ... | |
93 | 84 |
pRight = new JPanel(); |
94 | 85 |
pRight.setLayout(flowLayout2); |
95 | 86 |
pRight.add(getControlRight(), null); |
96 |
pRight.setSize(new java.awt.Dimension(width >> 1, height)); |
|
97 |
pRight.setPreferredSize(new java.awt.Dimension(width >> 1, height)); |
|
87 |
pRight.setPreferredSize(new java.awt.Dimension(100, 30)); |
|
98 | 88 |
} |
99 | 89 |
return pRight; |
100 | 90 |
} |
... | ... | |
122 | 112 |
} |
123 | 113 |
return controlRight; |
124 | 114 |
} |
125 |
|
|
126 |
/** |
|
127 |
* Asigna el tama?o del componente |
|
128 |
* @param w Nuevo ancho del componente padre |
|
129 |
* @param h Nuevo alto del componente padre |
|
130 |
*/ |
|
131 |
public void setComponentSize(int w, int h){ |
|
132 |
this.width = w; |
|
133 |
this.height = h; |
|
134 |
setSize(w, h); |
|
135 |
setPreferredSize(new java.awt.Dimension(w, h)); |
|
136 |
getPRight().setSize(w >> 1, h); |
|
137 |
getPRight().setPreferredSize(new java.awt.Dimension(w >> 1, h)); |
|
138 |
getPLeft().setSize(w >> 1, h); |
|
139 |
getPLeft().setPreferredSize(new java.awt.Dimension(w >> 1, h)); |
|
140 |
|
|
141 |
} |
|
142 |
|
|
115 |
|
|
143 | 116 |
//**************************************************** |
144 | 117 |
//M?TODOS DEL CONTROL |
145 | 118 |
|
... | ... | |
154 | 127 |
v[1] = getControlLeft().getValue(); |
155 | 128 |
return v; |
156 | 129 |
} |
157 |
} |
|
130 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/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 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/GraphicListener.java | ||
---|---|---|
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.graphic; |
|
20 |
|
|
21 |
import java.util.EventListener; |
|
22 |
|
|
23 |
public interface GraphicListener extends EventListener { |
|
24 |
public void actionValueChanged(GraphicEvent e); |
|
25 |
} |
|
0 | 26 |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/listeners/GraphicListener.java | ||
---|---|---|
34 | 34 |
* |
35 | 35 |
*/ |
36 | 36 |
public class GraphicListener implements MouseListener, ActionListener, MouseMotionListener{ |
37 |
|
|
38 |
private GraphicContainer graphicContainer = null; |
|
39 | 37 |
private boolean move = false; |
40 | 38 |
private JLabel left = null; |
41 | 39 |
private JLabel right = null; |
42 | 40 |
|
43 |
public GraphicListener(GraphicContainer graphicContainer){ |
|
44 |
this.graphicContainer = graphicContainer; |
|
41 |
public GraphicListener() { |
|
45 | 42 |
} |
46 | 43 |
|
47 | 44 |
public void mouseDragged(MouseEvent e) { |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/GraphicChartPanel.java | ||
---|---|---|
19 | 19 |
package org.gvsig.gui.beans.graphic; |
20 | 20 |
|
21 | 21 |
import java.awt.BasicStroke; |
22 |
import java.awt.BorderLayout; |
|
22 | 23 |
import java.awt.Color; |
23 |
import java.awt.FlowLayout; |
|
24 | 24 |
|
25 | 25 |
import javax.swing.JPanel; |
26 | 26 |
|
... | ... | |
40 | 40 |
|
41 | 41 |
public class GraphicChartPanel extends JPanel { |
42 | 42 |
private static final long serialVersionUID = 7328137487119964665L; |
43 |
private static final int HEIGHT_MARGIN = 5; |
|
44 |
private static final int WIDTH_MARGIN = 4; |
|
45 | 43 |
private JFreeChart chart; |
46 | 44 |
private ChartPanel jPanelChart = null; |
47 | 45 |
private XYSeries series[] = null; |
48 | 46 |
private XYSeriesCollection dataset = null; |
49 |
private int width = 300, height = 150; |
|
50 | 47 |
|
51 |
|
|
52 |
public GraphicChartPanel(int width, int height) { |
|
53 |
this.width = width; |
|
54 |
this.height = height; |
|
55 |
|
|
48 |
public GraphicChartPanel() { |
|
56 | 49 |
int nSeries = 3; |
57 | 50 |
|
58 | 51 |
series = new XYSeries[nSeries]; |
... | ... | |
79 | 72 |
* |
80 | 73 |
*/ |
81 | 74 |
private void initialize() { |
82 |
FlowLayout flowLayout = new FlowLayout(); |
|
83 |
flowLayout.setVgap(0); |
|
84 |
flowLayout.setHgap(0); |
|
85 |
this.setLayout(flowLayout); |
|
86 |
this.setSize(new java.awt.Dimension(width, height)); |
|
87 |
this.setPreferredSize(new java.awt.Dimension(width, height)); |
|
88 |
this.add(getChart(), null); |
|
75 |
this.setLayout(new BorderLayout()); |
|
76 |
this.add(getChart(), BorderLayout.CENTER); |
|
89 | 77 |
} |
90 | 78 |
|
91 | 79 |
/** |
... | ... | |
95 | 83 |
public ChartPanel getChart(){ |
96 | 84 |
if(jPanelChart == null){ |
97 | 85 |
jPanelChart = new ChartPanel(chart); |
98 |
jPanelChart.setSize(new java.awt.Dimension(width - WIDTH_MARGIN, height - HEIGHT_MARGIN)); |
|
99 |
jPanelChart.setPreferredSize(new java.awt.Dimension(width - WIDTH_MARGIN, height - HEIGHT_MARGIN)); |
|
100 | 86 |
jPanelChart.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1)); |
101 | 87 |
} |
102 | 88 |
return jPanelChart; |
... | ... | |
171 | 157 |
dataset.removeAllSeries(); |
172 | 158 |
jPanelChart.repaint(); |
173 | 159 |
} |
174 |
|
|
175 |
/** |
|
176 |
* Asigna el tama?o del componente |
|
177 |
* @param w Nuevo ancho del componente padre |
|
178 |
* @param h Nuevo alto del componente padre |
|
179 |
*/ |
|
180 |
public void setComponentSize(int w, int h){ |
|
181 |
width = w; |
|
182 |
height = h; |
|
183 |
this.setSize(new java.awt.Dimension(w, h)); |
|
184 |
this.setPreferredSize(new java.awt.Dimension(w, h)); |
|
185 |
jPanelChart.setSize(new java.awt.Dimension(w - WIDTH_MARGIN, h - HEIGHT_MARGIN)); |
|
186 |
jPanelChart.setPreferredSize(new java.awt.Dimension(w - WIDTH_MARGIN, h - HEIGHT_MARGIN)); |
|
187 |
} |
|
188 |
} |
|
160 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/GraphicEvent.java | ||
---|---|---|
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.graphic; |
|
20 |
|
|
21 |
import java.util.EventObject; |
|
22 |
|
|
23 |
public class GraphicEvent extends EventObject { |
|
24 |
private static final long serialVersionUID = -684281519921935004L; |
|
25 |
|
|
26 |
public GraphicEvent(Object source) { |
|
27 |
super(source); |
|
28 |
} |
|
29 |
} |
|
0 | 30 |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/textincreaser/TextIncreaserEvent.java | ||
---|---|---|
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.textincreaser; |
|
20 |
|
|
21 |
import java.util.EventObject; |
|
22 |
|
|
23 |
public class TextIncreaserEvent extends EventObject { |
|
24 |
private static final long serialVersionUID = -684281519921935004L; |
|
25 |
|
|
26 |
public TextIncreaserEvent(Object source) { |
|
27 |
super(source); |
|
28 |
} |
|
29 |
} |
|
0 | 30 |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/textincreaser/TextIncreaserContainer.java | ||
---|---|---|
23 | 23 |
import java.awt.GridBagLayout; |
24 | 24 |
import java.awt.event.ActionEvent; |
25 | 25 |
import java.awt.event.ActionListener; |
26 |
import java.awt.event.KeyEvent; |
|
27 |
import java.awt.event.KeyListener; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Iterator; |
|
26 | 30 |
|
27 | 31 |
import javax.swing.ImageIcon; |
28 | 32 |
import javax.swing.JButton; |
... | ... | |
36 | 40 |
* Nacho Brodin (brodin_ign@gva.es) |
37 | 41 |
*/ |
38 | 42 |
|
39 |
public class TextIncreaserContainer extends BaseComponent implements ActionListener{ |
|
43 |
public class TextIncreaserContainer extends BaseComponent implements ActionListener, KeyListener{
|
|
40 | 44 |
private static final long serialVersionUID = 7570162018139822874L; |
41 | 45 |
private int width = 70; |
42 | 46 |
private JTextField tText = null; |
... | ... | |
46 | 50 |
private JPanel pGeneral = null; |
47 | 51 |
private double minValue = 0; |
48 | 52 |
private double maxValue = 100; |
49 |
private double init = 0;
|
|
53 |
private double value = 0.0;
|
|
50 | 54 |
private String pathToImages = "images/";//"/com/iver/cit/gvsig/gui/panels/images/"; |
51 | 55 |
/** |
52 | 56 |
* Variable que est? a true si los controles est?n a la derecha |
53 | 57 |
*/ |
54 | 58 |
private boolean isRight = true; |
55 | 59 |
|
60 |
private ArrayList actionCommandListeners = new ArrayList(); |
|
61 |
private boolean bDoCallListeners = true; |
|
62 |
static private int eventId = Integer.MIN_VALUE; |
|
63 |
|
|
56 | 64 |
/** |
57 | 65 |
* Creaci?n de un componente TextIncrearserContainer |
58 | 66 |
* @param width Ancho del componente |
... | ... | |
67 | 75 |
this.minValue = minValue; |
68 | 76 |
this.maxValue = maxValue; |
69 | 77 |
this.isRight = right; |
70 |
this.init = init;
|
|
78 |
this.value = init;
|
|
71 | 79 |
initialize(); |
72 | 80 |
} |
73 | 81 |
|
... | ... | |
95 | 103 |
* @param value |
96 | 104 |
*/ |
97 | 105 |
public void setValue(double value){ |
106 |
this.value = value; |
|
98 | 107 |
getTText().setText(Double.toString(value)); |
99 | 108 |
} |
100 | 109 |
|
... | ... | |
103 | 112 |
* @return value |
104 | 113 |
*/ |
105 | 114 |
public double getValue(){ |
106 |
try{ |
|
107 |
Double.valueOf(getTText().getText()).doubleValue(); |
|
108 |
}catch(NumberFormatException exc){ |
|
109 |
getTText().setText("0.0"); |
|
110 |
return 0; |
|
111 |
} |
|
112 |
return Double.valueOf(getTText().getText()).doubleValue(); |
|
115 |
return value; |
|
113 | 116 |
} |
114 | 117 |
|
115 | 118 |
/** |
... | ... | |
117 | 120 |
* |
118 | 121 |
* @return javax.swing.JTextField |
119 | 122 |
*/ |
120 |
public JTextField getTText() {
|
|
123 |
private JTextField getTText() {
|
|
121 | 124 |
if (tText == null) { |
122 | 125 |
tText = new JTextField(); |
123 |
tText.setText(Double.toString(init));
|
|
126 |
tText.setText(Double.toString(value));
|
|
124 | 127 |
tText.setPreferredSize(new java.awt.Dimension(width - 25,25)); |
128 |
tText.addKeyListener(this); |
|
125 | 129 |
} |
126 | 130 |
return tText; |
127 | 131 |
} |
... | ... | |
155 | 159 |
* |
156 | 160 |
* @return javax.swing.JButton |
157 | 161 |
*/ |
158 |
public JButton getBmas() {
|
|
162 |
private JButton getBmas() {
|
|
159 | 163 |
if (bmas == null) { |
160 | 164 |
bmas = new JButton(); |
161 | 165 |
bmas.setPreferredSize(new java.awt.Dimension(25,12)); |
... | ... | |
170 | 174 |
* |
171 | 175 |
* @return javax.swing.JButton |
172 | 176 |
*/ |
173 |
public JButton getBmenos() {
|
|
177 |
private JButton getBmenos() {
|
|
174 | 178 |
if (bmenos == null) { |
175 | 179 |
bmenos = new JButton(); |
176 | 180 |
bmenos.setPreferredSize(new java.awt.Dimension(25,12)); |
... | ... | |
211 | 215 |
} |
212 | 216 |
|
213 | 217 |
public void actionPerformed(ActionEvent e) { |
214 |
double value = Double.parseDouble(getTText().getText()); |
|
215 |
if(e.getSource() == bmas){ |
|
218 |
if (e.getSource() == bmas) { |
|
216 | 219 |
value ++; |
217 |
if(value <= maxValue) |
|
218 |
tText.setText(Double.toString(value)); |
|
220 |
checkValues(); |
|
219 | 221 |
} |
220 | 222 |
|
221 |
if(e.getSource() == bmenos){
|
|
223 |
if (e.getSource() == bmenos) {
|
|
222 | 224 |
value --; |
223 |
if(value >= minValue) |
|
224 |
tText.setText(Double.toString(value)); |
|
225 |
checkValues(); |
|
225 | 226 |
} |
227 |
callValueChangedListeners(); |
|
226 | 228 |
} |
229 |
|
|
230 |
public void addValueChangedListener(TextIncreaserListener listener) { |
|
231 |
if (!actionCommandListeners.contains(listener)) |
|
232 |
actionCommandListeners.add(listener); |
|
233 |
} |
|
227 | 234 |
|
235 |
public void removeValueChangedListener(TextIncreaserListener listener) { |
|
236 |
actionCommandListeners.remove(listener); |
|
237 |
} |
|
238 |
|
|
239 |
private void callValueChangedListeners() { |
|
240 |
if (!bDoCallListeners) |
|
241 |
return; |
|
242 |
Iterator acIterator = actionCommandListeners.iterator(); |
|
243 |
while (acIterator.hasNext()) { |
|
244 |
TextIncreaserListener listener = (TextIncreaserListener) acIterator.next(); |
|
245 |
listener.actionValueChanged(new TextIncreaserEvent(this)); |
|
246 |
} |
|
247 |
eventId++; |
|
248 |
} |
|
249 |
|
|
250 |
private void checkValues() { |
|
251 |
if (value >= maxValue) value = maxValue; |
|
252 |
if (value <= minValue) value = minValue; |
|
253 |
tText.setText(Double.toString(value)); |
|
254 |
} |
|
255 |
|
|
256 |
public void keyPressed(KeyEvent e) { |
|
257 |
if (e.getKeyCode() == 10) { |
|
258 |
try { |
|
259 |
value = Double.valueOf(getTText().getText()).doubleValue(); |
|
260 |
} catch(NumberFormatException exc) { |
|
261 |
} |
|
262 |
|
|
263 |
checkValues(); |
|
264 |
callValueChangedListeners(); |
|
265 |
} |
|
266 |
} |
|
267 |
|
|
268 |
public void keyReleased(KeyEvent e) { |
|
269 |
// TODO Auto-generated method stub |
|
270 |
|
|
271 |
} |
|
272 |
|
|
273 |
public void keyTyped(KeyEvent e) { |
|
274 |
// TODO Auto-generated method stub |
|
275 |
|
|
276 |
} |
|
277 |
|
|
228 | 278 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/textincreaser/TextIncreaserListener.java | ||
---|---|---|
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.textincreaser; |
|
20 |
|
|
21 |
import java.util.EventListener; |
|
22 |
|
|
23 |
public interface TextIncreaserListener extends EventListener { |
|
24 |
public void actionValueChanged(TextIncreaserEvent e); |
|
25 |
} |
|
0 | 26 |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramPanelListener.java | ||
---|---|---|
21 | 21 |
import java.awt.event.ActionEvent; |
22 | 22 |
import java.awt.event.ActionListener; |
23 | 23 |
import java.awt.event.KeyEvent; |
24 |
import java.awt.event.KeyListener; |
|
25 | 24 |
import java.util.ArrayList; |
26 | 25 |
|
27 | 26 |
import javax.swing.JButton; |
28 | 27 |
import javax.swing.JComboBox; |
29 | 28 |
|
29 |
import org.gvsig.gui.beans.graphic.GraphicEvent; |
|
30 |
import org.gvsig.gui.beans.graphic.GraphicListener; |
|
30 | 31 |
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent; |
31 | 32 |
import org.gvsig.gui.beans.incrementabletask.IncrementableListener; |
32 | 33 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
33 | 34 |
import org.gvsig.raster.util.Histogram; |
34 | 35 |
import org.gvsig.raster.util.IHistogramable; |
35 | 36 |
import org.gvsig.rastertools.histogram.ui.HistogramPanel; |
36 |
|
|
37 |
import com.iver.utiles.swing.threads.Cancellable; |
|
38 | 37 |
/** |
39 | 38 |
* Listener para eventos del panel de histograma |
40 | 39 |
* |
... | ... | |
42 | 41 |
* @author Nacho Brodin (brodin_ign@gva.es) |
43 | 42 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es) |
44 | 43 |
*/ |
45 |
public class HistogramPanelListener implements ActionListener, KeyListener, IncrementableListener {
|
|
44 |
public class HistogramPanelListener implements IncrementableListener, GraphicListener, ActionListener {
|
|
46 | 45 |
private HistogramPanel histogramPanel = null; |
47 | 46 |
private IncrementableTask incrementableTask = null; |
48 | 47 |
private HistogramProcess histogramProcess = null; |
... | ... | |
50 | 49 |
private int bandCount = 0; |
51 | 50 |
|
52 | 51 |
public boolean comboEventEnable = false; |
52 |
|
|
53 |
private boolean[] showBands = {true, true, true}; |
|
54 |
|
|
53 | 55 |
|
54 | 56 |
public HistogramPanelListener(HistogramPanel p){ |
55 | 57 |
histogramPanel = p; |
56 | 58 |
} |
57 | 59 |
|
58 | 60 |
public void setControlListeners(){ |
59 |
histogramPanel.getGraphicContainer().getPlusButtonControlLeft().addActionListener(this); |
|
60 |
histogramPanel.getGraphicContainer().getPlusButtonControlRight().addActionListener(this); |
|
61 |
histogramPanel.getGraphicContainer().getLessButtonControlLeft().addActionListener(this); |
|
62 |
histogramPanel.getGraphicContainer().getLessButtonControlRight().addActionListener(this); |
|
63 |
histogramPanel.getGraphicContainer().getTextControlRight().addKeyListener(this); |
|
64 |
histogramPanel.getGraphicContainer().getTextControlLeft().addKeyListener(this); |
|
61 |
histogramPanel.getGraphicContainer().addValueChangedListener(this); |
|
65 | 62 |
} |
66 | 63 |
|
67 | 64 |
|
68 |
public void keyPressed(KeyEvent e) { |
|
69 |
if (e.getKeyCode() == 10) { |
|
70 |
updateStatistic(); |
|
71 |
updateGraphic(); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 | 65 |
private void updateStatistic() { |
76 | 66 |
// TODO Actualizar tabla de los histogramas. |
77 | 67 |
// histogramPanel.setStatistic(DatasetStatistics.getBasicStatsFromHistogram(getLastHistogram(), (int)panel.getBoxesValues()[1], (int)panel.getBoxesValues()[0], panel.showBands)); |
78 | 68 |
} |
79 | 69 |
|
80 |
|
|
81 | 70 |
public void actionPerformed(ActionEvent e) { |
82 |
//Botones de m?s y menos |
|
83 |
if (e.getSource() == histogramPanel.getGraphicContainer().getPlusButtonControlLeft() || |
|
84 |
e.getSource() == histogramPanel.getGraphicContainer().getLessButtonControlLeft() || |
|
85 |
e.getSource() == histogramPanel.getGraphicContainer().getPlusButtonControlRight() || |
|
86 |
e.getSource() == histogramPanel.getGraphicContainer().getLessButtonControlRight() ) { |
|
87 |
updateStatistic(); |
|
88 |
updateGraphic(); |
|
89 |
return; |
|
90 |
} |
|
91 |
|
|
92 | 71 |
//-------------------------------------- |
93 | 72 |
//Cambiar las bandas en el combo |
94 | 73 |
JComboBox cbb = histogramPanel.getJComboBands(); |
Also available in: Unified diff