Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / fframes / gui / dialogs / FFrameNorthDialog.java @ 29596

History | View | Annotate | Download (11.3 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 org.gvsig.app.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
import org.gvsig.andami.PluginServices;
55
import org.gvsig.andami.messages.NotificationManager;
56
import org.gvsig.andami.ui.mdiManager.WindowInfo;
57
import org.gvsig.app.extension.AddLayer;
58
import org.gvsig.app.gui.styling.SLDListBoxCellRenderer;
59
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
60
import org.gvsig.app.project.documents.layout.fframes.FFrameNorth;
61
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
62
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
63
import org.gvsig.app.project.documents.layout.fframes.ListViewModel;
64
import org.gvsig.app.project.documents.layout.gui.Layout;
65
import org.gvsig.gui.beans.AcceptCancelPanel;
66

    
67

    
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
    private AcceptCancelPanel acceptCancel = null;
88
    private FFrameView fframeDependence;
89
    private FFrameNorth newFFrameNorth;
90
    private String path;
91

    
92

    
93

    
94
    /**
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
        lblView.setBounds(new java.awt.Rectangle(5, 193, 325, 18));
112
        lblView.setText(PluginServices.getText(this, "marco_vista"));
113
        this.setLayout(null);
114
        this.setSize(370, 335);
115
        this.add(getScrollImages(), null);
116

    
117
        this.add(getAcceptCancel());
118

    
119
        this.add(getScrollViews(), null);
120
        this.add(lblView, null);
121
    }
122

    
123
    private AcceptCancelPanel getAcceptCancel(){
124
            if (this.acceptCancel == null ){
125
                    this.acceptCancel = new AcceptCancelPanel(
126
                                    new java.awt.event.ActionListener() { //Accept
127

    
128
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
129
                                                        newFFrameNorth=(FFrameNorth)fframenorth.cloneFFrame(layout);
130
                                                        if (m_file != null) {
131

    
132
                                                            Dimension dimension = null;
133

    
134
                                                            try {
135
                                                                    dimension = fframenorth.getBound(m_file.getAbsolutePath());
136
                                                            } catch (Exception ex) {
137
                                                                    NotificationManager.addError("Excepci?n :", ex);
138
                                                            }
139
                                                            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
                                                            // Ajustamos la relaci?n de aspecto a la altura.
147
                                                            double ratio = (float) (dimension.getWidth()) / (float) (dimension.getHeight());
148

    
149
                                                            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
                                                    newFFrameNorth.setBoundBox(FLayoutUtilities.toSheetRect(
155
                                                                    rect, layout.getLayoutControl().getAT()));
156
                                                    newFFrameNorth.setRotation(0);
157
                                                    PluginServices.getMDIManager().closeWindow(FFrameNorthDialog.this);
158
                                                    //layout.refresh();
159
                                                    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

    
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 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

    
280
                                        public void valueChanged(
281
                        javax.swing.event.ListSelectionEvent e) {
282
                        m_file = new File((String) ((JList) e.getSource()).getSelectedValue());
283
                        path=m_file.getAbsolutePath();
284
                    }
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
            scrollViews.setBounds(new java.awt.Rectangle(3, 212, 357, 65));
301
            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
                    if (fframeview == fframenorth.getFFrameDependence()[0]) {
324
                        listViews.setSelectedIndex(i);
325
                    }
326
                }
327
            }
328

    
329
            listViews.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
330
                    private int selectIndex=-1;
331
                                        public void valueChanged(
332
                                                                javax.swing.event.ListSelectionEvent e) {
333
                                    IFFrame[] fframes=layout.getLayoutContext().getFFrames();
334
                                                        int selectInt = ((JList) e.getSource())
335
                                                                        .getSelectedIndex();
336
                                                        if (selectInt != selectIndex) {
337
                                                                selectIndex = selectInt;
338
                                                                if (selectIndex == -1) {
339
                                                                        return;
340
                                                                }
341
                                                                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
                                                                                        fframeDependence=fframeview;
351
//                                                                                        fframenorth
352
//                                                                                                        .setFFrameDependence(fframeview);
353
                                                                                }
354
                                                                        }
355
                                                                }
356
                                                        }
357
                                                }
358
                                        });
359
                }
360

    
361
        return listViews;
362
    }
363

    
364
        public IFFrame getFFrame() {
365
                return newFFrameNorth;
366
        }
367

    
368

    
369
        public Object getWindowProfile() {
370
                return WindowInfo.DIALOG_PROFILE;
371
        }
372

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