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