root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / ViewBehaviorPage.java @ 13730
History | View | Annotate | Download (6.46 KB)
1 | 13730 | jaume | /* 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.gui.preferencespage; |
||
42 | |||
43 | import java.awt.BorderLayout; |
||
44 | import java.awt.Dimension; |
||
45 | import java.awt.FlowLayout; |
||
46 | |||
47 | import javax.swing.BorderFactory; |
||
48 | import javax.swing.ImageIcon; |
||
49 | import javax.swing.JLabel; |
||
50 | import javax.swing.JPanel; |
||
51 | import javax.swing.JSlider; |
||
52 | import javax.swing.border.Border; |
||
53 | |||
54 | import org.gvsig.gui.beans.swing.JBlank; |
||
55 | |||
56 | import com.iver.andami.PluginServices; |
||
57 | import com.iver.andami.preferences.AbstractPreferencePage; |
||
58 | import com.iver.andami.preferences.StoreException; |
||
59 | import com.iver.andami.ui.mdiManager.IWindow; |
||
60 | import com.iver.cit.gvsig.fmap.MapControl; |
||
61 | import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
||
62 | import com.iver.utiles.XMLEntity; |
||
63 | |||
64 | /**
|
||
65 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
66 | */
|
||
67 | public class ViewBehaviorPage extends AbstractPreferencePage{ |
||
68 | private static final int FACTORY_DEFAULT_MAPCONTEXT_FRAME_RATE = 3; |
||
69 | protected String id = ViewBehaviorPage.class.getName(); |
||
70 | private ScreenRefreshRatePanel refreshRate;
|
||
71 | private static final String MAPCONTROL_ENABLE_ANIMATION_KEY_NAME = "MapControlEnableAnimation"; |
||
72 | private static final String MAPCONTROL_REFRESH_RATE_KEY_NAME = "MapControlRefreshRate"; |
||
73 | |||
74 | public ViewBehaviorPage() {
|
||
75 | super();
|
||
76 | setParentID(ViewPage.id); |
||
77 | addComponent(new JBlank(1,1)); |
||
78 | refreshRate = new ScreenRefreshRatePanel();
|
||
79 | addComponent(refreshRate); |
||
80 | } |
||
81 | |||
82 | @Override
|
||
83 | public void setChangesApplied() { |
||
84 | setChanged(false);
|
||
85 | } |
||
86 | |||
87 | @Override
|
||
88 | public void storeValues() throws StoreException { |
||
89 | final int frameRate = refreshRate.getFrameRate(); |
||
90 | final boolean bAnimationEnabled = frameRate>0; |
||
91 | if (frameRate > 0) { |
||
92 | MapControl.setDrawFrameRate(frameRate); |
||
93 | } |
||
94 | MapControl.setDrawAnimationEnabled(bAnimationEnabled); |
||
95 | |||
96 | // Apply on-the-fly to all already created views
|
||
97 | IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
||
98 | for (int i = 0; i < windows.length; i++) { |
||
99 | if (windows[i] instanceof BaseView) { |
||
100 | BaseView view = (BaseView) windows[i]; |
||
101 | view.getMapControl().applyFrameRate(); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | PluginServices ps = PluginServices.getPluginServices(this);
|
||
106 | XMLEntity xml = ps.getPersistentXML(); |
||
107 | xml.putProperty( |
||
108 | MAPCONTROL_REFRESH_RATE_KEY_NAME, |
||
109 | MapControl.getDrawFrameRate()); |
||
110 | xml.putProperty( |
||
111 | MAPCONTROL_ENABLE_ANIMATION_KEY_NAME, |
||
112 | MapControl.isDrawAnimationEnabled()); |
||
113 | |||
114 | } |
||
115 | |||
116 | public String getID() { |
||
117 | return id;
|
||
118 | } |
||
119 | |||
120 | public ImageIcon getIcon() { |
||
121 | return null; |
||
122 | } |
||
123 | |||
124 | public JPanel getPanel() { |
||
125 | return this; |
||
126 | } |
||
127 | |||
128 | public String getTitle() { |
||
129 | return PluginServices.getText(this, "behavior"); |
||
130 | } |
||
131 | |||
132 | public void initializeDefaults() { |
||
133 | refreshRate.setFrameRate(FACTORY_DEFAULT_MAPCONTEXT_FRAME_RATE); |
||
134 | } |
||
135 | |||
136 | public void initializeValues() { |
||
137 | PluginServices ps = PluginServices.getPluginServices(this);
|
||
138 | XMLEntity xml = ps.getPersistentXML(); |
||
139 | |||
140 | // View refresh rate
|
||
141 | if (xml.contains(MAPCONTROL_REFRESH_RATE_KEY_NAME)) {
|
||
142 | MapControl.setDrawFrameRate(xml.getIntProperty(MAPCONTROL_REFRESH_RATE_KEY_NAME)); |
||
143 | } |
||
144 | |||
145 | // View animation enabled
|
||
146 | if (xml.contains(MAPCONTROL_ENABLE_ANIMATION_KEY_NAME)) {
|
||
147 | MapControl.setDrawAnimationEnabled(xml.getBooleanProperty(MAPCONTROL_ENABLE_ANIMATION_KEY_NAME)); |
||
148 | } |
||
149 | |||
150 | |||
151 | int frameRate = MapControl.getDrawFrameRate();
|
||
152 | if (!MapControl.isDrawAnimationEnabled())
|
||
153 | frameRate = 0;
|
||
154 | refreshRate.setFrameRate(frameRate); |
||
155 | } |
||
156 | |||
157 | public boolean isValueChanged() { |
||
158 | return super.hasChanged(); |
||
159 | } |
||
160 | |||
161 | private class ScreenRefreshRatePanel extends JPanel { |
||
162 | private static final long serialVersionUID = -68376902499946576L; |
||
163 | private JSlider sldRefreshRate; |
||
164 | |||
165 | public ScreenRefreshRatePanel() {
|
||
166 | setPreferredSize(new Dimension(500, 200)); |
||
167 | Border border=BorderFactory.createTitledBorder( |
||
168 | PluginServices.getText(this, "options.view.behavior.screen_refreshrate")); |
||
169 | setBorder(border); |
||
170 | setLayout(new BorderLayout(15, 15)); |
||
171 | |||
172 | JPanel aux = new JPanel(new BorderLayout()); |
||
173 | aux.add(new JLabel( |
||
174 | PluginServices.getText( |
||
175 | this,
|
||
176 | "options.view.behavior.screen_refreshrate.none")),
|
||
177 | BorderLayout.WEST);
|
||
178 | JPanel aux2 = new JPanel(new FlowLayout(FlowLayout.CENTER)); |
||
179 | aux2.add(new JLabel( |
||
180 | PluginServices.getText( |
||
181 | this,
|
||
182 | "options.view.behavior.screen_refreshrate.half")),
|
||
183 | BorderLayout.CENTER);
|
||
184 | aux.add(aux2); |
||
185 | aux.add(new JLabel( |
||
186 | PluginServices.getText( |
||
187 | this,
|
||
188 | "options.view.behavior.screen_refreshrate.full")),
|
||
189 | BorderLayout.EAST);
|
||
190 | |||
191 | add(aux, BorderLayout.NORTH);
|
||
192 | aux = new JPanel(new BorderLayout()); |
||
193 | aux.add(getSldRefreshRate(), BorderLayout.NORTH);
|
||
194 | aux.add(new JBlank(10, 20), BorderLayout.SOUTH); |
||
195 | add(aux, BorderLayout.CENTER);
|
||
196 | add(new JLabel(PluginServices. |
||
197 | getText(this, "options.view.behavior.screen_refresh_rate.help")), |
||
198 | BorderLayout.SOUTH);
|
||
199 | } |
||
200 | |||
201 | private JSlider getSldRefreshRate() { |
||
202 | if (sldRefreshRate == null) { |
||
203 | sldRefreshRate = new JSlider(0, 30); |
||
204 | |||
205 | } |
||
206 | |||
207 | return sldRefreshRate;
|
||
208 | } |
||
209 | |||
210 | public int getFrameRate() { |
||
211 | return getSldRefreshRate().getValue();
|
||
212 | } |
||
213 | |||
214 | public void setFrameRate(int sampleRate) { |
||
215 | if (sampleRate<=30) |
||
216 | getSldRefreshRate().setValue(sampleRate); |
||
217 | } |
||
218 | |||
219 | } |
||
220 | |||
221 | @Override
|
||
222 | public String getParentID() { |
||
223 | if (super.getParentID()==null) { |
||
224 | setParentID(ViewPage.id); |
||
225 | } |
||
226 | return super.getParentID(); |
||
227 | } |
||
228 | } |