Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / gui / dialogs / FFrameNorthDialog.java @ 717

History | View | Annotate | Download (13.9 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.event.ActionEvent;
27
import java.awt.geom.Rectangle2D;
28
import java.io.File;
29

    
30
import javax.swing.DefaultListModel;
31
import javax.swing.JLabel;
32
import javax.swing.JList;
33
import javax.swing.JPanel;
34
import javax.swing.JScrollPane;
35

    
36
import org.gvsig.andami.PluginServices;
37
import org.gvsig.andami.messages.NotificationManager;
38
import org.gvsig.andami.ui.mdiManager.WindowInfo;
39
import org.gvsig.app.extension.AddLayer;
40
import org.gvsig.app.gui.styling.SLDListBoxCellRenderer;
41
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
42
import org.gvsig.app.project.documents.layout.fframes.FFrameNorth;
43
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
44
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
45
import org.gvsig.app.project.documents.layout.fframes.ListViewModel;
46
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
47
import org.gvsig.gui.beans.AcceptCancelPanel;
48

    
49
/**
50
 * Di?logo para a?adir un gr?fico para se?alizar el norte.
51
 * 
52
 * @author Vicente Caballero Navarro
53
 */
54
public class FFrameNorthDialog extends AbstractFFrameDialog implements
55
    IFFrameDialog {
56

    
57
    private static final long serialVersionUID = -6320517042548835036L;
58
    private JScrollPane scrollImages = null;
59
    private JPanel pImages = null;
60
    private FFrameNorth fframenorth;
61
    private JList listNorth = null;
62
    private File m_file = null;
63
    private Rectangle2D rect = new Rectangle2D.Double();
64
    private boolean isAcepted = false;
65
    private JScrollPane scrollViews = null;
66
    private JList listViews = null;
67
    private FFrameView fframeview = null;
68
    private JLabel lblView = null;
69
    private AcceptCancelPanel acceptCancel = null;
70
    private FFrameView fframeDependence;
71
    private FFrameNorth newFFrameNorth;
72
    private String path;
73

    
74
    /**
75
     * This is the default constructor
76
     * 
77
     * @param l
78
     *            DOCUMENT ME!
79
     * @param f
80
     *            DOCUMENT ME!
81
     */
82
    public FFrameNorthDialog(LayoutPanel layoutPanel, IFFrame frame) {
83
        super(layoutPanel, frame);
84
        fframenorth = (FFrameNorth) frame;
85
        initialize();
86
    }
87

    
88
    /**
89
     * This method initializes this
90
     */
91
    private void initialize() {
92
        lblView = new JLabel();
93
        lblView.setBounds(new java.awt.Rectangle(5, 193, 325, 18));
94
        lblView.setText(PluginServices.getText(this, "marco_vista"));
95
        this.setLayout(null);
96
        this.setSize(370, 335);
97
        this.add(getScrollImages(), null);
98

    
99
        this.add(getAcceptCancel());
100

    
101
        this.add(getScrollViews(), null);
102
        this.add(lblView, null);
103
    }
104

    
105
    private AcceptCancelPanel getAcceptCancel() {
106
        if (this.acceptCancel == null) {
107
            this.acceptCancel =
108
                new AcceptCancelPanel(new java.awt.event.ActionListener() { // Accept
109

    
110
                        public void actionPerformed(java.awt.event.ActionEvent e) {
111
                            try {
112
                                newFFrameNorth =
113
                                    (FFrameNorth) fframenorth.clone();
114
                                if (m_file != null) {
115

    
116
                                    Dimension dimension = null;
117

    
118
                                    try {
119
                                        dimension =
120
                                            fframenorth.getBound(m_file
121
                                                .getAbsolutePath());
122
                                    } catch (Exception ex) {
123
                                        NotificationManager.addError(
124
                                            "Excepci?n :", ex);
125
                                    }
126
                                    newFFrameNorth
127
                                        .setFFrameDependence(fframeDependence);
128
                                    newFFrameNorth.setPath(path);
129
                                    newFFrameNorth.setViewing(0);
130
                                    newFFrameNorth.setQuality(0);
131
                                    // newFFrameNorth.setName(m_file.getName());
132
                                    newFFrameNorth.load(path);
133

    
134
                                    // Ajustamos la relaci?n de aspecto a la
135
                                    // altura.
136
                                    double ratio =
137
                                        (float) (dimension.getWidth())
138
                                            / (float) (dimension.getHeight());
139

    
140
                                    double newWidth = rect.getHeight() * ratio;
141
                                    Rectangle2D.Double rAdjust =
142
                                        new Rectangle2D.Double(rect.getMinX(),
143
                                            rect.getMinY(), newWidth, rect
144
                                                .getHeight());
145
                                    rect = rAdjust;
146
                                }
147
                                newFFrameNorth.setBoundBox(FLayoutUtilities
148
                                    .toSheetRect(rect, layoutPanel
149
                                        .getLayoutControl().getAT()));
150
                                newFFrameNorth.setRotation(0);
151
                            } catch (CloneNotSupportedException e1) {
152
                                LOG.error(
153
                                    "It is not possible clonate the object", e);
154
                            }
155

    
156
                            PluginServices.getMDIManager().closeWindow(
157
                                FFrameNorthDialog.this);
158
                            isAcepted = true;
159
                            notifyDialogClosed();
160
                            layoutPanel.getLayoutControl().setDefaultTool();
161
                            fireActionEvent(new ActionEvent(FFrameNorthDialog.this, 1, "accept"));
162
                        }
163
                    }, new java.awt.event.ActionListener() { // Cancel
164

    
165
                        public void actionPerformed(java.awt.event.ActionEvent e) {
166
                            PluginServices.getMDIManager().closeWindow(
167
                                FFrameNorthDialog.this);
168
                            notifyDialogClosed();
169
                        }
170
                    }
171

    
172
                );
173
            this.acceptCancel.setBounds(3, 290, 357, 30);
174

    
175
        }
176
        return this.acceptCancel;
177
    }
178

    
179
    /**
180
     * DOCUMENT ME!
181
     * 
182
     * @param r
183
     *            DOCUMENT ME!
184
     */
185
    public void setRectangle(Rectangle2D r) {
186
        rect.setRect(r);
187
    }
188

    
189
    /**
190
     * DOCUMENT ME!
191
     * 
192
     * @return DOCUMENT ME!
193
     */
194
    public WindowInfo getWindowInfo() {
195
        WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
196
        m_viewinfo.setTitle(PluginServices.getText(this,
197
            "propiedades_marco_imagenes"));
198

    
199
        return m_viewinfo;
200
    }
201

    
202
    /**
203
     * DOCUMENT ME!
204
     * 
205
     * @return DOCUMENT ME!
206
     */
207
    public boolean getIsAcepted() {
208
        return isAcepted;
209
    }
210

    
211
    /**
212
     * This method initializes scrollImages
213
     * 
214
     * @return javax.swing.JScrollPane
215
     */
216
    private JScrollPane getScrollImages() {
217
        if (scrollImages == null) {
218
            scrollImages = new JScrollPane();
219
            scrollImages.setBounds(new java.awt.Rectangle(3, 3, 357, 174));
220
            scrollImages.setBackground(java.awt.Color.white);
221
            scrollImages.setViewportView(getPImages());
222
        }
223

    
224
        return scrollImages;
225
    }
226

    
227
    /**
228
     * This method initializes pImages
229
     * 
230
     * @return javax.swing.JPanel
231
     */
232
    private JPanel getPImages() {
233
        if (pImages == null) {
234
            pImages = new JPanel();
235
            pImages.setBackground(java.awt.Color.white);
236
            pImages.add(getListNorth(), null);
237
        }
238

    
239
        return pImages;
240
    }
241

    
242
    /**
243
     * This method initializes listNorth
244
     * 
245
     * @return javax.swing.JList
246
     */
247
    private JList getListNorth() {
248
        if (listNorth == null) {
249
            listNorth = new JList();
250

    
251
            listNorth
252
                .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
253
            listNorth.setLayoutOrientation(JList.HORIZONTAL_WRAP);
254
            listNorth.setVisibleRowCount(-1);
255

    
256
            String ni_folder = "images" + File.separator + "northimages";
257
            File north_images_folder = new File(getClass().getClassLoader()
258
                    .getResource(ni_folder).getFile());
259
            listNorth.setSize(new java.awt.Dimension(300, 242));
260
            listNorth
261
                .setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
262

    
263
            File[] files = north_images_folder.listFiles();
264
            DefaultListModel listModel = new DefaultListModel();
265

    
266
            for (int i = 0; i < files.length; i++) {
267
                listModel.addElement(files[i].getAbsolutePath());
268
            }
269

    
270
            listNorth.setModel(listModel);
271

    
272
            SLDListBoxCellRenderer renderer = new SLDListBoxCellRenderer();
273
            renderer.setPreferredSize(new Dimension(60, 50));
274
            listNorth.setCellRenderer(renderer);
275
            if (fframenorth.getName() != null) {
276
                for (int i = 0; i < listNorth.getModel().getSize(); i++) {
277
                    if (((String) listNorth.getModel().getElementAt(i))
278
                        .endsWith(fframenorth.getName())) {
279
                        listNorth.setSelectedIndex(i);
280
                        m_file =
281
                            new File((String) listNorth.getSelectedValue());
282
                    }
283
                }
284

    
285
            }
286

    
287
            listNorth
288
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
289

    
290
                    public void valueChanged(
291
                        javax.swing.event.ListSelectionEvent e) {
292
                        m_file =
293
                            new File((String) ((JList) e.getSource())
294
                                .getSelectedValue());
295
                        path = m_file.getAbsolutePath();
296
                    }
297
                });
298
        }
299

    
300
        return listNorth;
301
    }
302

    
303
    /**
304
     * This method initializes scrollViews
305
     * 
306
     * @return javax.swing.JScrollPane
307
     */
308
    private JScrollPane getScrollViews() {
309
        if (scrollViews == null) {
310
            scrollViews = new JScrollPane();
311
            scrollViews.setBackground(Color.white);
312
            scrollViews.setBounds(new java.awt.Rectangle(3, 212, 357, 65));
313
            scrollViews.setViewportView(getListViews());
314
        }
315

    
316
        return scrollViews;
317
    }
318

    
319
    /**
320
     * This method initializes listViews
321
     * 
322
     * @return javax.swing.JList
323
     */
324
    private JList getListViews() {
325
        if (listViews == null) {
326
            ListViewModel listmodel = new ListViewModel();
327
            listmodel.addViews(layoutPanel);
328
            listViews = new javax.swing.JList();
329
            listViews.setModel(listmodel);
330

    
331
            for (int i = 0; i < listViews.getModel().getSize(); i++) {
332
                if (fframenorth.getFFrameDependence() != null) {
333
                    fframeview =
334
                        (FFrameView) listViews.getModel().getElementAt(i);
335

    
336
                    if (fframeview == fframenorth.getFFrameDependence()[0]) {
337
                        listViews.setSelectedIndex(i);
338
                    }
339
                }
340
            }
341

    
342
            listViews
343
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
344

    
345
                    private int selectIndex = -1;
346

    
347
                    public void valueChanged(
348
                        javax.swing.event.ListSelectionEvent e) {
349
                        IFFrame[] fframes =
350
                            layoutPanel.getLayoutContext().getFFrames();
351
                        int selectInt =
352
                            ((JList) e.getSource()).getSelectedIndex();
353
                        if (selectInt != selectIndex) {
354
                            selectIndex = selectInt;
355
                            if (selectIndex == -1) {
356
                                return;
357
                            }
358
                            fframeview =
359
                                (FFrameView) listViews.getModel().getElementAt(
360
                                    selectInt);
361

    
362
                            for (int i = 0; i < fframes.length; i++) {
363
                                IFFrame f = fframes[i];
364

    
365
                                if (f instanceof FFrameView) {
366
                                    if (((FFrameView) f).getView() == fframeview
367
                                        .getView()) {
368
                                        fframeDependence = fframeview;
369
                                        // fframenorth
370
                                        // .setFFrameDependence(fframeview);
371
                                    }
372
                                }
373
                            }
374
                        }
375
                    }
376
                });
377
        }
378

    
379
        return listViews;
380
    }
381

    
382
    public IFFrame getFFrame() {
383
        return newFFrameNorth;
384
    }
385

    
386
    public Object getWindowProfile() {
387
        return WindowInfo.DIALOG_PROFILE;
388
    }
389

    
390
} // @jve:decl-index=0:visual-constraint="10,10"