Revision 684

View differences:

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

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

  
10
    <parent>
11
        <groupId>org.gvsig</groupId>
12
        <artifactId>org.gvsig.app.document.layout2.app</artifactId>
13
        <version>2.0.104</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
            <scope>compile</scope>
102
        </dependency>
103
        <dependency>
104
            <groupId>org.apache.xmlgraphics</groupId>
105
            <artifactId>batik-gvt</artifactId>
106
            <scope>compile</scope>
107
        </dependency>
108
        <dependency>
109
            <groupId>org.apache.xmlgraphics</groupId>
110
            <artifactId>batik-script</artifactId>
111
            <scope>compile</scope>
112
        </dependency>
113
        
114
        <!--
115
        <dependency>
116
            <groupId>org.gvsig</groupId>
117
            <artifactId>batik-ext-gvsig-custom</artifactId>
118
        </dependency>
119
        -->
120
        
121
        <dependency>
122
            <groupId>com.sun</groupId>
123
            <artifactId>jimi</artifactId>
124
            <scope>compile</scope>
125
        </dependency>
126
        <dependency>
127
            <groupId>org.gvsig</groupId>
128
            <artifactId>org.gvsig.i18n</artifactId>
129
            <scope>compile</scope>
130
        </dependency>
131

  
132
    </dependencies>
133

  
134
    <properties>
135
	<gvsig.package.info.name>Document: Layout document plugin, version 2</gvsig.package.info.name>
136
        <gvsig.package.info.dependencies>conflict: org.gvsig.app.document.layout1.app.mainplugin -ge 1, required: org.gvsig.app.mainplugin -ge 2.1.0</gvsig.package.info.dependencies>
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>final</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.104/org.gvsig.app.document.layout2.app.mainplugin/buildNumber.properties
1
#Thu Aug 10 19:53:17 CEST 2017
2
buildNumber=123
tags/org.gvsig.app.document.layout2.app-2.0.104/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.104/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.104/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.104/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/LayoutNotification.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

  
25

  
26
/**
27
 * @author gvSIG Team
28
 * @version $Id$
29
 *
30
 */
31
public interface LayoutNotification {
32
	/** Fired when the layout has to be invalidated */
33
    public static final String LAYOUT_INVALIDATED = "layout_invalidated";
34

  
35
    /** Fired when the layout doesn't have to be repainted */
36
    public static final String LAYOUT_VALIDATED = "layout_validated";
37
    
38

  
39
    /** Fired when the layout has to be invalidated and immediately repainted */
40
    public static final String LAYOUT_REFRESH = "layout_refresh";
41
	
42
    /**
43
     * Returns the type of this notification, represented by one of the constants defined in this interface.
44
     * @return a String containing this notification's type
45
     */
46
    public String getType();
47
}
tags/org.gvsig.app.document.layout2.app-2.0.104/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/Attributes.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2015 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.project.documents.layout;
25

  
26
import java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28
import java.awt.print.PageFormat;
29
import java.awt.print.Paper;
30
import java.text.NumberFormat;
31
import java.util.ArrayList;
32

  
33
import javax.print.attribute.DocAttributeSet;
34
import javax.print.attribute.HashDocAttributeSet;
35
import javax.print.attribute.HashPrintRequestAttributeSet;
36
import javax.print.attribute.PrintRequestAttributeSet;
37
import javax.print.attribute.standard.Copies;
38
import javax.print.attribute.standard.Fidelity;
39
import javax.print.attribute.standard.Media;
40
import javax.print.attribute.standard.MediaPrintableArea;
41
import javax.print.attribute.standard.MediaSizeName;
42
import javax.print.attribute.standard.OrientationRequested;
43
import javax.print.attribute.standard.PrintQuality;
44
import javax.print.attribute.standard.Sides;
45

  
46
import org.gvsig.andami.PluginServices;
47
import org.gvsig.andami.PluginsLocator;
48
import org.gvsig.app.extension.LayoutExtension;
49
import org.gvsig.app.gui.preferencespage.PreferenceKeys;
50
import org.gvsig.compat.CompatLocator;
51
import org.gvsig.compat.print.PrintAttributes;
52
import org.gvsig.fmap.mapcontext.MapContext;
53
import org.gvsig.i18n.Messages;
54
import org.gvsig.tools.ToolsLocator;
55
import org.gvsig.tools.dynobject.DynStruct;
56
import org.gvsig.tools.persistence.PersistenceManager;
57
import org.gvsig.tools.persistence.Persistent;
58
import org.gvsig.tools.persistence.PersistentState;
59
import org.gvsig.tools.persistence.exception.PersistenceException;
60
import org.gvsig.utils.XMLEntity;
61
import org.slf4j.Logger;
62
import org.slf4j.LoggerFactory;
63
import org.gvsig.app.project.documents.layout.Size;
64

  
65
/**
66
 * Attributes of Layout.
67
 * 
68
 * @author Vicente Caballero Navarro
69
 * @author jldominguez
70
 */
71
public class Attributes implements Persistent, Cloneable {
72

  
73
    public static final String PERSISTENCE_DEFINITION_NAME = "Attributes";
74
    public static final String DPI_FIELD = "DPI";
75
    public static final String DPISCREEN_FIELD = "DPISCREEN";
76
    public static final String TYPEUNIT_FIELD = "typeUnit";
77
    public static final String NUMX_FIELD = "numX";
78
    public static final String NUMY_FIELD = "numY";
79
    public static final String UNITX_FIELD = "unitX";
80
    public static final String UNITY_FIELD = "unitY";
81
    public static final String HASMARGIN_FIELD = "hasMargin";
82
    public static final String RESOLUTIONSEL_FIELD = "resolutionSel";
83
    public static final String TYPESEL_FIELD = "typeSel";
84
    public static final String SELTYPEUNIT_FIELD = "selTypeUnit";
85
    public static final String SIZEPAPER_FIELD = "sizePaper";
86
    public static final String AREA_FIELD = "area";
87
    public static final String SIZEINUNITS_FIELD = "sizeInUnits";
88
    public static final String ISLANDSEL_FIELD = "isLandSel";
89
    public static final String DEGREES = "Grados";
90
    public static final int HIGH = 0;
91
    public static final int NORMAL = 1;
92
    public static final int DRAFT = 2;
93

  
94
    // Para impresi?n
95
    public final static double PULGADA = 2.54;
96

  
97
    public final static Size STANDARD_LETTER_PAPER_SIZE = new Size(8.5, 11.0);
98
    public final static Size STANDARD_FOLIO_PAPER_SIZE = new Size(8.5, 13.0);
99
    public final static Size STANDARD_LEGAL_PAPER_SIZE = new Size(8.5, 14.0);
100
    public final static Size STANDARD_TABLOID_PAPER_SIZE = new Size(11.0, 17.0);
101
    public final static Size METRIC_A0_PAPER_SIZE = new Size(118.9, 84.1);
102
    public final static Size METRIC_A1_PAPER_SIZE = new Size(84.1, 59.4);
103
    public final static Size METRIC_A2_PAPER_SIZE = new Size(59.4, 42.0);
104
    public final static Size METRIC_A3_PAPER_SIZE = new Size(42.0, 29.7);
105
    public final static Size METRIC_A4_PAPER_SIZE = new Size(29.7, 21.0);
106
    public final static Size METRIC_A5_PAPER_SIZE = new Size(21.0, 14.8);
107
    public final static Size ANSI_ENG_A_PAPER_SIZE = new Size(11.0, 8.5);
108
    public final static Size ANSI_ENG_B_PAPER_SIZE = new Size(17.0, 11.0);
109
    public final static Size ANSI_ENG_C_PAPER_SIZE = new Size(22.0, 17.0);
110
    public final static Size ANSI_ENG_D_PAPER_SIZE = new Size(34.0, 22.0);
111
    public final static Size ANSI_ENG_E_PAPER_SIZE = new Size(44.0, 34.0);
112
    public final static Size ANSI_ARCH_A_PAPER_SIZE = new Size(12.0, 9.0);
113
    public final static Size ANSI_ARCH_B_PAPER_SIZE = new Size(18.0, 12.0);
114
    public final static Size ANSI_ARCH_C_PAPER_SIZE = new Size(24.0, 18.0);
115
    public final static Size ANSI_ARCH_D_PAPER_SIZE = new Size(36.0, 24.0);
116
    public final static Size ANSI_ARCH_E_PAPER_SIZE = new Size(42.0, 30.0);
117
    
118
    /**
119
     * Stores the last custom paper size. It will be equal to
120
     * {@link #getPaperSize()} when {@link #getType()} is
121
     * {@link #CUSTOM}.
122
     * CUSTOM_PAPER_SIZE knows about portrait/landscape
123
     * (same as other PAPER constants)
124
     */
125
    private Size last_custom_paper_size = new Size(100.0, 100.0);
126
    
127
    public final static int PRINT = 0;
128
    public final static int CUSTOM = 6;
129
    public final static int A0 = 5;
130
    public final static int A1 = 4;
131
    public final static int A2 = 3;
132
    public final static int A3 = 2;
133
    public final static int A4 = 1;
134
    public static int DPI = 300;
135
    public static int DPISCREEN = 72;
136
    private static Point2D defaultGridGap;
137

  
138
    private PrintRequestAttributeSet attributes =
139
        new HashPrintRequestAttributeSet();
140
    /**
141
     * Media size name, used when type is {@link #PRINT}.
142
     * @see #setType(int)
143
     */
144
    private MediaSizeName m_type = MediaSizeName.ISO_A4;
145
    private OrientationRequested m_Orientation;
146
    /**
147
     * Change factor from configured map unit (m_selTypeUnit) to centimeters
148
     */
149
    private double m_TypeUnit = getConversionFactorToCm(2); // [2] = Centimeters
150
    private String m_NameUnit;
151
    /**
152
     * Horizontal space between grid lines, measured in centimeters
153
     */
154
    private Double m_gridGapCmX = null;
155
    /**
156
     * Vertical space between grid lines, measured  in centimeters
157
     */
158
    private Double m_gridGapCmY = null;
159
    /**
160
     * Horizontal space between grid lines, measured in centimeters
161
     */
162
    private double m_gridGapPxX = 0;
163
    /**
164
     * Vertical space between grid lines, measured  in pixels
165
     */
166
    private double m_gridGapPxY = 0;
167
    private boolean hasmargin;
168
    private int m_resolutionSel = NORMAL;
169
    private int m_typeSel = PRINT;
170
    /**
171
     * The selected unit (km, cm, etc) for this layout. It defaults to centimeters
172
     * 
173
     * @see {@link MapContext#getDistanceNames()}
174
     * @see {@link MapContext#getDistanceTrans2Meter()}
175
     */
176
    private int m_selTypeUnit = 2;
177
    
178
    /**
179
     * Paper size in centimeters.
180
     * This field changes when it's landscape
181
     * (it "knows" about portrait/landscape)
182
     */
183
    private Size m_sizePaper = new Size(
184
        METRIC_A4_PAPER_SIZE.getHeight(),
185
        METRIC_A4_PAPER_SIZE.getWidth());
186

  
187
    /**
188
     * Print area (top, bottom, left, right).
189
     * This array changes when it's landscape
190
     * (it "knows" about portrait/landscape)
191
     */
192
    private double[] area_tblr = {
193
        0,
194
        0,
195
        0,
196
        0 };
197
    
198
    /**
199
     * Page size in user selected units
200
     * This field changes when it's landscape
201
     * (it "knows" about portrait/landscape)
202
     */
203
    private Size m_sizeinUnits = m_sizePaper;
204

  
205
    /**
206
     * Create a new object of Attributes.
207
     * 
208
     */
209
    public Attributes() {
210
        m_NameUnit = Messages.getText("Centimetros");
211
        m_Orientation = OrientationRequested.LANDSCAPE;
212
        m_type = MediaSizeName.ISO_A4;
213
        resetSizeinUnits();
214

  
215
        hasmargin = false;
216
        attributes.add(new Copies(1));
217
        attributes.add(MediaSizeName.ISO_A4);
218
        attributes.add(Sides.ONE_SIDED);
219
        attributes.add(Fidelity.FIDELITY_FALSE);
220
        attributes.add(PrintQuality.NORMAL);
221

  
222
        setType(m_typeSel);
223

  
224
        attributes.add(new MediaPrintableArea(0, 0,
225
                (float) ((getPaperSize().getWidth() * DPISCREEN) / PULGADA),
226
                (float) ((getPaperSize().getHeight() * DPISCREEN) / PULGADA),
227
                MediaPrintableArea.MM)); // FIXME: centimeters or milimeters
228
    }
229

  
230
    /**
231
     * @return
232
     */
233
    public boolean isLandscape() {
234
        return m_Orientation.getValue() ==
235
            OrientationRequested.LANDSCAPE.getValue();
236
    }
237
    
238
    /**
239
     * @return
240
     */
241
    public boolean isPortrait() {
242
        return m_Orientation.getValue() ==
243
            OrientationRequested.PORTRAIT.getValue();
244
    }
245

  
246
    /**
247
     * Inserts the Layout's properties to print.
248
     * 
249
     * @param typeSel
250
     *            Type of sheet.
251
     * @param units
252
     *            Units.
253
     * @param isLand
254
     *            True if the sheet is horizontal.
255
     * @param margin
256
     *            True if the sheet has margin.
257
     * @param resolution
258
     *            Type of quality of resolution.
259
     * @param area
260
     *            Printing area (top, bottom, left, right). 
261
     */
262
    public void setSelectedOptions(int typeSel, int units, boolean isLand,
263
        boolean margin, int resolution, double[] _area_tplr) {
264
        setType(typeSel);
265
        setUnit(units);
266
        setIsLandScape(isLand);
267
        hasmargin = margin;
268
        setResolution(resolution);
269
        area_tblr = _area_tplr;
270
    }
271
    
272
    /**
273
     * Paper size, measured in centimeters.
274
     * This field knows about orientation.
275
     * 
276
     * Note that this size is always measured in centimeters, regardless
277
     * the selected unit for the page. However, the user should be always
278
     * presented measures in the selected unit.
279
     * 
280
     * @see #getUnit()
281
     * @see #setUnit(int)
282
     * 
283
     * @return
284
     */
285
    public Size getPaperSize() {
286
        return m_sizePaper;
287
    }
288
    
289
    /**
290
     * Sets the paper size, measured in centimeters
291
     * @param paperSize
292
     */
293
    public void setPaperSize(Size paperSize) {
294
    	this.m_sizePaper = getCorrectedSize(paperSize);
295
    	if (getType()==CUSTOM) {
296
    		this.last_custom_paper_size = paperSize;
297
    	}
298
    	resetSizeinUnits();
299
    }
300
    
301
    /**
302
     * Gets the last selected custom paper size. It will be equal to
303
     * {@link #getPaperSize()} when {@link #getType()} is
304
     * {@link #CUSTOM}.
305
     * @return
306
     */
307
    public Size getCustomPaperSize() {
308
    	return this.last_custom_paper_size;
309
    }
310

  
311
    /**
312
     * Returns a PageFormat with the properties of printing.
313
     * 
314
     * @return PageFormat
315
     */
316
    public PageFormat getPageFormat() {
317
        PageFormat pf1 = new PageFormat();
318
        Paper paper = pf1.getPaper();
319

  
320
        paper.setSize(
321
            (m_sizePaper.getWidth() * DPISCREEN) / PULGADA,
322
            (m_sizePaper.getHeight() * DPISCREEN) / PULGADA);
323

  
324
        if (isLandscape()) {
325
            pf1.setOrientation(0);
326
            /*
327
             * 'area_tblr' and 'm_sizeinUnits' depend on
328
             * whether it is portrait or landscape, but
329
             * 'Paper' and 'm_sizePaper' must not know if it's
330
             * portrait/landscape, so we change order of
331
             * parameters. 'PageFormat' will do the changes again
332
             * because it is aware of portrait/landscape
333
             */
334
            paper.setImageableArea(
335
                getInPixels(area_tblr[1]),
336
                getInPixels(area_tblr[2]),
337
                getInPixels(m_sizeinUnits.getHeight() - area_tblr[0] - area_tblr[1]),
338
                getInPixels(m_sizeinUnits.getWidth()  - area_tblr[2] - area_tblr[3]));
339
        } else {
340
            // portrait
341
            pf1.setOrientation(1);
342
            paper.setImageableArea(
343
                getInPixels(area_tblr[2]),
344
                getInPixels(area_tblr[0]),
345
                getInPixels(m_sizeinUnits.getWidth() - area_tblr[2] - area_tblr[3]),
346
                getInPixels(m_sizeinUnits.getHeight()  - area_tblr[0] - area_tblr[1]));
347
        }
348

  
349
        pf1.setPaper(paper);
350
        return pf1;
351
    }
352

  
353
    /**
354
     * Changes centimeters to pixels.
355
     * 
356
     * @param d
357
     *            Centimeters.
358
     * 
359
     * @return Pixels.
360
     */
361
    private double getInPixels(double d) {
362
        return d * (DPISCREEN / PULGADA);
363
    }
364

  
365
    /**
366
     * Changes pixels to centimeters.
367
     * 
368
     * @param d
369
     *            Pixel.
370
     * 
371
     * @return Centimeters.
372
     */
373
    private double getInCM(double d) {
374
        return d / (DPISCREEN / PULGADA);
375
    }
376

  
377
    /**
378
     * Returns the printing area.
379
     * The value returned changes if orientation changes
380
     * (it "knows" about portrait/landscape)
381
     * 
382
     * @return Rectangle Area.
383
     */
384
    public Rectangle2D getArea() {
385
        Rectangle2D.Double rect = new Rectangle2D.Double();
386
        rect.setRect(
387
                area_tblr[2],
388
                area_tblr[0],
389
                m_sizePaper.getWidth() - area_tblr[2] - area_tblr[3],
390
                m_sizePaper.getHeight()  - area_tblr[0] - area_tblr[1]);
391
        return rect;
392
    }
393
    
394
    public double[] getAreaInsets() {
395
        return area_tblr;
396
    }
397

  
398
    /**
399
     * Inserts the attributes with a PageFormat.
400
     * 
401
     * @param pf
402
     *            PageFormat.
403
     */
404
    public void setPageFormat(PageFormat pf) {
405
        
406
        /*
407
         * Paper does not know about orientation
408
         */
409
        Size portrait_size = new Size(
410
            pf.getPaper().getHeight(),
411
            pf.getPaper().getWidth());
412
        setType(getTypePaper(portrait_size, true));
413

  
414
        if (pf.getOrientation() == 0) {
415
            setIsLandScape(true);
416
        } else {
417
            setIsLandScape(false);
418
        }
419
        
420

  
421
        attributes.add(m_Orientation);
422

  
423
        // tipo formato
424
        if (isLandscape()) {
425
            // landscape
426
            area_tblr[1] = getInCM(pf.getImageableX());
427
            area_tblr[2] = getInCM(pf.getImageableY());
428
            area_tblr[0] = 
429
                portrait_size.getWidth() - getInCM(pf.getImageableHeight())
430
                - area_tblr[1];
431
            area_tblr[3] =
432
                portrait_size.getHeight() - getInCM(pf.getImageableWidth())
433
                - area_tblr[2];
434
        } else {
435
            // portrait
436
            area_tblr[2] = getInCM(pf.getImageableX());
437
            area_tblr[0] = getInCM(pf.getImageableY());
438
            area_tblr[1] =
439
                portrait_size.getHeight() - getInCM(pf.getImageableHeight())
440
                - area_tblr[0];
441
            area_tblr[3] =
442
                portrait_size.getWidth() - getInCM(pf.getImageableWidth())
443
                - area_tblr[2];
444
        }
445
        
446
        /*
447
         * 'area_tblr' and 'pf' "know"
448
         * about orientation
449
         * 
450
         */
451
        attributes.add(new MediaPrintableArea(
452
            (float) (area_tblr[2] * 10),
453
            (float) (area_tblr[0] * 10),
454
            (float) (getInCM(pf.getImageableWidth()) * 10),
455
            (float) (getInCM(pf.getImageableHeight()) * 10),
456
            MediaPrintableArea.MM));
457
    }
458

  
459
    /**
460
     * Returns a PrintRequestAttributeSet with all properties to the
461
     * PrintDialog.
462
     * 
463
     * @return PrintRequestAttributesSet.
464
     */
465
    public PrintRequestAttributeSet toPrintRequestAttributeSet() {
466
        HashPrintRequestAttributeSet resul = new HashPrintRequestAttributeSet();
467

  
468
        setType(m_typeSel);
469

  
470
        resul.add(m_type);
471

  
472
        // units, no hace falta a?adirlo a attributes
473
        resul.add(m_Orientation);
474
        // setArea(area_tblr);
475
        
476
        Rectangle2D rect = this.getArea();
477
        resul.add(new MediaPrintableArea(
478
            (float) (rect.getX() *10),
479
            (float) (rect.getY() *10),
480
            (float) (rect.getWidth() *10),
481
            (float) (rect.getHeight() *10),
482
            MediaPrintableArea.MM));
483

  
484
        resul.add(toPrintQuality(m_resolutionSel));
485
        return resul;
486
    }
487
    
488
    public DocAttributeSet toDocAttributes() {
489
        HashDocAttributeSet resul = new HashDocAttributeSet();
490

  
491
        setType(m_typeSel);
492

  
493
        resul.add(m_type);
494

  
495
        // units, no hace falta a?adirlo a attributes
496
        resul.add(m_Orientation);
497
        // setArea(area_tblr);
498
        
499
        Rectangle2D rect = this.getArea();
500
        resul.add(new MediaPrintableArea(
501
            (float) (rect.getX() *10),
502
            (float) (rect.getY() *10),
503
            (float) (rect.getWidth() *10),
504
            (float) (rect.getHeight() *10),
505
            MediaPrintableArea.MM));
506

  
507
        resul.add(toPrintQuality(m_resolutionSel));
508
        return resul;
509
    }
510

  
511
    public PrintAttributes toPrintAttributes() {
512
        PrintAttributes resul =
513
            CompatLocator.getGraphicsUtils().createPrintAttributes();
514

  
515
        if (m_resolutionSel == DRAFT) {
516
            resul.setPrintQuality(PrintAttributes.PRINT_QUALITY_DRAFT);
517

  
518
        } else
519
            if (m_resolutionSel == NORMAL) {
520
                resul.setPrintQuality(PrintAttributes.PRINT_QUALITY_NORMAL);
521

  
522
            } else
523
                if (m_resolutionSel == HIGH) {
524
                    resul.setPrintQuality(PrintAttributes.PRINT_QUALITY_HIGH);
525
                } else {
526
                    throw new UnsupportedOperationException(
527
                        "Unsupported Print Quality: " + m_resolutionSel);
528
                }
529
        setType(m_typeSel);
530

  
531
        return resul;
532
    }
533

  
534
    /**
535
     * Returns a PrintRequestAttributeSet with all properties to the
536
     * PrintDialog.
537
     * 
538
     * @return PrintRequestAttributesSet.
539
     */
540
    public PrintRequestAttributeSet toPrintAttributeSet() {
541
        HashPrintRequestAttributeSet resul = new HashPrintRequestAttributeSet();
542

  
543
        setType(m_typeSel);
544

  
545
        resul.add(m_type);
546

  
547
        resul.add(m_Orientation);
548
        
549
        Rectangle2D rect = this.getArea();
550
        resul.add(new MediaPrintableArea(
551
            (float) (rect.getX() * DPISCREEN / PULGADA),
552
            (float) (rect.getY() * DPISCREEN / PULGADA),
553
            (float) (rect.getWidth() * DPISCREEN / PULGADA),
554
            (float) (rect.getHeight() * DPISCREEN / PULGADA),
555
            MediaPrintableArea.MM));
556

  
557
        resul.add(toPrintQuality(m_resolutionSel));
558
        return resul;
559
    }
560
    /**
561
     * Returns true if the margin should be used.
562
     * 
563
     * @return True if margin should be used.
564
     */
565
    public boolean isMargin() {
566
        return hasmargin;
567
    }
568

  
569
    /**
570
     * Returns the resolution of properties to print.
571
     * 
572
     * @return Resolution.
573
     */
574
    public int getResolution() {
575
        return m_resolutionSel;
576
    }
577

  
578
    /**
579
     * Inserts the resolution to apply at printing.
580
     * 
581
     * @param i
582
     *            Type of resolution.
583
     * 
584
     *            The type of resolution can be:
585
     * 
586
     *            DRAFT: 27 dpi.
587
     *            NORMAL: 300 dpi.
588
     *            HIGH: 600 dpi.
589
     */
590
    public void setResolution(int i) {
591
        m_resolutionSel = i;
592
        switch (i) {
593
        case (HIGH):
594
            DPI = 600;
595
            break;
596

  
597
        case (NORMAL):
598
            DPI = 300;
599
            break;
600

  
601
        case (DRAFT):
602
            DPI = 72;
603
            break;
604
        }
605
        attributes.add(toPrintQuality(i));
606
    }
607
    
608
    /**
609
     * Converts print quality from Attributes format
610
     * ({@link #HIGH}, {@link #NORMAL}, {@link #DRAFT})
611
     * to {@link PrintQuality} format.
612
     * 
613
     * @param quality
614
     * @return
615
     */
616
    public static PrintQuality toPrintQuality(int quality) {
617
        switch (quality) {
618
        case (HIGH):
619
        	return PrintQuality.HIGH;
620
        case (NORMAL):
621
            return PrintQuality.NORMAL;
622
        case (DRAFT):
623
        	return PrintQuality.DRAFT;
624
        default:
625
        	return PrintQuality.NORMAL;
626
        }
627
    }
628

  
629
    /**
630
     * Returns attributes of PrintDialog.
631
     * 
632
     * @return Attributes of printing.
633
     */
634
    public PrintRequestAttributeSet getAttributes() {
635
        return attributes;
636
    }
637

  
638
    /**
639
     * Returns True if the position of sheet is horizontal.
640
     * 
641
     * @return True if position is horizontal.
642
     */
643

  
644
    /**
645
     * Returns the format of sheet.
646
     * 
647
     * @return Format of sheet.
648
     */
649
    public int getType() {
650
        return m_typeSel;
651
    }
652

  
653
    /**
654
     * Inserts the number of units to define the coords X grid.
655
     * 
656
     * @param d
657
     *            number of units to define the grid.
658
     */
659
    public void setHGridGrapCm(double d) {
660
        m_gridGapCmX = new Double(d);
661
    }
662

  
663
    /**
664
     * Gets the grid gap for the x axis, in centimeters. The grip gap is the
665
     * distance from one point to the next point in the snapping grid.
666
     * 
667
     * @return Default grid gap for the x axis, measured in centimeters
668
     */
669
    public double getHGridGapCm() {
670
        if (m_gridGapCmX == null) {
671
            m_gridGapCmX = new Double(getDefaultGridGap().getX());
672
        }
673
        return m_gridGapCmX.doubleValue();
674
    }
675

  
676
    /**
677
     * Gets the grid gap for the y axis, in centimeters. The grip gap is the
678
     * distance from one point to the next point in the snapping grid.
679
     * 
680
     * @return Default grid gap for the y axis, measured in centimeters
681
     */
682
    public double getVGridGapCm() {
683
        if (m_gridGapCmY == null) {
684
            m_gridGapCmY = new Double(getDefaultGridGap().getY());
685
        }
686
        return m_gridGapCmY.doubleValue();
687
    }
688

  
689
    /**
690
     * Inserts the number of units to define the coords X grid.
691
     * 
692
     * @param d
693
     *            number of units to define the grid.
694
     */
695
    public void setVGridGrapCm(double d) {
696
        m_gridGapCmY = new Double(d);
697
    }
698

  
699
    /**
700
     * Inserts true if the sheet is horizontal or false if is vertical.
701
     * 
702
     * @param b
703
     *            True if sheet is horizontal.
704
     */
705
    public void setIsLandScape(boolean b) {
706
        if (b) {
707
            m_Orientation = OrientationRequested.LANDSCAPE;
708
        } else {
709
            m_Orientation = OrientationRequested.PORTRAIT;
710
        }
711
        setType(m_typeSel);
712
    }
713

  
714
    /**
715
     * Sets the type of sheet to show. See
716
     * {@link #PRINT}, {@link #CUSTOM}, {@link #A4}, {@link #A3}, {@link #A2},
717
     * {@link #A1}, {@link #A0}.
718
     * 
719
     * @param t
720
     *            Type of sheet.
721
     */
722
    public void setType(int t) {
723
        m_typeSel = t;
724
        switch (t) {
725
        case (PRINT):
726
            m_type = ((MediaSizeName) attributes.get(Media.class));
727
        	// FIXME: Shouldn't we adapt the actual size to the printer???? 
728
        	setPaperSize(METRIC_A4_PAPER_SIZE);
729
            break;
730

  
731
        case (A4):
732
            m_type = MediaSizeName.ISO_A4;
733
        	setPaperSize(METRIC_A4_PAPER_SIZE);
734
            break;
735

  
736
        case (A3):
737
            m_type = MediaSizeName.ISO_A3;
738
        	setPaperSize(METRIC_A3_PAPER_SIZE);
739
            break;
740

  
741
        case (A2):
742
            m_type = MediaSizeName.ISO_A2;
743
        	setPaperSize(METRIC_A2_PAPER_SIZE);
744
            break;
745

  
746
        case (A1):
747
            m_type = MediaSizeName.ISO_A1;
748
        	setPaperSize(METRIC_A1_PAPER_SIZE);
749
            break;
750

  
751
        case (A0):
752
            m_type = MediaSizeName.ISO_A0;
753
        	setPaperSize(METRIC_A0_PAPER_SIZE);
754

  
755
            break;
756

  
757
        case (CUSTOM):
758
            m_type = MediaSizeName.PERSONAL_ENVELOPE;
759
        	setPaperSize(last_custom_paper_size);
760
            break;
761
        }
762
        attributes.add(m_type);
763
    }
764

  
765
    /**
766
     * Sets the paper size, measured on the selected units
767
     * @see #getUnit()
768
     */
769
    public void setPaperSizeInUnits(Size sizeInUnits) {
770
    	setPaperSize(new Size(sizeInUnits.getHeight() * m_TypeUnit,
771
    			sizeInUnits.getWidth() * m_TypeUnit));
772
    }
773
    
774
    /**
775
     * Returns the size of sheet.
776
     * 
777
     * @param isLand
778
     *            True if is horizontal and false if is vertical.
779
     * @param type
780
     *            Type of sheet.
781
     * 
782
     * @return Size of sheet with these properties.
783
     */
784
    public Size getPaperSizeinUnits(boolean isLand, int type) {
785
        Size size = null;
786

  
787
        switch (type) {
788
        case (PRINT):
789

  
790
            if (isLand) {
791
                size =
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff