Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / gui / JPRotation.java @ 24962

History | View | Annotate | Download (6.28 KB)

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