Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / dialogs / FFrameNorthDialog.java @ 8745

History | View | Annotate | Download (10.9 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.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.layout.FLayoutUtilities;
61
import com.iver.cit.gvsig.gui.layout.Layout;
62
import com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth;
63
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView;
64
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
65
import com.iver.cit.gvsig.gui.layout.fframes.ListViewModel;
66
import com.iver.cit.gvsig.gui.styling.SLDListBoxCellRenderer;
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

    
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(5, 193, 325, 18));
107
        lblView.setText(PluginServices.getText(this, "marco_vista"));
108
        this.setLayout(null);
109
        this.setSize(370, 335);
110
        this.add(getScrollImages(), null);
111
       
112
        this.add(getAcceptCancel());
113
        //this.add(getBAcept(), null);
114
        //this.add(getBCancel(), null);
115
        
116
        this.add(getScrollViews(), null);
117
        this.add(lblView, null);
118
    }
119
    
120
    private AcceptCancelPanel getAcceptCancel(){
121
            if (this.acceptCancel == null ){
122
                    this.acceptCancel = new AcceptCancelPanel(
123
                                    new java.awt.event.ActionListener() { //Accept
124
                                            public void actionPerformed(java.awt.event.ActionEvent e) {
125
                                                    if (m_file != null) {
126
                                                            Dimension dimension = null;
127
                                                            
128
                                                            try {
129
                                                                    dimension = fframenorth.getBound(m_file.getAbsolutePath());
130
                                                            } catch (Exception ex) {
131
                                                                    NotificationManager.addError("Excepci?n :", ex);
132
                                                            }
133
                                                            fframenorth.setPath(m_file.getAbsolutePath());
134
                                                            fframenorth.setViewing(0);
135
                                                            fframenorth.setQuality(0);
136
                                                            
137
                                                            
138
                                                            fframenorth.setName(m_file.getName());
139
                                                            
140
                                                            
141
                                                            // Ajustamos la relaci?n de aspecto a la altura.
142
                                                            double ratio = (float) (dimension.getWidth()) / (float) (dimension.getHeight());
143
                                                            
144
                                                            double newWidth = rect.getHeight() * ratio;
145
                                                            Rectangle2D.Double rAdjust = new Rectangle2D.Double(rect.getMinX(),
146
                                                                            rect.getMinY(), newWidth, rect.getHeight());
147
                                                            rect = rAdjust;
148
                                                    }
149
                                                    fframenorth.setBoundBox(FLayoutUtilities.toSheetRect(
150
                                                                    rect, layout.getAT()));
151
                                                    fframenorth.setRotation(0);
152
                                                    PluginServices.getMDIManager().closeWindow(FFrameNorthDialog.this);
153
                                                    layout.refresh();
154
                                                    isAcepted = true;
155
                                            }
156
                                    },
157
                                    new java.awt.event.ActionListener() { //Cancel
158
                                            public void actionPerformed(java.awt.event.ActionEvent e) {
159
                                                    PluginServices.getMDIManager().closeWindow(FFrameNorthDialog.this);
160
                                            }
161
                                    }
162
                                    
163
                    );
164
                    this.acceptCancel.setBounds(3, 290, 357, 30);
165
                    
166
            }
167
            return this.acceptCancel;
168
    }
169

    
170
    /**
171
     * DOCUMENT ME!
172
     *
173
     * @param r DOCUMENT ME!
174
     */
175
    public void setRectangle(Rectangle2D r) {
176
        rect.setRect(r);
177
    }
178

    
179
    /**
180
     * DOCUMENT ME!
181
     *
182
     * @return DOCUMENT ME!
183
     */
184
    public WindowInfo getWindowInfo() {
185
        WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
186
        m_viewinfo.setTitle(PluginServices.getText(this,
187
                "propiedades_marco_imagenes"));
188

    
189
        return m_viewinfo;
190
    }
191

    
192
    /**
193
     * DOCUMENT ME!
194
     *
195
     * @return DOCUMENT ME!
196
     */
197
    public boolean getIsAcepted() {
198
        return isAcepted;
199
    }
200

    
201
    /**
202
     * This method initializes scrollImages
203
     *
204
     * @return javax.swing.JScrollPane
205
     */
206
    private JScrollPane getScrollImages() {
207
        if (scrollImages == null) {
208
            scrollImages = new JScrollPane();
209
            scrollImages.setBounds(new java.awt.Rectangle(3, 3, 357, 174));
210
            scrollImages.setBackground(java.awt.Color.white);
211
            scrollImages.setViewportView(getPImages());
212
        }
213

    
214
        return scrollImages;
215
    }
216

    
217
    /**
218
     * This method initializes pImages
219
     *
220
     * @return javax.swing.JPanel
221
     */
