Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / gui / dialogs / FFrameNorthDialog.java @ 9392

History | View | Annotate | Download (11.2 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.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.gui.beans.AcceptCancelPanel;
55

    
56
import com.iver.andami.PluginServices;
57
import com.iver.andami.messages.NotificationManager;
58
import com.iver.andami.ui.mdiManager.WindowInfo;
59
import com.iver.cit.gvsig.AddLayer;
60
import com.iver.cit.gvsig.gui.styling.SLDListBoxCellRenderer;
61
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
62
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameNorth;
63
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameView;
64
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
65
import com.iver.cit.gvsig.project.documents.layout.fframes.ListViewModel;
66
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
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
                                                    if (m_file != null) {
130
                                                            newFFrameNorth=(FFrameNorth)fframenorth.cloneFFrame(layout);
131
                                                            Dimension dimension = null;
132

    
133
                                                            try {
134
                                                                    dimension = fframenorth.getBound(m_file.getAbsolutePath());
135
                                                            } catch (Exception ex) {
136
                                                                    NotificationManager.addError("Excepci?n :", ex);
137
                                                            }
138
                                                            newFFrameNorth.setFFrameDependence(fframeDependence);
139
                                                            newFFrameNorth.setPath(path);
140
                                                            newFFrameNorth.setViewing(0);
141
                                                            newFFrameNorth.setQuality(0);
142

    
143

    
144
                                                            newFFrameNorth.setName(m_file.getName());
145
                                                            newFFrameNorth.load(path);
146

    
147
                                                            // Ajustamos la relaci?n de aspecto a la altura.
148
                                                            double ratio = (float) (dimension.getWidth()) / (float) (dimension.getHeight());
149

    
150
                                                            double newWidth = rect.getHeight() * ratio;
151
                                                            Rectangle2D.Double rAdjust = new Rectangle2D.Double(rect.getMinX(),
152
                                                                            rect.getMinY(), newWidth, rect.getHeight());
153
                                                            rect = rAdjust;
154
                                                    }
155
                                                    newFFrameNorth.setBoundBox(FLayoutUtilities.toSheetRect(
156
                                                                    rect, layout.getLayoutControl().getAT()));
157
                                                    newFFrameNorth.setRotation(0);
158
                                                    PluginServices.getMDIManager().closeWindow(FFrameNorthDialog.this);
159
                                                    //layout.refresh();
160
                                                    isAcepted = true;
161
                                            }
162
                                    },
163
                                    new java.awt.event.ActionListener() { //Cancel
164
                                            public void actionPerformed(java.awt.event.ActionEvent e) {
165
                                                    PluginServices.getMDIManager().closeWindow(FFrameNorthDialog.this);
166
                                            }
167
                                    }
168

    
169
                    );
170
                    this.acceptCancel.setBounds(3, 290, 357, 30);
171

    
172
            }
173
            return this.acceptCancel;
174
    }
175

    
176
    /**
177
     * DOCUMENT ME!
178
     *
179
     * @param r 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.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
248
            listNorth.setLayoutOrientation(JList.HORIZONTAL_WRAP);
249
            listNorth.setVisibleRowCount(-1);
250

    
251
            File file = new File(AddLayer.class.getClassLoader()
252
                                               .getResource("northimages")
253
                                               .getFile());
254
            listNorth.setSize(new java.awt.Dimension(300, 242));
255
            listNorth.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
256

    
257
            File[] files = file.listFiles();
258
            DefaultListModel listModel = new DefaultListModel();
259

    
260
            for (int i = 0; i < files.length; i++) {
261
                listModel.addElement(files[i].getAbsolutePath());
262
            }
263

    
264
            listNorth.setModel(listModel);
265

    
266
            SLDListBoxCellRenderer renderer = new SLDListBoxCellRenderer();
267
            renderer.setPreferredSize(new Dimension(60, 50));
268
            listNorth.setCellRenderer(renderer);
269
            if (fframenorth.getName()!=null){
270
                    for (int i=0;i<listNorth.getModel().getSize();i++){
271
                            if (((String)listNorth.getModel().getElementAt(i)).endsWith(fframenorth.getName())){
272
                                    listNorth.setSelectedIndex(i);
273
                                    m_file = new File((String) listNorth.getSelectedValue());
274
                            }
275
                    }
276

    
277
            }
278

    
279
            listNorth.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
280

    
281
                                        public void valueChanged(
282
                        javax.swing.event.ListSelectionEvent e) {
283
                        m_file = new File((String) ((JList) e.getSource()).getSelectedValue());
284
                        path=m_file.getAbsolutePath();
285
                    }
286
                });
287
        }
288

    
289
        return listNorth;
290
    }
291

    
292
    /**
293
     * This method initializes scrollViews
294
     *
295
     * @return javax.swing.JScrollPane
296
     */
297
    private JScrollPane getScrollViews() {
298
        if (scrollViews == null) {
299
            scrollViews = new JScrollPane();
300
            scrollViews.setBackground(Color.white);
301
            scrollViews.setBounds(new java.awt.Rectangle(3, 212, 357, 65));
302
            scrollViews.setViewportView(getListViews());
303
        }
304

    
305
        return scrollViews;
306
    }
307

    
308
    /**
309
     * This method initializes listViews
310
     *
311
     * @return javax.swing.JList
312
     */
313
    private JList getListViews() {
314
        if (listViews == null) {
315
            ListViewModel listmodel = new ListViewModel();
316
            listmodel.addViews(layout);
317
            listViews = new javax.swing.JList();
318
            listViews.setModel(listmodel);
319

    
320
            for (int i = 0; i < listViews.getModel().getSize(); i++) {
321
                if (fframenorth.getFFrameDependence() != null) {
322
                    fframeview = (FFrameView) listViews.getModel().getElementAt(i);
323

    
324
                    if (fframeview == fframenorth.getFFrameDependence()) {
325
                        listViews.setSelectedIndex(i);
326
                    }
327
                }
328
            }
329

    
330
            listViews.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
331
                    private int selectIndex=-1;
332
                                        public void valueChanged(
333
                                                                javax.swing.event.ListSelectionEvent e) {
334
                                    IFFrame[] fframes=layout.getLayoutContext().getFFrames();
335
                                                        int selectInt = ((JList) e.getSource())
336
                                                                        .getSelectedIndex();
337
                                                        if (selectInt != selectIndex) {
338
                                                                selectIndex = selectInt;
339
                                                                if (selectIndex == -1)
340
                                                                        return;
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
} //  @jve:decl-index=0:visual-constraint="10,10"