root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / gui / JPRotation.java @ 7738
History | View | Annotate | Download (6.41 KB)
1 | 7304 | caballero | /* 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.project.documents.layout.fframes.gui; |
||
42 | |||
43 | import java.awt.BorderLayout; |
||
44 | import java.awt.Component; |
||
45 | |||
46 | import javax.swing.ImageIcon; |
||
47 | import javax.swing.JButton; |
||
48 | import javax.swing.JOptionPane; |
||
49 | 7738 | jaume | import javax.swing.JPanel; |
50 | 7304 | caballero | 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 | //getTxtRotation().setText(String.valueOf(rot));
|
||
65 | setTextRotation(rot); |
||
66 | } |
||
67 | 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 | public double getRotation(){ |
||
76 | return getPRotationView().getRotation();
|
||
77 | } |
||
78 | /**
|
||
79 | * This method initializes pRotationView
|
||
80 | *
|
||
81 | * @return javax.swing.JPanel
|
||
82 | */
|
||
83 | 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 | * This method initializes pButtons
|
||
95 | *
|
||
96 | * @return javax.swing.JPanel
|
||
97 | */
|
||
98 | 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 | * This method initializes bLeft
|
||
110 | *
|
||
111 | * @return javax.swing.JButton
|
||
112 | */
|
||
113 | 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 | bLeft.addActionListener(new java.awt.event.ActionListener() {
|
||
120 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
121 | setRotation(Double.parseDouble(txtRotation.getText())+1); |
||
122 | getTxtRotation().setText(txtRotation.getText()); |
||
123 | getPRotationView().repaint(); |
||
124 | } |
||
125 | }); |
||
126 | } |
||
127 | return bLeft;
|
||
128 | } |
||
129 | |||
130 | /**
|
||
131 | * This method initializes txtRotation
|
||
132 | *
|
||
133 | * @return javax.swing.JTextField
|
||
134 | */
|
||
135 | private JTextField getTxtRotation() { |
||
136 | if (txtRotation == null) { |
||
137 | txtRotation = new JTextField(); |
||
138 | txtRotation.setPreferredSize(new java.awt.Dimension(45,24)); |
||
139 | txtRotation.addKeyListener(new java.awt.event.KeyAdapter() {
|
||
140 | public void keyReleased(java.awt.event.KeyEvent e) { |
||
141 | //ensureDouble(txtRotation);
|
||
142 | //if (e.getKeyCode()==KeyEvent.VK_ENTER){
|
||
143 | if (txtRotation.getText().endsWith(".")) { |
||
144 | return;
|
||
145 | } |
||
146 | try{
|
||
147 | setRotation(Double.parseDouble(txtRotation.getText()));
|
||
148 | }catch (NumberFormatException e1) { |
||
149 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"numero_incorrecto")); |
||
150 | } |
||
151 | getPRotationView().repaint(); |
||
152 | //}
|
||
153 | } |
||
154 | }); |
||
155 | //txtRotation.setText(String.valueOf(getRotation()));
|
||
156 | setTextRotation(getRotation()); |
||
157 | } |
||
158 | return txtRotation;
|
||
159 | } |
||
160 | |||
161 | /**
|
||
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 | *
|
||
166 | * enteros.
|
||
167 | * @param tf
|
||
168 | */
|
||
169 | /*private boolean ensureDouble(JTextField tf){
|
||
170 | String s = tf.getText();
|
||
171 | try {
|
||
172 | Double.parseDouble(s);
|
||
173 | return true;
|
||
174 | } catch (Exception e){
|
||
175 | if (s.length()!=0){
|
||
176 | // tf.setText(s.substring(0, s.length()-1));
|
||
177 | }else {
|
||
178 | //tf.setText("0");
|
||
179 | }
|
||
180 | return true;
|
||
181 | }
|
||
182 | }*/
|
||
183 | /**
|
||
184 | * This method initializes bRight
|
||
185 | *
|
||
186 | * @return javax.swing.JButton
|
||
187 | */
|
||
188 | 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 | bRight.addActionListener(new java.awt.event.ActionListener() {
|
||
195 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
196 | 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 | *
|
||
223 | * @return void
|
||
224 | */
|
||
225 | private void initialize() { |
||
226 | this.setLayout(new BorderLayout()); |
||
227 | this.setSize(122, 112); |
||
228 | 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" |