Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / gui / JPRotation.java @ 27352

History | View | Annotate | Download (6.34 KB)

1
/* 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
import javax.swing.JPanel;
50
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(PluginServices.getIconTheme().get("left-rotation-icon"));
118
                        bLeft.addActionListener(new java.awt.event.ActionListener() {
119
                                public void actionPerformed(java.awt.event.ActionEvent e) {
120
                                        setRotation(Double.parseDouble(txtRotation.getText())+1);
121
                                        getTxtRotation().setText(txtRotation.getText());
122
                                        getPRotationView().repaint();
123
                                }
124
                        });
125
                }
126
                return bLeft;
127
        }
128

    
129
        /**
130
         * This method initializes txtRotation
131
         *
132
         * @return javax.swing.JTextField
133
         */
134
        private JTextField getTxtRotation() {
135
                if (txtRotation == null) {
136
                        txtRotation = new JTextField();
137
                        txtRotation.setPreferredSize(new java.awt.Dimension(45,24));
138
                        txtRotation.addKeyListener(new java.awt.event.KeyAdapter() {
139
                                public void keyReleased(java.awt.event.KeyEvent e) {
140
                                        //ensureDouble(txtRotation);
141
                                        //if (e.getKeyCode()==KeyEvent.VK_ENTER){
142
                                        if (txtRotation.getText().endsWith(".")) {
143
                                                return;
144
                                        }
145
                                        try{
146
                                        setRotation(Double.parseDouble(txtRotation.getText()));
147
                                        }catch (NumberFormatException e1) {
148
                                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"numero_incorrecto"));
149
                                        }
150
                                        getPRotationView().repaint();
151
                                        //}
152
                                }
153
                        });
154
                        //txtRotation.setText(String.valueOf(getRotation()));
155
                        setTextRotation(getRotation());
156
                }
157
                return txtRotation;
158
        }
159

    
160
        /**
161
         * Asegura cutremente que no se meten valores que no sean.
162
         * El funcionamiento consiste en si el �ltimo car�cter escrito
163
         * no vale para formar un int entonces se elimina.
164
         *
165
         * enteros.
166
         * @param tf
167
         */
168
        /*private boolean ensureDouble(JTextField tf){
169
            String s = tf.getText();
170
            try {
171
                Double.parseDouble(s);
172
                return true;
173
            } catch (Exception e){
174
                if (s.length()!=0){
175
                   // tf.setText(s.substring(0, s.length()-1));
176
                }else {
177
                        //tf.setText("0");
178
                }
179
                return true;
180
            }
181
        }*/
182
        /**
183
         * This method initializes bRight
184
         *
185
         * @return javax.swing.JButton
186
         */
187
        private JButton getBRight() {
188
                if (bRight == null) {
189
                        bRight = new JButton();
190
                        bRight.setPreferredSize(new java.awt.Dimension(24,24));
191
                        bRight.setIcon(PluginServices.getIconTheme().get("right-rotation-icon"));
192
                        bRight.addActionListener(new java.awt.event.ActionListener() {
193
                                public void actionPerformed(java.awt.event.ActionEvent e) {
194
                                        setRotation(Double.parseDouble(txtRotation.getText())-1);
195
                                        getTxtRotation().setText(txtRotation.getText());
196
                                        getPRotationView().repaint();
197
                                }
198
                        });
199
                }
200
                return bRight;
201
        }
202

    
203
        /**
204
         * @param args
205
         */
206
        public static void main(String[] args) {
207

    
208
        }
209

    
210
        /**
211
         * This is the default constructor
212
         */
213
        public JPRotation() {
214
                super();
215
                initialize();
216
        }
217

    
218
        /**
219
         * This method initializes this
220
         *
221
         * @return void
222
         */
223
        private void initialize() {
224
                this.setLayout(new BorderLayout());
225
                this.setSize(122, 112);
226
                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));
227
                this.setPreferredSize(new java.awt.Dimension(102,80));
228
                this.add(getPRotationView(), java.awt.BorderLayout.NORTH);
229
                this.add(getPButtons(), java.awt.BorderLayout.SOUTH);
230
        }
231

    
232
}  //  @jve:decl-index=0:visual-constraint="10,26"