Statistics
| Revision:

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

History | View | Annotate | Download (6.74 KB)

1 7304 caballero
/*
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.project.documents.layout.gui;
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.project.documents.layout.FLayoutGraphics;
56 9392 caballero
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameLegend;
57 7304 caballero
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
58 9392 caballero
import com.iver.cit.gvsig.project.documents.layout.tools.listener.ILayoutGraphicListener;
59 7304 caballero
60
61
/**
62
 * Popupmenu de bot?n derecho que se abre sobre el Layout.
63
 *
64
 * @author Vicente Caballero Navarro
65
 */
66
public class Popupmenu extends JPopupMenu {
67
    private JMenuItem m_properties=null;
68
    private JMenuItem m_selecAll = null;
69
    private JMenuItem m_behind = null;
70
    private JMenuItem m_before = null;
71
        private JMenuItem m_position = null;
72
    private JMenuItem m_simplify = null;
73
    private JMenuItem m_refresh = null;
74
    private JMenuItem m_terminate=null;
75
    private FLayoutGraphics m_flg = null;
76
    private Layout m_layout = null;
77
    private Point m_p = null;
78
79
    /**
80
     * Crea un nuevo Popupmenu.
81
     *
82
     * @param layout Layout sobre el que se abre el Popupmenu.
83
     * @param p punto donde se abre el popupmenu.
84
     */
85
    public Popupmenu(Layout layout, Point p) {
86
        m_layout = layout;
87
        m_flg = new FLayoutGraphics(m_layout);
88
        m_p = p;
89
        initialize();
90
    }
91
92
    /**
93
     * Inicializa los componentes del Popupmenu.
94
     */
95
    private void initialize() {
96
            m_properties=new JMenuItem(PluginServices.getText(this,"propiedades"));
97
        m_selecAll = new JMenuItem(PluginServices.getText(this,"seleccionar_todos"));
98
        m_behind = new JMenuItem(PluginServices.getText(this,"colocar_detras"));
99
        m_before = new JMenuItem(PluginServices.getText(this,"colocar_delante"));
100
        m_position = new JMenuItem(PluginServices.getText(this,"tamano_posicion"));
101
        m_simplify = new JMenuItem(PluginServices.getText(this,"simplificar_leyenda"));
102
        m_refresh = new JMenuItem(PluginServices.getText(this,"refrescar"));
103
        m_terminate=new JMenuItem(PluginServices.getText(this,"terminar"));
104
        setEnables();
105
        add(m_properties);
106
        addSeparator();
107
        add(m_selecAll);
108
        addSeparator();
109
        add(m_behind);
110
        add(m_before);
111
        add(m_position);
112
                addSeparator();
113
                add(m_simplify);
114
        addSeparator();
115
        add(m_refresh);
116
        addSeparator();
117
        add(m_terminate);
118
                m_properties.addActionListener(new ActionListener() {
119
                                public void actionPerformed(ActionEvent e) {
120
                                        m_flg.openFFrameDialog();
121
                                }
122
                        });
123
        m_selecAll.addActionListener(new ActionListener() {
124
                public void actionPerformed(ActionEvent e) {
125
                    m_flg.selecAll();
126
                }
127
            });
128
        m_behind.addActionListener(new ActionListener() {
129
                public void actionPerformed(ActionEvent e) {
130
                    m_flg.behind();
131
                }
132
            });
133
        m_before.addActionListener(new ActionListener() {
134
                public void actionPerformed(ActionEvent e) {
135
                    m_flg.before();
136
                }
137
            });
138
                m_position.addActionListener(new ActionListener() {
139
                                public void actionPerformed(ActionEvent e) {
140
                                        m_flg.position();
141
                                }
142
                        });
143
        m_simplify.addActionListener(new ActionListener() {
144
                public void actionPerformed(ActionEvent e) {
145
                    m_flg.simplify();
146
                }
147
            });
148
        m_refresh.addActionListener(new ActionListener() {
149
                public void actionPerformed(ActionEvent e) {
150 9392 caballero
                    m_layout.getLayoutControl().fullRefresh();
151 7304 caballero
                }
152
            });
153
        m_terminate.addActionListener(new ActionListener() {
154
            public void actionPerformed(ActionEvent e) {
155 9392 caballero
                    if (m_layout.getLayoutControl().getCurrentLayoutTool().getListener() instanceof ILayoutGraphicListener) {
156
                            ((ILayoutGraphicListener)m_layout.getLayoutControl().getCurrentLayoutTool().getListener()).endGraphic();
157
                    }
158 7304 caballero
            }
159
        });
160
        this.show(m_layout, m_p.x, m_p.y);
161
    }
162
163
        private void setEnables() {
164 9392 caballero
                if ((m_layout.getLayoutControl().getCurrentTool().equals("layoutaddpolyline") ||
165
                                m_layout.getLayoutControl().getCurrentTool().equals("layoutaddpolygon"))&&
166
                                m_layout.getLayoutControl().getGeometryAdapter().getPoints().length>0){
167 7304 caballero
168
                        m_refresh.setVisible(false);
169
                        m_selecAll.setVisible(false);
170
                        m_properties.setVisible(false);
171
                        m_behind.setVisible(false);
172
                        m_before.setVisible(false);
173
                        m_position.setVisible(false);
174
                        m_simplify.setVisible(false);
175
                        m_terminate.setVisible(true);
176
                        return;
177
                }
178
                m_terminate.setVisible(false);
179 9392 caballero
                IFFrame[] fframes=m_layout.getLayoutContext().getFFrameSelected();
180
                m_selecAll.setEnabled(m_layout.getLayoutContext().isEditable());
181
                if (fframes.length==0 || !m_layout.getLayoutContext().isEditable()) {
182 7304 caballero
                m_properties.setEnabled(false);
183
                m_behind.setEnabled(false);
184
                m_before.setEnabled(false);
185
                m_position.setEnabled(false);
186
                m_simplify.setEnabled(false);
187
        }else {
188
                m_properties.setEnabled(true);
189
                m_behind.setEnabled(true);
190
                m_before.setEnabled(true);
191
                m_position.setEnabled(true);
192
                boolean simplify=false;
193
                for (int i =0;i<fframes.length;i++) {
194
                        if (fframes[i] instanceof FFrameLegend) {
195
                                simplify=true;
196
                        }
197
                }
198
                m_simplify.setEnabled(simplify);
199
        }
200
        }
201
}