Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / layout / mapbox / LayoutMapBoxExtension.java @ 1757

History | View | Annotate | Download (3.59 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.layout.mapbox;
23

    
24
import org.gvsig.andami.IconThemeHelper;
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.andami.ui.mdiManager.IWindow;
28
import org.gvsig.app.project.ProjectManager;
29
import org.gvsig.app.project.documents.layout.DefaultLayoutManager;
30
import org.gvsig.app.project.documents.layout.LayoutControl;
31
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

    
35
/**
36
 * @author gvSIG-team
37
 */
38
public class LayoutMapBoxExtension extends Extension {
39

    
40
    private static final Logger logger = LoggerFactory
41
        .getLogger(LayoutMapBoxExtension.class);
42

    
43
//    private LayoutPanel layout = null;
44

    
45
    @Override
46
    public void initialize() {
47
        registerIcons();
48
        
49
    }
50

    
51
    @Override
52
    public void postInitialize() {
53
        DefaultLayoutManager layoutManager = (DefaultLayoutManager) ProjectManager
54
            .getInstance()
55
            .getDocumentManager(DefaultLayoutManager.TYPENAME);
56
        MapBoxUtils.registerPersistence();
57
        MapBoxUtils.register(layoutManager);
58
        MapBoxUtils.registerContextMenuOptions();
59
    }
60
    
61
    
62

    
63
    private void registerIcons() {
64
        IconThemeHelper.registerIcon("action", "layout-insert-mapbox", this);
65
        IconThemeHelper.registerIcon("action", "layout-edit-mapbox", this);
66
    }
67

    
68
    @Override
69
    public void execute(String s) {
70
        LayoutPanel layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
71
        LayoutControl control = layout.getLayoutControl();
72

    
73
        logger.debug("Comand : " + s);
74
        
75
        switch (s) {
76
            case "layout-insert-mapbox":
77
                MapBoxUtils.addLayoutAddMapBoxTool(layout, control);
78
                control.setTool("layoutaddmapbox");
79
                layout.getDocument().setModified(true);
80
                break;
81
            case "layout-edit-mapbox":
82
                MapBoxUtils.addLayoutEditMapBoxTool(layout, control);
83
                control.setTool("layouteditmapbox");
84
                layout.getDocument().setModified(true);
85
                break;
86
            default:
87
                break;
88
        }
89
    }
90

    
91
    @Override
92
    public boolean isEnabled() {
93
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
94

    
95
        if (f == null) {
96
            return false;
97
        }
98

    
99
        if (f instanceof LayoutPanel) {
100
            return ((LayoutPanel) f).getLayoutContext().isEditable();
101
        }
102

    
103
        return false;
104
    }
105

    
106
    @Override
107
    public boolean isVisible() {
108
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
109

    
110
        if (f == null) {
111
            return false;
112
        }
113

    
114
        return (f instanceof LayoutPanel);
115
    }
116
}