Revision 1454

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/Panels/AdjustTransparencyPanel.java
43 43
 */
44 44
package com.iver.cit.gvsig.gui.Panels;
45 45

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

  
46 51
import javax.swing.JButton;
47 52
import javax.swing.JDialog;
48 53
import javax.swing.JLabel;
......
51 56
import javax.swing.JTextField;
52 57

  
53 58
import com.iver.andami.PluginServices;
54
import com.iver.andami.Utilities;
55 59
import com.iver.andami.ui.mdiManager.View;
56 60
import com.iver.andami.ui.mdiManager.ViewInfo;
57 61
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
......
66 70
	private JLabel jLabel = null;
67 71
	private JSlider jSlider = null;
68 72
	private ValidatingTextField jTxtTransparency = null;
69
	private JButton jOkButton = null;
73
	private JPanel buttonsPanel = null;
70 74
	private FLyrDefault fLayer = null;
71 75
	
72 76
	private ViewInfo m_ViewInfo = null;
73 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;
74 85
	public AdjustTransparencyPanel(FLyrDefault layer) {
75 86
		super();
76 87
		initialize(layer);
77 88
	}
78 89
	private void initialize(FLyrDefault layer) {
90
		percentLabel = new JLabel();
79 91
		jLabel = new JLabel();
80
		setSize(255, 127);
81
		setMinimumSize(new java.awt.Dimension(220,80));
92
		setBounds(0,0,255,133);
82 93
        setLayout(null);
83 94

  
84 95
        setFLayer(layer);
96
        oldAlpha = layer.getTransparency();
85 97
        jLabel.setBounds(15, 17, 195, 21);
86 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("%");
87 102
        this.add(jLabel, null);
88 103
        this.add(getJSlider(), null);
89 104
        this.add(getJTxtTransparency(), null);
90
        this.add(getJOkButton(), null);
91
        jLabel.setText(PluginServices.getText(this, "Nivel_de_transparencia")+":");
92
        jOkButton.setText(PluginServices.getText(this, "Aceptar"));
105
        this.add(percentLabel, null);
106
        
107
        this.add(getButtonsPanel(), null);
108
        
93 109
	}
94 110
	
95 111
	public void setFLayer(FLyrDefault f) {
96 112
		fLayer = f;
97
		setAlpha(255 - fLayer.getTransparency());
113
		setAlpha(fLayer.getTransparency());
98 114
	}
99 115
	public void setAlpha(int alpha) {
100
		getJSlider().setValue(alpha);
116
		getJSlider().setValue(alpha*100/255);
101 117
	}
102 118

  
103 119
	public int getAlpha() {
104
		return getJSlider().getValue();
120
		return getJSlider().getValue()*255/100;
105 121
	}
106 122

  
107 123
	/**
......
112 128
	private JSlider getJSlider() {
113 129
		if (jSlider == null) {
114 130
			jSlider = new JSlider();
115
			jSlider.setBounds(20, 59, 163, 21);
116
			jSlider.setMaximum(255);
117
			jSlider.setMajorTickSpacing(10);
131
			jSlider.setBounds(15, 55, 165, 21);
132
			jSlider.setMaximum(100);
133
			jSlider.setMajorTickSpacing(5);
118 134
		}
119 135
		return jSlider;
120 136
	}
......
126 142
	private JTextField getJTxtTransparency() {
127 143
		if (jTxtTransparency == null) {
128 144
			jTxtTransparency = GUIUtil.createSyncdTextField(jSlider, 3);
129
			jTxtTransparency.setBounds(192, 55, 41, 25);
145
			jTxtTransparency.setBounds(190, 55, 30, 21);
130 146
			//jTxtTransparency.setText("" + getAlpha());
131 147
		}
132 148
		return jTxtTransparency;
133 149
	}
134
	/**
135
	 * This method initializes jButton	
136
	 * 	
137
	 * @return javax.swing.JButton	
138
	 */    
139
	private JButton getJOkButton() {
140
		if (jOkButton == null) {
141
			jOkButton = new JButton();
142
			jOkButton.setBounds(88, 98, 94, 19);
143
			jOkButton.setText("Aceptar");
144
			jOkButton.addActionListener(new java.awt.event.ActionListener() { 
145
				public void actionPerformed(java.awt.event.ActionEvent e) {    
146
					AdjustTransparencyPanel.this.closeJDialog();
147
				}
148
			});
150
	public JPanel getButtonsPanel() {
151
		if (buttonsPanel == null) {
152
			m_actionListener = new ComandosListener(this);
153
			buttonsPanel = new JPanel();
154
	        buttonsPanel.setBounds(10, 98, 227, 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("Cerrar");
194
	        btnCancel.setText(PluginServices.getText(this,"Cerrar"));
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;
149 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
            }
150 227
		}
151
		return jOkButton;
152
	}
228
    }
229
    
153 230
	/* (non-Javadoc)
154 231
	 * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
155 232
	 */
156 233
	public ViewInfo getViewInfo() {
157 234
		if (m_ViewInfo==null){
158
			m_ViewInfo=new ViewInfo(ViewInfo.MODELESSDIALOG | ViewInfo.RESIZABLE);
235
			m_ViewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
159 236
			m_ViewInfo.setTitle(PluginServices.getText(this,"Ajustar_transparencia"));
160 237
		}
161 238
		return m_ViewInfo;
......
170 247
	public void openJDialog() {
171 248
		if (PluginServices.getMainFrame() == null) {
172 249
			dlg = new JDialog();
173
			
174
			setPreferredSize(getSize());
250
			Rectangle bnds = getBounds();
251
			bnds.width += 10;
252
			bnds.height += 33;
253
			dlg.setBounds(bnds);
254
			dlg.setSize(getSize());
175 255
			dlg.getContentPane().add(this);
176
			dlg.setModal(false);			
256
			dlg.setModal(true);			
177 257
			dlg.pack();
178 258
			dlg.show();
179
			
180 259
		} else
181 260
			PluginServices.getMDIManager().addView(this);
182 261
	}
183 262
	public void closeJDialog() {
184
		fLayer.setTransparency(255 - getAlpha());
185 263
		if (PluginServices.getMainFrame() == null) {
186 264
			dlg.hide();
187 265
			dlg.dispose();
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/toc/FPopupMenu.java
210 210
	public void actionPerformed(ActionEvent e) {
211 211
       	lyr = getNodeLayer();
212 212
        AdjustTransparencyPanel transPanel = new AdjustTransparencyPanel((FLyrDefault) lyr);
213
        //transPanel.setFLayer((FLyrDefault) lyr);
214 213
		transPanel.openJDialog();
215
        /*dlg = JColorChooser.createDialog((JFrame) null,
216
                PluginServices.getText(this, "adjust_transparency"),
217
                true, panel, null, null);
218
        dlg.show(true);*/
219
		/*JDialog dlg = new JDialog();
220
		
221
		transPanel.setPreferredSize(transPanel.getSize());
222
		dlg.getContentPane().add(transPanel);
223
		dlg.setModal(true);			
224
		dlg.pack();
225
		dlg.show();
226
        */
227
        //((FLyrDefault) lyr).setTransparency(transPanel.getAlpha());
228
        //view.repaintMap();
229
		
230
        // TRUCO PARA REFRESCAR.
231
        getMapContext().invalidate();                    
214
        //getMapContext().invalidate();                    
232 215
	}
233 216
}
234 217

  
......
256 239
		} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
257 240
			e1.printStackTrace();
258 241
		}
259

  
260
		
261 242
	}
262 243
}
263 244

  

Also available in: Unified diff