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