Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / table / gui / PopupMenu.java @ 7738

History | View | Annotate | Download (9.42 KB)

1 7304 caballero
/* 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.table.gui;
42
43
import java.awt.Point;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46
import java.io.IOException;
47
48
import javax.swing.ImageIcon;
49
import javax.swing.JMenuItem;
50
import javax.swing.JPopupMenu;
51
52 7738 jaume
import com.iver.andami.PluginServices;
53
import com.iver.cit.gvsig.AddLayer;
54
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
55 7304 caballero
56 7738 jaume
57 7304 caballero
/**
58
 * PopupMenu with options to operate on the table.
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class PopupMenu extends JPopupMenu {
63
    private static final ImageIcon editcopy = new ImageIcon(AddLayer.class.getClassLoader()
64
                                                                          .getResource("images/editcopy.png"));
65
    private static final ImageIcon editcut = new ImageIcon(AddLayer.class.getClassLoader()
66
                                                                         .getResource("images/editcut.png"));
67
    private static final ImageIcon editpaste = new ImageIcon(AddLayer.class.getClassLoader()
68
                                                                           .getResource("images/editpaste.png"));
69
    private static final ImageIcon editdelete = new ImageIcon(AddLayer.class.getClassLoader()
70
                                                                            .getResource("images/editdelete.png"));
71
    private JMenuItem copy = null;
72
    private JMenuItem cut = null;
73
    private JMenuItem paste = null;
74
    //private JMenuItem insertRow = null;
75
    //private JMenuItem insertColumn = null;
76
    private JMenuItem removeRow = null;
77
    //private JMenuItem removeColumn = null;
78
    //private JMenuItem startEdition = null;
79
    //private JMenuItem stopEdition = null;
80
    private Table table = null;
81
    private Point point = null;
82
83
    /**
84
     * Create a new PopupMenu.
85
     *
86
     * @param p Point to location.
87
     */
88
    public PopupMenu(Point p) {
89
        point = p;
90
        initialize();
91
    }
92
93
    /**
94
     * Initialize the components of Popupmenu.
95
     */
