Revision 38297

View differences:

tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Tue May 29 16:38:23 CEST 2012
3
buildNumber=13
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.app.document.layout.app</artifactId>
7
	<packaging>pom</packaging>
8
	<version>2.0.0-SNAPSHOT</version>
9
    <name>Layout document plugins</name>
10
    <description>Layout document plugins</description>
11
	<parent>
12
		<groupId>org.gvsig</groupId>
13
		<artifactId>org.gvsig.maven.base.extension.pom</artifactId>
14
		<version>1.0.8-SNAPSHOT</version>
15
	</parent>
16

  
17
    <scm>
18
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/extensions/org.gvsig.app.document.layout.app</connection>
19
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/extensions/org.gvsig.app.document.layout.app</developerConnection>
20
        <url>https://devel.gvsig.org/redmine/projects/gvsig-desktop/repository/show/branches/v2_0_0_prep/extensions/org.gvsig.app.document.layout.app</url>
21
    </scm>
22

  
23
	<developers>
24
		<developer>
25
			<id>jjdelcerro</id>
26
			<name>Joaqu?n Jos? del Cerro</name>
27
			<email>jjdelcerro@gvsig.org</email>
28
			<roles>
29
				<role>Architect</role>
30
				<role>Developer</role>
31
			</roles>
32
		</developer>
33
		<developer>
34
			<id>cordinyana</id>
35
			<name>C?sar Ordi?ana</name>
36
			<email>cordinyana@gvsig.com</email>
37
			<roles>
38
				<role>Architect</role>
39
				<role>Developer</role>
40
			</roles>
41
		</developer>
42
	</developers>
43
	<repositories>
44
		<repository>
45
			<id>gvsig-public-http-repository</id>
46
			<name>gvSIG maven public HTTP repository</name>
47
            <url>http://devel.gvsig.org/m2repo/j2se</url>
48
			<releases>
49
				<enabled>true</enabled>
50
				<updatePolicy>daily</updatePolicy>
51
				<checksumPolicy>warn</checksumPolicy>
52
			</releases>
53
			<snapshots>
54
				<enabled>true</enabled>
55
				<updatePolicy>daily</updatePolicy>
56
				<checksumPolicy>warn</checksumPolicy>
57
			</snapshots>
58
		</repository>
59
	</repositories>
60
	<dependencyManagement>
61
		<dependencies>
62
			<dependency>
63
				<groupId>org.gvsig</groupId>
64
				<artifactId>org.gvsig.core.maven.dependencies</artifactId>
65
				<version>2.0.1-SNAPSHOT</version>
66
				<type>pom</type>
67
				<scope>import</scope>
68
			</dependency>
69
			<dependency>
70
				<groupId>org.gvsig</groupId>
71
				<artifactId>org.gvsig.andami</artifactId>
72
				<version>2.0-SNAPSHOT</version>
73
				<scope>compile</scope>
74
			</dependency>
75
			<dependency>
76
				<groupId>org.gvsig</groupId>
77
				<artifactId>org.gvsig.app</artifactId>
78
				<version>2.0-SNAPSHOT</version>
79
				<scope>compile</scope>
80
			</dependency>
81
		</dependencies>
82
	</dependencyManagement>
83
	<modules>
84
		<module>org.gvsig.app.document.layout.app.mainplugin</module>
85
	</modules>
86
	<properties>
87
		<package.info.state>alpha5</package.info.state>
88
	</properties>
89
</project>
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Tue May 29 16:38:23 CEST 2012
3
buildNumber=13
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/document/layout/app/mainplugin/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.landregistryviewer package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>LandRegistryViewer gvSIG extension</p>
11
	
12
	<p>
13
	Shows LandRegistryViewer into gvSIG.
14
	</p>
15

  
16
</body>
17
</html>
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/gui/preferencespage/PrintPropertiesPage.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.gui.preferencespage;
23

  
24
import java.awt.Dimension;
25
import java.awt.GridLayout;
26

  
27
import javax.swing.ButtonGroup;
28
import javax.swing.ImageIcon;
29
import javax.swing.JCheckBox;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.JRadioButton;
33
import javax.swing.JTextField;
34

  
35
import org.gvsig.andami.PluginServices;
36
import org.gvsig.andami.preferences.AbstractPreferencePage;
37
import org.gvsig.andami.preferences.StoreException;
38

  
39
public class PrintPropertiesPage extends AbstractPreferencePage {
40

  
41
    private static final long serialVersionUID = 5806304468312341691L;
42
    private static final boolean FACTORY_DEFAULT_LANDSCAPED_PAGE = true;
43
    protected static String id = PrintPropertiesPage.class.getName();
44
    private ImageIcon icon;
45
    private JRadioButton rdBtnPortraitPage;
46
    private JRadioButton rdBtnLandscapePage;
47
    private JCheckBox chkCustomMargins;
48
    private JTextField txtTopMargin;
49
    private JTextField txtLeftMargin;
50
    private JTextField txtBottomMargin;
51
    private JTextField txtRightMargin;
52

  
53
    public PrintPropertiesPage() {
54
        super();
55
        setParentID(LayoutPage.class.getName());
56
        icon = PluginServices.getIconTheme().get("prepare-page-icon");
57
        rdBtnPortraitPage =
58
            new JRadioButton(PluginServices.getText(this,
59
                "options.layout.paper_properties.portrait"));
60
        ImageIcon portrait =
61
            PluginServices.getIconTheme().get("portrait-page-setup");
62
        rdBtnLandscapePage =
63
            new JRadioButton(PluginServices.getText(this,
64
                "options.layout.paper_properties.landscaped"));
65
        ImageIcon landscape =
66
            PluginServices.getIconTheme().get("landscape-page-setup");
67

  
68
        ButtonGroup group = new ButtonGroup();
69
        group.add(rdBtnLandscapePage);
70
        group.add(rdBtnPortraitPage);
71

  
72
        JPanel aux = new JPanel(new GridLayout(2, 2, 10, 0));
73
        aux.setPreferredSize(new Dimension(200, 150));
74
        aux.setSize(200, 150);
75
        aux.add(new JLabel(landscape));
76
        aux.add(new JLabel(portrait));
77
        aux.add(rdBtnLandscapePage);
78
        aux.add(rdBtnPortraitPage);
79

  
80
        addComponent(new JLabel(PluginServices.getText(this,
81
            "options.layout.paper_properties.paper_direction")));
82
        addComponent("", aux);
83
        addComponent(chkCustomMargins =
84
            new JCheckBox(PluginServices.getText(this, "personalizar_margenes")));
85

  
86
        JPanel aux2 = new JPanel(new GridLayout(2, 4, 10, 3));
87
        aux2.add(new JLabel(PluginServices.getText(this, "Superior")));
88
        aux2.add(txtTopMargin = new JTextField(10));
89
        aux2.add(new JLabel(PluginServices.getText(this, "Izquierdo")));
90
        aux2.add(txtLeftMargin = new JTextField(10));
91
        aux2.add(new JLabel(PluginServices.getText(this, "Inferior")));
92
        aux2.add(txtBottomMargin = new JTextField(10));
93
        aux2.add(new JLabel(PluginServices.getText(this, "Derecho")));
94
        aux2.add(txtRightMargin = new JTextField(10));
95
        addComponent("", aux2);
96
    }
97

  
98
    public void storeValues() throws StoreException {
99
        // TODO Auto-generated method stub
100

  
101
    }
102

  
103
    public void setChangesApplied() {
104
        // TODO Auto-generated method stub
105

  
106
    }
107

  
108
    public String getID() {
109
        return id;
110
    }
111

  
112
    public String getTitle() {
113
        return PluginServices.getText(this,
114
            "options.layout.paper_properties.title");
115
    }
116

  
117
    public JPanel getPanel() {
118
        return this;
119
    }
120

  
121
    public void initializeValues() {
122
        // TODO Auto-generated method stub
123

  
124
    }
125

  
126
    public void initializeDefaults() {
127
        rdBtnLandscapePage.setSelected(FACTORY_DEFAULT_LANDSCAPED_PAGE);
128
        rdBtnPortraitPage.setSelected(!FACTORY_DEFAULT_LANDSCAPED_PAGE);
129
    }
130

  
131
    public ImageIcon getIcon() {
132
        return icon;
133
    }
134

  
135
    public boolean isValueChanged() {
136
        // TODO Auto-generated method stub
137
        return false;
138
    }
139

  
140
}
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/gui/preferencespage/LayoutPage.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.gui.preferencespage;
23

  
24
import javax.swing.ImageIcon;
25
import javax.swing.JCheckBox;
26
import javax.swing.JPanel;
27
import javax.swing.JTextField;
28

  
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.preferences.AbstractPreferencePage;
31
import org.gvsig.andami.preferences.StoreException;
32
import org.gvsig.app.project.ProjectManager;
33
import org.gvsig.app.project.documents.layout.Attributes;
34
import org.gvsig.app.project.documents.layout.DefaultLayoutManager;
35
import org.gvsig.utils.XMLEntity;
36

  
37
/**
38
 * Layout preference page where the user can establish default values for
39
 * <ol>
40
 * <li><b>grid horizontal gap</b></li>
41
 * <li><b>grid vertical gap</b></li>
42
 * <li><b>show or hide grid</b></li>
43
 * <li><b>adjust elements to grid</b></li>
44
 * <li><b>show or hide rules</b></li>
45
 * </ol>
46
 * 
47
 * @author jaume dominguez faus - jaume.dominguez@iver.es
48
 * 
49
 */
50
public class LayoutPage extends AbstractPreferencePage {
51

  
52
    private static final long serialVersionUID = -8225970409668105935L;
53
    private static final boolean FACTORY_DEFAULT_LAYOUT_ENABLE_RULES = true;
54
    private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_SHOW = true;
55
    private static final double FACTORY_DEFAULT_VERTICAL_GAP = 1;
56
    private static final double FACTORY_DEFAULT_HORIZONTAL_GAP = 1;
57
    private static final boolean FACTORY_DEFAULT_LAYOUT_GRID_ENABLE = false;
58
    private static final String DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME =
59
        "DefaultShowLayoutGrid";
60
    private static final String DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME =
61
        "DefaultEnableLayoutGrid";
62
    private static final String DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME =
63
        "DefaultShowLayoutRules";
64
    private static final String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME =
65
        "DefaultGridVerticalGap";
66
    private static final String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME =
67
        "DefaultGridHorizontalGap";
68
    static String id = LayoutPage.class.getName();;
69
    private ImageIcon icon;
70
    private JCheckBox chkGridEnabled;
71
    private JCheckBox chkShowRules;
72
    private JCheckBox chkShowGrid;
73
    private JTextField txtVGap;
74
    private JTextField txtHGap;
75

  
76
    private static DefaultLayoutManager layoutManager = null;
77

  
78
    /**
79
     * Builds preference page where the user can establish default values for
80
     * <ol>
81
     * <li><b>grid horizontal gap</b></li>
82
     * <li><b>grid vertical gap</b></li>
83
     * <li><b>show or hide grid</b></li>
84
     * <li><b>adjust elements to grid</b></li>
85
     * <li><b>show or hide rules</b></li>
86
     * </ol>
87
     */
88
    public LayoutPage() {
89
        super();
90
        layoutManager =
91
            (DefaultLayoutManager) ProjectManager.getInstance()
92
                .getDocumentManager(DefaultLayoutManager.TYPENAME);
93

  
94
        icon = PluginServices.getIconTheme().get("mapa-icono");
95

  
96
        // horizontal gap text field
97
        addComponent(PluginServices.getText(this, "espaciado_horizontal"),
98
            txtHGap = new JTextField(5));
99

  
100
        // vertical gap text field
101
        addComponent(PluginServices.getText(this, "espaciado_vertical"),
102
            txtVGap = new JTextField(5));
103

  
104
        // show/hide show check
105
        addComponent(chkShowGrid =
106
            new JCheckBox(PluginServices.getText(this, "visualizar_cuadricula")));
107

  
108
        // enable/disable grid
109
        addComponent(chkGridEnabled =
110
            new JCheckBox(PluginServices.getText(this, "malla_activada")));
111

  
112
        // show/hide rules
113
        addComponent(chkShowRules =
114
            new JCheckBox(PluginServices.getText(this, "activar_regla")));
115

  
116
    }
117

  
118
    public void storeValues() throws StoreException {
119
        double hGap, vGap;
120
        boolean gridEnabled, showRules, showGrid;
121
        try {
122
            hGap = Double.parseDouble(txtHGap.getText());
123
            vGap = Double.parseDouble(txtVGap.getText());
124
            gridEnabled = chkGridEnabled.isSelected();
125
            showGrid = chkShowGrid.isSelected();
126
            showRules = chkShowRules.isSelected();
127
        } catch (Exception e) {
128
            throw new StoreException(PluginServices.getText(this,
129
                "invalid_value_for_gap"));
130
        }
131
        layoutManager.setDefaultShowGrid(showGrid);
132
        layoutManager.setDefaultAdjustToGrid(gridEnabled);
133
        layoutManager.setDefaultShowRulers(showRules);
134
        Attributes.setDefaultGridGap(hGap, vGap);
135
        PluginServices ps = PluginServices.getPluginServices(this);
136
        XMLEntity xml = ps.getPersistentXML();
137
        xml.putProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME, hGap);
138
        xml.putProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME, vGap);
139
        xml.putProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME, showGrid);
140
        xml.putProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME, gridEnabled);
141
        xml.putProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME, showRules);
142
    }
143

  
144
    public String getID() {
145
        return id;
146
    }
147

  
148
    public String getTitle() {
149
        return PluginServices.getText(this, "Mapa");
150
    }
151

  
152
    public JPanel getPanel() {
153
        return this;
154
    }
155

  
156
    public void initializeValues() {
157
        PluginServices ps = PluginServices.getPluginServices(this);
158
        XMLEntity xml = ps.getPersistentXML();
159
        double hGap = FACTORY_DEFAULT_HORIZONTAL_GAP;
160
        double vGap = FACTORY_DEFAULT_VERTICAL_GAP;
161
        boolean showGrid = FACTORY_DEFAULT_LAYOUT_GRID_SHOW;
162
        boolean gridEnabled = FACTORY_DEFAULT_LAYOUT_GRID_ENABLE;
163
        boolean showRules = FACTORY_DEFAULT_LAYOUT_ENABLE_RULES;
164
        // horizontal gap
165
        if (xml.contains(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME)) {
166
            hGap =
167
                xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME);
168
        }
169
        txtHGap.setText(String.valueOf(hGap));
170

  
171
        // vertical gap
172
        if (xml.contains(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME)) {
173
            vGap =
174
                xml.getDoubleProperty(DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME);
175
        }
176
        txtVGap.setText(String.valueOf(vGap));
177

  
178
        // show/hide grid check
179
        if (xml.contains(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) {
180
            showGrid =
181
                xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME);
182
        }
183
        chkShowGrid.setSelected(showGrid);
184

  
185
        // enable/disable grid check
186
        if (xml.contains(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) {
187
            gridEnabled =
188
                xml.getBooleanProperty(DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME);
189
        }
190
        chkGridEnabled.setSelected(gridEnabled);
191

  
192
        // enable/disable rules
193
        if (xml.contains(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME)) {
194
            showRules =
195
                xml.getBooleanProperty(DEFAULT_SHOW_LAYOUT_RULES_KEY_NAME);
196
        }
197
        chkShowRules.setSelected(showRules);
198

  
199
        layoutManager.setDefaultShowGrid(showGrid);
200
        layoutManager.setDefaultAdjustToGrid(gridEnabled);
201
        layoutManager.setDefaultShowRulers(showRules);
202
        Attributes.setDefaultGridGap(hGap, vGap);
203
    }
204

  
205
    public void initializeDefaults() {
206
        txtHGap.setText(String.valueOf(FACTORY_DEFAULT_HORIZONTAL_GAP));
207
        txtVGap.setText(String.valueOf(FACTORY_DEFAULT_VERTICAL_GAP));
208
        chkShowGrid.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_SHOW);
209
        chkGridEnabled.setSelected(FACTORY_DEFAULT_LAYOUT_GRID_ENABLE);
210
        chkShowRules.setSelected(FACTORY_DEFAULT_LAYOUT_ENABLE_RULES);
211
    }
212

  
213
    public ImageIcon getIcon() {
214
        return icon;
215
    }
216

  
217
    public boolean isValueChanged() {
218
        return super.hasChanged();
219
    }
220

  
221
    public void setChangesApplied() {
222
        setChanged(false);
223
    }
224
}
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/LayoutManager.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.project.documents.layout;
23

  
24
import java.awt.geom.AffineTransform;
25

  
26
import org.gvsig.app.project.documents.DocumentManager;
27
import org.gvsig.app.project.documents.layout.fframes.FrameFactory;
28
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
29
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
30
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
31
import org.gvsig.app.project.documents.view.IContextMenuAction;
32

  
33
/**
34
 * @author gvSIG Team
35
 * @version $Id: LayoutManager.java 34861 2011-03-31 11:31:50Z nfrancisco $
36
 * 
37
 */
38
public interface LayoutManager extends DocumentManager {
39

  
40
    public static String TEMPLATE_FILE_EXTENSION = ".gvsLayoutTemp";
41

  
42
    public IFFrame createFrame(String frameName);
43

  
44
    public IFFrameDialog createFFrameDialog(IFFrame fframe,
45
        LayoutPanel layoutPanel, AffineTransform affineTransform);
46

  
47
    public IFFrameDialog createFFrameDialog(IFFrame fframe,
48
        LayoutPanel layoutPanel);
49
    
50
    public void registerFFrameDialog(String name, Class clazz);
51
    
52
    /**
53
     * Registers in the points of extension the Factory with alias.
54
     * 
55
     * @param frameFactory
56
     *            FrameFactory to register.
57
     * @param alias
58
     *            Alias.
59
     */
60
    public void registerFrameFactory(FrameFactory frameFactory, String alias);
61
    
62
    /**
63
     * Registers in the points of extension the Factory
64
     * 
65
     * @param frameFactory
66
     *            FrameFactory to register.
67
     */
68
    public void registerFrameFactory(FrameFactory frameFactory);
69
    
70
    public void registerLayoutMenuAction(String name, Class<? extends IContextMenuAction> clazz);
71
    
72
    public IContextMenuAction[] createLayoutMenuActions(LayoutPanel layoutPanel);
73
}
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/Size.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.project.documents.layout;
23

  
24
import org.gvsig.tools.ToolsLocator;
25
import org.gvsig.tools.dynobject.DynStruct;
26
import org.gvsig.tools.persistence.PersistenceManager;
27
import org.gvsig.tools.persistence.Persistent;
28
import org.gvsig.tools.persistence.PersistentState;
29
import org.gvsig.tools.persistence.exception.PersistenceException;
30

  
31
/**
32
 * Clase que almacena la altura y anchura de un folio.
33
 * 
34
 * @author Vicente Caballero Navarro
35
 */
36
public class Size implements Persistent {
37

  
38
    public static final String PERSISTENCE_DEFINITION_NAME = "Size";
39
    private static final String HEIGHT_FIELD = "height";
40
    private static final String WIDTH_FIELD = "width";
41

  
42
    private double alto;
43
    private double ancho;
44

  
45
    public Size() {
46

  
47
    }
48

  
49
    /**
50
     * Creates a new Size object.
51
     * 
52
     * @param al
53
     *            Altura
54
     * @param an
55
     *            Anchura
56
     */
57
    public Size(double al, double an) {
58
        alto = al;
59
        ancho = an;
60
    }
61

  
62
    /**
63
     * Devuelve el alto del folio.
64
     * 
65
     * @return altura.
66
     */
67
    public double getAlto() {
68
        return alto;
69
    }
70

  
71
    /**
72
     * Devuelve la anchura del folio.
73
     * 
74
     * @return Anchura.
75
     */
76
    public double getAncho() {
77
        return ancho;
78
    }
79

  
80
    public static void registerPersistent() {
81
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
82
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
83
            DynStruct definition =
84
                manager.addDefinition(Size.class, PERSISTENCE_DEFINITION_NAME,
85
                    "Size persistence definition", null, null);
86

  
87
            definition.addDynFieldDouble(HEIGHT_FIELD).setMandatory(true);
88
            definition.addDynFieldDouble(WIDTH_FIELD).setMandatory(true);
89
        }
90
    }
91

  
92
    public void loadFromState(PersistentState state)
93
        throws PersistenceException {
94
        alto = state.getDouble(HEIGHT_FIELD);
95
        ancho = state.getDouble(WIDTH_FIELD);
96
    }
97

  
98
    public void saveToState(PersistentState state) throws PersistenceException {
99
        state.set(HEIGHT_FIELD, alto);
100
        state.set(WIDTH_FIELD, ancho);
101
    }
102
}
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutZooms.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.project.documents.layout;
23

  
24
import java.awt.Point;
25
import java.awt.Toolkit;
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.Point2D;
28
import java.awt.geom.Rectangle2D;
29
import java.util.prefs.Preferences;
30

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

  
34
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
35
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
36
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
37
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
38
import org.gvsig.fmap.geom.GeometryLocator;
39
import org.gvsig.fmap.geom.GeometryManager;
40
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
41
import org.gvsig.fmap.mapcontext.MapContext;
42
import org.gvsig.tools.observer.Observable;
43
import org.gvsig.tools.observer.ObservableHelper;
44
import org.gvsig.tools.observer.Observer;
45

  
46
/**
47
 * Clase encargada de realizar los zooms al Layout.
48
 * 
49
 * @author Vicente Caballero Navarro
50
 */
51
public class FLayoutZooms implements Observable{
52

  
53
    private static final GeometryManager geomManager = GeometryLocator
54
        .getGeometryManager();
55
    private static final Logger logger = LoggerFactory
56
        .getLogger(FLayoutZooms.class);
57
    private LayoutPanel layout = null;
58
    private ObservableHelper observers;
59
    
60
    public FLayoutZooms(LayoutPanel layoutPanel) {
61
        layout = layoutPanel;
62
        observers = new ObservableHelper();
63
        observers.addObserver(layoutPanel.getLayoutControl());
64
    }
65

  
66
    /**
67
     * Realiza un zoom por rect?ngulo o por punto con un escalado por defecto
68
     * sobre el Layout que se le pasa como par?metro.
69
     * 
70
     * @param p1
71
     *            punto de inicio del rect?ngulo.
72
     * @param p2
73
     *            punto final del rec?ngulo.
74
     */
75
    public void setZoomIn(Point p1, Point p2) {
76
        if (java.lang.Math.abs(layout.getLayoutControl().getFirstPoint().x
77
            - p2.x) < 4) {
78
            double difw = 2;
79
            setZoom(difw, p2);
80
        } else {
81
            if (p1.getX() > p2.getX()) {
82
                int aux = p2.x;
83
                p2.x = p1.x;
84
                p1.x = aux;
85
            }
86

  
87
            if (p1.getY() > p2.getY()) {
88
                int aux = p2.y;
89
                p2.y = p1.y;
90
                p1.y = aux;
91
            }
92

  
93
            Point2D.Double pSheet1 =
94
                FLayoutUtilities.toSheetPoint(
95
                    new Point2D.Double(p1.getX(), p1.getY()), layout
96
                        .getLayoutControl().getAT());
97
            Point2D.Double pSheet2 =
98
                FLayoutUtilities.toSheetPoint(
99
                    new Point2D.Double(p2.getX(), p2.getY()), layout
100
                        .getLayoutControl().getAT());
101

  
102
            double xmin;
103
            double xmax;
104
            double ymin;
105
            double ymax = 0;
106

  
107
            if (pSheet1.x > pSheet2.x) {
108
                xmin = pSheet2.x;
109
                xmax = pSheet1.x;
110
            } else {
111
                xmin = pSheet1.x;
112
                xmax = pSheet2.x;
113
            }
114

  
115
            if (pSheet1.y > pSheet2.y) {
116
                ymin = pSheet2.y;
117
                ymax = pSheet1.y;
118
            } else {
119
                ymin = pSheet1.y;
120
                ymax = pSheet2.y;
121
            }
122

  
123
            Rectangle2D.Double rScreen = new Rectangle2D.Double();
124
            Rectangle2D.Double rSheet = new Rectangle2D.Double();
125
            double x =
126
                FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
127
                    .getRect().getX(), layout.getLayoutControl().getAT());
128
            double y =
129
                FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
130
                    .getRect().getY(), layout.getLayoutControl().getAT());
131
            double w =
132
                FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
133
                    .getRect().getWidth(), layout.getLayoutControl().getAT());
134
            double h =
135
                FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
136
                    .getRect().getHeight(), layout.getLayoutControl().getAT());
137

  
138
            double wv =
139
                FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
140
                    .getWidth(), layout.getLayoutControl().getAT());
141
            double hv =
142
                FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
143
                    .getHeight(), layout.getLayoutControl().getAT());
144
            double mw = xmax - xmin;
145
            double mh = ymax - ymin;
146
            double difw = wv / mw;
147
            double difh = hv / mh;
148

  
149
            if (difw < difh) {
150
                rSheet.x =
151
                    (-xmin * difw)
152
                        - x
153
                        + ((wv - ((pSheet2.getX() - pSheet1.getX()) * difw)) / 2);
154
                rSheet.y =
155
                    (-ymin * difw)
156
                        - y
157
                        + ((hv - ((pSheet2.getY() - pSheet1.getY()) * difw)) / 2);
158

  
159
                rSheet.width = w * difw;
160
                rSheet.height = h * difw;
161
            } else {
162
                rSheet.x =
163
                    (-xmin * difh)
164
                        - x
165
                        + ((wv - ((pSheet2.getX() - pSheet1.getX()) * difh)) / 2);
166
                rSheet.y =
167
                    (-ymin * difh)
168
                        - y
169
                        + ((hv - ((pSheet2.getY() - pSheet1.getY()) * difh)) / 2);
170

  
171
                rSheet.width = w * difh;
172
                rSheet.height = h * difh;
173
            }
174
            setPointsToZoom(p1, p2);
175
            rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout
176
                .getLayoutControl().getAT()));
177
            if (FLayoutUtilities.isPosible(rScreen)) {
178
                layout.getLayoutControl().getRect().setRect(rScreen);
179
            }
180
        }
181
    }
182

  
183
    /**
184
     * Realiza un zoom out sobre el Layout que se le pasa como par?metro.
185
     * 
186
     * @param p2
187
     *            punto central del rect?ngulo.
188
     */
189
    public void setZoomOut(Point p2) {
190
        double difw = 0.5;
191
        setZoom(difw, p2);
192
    }
193

  
194
    /**
195
     * Realiza un zoom out sobre el Layout que se le pasa como par?metro.
196
     * 
197
     * @param dif
198
     *            factor.
199
     * @param p2
200
     *            punto final del rec?ngulo.
201
     */
202
    public void setZoom(double dif, Point p2) {
203
        Point2D.Double pSheet2 =
204
            FLayoutUtilities.toSheetPoint(
205
                new Point2D.Double(p2.getX(), p2.getY()), layout
206
                    .getLayoutControl().getAT());
207
        Rectangle2D.Double rScreen = new Rectangle2D.Double();
208
        Rectangle2D.Double rSheet = new Rectangle2D.Double();
209

  
210
        double difw = dif;
211

  
212
        rSheet.x =
213
            (-pSheet2.getX() * difw)
214
                - FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
215
                    .getRect().getX(), layout.getLayoutControl().getAT())
216
                + FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
217
                    layout.getLayoutControl().getAT());
218
        rSheet.y =
219
            (-pSheet2.getY() * difw)
220
                - FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
221
                    .getRect().getY(), layout.getLayoutControl().getAT())
222
                + FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
223
                    layout.getLayoutControl().getAT());
224

  
225
        rSheet.width =
226
            FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
227
                .getRect().getWidth(), layout.getLayoutControl().getAT())
228
                * difw;
229
        rSheet.height =
230
            FLayoutUtilities.toSheetDistance(layout.getLayoutControl()
231
                .getRect().getHeight(), layout.getLayoutControl().getAT())
232
                * difw;
233

  
234
        rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout
235
            .getLayoutControl().getAT()));
236

  
237
        if (FLayoutUtilities.isPosible(rScreen)) {
238
            layout.getLayoutControl().getRect().setRect(rScreen);
239
        }
240

  
241
        // Para realizar el zoom a partir de un punto.
242
        Point p1 =
243
            new Point((int) (p2.getX() - (layout.getWidth() / (difw * 2))),
244
                (int) (p2.getY() - (layout.getHeight() / (difw * 2))));
245
        p2 =
246
            new Point((int) (p2.getX() + (layout.getWidth() / (difw * 2))),
247
                (int) (p2.getY() + (layout.getHeight() / (difw * 2))));
248
        setPointsToZoom(p1, p2);
249
    }
250

  
251
    /**
252
     * Introduce los puntos de control para controlar el zoom del Layout.
253
     */
254
    private void setPointsToZoom(Point p1, Point p2) {
255
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
256

  
257
        for (int i = 0; i < fframes.length; i++) {
258
            if (fframes[i] instanceof IFFrameUseFMap) {
259
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
260
                if (fframe.getATMap() != null) {
261
                    Point2D px1 =
262
                        FLayoutFunctions.toMapPoint(p1, fframe.getATMap());
263
                    Point2D px2 =
264
                        FLayoutFunctions.toMapPoint(p2, fframe.getATMap());
265
                    fframe.setPointsToZoom(px1, px2);
266
                }
267
            }
268
        }
269
    }
270

  
271
    /**
272
     * Aplica el zoom real teniendo en cuenta la resoluci?n de pantalla.
273
     */
274
    public void realZoom() {
275
        Preferences prefsResolution =
276
            Preferences.userRoot().node("gvsig.configuration.screen");
277
        double cm =
278
            layout.getLayoutContext().getAttributes()
279
                .getPixXCm(layout.getLayoutControl().getRect());
280
        Toolkit kit = Toolkit.getDefaultToolkit();
281
        double dpi = prefsResolution.getInt("dpi", kit.getScreenResolution());
282
        double dif = (cm * Attributes.PULGADA) / dpi;
283
        setZoom(1 / dif, new Point(layout.getWidth() / 2,
284
            layout.getHeight() / 2));
285
        layout.getLayoutControl().refresh();
286
    }
287

  
288
    /**
289
     * Realiza un zoom in a partir del zoom actual de la vista.
290
     */
291
    public void zoomIn() {
292
        setZoom(2, new Point(layout.getWidth() / 2, layout.getHeight() / 2));
293
        layout.getLayoutControl().refresh();
294
    }
295

  
296
    /**
297
     * Realiza un zoom out a partir del zoom actual de la vista.
298
     */
299
    public void zoomOut() {
300
        setZoom(0.5, new Point(layout.getWidth() / 2, layout.getHeight() / 2));
301
        layout.getLayoutControl().refresh();
302
    }
303

  
304
    /**
305
     * Realiza un zoom a los elementos que esten seleccionados, si no hay
306
     * ning?n elemento seleccionado no realiza ning?n zoom
307
     */
308
    public void zoomSelect() {
309
        Rectangle2D.Double recaux = null;
310
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
311
        for (int i = 0; i < fframes.length; i++) {
312
            if (fframes[i].getSelected() != IFFrame.NOSELECT) {
313
                if (recaux == null) {
314
                    recaux =
315
                        fframes[i].getBoundingBox(layout.getLayoutControl()
316
                            .getAT());
317
                } else {
318
                    recaux.add(fframes[i].getBoundingBox(layout
319
                        .getLayoutControl().getAT()));
320
                }
321
            }
322
        }
323

  
324
        if (recaux != null) {
325
            Point p1 = new Point((int) recaux.x, (int) recaux.y);
326
            Point p2 =
327
                new Point((int) recaux.getMaxX(), (int) recaux.getMaxY());
328
            setZoomIn(p1, p2);
329
            layout.getLayoutControl().refresh();
330
        }
331
    }
332

  
333
    /**
334
     * Realiza un zoom a todos los elementos del layout.
335
     */
336
    public void zoomAllFrames() {
337
        Rectangle2D.Double recaux = null;
338
        IFFrame[] fframes =
339
            layout.getLayoutControl().getLayoutContext().getFFrames();
340
        for (int i = 0; i < fframes.length; i++) {
341
            if (recaux == null) {
342
                recaux =
343
                    fframes[i]
344
                        .getBoundingBox(layout.getLayoutControl().getAT());
345
            } else {
346
                recaux.add(fframes[i].getBoundingBox(layout.getLayoutControl()
347
                    .getAT()));
348
            }
349
        }
350

  
351
        if (recaux != null) {
352
            Point p1 = new Point((int) recaux.x, (int) recaux.y);
353
            Point p2 =
354
                new Point((int) recaux.getMaxX(), (int) recaux.getMaxY());
355
            setZoomIn(p1, p2);
356
            layout.getLayoutControl().refresh();
357
        }
358
    }
359

  
360
    /**
361
     * Realiza un zoom in a las vista a?adidas al Layout que esten seleccionadas
362
     * 
363
     * @param p1
364
     *            Punto inicial del rect?ngulo
365
     * @param p2
366
     *            Punto final del rect?ngulo
367
     */
368
    public void setViewZoomIn(Point2D p1, Point2D p2) {
369
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
370
        for (int i = 0; i < fframes.length; i++) {
371
            if (fframes[i] instanceof IFFrameUseFMap) {
372
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
373

  
374
                if (((IFFrame) fframe).getSelected() != IFFrame.NOSELECT) {
375
                    // IFFrameUseFMap
376
                    // fframeAux=(IFFrameUseFMap)((IFFrame)fframe).cloneFFrame(layout);
377
                    p1 = FLayoutFunctions.toMapPoint(p1, fframe.getATMap());
378
                    p2 = FLayoutFunctions.toMapPoint(p2, fframe.getATMap());
379

  
380
                    // Borramos el anterior
381
                    observers.notifyObservers(this, 
382
                        new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));
383
                    Rectangle2D.Double r = new Rectangle2D.Double();
384

  
385
                    if (java.lang.Math.abs(p1.getX() - p2.getX()) <= 3) {
386
                        double nuevoX;
387
                        double nuevoY;
388
                        double cX;
389
                        double cY;
390

  
391
                        cX = p2.getX();
392
                        cY = p2.getY();
393

  
394
                        double factor = 1 / MapContext.ZOOMINFACTOR;
395

  
396
                        Rectangle2D extent =
397
                            fframe.getMapContext().getViewPort().getExtent();
398
                        if (extent != null) {
399
                            nuevoX = cX - ((extent.getWidth() * factor) / 2.0);
400
                            nuevoY = cY - ((extent.getHeight() * factor) / 2.0);
401
                            r.x = nuevoX;
402
                            r.y = nuevoY;
403
                            r.width = extent.getWidth() * factor;
404
                            r.height = extent.getHeight() * factor;
405
                        }
406

  
407
                        // fframeAux.setNewExtent(r);
408
                    } else {
409
                        // Fijamos el nuevo extent
410

  
411
                        r.setFrameFromDiagonal(p1, p2);
412

  
413
                        // fframeAux.setNewExtent(r);
414
                    }
415

  
416
                    /*
417
                     * if (fframe.getTypeScale()!=IFFrameUseFMap.AUTOMATICO) {
418
                     * fframeAux.setNewExtent(r);
419
                     * fframeAux.refresh();
420
                     * layout.getEFS().modifyFFrame((IFFrame)fframe,(IFFrame)
421
                     * fframeAux);
422
                     * ((IFFrame)fframeAux).getBoundingBox(layout.getAT());
423
                     * layout.updateFFrames();
424
                     * layout.setIsReSel(true);
425
                     * }else {
426
                     */
427
                    try {
428
                        fframe.setNewEnvelope(geomManager.createEnvelope(
429
                            r.getX(), r.getY(), r.getMaxX(), r.getMaxY(),
430
                            SUBTYPES.GEOM2D));
431
                    } catch (CreateEnvelopeException e) {
432
                        logger.error("Error creating the envelope", e);
433
                    }
434
                    fframe.refresh();
435
                    fframe.refreshOriginalExtent();
436
                    // /}
437
                    // Fin del else
438
                    // layout.repaint();
439
                }
440
            }
441
        }
442
    }
443

  
444
    /**
445
     * Realiza un zoom out a las vistas a?adidas al Layout y que est?n
446
     * seleccionadas
447
     * 
448
     * @param p2
449
     *            Punto central
450
     */
451
    public void setViewZoomOut(Point p2) {
452
        Point2D.Double pWorld;
453
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
454
        for (int i = 0; i < fframes.length; i++) {
455
            if (fframes[i] instanceof IFFrameUseFMap) {
456
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
457

  
458
                if (((IFFrame) fframe).getSelected() != IFFrame.NOSELECT) {
459
                    // IFFrameUseFMap
460
                    // fframeAux=(IFFrameUseFMap)((IFFrame)fframe).cloneFFrame(layout);
461
                    double nuevoX;
462
                    double nuevoY;
463
                    double cX;
464
                    double cY;
465
                    Point pScreen = new Point((int) p2.getX(), (int) p2.getY());
466
                    pWorld =
467
                        FLayoutFunctions.toMapPoint(pScreen, fframe.getATMap());
468

  
469
                    cX = pWorld.getX();
470
                    cY = pWorld.getY();
471

  
472
                    double factor = 1 / MapContext.ZOOMOUTFACTOR;
473
                    Rectangle2D extent =
474
                        fframe.getMapContext().getViewPort().getExtent();
475
                    if (extent != null) {
476
                        nuevoX = cX - ((extent.getWidth() * factor) / 2.0);
477
                        nuevoY = cY - ((extent.getHeight() * factor) / 2.0);
478
                        double x = nuevoX;
479
                        double y = nuevoY;
480
                        double width = extent.getWidth() * factor;
481
                        double height = extent.getHeight() * factor;
482
                        try {
483
                            fframe.setNewEnvelope(geomManager.createEnvelope(x,
484
                                y, x + width, y + height, SUBTYPES.GEOM2D));
485
                        } catch (CreateEnvelopeException e) {
486
                            logger.error("Error creating the envelope", e);
487
                        }
488
                        fframe.refresh();
489
                        fframe.refreshOriginalExtent();
490
                    }
491
                }
492
            }
493
        }
494
    }
495

  
496
    /**
497
     * Modifica los puntos de control para generar el zoom del Layout
498
     * 
499
     * @param p1
500
     *            Punto inicial
501
     * @param p2
502
     *            Punto final
503
     */
504
    public void setPan(Point p1, Point p2) {
505
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
506

  
507
        for (int i = 0; i < fframes.length; i++) {
508
            if (fframes[i] instanceof IFFrameUseFMap) {
509
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
510
                AffineTransform at = fframe.getATMap();
511
                if (at != null) {
512
                    Point2D px1 = FLayoutFunctions.toMapPoint(p1, at);
513
                    Point2D px2 = FLayoutFunctions.toMapPoint(p2, at);
514
                    fframe.movePoints(px1, px2);
515
                }
516
            }
517
        }
518
    }
519

  
520
    public void addObserver(Observer o) {
521
        observers.addObserver(o);        
522
    }
523

  
524
    public void deleteObserver(Observer o) {
525
      observers.deleteObserver(o);        
526
    }
527

  
528
    public void deleteObservers() {
529
       observers.deleteObservers();        
530
    }
531
}
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutFunctions.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.project.documents.layout;
23

  
24
import java.awt.Point;
25
import java.awt.Rectangle;
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.NoninvertibleTransformException;
28
import java.awt.geom.Point2D;
29
import java.awt.geom.Rectangle2D;
30

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

  
34
import org.gvsig.app.project.documents.layout.commands.FrameCommandsRecord;
35
import org.gvsig.app.project.documents.layout.fframes.FFrameGroup;
36
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
37
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
38
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
39
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
40
import org.gvsig.fmap.geom.GeometryLocator;
41
import org.gvsig.fmap.geom.GeometryManager;
42
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
43
import org.gvsig.tools.observer.Observable;
44
import org.gvsig.tools.observer.ObservableHelper;
45
import org.gvsig.tools.observer.Observer;
46

  
47
/**
48
 * Funciones utilizadas desde el Layout.
49
 * 
50
 * @author Vicente Caballero Navarro
51
 */
52
public class FLayoutFunctions implements Observable {
53

  
54
    protected static final Logger LOG = LoggerFactory
55
        .getLogger(FLayoutFunctions.class);
56
    private static final GeometryManager geomManager = GeometryLocator
57
        .getGeometryManager();
58
    private static final Logger logger = LoggerFactory
59
        .getLogger(FLayoutFunctions.class);
60
    
61
    private LayoutPanel layout = null;
62
    private ObservableHelper observers;
63
    /**
64
     * Crea un nuevo FLayoutFunctions.
65
     * 
66
     * @param l
67
     *            Referencia al Layout.
68
     */
69
    public FLayoutFunctions(LayoutPanel layoutPanel) {
70
        layout = layoutPanel;
71
        observers = new ObservableHelper();
72
        observers.addObserver(layoutPanel.getLayoutControl());
73
    }
74

  
75
    /**
76
     * Gestiona la herramienta de selecci?n sobre el Mapa.
77
     */
78
    public void setSelect() {
79
        IFFrame fframe = null;
80
        boolean isUpdate = false;
81
        layout.getLayoutContext().updateFFrames();
82
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
83
        FrameCommandsRecord efs =
84
            layout.getLayoutContext().getFrameCommandsRecord();
85
        efs.startComplex("move");
86
        for (int i = 0; i < fframes.length; i++) {
87
            fframe = fframes[i];
88

  
89
            int difx =
90
                (layout.getLayoutControl().getLastPoint().x - layout
91
                    .getLayoutControl().getFirstPoint().x);
92
            int dify =
93
                (layout.getLayoutControl().getLastPoint().y - layout
94
                    .getLayoutControl().getFirstPoint().y);
95

  
96
            if (((Math.abs(difx) > 3) || (Math.abs(dify) > 3))
97
                && (fframe.getSelected() != IFFrame.NOSELECT)) {
98
                Rectangle2D rectangle = fframe.getLastMoveRect();
99
                if (rectangle == null) {
100
                    efs.endComplex();
101
                    return;
102
                }
103
  
104
                if (fframe instanceof FFrameGroup) {
105
                    ((FFrameGroup) fframe).setAt(layout.getLayoutControl()
106
                        .getAT());
107
                }
108

  
109
                IFFrame fframeAux;
110
                try {
111
                    fframeAux = (IFFrame) fframe.clone();
112
                    fframeAux.setBoundBox(FLayoutUtilities.toSheetRect(
113
                        rectangle, layout.getLayoutControl().getAT()));
114
                    efs.update(fframe, fframeAux);
115
                    fframeAux.getBoundingBox(layout.getLayoutControl().getAT());
116

  
117
                    isUpdate = true;
118
                } catch (CloneNotSupportedException e) {
119
                    LOG.error("It is not possible clonate the object", e);
120
                }
121

  
122
            }
123
            Rectangle rect = null;
124
            if (layout.getLayoutControl().getReSel() == null) {
125
                rect = new Rectangle();
126
                rect.setFrameFromDiagonal(layout.getLayoutControl()
127
                    .getFirstPoint(), layout.getLayoutControl().getLastPoint());
128
            } else {
129
                rect = layout.getLayoutControl().getReSel();
130
            }
131
            if (layout.getLayoutControl().isReSel()
132
                && (rect.contains(fframe.getBoundingBox(layout
133
                    .getLayoutControl().getAT())))) {
134
                fframe.setSelected(true);
135
            }
136

  
137
            if (isUpdate) {
138
                observers.notifyObservers(this, 
139
                    new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));
140
            } else {
141
                observers.notifyObservers(this, 
142
                    new DefaultLayoutNotification(LayoutNotification.LAYOUT_VALIDATED));
143
            }
144
        }
145
        efs.endComplex();
146
        layout.getLayoutContext().updateFFrames();
147
    }
148

  
149
    /**
150
     * Pan sobre la vista del FFrameView.
151
     * 
152
     * @param p1
153
     *            Punto inicial del desplazamiento.
154
     * @param p2
155
     *            Punto final del desplazamiento.
156
     */
157
    public void setViewPan(Point p1, Point p2) {
158
        IFFrame[] fframes = layout.getLayoutContext().getFFrames();
159
        for (int i = 0; i < fframes.length; i++) {
160
            if (fframes[i] instanceof IFFrameUseFMap) {
161
                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
162

  
163
                if (((IFFrame) fframe).getSelected() != IFFrame.NOSELECT) {
164
                    if (fframe.getATMap() != null) {
165
                        Rectangle2D.Double r = new Rectangle2D.Double();
166
                        Rectangle2D extent =
167
                            fframe.getMapContext().getViewPort().getExtent();
168
                        if (extent != null) {
169
                            Point2D mp1 = toMapPoint(p1, fframe.getATMap());
170
                            Point2D mp2 = toMapPoint(p2, fframe.getATMap());
171
                            double x =
172
                                extent.getX() - (mp2.getX() - mp1.getX());
173
                            double y =
174
                                extent.getY() - (mp2.getY() - mp1.getY());
175
                            double width = extent.getWidth();
176
                            double height = extent.getHeight();
177
                            try {
178
                                fframe
179
                                    .getMapContext()
180
                                    .getViewPort()
181
                                    .setEnvelope(
182
                                        geomManager.createEnvelope(x, y, x
183
                                            + width, y + height,
184
                                            SUBTYPES.GEOM2D));
185
                            } catch (CreateEnvelopeException e) {
186
                                logger.error("Error creating the envelope", e);
187
                            }
188
                            fframe.refresh();
189
                            fframe.refreshOriginalExtent();
190
                        }
191
                    }
192
                }
193
            }
194
        }
195
    }
196

  
197
    /**
198
     * Devuelve un punto real a partir de un punto en pixels sobre la vista.
199
     * 
200
     * @param pScreen
201
     *            Punto en pixels.
202
     * @param at1
203
     *            Matriz de transformaci?n.
204
     * 
205
     * @return Punto real.
206
     */
207
    public static Point2D.Double toMapPoint(Point2D pScreen, AffineTransform at1) {
208
        Point2D.Double pWorld = new Point2D.Double();
209

  
210
        AffineTransform at;
211

  
212
        try {
213
            at = at1.createInverse();
214
            at.transform(pScreen, pWorld);
215
        } catch (NoninvertibleTransformException e) {
216
            // throw new RuntimeException(e);
217
        }
218

  
219
        return pWorld;
220
    }
221

  
222
    public void addObserver(Observer o) {
223
        observers.addObserver(o);        
224
    }
225

  
226
    public void deleteObserver(Observer o) {
227
      observers.deleteObserver(o);        
228
    }
229

  
230
    public void deleteObservers() {
231
       observers.deleteObservers();        
232
    }
233
}
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/LayoutDocument.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.project.documents.layout;
23

  
24
import org.gvsig.app.project.documents.Document;
25

  
26
/**
27
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
28
 */
29
public interface LayoutDocument extends Document {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff