root / branches / gvSIG_GisPlanet / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Panels / AdjustTransparencyPanel.java @ 2231
History | View | Annotate | Download (7.65 KB)
1 | 312 | fernando | /*
|
---|---|---|---|
2 | * Created on 18-sep-2004
|
||
3 | */
|
||
4 | 1103 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 | *
|
||
6 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
7 | *
|
||
8 | * This program is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | *
|
||
13 | * This program is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU General Public License
|
||
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
21 | *
|
||
22 | * For more information, contact:
|
||
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | *
|
||
34 | * or
|
||
35 | *
|
||
36 | * IVER T.I. S.A
|
||
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | *
|
||
41 | * +34 963163400
|
||
42 | * dac@iver.es
|
||
43 | */
|
||
44 | 312 | fernando | package com.iver.cit.gvsig.gui.Panels; |
45 | |||
46 | 1454 | luisw | import java.awt.FlowLayout; |
47 | import java.awt.Rectangle; |
||
48 | import java.awt.event.ActionEvent; |
||
49 | import java.awt.event.ActionListener; |
||
50 | |||
51 | 434 | fjp | import javax.swing.JButton; |
52 | import javax.swing.JDialog; |
||
53 | 312 | fernando | import javax.swing.JLabel; |
54 | import javax.swing.JPanel; |
||
55 | import javax.swing.JSlider; |
||
56 | import javax.swing.JTextField; |
||
57 | |||
58 | 621 | fjp | import com.iver.andami.PluginServices; |
59 | import com.iver.andami.ui.mdiManager.View; |
||
60 | import com.iver.andami.ui.mdiManager.ViewInfo; |
||
61 | 434 | fjp | import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
62 | 312 | fernando | import com.iver.cit.gvsig.gui.GUIUtil; |
63 | 434 | fjp | import com.iver.cit.gvsig.gui.ValidatingTextField; |
64 | 312 | fernando | /**
|
65 | * Panel de Ajuste de Transparencia.
|
||
66 | * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
||
67 | */
|
||
68 | public class AdjustTransparencyPanel extends JPanel implements View { |
||
69 | JDialog dlg = null; |
||
70 | private JLabel jLabel = null; |
||
71 | private JSlider jSlider = null; |
||
72 | private ValidatingTextField jTxtTransparency = null; |
||
73 | 1454 | luisw | private JPanel buttonsPanel = null; |
74 | 312 | fernando | private FLyrDefault fLayer = null; |
75 | |||
76 | private ViewInfo m_ViewInfo = null; |
||
77 | |||
78 | 1454 | luisw | private JLabel percentLabel = null; |
79 | private JButton btnApply = null; |
||
80 | private JButton btnOk = null; |
||
81 | private JButton btnCancel = null; |
||
82 | |||
83 | private ComandosListener m_actionListener;
|
||
84 | private int oldAlpha = 0; |
||
85 | 312 | fernando | public AdjustTransparencyPanel(FLyrDefault layer) {
|
86 | super();
|
||
87 | initialize(layer); |
||
88 | } |
||
89 | private void initialize(FLyrDefault layer) { |
||
90 | 1454 | luisw | percentLabel = new JLabel(); |
91 | 312 | fernando | jLabel = new JLabel(); |
92 | 1454 | luisw | setBounds(0,0,255,133); |
93 | 312 | fernando | setLayout(null);
|
94 | |||
95 | setFLayer(layer); |
||
96 | 1454 | luisw | oldAlpha = layer.getTransparency(); |
97 | 312 | fernando | jLabel.setBounds(15, 17, 195, 21); |
98 | jLabel.setText("Nivel de transparencia:");
|
||
99 | 1454 | luisw | jLabel.setText(PluginServices.getText(this, "Nivel_de_transparencia")+":"); |
100 | percentLabel.setBounds(225, 55, 21, 20); |
||
101 | percentLabel.setText("%");
|
||
102 | 312 | fernando | this.add(jLabel, null); |
103 | this.add(getJSlider(), null); |
||
104 | this.add(getJTxtTransparency(), null); |
||
105 | 1454 | luisw | this.add(percentLabel, null); |
106 | |||
107 | this.add(getButtonsPanel(), null); |
||
108 | |||
109 | 312 | fernando | } |
110 | |||
111 | public void setFLayer(FLyrDefault f) { |
||
112 | fLayer = f; |
||
113 | 1454 | luisw | setAlpha(fLayer.getTransparency()); |
114 | 312 | fernando | } |
115 | public void setAlpha(int alpha) { |
||
116 | 1454 | luisw | getJSlider().setValue(alpha*100/255); |
117 | 312 | fernando | } |
118 | |||
119 | public int getAlpha() { |
||
120 | 1454 | luisw | return getJSlider().getValue()*255/100; |
121 | 312 | fernando | } |
122 | |||
123 | /**
|
||
124 | * This method initializes jSlider
|
||
125 | *
|
||
126 | * @return javax.swing.JSlider
|
||
127 | */
|
||
128 | private JSlider getJSlider() { |
||
129 | if (jSlider == null) { |
||
130 | jSlider = new JSlider(); |
||
131 | 1454 | luisw | jSlider.setBounds(15, 55, 165, 21); |
132 | jSlider.setMaximum(100);
|
||
133 | jSlider.setMajorTickSpacing(5);
|
||
134 | 312 | fernando | } |
135 | return jSlider;
|
||
136 | } |
||
137 | /**
|
||
138 | * This method initializes jTextField
|
||
139 | *
|
||
140 | * @return javax.swing.JTextField
|
||
141 | */
|
||
142 | private JTextField getJTxtTransparency() { |
||
143 | if (jTxtTransparency == null) { |
||
144 | jTxtTransparency = GUIUtil.createSyncdTextField(jSlider, 3);
|
||
145 | 1454 | luisw | jTxtTransparency.setBounds(190, 55, 30, 21); |
146 | 312 | fernando | //jTxtTransparency.setText("" + getAlpha());
|
147 | } |
||
148 | return jTxtTransparency;
|
||
149 | } |
||
150 | 1454 | luisw | public JPanel getButtonsPanel() { |
151 | if (buttonsPanel == null) { |
||
152 | m_actionListener = new ComandosListener(this); |
||
153 | buttonsPanel = new JPanel(); |
||
154 | 1464 | luisw | buttonsPanel.setBounds(10, 98, 235, 25); |
155 | 1454 | luisw | |
156 | FlowLayout flowLayout2 = new FlowLayout(); |
||
157 | buttonsPanel.setLayout(flowLayout2); |
||
158 | flowLayout2.setHgap(5);
|
||
159 | flowLayout2.setAlignment(java.awt.FlowLayout.RIGHT); |
||
160 | flowLayout2.setVgap(1);
|
||
161 | //buttonsPanel.setPreferredSize(new java.awt.Dimension(225,25));
|
||
162 | buttonsPanel.setName("buttonPanel");
|
||
163 | |||
164 | buttonsPanel.add(getBtnOk(), null);
|
||
165 | buttonsPanel.add(getBtnApply(), null);
|
||
166 | buttonsPanel.add(getBtnCancel(), null);
|
||
167 | } |
||
168 | return buttonsPanel;
|
||
169 | } |
||
170 | |||
171 | public JButton getBtnOk() { |
||
172 | if (btnOk == null) { |
||
173 | btnOk = new JButton("Aceptar"); |
||
174 | btnOk.setText(PluginServices.getText(this,"Aceptar")); |
||
175 | btnOk.setActionCommand("OK");
|
||
176 | btnOk.addActionListener(m_actionListener); |
||
177 | } |
||
178 | return btnOk;
|
||
179 | } |
||
180 | |||
181 | public JButton getBtnApply() { |
||
182 | if (btnApply == null) { |
||
183 | btnApply = new JButton("Aplicar"); |
||
184 | btnApply.setText(PluginServices.getText(this,"Aplicar")); |
||
185 | btnApply.setActionCommand("APPLY");
|
||
186 | btnApply.addActionListener(m_actionListener); |
||
187 | } |
||
188 | return btnApply;
|
||
189 | } |
||
190 | |||
191 | public JButton getBtnCancel() { |
||
192 | if (btnCancel == null) { |
||
193 | 1464 | luisw | btnCancel = new JButton("Cancelar"); |
194 | btnCancel.setText(PluginServices.getText(this,"Cancelar")); |
||
195 | 1454 | luisw | btnCancel.setActionCommand("CANCEL");
|
196 | btnCancel.addActionListener(m_actionListener); |
||
197 | } |
||
198 | return btnCancel;
|
||
199 | } |
||
200 | |||
201 | private class ComandosListener implements ActionListener { |
||
202 | private AdjustTransparencyPanel m_tp;
|
||
203 | 312 | fernando | |
204 | 1454 | luisw | /**
|
205 | * Creates a new ComandosListener object.
|
||
206 | *
|
||
207 | * @param lg DOCUMENT ME!
|
||
208 | */
|
||
209 | public ComandosListener(AdjustTransparencyPanel tp) {
|
||
210 | m_tp = tp; |
||
211 | } |
||
212 | |||
213 | /* (non-Javadoc)
|
||
214 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
215 | */
|
||
216 | public void actionPerformed(ActionEvent e) { |
||
217 | if (e.getActionCommand() == "OK") { |
||
218 | fLayer.setTransparency(getAlpha()); |
||
219 | AdjustTransparencyPanel.this.closeJDialog(); |
||
220 | } else if (e.getActionCommand() == "APPLY") { |
||
221 | fLayer.setTransparency(getAlpha()); |
||
222 | } else if (e.getActionCommand() == "CANCEL") { |
||
223 | if (oldAlpha != fLayer.getTransparency())
|
||
224 | fLayer.setTransparency(oldAlpha); |
||
225 | AdjustTransparencyPanel.this.closeJDialog(); |
||
226 | } |
||
227 | 312 | fernando | } |
228 | 1454 | luisw | } |
229 | |||
230 | 312 | fernando | /* (non-Javadoc)
|
231 | * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
||
232 | */
|
||
233 | public ViewInfo getViewInfo() {
|
||
234 | if (m_ViewInfo==null){ |
||
235 | 1454 | luisw | m_ViewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
236 | 621 | fjp | m_ViewInfo.setTitle(PluginServices.getText(this,"Ajustar_transparencia")); |
237 | 312 | fernando | } |
238 | return m_ViewInfo;
|
||
239 | } |
||
240 | /* (non-Javadoc)
|
||
241 | * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
||
242 | */
|
||
243 | public void viewActivated() { |
||
244 | // TODO Auto-generated method stub
|
||
245 | |||
246 | } |
||
247 | public void openJDialog() { |
||
248 | 621 | fjp | if (PluginServices.getMainFrame() == null) { |
249 | 312 | fernando | dlg = new JDialog(); |
250 | 1454 | luisw | Rectangle bnds = getBounds();
|
251 | bnds.width += 10;
|
||
252 | bnds.height += 33;
|
||
253 | dlg.setBounds(bnds); |
||
254 | dlg.setSize(getSize()); |
||
255 | 312 | fernando | dlg.getContentPane().add(this);
|
256 | 1454 | luisw | dlg.setModal(true);
|
257 | 312 | fernando | dlg.pack(); |
258 | dlg.show(); |
||
259 | } else
|
||
260 | 621 | fjp | PluginServices.getMDIManager().addView(this);
|
261 | 312 | fernando | } |
262 | public void closeJDialog() { |
||
263 | 621 | fjp | if (PluginServices.getMainFrame() == null) { |
264 | 312 | fernando | dlg.hide(); |
265 | dlg.dispose(); |
||
266 | dlg = null;
|
||
267 | } else
|
||
268 | 621 | fjp | PluginServices.getMDIManager().closeView(this);
|
269 | 312 | fernando | |
270 | |||
271 | } |
||
272 | |||
273 | } // @jve:visual-info decl-index=0 visual-constraint="10,10" |