root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / dialogs / FFrameNorthDialog.java @ 6117
History | View | Annotate | Download (11.7 KB)
1 | 2915 | caballero | /* 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.layout.fframes.dialogs; |
||
42 | |||
43 | import java.awt.Color; |
||
44 | import java.awt.Dimension; |
||
45 | import java.awt.geom.Rectangle2D; |
||
46 | import java.io.File; |
||
47 | |||
48 | import javax.swing.DefaultListModel; |
||
49 | import javax.swing.JButton; |
||
50 | import javax.swing.JLabel; |
||
51 | import javax.swing.JList; |
||
52 | import javax.swing.JPanel; |
||
53 | import javax.swing.JScrollPane; |
||
54 | |||
55 | import com.iver.andami.PluginServices; |
||
56 | import com.iver.andami.messages.NotificationManager; |
||
57 | import com.iver.andami.ui.mdiManager.ViewInfo; |
||
58 | import com.iver.cit.gvsig.AddLayer; |
||
59 | import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
||
60 | import com.iver.cit.gvsig.gui.layout.Layout; |
||
61 | import com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth; |
||
62 | import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
||
63 | import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
||
64 | import com.iver.cit.gvsig.gui.layout.fframes.ListViewModel; |
||
65 | 2984 | fjp | import com.iver.cit.gvsig.gui.styling.SLDListBoxCellRenderer; |
66 | 2915 | caballero | |
67 | |||
68 | /**
|
||
69 | * Di?logo para a?adir un gr?fico para se?alizar el norte.
|
||
70 | *
|
||
71 | * @author Vicente Caballero Navarro
|
||
72 | */
|
||
73 | public class FFrameNorthDialog extends JPanel implements IFFrameDialog { |
||
74 | private JScrollPane scrollImages = null; |
||
75 | private JPanel pImages = null; |
||
76 | private JButton bAcept = null; |
||
77 | private JButton bCancel = null; |
||
78 | private Layout layout;
|
||
79 | private FFrameNorth fframenorth;
|
||
80 | private JList listNorth = null; |
||
81 | private File m_file = null; |
||
82 | private Rectangle2D rect = new Rectangle2D.Double(); |
||
83 | private boolean isAcepted = false; |
||
84 | private JScrollPane scrollViews = null; |
||
85 | private JList listViews = null; |
||
86 | private FFrameView fframeview = null; |
||
87 | private JLabel lblView = null; |
||
88 | |||
89 | /**
|
||
90 | * This is the default constructor
|
||
91 | *
|
||
92 | * @param l DOCUMENT ME!
|
||
93 | * @param f DOCUMENT ME!
|
||
94 | */
|
||
95 | public FFrameNorthDialog(Layout l, FFrameNorth f) {
|
||
96 | layout = l; |
||
97 | fframenorth = f; |
||
98 | initialize(); |
||
99 | } |
||
100 | |||
101 | /**
|
||
102 | * This method initializes this
|
||
103 | */
|
||
104 | private void initialize() { |
||
105 | lblView = new JLabel(); |
||
106 | lblView.setBounds(new java.awt.Rectangle(13, 195, 94, 18)); |
||
107 | lblView.setText(PluginServices.getText(this, "marco_vista")); |
||
108 | this.setLayout(null); |
||
109 | this.setSize(376, 305); |
||
110 | this.add(getScrollImages(), null); |
||
111 | this.add(getBAcept(), null); |
||
112 | this.add(getBCancel(), null); |
||
113 | this.add(getScrollViews(), null); |
||
114 | this.add(lblView, null); |
||
115 | } |
||
116 | |||
117 | /**
|
||
118 | * DOCUMENT ME!
|
||
119 | *
|
||
120 | * @param r DOCUMENT ME!
|
||
121 | */
|
||
122 | public void setRectangle(Rectangle2D r) { |
||
123 | rect.setRect(r); |
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | * DOCUMENT ME!
|
||
128 | *
|
||
129 | * @return DOCUMENT ME!
|
||
130 | */
|
||
131 | public ViewInfo getViewInfo() {
|
||
132 | ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODALDIALOG);
|
||
133 | m_viewinfo.setTitle(PluginServices.getText(this,
|
||
134 | "propiedades_marco_imagenes"));
|
||
135 | |||
136 | return m_viewinfo;
|
||
137 | } |
||
138 | |||
139 | /**
|
||
140 | * DOCUMENT ME!
|
||
141 | *
|
||
142 | * @return DOCUMENT ME!
|
||
143 | */
|
||
144 | public boolean getIsAcepted() { |
||
145 | return isAcepted;
|
||
146 | } |
||
147 | |||
148 | /**
|
||
149 | * This method initializes scrollImages
|
||
150 | *
|
||
151 | * @return javax.swing.JScrollPane
|
||
152 | */
|
||
153 | private JScrollPane getScrollImages() { |
||
154 | if (scrollImages == null) { |
||
155 | scrollImages = new JScrollPane(); |
||
156 | scrollImages.setBounds(new java.awt.Rectangle(3, 3, 357, 174)); |
||
157 | scrollImages.setBackground(java.awt.Color.white); |
||
158 | scrollImages.setViewportView(getPImages()); |
||
159 | } |
||
160 | |||
161 | return scrollImages;
|
||
162 | } |
||
163 | |||
164 | /**
|
||
165 | * This method initializes pImages
|
||
166 | *
|
||
167 | * @return javax.swing.JPanel
|
||
168 | */
|
||
169 | private JPanel getPImages() { |
||
170 | if (pImages == null) { |
||
171 | pImages = new JPanel(); |
||
172 | pImages.setBackground(java.awt.Color.white); |
||
173 | pImages.add(getListNorth(), null);
|
||
174 | } |
||
175 | |||
176 | return pImages;
|
||
177 | } |
||
178 | |||
179 | /**
|
||
180 | * This method initializes bAcept
|
||
181 | *
|
||
182 | * @return javax.swing.JButton
|
||
183 | */
|
||
184 | private JButton getBAcept() { |
||
185 | if (bAcept == null) { |
||
186 | bAcept = new JButton(); |
||
187 | bAcept.setBounds(new java.awt.Rectangle(49, 268, 108, 28)); |
||
188 | bAcept.setText(PluginServices.getText(this, "Aceptar")); |
||
189 | bAcept.addActionListener(new java.awt.event.ActionListener() {
|
||
190 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
191 | 3284 | caballero | if (m_file != null) { |
192 | Dimension dimension = null; |
||
193 | 4778 | caballero | |
194 | 2915 | caballero | try {
|
195 | dimension = fframenorth.getBound(m_file.getAbsolutePath()); |
||
196 | } catch (Exception ex) { |
||
197 | NotificationManager.addError("Excepci?n :", ex);
|
||
198 | } |
||
199 | fframenorth.setPath(m_file.getAbsolutePath()); |
||
200 | fframenorth.setViewing(0);
|
||
201 | fframenorth.setQuality(0);
|
||
202 | |||
203 | 4778 | caballero | |
204 | 2915 | caballero | fframenorth.setName(m_file.getName()); |
205 | |||
206 | 4778 | caballero | |
207 | 2915 | caballero | // Ajustamos la relaci?n de aspecto a la altura.
|
208 | double ratio = (float) (dimension.getWidth()) / (float) (dimension.getHeight()); |
||
209 | |||
210 | double newWidth = rect.getHeight() * ratio;
|
||
211 | Rectangle2D.Double rAdjust = new Rectangle2D.Double(rect.getMinX(), |
||
212 | rect.getMinY(), newWidth, rect.getHeight()); |
||
213 | rect = rAdjust; |
||
214 | 3284 | caballero | } |
215 | 2915 | caballero | fframenorth.setBoundBox(FLayoutUtilities.toSheetRect( |
216 | rect, layout.getAT())); |
||
217 | fframenorth.setRotation(0);
|
||
218 | PluginServices.getMDIManager().closeView(FFrameNorthDialog.this); |
||
219 | layout.refresh(); |
||
220 | isAcepted = true;
|
||
221 | } |
||
222 | }); |
||
223 | } |
||
224 | |||
225 | return bAcept;
|
||
226 | } |
||
227 | |||
228 | /**
|
||
229 | * This method initializes bCancel
|
||
230 | *
|
||
231 | * @return javax.swing.JButton
|
||
232 | */
|
||
233 | private JButton getBCancel() { |
||
234 | if (bCancel == null) { |
||
235 | bCancel = new JButton(); |
||
236 | bCancel.setBounds(new java.awt.Rectangle(206, 268, 108, 28)); |
||
237 | bCancel.setText(PluginServices.getText(this, "Cancelar")); |
||
238 | bCancel.addActionListener(new java.awt.event.ActionListener() {
|
||
239 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
240 | PluginServices.getMDIManager().closeView(FFrameNorthDialog.this); |
||
241 | } |
||
242 | }); |
||
243 | } |
||
244 | |||
245 | return bCancel;
|
||
246 | } |
||
247 | |||
248 | /**
|
||
249 | * This method initializes listNorth
|
||
250 | *
|
||
251 | * @return javax.swing.JList
|
||
252 | */
|
||
253 | private JList getListNorth() { |
||
254 | if (listNorth == null) { |
||
255 | listNorth = new JList(); |
||
256 | 4778 | caballero | |
257 | 2915 | caballero | listNorth.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
258 | listNorth.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
||
259 | listNorth.setVisibleRowCount(-1);
|
||
260 | |||
261 | File file = new File(AddLayer.class.getClassLoader() |
||
262 | .getResource("northimages")
|
||
263 | .getFile()); |
||
264 | listNorth.setSize(new java.awt.Dimension(300, 242)); |
||
265 | listNorth.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT); |
||
266 | |||
267 | File[] files = file.listFiles(); |
||
268 | DefaultListModel listModel = new DefaultListModel(); |
||
269 | |||
270 | for (int i = 0; i < files.length; i++) { |
||
271 | listModel.addElement(files[i].getAbsolutePath()); |
||
272 | } |
||
273 | |||
274 | listNorth.setModel(listModel); |
||
275 | |||
276 | SLDListBoxCellRenderer renderer = new SLDListBoxCellRenderer();
|
||
277 | renderer.setPreferredSize(new Dimension(60, 50)); |
||
278 | listNorth.setCellRenderer(renderer); |
||
279 | if (fframenorth.getName()!=null){ |
||
280 | for (int i=0;i<listNorth.getModel().getSize();i++){ |
||
281 | if (((String)listNorth.getModel().getElementAt(i)).endsWith(fframenorth.getName())){ |
||
282 | listNorth.setSelectedIndex(i); |
||
283 | m_file = new File((String) listNorth.getSelectedValue()); |
||
284 | } |
||
285 | } |
||
286 | 4778 | caballero | |
287 | 2915 | caballero | } |
288 | 4778 | caballero | |
289 | 2915 | caballero | listNorth.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
290 | public void valueChanged( |
||
291 | javax.swing.event.ListSelectionEvent e) { |
||
292 | m_file = new File((String) ((JList) e.getSource()).getSelectedValue()); |
||
293 | } |
||
294 | }); |
||
295 | } |
||
296 | |||
297 | return listNorth;
|
||
298 | } |
||
299 | |||
300 | /**
|
||
301 | * This method initializes scrollViews
|
||
302 | *
|
||
303 | * @return javax.swing.JScrollPane
|
||
304 | */
|
||
305 | private JScrollPane getScrollViews() { |
||
306 | if (scrollViews == null) { |
||
307 | scrollViews = new JScrollPane(); |
||
308 | scrollViews.setBackground(Color.white);
|
||
309 | scrollViews.setBounds(new java.awt.Rectangle(127, 191, 232, 65)); |
||
310 | scrollViews.setViewportView(getListViews()); |
||
311 | } |
||
312 | |||
313 | return scrollViews;
|
||
314 | } |
||
315 | |||
316 | /**
|
||
317 | * This method initializes listViews
|
||
318 | *
|
||
319 | * @return javax.swing.JList
|
||
320 | */
|
||
321 | private JList getListViews() { |
||
322 | if (listViews == null) { |
||
323 | ListViewModel listmodel = new ListViewModel();
|
||
324 | listmodel.addViews(layout); |
||
325 | listViews = new javax.swing.JList();
|
||
326 | listViews.setModel(listmodel); |
||
327 | |||
328 | for (int i = 0; i < listViews.getModel().getSize(); i++) { |
||
329 | 3114 | caballero | if (fframenorth.getFFrameDependence() != null) { |
330 | 2915 | caballero | fframeview = (FFrameView) listViews.getModel().getElementAt(i); |
331 | |||
332 | 3114 | caballero | if (fframeview == fframenorth.getFFrameDependence()) {
|
333 | 2915 | caballero | listViews.setSelectedIndex(i); |
334 | } |
||
335 | } |
||
336 | } |
||
337 | |||
338 | listViews.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
||
339 | 3239 | caballero | private int selectIndex=-1; |
340 | public void valueChanged( |
||
341 | 4778 | caballero | javax.swing.event.ListSelectionEvent e) { |
342 | int selectInt = (int) ((JList) e.getSource()) |
||
343 | .getSelectedIndex(); |
||
344 | if (selectInt != selectIndex) {
|
||
345 | selectIndex = selectInt; |
||
346 | if (selectIndex == -1) |
||
347 | return;
|
||
348 | fframeview = (FFrameView) listViews.getModel() |
||
349 | .getElementAt(selectInt); |
||
350 | 2915 | caballero | |
351 | 4778 | caballero | for (int i = 0; i < layout.getFFrames().length; i++) { |
352 | IFFrame f = (IFFrame) layout.getFFrame(i); |
||
353 | 2915 | caballero | |
354 | 4778 | caballero | if (f instanceof FFrameView) { |
355 | if (((FFrameView) f).getView() == fframeview
|
||
356 | .getView()) { |
||
357 | fframenorth |
||
358 | .setFFrameDependence(fframeview); |
||
359 | } |
||
360 | } |
||
361 | } |
||
362 | } |
||
363 | } |
||
364 | }); |
||
365 | } |
||
366 | 2915 | caballero | |
367 | return listViews;
|
||
368 | } |
||
369 | } // @jve:decl-index=0:visual-constraint="10,10" |