Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / Popupmenu.java @ 6738

History | View | Annotate | Download (6.16 KB)

1
/*
2
 * Created on 12-ago-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.gui.layout;
46

    
47
import java.awt.Point;
48
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionListener;
50

    
51
import javax.swing.JMenuItem;
52
import javax.swing.JPopupMenu;
53

    
54
import com.iver.andami.PluginServices;
55
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend;
56
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
57

    
58

    
59
/**
60
 * Popupmenu de bot?n derecho que se abre sobre el Layout.
61
 *
62
 * @author Vicente Caballero Navarro
63
 */
64
public class Popupmenu extends JPopupMenu {
65
    private JMenuItem m_properties=null;
66
    private JMenuItem m_selecAll = null;
67
    private JMenuItem m_behind = null;
68
    private JMenuItem m_before = null;
69
        private JMenuItem m_position = null;
70
    private JMenuItem m_simplify = null;
71
    private JMenuItem m_refresh = null;
72
    private JMenuItem m_terminate=null;
73
    private FLayoutGraphics m_flg = null;
74
    private Layout m_layout = null;
75
    private Point m_p = null;
76

    
77
    /**
78
     * Crea un nuevo Popupmenu.
79
     *
80
     * @param layout Layout sobre el que se abre el Popupmenu.
81
     * @param p punto donde se abre el popupmenu.
82
     */
83
    public Popupmenu(Layout layout, Point p) {
84
        m_layout = layout;
85
        m_flg = new FLayoutGraphics(m_layout);
86
        m_p = p;
87
        initialize();
88
    }
89

    
90
    /**
91
     * Inicializa los componentes del Popupmenu.
92
     */
93
    private void initialize() {
94
            m_properties=new JMenuItem(PluginServices.getText(this,"propiedades"));
95
        m_selecAll = new JMenuItem(PluginServices.getText(this,"seleccionar_todos"));
96
        m_behind = new JMenuItem(PluginServices.getText(this,"colocar_detras"));
97
        m_before = new JMenuItem(PluginServices.getText(this,"colocar_delante"));
98
        m_position = new JMenuItem(PluginServices.getText(this,"tamano_posicion"));
99
        m_simplify = new JMenuItem(PluginServices.getText(this,"simplificar_leyenda"));
100
        m_refresh = new JMenuItem(PluginServices.getText(this,"refrescar"));
101
        m_terminate=new JMenuItem(PluginServices.getText(this,"terminar"));
102
        setEnables();
103
        add(m_properties);
104
        addSeparator();
105
        add(m_selecAll);
106
        addSeparator();
107
        add(m_behind);
108
        add(m_before);
109
        add(m_position);
110
                addSeparator();
111
                add(m_simplify);
112
        addSeparator();
113
        add(m_refresh);
114
        addSeparator();
115
        add(m_terminate);
116
                m_properties.addActionListener(new ActionListener() {
117
                                public void actionPerformed(ActionEvent e) {
118
                                        m_flg.openFFrameDialog();
119
                                }
120
                        });
121
        m_selecAll.addActionListener(new ActionListener() {
122
                public void actionPerformed(ActionEvent e) {
123
                    m_flg.selecAll();
124
                }
125
            });
126
        m_behind.addActionListener(new ActionListener() {
127
                public void actionPerformed(ActionEvent e) {
128
                    m_flg.behind();
129
                }
130
            });
131
        m_before.addActionListener(new ActionListener() {
132
                public void actionPerformed(ActionEvent e) {
133
                    m_flg.before();
134
                }
135
            });
136
                m_position.addActionListener(new ActionListener() {
137
                                public void actionPerformed(ActionEvent e) {
138
                                        m_flg.position();
139
                                }
140
                        });
141
        m_simplify.addActionListener(new ActionListener() {
142
                public void actionPerformed(ActionEvent e) {
143
                    m_flg.simplify();
144
                }
145
            });
146
        m_refresh.addActionListener(new ActionListener() {
147
                public void actionPerformed(ActionEvent e) {
148
                    m_layout.refresh();
149
                }
150
            });
151
        m_terminate.addActionListener(new ActionListener() {
152
            public void actionPerformed(ActionEvent e) {
153
                    m_layout.endGraphic();
154
            }
155
        });
156
        this.show(m_layout, m_p.x, m_p.y);
157
    }
158

    
159
        private void setEnables() {
160
                if ((m_layout.getTool()==Layout.POLYLINE ||
161
                                m_layout.getTool()==Layout.POLYGON)&&
162
                                m_layout.getGeometryAdapter().getPoints().length>0){
163

    
164
                        m_refresh.setVisible(false);
165
                        m_selecAll.setVisible(false);
166
                        m_properties.setVisible(false);
167
                        m_behind.setVisible(false);
168
                        m_before.setVisible(false);
169
                        m_position.setVisible(false);
170
                        m_simplify.setVisible(false);
171
                        m_terminate.setVisible(true);
172
                        return;
173
                }
174
                m_terminate.setVisible(false);
175
                IFFrame[] fframes=m_layout.getFFrameSelected();
176
                m_selecAll.setEnabled(m_layout.isEditable());
177
                if (fframes.length==0 || !m_layout.isEditable()) {
178
                m_properties.setEnabled(false);
179
                m_behind.setEnabled(false);
180
                m_before.setEnabled(false);
181
                m_position.setEnabled(false);
182
                m_simplify.setEnabled(false);
183
        }else {
184
                m_properties.setEnabled(true);
185
                m_behind.setEnabled(true);
186
                m_before.setEnabled(true);
187
                m_position.setEnabled(true);
188
                boolean simplify=false;
189
                for (int i =0;i<fframes.length;i++) {
190
                        if (fframes[i] instanceof FFrameLegend) {
191
                                simplify=true;
192
                        }
193
                }
194
                m_simplify.setEnabled(simplify);
195
        }
196
        }
197
}