Revision 798

View differences:

tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
    
5
    <modelVersion>4.0.0</modelVersion>
6
    <packaging>jar</packaging>
7
    <artifactId>org.gvsig.app.document.layout2.app.mainplugin</artifactId>
8
    <name>${project.artifactId}</name>
9

  
10
    <parent>
11
        <groupId>org.gvsig</groupId>
12
        <artifactId>org.gvsig.app.document.layout2.app</artifactId>
13
        <version>2.0.125</version>
14
    </parent>
15
    
16
    <dependencies>
17

  
18
        <dependency>
19
            <groupId>org.gvsig</groupId>
20
            <artifactId>org.gvsig.app.mainplugin</artifactId>
21
            <scope>compile</scope>
22
        </dependency>
23
        <dependency>
24
            <groupId>org.gvsig</groupId>
25
            <artifactId>org.gvsig.andami</artifactId>
26
            <scope>compile</scope>
27
        </dependency>
28
        <dependency>
29
            <groupId>org.gvsig</groupId>
30
            <artifactId>org.gvsig.fmap.control</artifactId>
31
            <scope>compile</scope>
32
        </dependency>
33
        <dependency>
34
            <groupId>org.gvsig</groupId>
35
            <artifactId>org.gvsig.tools.lib</artifactId>
36
            <scope>compile</scope>
37
        </dependency>
38
        <dependency>
39
            <groupId>org.gvsig</groupId>
40
            <artifactId>org.gvsig.tools.swing.api</artifactId>
41
            <scope>compile</scope>
42
        </dependency>
43
        <dependency>
44
            <groupId>org.gvsig</groupId>
45
            <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
46
            <scope>compile</scope>
47
        </dependency>
48
        <dependency>
49
            <groupId>org.gvsig</groupId>
50
            <artifactId>org.gvsig.fmap.geometry.api</artifactId>
51
            <scope>compile</scope>
52
        </dependency>
53
        <dependency>
54
            <groupId>org.gvsig</groupId>
55
            <artifactId>org.gvsig.utils</artifactId>
56
            <scope>compile</scope>
57
        </dependency>
58
        <dependency>
59
            <groupId>org.gvsig</groupId>
60
            <artifactId>org.gvsig.ui</artifactId>
61
            <scope>compile</scope>
62
        </dependency>
63
        <dependency>
64
            <groupId>org.gvsig</groupId>
65
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
66
            <scope>compile</scope>
67
        </dependency>
68
        <dependency>
69
            <groupId>org.gvsig</groupId>
70
            <artifactId>org.gvsig.compat.api</artifactId>
71
            <scope>compile</scope>
72
        </dependency>
73
        <dependency>
74
            <groupId>org.gvsig</groupId>
75
            <artifactId>org.gvsig.projection.api</artifactId>
76
            <scope>compile</scope>
77
        </dependency>
78
        <dependency>
79
            <groupId>org.gvsig</groupId>
80
            <artifactId>org.gvsig.symbology.lib.api</artifactId>
81
            <scope>compile</scope>
82
        </dependency>
83
        <dependency>
84
            <groupId>org.gvsig</groupId>
85
            <artifactId>org.gvsig.symbology.swing.api</artifactId>
86
            <scope>compile</scope>
87
        </dependency>
88
        <dependency>
89
            <groupId>org.gvsig</groupId>
90
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
91
            <scope>compile</scope>
92
        </dependency>
93
        <dependency>
94
            <groupId>com.lowagie</groupId>
95
            <artifactId>itext</artifactId>
96
            <scope>compile</scope>
97
        </dependency>
98
        <dependency>
99
            <groupId>org.apache.xmlgraphics</groupId>
100
            <artifactId>batik-gvt</artifactId>
101
            <scope>compile</scope>
102
        </dependency>
103
        <dependency>
104
            <groupId>org.apache.xmlgraphics</groupId>
105
            <artifactId>batik-script</artifactId>
106
            <scope>compile</scope>
107
        </dependency>
108
        
109
        <!--
110
        <dependency>
111
            <groupId>org.gvsig</groupId>
112
            <artifactId>batik-ext-gvsig-custom</artifactId>
113
        </dependency>
114
        -->
115
        
116
        <dependency>
117
            <groupId>com.sun</groupId>
118
            <artifactId>jimi</artifactId>
119
            <scope>compile</scope>
120
        </dependency>
121
        <dependency>
122
            <groupId>org.gvsig</groupId>
123
            <artifactId>org.gvsig.i18n</artifactId>
124
            <scope>compile</scope>
125
        </dependency>
126

  
127
    </dependencies>
128

  
129
    <properties>
130
	<gvsig.package.info.name>Document: Layout document plugin, version 2</gvsig.package.info.name>
131
        <gvsig.package.info.dependencies>conflict: org.gvsig.app.document.layout1.app.mainplugin -ge 1, required: org.gvsig.app.mainplugin -ge 2.1.0</gvsig.package.info.dependencies>
132
        <gvsig.package.info.categories>Layout</gvsig.package.info.categories>
133
	<gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-app-document-layout/pool</gvsig.package.info.poolURL>
134
	<gvsig.package.info.sourcesURL>http://devel.gvsig.org/svn/gvsig-app-document-layout/trunk/org.gvsig.app.document.layout2.app</gvsig.package.info.sourcesURL>
135
	<gvsig.package.info.state>final</gvsig.package.info.state>
136
        <gvsig.package.info.official>true</gvsig.package.info.official>
137
        <gvsig.package.info.codealias>org.gvsig.app.document.layout.app.mainplugin</gvsig.package.info.codealias>
138

  
139
    </properties>
