root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / graphic / GraphicContainer.java @ 11115
History | View | Annotate | Download (5.68 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 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.BorderLayout; |
22 |
import java.awt.Color; |
23 |
import java.util.ArrayList; |
24 |
import java.util.Iterator; |
25 |
|
26 |
import javax.swing.JComponent; |
27 |
import javax.swing.JPanel; |
28 |
|
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; |
34 |
|
35 |
/**
|
36 |
* Control para el manejo de un gr?fico.
|
37 |
*
|
38 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
39 |
*
|
40 |
*/
|
41 |
public class GraphicContainer extends JPanel implements DoubleSliderListener, TextIncreaserListener { |
42 |
private static final long serialVersionUID = -6230083498345786500L; |
43 |
|
44 |
private JPanel pGeneral = null; |
45 |
private GraphicChartPanel pGraphic = null; |
46 |
private JPanel panelSlider = null; |
47 |
private BoxesPanel pBoxes = null; |
48 |
private DoubleSlider multiSlider;
|
49 |
|
50 |
private ArrayList actionCommandListeners = new ArrayList(); |
51 |
private boolean bDoCallListeners = true; |
52 |
static private int eventId = Integer.MIN_VALUE; |
53 |
|
54 |
public GraphicContainer() {
|
55 |
initialize(); |
56 |
} |
57 |
|
58 |
public GraphicContainer(boolean showSlider) { |
59 |
getPDoubleSlider().setVisible(showSlider); |
60 |
initialize(); |
61 |
} |
62 |
|
63 |
|
64 |
private void initialize() { |
65 |
this.setLayout(new BorderLayout(0, 4)); |
66 |
this.add(getPGraphic(), BorderLayout.CENTER); |
67 |
this.add(getPGeneral(), BorderLayout.SOUTH); |
68 |
} |
69 |
|
70 |
/**
|
71 |
* This method initializes jPanel1
|
72 |
*
|
73 |
* @return javax.swing.JPanel
|
74 |
*/
|
75 |
private JPanel getPGeneral() { |
76 |
if (pGeneral == null) { |
77 |
pGeneral = new JPanel(); |
78 |
pGeneral.setLayout(new BorderLayout(0, 2)); |
79 |
pGeneral.add(getPDoubleSlider(), BorderLayout.NORTH);
|
80 |
pGeneral.add(getPBoxes(), BorderLayout.SOUTH);
|
81 |
} |
82 |
return pGeneral;
|
83 |
} |
84 |
|
85 |
/**
|
86 |
* This method initializes jPanel1
|
87 |
*
|
88 |
* @return javax.swing.JPanel
|
89 |
*/
|
90 |
public GraphicChartPanel getPGraphic() {
|
91 |
if (pGraphic == null) { |
92 |
pGraphic = new GraphicChartPanel();
|
93 |
} |
94 |
return pGraphic;
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* This method initializes jPanel1
|
99 |
*
|
100 |
* @return javax.swing.JPanel
|
101 |
*/
|
102 |
private JComponent getPDoubleSlider() { |
103 |
if (panelSlider == null) { |
104 |
panelSlider = new JPanel(); |
105 |
multiSlider = new DoubleSlider();
|
106 |
multiSlider.addValueChangedListener(this);
|
107 |
panelSlider.setLayout(new BorderLayout()); |
108 |
panelSlider.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); |
109 |
panelSlider.add(multiSlider, BorderLayout.CENTER);
|
110 |
} |
111 |
return panelSlider;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* This method initializes jPanel1
|
116 |
*
|
117 |
* @return javax.swing.JPanel
|
118 |
*/
|
119 |
private BoxesPanel getPBoxes() {
|
120 |
if (pBoxes == null) { |
121 |
pBoxes = new BoxesPanel();
|
122 |
pBoxes.getControlLeft().addValueChangedListener(this);
|
123 |
pBoxes.getControlRight().addValueChangedListener(this);
|
124 |
} |
125 |
return pBoxes;
|
126 |
} |
127 |
|
128 |
//****************************************************
|
129 |
//M?TODOS DEL CONTROL
|
130 |
|
131 |
public double getX1() { |
132 |
return getPBoxes().getControlLeft().getValue();
|
133 |
} |
134 |
|
135 |
public double getX2() { |
136 |
return getPBoxes().getControlRight().getValue();
|
137 |
} |
138 |
|
139 |
public void actionValueChanged(DoubleSliderEvent e) { |
140 |
getPBoxes().getControlLeft().setValue(((DoubleSlider) e.getSource()).getX1()); |
141 |
getPBoxes().getControlRight().setValue(((DoubleSlider) e.getSource()).getX2()); |
142 |
callValueChangedListeners(); |
143 |
} |
144 |
|
145 |
public void actionValueChanged(TextIncreaserEvent e) { |
146 |
if (e.getSource() == getPBoxes().getControlLeft()) {
|
147 |
if (getPBoxes().getControlLeft().getValue() > getPBoxes().getControlRight().getValue())
|
148 |
getPBoxes().getControlRight().setValue(getPBoxes().getControlLeft().getValue()); |
149 |
} |
150 |
if (e.getSource() == getPBoxes().getControlRight()) {
|
151 |
if (getPBoxes().getControlRight().getValue() < getPBoxes().getControlLeft().getValue())
|
152 |
getPBoxes().getControlLeft().setValue(getPBoxes().getControlRight().getValue()); |
153 |
} |
154 |
multiSlider.setX1((int) getPBoxes().getControlLeft().getValue());
|
155 |
multiSlider.setX2((int) getPBoxes().getControlRight().getValue());
|
156 |
callValueChangedListeners(); |
157 |
} |
158 |
|
159 |
public void addValueChangedListener(GraphicListener listener) { |
160 |
if (!actionCommandListeners.contains(listener))
|
161 |
actionCommandListeners.add(listener); |
162 |
} |
163 |
|
164 |
public void removeValueChangedListener(GraphicListener listener) { |
165 |
actionCommandListeners.remove(listener); |
166 |
} |
167 |
|
168 |
private void callValueChangedListeners() { |
169 |
if (!bDoCallListeners)
|
170 |
return;
|
171 |
Iterator acIterator = actionCommandListeners.iterator();
|
172 |
while (acIterator.hasNext()) {
|
173 |
GraphicListener listener = (GraphicListener) acIterator.next(); |
174 |
listener.actionValueChanged(new GraphicEvent(this)); |
175 |
} |
176 |
eventId++; |
177 |
} |
178 |
|
179 |
public void setBandVisible(int band, boolean visible) { |
180 |
getPGraphic().getChart().getChart().getXYPlot().getRenderer().setSeriesVisible(band, Boolean.valueOf(visible));
|
181 |
} |
182 |
|
183 |
public void setBandColor(int band, Color color) { |
184 |
getPGraphic().getChart().getChart().getXYPlot().getRenderer().setSeriesPaint(band, color); |
185 |
} |
186 |
} |