Revision 585

View differences:

tags/org.gvsig.app.document.layout2.app-2.0.85/org.gvsig.app.document.layout2.app.mainplugin/buildNumber.properties
1
#Thu Aug 04 11:02:31 CEST 2016
2
buildNumber=104
tags/org.gvsig.app.document.layout2.app-2.0.85/org.gvsig.app.document.layout2.app.mainplugin/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
tags/org.gvsig.app.document.layout2.app-2.0.85/org.gvsig.app.document.layout2.app.mainplugin/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.app.document.layout">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
tags/org.gvsig.app.document.layout2.app-2.0.85/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.85/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.85/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
}
tags/org.gvsig.app.document.layout2.app-2.0.85/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
}
0 141

  
tags/org.gvsig.app.document.layout2.app-2.0.85/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/LayoutDocument.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout;
23

  
24
import java.util.Iterator;
25
import org.gvsig.app.project.documents.Document;
26

  
27
/**
28
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
29
 */
30
public interface LayoutDocument extends Document {
31

  
32
    public LayoutContext getLayoutContext();
33
   
34
    /**
35
     * Get an Iterator over al elements in the layout.
36
     * 
37
     * @return 
38
     */
39
    public Iterator deepiterator();
40

  
41
    public Iterator iterator();
42
    
43
}
tags/org.gvsig.app.document.layout2.app-2.0.85/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutFunctions.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout;
23

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

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

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

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

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

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

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

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

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

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

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

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

  
164
                if (((IFFrame) fframe).getSelected() != IFFrame.NOSELECT) {
165
                    if (fframe.getATMap() != null) {
166
                        Rectangle2D.Double r = new Rectangle2D.Double();
167
                        Envelope envel =
168
                            // fframe.getMapContext().getViewPort().getExtent();
169
                            fframe.getMapContext().getViewPort().getEnvelope();
170
                        
171
                        if (envel != null) {
172
                            double visible_factor = screenPixelToViewPortPixelRatio(
173
                                layout,
174
                                ((IFFrame) fframe).getBoundBox().getHeight(),
175
                                fframe.getMapContext().getViewPort().getImageHeight());
176

  
177
                            Point p1scaled = new Point(
178
                                (int) (visible_factor * p1.getX()),
179
                                (int) (visible_factor * p1.getY()));
180
                            Point p2scaled = new Point(
181
                                (int) (visible_factor * p2.getX()),
182
                                (int) (visible_factor * p2.getY()));
183
                            
184
                            Point2D mp1 = toMapPoint(p1scaled, fframe.getATMap());
185
                            Point2D mp2 = toMapPoint(p2scaled, fframe.getATMap());
186
                            double x =
187
                                envel.getMinimum(0) - (mp2.getX() - mp1.getX());
188
                            double y =
189
                                envel.getMinimum(1) - (mp2.getY() - mp1.getY());
190
                            double width = envel.getLength(0);
191
                            double height = envel.getLength(1);
192
                            try {
193
                                fframe
194
                                    .getMapContext()
195
                                    .getViewPort()
196
                                    .setEnvelope(
197
                                        geomManager.createEnvelope(x, y, x
198
                                            + width, y + height,
199
                                            SUBTYPES.GEOM2D));
200
                            } catch (CreateEnvelopeException e) {
201
                                logger.error("Error creating the envelope", e);
202
                            }
203
                            fframe.refresh();
204
                            if (fframe.getExtentSynced()) {
205
                                fframe.refreshOriginalExtent();
206
                            }
207
                        }
208
                    }
209
                }
210
            }
211
        }
212
    }
213

  
214
    public void setScale(long scale) {
215
    	IFFrameUseFMap[] selectedFrames = layout.getLayoutContext().getSelectedFFrames(IFFrameUseFMap.class);
216
    	if (selectedFrames.length==1) {
217
    		IFFrameUseFMap fframe = (IFFrameUseFMap) selectedFrames[0];
218
    		fframe.setScale(scale);
219
    		// FIXME CMI: needed?? fframe.refresh();
220
    	}
221
    }
222

  
223
    public void addLayer() {
224
    	
225
    }
226
    
227
    /**
228
     * Devuelve un punto real a partir de un punto en pixels sobre la vista.
229
     * 
230
     * @param pScreen
231
     *            Punto en pixels.
232
     * @param at1
233
     *            Matriz de transformaci?n.
234
     * 
235
     * @return Punto real.
236
     */
237
    public static Point2D.Double toMapPoint(Point2D pScreen, AffineTransform at1) {
238
        Point2D.Double pWorld = new Point2D.Double();
239

  
240
        AffineTransform at;
241

  
242
        try {
243
            at = at1.createInverse();
244
            at.transform(pScreen, pWorld);
245
        } catch (NoninvertibleTransformException e) {
246
            // throw new RuntimeException(e);
247
        }
248

  
249
        return pWorld;
250
    }
251

  
252
    public void addObserver(Observer o) {
253
        observers.addObserver(o);        
254
    }
255

  
256
    public void deleteObserver(Observer o) {
257
      observers.deleteObserver(o);        
258
    }
259

  
260
    public void deleteObservers() {
261
       observers.deleteObservers();        
262
    }
263
    
264
    /**
265
     * Gets the proportion between the number of pixels used
266
     * on the screen (physical pixels) and the "logical" pixels
267
     * used in the viewport of a frame (imageHeight, etc).
268
     * 
269
     * For example if viewport image height is 500
270
     * and the frame actually needs 100 pixels in height
271
     * (due to zooming) then this method returns 5.
272
     *  
273
     * @param lyt_panel
274
     * @param frame_height_cm frame height in cm
275
     * @param frame_vp_img_height frame viewport image height (pixels)
276
     * @return
277
     */
278
    public static double screenPixelToViewPortPixelRatio(
279
        LayoutPanel lyt_panel, double frame_height_cm, int frame_vp_img_height) {
280
        
281
        double sheet_height_screen_pix = lyt_panel.getLayoutControl().getRect().getHeight();
282
        int ori = lyt_panel.getLayoutContext().getAttributes().getPageFormat().getOrientation();
283
        double paper_h_i72 = 0;
284
        
285
        /*
286
         * Javadoc says getPageFormat().getWidth()(getHeight()
287
         * take into account orientation
288
         * but apparently it's not like that
289
         */
290
        if (ori == PageFormat.LANDSCAPE || ori == PageFormat.REVERSE_LANDSCAPE) {
291
            paper_h_i72 = lyt_panel.getLayoutContext().getAttributes().getPageFormat().getWidth();
292
        } else {
293
            paper_h_i72 = lyt_panel.getLayoutContext().getAttributes().getPageFormat().getHeight();
294
        }
295
        
296
        /*
297
         * page format uses old unit (inch/72)
298
         */
299
        double paper_h_cm = (2.54 / 72.0) * paper_h_i72;
300
        double frame_part = frame_height_cm / paper_h_cm;
301
        double pixels_fview_screen_h = sheet_height_screen_pix * frame_part;   
302
        double pixels_fview_vp_h = 1.0 * frame_vp_img_height;
303
        return pixels_fview_vp_h / pixels_fview_screen_h;
304
    }
305
    
306

  
307
    public static String getLastMessage(Throwable ex) {
308
        
309
        if (ex == null) {
310
            return "[null]";
311
        }
312
        
313
        Throwable p = ex;
314
        while (p.getCause() != null && p.getCause() != p) {
315
            p = p.getCause();
316
        }
317
        return p.getMessage();
318
    }
319
}
tags/org.gvsig.app.document.layout2.app-2.0.85/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/DefaultLayoutManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.lang.reflect.Array;
26
import java.text.NumberFormat;
27
import java.util.ArrayList;
28
import java.util.Arrays;
29
import java.util.Comparator;
30
import java.util.Iterator;
31
import java.util.List;
32

  
33
import javax.swing.ImageIcon;
34

  
35
import org.gvsig.andami.PluginServices;
36
import org.gvsig.andami.PluginsLocator;
37
import org.gvsig.andami.messages.NotificationManager;
38
import org.gvsig.andami.ui.mdiManager.IWindow;
39
import org.gvsig.app.ApplicationLocator;
40
import org.gvsig.app.gui.preferencespage.PreferenceKeys;
41
import org.gvsig.app.project.ProjectManager;
42
import org.gvsig.app.project.documents.AbstractDocument;
43
import org.gvsig.app.project.documents.AbstractDocumentManager;
44
import org.gvsig.app.project.documents.Document;
45
import org.gvsig.app.project.documents.actions.CopyDocumentAction;
46
import org.gvsig.app.project.documents.actions.CutDocumentAction;
47
import org.gvsig.app.project.documents.actions.PasteDocumentAction;
48
import org.gvsig.app.project.documents.gui.WindowLayout;
49
import org.gvsig.app.project.documents.layout.contextmenu.gui.AbstractLayoutContextMenuAction;
50
import org.gvsig.app.project.documents.layout.fframes.FrameFactory;
51
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
52
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
53
import org.gvsig.app.project.documents.layout.gui.DefaultLayoutPanel;
54
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
55
import org.gvsig.app.project.documents.layout.gui.LayoutPanelImpl;
56
import org.gvsig.app.project.documents.layout.gui.MapProperties;
57
import org.gvsig.app.project.documents.layout.gui.dialogs.FConfigLayoutDialog;
58
import org.gvsig.app.project.documents.view.IContextMenuAction;
59
import org.gvsig.tools.ToolsLocator;
60
import org.gvsig.tools.dynobject.DynStruct;
61
import org.gvsig.tools.extensionpoint.ExtensionPoint;
62
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
63
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
64
import org.gvsig.tools.persistence.PersistenceManager;
65
import org.gvsig.tools.swing.api.ToolsSwingLocator;
66
import org.gvsig.utils.XMLEntity;
67
import org.slf4j.Logger;
68
import org.slf4j.LoggerFactory;
69

  
70
/**
71
 * Factory of maps.
72
 * 
73
 * @author Vicente Caballero Navarro
74
 */
75
public class DefaultLayoutManager extends AbstractDocumentManager implements
76
    LayoutManager {
77
    static final Logger LOG = LoggerFactory
78
        .getLogger(DefaultLayoutManager.class);
79

  
80
    static final String KEY_LAYOUT_FFRAMEDIALOG =
81
        "app.project.documents.layout.fframes.gui";
82
    static final String KEY_LAYOUT_FFRAME =
83
        "app.project.documents.layout.fframes";
84

  
85
    public static final String PERSISTENCE_LAYOUT_DOCUMENT_DEFINITION_NAME =
86
        "LayoutDocument";
87
    
88
    private static final String LAYOUT_CONTEXT_MENUS = "Layout_ContextMenus";
89

  
90
    ExtensionPointManager extensionPoints = ToolsLocator
91
        .getExtensionPointManager();
92

  
93
    private Boolean defaultShowGrid = null;
94
    private Boolean defaultAdjustToGrid = null;
95
    private Boolean defaultShowRulers = null;
96

  
97
    private DynStruct persistenceDefinition;
98

  
99
    /**
100
     * Returns image of button.
101
     * 
102
     * @return Image button.
103
     */
104
    public ImageIcon getIcon() {
105
    	return ToolsSwingLocator.getIconThemeManager().getCurrent().get("document-map-icon");
106
    }
107

  
108
    /**
109
     * Returns image of selected button.
110
     * 
111
     * @return Image button.
112
     */
113
    public ImageIcon getIconSelected() {
114
        return ToolsSwingLocator.getIconThemeManager().getCurrent().get("document-map-icon-sel");
115
    }
116

  
117
    /**
118
     * Returns the name of registration in the point of extension.
119
     * 
120
     * @return Name of registration
121
     */
122
    public String getTypeName() {
123
        return TYPENAME;
124
    }
125

  
126
    /**
127
     * Returns the name of ProjectDocument.
128
     * 
129
     * @return Name of ProjectDocument.
130
     */
131
    public String getTitle() {
132
        return PluginServices.getText(this, "Mapa");
133
    }
134

  
135
    public AbstractDocument createDocument() {
136
        return new DefaultLayoutDocument(this);
137
    }
138

  
139
    public Class getMainWindowClass() {
140
        return LayoutPanelImpl.class;
141
    }
142

  
143
    public IWindow getMainWindow(Document doc, WindowLayout layout) {
144
        LayoutPanel layoutPanel = (LayoutPanel) super.getMainWindow(doc, layout);
145
        if (layoutPanel == null) {
146
            layoutPanel = (LayoutPanel) this.createDocumentWindow(doc);
147
            if (layout != null) {
148
                layoutPanel.setWindowLayout(layout);
149
                layoutPanel.setLayoutManager(this);
150
                layoutPanel.getLayoutControl().fullRect();
151
                layoutPanel.getWindowInfo().setTitle(
152
                        PluginServices.getText(this, "Mapa") + " : "
153
                        + layoutPanel.getName());
154
            }
155
        }
156
        ((AbstractDocument) doc).raiseEventCreateWindow(layoutPanel);
157
        return layoutPanel;
158
    }
159

  
160
    public IFFrameDialog createFFrameDialog(IFFrame fframe,
161
        LayoutPanel layoutPanel, AffineTransform affineTransform) {
162
        ExtensionPoint ep = extensionPoints.add(KEY_LAYOUT_FFRAMEDIALOG);
163

  
164
        try {
165
            Object[] args = new Object[2];
166
            args[0] = layoutPanel;
167
            args[1] = fframe;
168
            Object obj = ep.create(fframe.getName(), args);
169
            if (obj != null) {
170
                IFFrameDialog fframedialog = (IFFrameDialog) obj;
171
                fframedialog.setRectangle(fframe
172
                    .getBoundingBox(affineTransform));
173
                return fframedialog;
174
            }
175
        } catch (Exception e) {
176
            LOG.error("Error creating a FFrameDialog", e);
177
        }
178
        return null;
179
    }
180

  
181
    public IFFrameDialog createFFrameDialog(IFFrame fframe,
182
        LayoutPanel layoutPanel) {
183
        return createFFrameDialog(fframe, layoutPanel, layoutPanel
184
            .getLayoutControl().getAT());
185
    }
186

  
187
    public void registerFrameFactory(FrameFactory frameFactory, String alias) {
188
        ExtensionPoint ep =
189
            ToolsLocator.getExtensionPointManager().add(KEY_LAYOUT_FFRAME);
190
        ep.append(frameFactory.getRegisterName(), "", frameFactory);
191
        if (alias != null) {
192
            ep.addAlias(frameFactory.getRegisterName(), alias);
193
        }
194
    }
195

  
196
    public void registerFrameFactory(FrameFactory frameFactory) {
197
        registerFrameFactory(frameFactory, null);
198
    }
199

  
200
    @SuppressWarnings("unchecked")
201
    public IFFrame createFrame(String frameName) {
202

  
203
        Iterator<Extension> iterator =
204
            ToolsLocator.getExtensionPointManager().get(KEY_LAYOUT_FFRAME)
205
                .iterator();
206
        while (iterator.hasNext()) {
207
            try {
208
                FrameFactory frameFactory =
209
                    (FrameFactory) iterator.next().create();
210
                if (frameFactory.getRegisterName().equals(frameName)) {
211
                    IFFrame frame = frameFactory.createFrame();
212
                    if (frame == null) {
213
                        return null;
214
                    }
215
                    frame.setFrameFactory(frameFactory);
216
                    return frame;
217
                }
218
            } catch (Exception e) {
219
                NotificationManager.addError(e);
220
            }
221
        }
222
        return null;
223
    }
224

  
225
    @SuppressWarnings("unchecked")
226
    public void registerFFrameDialog(String name, Class clazz) {
227
        if (!IFFrameDialog.class.isAssignableFrom(clazz)) {
228
            throw new IllegalArgumentException(clazz.getName()
229
                + " must implement the IFFrameDialog interface");
230
        }
231
        ExtensionPoint extensionPoint =
232
            extensionPoints.add(KEY_LAYOUT_FFRAMEDIALOG, "");
233
        extensionPoint.append(name, name, clazz);
234
    }
235

  
236
    @Override
237
    public IWindow getPropertiesWindow(Document doc) {
238
        IWindow win = super.getPropertiesWindow(doc);
239
        if( win == null ) {
240
            win = new MapProperties((LayoutDocument) doc);
241
        }
242
        return win;
243
    }
244

  
245
    /**
246
     * Registers in the points of extension the Factory with alias.
247
     * 
248
     */
249
    public static void register() {
250
        DefaultLayoutManager factory = new DefaultLayoutManager();
251
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
252
        manager.registerFactory(factory);
253

  
254
        ProjectManager.getInstance().registerDocumentFactory(factory);
255
        
256
        ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
257
        ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
258
        ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
259

  
260

  
261
        if (factory.persistenceDefinition == null) {
262
            factory.persistenceDefinition =
263
                manager.addDefinition(LayoutDocument.class,
264
                    PERSISTENCE_LAYOUT_DOCUMENT_DEFINITION_NAME,
265
                    "Layout document Persistence definition", null, null);
266
            factory.persistenceDefinition.extend(manager
267
                .getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
268

  
269
            factory.persistenceDefinition
270
                .addDynFieldObject(DefaultLayoutDocument.LAYOUT_CONTEXT_OBJECT)
271
                .setClassOfValue(LayoutContext.class).setMandatory(false);
272

  
273
            DefaultLayoutPanel.registerPersistent();
274
            DefaultLayoutContext.registerPersistent();
275
        }
276
    }
277

  
278
    public int getPriority() {
279
        return 2;
280
    }
281

  
282
    /**
283
     * Sets whether the grid should be shown.
284
     * 
285
     * @param showGrid
286
     */
287
    public void setDefaultShowGrid(boolean showGrid) {
288
        defaultShowGrid = new Boolean(showGrid);
289
    }
290

  
291
    /**
292
     * Sets whether the snapping to grid should be enabled or not
293
     * 
294
     * @param gridEnable
295
     */
296
    public void setDefaultAdjustToGrid(boolean gridEnabled) {
297
        defaultAdjustToGrid = new Boolean(gridEnabled);
298
    }
299

  
300
    /**
301
     * Sets whether the ruler should be shown or not
302
     * 
303
     * @param showRuler
304
     */
305
    public void setDefaultShowRulers(boolean showRules) {
306
        defaultShowRulers = new Boolean(showRules);
307
    }
308

  
309
    /**
310
     * Returns if the grid should be shown.
311
     * 
312
     * @return True if the grid should be shown.
313
     */
314
    public boolean getDefaultShowGrid() {
315
        if (defaultShowGrid == null) {
316
        	XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
317
            if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) {
318
                defaultShowGrid =
319
                    new Boolean(xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME));
320
            } else {
321
                defaultShowGrid = new Boolean(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_SHOW);
322
            }
323
        }
324
        return defaultShowGrid.booleanValue();
325
    }
326

  
327
    /**
328
     * Returns if the adjust to grid should be active.
329
     * 
330
     * @return True if the adjust to grid should be active.
331
     */
332
    public boolean getDefaultAdjustToGrid() {
333
        if (defaultAdjustToGrid == null) {
334
        	XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
335
            if (xml.contains(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) {
336
                defaultAdjustToGrid =
337
                    new Boolean(
338
                        xml.getBooleanProperty(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME));
339
            } else {
340
                defaultAdjustToGrid = new Boolean(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_ENABLE);
341
            }
342
        }
343
        return defaultAdjustToGrid.booleanValue();
344
    }
345

  
346
    /**
347
     * Returns if the ruler should be shown.
348
     * 
349
     * @return True if the ruler should be shown.
350
     */
351
    public boolean getDefaultShowRulers() {
352
        if (defaultShowRulers == null) {
353
        	XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
354
            if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME)) {
355
                defaultShowRulers =
356
                    new Boolean(
357
                        xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME));
358
            } else {
359
                defaultShowRulers = new Boolean(PreferenceKeys.FACTORY_DEFAULT_LAYOUT_ENABLE_RULERS);
360
            }
361
        }
362
        return defaultShowRulers.booleanValue();
363
    }
364

  
365
    public boolean getDefaultShowInitialPageConfigDialog() {
366
    	XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
367
    	boolean value;
368
        if (xml.contains(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME)) {
369
            value = xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME);
370
        } else {
371
        	value = PreferenceKeys.FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT;
372
        }
373
        return value;
374
    }
375

  
376
    public DynStruct getDefinition(String className) {
377

  
378
        if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) {
379
            return this.persistenceDefinition;
380
        }
381
        if (this.persistenceDefinition.getFullName()
382
            .equalsIgnoreCase(className)) {
383
            return this.persistenceDefinition;
384
        }
385
        if (this.getDocumentClass().getName().equals(className)) {
386
            return this.persistenceDefinition;
387
        }
388
        return null;
389
    }
390

  
391
    @SuppressWarnings("unchecked")
392
    protected Class getDocumentClass() {
393
        return DefaultLayoutDocument.class;
394
    }
395

  
396
    public boolean manages(Object object) {
397
        return object instanceof LayoutDocument;
398
    }
399

  
400
    public void registerLayoutMenuAction(String name,
401
        Class<? extends IContextMenuAction> clazz) {
402
        ExtensionPoint extensionPoint =
403
            ToolsLocator.getExtensionPointManager().add(LAYOUT_CONTEXT_MENUS);
404
        extensionPoint.append(name, "", clazz);
405
    }
406

  
407
    public IContextMenuAction[] createLayoutMenuActions(LayoutPanel layoutPanel) {
408
        List<IContextMenuAction> actionArrayList =
409
            new ArrayList<IContextMenuAction>();
410
        @SuppressWarnings("unchecked")
411
        Iterator<ExtensionPoint.Extension> iter =
412
            ToolsLocator.getExtensionPointManager().get(LAYOUT_CONTEXT_MENUS).iterator();
413
        AbstractLayoutContextMenuAction action;
414
        while (iter.hasNext()) {
415
            action = null;
416
            try {
417
                action = (AbstractLayoutContextMenuAction) iter.next().create();
418
            } catch (InstantiationException e) {
419
                LOG.error("Error creating the context menu", e);
420
            } catch (IllegalAccessException e) {
421
                LOG.error("Error creating the context menu", e);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff