Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / contextmenu / gui / PropertyLayoutMenuEntry.java @ 1714

History | View | Annotate | Download (5.02 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.contextmenu.gui;
23

    
24
import java.awt.event.ActionEvent;
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.app.project.ProjectManager;
27
import org.gvsig.app.project.documents.layout.DefaultLayoutManager;
28
import org.gvsig.app.project.documents.layout.LayoutContext;
29
import org.gvsig.app.project.documents.layout.LayoutManager;
30
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
31
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
32
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
33
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFramePanel;
34
import org.gvsig.tools.swing.api.ToolsSwingLocator;
35
import org.gvsig.tools.swing.api.windowmanager.Dialog;
36
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
37
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
38

    
39
/**
40
 * Abre el di?logo de propiedades del FFrame seleccionado.
41
 *
42
 * @author Vicente Caballero Navarro
43
 */
44
public class PropertyLayoutMenuEntry extends AbstractLayoutContextMenuAction {
45

    
46
    private static LayoutManager layoutManager = null;
47

    
48
    public PropertyLayoutMenuEntry() {
49
        layoutManager =
50
            (LayoutManager) ProjectManager.getInstance().getDocumentManager(
51
                DefaultLayoutManager.TYPENAME);
52
    }
53

    
54
    @Override
55
    public String getGroup() {
56
        return "layout";
57
    }
58

    
59
    @Override
60
    public int getGroupOrder() {
61
        return 6;
62
    }
63

    
64
    @Override
65
    public int getOrder() {
66
        return 1;
67
    }
68

    
69
    @Override
70
    public String getText() {
71
        return PluginServices.getText(this, "propiedades");
72
    }
73

    
74
    @Override
75
    public boolean isEnabled(LayoutContext layoutContext,
76
        IFFrame[] selectedFrames) {
77
        return true;
78
    }
79

    
80
    @Override
81
    public boolean isVisible(LayoutContext layoutContext,
82
        IFFrame[] selectedFrames) {
83
        if (selectedFrames.length == 1
84
            && !(getLayout().getLayoutControl().getGeometryAdapter()
85
                .getPoints().length > 0))
86
            return true;
87
        return false;
88
    }
89
    
90
    private void doPanelAccept(LayoutContext layoutContext, IFFrame frame, IFFramePanel panel) {
91
        IFFrame fframeAux = panel.getFFrame();
92

    
93
        if (fframeAux != null) {
94
            if (fframeAux instanceof IFFrameUseFMap) {
95
                ((IFFrameUseFMap) fframeAux).refresh();
96
            }
97
            fframeAux.setLevel(frame.getLevel());
98
            fframeAux.setSelected(frame.getSelected() != IFFrame.NOSELECT);
99
            layoutContext.getFrameCommandsRecord().update(frame, fframeAux);
100
            fframeAux.getBoundingBox(layoutContext.getAT());
101
            layoutContext.updateFFrames();
102
            layoutContext.notifAllObservers();
103
        }
104

    
105
    }
106

    
107
    @Override
108
    public void execute(final LayoutContext layoutContext, IFFrame[] selectedFrames) {
109
        IFFrame[] selecList = layoutContext.getSelectedFFrames();
110
        if (selecList.length == 1) {
111
            final IFFrame frame = selecList[0];
112
            final IFFramePanel panel =
113
                layoutManager.createFFrameDialog(frame, layoutPanel, layoutContext.getAT());
114
            
115
            if(panel instanceof IFFrameDialog) {
116
                IFFrameDialog fframeDialog = (IFFrameDialog) panel;
117
                fframeDialog.addActionListener((ActionEvent e) -> {
118
                    doPanelAccept(layoutContext, frame, panel);
119
                });
120
                PluginServices.getMDIManager().addWindow(fframeDialog);
121
            } else if (panel != null) {
122
                WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
123
                Dialog dialog = winManager.createDialog(
124
                    panel.asJComponent(),
125
                    panel.getTitle(),
126
                    "", 
127
                    WindowManager_v2.BUTTONS_OK_CANCEL);
128
                dialog.addActionListener((ActionEvent e) -> {
129
                    if(dialog.getAction() == WindowManager_v2.BUTTON_OK) {
130
                        doPanelAccept(layoutContext, frame, panel);
131
                    }
132
                });
133
                dialog.show(WindowManager.MODE.TOOL);
134
            }
135
        }
136
    }
137
}