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