140

  
141
</project>
142

  
tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/buildNumber.properties
1
#Tue Jan 15 13:51:07 CET 2019
2
buildNumber=144
tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/math/intervals/IntervalUtils.java
1
package org.gvsig.math.intervals;
2

  
3
public class IntervalUtils {
4

  
5
	/**
6
	 * Calculates an nice round interval division. For instance, for
7
	 * intervalLenght = 1100000 and numberOfDivisions=5,
8
	 * the result would be 250000.
9
	 * 
10
	 * @param intervalLength The full interval to be divided
11
	 * @param numberOfDivisions The exact number of divisions to perform
12
	 * @return A nice round interval division. The calculated result
13
	 * ensures that the whole interval length is covered by the proposed
14
	 * division, so it always fulfills the following formula:
15
	 *  <code>result*numberOfDivisions>=intervalLength</code>
16
	 */
17
	public static double roundIntervalDivision(double intervalLength, int numberOfDivisions) {
18
		if (intervalLength<=0.0d || numberOfDivisions<=0) {
19
			return 0.0d;
20
		}
21

  
22
		double division = intervalLength/numberOfDivisions;
23
		if (division==0.0d) {
24
			return 0.0d;
25
		}
26
		double digitShift = Math.floor((Math.log10(division)));
27
		double scale = Math.pow(10, -digitShift);
28
		double firstSignificatDigit = Math.floor(scale*division);
29
		double result = firstSignificatDigit*Math.pow(10, digitShift);
30
		if (result*numberOfDivisions>=intervalLength) {
31
			return result;
32
		}
33
		else {
34
			result = (0.5+firstSignificatDigit)*Math.pow(10, digitShift);
35
			if (result*numberOfDivisions>=intervalLength) {
36
				return result;
37
			}
38
		}
39
		result = (1+firstSignificatDigit)*Math.pow(10, digitShift);
40
		return result;
41
	}
42
}
tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/TagExtension.java
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

  
26
import javax.swing.JOptionPane;
27

  
28
import org.gvsig.andami.IconThemeHelper;
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.plugins.Extension;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
33
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
34

  
35
public class TagExtension extends Extension {
36

  
37
    private LayoutPanel layout = null;
38

  
39
    /**
40
     * @see org.gvsig.andami.plugins.IExtension#initialize()
41
     */
42
    public void initialize() {
43
        registerIcons();
44
    }
45

  
46
    private void registerIcons() {
47

  
48
        IconThemeHelper.registerIcon("action", "layout-graphic-show-tags", this);
49
        IconThemeHelper.registerIcon("action", "layout-insert-tag", this);
50

  
51
    }
52

  
53
    /**
54
     * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
55
     */
56
    public void execute(String s) {
57

  
58
        /*
59
         * FLayoutZooms zooms = new FLayoutZooms(layout);
60
         * logger.debug("Comand : " + s);
61
         * if (s.compareTo("SET_TAG") == 0) {
62
         * layout.setTool(Layout.SET_TAG);
63
         * }
64
         */
65

  
66
        // FJP: Cambio: abrimos la ventana de tag para
67
        // asignar el tag a los elementos seleccionados
68
        if (s.equals("layout-insert-tag")) {
69
            IFFrame[] selectedFrames =
70
                layout.getLayoutContext().getSelectedFFrames();
71
            if (selectedFrames.length > 0) {
72
                String defaultStr = "";
73
                if (selectedFrames.length == 1)
74
                    defaultStr = selectedFrames[0].getTag();
75
                String theTag =
76
                    JOptionPane.showInputDialog(
77
                        (Component) PluginServices.getMainFrame(),
78
                        "Introduzca el tag:", defaultStr);
79
                if (theTag != null) {
80
                    for (int i = 0; i < selectedFrames.length; i++)
81
                        selectedFrames[i].setTag(theTag);
82
                }
83
                layout.getDocument().setModified(true);
84
            }
85
        } else
86
            if (s.equals("layout-graphic-show-tags")) {
87
                // IFFrame[] frames = layout.getFFrames();
88
                // for (int i=0; i< frames.length; i++)
89
                // {
90
                // IFFrame f = frames[i];
91
                // if (f instanceof FFrameText)
92
                // {
93
                // FFrameText txt = (FFrameText) f;
94
                // if (f.getTag() != null)
95
                // {
96
                // txt.clearText();
97
                // txt.addText(f.getTag());
98
                // }
99
                // }
100
                // }
101
                layout.setShowIconTag(true);
102
                layout.getLayoutControl().refresh();
103
            }
104
    }
105

  
106
    /**
107
     * @see org.gvsig.andami.plugins.IExtension#isEnabled()
108
     */
109
    public boolean isEnabled() {
110
        IFFrame[] selectedFrames =
111
            layout.getLayoutContext().getSelectedFFrames();
112
        if (selectedFrames == null)
113
            return false;
114
        return (selectedFrames.length > 0);
115
    }
116

  
117
    /**
118
     * @see org.gvsig.andami.plugins.IExtension#isVisible()
119
     */
120
    public boolean isVisible() {
121
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
122

  
123
        if (f != null && f instanceof LayoutPanel) {
124
            layout = (LayoutPanel) f;
125
            return true;
126
        }
127
        return false;
128
    }
129

  
130
}
tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/PrintProperties.java
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
/**
25
 */
26
import java.awt.geom.Rectangle2D;
27

  
28
import org.gvsig.andami.IconThemeHelper;
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.plugins.Extension;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
33

  
34
/**
35
 * DOCUMENT ME!
36
 * 
37
 * @author vcn
38
 */