222
    private JPanel getPImages() {
223
        if (pImages == null) {
224
            pImages = new JPanel();
225
            pImages.setBackground(java.awt.Color.white);
226
            pImages.add(getListNorth(), null);
227
        }
228

    
229
        return pImages;
230
    }
231

    
232
    /**
233
     * This method initializes listNorth
234
     *
235
     * @return javax.swing.JList
236
     */
237
    private JList getListNorth() {
238
        if (listNorth == null) {
239
            listNorth = new JList();
240

    
241
            listNorth.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
242
            listNorth.setLayoutOrientation(JList.HORIZONTAL_WRAP);
243
            listNorth.setVisibleRowCount(-1);
244

    
245
            File file = new File(AddLayer.class.getClassLoader()
246
                                               .getResource("northimages")
247
                                               .getFile());
248
            listNorth.setSize(new java.awt.Dimension(300, 242));
249
            listNorth.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
250

    
251
            File[] files = file.listFiles();
252
            DefaultListModel listModel = new DefaultListModel();
253

    
254
            for (int i = 0; i < files.length; i++) {
255
                listModel.addElement(files[i].getAbsolutePath());
256
            }
257

    
258
            listNorth.setModel(listModel);
259

    
260
            SLDListBoxCellRenderer renderer = new SLDListBoxCellRenderer();
261
            renderer.setPreferredSize(new Dimension(60, 50));
262
            listNorth.setCellRenderer(renderer);
263
            if (fframenorth.getName()!=null){
264
                    for (int i=0;i<listNorth.getModel().getSize();i++){
265
                            if (((String)listNorth.getModel().getElementAt(i)).endsWith(fframenorth.getName())){
266
                                    listNorth.setSelectedIndex(i);
267
                                    m_file = new File((String) listNorth.getSelectedValue());
268
                            }
269
                    }
270

    
271
            }
272

    
273
            listNorth.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
274
                    public void valueChanged(
275
                        javax.swing.event.ListSelectionEvent e) {
276
                        m_file = new File((String) ((JList) e.getSource()).getSelectedValue());
277
                    }
278
                });
279
        }
280

    
281
        return listNorth;
282
    }
283

    
284
    /**
285
     * This method initializes scrollViews
286
     *
287
     * @return javax.swing.JScrollPane
288
     */
289
    private JScrollPane getScrollViews() {
290
        if (scrollViews == null) {
291
            scrollViews = new JScrollPane();
292
            scrollViews.setBackground(Color.white);
293
            scrollViews.setBounds(new java.awt.Rectangle(3, 212, 357, 65));
294
            scrollViews.setViewportView(getListViews());
295
        }
296

    
297
        return scrollViews;
298
    }
299

    
300
    /**
301
     * This method initializes listViews
302
     *
303
     * @return javax.swing.JList
304
     */
305
    private JList getListViews() {
306
        if (listViews == null) {
307
            ListViewModel listmodel = new ListViewModel();
308
            listmodel.addViews(layout);
309
            listViews = new javax.swing.JList();
310
            listViews.setModel(listmodel);
311

    
312
            for (int i = 0; i < listViews.getModel().getSize(); i++) {
313
                if (fframenorth.getFFrameDependence() != null) {
314
                    fframeview = (FFrameView) listViews.getModel().getElementAt(i);
315

    
316
                    if (fframeview == fframenorth.getFFrameDependence()) {
317
                        listViews.setSelectedIndex(i);
318
                    }
319
                }
320
            }
321

    
322
            listViews.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
323
                    private int selectIndex=-1;
324
                            public void valueChanged(
325
                                                                javax.swing.event.ListSelectionEvent e) {
326
                                    IFFrame[] fframes=layout.getFFrames();
327
                                                        int selectInt = ((JList) e.getSource())
328
                                                                        .getSelectedIndex();
329
                                                        if (selectInt != selectIndex) {
330
                                                                selectIndex = selectInt;
331
                                                                if (selectIndex == -1)
332
                                                                        return;
333
                                                                fframeview = (FFrameView) listViews.getModel()
334
                                                                                .getElementAt(selectInt);
335

    
336
                                                                for (int i = 0; i < fframes.length; i++) {
337
                                                                        IFFrame f =fframes[i];
338

    
339
                                                                        if (f instanceof FFrameView) {
340
                                                                                if (((FFrameView) f).getView() == fframeview
341
                                                                                                .getView()) {
342
                                                                                        fframenorth
343
                                                                                                        .setFFrameDependence(fframeview);
344
                                                                                }
345
                                                                        }
346
                                                                }
347
                                                        }
348
                                                }
349
                                        });
350
                }
351

    
352
        return listViews;
353
    }
354
} //  @jve:decl-index=0:visual-constraint="10,10"