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