root / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / gui / JPRotation.java @ 36648
History | View | Annotate | Download (7.17 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.project.documents.layout.fframes.gui; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.Component; |
26 |
|
27 |
import javax.swing.JButton; |
28 |
import javax.swing.JOptionPane; |
29 |
import javax.swing.JPanel; |
30 |
import javax.swing.JTextField; |
31 |
|
32 |
import org.gvsig.andami.PluginServices; |
33 |
|
34 |
public class JPRotation extends JPanel { |
35 |
|
36 |
private static final long serialVersionUID = 5537314374490402138L; |
37 |
private JPRotationView pRotationView = null; |
38 |
private JPanel pButtons = null; |
39 |
private JButton bLeft = null; |
40 |
private JTextField txtRotation = null; |
41 |
private JButton bRight = null; |
42 |
|
43 |
public void setRotation(double rot) { |
44 |
getPRotationView().setRotation(rot); |
45 |
// getTxtRotation().setText(String.valueOf(rot));
|
46 |
setTextRotation(rot); |
47 |
} |
48 |
|
49 |
private void setTextRotation(double d) { |
50 |
String s = String.valueOf(d); |
51 |
if (s.endsWith(".0")) { |
52 |
txtRotation.setText(s.substring(0, s.length() - 2)); |
53 |
} else {
|
54 |
txtRotation.setText(s); |
55 |
} |
56 |
} |
57 |
|
58 |
public double getRotation() { |
59 |
return getPRotationView().getRotation();
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* This method initializes pRotationView
|
64 |
*
|
65 |
* @return javax.swing.JPanel
|
66 |
*/
|
67 |
private JPRotationView getPRotationView() {
|
68 |
if (pRotationView == null) { |
69 |
pRotationView = new JPRotationView();
|
70 |
pRotationView.setForeground(java.awt.Color.black); |
71 |
pRotationView.setBackground(java.awt.SystemColor.controlShadow); |
72 |
pRotationView.setPreferredSize(new java.awt.Dimension(80, 50)); |
73 |
} |
74 |
return pRotationView;
|
75 |
} |
76 |
|
77 |
/**
|
78 |
* This method initializes pButtons
|
79 |
*
|
80 |
* @return javax.swing.JPanel
|
81 |
*/
|
82 |
private JPanel getPButtons() { |
83 |
if (pButtons == null) { |
84 |
pButtons = new JPanel(); |
85 |
pButtons.add(getBLeft(), null);
|
86 |
pButtons.add(getTxtRotation(), null);
|
87 |
pButtons.add(getBRight(), null);
|
88 |
} |
89 |
return pButtons;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* This method initializes bLeft
|
94 |
*
|
95 |
* @return javax.swing.JButton
|
96 |
*/
|
97 |
private JButton getBLeft() { |
98 |
if (bLeft == null) { |
99 |
bLeft = new JButton(); |
100 |
bLeft.setPreferredSize(new java.awt.Dimension(24, 24)); |
101 |
bLeft.setIcon(PluginServices.getIconTheme().get( |
102 |
"left-rotation-icon"));
|
103 |
bLeft.addActionListener(new java.awt.event.ActionListener() {
|
104 |
|
105 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
106 |
setRotation(Double.parseDouble(txtRotation.getText()) + 1); |
107 |
getTxtRotation().setText(txtRotation.getText()); |
108 |
getPRotationView().repaint(); |
109 |
} |
110 |
}); |
111 |
} |
112 |
return bLeft;
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* This method initializes txtRotation
|
117 |
*
|
118 |
* @return javax.swing.JTextField
|
119 |
*/
|
120 |
private JTextField getTxtRotation() { |
121 |
if (txtRotation == null) { |
122 |
txtRotation = new JTextField(); |
123 |
txtRotation.setPreferredSize(new java.awt.Dimension(45, 24)); |
124 |
txtRotation.addKeyListener(new java.awt.event.KeyAdapter() {
|
125 |
|
126 |
public void keyReleased(java.awt.event.KeyEvent e) { |
127 |
// ensureDouble(txtRotation);
|
128 |
// if (e.getKeyCode()==KeyEvent.VK_ENTER){
|
129 |
if (txtRotation.getText().endsWith(".")) { |
130 |
return;
|
131 |
} |
132 |
try {
|
133 |
setRotation(Double.parseDouble(txtRotation.getText()));
|
134 |
} catch (NumberFormatException e1) { |
135 |
JOptionPane.showMessageDialog(
|
136 |
(Component) PluginServices.getMainFrame(),
|
137 |
PluginServices.getText(this, "numero_incorrecto")); |
138 |
} |
139 |
getPRotationView().repaint(); |
140 |
// }
|
141 |
} |
142 |
}); |
143 |
// txtRotation.setText(String.valueOf(getRotation()));
|
144 |
setTextRotation(getRotation()); |
145 |
} |
146 |
return txtRotation;
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Asegura cutremente que no se meten valores que no sean.
|
151 |
* El funcionamiento consiste en si el �ltimo car�cter escrito
|
152 |
* no vale para formar un int entonces se elimina.
|
153 |
*
|
154 |
* enteros.
|
155 |
*
|
156 |
* @param tf
|
157 |
*/
|
158 |
/*
|
159 |
* private boolean ensureDouble(JTextField tf){
|
160 |
* String s = tf.getText();
|
161 |
* try {
|
162 |
* Double.parseDouble(s);
|
163 |
* return true;
|
164 |
* } catch (Exception e){
|
165 |
* if (s.length()!=0){
|
166 |
* // tf.setText(s.substring(0, s.length()-1));
|
167 |
* }else {
|
168 |
* //tf.setText("0");
|
169 |
* }
|
170 |
* return true;
|
171 |
* }
|
172 |
* }
|
173 |
*/
|
174 |
/**
|
175 |
* This method initializes bRight
|
176 |
*
|
177 |
* @return javax.swing.JButton
|
178 |
*/
|
179 |
private JButton getBRight() { |
180 |
if (bRight == null) { |
181 |
bRight = new JButton(); |
182 |
bRight.setPreferredSize(new java.awt.Dimension(24, 24)); |
183 |
bRight.setIcon(PluginServices.getIconTheme().get( |
184 |
"right-rotation-icon"));
|
185 |
bRight.addActionListener(new java.awt.event.ActionListener() {
|
186 |
|
187 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
188 |
setRotation(Double.parseDouble(txtRotation.getText()) - 1); |
189 |
getTxtRotation().setText(txtRotation.getText()); |
190 |
getPRotationView().repaint(); |
191 |
} |
192 |
}); |
193 |
} |
194 |
return bRight;
|
195 |
} |
196 |
|
197 |
/**
|
198 |
* @param args
|
199 |
*/
|
200 |
public static void main(String[] args) { |
201 |
|
202 |
} |
203 |
|
204 |
/**
|
205 |
* This is the default constructor
|
206 |
*/
|
207 |
public JPRotation() {
|
208 |
super();
|
209 |
initialize(); |
210 |
} |
211 |
|
212 |
/**
|
213 |
* This method initializes this
|
214 |
*
|
215 |
* @return void
|
216 |
*/
|
217 |
private void initialize() { |
218 |
this.setLayout(new BorderLayout()); |
219 |
this.setSize(122, 112); |
220 |
this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, |
221 |
PluginServices.getText(this, "grados"), |
222 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
223 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
224 |
this.setPreferredSize(new java.awt.Dimension(102, 80)); |
225 |
this.add(getPRotationView(), java.awt.BorderLayout.NORTH);
|
226 |
this.add(getPButtons(), java.awt.BorderLayout.SOUTH);
|
227 |
} |
228 |
|
229 |
} // @jve:decl-index=0:visual-constraint="10,26"
|