Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_906 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / panels / AdjustTransparencyPanel.java @ 10972

History | View | Annotate | Download (7.67 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 com.iver.cit.gvsig.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 com.iver.andami.PluginServices;
59
import com.iver.andami.ui.mdiManager.IWindow;
60
import com.iver.andami.ui.mdiManager.WindowInfo;
61
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
62
import com.iver.cit.gvsig.gui.GUIUtil;
63
import com.iver.cit.gvsig.gui.ValidatingTextField;
64
/**
65
 * Panel de Ajuste de Transparencia.
66
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
67
 */
68
public class AdjustTransparencyPanel extends JPanel implements IWindow  {
69
        JDialog dlg = null;
70
        private JLabel jLabel = null;
71
        private JSlider jSlider = null;
72
        private ValidatingTextField jTxtTransparency = null;
73
        private JPanel buttonsPanel = null;
74
        private FLyrDefault fLayer = null;
75
        
76
        private WindowInfo m_ViewInfo = null;
77
        
78
        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
        public AdjustTransparencyPanel(FLyrDefault layer) {
86
                super();
87
                initialize(layer);
88
        }
89
        private void initialize(FLyrDefault layer) {
90
                percentLabel = new JLabel();
91
                jLabel = new JLabel();
92
                setBounds(0,0,255,133);
93
        setLayout(null);
94

    
95
        setFLayer(layer);
96
        oldAlpha = layer.getTransparency();
97
        jLabel.setBounds(15, 17, 195, 21);
98
        jLabel.setText("Nivel de transparencia:");
99
        jLabel.setText(PluginServices.getText(this, "Nivel_de_transparencia")+":");
100
        percentLabel.setBounds(225, 55, 21, 20);
101
        percentLabel.setText("%");
102
        this.add(jLabel, null);
103
        this.add(getJSlider(), null);
104
        this.add(getJTxtTransparency(), null);
105
        this.add(percentLabel, null);
106
        
107
        this.add(getButtonsPanel(), null);
108
        
109
        }
110
        
111
        public void setFLayer(FLyrDefault f) {
112
                fLayer = f;
113
                setAlpha(fLayer.getTransparency());
114
        }
115
        public void setAlpha(int alpha) {
116
                getJSlider().setValue(alpha*100/255);
117
        }
118

    
119
        public int getAlpha() {
120
                return getJSlider().getValue()*255/100;
121
        }
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
                        jSlider.setBounds(15, 55, 165, 21);
132
                        jSlider.setMaximum(100);
133
                        jSlider.setMajorTickSpacing(5);
134
                }
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
                        jTxtTransparency.setBounds(190, 55, 30, 21);
146
                        //jTxtTransparency.setText("" + getAlpha());
147
                }
148
                return jTxtTransparency;
149
        }
150
        public JPanel getButtonsPanel() {
151
                if (buttonsPanel == null) {
152
                        m_actionListener = new ComandosListener(this);
153
                        buttonsPanel = new JPanel();
154
                buttonsPanel.setBounds(10, 98, 235, 25);
155
                
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
                btnCancel = new JButton("Cancelar");
194
                btnCancel.setText(PluginServices.getText(this,"Cancelar"));
195
                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

    
204
        /**
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
                }
228
    }
229
    
230
        /* (non-Javadoc)
231
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
232
         */
233
        public WindowInfo getWindowInfo() {
234
                if (m_ViewInfo==null){
235
                        m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
236
                        m_ViewInfo.setTitle(PluginServices.getText(this,"Ajustar_transparencia"));
237
                }
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
                if (PluginServices.getMainFrame() == null) {
249
                        dlg = new JDialog();
250
                        Rectangle bnds = getBounds();
251
                        bnds.width += 10;
252
                        bnds.height += 33;
253
                        dlg.setBounds(bnds);
254
                        dlg.setSize(getSize());
255
                        dlg.getContentPane().add(this);
256
                        dlg.setModal(true);                        
257
                        dlg.pack();
258
                        dlg.show();
259
                } else
260
                        PluginServices.getMDIManager().addWindow(this);
261
        }
262
        public void closeJDialog() {
263
                if (PluginServices.getMainFrame() == null) {
264
                        dlg.hide();
265
                        dlg.dispose();
266
                        dlg = null;
267
                } else
268
                        PluginServices.getMDIManager().closeWindow(this);
269

    
270
                
271
        }
272

    
273
   }  //  @jve:visual-info  decl-index=0 visual-constraint="10,10"