Revision 230
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/gui/JPRotation.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import java.awt.BorderLayout; |
25 | 25 |
import java.awt.Component; |
26 |
import java.awt.event.FocusEvent; |
|
27 |
import java.awt.event.FocusListener; |
|
28 |
import java.awt.event.KeyEvent; |
|
26 | 29 |
|
27 | 30 |
import javax.swing.JButton; |
28 | 31 |
import javax.swing.JOptionPane; |
... | ... | |
38 | 41 |
private JPanel pButtons = null; |
39 | 42 |
private JButton bLeft = null; |
40 | 43 |
private JTextField txtRotation = null; |
44 |
private String parsedText = null; |
|
41 | 45 |
private JButton bRight = null; |
42 | 46 |
|
43 | 47 |
public void setRotation(double rot) { |
... | ... | |
120 | 124 |
if (txtRotation == null) { |
121 | 125 |
txtRotation = new JTextField(); |
122 | 126 |
txtRotation.setPreferredSize(new java.awt.Dimension(45, 24)); |
123 |
txtRotation.addKeyListener(new java.awt.event.KeyAdapter() { |
|
124 |
|
|
125 |
public void keyReleased(java.awt.event.KeyEvent e) { |
|
126 |
// ensureDouble(txtRotation); |
|
127 |
// if (e.getKeyCode()==KeyEvent.VK_ENTER){ |
|
127 |
txtRotation.addFocusListener(new FocusListener() { |
|
128 |
|
|
129 |
public void focusLost(FocusEvent e) { |
|
130 |
System.out.println("focus lost " + e.toString()); |
|
128 | 131 |
if (txtRotation.getText().endsWith(".")) { |
129 | 132 |
return; |
130 | 133 |
} |
131 | 134 |
try { |
132 | 135 |
setRotation(Double.parseDouble(txtRotation.getText())); |
133 | 136 |
} catch (NumberFormatException e1) { |
134 |
JOptionPane.showMessageDialog( |
|
135 |
(Component) PluginServices.getMainFrame(), |
|
136 |
PluginServices.getText(this, "numero_incorrecto")); |
|
137 |
String oldText = parsedText; |
|
138 |
parsedText = txtRotation.getText(); |
|
139 |
if (!parsedText.equals(oldText)) { // don't show more than once for the same string |
|
140 |
JOptionPane.showMessageDialog( |
|
141 |
(Component) PluginServices.getMainFrame(), |
|
142 |
PluginServices.getText(this, "numero_incorrecto")); |
|
143 |
} |
|
137 | 144 |
} |
138 |
getPRotationView().repaint(); |
|
139 |
// } |
|
145 |
getPRotationView().repaint(); } |
|
146 |
|
|
147 |
public void focusGained(FocusEvent e) { |
|
148 |
System.out.println("focus gained" + e.toString()); |
|
149 |
} |
|
150 |
}); |
|
151 |
txtRotation.addKeyListener(new java.awt.event.KeyAdapter() { |
|
152 |
|
|
153 |
public void keyReleased(java.awt.event.KeyEvent e) { |
|
154 |
System.out.println("key released" + e.toString()); |
|
155 |
String text = txtRotation.getText(); |
|
156 |
if (text.endsWith(".")) { |
|
157 |
return; |
|
158 |
} |
|
159 |
Double value = getDouble(text); |
|
160 |
if (value!=null) { |
|
161 |
setRotation(value); |
|
162 |
getPRotationView().repaint(); |
|
163 |
} |
|
164 |
else if (e.getKeyCode()==KeyEvent.VK_ENTER) { |
|
165 |
String oldText = parsedText; |
|
166 |
parsedText = txtRotation.getText(); |
|
167 |
if (!parsedText.equals(oldText)) { // don't show more than once for the same string |
|
168 |
JOptionPane.showMessageDialog( |
|
169 |
(Component) PluginServices.getMainFrame(), |
|
170 |
PluginServices.getText(this, "numero_incorrecto")); |
|
171 |
} |
|
172 |
} |
|
140 | 173 |
} |
141 | 174 |
}); |
142 |
// txtRotation.setText(String.valueOf(getRotation())); |
|
143 | 175 |
setTextRotation(getRotation()); |
144 | 176 |
} |
145 | 177 |
return txtRotation; |
146 | 178 |
} |
179 |
|
|
180 |
protected Double getDouble(String strValue) { |
|
181 |
// allow comma separated decimal values |
|
182 |
String text = strValue.replaceAll(",", "."); |
|
183 |
try { |
|
184 |
return Double.parseDouble(text); |
|
185 |
} catch (NumberFormatException e1) { |
|
186 |
} |
|
187 |
return null; |
|
188 |
} |
|
147 | 189 |
|
148 | 190 |
/** |
149 | 191 |
* This method initializes bRight |
Also available in: Unified diff