39
public class PrintProperties extends Extension /*
40
                                                * implements
41
                                                * IPreferenceExtension
42
                                                */{
43

  
44
    private LayoutPanel l;
45
    // private static final IPreference printPropertiesPage = new
46
    // PrintPropertiesPage();
47
    // private Paper paper;
48
    Rectangle2D.Double aux = null;
49

  
50
    /**
51
     * DOCUMENT ME!
52
     * 
53
     * @param s
54
     *            DOCUMENT ME!
55
     */
56
    public void execute(String s) {
57
        if (s.compareTo("application-page-setup-layout") == 0) {
58
            l = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
59
            l.showFConfig();
60
        }
61
    }
62

  
63
    /**
64
     * DOCUMENT ME!
65
     * 
66
     * @return DOCUMENT ME!
67
     */
68
    public boolean isVisible() {
69
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
70

  
71
        if (f == null) {
72
            return false;
73
        }
74

  
75
        return (f instanceof LayoutPanel);
76
    }
77

  
78
    /**
79
     * @see com.iver.mdiApp.plugins.IExtension#isEnabled()
80
     */
81
    public boolean isEnabled() {
82
        LayoutPanel f =
83
            (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
84

  
85
        if (f == null || !f.getLayoutContext().isEditable()) {
86
            return false;
87
        }
88

  
89
        return true;
90
    }
91

  
92
    /**
93
     * @see org.gvsig.andami.plugins.IExtension#initialize()
94
     */
95
    public void initialize() {
96
        registerIcons();
97
    }
98

  
99
    private void registerIcons() {
100
        IconThemeHelper.registerIcon("action", "application-page-setup", this);
101
    }
102
}
tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/LayoutExtension.java
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.i18n.Messages;
46
import org.gvsig.tools.ToolsLocator;
47
import org.gvsig.tools.persistence.PersistenceManager;
48
import org.gvsig.tools.persistence.PersistentState;
49
import org.gvsig.tools.persistence.text.JavaTextFactory;
50
import org.gvsig.utils.GenericFileFilter;
51

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

  
59
    private static final Logger logger = LoggerFactory
60
            .getLogger(LayoutExtension.class);
61

  
62
    private LayoutPanel layout = null;
63

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

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

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

  
102
    private void saveLayout() {
103
        layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
104
        JFileChooser jfc = new JFileChooser();
105
        GenericFileFilter layoutMainFilter = new GenericFileFilter(
106
                LayoutManager.TEMPLATE_FILE_POINTEXT,
107
                Messages.getText("_Layout_template") + " (*"
108
                        + LayoutManager.TEMPLATE_FILE_POINTEXT + ")");
109
        jfc.addChoosableFileFilter(layoutMainFilter);
110
        jfc.setFileFilter(layoutMainFilter);
111

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

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

  
148
    /**
149
     * @see com.iver.mdiApp.plugins.IExtension#isVisible()
150
     */
151
    public boolean isVisible() {
152
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
153

  
154
        if (f == null) {
155
            return false;
156
        }
157

  
158
        if (f instanceof LayoutPanel) {
159
            return true;
160
        }
161
        return false;
162
    }
163

  
164
    /**
165
     * @see org.gvsig.andami.plugins.IExtension#initialize()
166
     */
167
    public void initialize() {
168
        registerPersistence();
169
        registerIcons();
170
    }
171

  
172
    private void registerPersistence() {
173
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
174
        JavaTextFactory factory = new JavaTextFactory();
175
        manager.registerFactory(factory);
176
    }
177

  
178
    private void registerIcons() {
179

  
180
        IconThemeHelper.registerIcon("action",
181
                "application-layout-template-save", this);
182

  
183
        IconThemeHelper.registerIcon("action",
184
                "layout-navigation-zoom-in-center", this);
185
        IconThemeHelper.registerIcon("action",
186
                "layout-navigation-zoom-out-center", this);
187
        IconThemeHelper.registerIcon("action",
188
                "layout-navigation-zoom-in-topoint", this);
189
        IconThemeHelper.registerIcon("action",
190
                "layout-navigation-zoom-out-topoint", this);
191
        IconThemeHelper.registerIcon("action", "layout-navigation-zoom-all",
192
                this);
193
        IconThemeHelper.registerIcon("action", "layout-navigation-zoom-real",
194
                this);
195
        IconThemeHelper.registerIcon("action",
196
                "layout-navigation-zoom-selected", this);
197
        IconThemeHelper.registerIcon("action", "layout-navigation-pan", this);
198

  
199
        IconThemeHelper.registerIcon("action",
200
                "layout-view-navigation-zoom-in-topoint", this);
201
        IconThemeHelper.registerIcon("action",
202
                "layout-view-navigation-zoom-out-topoint", this);
203
        IconThemeHelper.registerIcon("action",
204
                "layout-view-navigation-zoom-all", this);
205
        IconThemeHelper.registerIcon("action", "layout-view-navigation-pan",
206
                this);
207
        // ================================================
208
        // Cursors
209
        IconThemeHelper.registerIcon("cursor",
210
                "cursor-layout-navigation-zoom-in-topoint", this);
211
        IconThemeHelper.registerIcon("cursor",
212
                "cursor-layout-navigation-zoom-out-topoint", this);
213
        IconThemeHelper.registerIcon("cursor", "cursor-selection-by-rectangle",
214
                this);
215
        IconThemeHelper.registerIcon("cursor", "cursor-selection-simple", this);
216
        IconThemeHelper
217
                .registerIcon("cursor", "cursor-selection-complex", this);
218
        IconThemeHelper.registerIcon("cursor",
219
                "cursor-layout-graphic-edit-vertex", this);
220
        IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-circle",
221
                this);
222
        IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-polyline",
223
                this);
224
        IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-point",
225
                this);
226
        IconThemeHelper.registerIcon("cursor", "cursor-layout-insert-polygon",
227
                this);
228
        IconThemeHelper.registerIcon("cursor",
229
                "cursor-layout-insert-rectangle", this);
