Revision 294

View differences:

tags/org.gvsig.app.document.layout2.app-2.0.38/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>Document: Layout document plugin, version 2</name>
9
    
10
    <parent>
11
        <groupId>org.gvsig</groupId>
12
        <artifactId>org.gvsig.app.document.layout2.app</artifactId>
13
        <version>2.0.38</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.mapcontext.operation</artifactId>
51
            <scope>compile</scope>
52
        </dependency>
53
        <dependency>
54
            <groupId>org.gvsig</groupId>
55
            <artifactId>org.gvsig.fmap.geometry.api</artifactId>
56
            <scope>compile</scope>
57
        </dependency>
58
        <dependency>
59
            <groupId>org.gvsig</groupId>
60
            <artifactId>org.gvsig.utils</artifactId>
61
            <scope>compile</scope>
62
        </dependency>
63
        <dependency>
64
            <groupId>org.gvsig</groupId>
65
            <artifactId>org.gvsig.ui</artifactId>
66
            <scope>compile</scope>
67
        </dependency>
68
        <dependency>
69
            <groupId>org.gvsig</groupId>
70
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
71
            <scope>compile</scope>
72
        </dependency>
73
        <dependency>
74
            <groupId>org.gvsig</groupId>
75
            <artifactId>org.gvsig.compat.api</artifactId>
76
            <scope>compile</scope>
77
        </dependency>
78
        <dependency>
79
            <groupId>org.gvsig</groupId>
80
            <artifactId>org.gvsig.projection.api</artifactId>
81
            <scope>compile</scope>
82
        </dependency>
83
        <dependency>
84
            <groupId>org.gvsig</groupId>
85
            <artifactId>org.gvsig.symbology.lib.api</artifactId>
86
            <scope>compile</scope>
87
        </dependency>
88
        <dependency>
89
            <groupId>org.gvsig</groupId>
90
            <artifactId>org.gvsig.symbology.swing.api</artifactId>
91
            <scope>compile</scope>
92
        </dependency>
93
        <dependency>
94
            <groupId>org.gvsig</groupId>
95
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
96
            <scope>compile</scope>
97
        </dependency>
98
        <dependency>
99
            <groupId>com.lowagie</groupId>
100
            <artifactId>itext</artifactId>
101
            <version>2.1.7</version>
102
            <scope>compile</scope>
103
        </dependency>
104
        <dependency>
105
            <groupId>org.apache.xmlgraphics</groupId>
106
            <artifactId>batik-gvt</artifactId>
107
            <scope>compile</scope>
108
        </dependency>
109
        <dependency>
110
            <groupId>org.apache.xmlgraphics</groupId>
111
            <artifactId>batik-script</artifactId>
112
            <scope>compile</scope>
113
        </dependency>
114
        
115
        <!--
116
        <dependency>
117
            <groupId>org.gvsig</groupId>
118
            <artifactId>batik-ext-gvsig-custom</artifactId>
119
        </dependency>
120
        -->
121
        
122
        <dependency>
123
            <groupId>com.sun</groupId>
124
            <artifactId>jimi</artifactId>
125
            <scope>compile</scope>
126
        </dependency>
127
        <dependency>
128
            <groupId>org.gvsig</groupId>
129
            <artifactId>org.gvsig.i18n</artifactId>
130
            <scope>compile</scope>
131
        </dependency>
132

  
133
    </dependencies>
134

  
135
    <properties>
136
        <gvsig.package.info.dependencies>conflict: org.gvsig.app.document.layout1.app.mainplugin -ge 1, required: org.gvsig.app.mainplugin -ge 2.1.57</gvsig.package.info.dependencies>
137
        <gvsig.package.info.categories>Layout</gvsig.package.info.categories>
138
	<gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-app-document-layout/pool</gvsig.package.info.poolURL>
139
	<gvsig.package.info.sourcesURL>http://devel.gvsig.org/svn/gvsig-app-document-layout/trunk/org.gvsig.app.document.layout2.app</gvsig.package.info.sourcesURL>
140
	<gvsig.package.info.state>testing</gvsig.package.info.state>
141
        <gvsig.package.info.official>true</gvsig.package.info.official>
142
        <gvsig.package.info.codealias>org.gvsig.app.document.layout.app.mainplugin</gvsig.package.info.codealias>
143

  
144
    </properties>
145

  
146
</project>
147

  
tags/org.gvsig.app.document.layout2.app-2.0.38/org.gvsig.app.document.layout2.app.mainplugin/buildNumber.properties
1
#Thu Oct 16 05:36:39 EDT 2014
2
buildNumber=57
0 3

  
tags/org.gvsig.app.document.layout2.app-2.0.38/org.gvsig.app.document.layout2.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25
  <dependencySets>
26
  
27
  <!--
28
    <dependencySet>
29
      <useProjectArtifact>false</useProjectArtifact>
30
      <useTransitiveDependencies>false</useTransitiveDependencies>
31
      <outputDirectory>lib</outputDirectory>
32
      <includes>
33
      </includes>
34
    </dependencySet>
35
    
36
    -->
37
    
38
  </dependencySets>
39

  
40
</assembly>
0 41

  
tags/org.gvsig.app.document.layout2.app-2.0.38/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.38/org.gvsig.app.document.layout2.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/org.gvsig.app.document.layout2.app-2.0.38/org.gvsig.app.document.layout2.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 java.awt.GridBagConstraints;
25
import java.awt.Insets;
26

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

  
35
import org.gvsig.andami.IconThemeHelper;
36
import org.gvsig.andami.PluginServices;
37
import org.gvsig.andami.PluginsLocator;
38
import org.gvsig.andami.preferences.AbstractPreferencePage;
39
import org.gvsig.andami.preferences.StoreException;
40
import org.gvsig.app.project.ProjectManager;
41
import org.gvsig.app.project.documents.layout.Attributes;
42
import org.gvsig.app.project.documents.layout.DefaultLayoutManager;
43
import org.gvsig.fmap.mapcontext.MapContext;
44
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
45
import org.gvsig.i18n.Messages;
46
import org.gvsig.utils.XMLEntity;
47

  
48
/**
49
 * Layout preference page where the user can establish default values for
50
 * <ol>
51
 * <li><b>grid horizontal gap</b></li>
52
 * <li><b>grid vertical gap</b></li>
53
 * <li><b>show or hide grid</b></li>
54
 * <li><b>adjust elements to grid</b></li>
55
 * <li><b>show or hide rules</b></li>
56
 * </ol>
57
 * 
58
 * @author jaume dominguez faus - jaume.dominguez@iver.es
59
 * 
60
 */
61
public class LayoutPage extends AbstractPreferencePage {
62

  
63
    private static final long serialVersionUID = -8225970409668105935L;
64
    static String id = LayoutPage.class.getName();;
65
    private ImageIcon icon;
66
    private JCheckBox chkGridEnabled;
67
    private JCheckBox chkShowRules;
68
    private JCheckBox chkShowGrid;
69
    private JTextField txtVGap;
70
    private JTextField txtHGap;
71
    private JCheckBox chkShowInitialPageConfig;
72
	private JCheckBox chkShowLayoutTOC;
73
	private JComboBox cbHGapUnit;
74
	private JComboBox cbVGapUnit;
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 = IconThemeHelper.getImageIcon("document-map-icon");
95

  
96
        GridBagLayoutPanel gridRulerPanel = new GridBagLayoutPanel();
97
        Insets topInsets = new Insets(10, 10, 0, 10);
98
        Insets insets = new Insets(8, 10, 0, 10);
99
        Insets lastInsets = new Insets(8, 10, 12, 10);
100
        gridRulerPanel.setBorder(BorderFactory.createTitledBorder(Messages.getText("Grid_and_ruler")));
101
        
102
        // horizontal gap text field and units combo
103
        cbHGapUnit = new JComboBox();
104
        String[] names = MapContext.getDistanceNames();
105
        for (int i = 0; i < names.length; i++) {
106
        	cbHGapUnit.addItem(PluginServices.getText(this, names[i]));
107
        }
108
        gridRulerPanel.addComponent(new JLabel(PluginServices.getText(this, "espaciado_horizontal")),
109
            txtHGap = new JTextField(5), cbHGapUnit, GridBagConstraints.NONE, insets);
110
        
111
        // vertical gap text field and units combo
112
        cbVGapUnit = new JComboBox();
113
        for (int i = 0; i < names.length; i++) {
114
        	cbVGapUnit.addItem(PluginServices.getText(this, names[i]));
115
        }
116
        gridRulerPanel.addComponent(new JLabel(PluginServices.getText(this, "espaciado_vertical")),
117
        		txtVGap = new JTextField(5), cbVGapUnit, GridBagConstraints.NONE, insets);
118

  
119
        // show/hide show check
120
        gridRulerPanel.addComponent(chkShowGrid =
121
            new JCheckBox(PluginServices.getText(this, "visualizar_cuadricula")), insets);
122

  
123
        // enable/disable grid
124
        gridRulerPanel.addComponent(chkGridEnabled =
125
            new JCheckBox(PluginServices.getText(this, "malla_activada")), insets);
126

  
127
        // show/hide rules
128
        gridRulerPanel.addComponent(chkShowRules =
129
            new JCheckBox(PluginServices.getText(this, "activar_regla")), lastInsets);
130
        
131
        addComponent(gridRulerPanel, topInsets);
132
        
133
        GridBagLayoutPanel behaviourPanel = new GridBagLayoutPanel();
134
        behaviourPanel.setBorder(BorderFactory.createTitledBorder(Messages.getText("User_interface")));
135
        
136
        behaviourPanel.addComponent(
137
        		chkShowInitialPageConfig = new JCheckBox(Messages.getText("Show_page_config_dialog_when_layout_document_is_created")),
138
        		insets);
139
        
140
        behaviourPanel.addComponent(
141
        		chkShowLayoutTOC = new JCheckBox(Messages.getText("Show_table_of_contents_TOC_for_Layout_views")),
142
        		insets);
143
        
144
        addComponent(behaviourPanel, lastInsets);
145

  
146
    }
147

  
148
    public void storeValues() throws StoreException {
149
        double hGap, vGap;
150
        boolean gridEnabled, showRules, showGrid, showInitPageConfig,
151
        	showLayoutToc;
152
        String hGapUnits, vGapUnits;
153
        try {
154
            hGap = Double.parseDouble(txtHGap.getText());
155
            hGapUnits = MapContext.getDistanceAbbr()[cbHGapUnit.getSelectedIndex()];
156
            vGap = Double.parseDouble(txtVGap.getText());
157
            vGapUnits = MapContext.getDistanceAbbr()[cbVGapUnit.getSelectedIndex()];
158
            gridEnabled = chkGridEnabled.isSelected();
159
            showGrid = chkShowGrid.isSelected();
160
            showRules = chkShowRules.isSelected();
161
            showInitPageConfig = chkShowInitialPageConfig.isSelected();
162
            showLayoutToc = chkShowLayoutTOC.isSelected();
163
        } catch (Exception e) {
164
            throw new StoreException(PluginServices.getText(this,
165
                "invalid_value_for_gap"));
166
        }
167
        layoutManager.setDefaultShowGrid(showGrid);
168
        layoutManager.setDefaultAdjustToGrid(gridEnabled);
169
        layoutManager.setDefaultShowRulers(showRules);
170
        Attributes.setDefaultGridGap(hGap, vGap, hGapUnits, vGapUnits);
171
        PluginServices ps = PluginsLocator.getManager().getPlugin(this);
172
		XMLEntity xml = ps.getPersistentXML();
173
        xml.putProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME, hGap);
174
        xml.putProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME, vGap);
175
        xml.putProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_UNITS_KEY_NAME, hGapUnits);
176
        xml.putProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_UNITS_KEY_NAME, vGapUnits);
177
        xml.putProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME, showGrid);
178
        xml.putProperty(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME, gridEnabled);
179
        xml.putProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME, showRules);
180
        xml.putProperty(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME, showInitPageConfig);
181
        xml.putProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME, showLayoutToc);
182
    }
183

  
184
    public String getID() {
185
        return id;
186
    }
187

  
188
    public String getTitle() {
189
        return PluginServices.getText(this, "Mapa");
190
    }
191

  
192
    public JPanel getPanel() {
193
        return this;
194
    }
195

  
196
    public void initializeValues() {
197
    	PluginServices ps = PluginsLocator.getManager().getPlugin(this);
198
		XMLEntity xml = ps.getPersistentXML();
199
        double hGap = PreferenceKeys.FACTORY_DEFAULT_HORIZONTAL_GAP;
200
        double vGap = PreferenceKeys.FACTORY_DEFAULT_VERTICAL_GAP;
201
        boolean showGrid = PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_SHOW;
202
        boolean gridEnabled = PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_ENABLE;
203
        boolean showRules = PreferenceKeys.FACTORY_DEFAULT_LAYOUT_ENABLE_RULERS;
204
        boolean showInitPageConfig = PreferenceKeys.FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT;
205
        boolean showLayoutToc = PreferenceKeys.FACTORY_DEFAULT_SHOW_LAYOUT_TOC;
206
        // horizontal gap
207
        if (xml.contains(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME)) {
208
            hGap =
209
                xml.getDoubleProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME);
210
        }
211
        txtHGap.setText(String.valueOf(hGap));
212

  
213
        // vertical gap
214
        if (xml.contains(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME)) {
215
            vGap =
216
                xml.getDoubleProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME);
217
        }
218
        txtVGap.setText(String.valueOf(vGap));
219
        
220
        String hGapUnit = xml.contains(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_UNITS_KEY_NAME)?
221
        		xml.getStringProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_UNITS_KEY_NAME):
222
        			PreferenceKeys.FACTORY_DEFAULT_HORIZONTAL_GAP_UNIT;
223
        cbHGapUnit.setSelectedIndex(Attributes.getDistanceAbbrPosition(hGapUnit));
224
        
225
        String vGapUnit = xml.contains(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_UNITS_KEY_NAME)?
226
                		xml.getStringProperty(PreferenceKeys.DEFAULT_LAYOUT_GRID_VERTICAL_GAP_UNITS_KEY_NAME):
227
                			PreferenceKeys.FACTORY_DEFAULT_VERTICAL_GAP_UNIT;
228
        cbVGapUnit.setSelectedIndex(Attributes.getDistanceAbbrPosition(vGapUnit));
229

  
230
        // show/hide grid check
231
        if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) {
232
            showGrid =
233
                xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME);
234
        }
235
        chkShowGrid.setSelected(showGrid);
236

  
237
        // enable/disable grid check
238
        if (xml.contains(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) {
239
            gridEnabled =
240
                xml.getBooleanProperty(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME);
241
        }
242
        chkGridEnabled.setSelected(gridEnabled);
243

  
244
        // enable/disable rules
245
        if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME)) {
246
            showRules =
247
                xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME);
248
        }
249
        chkShowRules.setSelected(showRules);
250
        
251
        if (xml.contains(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME)) {
252
        	showInitPageConfig = xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME);
253
        }
254
        chkShowInitialPageConfig.setSelected(showInitPageConfig);
255
        
256
        if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME)) {
257
        	showLayoutToc = xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME);
258
        }
259
        chkShowLayoutTOC.setSelected(showLayoutToc);
260

  
261
        layoutManager.setDefaultShowGrid(showGrid);
262
        layoutManager.setDefaultAdjustToGrid(gridEnabled);
263
        layoutManager.setDefaultShowRulers(showRules);
264
        Attributes.setDefaultGridGap(hGap, vGap, hGapUnit, vGapUnit);
265
    }
266

  
267
    public void initializeDefaults() {
268
        txtHGap.setText(String.valueOf(PreferenceKeys.FACTORY_DEFAULT_HORIZONTAL_GAP));
269
        txtVGap.setText(String.valueOf(PreferenceKeys.FACTORY_DEFAULT_VERTICAL_GAP));
270
        cbHGapUnit.setSelectedIndex(Attributes.getDistanceAbbrPosition(PreferenceKeys.FACTORY_DEFAULT_HORIZONTAL_GAP_UNIT));
271
        cbVGapUnit.setSelectedIndex(Attributes.getDistanceAbbrPosition(PreferenceKeys.FACTORY_DEFAULT_VERTICAL_GAP_UNIT));
272
        chkShowGrid.setSelected(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_SHOW);
273
        chkGridEnabled.setSelected(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_ENABLE);
274
        chkShowRules.setSelected(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_ENABLE_RULERS);
275
        chkShowInitialPageConfig.setSelected(PreferenceKeys.FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT);
276
    }
277

  
278
    public ImageIcon getIcon() {
279
        return icon;
280
    }
281

  
282
    public boolean isValueChanged() {
283
        return super.hasChanged();
284
    }
285

  
286
    public void setChangesApplied() {
287
        setChanged(false);
288
    }
289
}
tags/org.gvsig.app.document.layout2.app-2.0.38/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/gui/preferencespage/PreferenceKeys.java
1
package org.gvsig.app.gui.preferencespage;
2

  
3
/**
4
 * The purpose of this interface is to define the keys used for the
5
 * persistence of this plugin in order to make these keys available
6
 * on library level, instead of defining them within the
7
 * preference page (which has UI dependences).
8
 * 
9
 * @author Cesar Martinez Izquierdo <cesar.izq@gmail.com>
10
 *
11
 */
12
public interface PreferenceKeys {
13
    String DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME = "DefaultShowLayoutGrid";
14
    String DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME = "DefaultEnableLayoutGrid";
15
    String DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME = "DefaultShowLayoutRules";
16
    String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_KEY_NAME = "DefaultGridVerticalGap";
17
    String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_KEY_NAME = "DefaultGridHorizontalGap";
18
    String DEFAULT_LAYOUT_GRID_VERTICAL_GAP_UNITS_KEY_NAME = "DefaultGridVerticalGapUnits";
19
    String DEFAULT_LAYOUT_GRID_HORIZONTAL_GAP_UNITS_KEY_NAME = "DefaultGridHorizontalGapUnits";
20
    String DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME = "DefaulShowInitialPageConfigLayout";
21
    String DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME = "DefaultShowLayoutToc";
22
    boolean FACTORY_DEFAULT_LAYOUT_ENABLE_RULERS = true;
23
    boolean FACTORY_DEFAULT_LAYOUT_GRID_SHOW = true;
24
    double FACTORY_DEFAULT_VERTICAL_GAP = 1.0d;
25
    double FACTORY_DEFAULT_HORIZONTAL_GAP = 1.0d;
26
    String FACTORY_DEFAULT_VERTICAL_GAP_UNIT = "cm";
27
    String FACTORY_DEFAULT_HORIZONTAL_GAP_UNIT = "cm";
28
    boolean FACTORY_DEFAULT_LAYOUT_GRID_ENABLE = false;
29
    boolean FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT = true;
30
    boolean FACTORY_DEFAULT_SHOW_LAYOUT_TOC = true;
31

  
32
}
0 33

  
tags/org.gvsig.app.document.layout2.app-2.0.38/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.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.fframes;
23

  
24
import java.awt.BasicStroke;
25
import java.awt.Color;
26
import java.awt.Dimension;
27
import java.awt.Font;
28
import java.awt.Graphics2D;
29
import java.awt.Point;
30
import java.awt.Rectangle;
31
import java.awt.geom.AffineTransform;
32
import java.awt.geom.Area;
33
import java.awt.geom.NoninvertibleTransformException;
34
import java.awt.geom.Point2D;
35
import java.awt.geom.Rectangle2D;
36
import java.awt.image.BufferedImage;
37

  
38
import org.cresques.cts.IProjection;
39
import org.gvsig.andami.PluginServices;
40
import org.gvsig.andami.messages.NotificationManager;
41
import org.gvsig.andami.ui.mdiFrame.NewStatusBar;
42
import org.gvsig.app.project.Project;
43
import org.gvsig.app.project.ProjectManager;
44
import org.gvsig.app.project.documents.Document;
45
import org.gvsig.app.project.documents.layout.DefaultLayoutNotification;
46
import org.gvsig.app.project.documents.layout.FLayoutFunctions;
47
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
48
import org.gvsig.app.project.documents.layout.LayoutNotification;
49
import org.gvsig.app.project.documents.layout.TocModelChangedNotification;
50
import org.gvsig.app.project.documents.view.ViewDocument;
51
import org.gvsig.compat.print.PrintAttributes;
52
import org.gvsig.fmap.dal.exception.ReadException;
53
import org.gvsig.fmap.geom.Geometry;
54
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
55
import org.gvsig.fmap.geom.GeometryLocator;
56
import org.gvsig.fmap.geom.GeometryManager;
57
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
58
import org.gvsig.fmap.geom.primitive.Envelope;
59
import org.gvsig.fmap.mapcontext.MapContext;
60
import org.gvsig.fmap.mapcontext.MapContextException;
61
import org.gvsig.fmap.mapcontext.ViewPort;
62
import org.gvsig.fmap.mapcontext.events.AtomicEvent;
63
import org.gvsig.fmap.mapcontext.events.ColorEvent;
64
import org.gvsig.fmap.mapcontext.events.ExtentEvent;
65
import org.gvsig.fmap.mapcontext.events.FMapEvent;
66
import org.gvsig.fmap.mapcontext.events.ProjectionEvent;
67
import org.gvsig.fmap.mapcontext.events.listeners.AtomicEventListener;
68
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener;
69
import org.gvsig.fmap.mapcontext.layers.CancelationException;
70
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
71
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener;
72
import org.gvsig.fmap.mapcontext.layers.LayerEvent;
73
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent;
74
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
75
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener;
76
import org.gvsig.gui.beans.Messages;
77
import org.gvsig.tools.ToolsLocator;
78
import org.gvsig.tools.dynobject.DynStruct;
79
import org.gvsig.tools.locator.LocatorException;
80
import org.gvsig.tools.persistence.PersistenceManager;
81
import org.gvsig.tools.persistence.PersistentState;
82
import org.gvsig.tools.persistence.exception.PersistenceException;
83
import org.slf4j.Logger;
84
import org.slf4j.LoggerFactory;
85

  
86
/**
87
 * FFrame used for embedding a View in the Layout. The View is not actually
88
 * inserted on the Layout, but it is used together with the MapContext
89
 * in order do draw an image which is then painted on the FFrame. Therefore,
90
 * no MapControl is used in current implementation, but a similar behavior
91
 * is simulated by the FFrameView. The original MapContext is cloned when
92
 * assigned to the FFrameView, which is then used for drawing.
93
 * 
94
 * The FFrameView and the associated View can be synchronized, depending
95
 * on the values of {@link #getTypeScale()} and {@link #getLinked()}.
96
 * 
97
 * The main synchronization logic is kept on two internal classes: 
98
 * {@link OwnMapContextListener} and {@link ViewDocListener}. The first one
99
 * listens for events on the FFrameView and synchronizes the View accordingly.
100
 * The second one listens for events on the View and synchronizes the FFrameView
101
 * accordingly. There synchronization process is flagged using
102
 * {@link #b_updating} and {@link #b_updating}, in order
103
 * to avoid incurring on infinite synchronization loops. 
104
 * 
105
 * @author Vicente Caballero Navarro
106
 * @author Cesar Martinez Izquierdo
107
 */
108
public class FFrameView extends FFrame implements IFFrameUseProject, IFFrameUseFMap {
109

  
110
    public static final String PERSISTENCE_DEFINITION_NAME = "FFrameView";
111

  
112
    private static final String QUALITY_FIELD = "quality";
113
    private static final String MAPUNITS_FIELD = "mapUnits";
114
    private static final String SCALE_FIELD = "scale";
115
    private static final String VIEW_FIELD = "view";
116
    private static final String ENVELOPE_FIELD = "envelope";
117
    private static final String SHOWGRID_FIELD = "showGrid";
118
    private static final String GRID_FIELD = "gridview";
119
    private static final String HAS_TOC_FIELD = "hasToc";
120
    private static final String LAYER_SYNC_FIELD = "layerSync";
121
    private static final String EXTENT_SYNC_FIELD = "extentSync";
122
    private static final String SCALE_TYPE_FIELD = "scaleType";
123
    // following fields are unused - they are kept for backward-compatibility 
124
    private static final String EXTENSION_FIELD = "extension";
125
    private static final String BLINKED_FIELD = "bLinked";
126
    private static final String MODE_FIELD = "mode";
127
    private static final String TYPESCALE_FIELD = "typeScale";
128
    private static final String MAPCONTEXT_FIELD = "mapContext";
129
    private static final String VIEWING_FIELD = "viewing";
130

  
131
    private static final Logger logger = LoggerFactory
132
        .getLogger(FFrameView.class);
133
    public static final int PRESENTATION = 0;
134
    public static final int DRAFT = 1;
135

  
136
    protected boolean syncLayers = true;
137
    protected boolean syncExtents = true;
138
    protected int quality = PRESENTATION;
139
    protected ViewDocument viewDocument = null;
140
    protected MapContext mapContext = null;
141
    protected int mapUnits = 1; // Meters.
142

  
143
    protected BufferedImage m_image = null;
144
    protected AffineTransform mapAT = null;
145
    protected Project project = null;
146
    protected double scaleAnt;
147
    protected Point origin;
148
    protected Point2D p1;
149
    protected Point2D p2;
150
    protected IFFrame grid;
151
    protected boolean showGrid = false;
152

  
153
	private boolean b_updating = false;
154
	protected boolean b_validCache = false;
155
	protected boolean b_drawing = false;
156
	protected ViewDocListener viewDocListener;
157
	protected OwnMapContextListener ownMapContextListener;
158
	private boolean b_hasToc = true;
159
    protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
160
    protected Envelope oldViewEnvelope = null;
161

  
162
	/**
163
	 * When we load a FFrameview from project, it will receive a wrong
164
	 * extentChanged event the first time the View is painted, so we must
165
	 * ignore this first event. 
166
	 */
167
	private boolean b_frameInitialized = true;
168

  
169
	protected AffineTransform originalGraphicsAT = null;
170
	protected Rectangle originalClip = null;
171

  
172
	private SCALE_TYPE scaleType = SCALE_TYPE.NORMAL;
173
	private Double fixedScale = null;
174
	private Envelope fixedExtent = null;
175

  
176

  
177
    /**
178
     * Creates a new FFrameView object.
179
     */
180
    public FFrameView() {
181
        num++;
182
        createListeners();
183
    }
184
    
185
    protected void createListeners() {
186
    	viewDocListener = new ViewDocListener();
187
    	ownMapContextListener = new OwnMapContextListener();
188
    }
189

  
190
    /**
191
     * Returns a description of the FFrame
192
     * 
193
     * @return Description.
194
     */
195
    public String toString() {
196
        if (getView() == null) {
197
            return "FFrameView " + num + ": " + "Vacio";
198
        }
199

  
200
        return "FFrameView " + num + ": " + getView().getName();
201
    }
202

  
203
    /**
204
     * Sets the scale of the MapContext contained in this FFrameView
205
     * 
206
     * @param d Scale to be set
207
     */
208
    public void setScale(double d) {
209
    	if (getMapContext()!=null) {
210
    		getMapContext().setScaleView((long) d);
211
    	}
212
    }
213

  
214
    /**
215
     * Sets a new Envelope on the MapContext contained in
216
     * this FFrameView
217
     * 
218
     * @param r Envelope to be set
219
     */
220
    public void setNewEnvelope(Envelope r) {
221
    	if (getView()!=null) {
222
    		oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope();
223
    	}
224
    	getMapContext().getViewPort().setEnvelope(r);
225
    	updateScaleCtrl();
226
    }
227
    
228
    /**
229
     * Calculates the resolution (measured on dots per inch, DPI) to be
230
     * considered to draw the FFrameView on screen. It is calculated by
231
     * dividing the width (in pixels) of the FFrame divided by the width
232
     * in inches of the paper.
233
     */
234
    protected double getDrawPaperDPI() {
235
    	AffineTransform at = null;
236
    	if (getLayoutContext()!=null) {
237
    		at = getLayoutContext().getAT();
238
    	}
239
    	return (2.54*getBoundingBox(at).width)/getBoundBox().width;	
240
    }
241

  
242
    /**
243
     * Returns the MapContext contained in this FFrameView, which is
244
     * usually a clone of the associated View. This MapContext
245
     * may be synchronized with the View one, depending on the
246
     * scale type that has been set (see {{@link #getTypeScale()}.
247
     * 
248
     * @return The mapContext object
249
     */
250
    public MapContext getMapContext() {
251
        return mapContext;
252
    }
253

  
254
    /**
255
     * Sets the quality of the visualization of the FFrame on screen.
256
     * Valid values include {@link #DRAFT} and {@link #PRESENTATION}.
257
     * Draft will disable the frame normal drawing, which will be
258
     * replaced by an empty rectangle only showing the name of the
259
     * frame.  
260
     * 
261
     * @param q Integer representing the quality.
262
     */
263
    public void setQuality(int q) {
264
        quality = q;
265
    }
266

  
267
    /**
268
     * Gets the quality of the visualization of the FFrame on screen.
269
     * Valid values include {@link #DRAFT} and {@link #PRESENTATION}.
270
     * Draft will disable the frame normal drawing, which will be
271
     * replaced by an empty rectangle only showing the name of the
272
     * frame.  
273
     * 
274
     * @param q The selected quality
275
     */
276
    public int getQuality() {
277
        return quality;
278
    }
279

  
280
    /**
281
     * Sets the MapContext associated with this FFrameView, which will
282
     * be used to clone the layers and synchronize the FFrameView with
283
     * the associated View 
284
     * 
285
     * @param viewMapContext
286
     */
287
    public void setViewMapContext(MapContext viewMapContext) {
288
    	if (mapContext!=null) {
289
    		clearOwnListeners(mapContext);
290
    	}
291
    	try {
292
    		if (syncLayers){
293
    			mapContext =
294
    					viewMapContext.createNewFMap(
295
    							(ViewPort) viewMapContext.getViewPort().clone());
296
    		}
297
    		else {
298
    			mapContext = viewMapContext.cloneFMap();
299
    			mapContext.setViewPort((ViewPort) viewMapContext
300
    					.getViewPort().clone());
301
    		}
302
    		ViewPort newViewPort = getMapContext().getViewPort();
303
    		if (!syncExtents && oldViewEnvelope!=null) {
304
    			// if extent is not synced with the view, restore the previous
305
    			// envelope if existing
306
    			newViewPort.setEnvelope(oldViewEnvelope);
307
    		}
308
    		AffineTransform at;
309
    		if (getLayoutContext()!=null) {
310
    			at = getLayoutContext().getAT();
311
    		}
312
    		else {
313
    			at = null;
314
    		}
315
    		newViewPort.setImageSize(new Dimension((int) getBoundingBox(at).width,
316
    				(int) getBoundingBox(at).height));
317
    		newViewPort.setDPI(getDrawPaperDPI());
318
    		setListeners();
319
    		updateScaleCtrl();
320
    		setTocModel();
321
    	} catch (CloneNotSupportedException e1) {
322
    		NotificationManager.addError("Excepci?n :", e1);
323
    	}
324

  
325
    }
326

  
327
    /**
328
     * Sets the View associated with this FFrameView, which will
329
     * be used to clone the MapContext and the layers. It will
330
     * also used to synchronize the FFrameView with
331
     * the associated View, depending on the selected scle type 
332
     * 
333
     * @param viewMapContext
334
     */
335
    public void setView(ViewDocument dvd) {
336
    	ViewDocument oldDoc = viewDocument;
337
    	if (oldDoc!=null) {
338
    		if (oldDoc!=dvd) {
339
    			// Remove the oldEnvelope if the view has changed
340
    			oldViewEnvelope = null;
341
    		}
342
    		else {
343
    			if (getMapContext()!=null && getMapContext().getViewPort()!=null) {
344
    				oldViewEnvelope = getMapContext().getViewPort().getAdjustedEnvelope();
345
    			}
346
    		}
347
    		if (oldDoc.getMapContext()!=null) {
348
    			clearViewListeners(oldDoc.getMapContext());
349
    		}
350
    	}
351
        viewDocument = dvd;
352
        if (dvd!=null) {
353
            setViewMapContext(dvd.getMapContext());
354
        }
355
    }
356

  
357
    /**
358
     * Gets the associated View
359
     * 
360
     * @return The associated view
361
     * @see {@link #setView(ViewDocument)}
362
     */
363
    public ViewDocument getView() {
364
        return viewDocument;
365
    }
366

  
367
    /**
368
     * Draws the FFrameView on the provided Graphics, according to the
369
     * provided affine transform and the visible rectangle.
370
     * 
371
     * @param g Graphics2D
372
     * @param at Affine transform to translate sheet coordinates (in cm)
373
     * 				to screen coordinates (in pixels)
374
     * @param visibleLayoutDocRect visible rectangle
375
     * @param imgBase Image used to speed up the drawing process
376
     */
377
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D visibleLayoutDocRect, BufferedImage imgBase) {
378
        Rectangle2D.Double fframeViewRect = getBoundingBox(at);
379
        Rectangle2D.Double visibleArea = (Rectangle2D.Double) getVisibleRect(visibleLayoutDocRect, fframeViewRect);
380
        if (visibleArea==null) {
381
        	return;
382
        }
383
        preDraw(g, fframeViewRect, visibleArea);
384
        if (getMapContext() == null) {
385
        	drawEmpty(g);
386
        } else {
387
        	if (FLayoutUtilities.hasEditingLayers(getView())) {
388

  
389
        		/*
390
        		 * We are not drawing if any layer is in editing mode
391
        		 */
392
        		drawMessage(g, Messages.getText(
393
        				"_Cannot_draw_view_if_layers_in_editing_mode"));
394

  
395
        	} else {
396
        		if (getQuality() == PRESENTATION) {
397
        			try {
398
        				drawPresentation(g, at, fframeViewRect, visibleArea, imgBase);
399
        			} catch (Exception exc) {
400
        				drawMessage(g, FLayoutFunctions.getLastMessage(exc));
401
        			}
402

  
403
        		} else {
404
        			drawDraft(g);
405
        		}               
406
        	}
407
        	updateScaleCtrl(); // we need to update the scale whenever the window gets activated
408
        }
409
        postDraw(g, fframeViewRect, at); 
410
        if (showGrid && grid != null) {           
411
            grid.draw(g, at, visibleLayoutDocRect, imgBase);
412
        }    
413
    }
