svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.image.extension / src / main / java / org / gvsig / arcims / image / gui / dialogs / LayerScaleDialog.java @ 32321
History | View | Annotate | Download (6.43 KB)
1 | 32321 | vsanjaime | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
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 2
|
||
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 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2010 Prodevelop S.L. main development
|
||
26 | * http://www.prodevelop.es
|
||
27 | */
|
||
28 | |||
29 | package org.gvsig.arcims.image.gui.dialogs; |
||
30 | |||
31 | import java.awt.BorderLayout; |
||
32 | import java.awt.Dimension; |
||
33 | import java.awt.event.ActionEvent; |
||
34 | import java.awt.event.ActionListener; |
||
35 | import java.text.DecimalFormat; |
||
36 | import java.text.DecimalFormatSymbols; |
||
37 | import java.util.Vector; |
||
38 | |||
39 | import javax.swing.JButton; |
||
40 | import javax.swing.JLabel; |
||
41 | import javax.swing.JPanel; |
||
42 | import javax.swing.JScrollPane; |
||
43 | import javax.swing.ScrollPaneConstants; |
||
44 | |||
45 | import org.gvsig.andami.PluginServices; |
||
46 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
47 | import org.gvsig.andami.ui.mdiManager.WindowInfo; |
||
48 | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
||
49 | import org.gvsig.app.project.documents.view.gui.IView; |
||
50 | import org.gvsig.arcims.image.fmap.layers.FRasterLyrArcIMS; |
||
51 | import org.gvsig.arcims.image.fmap.listeners.FRasterLyrArcIMSListener; |
||
52 | import org.gvsig.arcims.image.gui.panels.LayerScaleDrawPanel; |
||
53 | |||
54 | |||
55 | /**
|
||
56 | * This class shows the ArcIMS layer's scale limits status.
|
||
57 | *
|
||
58 | * @author jldominguez, vsanjaime
|
||
59 | */
|
||
60 | public class LayerScaleDialog extends JPanel implements ActionListener, IWindow, |
||
61 | FRasterLyrArcIMSListener { |
||
62 | private static final long serialVersionUID = 0; |
||
63 | private JPanel button_p; |
||
64 | private JButton b; |
||
65 | private LayerScaleDrawPanel dp;
|
||
66 | private FRasterLyrArcIMS layer;
|
||
67 | private WindowInfo theViewInfo;
|
||
68 | private JScrollPane sp; |
||
69 | private String vistaName; |
||
70 | private JLabel southLabel; |
||
71 | |||
72 | /**
|
||
73 | * Needs the layer as parameter.
|
||
74 | *
|
||
75 | * @param ailyr the layer
|
||
76 | */
|
||
77 | public LayerScaleDialog(FRasterLyrArcIMS ailyr, IView view) {
|
||
78 | super();
|
||
79 | layer = ailyr; |
||
80 | southLabel = new JLabel(); |
||
81 | |||
82 | if (view != null) { |
||
83 | vistaName = ((DefaultViewPanel)view).getName(); |
||
84 | } |
||
85 | else {
|
||
86 | vistaName = "Unknown";
|
||
87 | } |
||
88 | |||
89 | ailyr.addActionlistener(this);
|
||
90 | ailyr.addNameOrQueryListener(this);
|
||
91 | |||
92 | Vector infoV = layer.getLayerScaleInfoVector();
|
||
93 | int spHeight = 201 + (15 * infoV.size()); |
||
94 | |||
95 | if (spHeight > 500) { |
||
96 | spHeight = 500;
|
||
97 | } |
||
98 | |||
99 | setLayout(new BorderLayout()); |
||
100 | setSize(140 + 680, spHeight + 10); |
||
101 | setMinimumSize(new Dimension(410, 226)); |
||
102 | |||
103 | b = new JButton(PluginServices.getText(this, "close")); |
||
104 | b.setBounds(10, 10, 90, 25); |
||
105 | b.addActionListener(this);
|
||
106 | |||
107 | button_p = new JPanel(); |
||
108 | button_p.setLayout(new BorderLayout()); |
||
109 | button_p.add(southLabel, BorderLayout.WEST); // setPreferredSize(new Dimension(10, 5)); |
||
110 | // button_p.add(b);
|
||
111 | |||
112 | dp = new LayerScaleDrawPanel(infoV, this, southLabel); |
||
113 | dp.setDpi(ailyr.getArcimsStatus().getServiceInfo().getScreen_dpi()); |
||
114 | dp.setCurrentScale(1.0 * layer.getMapContext().getScaleView());
|
||
115 | |||
116 | southLabel.setText(PluginServices.getText(this, "Escala") + " 1 : " + |
||
117 | getFormattedInteger(Math.round(dp.getCurrentScale())));
|
||
118 | |||
119 | dp.setPreferredSize(new Dimension(300, 200 + (15 * infoV.size()))); |
||
120 | |||
121 | sp = new JScrollPane(dp); |
||
122 | sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||
123 | sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||
124 | |||
125 | add(BorderLayout.CENTER, sp);
|
||
126 | add(BorderLayout.SOUTH, button_p);
|
||
127 | } |
||
128 | |||
129 | public void resetDrawingPanel() { |
||
130 | Vector infoV = layer.getLayerScaleInfoVector();
|
||
131 | dp.resetInfo(infoV); |
||
132 | dp.setPreferredSize(new Dimension(300, 200 + (15 * infoV.size()))); |
||
133 | dp.repaint(); |
||
134 | } |
||
135 | |||
136 | public void actionPerformed(ActionEvent arg0) { |
||
137 | if (arg0.getActionCommand()
|
||
138 | .compareToIgnoreCase(FRasterLyrArcIMS.SCALE_CHANGED_COMMAND) == 0) {
|
||
139 | dp.setCurrentScale(1.0 * layer.getScale());
|
||
140 | dp.repaint(); |
||
141 | |||
142 | return;
|
||
143 | } |
||
144 | |||
145 | if (arg0.getSource() == b) {
|
||
146 | this.close();
|
||
147 | } |
||
148 | } |
||
149 | |||
150 | public void close() { |
||
151 | PluginServices.getMDIManager().closeWindow(this);
|
||
152 | } |
||
153 | |||
154 | public WindowInfo getWindowInfo() {
|
||
155 | if (theViewInfo == null) { |
||
156 | theViewInfo = new WindowInfo(0 + // palette |
||
157 | 16 + // no modal |
||
158 | 0 + // modal |
||
159 | 4 + // iconifiable |
||
160 | 2 + // maximizable |
||
161 | 1 // resizable |
||
162 | ); |
||
163 | theViewInfo.setTitle(PluginServices.getText(this, "view") + ": " + |
||
164 | vistaName + " - " + PluginServices.getText(this, "layer") + |
||
165 | ": " + layer.getName() + " - " + |
||
166 | PluginServices.getText(this, "layer_scale_status")); |
||
167 | theViewInfo.setWidth(getInitialWidth()); |
||
168 | theViewInfo.setHeight(getInitialHeight()); |
||
169 | } |
||
170 | |||
171 | return theViewInfo;
|
||
172 | } |
||
173 | |||
174 | public FRasterLyrArcIMS getLayer() {
|
||
175 | return layer;
|
||
176 | } |
||
177 | |||
178 | public void setLayer(FRasterLyrArcIMS layer) { |
||
179 | this.layer = layer;
|
||
180 | } |
||
181 | |||
182 | private int getInitialWidth() { |
||
183 | return 365; |
||
184 | } |
||
185 | |||
186 | private int getInitialHeight() { |
||
187 | return 290 - 35; |
||
188 | } |
||
189 | |||
190 | public void thingsHaveChanged(String query, String name) { |
||
191 | resetDrawingPanel(); |
||
192 | } |
||
193 | |||
194 | public static String getFormattedInteger(int n) { |
||
195 | DecimalFormat df = new DecimalFormat(); |
||
196 | df.setGroupingUsed(true);
|
||
197 | df.setGroupingSize(3);
|
||
198 | |||
199 | DecimalFormatSymbols dfs = new DecimalFormatSymbols(); |
||
200 | dfs.setGroupingSeparator('.');
|
||
201 | df.setDecimalFormatSymbols(dfs); |
||
202 | |||
203 | return df.format(n);
|
||
204 | } |
||
205 | |||
206 | public Object getWindowProfile() { |
||
207 | return WindowInfo.DIALOG_PROFILE;
|
||
208 | } |
||
209 | |||
210 | } |