230
        IconThemeHelper.registerIcon("cursor",
231
                "cursor-layout-view-navigation-zoom-in-topoint", this);
232
        IconThemeHelper.registerIcon("cursor",
233
                "cursor-layout-view-navigation-zoom-out-topoint", this);
234
        // End cursors
235
        // ================================================
236

  
237
        IconThemeHelper.registerIcon("document", "document-map-icon", this);
238
        IconThemeHelper.registerIcon("document", "document-map-icon-sel", this);
239

  
240
        IconThemeHelper.registerIcon("layout", "neresize-icon", this);
241
        IconThemeHelper.registerIcon("layout", "eresize-icon", this);
242
        IconThemeHelper.registerIcon("layout", "nresize-icon", this);
243
        IconThemeHelper.registerIcon("layout", "graphic-move-icon", this);
244

  
245
        IconThemeHelper.registerIcon("layout", "sereresize-icon", this);
246
        IconThemeHelper.registerIcon("layout", "symboltag-icon", this);
247
        IconThemeHelper.registerIcon("layout", "numero-icon", this);
248
        IconThemeHelper.registerIcon("layout", "barra1-icon", this);
249
        IconThemeHelper.registerIcon("layout", "barra2-icon", this);
250
        IconThemeHelper.registerIcon("layout", "barra3-icon", this);
251

  
252
        IconThemeHelper.registerIcon("layout", "text-left-icon", this);
253
        IconThemeHelper.registerIcon("layout", "text-center-v-icon", this);
254
        IconThemeHelper.registerIcon("layout", "text-right-icon", this);
255
        IconThemeHelper.registerIcon("layout", "left-rotation-icon", this);
256
        IconThemeHelper.registerIcon("layout", "text-up-icon", this);
257
        IconThemeHelper.registerIcon("layout", "text-center-h-icon", this);
258
        IconThemeHelper.registerIcon("layout", "text-down-icon", this);
259
        IconThemeHelper.registerIcon("layout", "text-distup-icon", this);
260
        IconThemeHelper.registerIcon("layout", "text-distcenterh-icon", this);
261
        IconThemeHelper.registerIcon("layout", "text-distdown-icon", this);
262
        IconThemeHelper.registerIcon("layout", "text-distleft-icon", this);
263

  
264
        IconThemeHelper.registerIcon("layout", "text-distcenterv-icon", this);
265
        IconThemeHelper.registerIcon("layout", "text-distright-icon", this);
266
        IconThemeHelper.registerIcon("layout", "text-size-width-icon", this);
267
        IconThemeHelper.registerIcon("layout", "text-size-height-icon", this);
268
        IconThemeHelper.registerIcon("layout", "text-size-other-icon", this);
269
        IconThemeHelper.registerIcon("layout", "text-space-right-icon", this);
270
        IconThemeHelper.registerIcon("layout", "text-space-down-icon", this);
271
        IconThemeHelper.registerIcon("layout", "text-inlayout-icon", this);
272
        IconThemeHelper.registerIcon("layout", "layout-pan-icon", this);
273
        IconThemeHelper.registerIcon("layout", "view-pan-icon", this);
274
        IconThemeHelper.registerIcon("layout", "right-rotation-icon", this);
275
    }
276

  
277
    /**
278
     * @see org.gvsig.andami.plugins.IExtension#isEnabled()
279
     */
280
    public boolean isEnabled() {
281
        return true;
282
    }
283

  
284
    /**
285
     * Devuelve el Layout sobre el que se opera.
286
     * 
287
     * @return Layout.
288
     */
289
    public LayoutPanel getLayout() {
290
        return layout;
291
    }
292

  
293
    public IPreference[] getPreferencesPages() {
294
        return new IPreference[] { new LayoutPage() };
295
    }
296
}
tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/ExportLayoutExtension.java
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.io.File;
25
import org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.andami.plugins.Extension;
28
import org.gvsig.andami.ui.mdiManager.IWindow;
29
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
30
import org.gvsig.tools.util.ArrayUtils;
31

  
32
/**
33
 * Extension for exporting the layout to PDF or PostScript.
34
 *
35
 * @author jaume dominguez faus - jaume.dominguez@iver.es
36
 */
37
public class ExportLayoutExtension extends Extension {
38

  
39
    private LayoutPanel layoutPanel;
40

  
41
    public void initialize() {
42
        registerIcons();
43
    }
44

  
45
    private void registerIcons() {
46

  
47
        IconThemeHelper.registerIcon("action", "application-export-to-postscript", this);
48
        IconThemeHelper.registerIcon("action", "application-export-to-pdf", this);
49
    }
50

  
51
    /**
52
     * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
53
     */
54
    public void execute(String s) {
55
        this.execute(s, null);
56
    }
57

  
58
    @Override
59
    public void execute(String command, Object[] args) {
60
        layoutPanel = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
61
        if (command.equals("application-export-to-pdf")) {
62
            Object file = ArrayUtils.get(args, 0);
63
            if( file instanceof String ) {
64
                file = new File((String)file);
65
            }
66
            if( file == null ) {
67
                layoutPanel.layoutToPDF();
68
            } else {
69
                layoutPanel.layoutToPDF((File)file);
70
            }
71
        } else if (command.equals("application-export-to-postscript")) {
72
            layoutPanel.layoutToPS();
73
        }
74
    }
75

  
76
    public boolean isEnabled() {
77
        return true;
78
    }
79

  
80
    public boolean isVisible() {
81
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
82

  
83
        if (f == null) {
84
            return false;
85
        }
86

  
87
        if (f instanceof LayoutPanel) {
88
            // Layout layout = (Layout) f;
89

  
90
            return true; // layout.m_Display.getMapControl().getMapContext().getLayers().layerCount()
91
            // > 0;
92
        } else {
93
            return false;
94
        }
95
    }
96

  
97
}
tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/FFrameLegendExtension.java
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 org.gvsig.andami.PluginServices;
25
import org.gvsig.andami.plugins.Extension;
26
import org.gvsig.andami.ui.mdiManager.IWindow;
27
import org.gvsig.app.project.documents.layout.FLayoutGraphics;
28
import org.gvsig.app.project.documents.layout.fframes.FFrameLegend;
29
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
30
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
31

  
32
/**
33
 * Extensi?n preparada para controlar las opciones que se pueden realizar sobre
34
 * una vista a?adida en el Layout.
35
 * 
36
 * @author Vicente Caballero Navarro
37
 */
38
public class FFrameLegendExtension extends Extension {
39

  
40
    private LayoutPanel layout = null;
41

  
42
    /**
43
     * @see org.gvsig.andami.plugins.IExtension#initialize()
44
     */
45
    public void initialize() {
46
    }
47

  
48
    /**
49
     * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
50
     */
51
    public void execute(String s) {
52
        layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
53
        FLayoutGraphics lg = new FLayoutGraphics(layout);
54
        if (s.compareTo("layout-graphic-simplify-legend") == 0) {
55
            lg.simplify();
56
            layout.getDocument().setModified(true);
57
        }
58
    }
59

  
60
    /**
61
     * @see org.gvsig.andami.plugins.IExtension#isEnabled()
62
     */
63
    public boolean isEnabled() {
64
        LayoutPanel l =
65
            (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
66
        IFFrame[] fframes = l.getLayoutContext().getSelectedFFrames();
67
        if (!l.getLayoutContext().isEditable())
68
            return false;
69
        for (int i = 0; i < fframes.length; i++) {
70
            if (fframes[i] instanceof FFrameLegend) {
71
                return true;
72
            }
73
        }
74

  
75
        return false;
76
    }
77

  
78
    /**
79
     * @see org.gvsig.andami.plugins.IExtension#isVisible()
80
     */
81
    public boolean isVisible() {
82
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
83

  
84
        if (f == null) {
85
            return false;
86
        }
87

  
88
        if (f instanceof LayoutPanel) {
89
            return true; // layout.m_Display.getMapControl().getMapContext().getLayers().layerCount()
90
                         // > 0;
91
        } else {
92
            return false;
93
        }
94
    }
95
}
tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/LayoutEditVertexExtension.java
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 org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

  
27
import org.gvsig.andami.IconThemeHelper;
28
import org.gvsig.andami.PluginServices;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
32

  
33
/**
34
 * Extensi?n que contiene todas las herramientas de edici?n.
35
 * 
36
 * @author Vicente Caballero Navarro
37
 */
38
public class LayoutEditVertexExtension extends Extension {
39

  
40
    private static final Logger logger = LoggerFactory
41
        .getLogger(LayoutEditVertexExtension.class);;
42
    private LayoutPanel layout = null;
43

  
44
    /**
45
     * DOCUMENT ME!
46
     */
47
    public void initialize() {
48
        // TODO Auto-generated method stub
49
        registerIcons();
50
    }
51

  
52
    private void registerIcons() {
53
        
54
        IconThemeHelper.registerIcon(
55
            "action", "layout-graphic-edit-vertex", this);
56
    }
57

  
58
    /**
59
     * DOCUMENT ME!
60
     * 
61
     * @param s
62
     *            DOCUMENT ME!
63
     */
64
    public void execute(String s) {
65
        layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
66

  
67
        logger.debug("Comand : " + s);
68
        if (s.compareTo("layout-graphic-edit-vertex") == 0) {
69
            layout.getLayoutControl().setTool("layoutedit");
70
            layout.getDocument().setModified(true);
71
        }
72
    }
73

  
74
    /**
75
     * DOCUMENT ME!
76
     * 
77
     * @return DOCUMENT ME!
78
     */
79
    public boolean isEnabled() {
80
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
81

  
82
        if (f == null) {
83
            return false;
84
        }
85

  
86
        if (f instanceof LayoutPanel) {
87
            LayoutPanel layout = (LayoutPanel) f;
88
            if (layout.getLayoutContext().isEditable()) {
89
                return true;
90
                // IFFrame[] fframes = layout.getFFrames();
91
                // for (int i = 0; i < fframes.length; i++) {
92
                // if (fframes[i].getSelected() != IFFrame.NOSELECT
93
                // && fframes[i] instanceof IFFrameEditableVertex) {
94
                // return true;
95
                // }
96
                // }
97
            }
98
        }
99
        return false;
100
    }
101

  
102
    /**
103
     * DOCUMENT ME!
104
     * 
105
     * @return DOCUMENT ME!
106
     */
107
    public boolean isVisible() {
108
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
109

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

  
114
        if (f instanceof LayoutPanel) {
115
            // Layout layout = (Layout) f;
116
            return true; // layout.m_Display.getMapControl().getMapContext().getLayers().layerCount()
117
                         // > 0;
118
        } else {
119
            return false;
120
        }
121
    }
122
}
tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/LayoutMainExtension.java
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.beans.PropertyVetoException;
26
import java.io.File;
27
import java.io.FileInputStream;
28
import java.io.IOException;
29
import java.util.Iterator;
30
import java.util.prefs.Preferences;
31
import javax.swing.JOptionPane;
32
import org.gvsig.andami.IconThemeHelper;
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.andami.plugins.Extension;
35
import org.gvsig.andami.ui.mdiManager.IWindow;
36
import org.gvsig.andami.ui.mdiManager.MDIManager;
37
import org.gvsig.app.ApplicationLocator;
38
import org.gvsig.app.ApplicationManager;
39
import org.gvsig.app.project.Project;
40
import org.gvsig.app.project.ProjectManager;
41
import org.gvsig.app.project.documents.Document;
42
import org.gvsig.app.project.documents.layout.DefaultLayoutManager;
43
import org.gvsig.app.project.documents.layout.LayoutDocument;
44
import org.gvsig.app.project.documents.layout.LayoutManager;
45
import org.gvsig.app.project.documents.layout.contextmenu.gui.BeforeLayoutMenuEntry;
46
import org.gvsig.app.project.documents.layout.contextmenu.gui.BehindLayoutMenuEntry;
47
import org.gvsig.app.project.documents.layout.contextmenu.gui.CancelLayoutMenuEntry;
48
import org.gvsig.app.project.documents.layout.contextmenu.gui.CopyLayoutMenuEntry;
49
import org.gvsig.app.project.documents.layout.contextmenu.gui.CutLayoutMenuEntry;
50
import org.gvsig.app.project.documents.layout.contextmenu.gui.PasteLayoutMenuEntry;
51
import org.gvsig.app.project.documents.layout.contextmenu.gui.PositionLayoutMenuEntry;
52
import org.gvsig.app.project.documents.layout.contextmenu.gui.PropertyLayoutMenuEntry;
53
import org.gvsig.app.project.documents.layout.contextmenu.gui.RefreshLayoutMenuEntry;
54
import org.gvsig.app.project.documents.layout.contextmenu.gui.SelectAllLayoutMenuEntry;
55
import org.gvsig.app.project.documents.layout.contextmenu.gui.SimplifyLayoutMenuEntry;
56
import org.gvsig.app.project.documents.layout.contextmenu.gui.TerminateLayoutMenuEntry;
57
import org.gvsig.app.project.documents.layout.fframes.FFrame;
58
import org.gvsig.app.project.documents.layout.fframes.FFrameBasicFactory;
59
import org.gvsig.app.project.documents.layout.fframes.FFrameGraphics;
60
import org.gvsig.app.project.documents.layout.fframes.FFrameGraphicsFactory;
61
import org.gvsig.app.project.documents.layout.fframes.FFrameGrid;
62
import org.gvsig.app.project.documents.layout.fframes.FFrameGridFactory;
63
import org.gvsig.app.project.documents.layout.fframes.FFrameGroup;
64
import org.gvsig.app.project.documents.layout.fframes.FFrameGroupFactory;
65
import org.gvsig.app.project.documents.layout.fframes.FFrameLegend;
66
import org.gvsig.app.project.documents.layout.fframes.FFrameLegendFactory;
67
import org.gvsig.app.project.documents.layout.fframes.FFrameNorth;
68
import org.gvsig.app.project.documents.layout.fframes.FFrameNorthFactory;
69
import org.gvsig.app.project.documents.layout.fframes.FFrameOverView;
70
import org.gvsig.app.project.documents.layout.fframes.FFrameOverViewFactory;
71
import org.gvsig.app.project.documents.layout.fframes.FFramePicture;
72
import org.gvsig.app.project.documents.layout.fframes.FFramePictureFactory;
73
import org.gvsig.app.project.documents.layout.fframes.FFrameScaleBar;
74
import org.gvsig.app.project.documents.layout.fframes.FFrameScaleBarFactory;
75
import org.gvsig.app.project.documents.layout.fframes.FFrameSymbol;
76
import org.gvsig.app.project.documents.layout.fframes.FFrameSymbolFactory;
77
import org.gvsig.app.project.documents.layout.fframes.FFrameTable;
78
import org.gvsig.app.project.documents.layout.fframes.FFrameTableFactory;
79
import org.gvsig.app.project.documents.layout.fframes.FFrameText;
80
import org.gvsig.app.project.documents.layout.fframes.FFrameTextFactory;
81
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
82
import org.gvsig.app.project.documents.layout.fframes.FFrameViewFactory;
83
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameBoxDialog;
84
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameGraphicsDialog;
85
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameGridDialog;
86
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameGroupDialog;
87
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameLegendDialog;
88
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameNorthDialog;
89
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameOverViewDialog;
90
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFramePictureDialog;
91
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameScaleBarDialog;
92
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameTextDialog;
93
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameViewDialog;
94
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
95
import org.gvsig.gui.beans.swing.JFileChooser;
96
import org.gvsig.i18n.Messages;
97
import org.gvsig.tools.ToolsLocator;
98
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
99
import org.gvsig.tools.i18n.I18nManager;
100
import org.gvsig.tools.persistence.PersistenceManager;
101
import org.gvsig.tools.persistence.PersistentState;
102
import org.gvsig.tools.persistence.exception.PersistenceException;
103
import org.gvsig.utils.GenericFileFilter;
104
import org.slf4j.Logger;
105
import org.slf4j.LoggerFactory;
106

  
107
/**
108
 * Extension que proporciona controles para crear proyectos nuevos, abrirlos y
109
 * guardarlos. Adem?s los tipos de tabla que soporta el proyecto son a?adidos en
110
 * esta clase.
111
 * 
112
 * @author Fernando Gonz?lez Cort?s
113
 */
114
public class LayoutMainExtension extends Extension {
115

  
116
    private static final Logger logger = LoggerFactory
117
            .getLogger(FFrameView.class);
118

  
119
    private String templatesPath;
120

  
121
    public static final String LAYOUT_TEMPLATE_FILECHOOSER_ID = "LAYOUT_TEMPLATE_FILECHOOSER_ID";
122

  
123
    private void registerIcons() {
124

  
125
        IconThemeHelper.registerIcon("action",
126
                "application-layout-template-open", this);
127
        IconThemeHelper.registerIcon("action",
128
                "application-layout-new", this);
129
        
130
    }
131

  
132
    @Override
133
    public void initialize() {
134
        registerIcons();
135
    }
136

  
137
    @Override
138
    public void postInitialize() {
139
        super.postInitialize();
140
        initializeDocumentActionsExtensionPoint();
141
        registerDocuments();
142
        registerFFrames();
143
        registerContextMenuOptions();
144
    }
145

  
146

  
147
    @Override
148
    public void execute(String actionCommand) {
149
        if ("application-layout-template-open".equals(actionCommand)) {
150
            openLayout();
151
        } else if ("application-layout-new".equals(actionCommand)) { 
152
            newLayout();   
153
        }
154
    }
155

  
156
    private void newLayout() {
157
        ApplicationManager application = ApplicationLocator.getManager();
158
        ProjectManager projectManager = ApplicationLocator.getProjectManager();
159
        I18nManager i18nManager = ToolsLocator.getI18nManager();
160
        Project project = projectManager.getCurrentProject();
161
        
162
        Iterator<? extends Document> documents =
163
            projectManager.createDocumentsByUser(LayoutManager.TYPENAME);
164
        for (; (documents != null) && (documents.hasNext());) {
165
            try {
166
                Document document = documents.next();
167
                project.addDocument(document);
168
                IWindow window = document.getFactory().getMainWindow(document);
169
                if (window == null) {
170
                    application.messageDialog(
171
                            i18nManager.getTranslation("error_opening_the_document"), 
172
                            i18nManager.getTranslation("warning"), 
173
                            JOptionPane.WARNING_MESSAGE
174
                    );
175
                    continue;
176
                }
177
                application.getUIManager().addWindow(
178
                    window,
179
                    MDIManager.ALIGN_FIRST_LINE_END_CASCADE
180
                );
181
                try {
182
                    application.getUIManager().setMaximum(window, true);
183
                } catch (PropertyVetoException e) {
184
                    logger.info("Can't maximize layout.", e);
185
                }
186
                
187
            } catch (Exception e) {
188
                logger.warn("Problems creating a Layout document.",e);
189
            }
190
        }        
191
    }
192
    
193

  
194
    private void openLayout() {
195
        LayoutPanel layout = null;
196

  
197
        if (templatesPath == null) {
198
            Preferences prefs = Preferences.userRoot().node("gvsig.foldering");
199
            templatesPath = prefs.get("TemplatesFolder", null);
200
        }
201

  
202
        JFileChooser jfc = new JFileChooser(LAYOUT_TEMPLATE_FILECHOOSER_ID,
203
                templatesPath);
204
        GenericFileFilter layoutMainExtensionFilter = new GenericFileFilter(
205
                LayoutManager.TEMPLATE_FILE_POINTEXT,
206
                Messages.getText("_Layout_template") + " (*"
207
                        + LayoutManager.TEMPLATE_FILE_POINTEXT + ")");
208
        jfc.addChoosableFileFilter(layoutMainExtensionFilter);
209
        jfc.setFileFilter(layoutMainExtensionFilter);
210

  
211
        if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
212
            File file = jfc.getSelectedFile();
213
            try {
214
                if (!file.exists()) {
215
                    /*
216
                     * The user has written a file name instead of clicking on
217
                     * one and it does not exist
218
                     */
219
                    File auxfile = new File(file.getPath()
220
                            + LayoutManager.TEMPLATE_FILE_POINTEXT);
221
                    if (!auxfile.exists()) {
222
                        /*
223
                         * Not even this one exists: error
224
                         */
225
                        throw new IOException("File does not exist: "
226
                                + file.getName());
227
                    }
228
                    else {
229
                        file = auxfile;
230
                    }
231
                }
232

  
233
                File xmlFile = new File(file.getAbsolutePath());
234
                FileInputStream is = new FileInputStream(xmlFile);
235

  
236
                PersistenceManager persistenceManager = ToolsLocator
237
                        .getPersistenceManager();
238
                PersistentState persistentState = persistenceManager
239
                        .loadState(is);
240
                layout = (LayoutPanel) persistenceManager
241
                        .create(persistentState);
242

  
243
            }
244
            catch (Exception e) {
245
                String tit = Messages.getText("_Layout_template");
246
                String msg;
247

  
248
                if (e instanceof PersistenceException) {
249
                    msg = Messages.getText("_Bad_format_in_layout_template");
250
                }
251
                else {
252
                    msg = Messages.getText("_Cant_load_layout_template");
253
                }
254

  
255
                msg = msg + ": " + file.getPath();
256
                msg = msg + "\n" + e.getMessage();
257
                logger.warn(msg, e);
258
                JOptionPane.showMessageDialog(ApplicationLocator.getManager()
259
                        .getRootComponent(), msg, tit,
260
                        JOptionPane.ERROR_MESSAGE);
261
            }
262

  
263
            if (layout == null) {
264
                return;
265
            }
266

  
267
            LayoutDocument layoutDocument = (LayoutDocument) layout
268
                    .getDocument();
269
            /*
270
             * (LayoutDocument) ProjectManager.getInstance().createDocument(
271
             * DefaultLayoutManager.TYPENAME, file.getName());
272
             */
273

  
274
            Project p = ApplicationLocator.getManager().getProjectManager()
275
                    .getCurrentProject();
276
            p.addDocument(layoutDocument);
277

  
278
            layout.getLayoutControl().setTool("layoutselect");
279

  
280
            LayoutManager lm = (LayoutManager) layoutDocument.getFactory();
281
            layout.setLayoutManager(lm);
282

  
283
            PluginServices.getMDIManager().addWindow(layout);
284

  
285
        }
286
    }
287

  
288
    private void registerDocuments() {
289
        DefaultLayoutManager.register();
290
    }
291

  
292
    private void registerFFrames() {
293
        DefaultLayoutManager layoutManager = (DefaultLayoutManager) ProjectManager
294
                .getInstance()
295
                .getDocumentManager(DefaultLayoutManager.TYPENAME);
296

  
297
        // Register Frames
298
        layoutManager.registerFrameFactory(new FFrameBasicFactory());
299
        layoutManager.registerFrameFactory(new FFrameGraphicsFactory());
300
        layoutManager.registerFrameFactory(new FFrameGroupFactory());
301
        layoutManager.registerFrameFactory(new FFrameLegendFactory());
302
        layoutManager.registerFrameFactory(new FFrameNorthFactory());
303
        layoutManager.registerFrameFactory(new FFrameOverViewFactory());
304
        layoutManager.registerFrameFactory(new FFramePictureFactory());
305
        layoutManager.registerFrameFactory(new FFrameScaleBarFactory());
306
        layoutManager.registerFrameFactory(new FFrameSymbolFactory());
307
        layoutManager.registerFrameFactory(new FFrameTableFactory());
308
        layoutManager.registerFrameFactory(new FFrameTextFactory());
309
        layoutManager.registerFrameFactory(new FFrameViewFactory());
310
        layoutManager.registerFrameFactory(new FFrameGridFactory());
311

  
312
        // Register FFrameDialogs forms
313
        layoutManager.registerFFrameDialog(
314
                FFrameGraphics.PERSISTENCE_DEFINITION_NAME,
315
                FFrameGraphicsDialog.class);
316
        layoutManager.registerFFrameDialog(
317
                FFrameSymbol.PERSISTENCE_DEFINITION_NAME,
318
                FFrameGraphicsDialog.class);
319
        layoutManager.registerFFrameDialog(
320
                FFrameGroup.PERSISTENCE_DEFINITION_NAME,
321
                FFrameGroupDialog.class);
322
        layoutManager.registerFFrameDialog(
323
                FFrameTable.PERSISTENCE_DEFINITION_NAME, FFrameBoxDialog.class);
324
        layoutManager.registerFFrameDialog(
325
                FFrameLegend.PERSISTENCE_DEFINITION_NAME,
326
                FFrameLegendDialog.class);
327
        layoutManager.registerFFrameDialog(
328
                FFramePicture.PERSISTENCE_DEFINITION_NAME,
329
                FFramePictureDialog.class);
330
        layoutManager.registerFFrameDialog(
331
                FFrameNorth.PERSISTENCE_DEFINITION_NAME,
332
                FFrameNorthDialog.class);
333
        layoutManager.registerFFrameDialog(
334
                FFrameScaleBar.PERSISTENCE_DEFINITION_NAME,
335
                FFrameScaleBarDialog.class);
336
        layoutManager.registerFFrameDialog(
337
                FFrameText.PERSISTENCE_DEFINITION_NAME, FFrameTextDialog.class);
338
        layoutManager.registerFFrameDialog(
339
                FFrameView.PERSISTENCE_DEFINITION_NAME, FFrameViewDialog.class);
340
        layoutManager.registerFFrameDialog(
341
                FFrameOverView.PERSISTENCE_DEFINITION_NAME,
342
                FFrameOverViewDialog.class);
343
        layoutManager.registerFFrameDialog(
344
                FFrameGrid.PERSISTENCE_DEFINITION_NAME, FFrameGridDialog.class);
345

  
346
        FFrame.initializeIcons();
347
        FFrameTable.initializeIcons();
348
    }
349

  
350
    private void registerContextMenuOptions() {
351
        LayoutManager layoutManager = (LayoutManager) ProjectManager
352
                .getInstance().getDocumentManager("project.document.layout");
353

  
354
        layoutManager.registerLayoutMenuAction("Terminate",
355
                TerminateLayoutMenuEntry.class);
356
        layoutManager.registerLayoutMenuAction("Cancel",
357
                CancelLayoutMenuEntry.class);
358
        layoutManager.registerLayoutMenuAction("Copy",
359
                CopyLayoutMenuEntry.class);
360
        layoutManager.registerLayoutMenuAction("Cut", CutLayoutMenuEntry.class);
361
        layoutManager.registerLayoutMenuAction("Paste",
362
                PasteLayoutMenuEntry.class);
363
        layoutManager.registerLayoutMenuAction("Simplify",
364
                SimplifyLayoutMenuEntry.class);
365
        layoutManager.registerLayoutMenuAction("Property",
366
                PropertyLayoutMenuEntry.class);
367
        layoutManager.registerLayoutMenuAction("SelectAll",
368
                SelectAllLayoutMenuEntry.class);
369
        layoutManager.registerLayoutMenuAction("Behind",
370
                BehindLayoutMenuEntry.class);
371
        layoutManager.registerLayoutMenuAction("Before",
372
                BeforeLayoutMenuEntry.class);
373
        layoutManager.registerLayoutMenuAction("Position",
374
                PositionLayoutMenuEntry.class);
375
        layoutManager.registerLayoutMenuAction("Refresh",
376
                RefreshLayoutMenuEntry.class);
377

  
378
    }
379

  
380
    private void initializeDocumentActionsExtensionPoint() {
381
        ExtensionPointManager epMan = ToolsLocator.getExtensionPointManager();
382
        epMan.add(
383
                "DocumentActions_Map",
384
                "Context menu options of the map document list"
385
                        + " in the project window "
386
                        + "(register instances of "
387
                        + "org.gvsig.app.project.AbstractDocumentContextMenuAction)");
388
    }
389

  
390
    @Override
391
    public boolean isEnabled() {
392
        return true;
393
    }
394

  
395
    @Override
396
    public boolean isVisible() {
397
        return true;
398
    }
399
}
tags/org.gvsig.app.document.layout2.app-2.0.125/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/LayoutInsertToolsExtension.java
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.
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff