gvsig-projects-pool / org.gvsig.winmgr / trunk / org.gvsig.winmgr.app / org.gvsig.winmgr.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / ScreenSettingsPage.java @ 682
History | View | Annotate | Download (6.3 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.coreplugin.preferences.general; |
25 |
|
26 |
import java.awt.BasicStroke; |
27 |
import java.awt.Color; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.Graphics; |
30 |
import java.awt.Graphics2D; |
31 |
import java.awt.Toolkit; |
32 |
import java.awt.event.ActionEvent; |
33 |
import java.awt.event.ActionListener; |
34 |
import java.text.NumberFormat; |
35 |
import java.util.prefs.Preferences; |
36 |
|
37 |
import javax.swing.BorderFactory; |
38 |
import javax.swing.ImageIcon; |
39 |
import javax.swing.JComboBox; |
40 |
import javax.swing.JLabel; |
41 |
import javax.swing.JPanel; |
42 |
import javax.swing.JTextField; |
43 |
import javax.swing.border.Border; |
44 |
|
45 |
import org.gvsig.andami.PluginServices; |
46 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
47 |
import org.gvsig.andami.preferences.StoreException; |
48 |
import org.gvsig.gui.beans.swing.JBlank; |
49 |
import org.gvsig.gui.beans.swing.JButton; |
50 |
|
51 |
|
52 |
|
53 |
/**
|
54 |
* Page to calculate correctly all the scales of screen. In it we introduce
|
55 |
* the values of our screen just as we see it.
|
56 |
*
|
57 |
* @author Vicente Caballero Navarro
|
58 |
*/
|
59 |
public class ScreenSettingsPage extends AbstractPreferencePage { |
60 |
protected static String id = ScreenSettingsPage.class.getName(); |
61 |
private static final long serialVersionUID = 6012279465073443753L; |
62 |
private static final double MILLIMETERS_PER_INCH = 2.54; |
63 |
private static Preferences prefs = Preferences.userRoot().node( "gvsig.configuration.screen" ); |
64 |
private ImageIcon icon; |
65 |
private JPanel pTestMeasure; |
66 |
private JTextField txtResolution; |
67 |
private JTextField txtMeasure; |
68 |
private JComboBox cmbUnits; |
69 |
private JButton btnRefresh; |
70 |
|
71 |
public ScreenSettingsPage() {
|
72 |
super();
|
73 |
setParentID(GeneralPage.id); |
74 |
icon=PluginServices.getIconTheme().get("edit-setup-screensetting");
|
75 |
addComponent(PluginServices.getText(this, "resolution") + ":", |
76 |
txtResolution = new JTextField("", 15)); |
77 |
|
78 |
pTestMeasure = new TestMeasurePanel();
|
79 |
addComponent(pTestMeasure); |
80 |
addComponent(new JLabel(PluginServices.getText(this,"the_length_of_the_line_above_is")+":")); |
81 |
cmbUnits=new JComboBox(); |
82 |
cmbUnits.addItem(PluginServices.getText(this,"centimeters")); |
83 |
cmbUnits.addItem(PluginServices.getText(this,"inches")); |
84 |
cmbUnits.addActionListener(new ActionListener() { |
85 |
public void actionPerformed(ActionEvent arg0) { |
86 |
/*double d=Double.parseDouble(txtMeasure.getText().replace(',','.'));
|
87 |
if (cmbUnits.getSelectedIndex()==0) {
|
88 |
txtResolution.setText(String.valueOf((int)((210*MILLIMETERS_PER_INCH)/d)));
|
89 |
}else {
|
90 |
txtResolution.setText(String.valueOf((int)(210/d)));
|
91 |
}
|
92 |
*/
|
93 |
} |
94 |
}); |
95 |
txtMeasure=new JTextField(); |
96 |
addComponent(txtMeasure,cmbUnits); |
97 |
|
98 |
addComponent(new JBlank(1,1)); |
99 |
|
100 |
btnRefresh=new JButton(PluginServices.getText(this,"button.resolution.calculate")); |
101 |
btnRefresh.addActionListener(new ActionListener() { |
102 |
public void actionPerformed(ActionEvent arg0) { |
103 |
|
104 |
double d=Double.parseDouble(txtMeasure.getText().replace(',','.')); |
105 |
if (cmbUnits.getSelectedIndex()==0) { |
106 |
txtResolution.setText(String.valueOf((int)((210*MILLIMETERS_PER_INCH)/d))); |
107 |
}else {
|
108 |
txtResolution.setText(String.valueOf((int)(210/d))); |
109 |
} |
110 |
|
111 |
|
112 |
} |
113 |
|
114 |
}); |
115 |
addComponent(btnRefresh); |
116 |
|
117 |
|
118 |
|
119 |
initialize(); |
120 |
} |
121 |
|
122 |
|
123 |
private class TestMeasurePanel extends JPanel{ |
124 |
|
125 |
private static final long serialVersionUID = -8307475893309753439L; |
126 |
public TestMeasurePanel() {
|
127 |
setPreferredSize(new Dimension(250,60)); |
128 |
Border border=BorderFactory.createTitledBorder( |
129 |
PluginServices.getText(this, "test_measure")); |
130 |
setBorder(border); |
131 |
} |
132 |
protected void paintComponent(Graphics g) { |
133 |
super.paintComponent(g);
|
134 |
((Graphics2D)g).setStroke(new BasicStroke(2)); |
135 |
g.setColor(Color.black);
|
136 |
g.drawLine(20,30,230,30); |
137 |
g.drawLine(20,20,20,40); |
138 |
g.drawLine(230,20,230,40); |
139 |
} |
140 |
|
141 |
} |
142 |
|
143 |
private void initialize() { |
144 |
// this.setSize(394, 248);
|
145 |
} |
146 |
|
147 |
public void storeValues() throws StoreException { |
148 |
int dpi=Integer.parseInt(txtResolution.getText()); |
149 |
prefs.putInt("dpi",dpi);
|
150 |
} |
151 |
|
152 |
public void setChangesApplied() { |
153 |
setChanged(false);
|
154 |
} |
155 |
|
156 |
public String getID() { |
157 |
return id;
|
158 |
} |
159 |
|
160 |
public String getTitle() { |
161 |
return PluginServices.getText(this, "options.configuration.screen"); |
162 |
} |
163 |
|
164 |
public JPanel getPanel() { |
165 |
return this; |
166 |
} |
167 |
|
168 |
public void initializeValues() { |
169 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
170 |
double dpi = kit.getScreenResolution();
|
171 |
int resDPI=prefs.getInt("dpi",(int)dpi); |
172 |
|
173 |
txtResolution.setText(String.valueOf(resDPI));
|
174 |
txtMeasure.setText(String.valueOf(format(210*MILLIMETERS_PER_INCH/resDPI))); |
175 |
cmbUnits.setSelectedIndex(0);
|
176 |
} |
177 |
|
178 |
public void initializeDefaults() { |
179 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
180 |
int dpi = kit.getScreenResolution();
|
181 |
txtResolution.setText(String.valueOf(dpi));
|
182 |
txtMeasure.setText(String.valueOf(format(210*MILLIMETERS_PER_INCH/dpi))); |
183 |
cmbUnits.setSelectedIndex(0);
|
184 |
} |
185 |
|
186 |
|
187 |
public ImageIcon getIcon() { |
188 |
return icon;
|
189 |
} |
190 |
|
191 |
|
192 |
public boolean isValueChanged() { |
193 |
return super.hasChanged(); |
194 |
} |
195 |
|
196 |
private String format(double d) { |
197 |
NumberFormat nf = NumberFormat.getInstance(); |
198 |
|
199 |
if ((d % (long) d) != 0) { |
200 |
nf.setMaximumFractionDigits(2);
|
201 |
} else {
|
202 |
nf.setMaximumFractionDigits(0);
|
203 |
} |
204 |
|
205 |
return nf.format(d); //(Double.valueOf(s).doubleValue()); |
206 |
} |
207 |
} // @jve:decl-index=0:visual-constraint="10,10"
|