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 / extension / LayoutExtension.java @ 200

History | View | Annotate | Download (11.7 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.extension;
23

    
24
import java.awt.Component;
25
import java.io.File;
26
import java.io.FileOutputStream;
27

    
28
import javax.swing.JFileChooser;
29
import javax.swing.JOptionPane;
30

    
31
import org.slf4j.Logger;
32
import org.slf4j.LoggerFactory;
33

    
34
import org.gvsig.andami.IconThemeHelper;
35
import org.gvsig.andami.PluginServices;
36
import org.gvsig.andami.messages.NotificationManager;
37
import org.gvsig.andami.plugins.Extension;
38
import org.gvsig.andami.preferences.IPreference;
39
import org.gvsig.andami.preferences.IPreferenceExtension;
40
import org.gvsig.andami.ui.mdiManager.IWindow;
41
import org.gvsig.app.gui.preferencespage.LayoutPage;
42
import org.gvsig.app.project.documents.layout.FLayoutZooms;
43
import org.gvsig.app.project.documents.layout.LayoutManager;
44
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
45
import org.gvsig.tools.ToolsLocator;
46
import org.gvsig.tools.persistence.PersistenceManager;
47
import org.gvsig.tools.persistence.PersistentState;
48
import org.gvsig.utils.GenericFileFilter;
49

    
50
/**
51
 * Extensi?n para controlar las operaciones basicas sobre el Layout.
52
 * 
53
 * @author Vicente Caballero Navarro
54
 */
55
public class LayoutExtension extends Extension implements IPreferenceExtension {
56

    
57
    private static final Logger logger = LoggerFactory
58
        .getLogger(LayoutExtension.class);
59

    
60
    private LayoutPanel layout = null;
61

    
62
    /**
63
     * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
64
     */
65
    public void execute(String s) {
66
        layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
67

    
68
        FLayoutZooms zooms = new FLayoutZooms(layout);
69
        logger.debug("Comand : " + s);
70

    
71
        if (s.equals("layout-navigation-pan")) {
72
            layout.getLayoutControl().setTool("layoutpan");
73
        } else
74
            if (s.equals("layout-navigation-zoom-in-topoint")) {
75
                layout.getLayoutControl().setTool("layoutzoomin");
76
            } else
77
                if (s.equals("layout-navigation-zoom-out-topoint")) {
78
                    layout.getLayoutControl().setTool("layoutzoomout");
79
                } else
80
                    if (s.equals("layout-navigation-zoom-all")) {
81
                        layout.getLayoutControl().fullRect();
82
                    } else
83
                        if (s.equals("layout-navigation-zoom-real")) {
84
                            zooms.realZoom();
85
                        } else
86
                            if (s.equals("layout-navigation-zoom-out-center")) {
87
                                zooms.zoomOut();
88
                            } else
89
                                if (s.equals("layout-navigation-zoom-in-center")) {
90
                                    zooms.zoomIn();
91
                                } else
92
                                    if (s.equals("layout-navigation-zoom-selected")) {
93
                                        zooms.zoomSelect();
94
                                    } else
95
                                        if (s.equals("application-layout-template-save")) {
96
                                            saveLayout();
97
                                        }
98
    }
99

    
100
    private void saveLayout() {
101
        layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
102
        JFileChooser jfc = new JFileChooser();
103
        jfc.addChoosableFileFilter(new GenericFileFilter(
104
            LayoutManager.TEMPLATE_FILE_POINTEXT,
105
            PluginServices.getText(this, "plantilla")));
106

    
107
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
108
            File file = jfc.getSelectedFile();
109
            if (!(file.getPath().endsWith(
110
                LayoutManager.TEMPLATE_FILE_POINTEXT.toLowerCase())
111
                || file.getPath().endsWith(
112
                    LayoutManager.TEMPLATE_FILE_POINTEXT))) {
113
                file = new File(file.getPath() +
114
                    LayoutManager.TEMPLATE_FILE_POINTEXT);
115
            }
116
            if (file.exists()) {
117
                int resp =
118
                    JOptionPane.showConfirmDialog((Component) PluginServices
119
                        .getMainFrame(), PluginServices.getText(this,
120
                        "fichero_ya_existe_seguro_desea_guardarlo"),
121
                        PluginServices.getText(this, "guardar"),
122
                        JOptionPane.YES_NO_OPTION);
123
                if (resp != JOptionPane.YES_OPTION) {
124
                    return;
125
                }
126
            }
127

    
128
            try {
129
                FileOutputStream fos =
130
                    new FileOutputStream(file.getAbsolutePath());
131
                PersistenceManager persistenceManager =
132
                    ToolsLocator.getPersistenceManager();
133
                PersistentState persistentState =
134
                    persistenceManager.getState(layout);
135
                persistenceManager.saveState(persistentState, fos);
136
            } catch (Exception e) {
137
                NotificationManager.addError(PluginServices.getText(this,
138
                    "Error_guardando_la_plantilla"), e);
139
            }
140
        }
141
    }
142

    
143
    /**
144
     * @see com.iver.mdiApp.plugins.IExtension#isVisible()
145
     */
146
    public boolean isVisible() {
147
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
148

    
149
        if (f == null) {
150
            return false;
151
        }
152

    
153
        if (f instanceof LayoutPanel) {
154
            return true;
155
        }
156
        return false;
157
    }
158

    
159
    /**
160
     * @see org.gvsig.andami.plugins.IExtension#initialize()
161
     */
162
    public void initialize() {
163
        registerIcons();
164
    }
165

    
166
    private void registerIcons() {
167
        
168
        IconThemeHelper.registerIcon("action", "application-layout-template-save", this);
169
        
170
        IconThemeHelper.registerIcon("action", "layout-navigation-zoom-in-center", this);
171
        IconThemeHelper.registerIcon("action", "layout-navigation-zoom-out-center", this);
172
        IconThemeHelper.registerIcon("action", "layout-navigation-zoom-in-topoint", this);
173
        IconThemeHelper.registerIcon("action", "layout-navigation-zoom-out-topoint", this);
174
        IconThemeHelper.registerIcon("action", "layout-navigation-zoom-all", this);
175
        IconThemeHelper.registerIcon("action", "layout-navigation-zoom-real", this);
176
        IconThemeHelper.registerIcon("action", "layout-navigation-zoom-selected", this);
177
        IconThemeHelper.registerIcon("action", "layout-navigation-pan", this);
178

    
179
        IconThemeHelper.registerIcon("action", "layout-view-navigation-zoom-in-topoint", this);
180
        IconThemeHelper.registerIcon("action", "layout-view-navigation-zoom-out-topoint", this);
181
        IconThemeHelper.registerIcon("action", "layout-view-navigation-zoom-all", this);
182
        IconThemeHelper.registerIcon("action", "layout-view-navigation-pan", this);
183
        // ================================================
184
        // Cursors
185
        IconThemeHelper.registerIcon("cursor", "cursor-layout-navigation-zoom-in-topoint", this);
186
        IconThemeHelper.registerIcon("cursor", "cursor-layout-navigation-zoom-out-topoint", this);
187
        IconThemeHelper.registerIcon("cursor", "cursor-selection-by-rectangle", this);
188
        IconThemeHelper.registerIcon("cursor", "cursor-selection-simple", this);
189
        IconThemeHelper.registerIcon("cursor", "cursor-selection-complex", this);
190
        IconThemeHelper.registerIcon("cursor", "cursor-layout-graphic-edit-vertex", this);
191
        IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-circle", this);
192
        IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-polyline", this);
193
        IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-point", this);
194
        IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-polygon", this);
195
        IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-rectangle", this);
196
        IconThemeHelper.registerIcon("cursor", "cursor-layout-view-navigation-zoom-in-topoint", this);
197
        IconThemeHelper.registerIcon("cursor", "cursor-layout-view-navigation-zoom-out-topoint", this);
198
        // End cursors
199
        // ================================================
200

    
201
        IconThemeHelper.registerIcon("document", "document-map-icon", this);
202
        IconThemeHelper.registerIcon("document", "document-map-icon-sel", this);
203
        
204
        IconThemeHelper.registerIcon("layout", "neresize-icon", this);
205
        IconThemeHelper.registerIcon("layout", "eresize-icon", this);
206
        IconThemeHelper.registerIcon("layout", "nresize-icon", this);
207
        IconThemeHelper.registerIcon("layout", "graphic-move-icon", this);
208
        
209
        IconThemeHelper.registerIcon("layout", "sereresize-icon", this);
210
        IconThemeHelper.registerIcon("layout", "symboltag-icon", this);
211
        IconThemeHelper.registerIcon("layout", "numero-icon", this);
212
        IconThemeHelper.registerIcon("layout", "barra1-icon", this);
213
        IconThemeHelper.registerIcon("layout", "barra2-icon", this);
214
        IconThemeHelper.registerIcon("layout", "barra3-icon", this);
215

    
216
        IconThemeHelper.registerIcon("layout", "text-left-icon", this);
217
        IconThemeHelper.registerIcon("layout", "text-center-v-icon", this);
218
        IconThemeHelper.registerIcon("layout", "text-right-icon", this);
219
        IconThemeHelper.registerIcon("layout", "left-rotation-icon", this);
220
        IconThemeHelper.registerIcon("layout", "text-up-icon", this);
221
        IconThemeHelper.registerIcon("layout", "text-center-h-icon", this);
222
        IconThemeHelper.registerIcon("layout", "text-down-icon", this);
223
        IconThemeHelper.registerIcon("layout", "text-distup-icon", this);
224
        IconThemeHelper.registerIcon("layout", "text-distcenterh-icon", this);
225
        IconThemeHelper.registerIcon("layout", "text-distdown-icon", this);
226
        IconThemeHelper.registerIcon("layout", "text-distleft-icon", this);
227

    
228
        IconThemeHelper.registerIcon("layout", "text-distcenterv-icon", this);
229
        IconThemeHelper.registerIcon("layout", "text-distright-icon", this);
230
        IconThemeHelper.registerIcon("layout", "text-size-width-icon", this);
231
        IconThemeHelper.registerIcon("layout", "text-size-height-icon", this);
232
        IconThemeHelper.registerIcon("layout", "text-size-other-icon", this);
233
        IconThemeHelper.registerIcon("layout", "text-space-right-icon", this);
234
        IconThemeHelper.registerIcon("layout", "text-space-down-icon", this);
235
        IconThemeHelper.registerIcon("layout", "text-inlayout-icon", this);
236
        IconThemeHelper.registerIcon("layout", "layout-pan-icon", this);
237
        IconThemeHelper.registerIcon("layout", "view-pan-icon", this);
238
        IconThemeHelper.registerIcon("layout", "right-rotation-icon", this);
239
    }
240

    
241
    /**
242
     * @see org.gvsig.andami.plugins.IExtension#isEnabled()
243
     */
244
    public boolean isEnabled() {
245
        return true;
246
    }
247

    
248
    /**
249
     * Devuelve el Layout sobre el que se opera.
250
     * 
251
     * @return Layout.
252
     */
253
    public LayoutPanel getLayout() {
254
        return layout;
255
    }
256

    
257
    public IPreference[] getPreferencesPages() {
258
        return new IPreference[] { new LayoutPage() };
259
    }
260
}