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 / FFrameOverViewDialog.java @ 717

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.event.ActionEvent;
25
import java.awt.geom.Rectangle2D;
26
import java.util.ArrayList;
27
import java.util.List;
28

    
29
import javax.swing.JList;
30

    
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.andami.ui.mdiManager.WindowInfo;
33
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
34
import org.gvsig.app.project.documents.layout.fframes.FFrameOverView;
35
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
36
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
37
import org.gvsig.app.project.documents.layout.fframes.ListViewModel;
38
import org.gvsig.app.project.documents.layout.fframes.ListWithoutOverViewModel;
39
import org.gvsig.app.project.documents.layout.fframes.gui.JPRotation;
40
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
41

    
42
/**
43
 * Di?logo para a?adir una localizador al Layout.
44
 * 
45
 * @author Vicente Caballero Navarro
46
 */
47
public class FFrameOverViewDialog extends AbstractFFrameDialog implements
48
    IFFrameDialog {
49

    
50
    private static final long serialVersionUID = 4912177399119383422L;
51
    private javax.swing.JPanel jContentPane = null; // @jve:decl-index=0:visual-constraint="37,10"
52
    private javax.swing.JLabel lVistas = null;
53
    private javax.swing.JScrollPane jScrollPane = null;
54
    private javax.swing.JList liVistas = null; // @jve:visual-info decl-index=0
55
                                               // visual-constraint="98,-3"
56
    private javax.swing.JButton bAceptar = null;
57
    private javax.swing.JButton bCancelar = null;
58
    private javax.swing.JLabel lCalidad = null;
59
    private javax.swing.JComboBox cbCalidad = null;
60
    private Rectangle2D rect = new Rectangle2D.Double();
61
    private FFrameOverView fframeoverview = null; // new FFrameView();
62
    private boolean isAcepted = false;
63
    private JPRotation rotation = null;
64
    private FFrameOverView newFFrameView;
65
    private FFrameView fframeDependence;
66
    private FFrameView fframeview;
67

    
68
    /**
69
     * This is the default constructor
70
     * 
71
     * @param layoutPanel
72
     *            Referencia al Layout.
73
     * @param fframe
74
     *            Referencia al fframe vista.
75
     */
76
    public FFrameOverViewDialog(LayoutPanel layoutPanel, IFFrame frame) {
77
        super(layoutPanel, frame);
78
        fframeoverview = (FFrameOverView) frame;
79
        fframeDependence = (FFrameView) fframeoverview.getFFrameDependence()[0];
80
        initialize();
81
    }
82

    
83
    /**
84
     * This method initializes this
85
     */
86
    private void initialize() {
87
        this.setLayout(null);
88
        this.add(getJContentPane(), null);
89
        this.setSize(463, 222);
90

    
91
        getPRotation().setRotation(fframeoverview.getRotation());
92
    }
93

    
94
    /**
95
     * Inserta el rect?ngulo que ocupar? el fframe vista.
96
     * 
97
     * @param r
98
     *            Rect?ngulo.
99
     */
100
    public void setRectangle(Rectangle2D r) {
101
        rect.setRect(r);
102
    }
103

    
104
    /**
105
     * This method initializes jContentPane
106
     * 
107
     * @return javax.swing.JPanel
108
     */
109
    private javax.swing.JPanel getJContentPane() {
110
        if (jContentPane == null) {
111
            jContentPane = new javax.swing.JPanel();
112
            jContentPane.setLayout(null);
113
            jContentPane.add(getLVistas(), null);
114
            jContentPane.add(getJScrollPane(), null);
115
            jContentPane.add(getLCalidad(), null);
116
            jContentPane.add(getCbCalidad(), null);
117
            jContentPane.add(getbAceptar(), null);
118
            jContentPane.add(getBCancelar(), null);
119
            jContentPane.setSize(462, 184);
120
            jContentPane.setPreferredSize(new java.awt.Dimension(60, 60));
121
            jContentPane.setLocation(0, 0);
122
            jContentPane.add(getPRotation(), null);
123
        }
124

    
125
        return jContentPane;
126
    }
127

    
128
    /**
129
     * This method initializes lVistas
130
     * 
131
     * @return javax.swing.JLabel
132
     */
133
    private javax.swing.JLabel getLVistas() {
134
        if (lVistas == null) {
135
            lVistas = new javax.swing.JLabel();
136
            lVistas.setSize(85, 19);
137
            lVistas.setText(PluginServices.getText(this, "Vista"));
138
            lVistas.setLocation(10, 10);
139
        }
140

    
141
        return lVistas;
142
    }
143

    
144
    /**
145
     * This method initializes jScrollPane
146
     * 
147
     * @return javax.swing.JScrollPane
148
     */
149
    private javax.swing.JScrollPane getJScrollPane() {
150
        if (jScrollPane == null) {
151
            jScrollPane = new javax.swing.JScrollPane();
152
            jScrollPane.setViewportView(getLiVistas());
153
            jScrollPane.setBounds(99, 8, 224, 64);
154
            jScrollPane.setPreferredSize(new java.awt.Dimension(250, 60));
155
        }
156

    
157
        return jScrollPane;
158
    }
159

    
160
    /**
161
     * This method initializes liVistas
162
     * 
163
     * @return javax.swing.JList
164
     */
165
    private javax.swing.JList getLiVistas() {
166
        if (liVistas == null) {
167
            ListViewModel listmodel = new ListWithoutOverViewModel();
168

    
169
            listmodel.addViews(layoutPanel);
170
            
171
            // ================ Remove frames with view = null
172
            List<FFrameView> toremove = new ArrayList();
173
            int sz = listmodel.getSize();
174
            Object item = null;
175
            FFrameView item_fv = null;
176
            for (int i=0; i<sz; i++) {
177
                item = listmodel.getElementAt(i);
178
                if (item instanceof FFrameView) {
179
                    item_fv = (FFrameView) item;
180
                    if (item_fv.getView() == null) {
181
                        toremove.add(item_fv);
182
                    }
183
                }
184
            }
185
            for (int i=0; i<toremove.size(); i++) {
186
                listmodel.removeFrameView(toremove.get(i));
187
            }
188
            // ================
189

    
190
            liVistas = new javax.swing.JList();
191
            liVistas.setModel(listmodel);
192

    
193
            for (int i = 0; i < liVistas.getModel().getSize(); i++) {
194
                if (fframeDependence != null) {
195
                    fframeview =
196
                        (FFrameView) liVistas.getModel().getElementAt(i);
197

    
198
                    if (fframeview == fframeoverview.getFFrameDependence()[0]) {
199
                        liVistas.setSelectedIndex(i);
200
                    }
201
                }
202
            }
203

    
204
            liVistas
205
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
206

    
207
                    private int selectIndex = -1;
208

    
209
                    public void valueChanged(
210
                        javax.swing.event.ListSelectionEvent e) {
211
                        IFFrame[] fframes =
212
                            layoutPanel.getLayoutContext().getFFrames();
213
                        int selectInt =
214
                            ((JList) e.getSource()).getSelectedIndex();
215
                        if (selectInt != selectIndex) {
216
                            selectIndex = selectInt;
217
                            if (selectIndex == -1) {
218
                                return;
219
                            }
220
                            fframeview =
221
                                (FFrameView) liVistas.getModel().getElementAt(
222
                                    selectInt);
223

    
224
                            for (int i = 0; i < fframes.length; i++) {
225
                                IFFrame f = fframes[i];
226

    
227
                                if (f instanceof FFrameView) {
228
                                    if (((FFrameView) f).getView() == fframeview
229
                                        .getView()) {
230
                                        fframeDependence = fframeview;
231
                                    }
232
                                }
233
                            }
234
                        }
235
                    }
236

    
237
                });
238
        }
239

    
240
        return liVistas;
241
    }
242

    
243
    /**
244
     * This method initializes jButton
245
     * 
246
     * @return javax.swing.JButton
247
     */
248
    private javax.swing.JButton getbAceptar() {
249
        if (bAceptar == null) {
250
            bAceptar = new javax.swing.JButton();
251
            bAceptar.setSize(85, 26);
252
            bAceptar.setText(PluginServices.getText(this, "Aceptar"));
253
            bAceptar.setLocation(59, 136);
254
            bAceptar.addActionListener(new java.awt.event.ActionListener() {
255

    
256
                public void actionPerformed(java.awt.event.ActionEvent e) {
257
                    try {
258
                        newFFrameView = (FFrameOverView) fframeoverview.clone();
259
                        newFFrameView.setBoundBox(FLayoutUtilities.toSheetRect(
260
                            rect, layoutPanel.getLayoutControl().getAT()));
261
                        newFFrameView.setRotation(getPRotation().getRotation());
262
                        if (fframeDependence != null) {
263
                            newFFrameView.setFFrameDependence(fframeDependence);
264
                            newFFrameView.setView(fframeDependence.getView());
265

    
266
                            newFFrameView.setQuality(getCbCalidad()
267
                                .getSelectedIndex());
268
                            newFFrameView.setBoundBox(FLayoutUtilities
269
                                .toSheetRect(rect, layoutPanel
270
                                    .getLayoutControl().getAT()));
271

    
272
                        fireActionEvent(new ActionEvent(FFrameOverViewDialog.this, 1, "accept"));
273
                        }
274
                    } catch (CloneNotSupportedException e1) {
275
                        LOG.error("It is not possible clonate the object", e);
276
                    }
277

    
278
                    isAcepted = true;
279
                    PluginServices.getMDIManager().closeWindow(
280
                        FFrameOverViewDialog.this);
281
                    notifyDialogClosed();
282
                    layoutPanel.getLayoutControl().setDefaultTool();
283
                    fframeoverview.refresh();
284
                }
285
            });
286
        }
287

    
288
        return bAceptar;
289
    }