96
    private void initialize() {
97
        copy = new JMenuItem(PluginServices.getText(this, "copiar"), editcopy);
98
        cut = new JMenuItem(PluginServices.getText(this, "cortar"), editcut);
99
        paste = new JMenuItem(PluginServices.getText(this, "pegar"), editpaste);
100
//        insertRow = new JMenuItem(PluginServices.getText(this, "insertar_fila"));
101
//        insertColumn = new JMenuItem(PluginServices.getText(this,
102
//                    "insertar_columna"));
103
        removeRow = new JMenuItem(PluginServices.getText(this, "eliminar_fila"),
104
                editdelete);
105
//        removeColumn = new JMenuItem(PluginServices.getText(this,
106
//                    "eliminar_columna"));
107
//        startEdition = new JMenuItem(PluginServices.getText(this,
108
//                    "comenzar_edicion"));
109
//        stopEdition = new JMenuItem(PluginServices.getText(this,
110
//                    "terminar_edicion"));
111
112
//        add(startEdition);
113
//        add(stopEdition);
114
//        addSeparator();
115
        add(copy);
116
        add(cut);
117
        add(paste);
118
        addSeparator();
119
//        add(insertRow);
120
        add(removeRow);
121
//        add(insertColumn);
122
//        add(removeColumn);
123
124
        table = (Table) PluginServices.getMDIManager().getActiveWindow();
125
//        startEdition.addActionListener(new ActionListener() {
126
//                public void actionPerformed(ActionEvent e) {
127
//                        try {
128
//                                                        table.startEditing();
129
//                                                } catch (EditionException e1) {
130
//                                                        // TODO Auto-generated catch block
131
//                                                        e1.printStackTrace();
132
//                                                }
133
//                        PluginServices.getMainFrame().enableControls();
134
//                }
135
//            });
136
//        stopEdition.addActionListener(new ActionListener() {
137
//                public void actionPerformed(ActionEvent e) {
138
//
139
//                        table.stopEditing();
140
//                        PluginServices.getMainFrame().enableControls();
141
//
142
//                }
143
//            });
144
        copy.addActionListener(new ActionListener() {
145
                public void actionPerformed(ActionEvent e) {
146
147
                        try {
148
                                                        table.copyRow();
149
                                                } catch (DriverIOException e1) {
150
                                                        // TODO Auto-generated catch block
151
                                                        e1.printStackTrace();
152
                                                } catch (IOException e1) {
153
                                                        // TODO Auto-generated catch block
154
                                                        e1.printStackTrace();
155
                                                }
156
                        PluginServices.getMainFrame().enableControls();
157
158
                }
159
            });
160
        cut.addActionListener(new ActionListener() {
161
                public void actionPerformed(ActionEvent e) {
162
163
                        try {
164
                                                        table.cutRow();
165
                                                } catch (DriverIOException e1) {
166
                                                        // TODO Auto-generated catch block
167
                                                        e1.printStackTrace();
168
                                                } catch (IOException e1) {
169
                                                        // TODO Auto-generated catch block
170
                                                        e1.printStackTrace();
171
                                                }
172
                        PluginServices.getMainFrame().enableControls();
173
174
                }
175
            });
176
        paste.addActionListener(new ActionListener() {
177
                public void actionPerformed(ActionEvent e) {
178
                    //TODO este m?todo a?ade las filas seleccionadas previamente al final de la tabla.
179
                    //De momento no se puede a?adir filas en una posici?n en concreto.
180
181
                        try {
182
                                                        table.pasteRow();
183
                                                } catch (DriverIOException e1) {
184
                                                        // TODO Auto-generated catch block
185
                                                        e1.printStackTrace();
186
                                                } catch (IOException e1) {
187
                                                        // TODO Auto-generated catch block
188
                                                        e1.printStackTrace();
189
                                                }
190
                        PluginServices.getMainFrame().enableControls();
191
192
                }
193
            });
194
//        insertRow.addActionListener(new ActionListener() {
195
//                public void actionPerformed(ActionEvent e) {
196
//                    //TODO Este m?todo a?ade filas al final de la tabla y deber?a a?adirlas justo antes de la fila que tengamos seleccionada.
197
//
198
//                        try {
199
//                                                        table.addRow(null);
200
//                                                } catch (DriverIOException e1) {
201
//                                                        // TODO Auto-generated catch block
202
//                                                        e1.printStackTrace();
203
//                                                } catch (IOException e1) {
204
//                                                        // TODO Auto-generated catch block
205
//                                                        e1.printStackTrace();
206
//                                                }
207
//                        PluginServices.getMainFrame().enableControls();
208
//
209
//                }
210
//            });
211
        removeRow.addActionListener(new ActionListener() {
212
                public void actionPerformed(ActionEvent e) {
213
                        try {
214
                                                        table.removeRow();
215
                                                } catch (DriverIOException e1) {
216
                                                        // TODO Auto-generated catch block
217
                                                        e1.printStackTrace();
218
                                                } catch (IOException e1) {
219
                                                        // TODO Auto-generated catch block
220
                                                        e1.printStackTrace();
221
                                                }
222
                        PluginServices.getMainFrame().enableControls();
223
224
                }
225
            });
226
//        insertColumn.addActionListener(new ActionListener() {
227
//                public void actionPerformed(ActionEvent e) {
228
//                    //TODO Falta que implementar.
229
//
230
//                }
231
//            });
232
//        removeColumn.addActionListener(new ActionListener() {
233
//                public void actionPerformed(ActionEvent e) {
234
//                    //TODO Falta que implementar.
235
//                }
236
//            });
237
        editingMenu(table.isEditing());
238
        setEnablePaste(table.isCopied());
239
        this.show(table, point.x, point.y);
240
    }
241
242
    /**
243
     * Set the menu enabled if it?s possible.
244
     *
245
     * @param b boolean
246
     */
247
    private void editingMenu(boolean b) {
248
        copy.setEnabled(false);
249
        cut.setEnabled(false);
250
//        startEdition.setEnabled(!b);
251
//        stopEdition.setEnabled(b);
252
//        insertRow.setEnabled(b);
253
//        insertColumn.setEnabled(b);
254
        removeRow.setEnabled(false);
255
        if (table.getSelectedRowIndices().length > 0){
256
                copy.setEnabled(true);
257
                if(b) {
258
                        cut.setEnabled(true);
259
                        removeRow.setEnabled(true);
260
                }
261
        }
262
263
//        if ((table.getSelectedFieldIndices().length() > 0) && b) {
264
//            removeColumn.setEnabled(true);
265
//        } else {
266
//            removeColumn.setEnabled(false);
267
//        }
268
    }
269
270
    /**
271
     * Set the menu of paste enabled if it?s possible
272
     *
273
     * @param b boolean
274
     */
275
    private void setEnablePaste(boolean b) {
276
        paste.setEnabled(b);
277
    }
278
}