Statistics
| Revision:

svn-document-layout / branches / usability_v2 / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / gui / FPopupMenu.java @ 140

History | View | Annotate | Download (4.23 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.gui;
23

    
24
import java.awt.Font;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27

    
28
import javax.swing.JMenuItem;
29
import javax.swing.JPopupMenu;
30

    
31
import org.gvsig.app.project.ProjectManager;
32
import org.gvsig.app.project.documents.layout.LayoutManager;
33
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
34
import org.gvsig.app.project.documents.view.IContextMenuAction;
35

    
36
/**
37
 * Menu de bot?n derecho para el Layout.
38
 * Se pueden a?adir entradas facilmente desde una extensi?n,
39
 * creando una clase derivando de LayoutMenuEntry, y a?adiendola en
40
 * est?tico (o en tiempo de carga de la extensi?n) a FPopupMenu.
41
 * (Las entradas actuales est?n hechas de esa manera).
42
 * 
43
 * @author Vicente Caballero Navarro
44
 * 
45
 */
46

    
47
public class FPopupMenu extends JPopupMenu {
48

    
49
    /**
50
         *
51
         */
52
    private static final long serialVersionUID = 5340224239252101704L;
53
    // private static ArrayList menuEntrys = new ArrayList();
54
    protected LayoutPanel layout;
55
    private IFFrame[] selecteds;
56
   
57
    // private JMenuItem capa;
58
    // Lo de fijar la fuente es porque en linux se ve?a mal si no se fija.
59
    // TODO: Esto no funcionar? para idiomas como el chino. Hay que cambiarlo.
60
    public final static Font theFont = new Font("SansSerif", Font.PLAIN, 10);
61

    
62

    
63
    /**
64
     * Creates a new FPopupMenu object.
65
     * 
66
     * @param nodo
67
     *            DOCUMENT ME!
68
     * @param vista
69
     *            DOCUMENT ME!
70
     */
71
    public FPopupMenu(LayoutPanel layout) {
72
        super();
73
        this.initialize(layout);
74
    }
75

    
76
    private void initialize(LayoutPanel layout) {
77
        this.layout = layout;
78
        this.selecteds = this.layout.getLayoutContext().getSelectedFFrames();
79
        LayoutManager layoutManager =
80
            (LayoutManager) ProjectManager.getInstance()
81
                .getDocumentManager("project.document.layout");
82
        
83
        IContextMenuAction[] actions = layoutManager.createLayoutMenuActions(layout);
84
        this.createMenuElements(actions);
85
    }
86
  
87

    
88
    private void createMenuElements(IContextMenuAction[] actions) {
89
        String group = null;
90
        for (int i = 0; i < actions.length; i++) {
91
            IContextMenuAction action = actions[i];
92
            MenuItem item = new MenuItem(action.getText(), action);
93
            item.setFont(theFont);
94
            item.setEnabled(action.isEnabled(null, this.selecteds));
95
            if (!action.getGroup().equals(group)) {
96
                if (group != null) {
97
                    this.addSeparator();
98
                }
99
                group = action.getGroup();
100
            }
101
            this.add(item);
102
        }
103

    
104
    }
105

    
106
    public class MenuItem extends JMenuItem implements ActionListener {
107

    
108
        /**
109
                 *
110
                 */
111
        private static final long serialVersionUID = 2518112362194914446L;
112
        private IContextMenuAction action;
113

    
114
        public MenuItem(String text, IContextMenuAction documentAction) {
115
            super(text);
116
            this.action = documentAction;
117
            String tip = this.action.getDescription();
118
            if (tip != null && tip.length() > 0) {
119
                this.setToolTipText(tip);
120
            }
121
            this.addActionListener(this);
122
        }
123

    
124
        public void actionPerformed(ActionEvent e) {
125
            this.action.execute(layout.getLayoutContext(),
126
                FPopupMenu.this.selecteds);
127
        }
128
    }
129
}