290

    
291
    /**
292
     * This method initializes bCancelar
293
     * 
294
     * @return javax.swing.JButton
295
     */
296
    private javax.swing.JButton getBCancelar() {
297
        if (bCancelar == null) {
298
            bCancelar = new javax.swing.JButton();
299
            bCancelar.setSize(85, 26);
300
            bCancelar.setText(PluginServices.getText(this, "Cancelar"));
301
            bCancelar.setLocation(199, 136);
302
            bCancelar.addActionListener(new java.awt.event.ActionListener() {
303

    
304
                public void actionPerformed(java.awt.event.ActionEvent e) {
305
                    newFFrameView = null;
306
                    PluginServices.getMDIManager().closeWindow(
307
                        FFrameOverViewDialog.this);
308
                    notifyDialogClosed();
309
                }
310
            });
311
        }
312

    
313
        return bCancelar;
314
    }
315

    
316
    /**
317
     * This method initializes lCalidad
318
     * 
319
     * @return javax.swing.JLabel
320
     */
321
    private javax.swing.JLabel getLCalidad() {
322
        if (lCalidad == null) {
323
            lCalidad = new javax.swing.JLabel();
324
            lCalidad.setSize(86, 16);
325
            lCalidad.setText(PluginServices.getText(this, "calidad"));
326
            lCalidad.setLocation(14, 112);
327
        }
328

    
329
        return lCalidad;
330
    }
331

    
332
    /**
333
     * This method initializes cbCalidad
334
     * 
335
     * @return javax.swing.JComboBox
336
     */
337
    private javax.swing.JComboBox getCbCalidad() {
338
        if (cbCalidad == null) {
339
            // String[] s={"Presentaci?n","Borrador"};
340
            cbCalidad = new javax.swing.JComboBox();
341
            cbCalidad.setSize(220, 20);
342
            cbCalidad.addItem(PluginServices.getText(this, "presentacion"));
343
            cbCalidad.addItem(PluginServices.getText(this, "borrador"));
344
            cbCalidad.setSelectedIndex(fframeoverview.getQuality());
345
            cbCalidad.setPreferredSize(new java.awt.Dimension(200, 20));
346
            cbCalidad.setLocation(104, 112);
347
        }
348

    
349
        return cbCalidad;
350
    }
351

    
352
    /*
353
     * (non-Javadoc)
354
     * 
355
     * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
356
     */
357
    public WindowInfo getWindowInfo() {
358
        WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
359

    
360
        // vi.setResizable(false);
361
        m_viewinfo.setTitle(PluginServices.getText(this,
362
            "propiedades_marco_localizador"));
363

    
364
        return m_viewinfo;
365
    }
366

    
367
    /**
368
     * @see org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
369
     */
370
    public boolean getIsAcepted() {
371
        return isAcepted;
372
    }
373

    
374
    /**
375
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
376
     */
377
    public void viewActivated() {
378
    }
379

    
380
    /**
381
     * This method initializes rotation
382
     * 
383
     * @return javax.swing.JPanel
384
     */
385
    private JPRotation getPRotation() {
386
        if (rotation == null) {
387
            rotation = new JPRotation();
388
            rotation.setBounds(330, 30, 120, 130);
389
        }
390
        return rotation;
391
    }
392

    
393
    public IFFrame getFFrame() {
394
        return newFFrameView;
395
    }
396

    
397
    public Object getWindowProfile() {
398
        return WindowInfo.DIALOG_PROFILE;
399
    }
400

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