Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / panels / AdjustTransparencyPanel.java @ 29596

History | View | Annotate | Download (7.71 KB)

1
/*
2
 * Created on 18-sep-2004
3
 */
4
/* 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
package org.gvsig.app.gui.panels;
45

    
46
import java.awt.FlowLayout;
47
import java.awt.Rectangle;
48
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionListener;
50

    
51
import javax.swing.JButton;
52
import javax.swing.JDialog;
53
import javax.swing.JLabel;
54
import javax.swing.JPanel;
55
import javax.swing.JSlider;
56
import javax.swing.JTextField;
57

    
58
import org.gvsig.andami.PluginServices;
59
import org.gvsig.andami.ui.mdiManager.IWindow;
60
import org.gvsig.andami.ui.mdiManager.WindowInfo;
61
import org.gvsig.app.gui.GUIUtil;
62
import org.gvsig.fmap.mapcontext.layers.FLyrDefault;
63
import org.gvsig.gui.beans.swing.ValidatingTextField;
64

    
65
/**
66
 * Panel de Ajuste de Transparencia.
67
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
68
 */
69
public class AdjustTransparencyPanel extends JPanel implements IWindow  {
70
        JDialog dlg = null;
71
        private JLabel jLabel = null;
72
        private JSlider jSlider = null;
73
        private ValidatingTextField jTxtTransparency = null;
74
        private JPanel buttonsPanel = null;
75
        private FLyrDefault fLayer = null;
76

    
77
        private WindowInfo m_ViewInfo = null;
78

    
79
        private JLabel percentLabel = null;
80
        private JButton btnApply = null;
81
        private JButton btnOk = null;
82
        private JButton btnCancel = null;
83

    
84
    private ComandosListener m_actionListener;
85
    private int oldAlpha = 0;
86
        public AdjustTransparencyPanel(FLyrDefault layer) {
87
                super();
88
                initialize(layer);
89
        }
90
        private void initialize(FLyrDefault layer) {
91
                percentLabel = new JLabel();
92
                jLabel = new JLabel();
93
                setBounds(0,0,255,133);
94
        setLayout(null);
95

    
96
        setFLayer(layer);
97
        oldAlpha = layer.getTransparency();
98
        jLabel.setBounds(15, 17, 195, 21);
99
        jLabel.setText("Nivel de transparencia:");
100
        jLabel.setText(PluginServices.getText(this, "Nivel_de_transparencia")+":");
101
        percentLabel.setBounds(225, 55, 21, 20);
102
        percentLabel.setText("%");
103
        this.add(jLabel, null);
104
        this.add(getJSlider(), null);
105
        this.add(getJTxtTransparency(), null);
106
        this.add(percentLabel, null);
107

    
108
        this.add(getButtonsPanel(), null);
109

    
110
        }
111

    
112
        public void setFLayer(FLyrDefault f) {
113
                fLayer = f;
114
                setAlpha(fLayer.getTransparency());
115
        }
116
        public void setAlpha(int alpha) {
117
                getJSlider().setValue(alpha*100/255);
118
        }
119

    
120
        public int getAlpha() {
121
                return getJSlider().getValue()*255/100;
122
        }
123

    
124
        /**
125
         * This method initializes jSlider
126
         *
127
         * @return javax.swing.JSlider
128
         */
129
        private JSlider getJSlider() {
130
                if (jSlider == null) {
131
                        jSlider = new JSlider();
132
                        jSlider.setBounds(15, 55, 165, 21);
133
                        jSlider.setMaximum(100);
134
                        jSlider.setMajorTickSpacing(5);
135
                }
136
                return jSlider;
137
        }
138
        /**
139
         * This method initializes jTextField
140
         *
141
         * @return javax.swing.JTextField
142
         */
143
        private JTextField getJTxtTransparency() {
144
                if (jTxtTransparency == null) {
145
                        jTxtTransparency = GUIUtil.createSyncdTextField(jSlider, 3);
146
                        jTxtTransparency.setBounds(190, 55, 30, 21);
147
                        //jTxtTransparency.setText("" + getAlpha());
148
                }
149
                return jTxtTransparency;
150
        }
151
        public JPanel getButtonsPanel() {
152
                if (buttonsPanel == null) {
153
                        m_actionListener = new ComandosListener(this);
154
                        buttonsPanel = new JPanel();
155
                buttonsPanel.setBounds(10, 98, 235, 25);
156

    
157
                        FlowLayout flowLayout2 = new FlowLayout();
158
                        buttonsPanel.setLayout(flowLayout2);
159
                        flowLayout2.setHgap(5);
160
                        flowLayout2.setAlignment(java.awt.FlowLayout.RIGHT);
161
                        flowLayout2.setVgap(1);
162
                        //buttonsPanel.setPreferredSize(new java.awt.Dimension(225,25));
163
                        buttonsPanel.setName("buttonPanel");
164

    
165
                buttonsPanel.add(getBtnOk(), null);
166
                buttonsPanel.add(getBtnApply(), null);
167
                buttonsPanel.add(getBtnCancel(), null);
168
                }
169
                return buttonsPanel;
170
        }
171

    
172
        public JButton getBtnOk() {
173
                if (btnOk == null) {
174
                btnOk = new JButton("Aceptar");
175
                btnOk.setText(PluginServices.getText(this,"Aceptar"));
176
                btnOk.setActionCommand("OK");
177
                btnOk.addActionListener(m_actionListener);
178
                }
179
                return btnOk;
180
        }
181

    
182
        public JButton getBtnApply() {
183
                if (btnApply == null) {
184
                btnApply = new JButton("Aplicar");
185
                btnApply.setText(PluginServices.getText(this,"Aplicar"));
186
                btnApply.setActionCommand("APPLY");
187
                btnApply.addActionListener(m_actionListener);
188
                }
189
                return btnApply;
190
        }
191

    
192
        public JButton getBtnCancel() {
193
                if (btnCancel == null) {
194
                btnCancel = new JButton("Cancelar");
195
                btnCancel.setText(PluginServices.getText(this,"Cancelar"));
196
                btnCancel.setActionCommand("CANCEL");
197
                btnCancel.addActionListener(m_actionListener);
198
                }
199
                return btnCancel;
200
        }
201

    
202
    private class ComandosListener implements ActionListener {
203
        private AdjustTransparencyPanel m_tp;
204

    
205
        /**
206
         * Creates a new ComandosListener object.
207
         *
208
         * @param lg DOCUMENT ME!
209
         */
210
        public ComandosListener(AdjustTransparencyPanel tp) {
211
            m_tp = tp;
212
        }
213

    
214
                /* (non-Javadoc)
215
                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
216
                 */
217
                public void actionPerformed(ActionEvent e) {
218
            if (e.getActionCommand() == "OK") {
219
                        fLayer.setTransparency(getAlpha());
220
                                AdjustTransparencyPanel.this.closeJDialog();
221
            } else if (e.getActionCommand() == "APPLY") {
222
                        fLayer.setTransparency(getAlpha());
223
            } else if (e.getActionCommand() == "CANCEL") {
224
                    if (oldAlpha != fLayer.getTransparency()) {
225
                                        fLayer.setTransparency(oldAlpha);
226
                                }
227
                                AdjustTransparencyPanel.this.closeJDialog();
228
            }
229
                }
230
    }
231

    
232
        /* (non-Javadoc)
233
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
234
         */
235
        public WindowInfo getWindowInfo() {
236
                if (m_ViewInfo==null){
237
                        m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
238
                        m_ViewInfo.setTitle(PluginServices.getText(this,"Ajustar_transparencia"));
239
                }
240
                return m_ViewInfo;
241
        }
242
        /* (non-Javadoc)
243
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
244
         */
245
        public void viewActivated() {
246
                // TODO Auto-generated method stub
247

    
248
        }
249
        public void openJDialog() {
250
                if (PluginServices.getMainFrame() == null) {
251
                        dlg = new JDialog();
252
                        Rectangle bnds = getBounds();
253
                        bnds.width += 10;
254
                        bnds.height += 33;
255
                        dlg.setBounds(bnds);
256
                        dlg.setSize(getSize());
257
                        dlg.getContentPane().add(this);
258
                        dlg.setModal(true);
259
                        dlg.pack();
260
                        dlg.setVisible(true);
261
                } else {
262
                        PluginServices.getMDIManager().addWindow(this);
263
                }
264
        }
265
        public void closeJDialog() {
266
                if (PluginServices.getMainFrame() == null) {
267
                        dlg.setVisible(false);
268
                        dlg.dispose();
269
                        dlg = null;
270
                } else {
271
                        PluginServices.getMDIManager().closeWindow(this);
272
                }
273

    
274

    
275
        }
276
        public Object getWindowProfile() {
277
                return WindowInfo.DIALOG_PROFILE;
278
        }
279
   }  //  @jve:visual-info  decl-index=0 visual-constraint="10,10"