svn-document-layout / 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 @ 228
History | View | Annotate | Download (6.43 KB)
1 | 5 | jldominguez | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.app.project.documents.layout.fframes.gui; |
||
23 | |||
24 | import java.awt.BorderLayout; |
||
25 | import java.awt.Component; |
||
26 | |||
27 | import javax.swing.JButton; |
||
28 | import javax.swing.JOptionPane; |
||
29 | import javax.swing.JPanel; |
||
30 | import javax.swing.JTextField; |
||
31 | |||
32 | import org.gvsig.andami.PluginServices; |
||
33 | |||
34 | public class JPRotation extends JPanel { |
||
35 | |||
36 | private static final long serialVersionUID = 5537314374490402138L; |
||
37 | private JPRotationView pRotationView = null; |
||
38 | private JPanel pButtons = null; |
||
39 | private JButton bLeft = null; |
||
40 | private JTextField txtRotation = null; |
||
41 | private JButton bRight = null; |
||
42 | |||
43 | public void setRotation(double rot) { |
||
44 | getPRotationView().setRotation(rot); |
||
45 | setTextRotation(rot); |
||
46 | } |
||
47 | |||
48 | private void setTextRotation(double d) { |
||
49 | String s = String.valueOf(d); |
||
50 | if (s.endsWith(".0")) { |
||
51 | txtRotation.setText(s.substring(0, s.length() - 2)); |
||
52 | } else {
|
||
53 | txtRotation.setText(s); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | public double getRotation() { |
||
58 | return getPRotationView().getRotation();
|
||
59 | } |
||
60 | |||
61 | /**
|
||
62 | * This method initializes pRotationView
|
||
63 | *
|
||
64 | * @return javax.swing.JPanel
|
||
65 | */
|
||
66 | private JPRotationView getPRotationView() {
|
||
67 | if (pRotationView == null) { |
||
68 | pRotationView = new JPRotationView();
|
||
69 | pRotationView.setForeground(java.awt.Color.black); |
||
70 | pRotationView.setBackground(java.awt.SystemColor.controlShadow); |
||
71 | pRotationView.setPreferredSize(new java.awt.Dimension(80, 50)); |
||
72 | } |
||
73 | return pRotationView;
|
||
74 | } |
||
75 | |||
76 | /**
|
||
77 | * This method initializes pButtons
|
||
78 | *
|
||
79 | * @return javax.swing.JPanel
|
||
80 | */
|
||
81 | private JPanel getPButtons() { |
||
82 | if (pButtons == null) { |
||
83 | pButtons = new JPanel(); |
||
84 | pButtons.add(getBLeft(), null);
|
||
85 | pButtons.add(getTxtRotation(), null);
|
||
86 | pButtons.add(getBRight(), null);
|
||
87 | } |
||
88 | return pButtons;
|
||
89 | } |
||
90 | |||
91 | /**
|
||
92 | * This method initializes bLeft
|
||
93 | *
|
||
94 | * @return javax.swing.JButton
|
||
95 | */
|
||
96 | private JButton getBLeft() { |
||
97 | if (bLeft == null) { |
||
98 | bLeft = new JButton(); |
||
99 | bLeft.setPreferredSize(new java.awt.Dimension(24, 24)); |
||
100 | bLeft.setIcon(PluginServices.getIconTheme().get( |
||
101 | "left-rotation-icon"));
|
||
102 | bLeft.addActionListener(new java.awt.event.ActionListener() {
|
||
103 | |||
104 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
105 | setRotation(Double.parseDouble(txtRotation.getText()) + 1); |
||
106 | getTxtRotation().setText(txtRotation.getText()); |
||
107 | getPRotationView().repaint(); |
||
108 | } |
||
109 | }); |
||
110 | } |
||
111 | return bLeft;
|
||
112 | } |
||
113 | |||
114 | /**
|
||
115 | * This method initializes txtRotation
|
||
116 | *
|
||
117 | * @return javax.swing.JTextField
|
||
118 | */
|
||
119 | private JTextField getTxtRotation() { |
||
120 | if (txtRotation == null) { |
||
121 | txtRotation = new JTextField(); |
||
122 | 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){
|
||
128 | if (txtRotation.getText().endsWith(".")) { |
||
129 | return;
|
||
130 | } |
||
131 | try {
|
||
132 | setRotation(Double.parseDouble(txtRotation.getText()));
|
||
133 | } catch (NumberFormatException e1) { |
||
134 | JOptionPane.showMessageDialog(
|
||
135 | (Component) PluginServices.getMainFrame(),
|
||
136 | PluginServices.getText(this, "numero_incorrecto")); |
||
137 | } |
||
138 | getPRotationView().repaint(); |
||
139 | // }
|
||
140 | } |
||
141 | }); |
||
142 | // txtRotation.setText(String.valueOf(getRotation()));
|
||
143 | setTextRotation(getRotation()); |
||
144 | } |
||
145 | return txtRotation;
|
||
146 | } |
||
147 | |||
148 | /**
|
||
149 | * This method initializes bRight
|
||
150 | *
|
||
151 | * @return javax.swing.JButton
|
||
152 | */
|
||
153 | private JButton getBRight() { |
||
154 | if (bRight == null) { |
||
155 | bRight = new JButton(); |
||
156 | bRight.setPreferredSize(new java.awt.Dimension(24, 24)); |
||
157 | bRight.setIcon(PluginServices.getIconTheme().get( |
||
158 | "right-rotation-icon"));
|
||
159 | bRight.addActionListener(new java.awt.event.ActionListener() {
|
||
160 | |||
161 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
162 | setRotation(Double.parseDouble(txtRotation.getText()) - 1); |
||
163 | getTxtRotation().setText(txtRotation.getText()); |
||
164 | getPRotationView().repaint(); |
||
165 | } |
||
166 | }); |
||
167 | } |
||
168 | return bRight;
|
||
169 | } |
||
170 | |||
171 | /**
|
||
172 | * @param args
|
||
173 | */
|
||
174 | public static void main(String[] args) { |
||
175 | |||
176 | } |
||
177 | |||
178 | /**
|
||
179 | * This is the default constructor
|
||
180 | */
|
||
181 | public JPRotation() {
|
||
182 | super();
|
||
183 | initialize(); |
||
184 | } |
||
185 | |||
186 | /**
|
||
187 | * This method initializes this
|
||
188 | *
|
||
189 | * @return void
|
||
190 | */
|
||
191 | private void initialize() { |
||
192 | this.setLayout(new BorderLayout()); |
||
193 | this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, |
||
194 | PluginServices.getText(this, "grados"), |
||
195 | javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
||
196 | javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
||
197 | this.add(getPRotationView(), java.awt.BorderLayout.NORTH);
|
||
198 | this.add(getPButtons(), java.awt.BorderLayout.SOUTH);
|
||
199 | } |
||
200 | |||
201 | } // @jve:decl-index=0:visual-constraint="10,26" |