svn-gvsig-desktop / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / graphic / GraphicContainer.java @ 11004
History | View | Annotate | Download (6.04 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.GridBagConstraints; |
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 |
GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
78 |
gridBagConstraints4.gridy = 2;
|
79 |
gridBagConstraints4.insets = new java.awt.Insets(2,0,0,0); |
80 |
gridBagConstraints4.gridwidth = 0;
|
81 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
82 |
gridBagConstraints3.gridy = 1;
|
83 |
gridBagConstraints3.insets = new java.awt.Insets(2,0,0,0); |
84 |
gridBagConstraints3.gridx = 0;
|
85 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
86 |
gridBagConstraints.gridy = 0;
|
87 |
gridBagConstraints.insets = new java.awt.Insets(0,0,0,0); |
88 |
gridBagConstraints.gridx = 0;
|
89 |
pGeneral = new JPanel(); |
90 |
pGeneral.setLayout(new BorderLayout(0, 2)); |
91 |
pGeneral.add(getPDoubleSlider(), BorderLayout.NORTH);
|
92 |
pGeneral.add(getPBoxes(), BorderLayout.SOUTH);
|
93 |
} |
94 |
return pGeneral;
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* This method initializes jPanel1
|
99 |
*
|
100 |
* @return javax.swing.JPanel
|
101 |
*/
|
102 |
public GraphicChartPanel getPGraphic() {
|
103 |
if (pGraphic == null) { |
104 |
pGraphic = new GraphicChartPanel();
|
105 |
} |
106 |
return pGraphic;
|
107 |
} |
108 |
|
109 |
/**
|
110 |
* This method initializes jPanel1
|
111 |
*
|
112 |
* @return javax.swing.JPanel
|
113 |
*/
|
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);
|
123 |
} |
124 |
return panelSlider;
|
125 |
} |
126 |
|
127 |
/**
|
128 |
* This method initializes jPanel1
|
129 |
*
|
130 |
* @return javax.swing.JPanel
|
131 |
*/
|
132 |
private BoxesPanel getPBoxes() {
|
133 |
if (pBoxes == null) { |
134 |
pBoxes = new BoxesPanel();
|
135 |
pBoxes.getControlLeft().addValueChangedListener(this);
|
136 |
pBoxes.getControlRight().addValueChangedListener(this);
|
137 |
} |
138 |
return pBoxes;
|
139 |
} |
140 |
|
141 |
//****************************************************
|
142 |
//M?TODOS DEL CONTROL
|
143 |
|
144 |
public double getX1() { |
145 |
return getPBoxes().getControlLeft().getValue();
|
146 |
} |
147 |
|
148 |
public double getX2() { |
149 |
return getPBoxes().getControlRight().getValue();
|
150 |
} |
151 |
|
152 |
public void actionValueChanged(DoubleSliderEvent e) { |
153 |
getPBoxes().getControlLeft().setValue(((DoubleSlider) e.getSource()).getX1()); |
154 |
getPBoxes().getControlRight().setValue(((DoubleSlider) e.getSource()).getX2()); |
155 |
callValueChangedListeners(); |
156 |
} |
157 |
|
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(); |
170 |
} |
171 |
|
172 |
public void addValueChangedListener(GraphicListener listener) { |
173 |
if (!actionCommandListeners.contains(listener))
|
174 |
actionCommandListeners.add(listener); |
175 |
} |
176 |
|
177 |
public void removeValueChangedListener(GraphicListener listener) { |
178 |
actionCommandListeners.remove(listener); |
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 |
|
192 |
} |