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