root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / fframes / gui / JPRotation.java @ 29598
History | View | Annotate | Download (6.27 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.app.project.documents.layout.fframes.gui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Component; |
45 |
|
46 |
import javax.swing.JButton; |
47 |
import javax.swing.JOptionPane; |
48 |
import javax.swing.JPanel; |
49 |
import javax.swing.JTextField; |
50 |
|
51 |
import org.gvsig.andami.PluginServices; |
52 |
|
53 |
|
54 |
public class JPRotation extends JPanel { |
55 |
|
56 |
private JPRotationView pRotationView = null; |
57 |
private JPanel pButtons = null; |
58 |
private JButton bLeft = null; |
59 |
private JTextField txtRotation = null; |
60 |
private JButton bRight = null; |
61 |
public void setRotation(double rot){ |
62 |
getPRotationView().setRotation(rot); |
63 |
//getTxtRotation().setText(String.valueOf(rot));
|
64 |
setTextRotation(rot); |
65 |
} |
66 |
private void setTextRotation(double d) { |
67 |
String s=String.valueOf(d); |
68 |
if (s.endsWith(".0")) { |
69 |
txtRotation.setText(s.substring(0,s.length()-2)); |
70 |
}else {
|
71 |
txtRotation.setText(s); |
72 |
} |
73 |
} |
74 |
public double getRotation(){ |
75 |
return getPRotationView().getRotation();
|
76 |
} |
77 |
/**
|
78 |
* This method initializes pRotationView
|
79 |
*
|
80 |
* @return javax.swing.JPanel
|
81 |
*/
|
82 |
private JPRotationView getPRotationView() {
|
83 |
if (pRotationView == null) { |
84 |
pRotationView = new JPRotationView();
|
85 |
pRotationView.setForeground(java.awt.Color.black); |
86 |
pRotationView.setBackground(java.awt.SystemColor.controlShadow); |
87 |
pRotationView.setPreferredSize(new java.awt.Dimension(80,50)); |
88 |
} |
89 |
return pRotationView;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* This method initializes pButtons
|
94 |
*
|
95 |
* @return javax.swing.JPanel
|
96 |
*/
|
97 |
private JPanel getPButtons() { |
98 |
if (pButtons == null) { |
99 |
pButtons = new JPanel(); |
100 |
pButtons.add(getBLeft(), null);
|
101 |
pButtons.add(getTxtRotation(), null);
|
102 |
pButtons.add(getBRight(), null);
|
103 |
} |
104 |
return pButtons;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* This method initializes bLeft
|
109 |
*
|
110 |
* @return javax.swing.JButton
|
111 |
*/
|
112 |
private JButton getBLeft() { |
113 |
if (bLeft == null) { |
114 |
bLeft = new JButton(); |
115 |
bLeft.setPreferredSize(new java.awt.Dimension(24,24)); |
116 |
bLeft.setIcon(PluginServices.getIconTheme().get("left-rotation-icon"));
|
117 |
bLeft.addActionListener(new java.awt.event.ActionListener() {
|
118 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
119 |
setRotation(Double.parseDouble(txtRotation.getText())+1); |
120 |
getTxtRotation().setText(txtRotation.getText()); |
121 |
getPRotationView().repaint(); |
122 |
} |
123 |
}); |
124 |
} |
125 |
return bLeft;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* This method initializes txtRotation
|
130 |
*
|
131 |
* @return javax.swing.JTextField
|
132 |
*/
|
133 |
private JTextField getTxtRotation() { |
134 |
if (txtRotation == null) { |
135 |
txtRotation = new JTextField(); |
136 |
txtRotation.setPreferredSize(new java.awt.Dimension(45,24)); |
137 |
txtRotation.addKeyListener(new java.awt.event.KeyAdapter() {
|
138 |
public void keyReleased(java.awt.event.KeyEvent e) { |
139 |
//ensureDouble(txtRotation);
|
140 |
//if (e.getKeyCode()==KeyEvent.VK_ENTER){
|
141 |
if (txtRotation.getText().endsWith(".")) { |
142 |
return;
|
143 |
} |
144 |
try{
|
145 |
setRotation(Double.parseDouble(txtRotation.getText()));
|
146 |
}catch (NumberFormatException e1) { |
147 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"numero_incorrecto")); |
148 |
} |
149 |
getPRotationView().repaint(); |
150 |
//}
|
151 |
} |
152 |
}); |
153 |
//txtRotation.setText(String.valueOf(getRotation()));
|
154 |
setTextRotation(getRotation()); |
155 |
} |
156 |
return txtRotation;
|
157 |
} |
158 |
|
159 |
/**
|
160 |
* Asegura cutremente que no se meten valores que no sean.
|
161 |
* El funcionamiento consiste en si el �ltimo car�cter escrito
|
162 |
* no vale para formar un int entonces se elimina.
|
163 |
*
|
164 |
* enteros.
|
165 |
* @param tf
|
166 |
*/
|
167 |
/*private boolean ensureDouble(JTextField tf){
|
168 |
String s = tf.getText();
|
169 |
try {
|
170 |
Double.parseDouble(s);
|
171 |
return true;
|
172 |
} catch (Exception e){
|
173 |
if (s.length()!=0){
|
174 |
// tf.setText(s.substring(0, s.length()-1));
|
175 |
}else {
|
176 |
//tf.setText("0");
|
177 |
}
|
178 |
return true;
|
179 |
}
|
180 |
}*/
|
181 |
/**
|
182 |
* This method initializes bRight
|
183 |
*
|
184 |
* @return javax.swing.JButton
|
185 |
*/
|
186 |
private JButton getBRight() { |
187 |
if (bRight == null) { |
188 |
bRight = new JButton(); |
189 |
bRight.setPreferredSize(new java.awt.Dimension(24,24)); |
190 |
bRight.setIcon(PluginServices.getIconTheme().get("right-rotation-icon"));
|
191 |
bRight.addActionListener(new java.awt.event.ActionListener() {
|
192 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
193 |
setRotation(Double.parseDouble(txtRotation.getText())-1); |
194 |
getTxtRotation().setText(txtRotation.getText()); |
195 |
getPRotationView().repaint(); |
196 |
} |
197 |
}); |
198 |
} |
199 |
return bRight;
|
200 |
} |
201 |
|
202 |
/**
|
203 |
* @param args
|
204 |
*/
|
205 |
public static void main(String[] args) { |
206 |
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* This is the default constructor
|
211 |
*/
|
212 |
public JPRotation() {
|
213 |
super();
|
214 |
initialize(); |
215 |
} |
216 |
|
217 |
/**
|
218 |
* This method initializes this
|
219 |
*
|
220 |
* @return void
|
221 |
*/
|
222 |
private void initialize() { |
223 |
this.setLayout(new BorderLayout()); |
224 |
this.setSize(122, 112); |
225 |
this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"grados"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
226 |
this.setPreferredSize(new java.awt.Dimension(102,80)); |
227 |
this.add(getPRotationView(), java.awt.BorderLayout.NORTH);
|
228 |
this.add(getPButtons(), java.awt.BorderLayout.SOUTH);
|
229 |
} |
230 |
|
231 |
} // @jve:decl-index=0:visual-constraint="10,26"
|