Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / dialogs / FFrameNorthDialog.java @ 2984

History | View | Annotate | Download (11.7 KB)

1
/* 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
import com.iver.cit.gvsig.gui.styling.SLDListBoxCellRenderer;
66

    
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
                        Dimension dimension = null;
192

    
193
                        try {
194
                            dimension = fframenorth.getBound(m_file.getAbsolutePath());
195
                        } catch (Exception ex) {
196
                            NotificationManager.addError("Excepci?n :", ex);
197
                        }
198
                        fframenorth.setPath(m_file.getAbsolutePath());
199
                        fframenorth.setViewing(0);
200
                        fframenorth.setQuality(0);
201

    
202
                        if (m_file != null) {
203
                            fframenorth.setName(m_file.getName());
204
                        }
205

    
206
                        // Ajustamos la relaci?n de aspecto a la altura.
207
                        double ratio = (float) (dimension.getWidth()) / (float) (dimension.getHeight());
208

    
209
                        double newWidth = rect.getHeight() * ratio;
210
                        Rectangle2D.Double rAdjust = new Rectangle2D.Double(rect.getMinX(),
211
                                rect.getMinY(), newWidth, rect.getHeight());
212
                        rect = rAdjust;
213

    
214
                        fframenorth.setBoundBox(FLayoutUtilities.toSheetRect(
215
                                rect, layout.getAT()));
216
                        fframenorth.setRotation(0);
217
                        PluginServices.getMDIManager().closeView(FFrameNorthDialog.this);
218
                        layout.refresh();
219
                        isAcepted = true;
220
                    }
221
                });
222
        }
223

    
224
        return bAcept;
225
    }
226

    
227
    /**
228
     * This method initializes bCancel
229
     *
230
     * @return javax.swing.JButton
231
     */
232
    private JButton getBCancel() {
233
        if (bCancel == null) {
234
            bCancel = new JButton();
235
            bCancel.setBounds(new java.awt.Rectangle(206, 268, 108, 28));
236
            bCancel.setText(PluginServices.getText(this, "Cancelar"));
237
            bCancel.addActionListener(new java.awt.event.ActionListener() {
238
                    public void actionPerformed(java.awt.event.ActionEvent e) {
239
                        PluginServices.getMDIManager().closeView(FFrameNorthDialog.this);
240
                    }
241
                });
242
        }
243

    
244
        return bCancel;
245
    }
246

    
247
    /**
248
     * This method initializes listNorth
249
     *
250
     * @return javax.swing.JList
251
     */
252
    private JList getListNorth() {
253
        if (listNorth == null) {
254
            listNorth = new JList();
255
            
256
            listNorth.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
257
            listNorth.setLayoutOrientation(JList.HORIZONTAL_WRAP);
258
            listNorth.setVisibleRowCount(-1);
259

    
260
            File file = new File(AddLayer.class.getClassLoader()
261
                                               .getResource("northimages")
262
                                               .getFile());
263
            listNorth.setSize(new java.awt.Dimension(300, 242));
264
            listNorth.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
265

    
266
            File[] files = file.listFiles();
267
            DefaultListModel listModel = new DefaultListModel();
268

    
269
            for (int i = 0; i < files.length; i++) {
270
                listModel.addElement(files[i].getAbsolutePath());
271
            }
272

    
273
            listNorth.setModel(listModel);
274

    
275
            SLDListBoxCellRenderer renderer = new SLDListBoxCellRenderer();
276
            renderer.setPreferredSize(new Dimension(60, 50));
277
            listNorth.setCellRenderer(renderer);
278
            if (fframenorth.getName()!=null){
279
                    for (int i=0;i<listNorth.getModel().getSize();i++){
280
                            if (((String)listNorth.getModel().getElementAt(i)).endsWith(fframenorth.getName())){
281
                                    listNorth.setSelectedIndex(i);
282
                                    m_file = new File((String) listNorth.getSelectedValue());
283
                            }
284
                    }
285
                    
286
            }
287
            
288
            listNorth.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
289
                    public void valueChanged(
290
                        javax.swing.event.ListSelectionEvent e) {
291
                        m_file = new File((String) ((JList) e.getSource()).getSelectedValue());
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(127, 191, 232, 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(layout);
324
            listViews = new javax.swing.JList();
325
            listViews.setModel(listmodel);
326

    
327
            for (int i = 0; i < listViews.getModel().getSize(); i++) {
328
                if (fframenorth.getFFrameView() != null) {
329
                    fframeview = (FFrameView) listViews.getModel().getElementAt(i);
330

    
331
                    if (fframeview == fframenorth.getFFrameView()) {
332
                        listViews.setSelectedIndex(i);
333
                    }
334
                }
335
            }
336

    
337
            listViews.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
338
                    public void valueChanged(
339
                        javax.swing.event.ListSelectionEvent e) {
340
                        int selectInt = (int) e.getFirstIndex();
341
                        fframeview = (FFrameView) listViews.getModel()
342
                                                           .getElementAt(selectInt);
343

    
344
                        for (int i = 0; i < layout.getFFrames().size(); i++) {
345
                            IFFrame f = (IFFrame) layout.getFFrames().get(i);
346

    
347
                            if (f instanceof FFrameView) {
348
                                if (((FFrameView) f).getView() == fframeview.getView()) {
349
                                    fframenorth.setFFrameView(fframeview);
350
                                }
351
                            }
352
                        }
353

    
354
                   }
355
                });
356
        }
357

    
358
        return listViews;
359
    }
360
} //  @jve:decl-index=0:visual-constraint="10,10"