root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / dialogs / JPRotation.java @ 5770
History | View | Annotate | Download (6.4 KB)
1 | 2305 | vcaballero | /* 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 com.iver.cit.gvsig.gui.layout.fframes.dialogs; |
||
42 | |||
43 | import javax.swing.JPanel; |
||
44 | import java.awt.BorderLayout; |
||
45 | 2436 | caballero | import java.awt.Component; |
46 | 2305 | vcaballero | |
47 | import javax.swing.ImageIcon; |
||
48 | import javax.swing.JButton; |
||
49 | 2436 | caballero | import javax.swing.JOptionPane; |
50 | 2305 | vcaballero | import javax.swing.JTextField; |
51 | |||
52 | import com.iver.andami.PluginServices; |
||
53 | import com.iver.cit.gvsig.AddLayer; |
||
54 | |||
55 | public class JPRotation extends JPanel { |
||
56 | |||
57 | private JPRotationView pRotationView = null; |
||
58 | private JPanel pButtons = null; |
||
59 | private JButton bLeft = null; |
||
60 | private JTextField txtRotation = null; |
||
61 | private JButton bRight = null; |
||
62 | public void setRotation(double rot){ |
||
63 | getPRotationView().setRotation(rot); |
||
64 | 5770 | caballero | //getTxtRotation().setText(String.valueOf(rot));
|
65 | setTextRotation(rot); |
||
66 | 2305 | vcaballero | } |
67 | 5770 | caballero | private void setTextRotation(double d) { |
68 | String s=String.valueOf(d); |
||
69 | if (s.endsWith(".0")) { |
||
70 | txtRotation.setText(s.substring(0,s.length()-2)); |
||
71 | }else {
|
||
72 | txtRotation.setText(s); |
||
73 | } |
||
74 | } |
||
75 | 2305 | vcaballero | public double getRotation(){ |
76 | return getPRotationView().getRotation();
|
||
77 | } |
||
78 | /**
|
||
79 | 5770 | caballero | * This method initializes pRotationView
|
80 | *
|
||
81 | * @return javax.swing.JPanel
|
||
82 | */
|
||
83 | 2305 | vcaballero | private JPRotationView getPRotationView() {
|
84 | if (pRotationView == null) { |
||
85 | pRotationView = new JPRotationView();
|
||
86 | pRotationView.setForeground(java.awt.Color.black); |
||
87 | pRotationView.setBackground(java.awt.SystemColor.controlShadow); |
||
88 | pRotationView.setPreferredSize(new java.awt.Dimension(80,50)); |
||
89 | } |
||
90 | return pRotationView;
|
||
91 | } |
||
92 | |||
93 | /**
|
||
94 | 5770 | caballero | * This method initializes pButtons
|
95 | *
|
||
96 | * @return javax.swing.JPanel
|
||
97 | */
|
||
98 | 2305 | vcaballero | private JPanel getPButtons() { |
99 | if (pButtons == null) { |
||
100 | pButtons = new JPanel(); |
||
101 | pButtons.add(getBLeft(), null);
|
||
102 | pButtons.add(getTxtRotation(), null);
|
||
103 | pButtons.add(getBRight(), null);
|
||
104 | } |
||
105 | return pButtons;
|
||
106 | } |
||
107 | |||
108 | /**
|
||
109 | 5770 | caballero | * This method initializes bLeft
|
110 | *
|
||
111 | * @return javax.swing.JButton
|
||
112 | */
|
||
113 | 2305 | vcaballero | private JButton getBLeft() { |
114 | if (bLeft == null) { |
||
115 | bLeft = new JButton(); |
||
116 | bLeft.setPreferredSize(new java.awt.Dimension(24,24)); |
||
117 | bLeft.setIcon(new ImageIcon(AddLayer.class.getClassLoader() |
||
118 | .getResource("images/leftrotation.png")));
|
||
119 | 5770 | caballero | bLeft.addActionListener(new java.awt.event.ActionListener() {
|
120 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
121 | 2305 | vcaballero | setRotation(Double.parseDouble(txtRotation.getText())+1); |
122 | getTxtRotation().setText(txtRotation.getText()); |
||
123 | getPRotationView().repaint(); |
||
124 | } |
||
125 | }); |
||
126 | } |
||
127 | return bLeft;
|
||
128 | } |
||
129 | |||
130 | /**
|
||
131 | 5770 | caballero | * This method initializes txtRotation
|
132 | *
|
||
133 | * @return javax.swing.JTextField
|
||
134 | */
|
||
135 | 2305 | vcaballero | private JTextField getTxtRotation() { |
136 | if (txtRotation == null) { |
||
137 | txtRotation = new JTextField(); |
||
138 | 2550 | caballero | txtRotation.setPreferredSize(new java.awt.Dimension(45,24)); |
139 | 5770 | caballero | txtRotation.addKeyListener(new java.awt.event.KeyAdapter() {
|
140 | public void keyReleased(java.awt.event.KeyEvent e) { |
||
141 | 2436 | caballero | //ensureDouble(txtRotation);
|
142 | 5770 | caballero | //if (e.getKeyCode()==KeyEvent.VK_ENTER){
|
143 | if (txtRotation.getText().endsWith(".")) { |
||
144 | return;
|
||
145 | } |
||
146 | 2436 | caballero | try{
|
147 | 2305 | vcaballero | setRotation(Double.parseDouble(txtRotation.getText()));
|
148 | 2436 | caballero | }catch (NumberFormatException e1) { |
149 | 5770 | caballero | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"numero_incorrecto")); |
150 | 2436 | caballero | } |
151 | 2305 | vcaballero | getPRotationView().repaint(); |
152 | 5770 | caballero | //}
|
153 | 2305 | vcaballero | } |
154 | }); |
||
155 | 5770 | caballero | //txtRotation.setText(String.valueOf(getRotation()));
|
156 | setTextRotation(getRotation()); |
||
157 | 2305 | vcaballero | } |
158 | return txtRotation;
|
||
159 | } |
||
160 | 5770 | caballero | |
161 | 2305 | vcaballero | /**
|
162 | * Asegura cutremente que no se meten valores que no sean.
|
||
163 | * El funcionamiento consiste en si el ?ltimo car?cter escrito
|
||
164 | * no vale para formar un int entonces se elimina.
|
||
165 | 5770 | caballero | *
|
166 | 2305 | vcaballero | * enteros.
|
167 | * @param tf
|
||
168 | */
|
||
169 | 2436 | caballero | /*private boolean ensureDouble(JTextField tf){
|
170 | 2305 | vcaballero | String s = tf.getText();
|
171 | try {
|
||
172 | Double.parseDouble(s);
|
||
173 | return true;
|
||
174 | } catch (Exception e){
|
||
175 | if (s.length()!=0){
|
||
176 | 2436 | caballero | // tf.setText(s.substring(0, s.length()-1));
|
177 | 2305 | vcaballero | }else {
|
178 | 2436 | caballero | //tf.setText("0");
|
179 | 2305 | vcaballero | }
|
180 | 2436 | caballero | return true;
|
181 | 2305 | vcaballero | }
|
182 | 2436 | caballero | }*/
|
183 | 2305 | vcaballero | /**
|
184 | 5770 | caballero | * This method initializes bRight
|
185 | *
|
||
186 | * @return javax.swing.JButton
|
||
187 | */
|
||
188 | 2305 | vcaballero | private JButton getBRight() { |
189 | if (bRight == null) { |
||
190 | bRight = new JButton(); |
||
191 | bRight.setPreferredSize(new java.awt.Dimension(24,24)); |
||
192 | bRight.setIcon(new ImageIcon(AddLayer.class.getClassLoader() |
||
193 | .getResource("images/rightrotation.png")));
|
||
194 | 5770 | caballero | bRight.addActionListener(new java.awt.event.ActionListener() {
|
195 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
196 | 2305 | vcaballero | setRotation(Double.parseDouble(txtRotation.getText())-1); |
197 | getTxtRotation().setText(txtRotation.getText()); |
||
198 | getPRotationView().repaint(); |
||
199 | } |
||
200 | }); |
||
201 | } |
||
202 | return bRight;
|
||
203 | } |
||
204 | |||
205 | /**
|
||
206 | * @param args
|
||
207 | */
|
||
208 | public static void main(String[] args) { |
||
209 | |||
210 | } |
||
211 | |||
212 | /**
|
||
213 | * This is the default constructor
|
||
214 | */
|
||
215 | public JPRotation() {
|
||
216 | super();
|
||
217 | initialize(); |
||
218 | } |
||
219 | |||
220 | /**
|
||
221 | * This method initializes this
|
||
222 | 5770 | caballero | *
|
223 | 2305 | vcaballero | * @return void
|
224 | */
|
||
225 | private void initialize() { |
||
226 | this.setLayout(new BorderLayout()); |
||
227 | 2550 | caballero | this.setSize(122, 112); |
228 | 2305 | vcaballero | 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)); |
229 | this.setPreferredSize(new java.awt.Dimension(102,80)); |
||
230 | this.add(getPRotationView(), java.awt.BorderLayout.NORTH);
|
||
231 | this.add(getPButtons(), java.awt.BorderLayout.SOUTH);
|
||
232 | } |
||
233 | |||
234 | } // @jve:decl-index=0:visual-constraint="10,26" |