svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / PictureLine.java @ 40560
History | View | Annotate | Download (4.82 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40560 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.app.gui.styling; |
||
25 | |||
26 | import java.io.File; |
||
27 | import java.io.IOException; |
||
28 | import java.net.URISyntaxException; |
||
29 | |||
30 | import org.gvsig.andami.PluginServices; |
||
31 | import org.gvsig.andami.messages.NotificationManager; |
||
32 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
33 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
34 | import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol; |
||
35 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
||
36 | import org.gvsig.i18n.Messages; |
||
37 | import org.gvsig.symbology.SymbologyLocator; |
||
38 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IPictureLineSymbol; |
||
39 | |||
40 | /**
|
||
41 | * PictureLine initializes the properties that define a
|
||
42 | * <b>picture marker symbol</b> and are showed in the tab created by
|
||
43 | * PictureMarker which is called simple marker.<p>
|
||
44 | * <p>
|
||
45 | * Moreover, PictureLine has other methods such as getSymbolClass,getName,
|
||
46 | * refreshControls and getLayer.
|
||
47 | *
|
||
48 | *
|
||
49 | *@author jaume dominguez faus - jaume.dominguez@iver.es
|
||
50 | */
|
||
51 | public class PictureLine extends PictureMarker { |
||
52 | public PictureLine(SymbolEditor owner) {
|
||
53 | super(owner);
|
||
54 | initialize(); |
||
55 | } |
||
56 | /**
|
||
57 | * Initializes the values in the tab
|
||
58 | *
|
||
59 | */
|
||
60 | private void initialize() { |
||
61 | // tabs.remove(mask);
|
||
62 | lblSize.setText(Messages.getText("width")+":"); |
||
63 | lblX.setText(Messages.getText("scale")+" X:"); |
||
64 | lblY.setText(Messages.getText("scale")+" Y:"); |
||
65 | txtX.setMinValue(0.1);
|
||
66 | txtX.setMaxValue(Double.POSITIVE_INFINITY);
|
||
67 | txtX.setStep(0.1);
|
||
68 | txtX.setDouble(1);
|
||
69 | |||
70 | txtY.setMinValue(0.1);
|
||
71 | txtY.setMaxValue(Double.POSITIVE_INFINITY);
|
||
72 | txtY.setStep(0.1);
|
||
73 | txtY.setDouble(1);
|
||
74 | } |
||
75 | |||
76 | public String getName() { |
||
77 | return Messages.getText("picture_line_symbol"); |
||
78 | |||
79 | } |
||
80 | |||
81 | public void refreshControls(ISymbol layer) { |
||
82 | IPictureLineSymbol sym; |
||
83 | try {
|
||
84 | double size, xScale, yScale;
|
||
85 | String fileName = null, selectionFileName = null; |
||
86 | |||
87 | if (layer == null) { |
||
88 | // initialize defaults
|
||
89 | System.err.println(getClass().getName()+":: should be unreachable code"); |
||
90 | |||
91 | size = 1D;
|
||
92 | xScale = 1D;
|
||
93 | yScale = 1D;
|
||
94 | fileName = "-";
|
||
95 | selectionFileName = "-";
|
||
96 | } else {
|
||
97 | sym = (IPictureLineSymbol) layer; |
||
98 | |||
99 | size = sym.getLineWidth(); |
||
100 | xScale = sym.getXScale(); |
||
101 | yScale = sym.getYScale(); |
||
102 | |||
103 | fileName = sym.getSource().toURI().getPath(); |
||
104 | selectionFileName = sym.getSelectedSource().toURI().getPath(); |
||
105 | |||
106 | } |
||
107 | |||
108 | setValues(size, xScale, yScale, fileName, selectionFileName); |
||
109 | } catch (IndexOutOfBoundsException ioEx) { |
||
110 | NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
|
||
111 | } catch (ClassCastException ccEx) { |
||
112 | NotificationManager.addWarning("Illegal casting from " +
|
||
113 | layer.getClass().getName() + " to IPictureLineSymbol.", ccEx);
|
||
114 | } catch (URISyntaxException e) { |
||
115 | NotificationManager.addWarning("URI Syntax error", e);
|
||
116 | } |
||
117 | } |
||
118 | |||
119 | public ISymbol getLayer() {
|
||
120 | |||
121 | try {
|
||
122 | IPictureLineSymbol layer = null;
|
||
123 | |||
124 | |||
125 | if(lblFileName.getText().equals("") ) |
||
126 | layer=null;
|
||
127 | |||
128 | else {
|
||
129 | layer = SymbologyLocator.getSymbologyManager().createPictureLineSymbol(new File(lblFileName.getText()).toURI().toURL(),null); |
||
130 | if (!lblSelFileName.getText().equals("")){ |
||
131 | layer = SymbologyLocator.getSymbologyManager().createPictureLineSymbol(new File(lblFileName.getText()).toURI().toURL(),new File(lblSelFileName.getText()).toURI().toURL()); |
||
132 | } |
||
133 | // layer.setIsShapeVisible(true); //true is the default value of this property
|
||
134 | layer.setLineWidth(txtSize.getDouble()); |
||
135 | layer.setXScale(txtX.getDouble()); |
||
136 | layer.setYScale(txtY.getDouble()); |
||
137 | } |
||
138 | |||
139 | return layer;
|
||
140 | } catch (IOException e) { |
||
141 | IWarningSymbol warning = |
||
142 | (IWarningSymbol) MapContextLocator.getSymbolManager() |
||
143 | .getWarningSymbol( |
||
144 | SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS, |
||
145 | Messages.getText("failed_acessing_files"),
|
||
146 | SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS); |
||
147 | return warning;
|
||
148 | |||
149 | } |
||
150 | |||
151 | } |
||
152 | |||
153 | public boolean canManageSymbol(ISymbol symbol) { |
||
154 | return symbol instanceof IPictureLineSymbol; |
||
155 | } |
||
156 | |||
157 | } |