414
    
415
    private void drawMessage(Graphics2D g, String msg) {
416
        
417
        Rectangle2D r = getBoundingBox(null);
418
        g.setColor(Color.lightGray);
419
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
420
            (int) r.getHeight());
421
        g.setColor(Color.darkGray);
422
        g.setStroke(new BasicStroke(2));
423
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
424
            (int) r.getHeight());
425
        g.setColor(Color.black);
426

  
427
        int scale = (int) (r.getWidth() / 24);
428
        Font f = new Font("SansSerif", Font.PLAIN, scale);
429
        g.setFont(f);
430
        if (msg==null) {
431
        	msg = Messages.getText("error");
432
        }
433
        g.drawString(msg, (int) (r.getCenterX() - ((msg.length() * scale) / 4)),
434
        		(int) (r.getCenterY()));
435
    }
436

  
437
    /**
438
     * Gets the visible envelope, in map coordinates
439
     * 
440
     * @param fframeViewRect Rectangle defining the bounding box of the
441
     * FFrameView, in screen coordinates
442
     * @param visiblefframeViewRect Rectangle defining the bounding box
443
     * of the visible area of the fframeView, in screen coordinates
444
     * @return
445
     */
446
    protected Envelope getVisibleEnvelope(Rectangle2D.Double fframeViewRect,
447
            Rectangle2D.Double visiblefframeViewRect) {
448
    	Envelope oldEnv = getMapContext().getViewPort().getAdjustedEnvelope();
449
    	double widthFactor = ((int)visiblefframeViewRect.width) / fframeViewRect.width;
450
    	double heightFactor = ((int)visiblefframeViewRect.height) / fframeViewRect.height;
451
    	
452
    	double newWidth = oldEnv.getLength(0)*widthFactor;
453
    	double newHeight = oldEnv.getLength(1)*heightFactor;
454
        
455
        double translateX = visiblefframeViewRect.x - fframeViewRect.x;
456
        double translateY = visiblefframeViewRect.y - fframeViewRect.y;
457
        double translateFactorX = translateX / fframeViewRect.width;
458
        double translateFactorY = translateY / fframeViewRect.height;
459
        
460
        double newX = oldEnv.getMinimum(0) + translateFactorX*oldEnv.getLength(0);
461
        double newMaxY =  oldEnv.getMaximum(1) - translateFactorY*oldEnv.getLength(1);
462
        double newMaxX = newX + newWidth;
463
        double newY = newMaxY - newHeight;
464

  
465
        Envelope newEnv = null;
466
		try {
467
			newEnv = geomManager.createEnvelope(newX, newY, newMaxX, newMaxY, SUBTYPES.GEOM2D);
468
		} catch (CreateEnvelopeException e) {
469
			logger.error("Error calculating visible extent", e);
470
		}
471
        return newEnv;
472
            	
473
    }
474
    
475
    protected void drawPresentation(
476
        Graphics2D g,
477
        AffineTransform affineTransform,
478
        Rectangle2D.Double fframeViewRect,
479
        Rectangle2D.Double visibleRect,
480
        BufferedImage imgBase) throws Exception {
481
    	
482
    	b_drawing = true;
483
    	int drawWidth = (int)visibleRect.width;
484
    	int drawHeight = (int)visibleRect.height;
485

  
486
    	Envelope oldEnvelope = null;
487
        if (!visibleRect.equals(fframeViewRect)) {
488
        	// if visible area is smaller than the fframe, we will only draw this area,
489
        	// so we need to tell the ViewPort the image size and extent for drawing,
490
        	// and restore the real extent after drawing
491
            oldEnvelope = getMapContext().getViewPort().getEnvelope();
492
            if (oldEnvelope==null) {
493
            	return;
494
            }
495
        	Envelope newEnvelope = getVisibleEnvelope(fframeViewRect, visibleRect);
496
        	// image size must be set before the envelope, as it has influence on the adjustedExtent
497
        	getMapContext().getViewPort().setImageSize(new Dimension(drawWidth, drawHeight));
498
        	getMapContext().getViewPort().setEnvelope(newEnvelope);
499
        }
500
        else {
501
        	getMapContext().getViewPort().setImageSize(new Dimension(drawWidth, drawHeight));
502
        	getMapContext().getViewPort().refreshExtent();
503
        }
504
        
505
        // map origin should be calculated using the full fframeview, as the visible position will be relative
506
        Point mapOrigin = new Point((int)fframeViewRect.getMinX(), (int)fframeViewRect.getMaxY());
507

  
508
        // paint the MapContext on m_image, if not already cached
509
        createImage(affineTransform, drawWidth, drawHeight, mapOrigin);
510

  
511
        //Draw the created image
512
        drawImage(g, m_image, visibleRect);
513
        
514
        if (oldEnvelope!=null) {
515
        	// restore real envelope and image size
516
        	getMapContext().getViewPort().setImageSize(new Dimension((int)fframeViewRect.width, (int) fframeViewRect.height));
517
        	getMapContext().getViewPort().setEnvelope(oldEnvelope);
518
        }
519
        
520
        scaleAnt = affineTransform.getScaleX();
521
        origin = mapOrigin;
522
        b_drawing = false;
523
    }
524
    
525
    protected void createImage(AffineTransform affineTransform,
526
    		int width, int height, Point mapOrigin) throws ReadException, MapContextException {
527
    	ViewPort viewPort = this.getMapContext().getViewPort();
528

  
529
        //If the image has to be created...
530
    	if (origin == null ||
531
    			!origin.equals(mapOrigin) ||
532
    			affineTransform.getScaleX() != scaleAnt ||
533
    			m_image == null ||
534
    			!b_validCache) { 
535

  
536
    		viewPort.setDPI(getDrawPaperDPI());
537
        	viewPort.setImageSize(new Dimension(width, height)); 
538
            
539
            m_image =
540
                    new BufferedImage(
541
                    		width,
542
                    		height,
543
                    		BufferedImage.TYPE_INT_ARGB);
544

  
545
            Graphics2D gimg = (Graphics2D) m_image.createGraphics();
546
            getMapContext().draw(m_image, gimg, getScale());
547
            gimg.dispose();
548
            b_validCache = true;
549
        } 
550

  
551
    }
552
    
553
    protected void drawImage(Graphics2D g, BufferedImage image,
554
    		Rectangle2D.Double visibleRectangle) {
555

  
556
    	Color theBackColor = getMapContext().getViewPort().getBackColor();
557
        if (theBackColor != null) {
558
            g.setColor(theBackColor);
559
            g.fillRect((int) visibleRectangle.x, (int) visibleRectangle.y,
560
            		(int)visibleRectangle.width,
561
            		(int)visibleRectangle.height);
562
        }
563
        g.drawImage(m_image, 
564
        		(int) visibleRectangle.x,
565
        		(int) visibleRectangle.y,
566
        		null);    	
567
    }
568

  
569
    protected void preDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, Rectangle2D.Double visibleRect){
570
    	originalGraphicsAT = (AffineTransform) g.getTransform().clone();
571
    	
572
        if (g.getClipBounds() != null) {
573
            originalClip = (Rectangle) g.getClipBounds().clone();
574
        }
575
        AffineTransform rotationAT = getRotationAT();
576
        if (rotationAT!=null) {
577
        	g.transform(rotationAT);
578
        }
579
        g.setClip((int) visibleRect.getMinX(), (int) visibleRect.getMinY(),
580
            (int) visibleRect.getWidth(), (int) visibleRect.getHeight());
581
    }
582
    
583
    protected void postDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, AffineTransform at){
584
    	g.setTransform(originalGraphicsAT);
585
        if (getMapContext() != null) {
586
            setATMap(getMapContext().getViewPort().getAffineTransform());
587
        }
588
        if (originalClip != null) {
589
            g.setClip(originalClip.x, originalClip.y, originalClip.width, originalClip.height);
590
        }            
591
    }
592

  
593
    public void print(Graphics2D g, AffineTransform at, Geometry geom,
594
        PrintAttributes printAttributes) {
595
        Rectangle2D.Double rectangleLayout = getBoundingBox(at);  
596
        
597
        preDraw(g, rectangleLayout, rectangleLayout);
598
        print(g, at, printAttributes);
599
        postDraw(g, rectangleLayout, at);
600
        if (showGrid && grid != null) {
601
            grid.print(g, at, geom, printAttributes);
602
        }    
603
    }
604

  
605
    protected void print(Graphics2D g, AffineTransform at, PrintAttributes printAttributes) {
606
        Rectangle2D.Double layoutRectangle = getBoundingBox(at);
607
        
608
        // FIXME: should we clone the mapcontext and viewport before printing ??
609
        // otherwise we will probably have unexpected results if the user modifies
610
        // the layout while printing
611
        ViewPort viewPort = this.getMapContext().getViewPort();
612
        
613
        Point2D old_offset = viewPort.getOffset();
614
        Dimension old_imgsize = viewPort.getImageSize();
615
        
616
        viewPort.setOffset(new Point2D.Double(layoutRectangle.x, layoutRectangle.y));
617
        viewPort.setImageSize(new Dimension((int) layoutRectangle.width, (int) layoutRectangle.height));
618

  
619
        //Draw the backgroung color of the map
620
        Color theBackColor = viewPort.getBackColor();
621
        if (theBackColor != null) {
622
            g.setColor(theBackColor);
623
            g.fillRect((int) layoutRectangle.x, (int) layoutRectangle.y, viewPort
624
                    .getImageWidth(), viewPort
625
                    .getImageHeight());
626
        }        
627
        
628
        //Print the map
629
        try {
630
            this.getMapContext().print(g, getScale(), printAttributes);
631
        } catch (ReadException e) {
632
            NotificationManager.addError(e.getMessage(), e);
633
        } catch (MapContextException e) {
634
            NotificationManager.addError(e.getMessage(), e);
635
        }      
636
        
637
        // Restore offset, imgsize
638
        viewPort.setOffset(old_offset);
639
        viewPort.setImageSize(old_imgsize);
640
    }
641

  
642
    /**
643
     * Rellena la unidad de medida en la que est? la vista.
644
     * 
645
     * @param i
646
     *            entero que representa la unidad de medida de la vista.
647
     */
648
    public void setMapUnits(int i) {
649
        mapUnits = i;
650
    }
651

  
652
    /**
653
     * Obtiene la unidad de medida en la que est? la vista.
654
     * 
655
     * @return Unidad de medida.
656
     */
657
    public int getMapUnits() {
658
        return mapUnits;
659
    }
660

  
661
    /**
662
     * Devuelve la escala seg?n el tipo de escala que se haya seleccionado al
663
     * a?adida la vista.
664
     * 
665
     * @return escala.
666
     */
667
    public long getScale() {
668
    	return (long) getMapContext().getScaleView();
669
    }
670

  
671
    /**
672
     * Inserta la imagen para repintar el FFrameView.
673
     * 
674
     * @param bi
675
     *            Imagen para repintar.
676
     */
677
    public void setBufferedImage(BufferedImage bi) {
678
        m_image = bi;
679
    }
680

  
681
    /**
682
     * Devuelve la imagen para repintar.
683
     * 
684
     * @return Imagen para repintar.
685
     */
686
    public BufferedImage getBufferedImage() {
687
        return m_image;
688
    }
689

  
690
    /**
691
     * Devuelve la MAtriz de transformaci?n utilizada por la FFrameView.
692
     * 
693
     * @return MAtriz de transformaci?n.
694
     */
695
    public AffineTransform getATMap() {
696
        return mapAT;
697
    }
698

  
699
    /**
700
     * Inserta la matriz de transformaci?n.
701
     * 
702
     * @param transform
703
     *            Matriz de transformaci?n.
704
     */
705
    public void setATMap(AffineTransform transform) {
706
        mapAT = transform;
707
    }
708

  
709
    /**
710
     * Inserta el proyecto.
711
     * 
712
     * @param p
713
     *            Proyecto.
714
     */
715
    public void setProject(Project p) {
716
        project = p;
717
    }
718

  
719
    /**
720
     * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#getNameFFrame()
721
     */
722
    public String getNameFFrame() {
723
        return PluginServices.getText(this, "Vista") + num;
724
    }
725

  
726
    public String getName() {
727
        return PERSISTENCE_DEFINITION_NAME;
728
    }
729

  
730
    /**
731
     * DOCUMENT ME!
732
     * 
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff