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