Revision 2234
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/README.txt | ||
---|---|---|
1 |
==== |
|
2 |
gvSIG. Desktop Geographic Information System. |
|
3 |
|
|
4 |
Copyright (C) 2007-2013 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 |
|
|
25 |
The first time you checkout the current project to a new workspace, |
|
26 |
you have to prepare it to be able to work easily with maven from |
|
27 |
eclipse itself. |
|
28 |
|
|
29 |
Perform the following steps: |
|
30 |
|
|
31 |
1.- Launch the *prepare-workspace.xml* ant build file. |
|
32 |
You can do it by loading the file into the ant view, |
|
33 |
and running the default task, or right-clicking the |
|
34 |
file from the package explorer or the navigator and |
|
35 |
select the option: *Run as > Ant build*. |
|
36 |
|
|
37 |
2.- Restart eclipse. |
|
38 |
|
|
39 |
3.- Import the subprojects of the project you have just checked out. |
|
40 |
|
|
41 |
Those steps are only needed once per workspace. |
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/pom.xml | ||
---|---|---|
1 |
<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"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.tools</artifactId> |
|
6 |
<version>3.0.234</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.tools.util</artifactId> |
|
9 |
<name>org.gvsig.tools.util</name> |
|
10 |
<packaging>pom</packaging> |
|
11 |
<modules> |
|
12 |
<module>org.gvsig.tools.util.api</module> |
|
13 |
<module>org.gvsig.tools.util.impl</module> |
|
14 |
</modules> |
|
15 |
</project> |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/svgsupport/DumbSVGRenderer.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.svgsupport; |
|
3 |
|
|
4 |
import java.awt.Graphics2D; |
|
5 |
import java.awt.geom.Rectangle2D; |
|
6 |
import java.io.File; |
|
7 |
import java.io.IOException; |
|
8 |
import java.net.URISyntaxException; |
|
9 |
import java.net.URL; |
|
10 |
|
|
11 |
|
|
12 |
public class DumbSVGRenderer implements SVGRenderer { |
|
13 |
|
|
14 |
private URL source; |
|
15 |
|
|
16 |
@Override |
|
17 |
public void drawInsideRectangle(Graphics2D g, Rectangle2D rect, boolean keepAspectRatio) { |
|
18 |
|
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
public Rectangle2D getBounds() { |
|
23 |
return new Rectangle2D.Float(0, 0, 1, 1); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public URL getSource() { |
|
28 |
return source; |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public void setSource(URL url) throws IOException { |
|
33 |
this.source = url; |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public void setSource(File f) throws IOException { |
|
38 |
try { |
|
39 |
this.source = source.toURI().toURL(); |
|
40 |
} catch (URISyntaxException ex) { |
|
41 |
|
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/svgsupport/DumbSVGSupportManager.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.svgsupport; |
|
3 |
|
|
4 |
import java.io.File; |
|
5 |
import java.io.IOException; |
|
6 |
import java.net.URL; |
|
7 |
|
|
8 |
|
|
9 |
public class DumbSVGSupportManager implements SVGSupportManager { |
|
10 |
|
|
11 |
@Override |
|
12 |
public SVGRenderer createRenderer() { |
|
13 |
return new DumbSVGRenderer(); |
|
14 |
} |
|
15 |
|
|
16 |
@Override |
|
17 |
public SVGRenderer createRenderer(URL source) throws IOException { |
|
18 |
SVGRenderer renderer = new DumbSVGRenderer(); |
|
19 |
renderer.setSource(source); |
|
20 |
return renderer; |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
public SVGRenderer createRenderer(File source) throws IOException { |
|
25 |
SVGRenderer renderer = new DumbSVGRenderer(); |
|
26 |
renderer.setSource(source); |
|
27 |
return renderer; |
|
28 |
} |
|
29 |
|
|
30 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/tools/util/impl/ToolsUtilLibraryImpl.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify it under |
|
7 |
* the terms of the GNU General Public License as published by the Free Software |
|
8 |
* Foundation; either version 2 of the License, or (at your option) any later |
|
9 |
* version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
14 |
* details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us at info AT |
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.tools.util.impl; |
|
24 |
|
|
25 |
import org.gvsig.configurableactions.DefaultConfigurableActionsMamager; |
|
26 |
import org.gvsig.filedialogchooser.impl.DefaultFileDialogChooserManager; |
|
27 |
import org.gvsig.imageviewer.DefaultImageViewerManager; |
|
28 |
import org.gvsig.propertypage.impl.DefaultPropertiesPageManager; |
|
29 |
import org.gvsig.svgsupport.DumbSVGSupportManager; |
|
30 |
import org.gvsig.tools.library.AbstractLibrary; |
|
31 |
import org.gvsig.tools.library.Library; |
|
32 |
import org.gvsig.tools.library.LibraryException; |
|
33 |
import org.gvsig.tools.util.ToolsUtilLibrary; |
|
34 |
import org.gvsig.tools.util.ToolsUtilLocator; |
|
35 |
|
|
36 |
/** |
|
37 |
* {@link Library} for the default tools util implementation. |
|
38 |
* |
|
39 |
* @author gvSIG team |
|
40 |
*/ |
|
41 |
public class ToolsUtilLibraryImpl extends AbstractLibrary { |
|
42 |
|
|
43 |
@Override |
|
44 |
public void doRegistration() { |
|
45 |
super.doRegistration(); |
|
46 |
registerAsImplementationOf(ToolsUtilLibrary.class); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
protected void doInitialize() throws LibraryException { |
|
51 |
ToolsUtilLocator.registerDefaultToolsUtilManager(DefaultToolsUtilManager.class); |
|
52 |
ToolsUtilLocator.registerDefaultFileDialogChooserManager(DefaultFileDialogChooserManager.class); |
|
53 |
ToolsUtilLocator.registerDefaultSVGSupportManager(DumbSVGSupportManager.class); |
|
54 |
ToolsUtilLocator.registerDefaultImageViewerManager(DefaultImageViewerManager.class); |
|
55 |
ToolsUtilLocator.registerDefaultConfigurableActionsMamager(DefaultConfigurableActionsMamager.class); |
|
56 |
ToolsUtilLocator.registerDefaultPropertiesPageManager(DefaultPropertiesPageManager.class); |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
protected void doPostInitialize() throws LibraryException { |
|
61 |
|
|
62 |
} |
|
63 |
|
|
64 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/tools/util/impl/BaseInformationBuilder.java | ||
---|---|---|
1 |
package org.gvsig.tools.util.impl; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.apache.commons.lang3.StringEscapeUtils; |
|
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
|
|
9 |
import org.gvsig.tools.ToolsLocator; |
|
10 |
import org.gvsig.tools.util.InformationBuilder; |
|
11 |
|
|
12 |
|
|
13 |
public class BaseInformationBuilder implements InformationBuilder { |
|
14 |
|
|
15 |
private String backgroundColor = "\"#FFFFFF\""; |
|
16 |
private String backgroundColorTitle = "\"#FBFFE1\""; // light yellow |
|
17 |
private String backgroundColorPropertyLabel = "\"#D6D6D6\""; // Gris |
|
18 |
private String backgroundColorPropertyValue1 = "\"#FEEDD6\""; // light salmon |
|
19 |
private String backgroundColorPropertyValue2 = "\"#EAEAEA\""; // light grey |
|
20 |
|
|
21 |
protected int propertyCount = 0; |
|
22 |
protected final List<Element> elements; |
|
23 |
|
|
24 |
protected class BaseTitleElement implements TitleElement { |
|
25 |
|
|
26 |
protected String label; |
|
27 |
|
|
28 |
@Override |
|
29 |
public TitleElement value(String format, Object... args) { |
|
30 |
if (args == null) { |
|
31 |
this.label = format; |
|
32 |
} else { |
|
33 |
this.label = String.format(format, args); |
|
34 |
} |
|
35 |
return this; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public TitleElement label(String label) { |
|
40 |
this.label = StringEscapeUtils.escapeHtml3(label); |
|
41 |
return this; |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public TitleElement labelkey(String labelkey) { |
|
46 |
return label(ToolsLocator.getI18nManager().getTranslation(labelkey)); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public String build() { |
|
51 |
propertyCount = 0; |
|
52 |
return "<tr valign=\"middle\" >" |
|
53 |
+ "<td bgcolor=" + backgroundColorTitle + " align=\"center\" colspan=\"2\"><font face=\"Arial\" size=\"3\"><b> " + this.label + "</b></font></td>" |
|
54 |
+ "</tr>"; |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
protected class BaseRawElement implements RawElement { |
|
59 |
|
|
60 |
protected String value; |
|
61 |
|
|
62 |
@Override |
|
63 |
public RawElement value(String format, Object... args) { |
|
64 |
if (args == null) { |
|
65 |
this.value = format; |
|
66 |
} else { |
|
67 |
this.value = String.format(format, args); |
|
68 |
} |
|
69 |
return this; |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public String build() { |
|
74 |
String color = ((propertyCount++ % 2) == 0) ? backgroundColorPropertyValue1 : backgroundColorPropertyValue2; |
|
75 |
String content = "<tr valign=\"top\">\n"; |
|
76 |
content += "<td bgcolor=" + color + "align=\"left\" colspan=\"2\"><font face=\"Arial\" size=\"3\"><div>" + value.replace("\\n", "<br>\n") + "</div></font></td>\n"; |
|
77 |
content += "</tr>\n"; |
|
78 |
return content; |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
protected class BaseTextElement implements TextElement { |
|
83 |
|
|
84 |
protected String value; |
|
85 |
|
|
86 |
@Override |
|
87 |
public TextElement value(String format, Object... args) { |
|
88 |
if (args == null) { |
|
89 |
this.value = StringEscapeUtils.escapeHtml3(format); |
|
90 |
} else { |
|
91 |
this.value = StringEscapeUtils.escapeHtml3(String.format(format, args)); |
|
92 |
} |
|
93 |
return this; |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public String build() { |
|
98 |
String color = ((propertyCount++ % 2) == 0) ? backgroundColorPropertyValue1 : backgroundColorPropertyValue2; |
|
99 |
String content = "<tr valign=\"top\">\n"; |
|
100 |
content += "<td bgcolor=" + color + "align=\"left\" colspan=\"2\"><font face=\"Arial\" size=\"3\">" + value.replace("\n", "<br>\n") + "</font></td>\n"; |
|
101 |
content += "</tr>\n"; |
|
102 |
return content; |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
protected class BasePropertyElement implements PropertyElement { |
|
107 |
|
|
108 |
protected String label; |
|
109 |
protected boolean monospace = false; |
|
110 |
protected String value; |
|
111 |
|
|
112 |
@Override |
|
113 |
public PropertyElement value(String format, Object... args) { |
|
114 |
if (args == null) { |
|
115 |
this.value = StringEscapeUtils.escapeHtml3(format); |
|
116 |
} else { |
|
117 |
this.value = StringEscapeUtils.escapeHtml3(String.format(format, args)); |
|
118 |
} |
|
119 |
return this; |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public PropertyElement label(String label) { |
|
124 |
this.label = StringEscapeUtils.escapeHtml3(label); |
|
125 |
return this; |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public PropertyElement labelkey(String labelkey) { |
|
130 |
return label(ToolsLocator.getI18nManager().getTranslation(labelkey)); |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public PropertyElement monospace() { |
|
135 |
this.monospace = true; |
|
136 |
return this; |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public String build() { |
|
141 |
String color = ((propertyCount++ % 2) == 0) ? backgroundColorPropertyValue1 : backgroundColorPropertyValue2; |
|
142 |
String content = "<tr valign=\"top\">\n"; |
|
143 |
if (!StringUtils.isEmpty(label)) { |
|
144 |
content += "<td nowrap bgcolor=" + backgroundColorPropertyLabel + "align=\"right\" width=\"140\"><font face=\"Arial\" size=\"3\">" + label + ": </font></td>\n"; |
|
145 |
} |
|
146 |
if( this.monospace ) { |
|
147 |
content += "<td bgcolor=" + color + "align=\"left\"><font face=\"Monospaced\" size=\"3\">" + value.replace("\\n", "<br>\n") + "</font></td>"; |
|
148 |
} else { |
|
149 |
content += "<td bgcolor=" + color + "align=\"left\"><font face=\"Arial\" size=\"3\">" + value.replace("\\n", "<br>\n") + "</font></td>"; |
|
150 |
} |
|
151 |
content += "</tr>\n"; |
|
152 |
return content; |
|
153 |
} |
|
154 |
|
|
155 |
} |
|
156 |
|
|
157 |
public BaseInformationBuilder() { |
|
158 |
this.elements = new ArrayList<>(); |
|
159 |
} |
|
160 |
|
|
161 |
@Override |
|
162 |
public InformationBuilder backgroundColor(String color) { |
|
163 |
this.backgroundColor = color; |
|
164 |
return this; |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public InformationBuilder backgroundColorTitle(String color) { |
|
169 |
this.backgroundColorTitle = color; |
|
170 |
return this; |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public InformationBuilder backgroundColorPropertyLabel(String color) { |
|
175 |
this.backgroundColorPropertyLabel = color; |
|
176 |
return this; |
|
177 |
} |
|
178 |
|
|
179 |
@Override |
|
180 |
public InformationBuilder backgroundColorPropertyValue1(String color) { |
|
181 |
this.backgroundColorPropertyValue1 = color; |
|
182 |
return this; |
|
183 |
} |
|
184 |
|
|
185 |
@Override |
|
186 |
public InformationBuilder backgroundColorPropertyValue2(String color) { |
|
187 |
this.backgroundColorPropertyValue2 = color; |
|
188 |
return this; |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public TitleElement title() { |
|
193 |
TitleElement element = new BaseTitleElement(); |
|
194 |
this.elements.add(element); |
|
195 |
return element; |
|
196 |
} |
|
197 |
|
|
198 |
@Override |
|
199 |
public PropertyElement property() { |
|
200 |
PropertyElement element = new BasePropertyElement(); |
|
201 |
this.elements.add(element); |
|
202 |
return element; |
|
203 |
} |
|
204 |
|
|
205 |
@Override |
|
206 |
public TextElement text() { |
|
207 |
TextElement element = new BaseTextElement(); |
|
208 |
this.elements.add(element); |
|
209 |
return element; |
|
210 |
} |
|
211 |
|
|
212 |
@Override |
|
213 |
public RawElement raw() { |
|
214 |
RawElement element = new BaseRawElement(); |
|
215 |
this.elements.add(element); |
|
216 |
return element; |
|
217 |
} |
|
218 |
|
|
219 |
@Override |
|
220 |
public String build() { |
|
221 |
StringBuilder html = new StringBuilder(); |
|
222 |
html.append("<html>\n"); |
|
223 |
html.append("<body bgcolor=").append(backgroundColor).append(" topmargin=\"0\" marginheight=\"0\">\n"); |
|
224 |
html.append("<table cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"100%\">"); |
|
225 |
boolean first = true; |
|
226 |
for (Element element : elements) { |
|
227 |
if( element instanceof TitleElement ) { |
|
228 |
if( first ) { |
|
229 |
first = false; |
|
230 |
} else { |
|
231 |
html.append("<tr>\n<td><br></td>\n<td></td></tr>\n"); |
|
232 |
} |
|
233 |
} |
|
234 |
html.append(element.build()); |
|
235 |
} |
|
236 |
html.append("</table>"); |
|
237 |
html.append("</body>"); |
|
238 |
html.append("</html>"); |
|
239 |
return html.toString(); |
|
240 |
} |
|
241 |
|
|
242 |
@Override |
|
243 |
public String toString() { |
|
244 |
return this.build(); |
|
245 |
} |
|
246 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/tools/util/impl/DefaultToolsUtilManager.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.tools.util.impl; |
|
3 |
|
|
4 |
import org.gvsig.desktopopen.DefaultDesktopOpen; |
|
5 |
import org.gvsig.desktopopen.DesktopOpen; |
|
6 |
import org.gvsig.htmlbuilder.HTMLBuilder; |
|
7 |
import org.gvsig.htmlbuilder.impl.DefaultHTMLBuilder; |
|
8 |
import org.gvsig.tools.util.InformationBuilder; |
|
9 |
import org.gvsig.tools.util.ToolsUtilManager; |
|
10 |
|
|
11 |
|
|
12 |
/** |
|
13 |
* @author fdiaz |
|
14 |
* |
|
15 |
*/ |
|
16 |
public class DefaultToolsUtilManager implements ToolsUtilManager { |
|
17 |
|
|
18 |
@Override |
|
19 |
public InformationBuilder createInformationBuilder() { |
|
20 |
return new BaseInformationBuilder(); |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
public DesktopOpen createDesktopOpen() { |
|
25 |
return new DefaultDesktopOpen(); |
|
26 |
} |
|
27 |
|
|
28 |
public HTMLBuilder createHTMLBuilder() { |
|
29 |
DefaultHTMLBuilder x = new DefaultHTMLBuilder(); |
|
30 |
return x; |
|
31 |
} |
|
32 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/configurableactions/ActionsComponent.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.configurableactions; |
|
3 |
|
|
4 |
import java.awt.event.ActionEvent; |
|
5 |
import java.awt.event.MouseAdapter; |
|
6 |
import java.awt.event.MouseEvent; |
|
7 |
import java.net.URL; |
|
8 |
import java.util.Collection; |
|
9 |
import javax.swing.AbstractAction; |
|
10 |
import javax.swing.Action; |
|
11 |
import javax.swing.ImageIcon; |
|
12 |
import javax.swing.JLabel; |
|
13 |
import javax.swing.JMenuItem; |
|
14 |
import javax.swing.JPopupMenu; |
|
15 |
import org.gvsig.tools.ToolsLocator; |
|
16 |
import org.gvsig.tools.i18n.I18nManager; |
|
17 |
|
|
18 |
|
|
19 |
public class ActionsComponent extends JLabel { |
|
20 |
|
|
21 |
private final Object source; |
|
22 |
private Collection<Action> actions; |
|
23 |
|
|
24 |
private class ActionListenerAdapter extends AbstractAction { |
|
25 |
|
|
26 |
private final Action action; |
|
27 |
|
|
28 |
public ActionListenerAdapter(Action action) { |
|
29 |
this.action = action; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public void actionPerformed(ActionEvent e) { |
|
34 |
e.setSource(source); |
|
35 |
action.actionPerformed(e); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Object getValue(String key) { |
|
40 |
return action.getValue(key); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public void putValue(String key, Object newValue) { |
|
45 |
action.putValue(key, newValue); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public boolean isEnabled() { |
|
50 |
return action.isEnabled(); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public void setEnabled(boolean newValue) { |
|
55 |
action.setEnabled(newValue); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
60 |
public ActionsComponent(Collection<Action> actions, Object source) { |
|
61 |
this.source = source; |
|
62 |
this.update(actions); |
|
63 |
this.initComponent(); |
|
64 |
} |
|
65 |
|
|
66 |
private void initComponent() { |
|
67 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
68 |
this.setToolTipText(i18n.getTranslation("_Click_to_see_more_action_in_this_panel")); |
|
69 |
URL url = this.getClass().getResource("/org/gvsig/configurableactions/images/configurableactions.png"); |
|
70 |
this.setIcon(new ImageIcon(url)); |
|
71 |
this.setBorder(null); |
|
72 |
this.addMouseListener(new MouseAdapter() { |
|
73 |
@Override |
|
74 |
public void mouseClicked(MouseEvent e) { |
|
75 |
if( e.getClickCount()==1 && e.getButton()==MouseEvent.BUTTON1 ) { |
|
76 |
doShowMenu(); |
|
77 |
} |
|
78 |
} |
|
79 |
}); |
|
80 |
// this.addActionListener(new ActionListener() { |
|
81 |
// @Override |
|
82 |
// public void actionPerformed(ActionEvent e) { |
|
83 |
// doShowMenu(); |
|
84 |
// } |
|
85 |
// }); |
|
86 |
} |
|
87 |
|
|
88 |
public void update(Collection<Action> actions) { |
|
89 |
this.actions = actions; |
|
90 |
if( actions==null || actions.isEmpty() ) { |
|
91 |
this.setVisible(false); |
|
92 |
} else { |
|
93 |
this.setVisible(true); |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
private void doShowMenu() { |
|
98 |
JPopupMenu menu = new JPopupMenu(); |
|
99 |
for (Action action : actions) { |
|
100 |
JMenuItem item = new JMenuItem(new ActionListenerAdapter(action)); |
|
101 |
menu.add(item); |
|
102 |
} |
|
103 |
menu.show(this, 0,this.getHeight()); |
|
104 |
} |
|
105 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/configurableactions/DefaultConfigurableActionsMamager.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.configurableactions; |
|
3 |
|
|
4 |
import java.lang.ref.WeakReference; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.Collection; |
|
7 |
import java.util.HashMap; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Map; |
|
10 |
import javax.swing.Action; |
|
11 |
import javax.swing.JComponent; |
|
12 |
import org.apache.commons.lang3.StringUtils; |
|
13 |
|
|
14 |
|
|
15 |
public class DefaultConfigurableActionsMamager implements ConfigurableActionsMamager { |
|
16 |
|
|
17 |
private class PanelActions { |
|
18 |
List<Action> actions; |
|
19 |
WeakReference<ActionsComponent> component; |
|
20 |
private final String panelid; |
|
21 |
|
|
22 |
public PanelActions(String panelid) { |
|
23 |
this.panelid = panelid; |
|
24 |
this.actions = new ArrayList<>(); |
|
25 |
} |
|
26 |
|
|
27 |
public void setComponent(ActionsComponent component) { |
|
28 |
this.component = new WeakReference<>(component); |
|
29 |
} |
|
30 |
|
|
31 |
public ActionsComponent getComponent() { |
|
32 |
if( this.component == null ) { |
|
33 |
return null; |
|
34 |
} |
|
35 |
ActionsComponent component = this.component.get(); |
|
36 |
return component; |
|
37 |
} |
|
38 |
|
|
39 |
public void updateComponent() { |
|
40 |
ActionsComponent component = this.getComponent(); |
|
41 |
if( component == null ) { |
|
42 |
return; |
|
43 |
} |
|
44 |
component.update(actions); |
|
45 |
} |
|
46 |
|
|
47 |
public int size() { |
|
48 |
return this.actions.size(); |
|
49 |
} |
|
50 |
|
|
51 |
public Action get(int i) { |
|
52 |
return this.actions.get(i); |
|
53 |
} |
|
54 |
|
|
55 |
public void set(int i, Action action) { |
|
56 |
this.actions.set(i, action); |
|
57 |
this.updateComponent(); |
|
58 |
} |
|
59 |
|
|
60 |
public void add(Action action) { |
|
61 |
this.actions.add(action); |
|
62 |
this.updateComponent(); |
|
63 |
} |
|
64 |
|
|
65 |
public void remove(int i) { |
|
66 |
this.actions.remove(i); |
|
67 |
this.updateComponent(); |
|
68 |
} |
|
69 |
|
|
70 |
public Collection<Action> getActions() { |
|
71 |
return this.actions; |
|
72 |
} |
|
73 |
|
|
74 |
private void removeAll() { |
|
75 |
this.actions.clear(); |
|
76 |
this.updateComponent(); |
|
77 |
} |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
private Map<String,PanelActions> panelsActions; |
|
82 |
|
|
83 |
|
|
84 |
public DefaultConfigurableActionsMamager() { |
|
85 |
this.panelsActions = new HashMap<>(); |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public void addConfigurableAction(String panelid, Action action) { |
|
90 |
PanelActions panelActions = this.panelsActions.get(panelid); |
|
91 |
if( panelActions==null ) { |
|
92 |
panelActions = new PanelActions(panelid); |
|
93 |
this.panelsActions.put(panelid, panelActions); |
|
94 |
} |
|
95 |
for( int i=0; i<panelActions.size(); i++ ) { |
|
96 |
Action currentAction = panelActions.get(i); |
|
97 |
if( StringUtils.equalsIgnoreCase( |
|
98 |
(String)currentAction.getValue(Action.ACTION_COMMAND_KEY), |
|
99 |
(String)action.getValue(Action.ACTION_COMMAND_KEY) ) ) { |
|
100 |
panelActions.set(i, action); |
|
101 |
return; |
|
102 |
} |
|
103 |
} |
|
104 |
panelActions.add(action); |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public void removeConfigurableAction(String panelid, String actionName) { |
|
109 |
PanelActions panelActions = this.panelsActions.get(panelid); |
|
110 |
if( panelActions==null ) { |
|
111 |
return; |
|
112 |
} |
|
113 |
for( int i=0; i<panelActions.size(); i++ ) { |
|
114 |
Action currentAction = panelActions.get(i); |
|
115 |
if( StringUtils.equalsIgnoreCase( |
|
116 |
(String)currentAction.getValue(Action.ACTION_COMMAND_KEY), |
|
117 |
actionName ) ) { |
|
118 |
panelActions.remove(i); |
|
119 |
return; |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public void removeAllConfigurableActions(String panelid) { |
|
126 |
PanelActions panelActions = this.panelsActions.get(panelid); |
|
127 |
if( panelActions==null ) { |
|
128 |
return; |
|
129 |
} |
|
130 |
panelActions.removeAll(); |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public Collection<Action> getConfigurableActions(String panelid) { |
|
135 |
PanelActions panelActions = this.panelsActions.get(panelid); |
|
136 |
if( panelActions==null ) { |
|
137 |
panelActions = new PanelActions(panelid); |
|
138 |
this.panelsActions.put(panelid, panelActions); |
|
139 |
} |
|
140 |
return panelActions.getActions(); |
|
141 |
} |
|
142 |
|
|
143 |
@Override |
|
144 |
public JComponent getConfigurableActionsComponent(String panelid, Object source) { |
|
145 |
PanelActions panelActions = this.panelsActions.get(panelid); |
|
146 |
if( panelActions==null ) { |
|
147 |
panelActions = new PanelActions(panelid); |
|
148 |
this.panelsActions.put(panelid, panelActions); |
|
149 |
} |
|
150 |
ActionsComponent component = new ActionsComponent(panelActions.getActions(), source); |
|
151 |
panelActions.setComponent(component); |
|
152 |
return component; |
|
153 |
} |
|
154 |
|
|
155 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/propertypage/impl/DefaultPropertiesPageManager.java | ||
---|---|---|
1 |
package org.gvsig.propertypage.impl; |
|
2 |
|
|
3 |
import java.awt.event.ActionEvent; |
|
4 |
import java.lang.reflect.InvocationTargetException; |
|
5 |
import java.lang.reflect.Method; |
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.Collection; |
|
8 |
import java.util.Collections; |
|
9 |
import java.util.Comparator; |
|
10 |
import java.util.HashMap; |
|
11 |
import java.util.List; |
|
12 |
import java.util.Map; |
|
13 |
import org.apache.commons.lang3.StringUtils; |
|
14 |
import org.gvsig.propertypage.PropertiesPage; |
|
15 |
import org.gvsig.propertypage.PropertiesPage.SetPageEnabledEvent; |
|
16 |
import org.gvsig.propertypage.PropertiesPageFactory; |
|
17 |
import org.gvsig.propertypage.PropertiesPageManager; |
|
18 |
import org.gvsig.tools.ToolsLocator; |
|
19 |
import org.gvsig.tools.identitymanagement.SimpleIdentity; |
|
20 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
|
21 |
import org.gvsig.tools.util.Invocable; |
|
22 |
import org.slf4j.Logger; |
|
23 |
import org.slf4j.LoggerFactory; |
|
24 |
|
|
25 |
public class DefaultPropertiesPageManager implements PropertiesPageManager { |
|
26 |
|
|
27 |
private static class DefaultSetPageEnabledEvent extends ActionEvent { |
|
28 |
|
|
29 |
private Invocable filter; |
|
30 |
private boolean enabled; |
|
31 |
|
|
32 |
public DefaultSetPageEnabledEvent(Object source, Invocable filter, boolean enabled ) { |
|
33 |
super(source, SetPageEnabledEvent.ID, SetPageEnabledEvent.ACTION_COMMAND); |
|
34 |
this.filter = filter; |
|
35 |
this.enabled = enabled; |
|
36 |
} |
|
37 |
|
|
38 |
public Invocable getFilter() { |
|
39 |
return filter; |
|
40 |
} |
|
41 |
|
|
42 |
public boolean isEnabled() { |
|
43 |
return enabled; |
|
44 |
} |
|
45 |
|
|
46 |
} |
|
47 |
|
|
48 |
public static final String ACCESS_PAGE_AUTHORIZATION = "propertypage-access"; |
|
49 |
|
|
50 |
private static final Logger logger = LoggerFactory.getLogger(DefaultPropertiesPageManager.class); |
|
51 |
|
|
52 |
private final Map<String, Map<String, PropertiesPageFactory>> groups = new HashMap<>(); |
|
53 |
|
|
54 |
public DefaultPropertiesPageManager() { |
|
55 |
|
|
56 |
} |
|
57 |
|
|
58 |
private String getFactoryName(PropertiesPageFactory factory) { |
|
59 |
String factoryName = factory.getClass().getName(); |
|
60 |
try { |
|
61 |
factoryName = factory.getName(); |
|
62 |
} catch(Throwable ex) { |
|
63 |
|
|
64 |
} |
|
65 |
return factoryName; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public void registerFactory(PropertiesPageFactory factory) { |
|
70 |
logger.info("Register PropertisPageFactory " + factory.getClass().getName() + " , groupID=" + factory.getGroupID() + " (" + factory.toString() + ")."); |
|
71 |
Map<String, PropertiesPageFactory> group = this.getFactories(factory.getGroupID()); |
|
72 |
group.put(getFactoryName(factory), factory); |
|
73 |
} |
|
74 |
|
|
75 |
private Map<String, PropertiesPageFactory> getFactories(String groupID) { |
|
76 |
logger.info("get propeties page factories for groupID '" + groupID + "'"); |
|
77 |
Map<String,PropertiesPageFactory> group = this.groups.get(groupID); |
|
78 |
if (group == null) { |
|
79 |
group = new HashMap<>(); |
|
80 |
this.groups.put(groupID, group); |
|
81 |
} |
|
82 |
return group; |
|
83 |
} |
|
84 |
|
|
85 |
@Override |
|
86 |
public List<PropertiesPage> getPages(String groupID, Object container, Object data) { |
|
87 |
logger.info("get propeties page for groupID '" + groupID + "', and object '" + ((data==null)?"null":data.toString()) + "'."); |
|
88 |
List<PropertiesPage> pages = new ArrayList<>(); |
|
89 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
|
90 |
SimpleIdentity currentUser = identityManager.getCurrentIdentity(); |
|
91 |
if (!currentUser.isAuthorized(ACCESS_PAGE_AUTHORIZATION,null,groupID ) ) { |
|
92 |
return pages; // Empty list, no access to pages authoriced |
|
93 |
} |
|
94 |
|
|
95 |
Collection<PropertiesPageFactory> factories = this.getFactories(groupID).values(); |
|
96 |
String authorizationId = ACCESS_PAGE_AUTHORIZATION+"-"+groupID; |
|
97 |
for (PropertiesPageFactory factory : factories) { |
|
98 |
String factoryName = getFactoryName(factory); |
|
99 |
try { |
|
100 |
if (factory.isVisible(data)) { |
|
101 |
PropertiesPage page = createPage(factory, container, data); |
|
102 |
if (currentUser.isAuthorized(authorizationId,page, page.getTitle()) ) { |
|
103 |
pages.add(page); |
|
104 |
} |
|
105 |
} |
|
106 |
} catch(Throwable ex) { |
|
107 |
logger.warn("Can't get properties page from factory '"+factoryName+"'.",ex); |
|
108 |
} |
|
109 |
} |
|
110 |
Collections.sort(pages, new Comparator<PropertiesPage>() { |
|
111 |
@Override |
|
112 |
public int compare(PropertiesPage f1, PropertiesPage f2) { |
|
113 |
int n = f2.getPriority() - f1.getPriority(); |
|
114 |
if (n != 0) { |
|
115 |
return n; |
|
116 |
} |
|
117 |
return StringUtils.compareIgnoreCase(f1.getTitle(), f2.getTitle()); |
|
118 |
} |
|
119 |
}); |
|
120 |
return pages; |
|
121 |
} |
|
122 |
|
|
123 |
private PropertiesPage createPage(PropertiesPageFactory factory, Object container, Object data) |
|
124 |
throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException |
|
125 |
{ |
|
126 |
PropertiesPage page; |
|
127 |
try { |
|
128 |
page = factory.create(container, data); |
|
129 |
return page; |
|
130 |
} catch(AbstractMethodError ex) { |
|
131 |
} |
|
132 |
// Antes factory.create llevaba solo un argumento, data. Probamos |
|
133 |
// invocando a ese create. |
|
134 |
Method method = factory.getClass().getMethod("create", Object.class); |
|
135 |
page = (PropertiesPage) method.invoke(factory, data); |
|
136 |
return page; |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public ActionEvent createSetPageEnableEvent(PropertiesPage source, Invocable filter, boolean enabled) { |
|
141 |
return new DefaultSetPageEnabledEvent(source, filter, enabled); |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public ActionEvent createSetPageEnableEvent(final PropertiesPage source, final Class filterClass, final boolean enabled) { |
|
146 |
return new DefaultSetPageEnabledEvent( |
|
147 |
source, |
|
148 |
new Invocable() { |
|
149 |
@Override |
|
150 |
public Object call(Object... propertiesPages) { |
|
151 |
return filterClass.isInstance(propertiesPages[0]); |
|
152 |
} |
|
153 |
}, |
|
154 |
enabled |
|
155 |
); |
|
156 |
} |
|
157 |
|
|
158 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/filedialogchooser/impl/VFSJFileChooserBased.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.filedialogchooser.impl; |
|
7 |
|
|
8 |
import com.googlecode.vfsjfilechooser2.VFSJFileChooser; |
|
9 |
import com.googlecode.vfsjfilechooser2.filechooser.AbstractVFSFileFilter; |
|
10 |
import java.awt.Component; |
|
11 |
import java.beans.PropertyChangeListener; |
|
12 |
import java.io.File; |
|
13 |
import javax.swing.JComponent; |
|
14 |
import javax.swing.filechooser.FileFilter; |
|
15 |
import org.apache.commons.vfs2.FileObject; |
|
16 |
import org.apache.commons.vfs2.provider.local.LocalFile; |
|
17 |
import org.gvsig.filedialogchooser.FileDialogChooser; |
|
18 |
import org.gvsig.filedialogchooser.FileDialogChooserManager; |
|
19 |
import org.gvsig.tools.util.ToolsUtilLocator; |
|
20 |
|
|
21 |
|
|
22 |
public class VFSJFileChooserBased implements FileDialogChooser { |
|
23 |
|
|
24 |
private static class FileFilterAdapter extends AbstractVFSFileFilter { |
|
25 |
|
|
26 |
private final FileFilter filter; |
|
27 |
|
|
28 |
FileFilterAdapter(FileFilter filter) { |
|
29 |
this.filter = filter; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public boolean accept(FileObject f) { |
|
34 |
if( f instanceof LocalFile ) { |
|
35 |
return this.filter.accept( new File(f.getName().getPath())); |
|
36 |
} |
|
37 |
return false; |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public String getDescription() { |
|
42 |
return this.filter.getDescription(); |
|
43 |
} |
|
44 |
|
|
45 |
public FileFilter getFilter() { |
|
46 |
return this.filter; |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
private final VFSJFileChooser jfc; |
|
51 |
private final String fileChooserID; |
|
52 |
|
|
53 |
public VFSJFileChooserBased(String fileChooserID) { |
|
54 |
super(); |
|
55 |
this.jfc = new VFSJFileChooser(); |
|
56 |
this.fileChooserID = fileChooserID; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public void setCurrentDirectory(File dir) { |
|
61 |
if( dir == null ) { |
|
62 |
dir = new File(System.getProperty("user.home")); |
|
63 |
} |
|
64 |
this.jfc.setCurrentDirectory(dir); |
|
65 |
} |
|
66 |
|
|
67 |
@Override |
|
68 |
public File getCurrentDirectory() { |
|
69 |
return this.jfc.getCurrentDirectory(); |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public void setDialogTitle(String dialogTitle) { |
|
74 |
this.jfc.setDialogTitle(dialogTitle); |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public void setDialogType(int dialogType) { |
|
79 |
switch(dialogType) { |
|
80 |
default: |
|
81 |
case OPEN_DIALOG: |
|
82 |
this.jfc.setDialogType(VFSJFileChooser.DIALOG_TYPE.OPEN); |
|
83 |
break; |
|
84 |
case SAVE_DIALOG: |
|
85 |
this.jfc.setDialogType(VFSJFileChooser.DIALOG_TYPE.SAVE); |
|
86 |
break; |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public void setDragEnabled(boolean b) { |
|
92 |
this.jfc.setDragEnabled(b); |
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
public void setFileFilter(FileFilter filter) { |
|
97 |
if( filter == null ) { |
|
98 |
this.jfc.setFileFilter(null); |
|
99 |
} else { |
|
100 |
this.jfc.setFileFilter(new FileFilterAdapter(filter)); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public FileFilter getFileFilter() { |
|
106 |
FileFilterAdapter f = (FileFilterAdapter) this.jfc.getFileFilter(); |
|
107 |
return f.getFilter(); |
|
108 |
} |
|
109 |
|
|
110 |
@Override |
|
111 |
public void setFileSelectionMode(int mode) { |
|
112 |
switch(mode) { |
|
113 |
case FILES_ONLY: |
|
114 |
this.jfc.setFileSelectionMode(VFSJFileChooser.SELECTION_MODE.FILES_ONLY); |
|
115 |
break; |
|
116 |
case DIRECTORIES_ONLY: |
|
117 |
this.jfc.setFileSelectionMode(VFSJFileChooser.SELECTION_MODE.DIRECTORIES_ONLY); |
|
118 |
break; |
|
119 |
default: |
|
120 |
case FILES_AND_DIRECTORIES: |
|
121 |
this.jfc.setFileSelectionMode(VFSJFileChooser.SELECTION_MODE.FILES_AND_DIRECTORIES); |
|
122 |
break; |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public File getSelectedFile() { |
|
128 |
return this.jfc.getSelectedFile(); |
|
129 |
} |
|
130 |
|
|
131 |
@Override |
|
132 |
public File[] getSelectedFiles() { |
|
133 |
return this.jfc.getSelectedFiles(); |
|
134 |
} |
|
135 |
|
|
136 |
@Override |
|
137 |
public void setFileHidingEnabled(boolean b) { |
|
138 |
this.jfc.setFileHidingEnabled(b); |
|
139 |
} |
|
140 |
|
|
141 |
@Override |
|
142 |
public void setMultiSelectionEnabled(boolean b) { |
|
143 |
this.jfc.setMultiSelectionEnabled(b); |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public boolean isMultiSelectionEnabled() { |
|
148 |
return this.jfc.isMultiSelectionEnabled(); |
|
149 |
} |
|
150 |
|
|
151 |
@Override |
|
152 |
public int showOpenDialog(Component parent) { |
|
153 |
FileDialogChooserManager manager = ToolsUtilLocator.getFileDialogChooserManager(); |
|
154 |
File f = this.getCurrentDirectory(); |
|
155 |
if( f==null ) { |
|
156 |
f = manager.getLastPath(fileChooserID, null); |
|
157 |
this.jfc.setCurrentDirectory(f); |
|
158 |
} |
|
159 |
VFSJFileChooser.RETURN_TYPE r = this.jfc.showOpenDialog(parent); |
|
160 |
if( r == VFSJFileChooser.RETURN_TYPE.CANCEL ) { |
|
161 |
return CANCEL_OPTION; |
|
162 |
} |
|
163 |
if( r == VFSJFileChooser.RETURN_TYPE.APPROVE ) { |
|
164 |
manager.setLastPath(fileChooserID, this.getCurrentDirectory()); |
|
165 |
return APPROVE_OPTION; |
|
166 |
} |
|
167 |
if( r == VFSJFileChooser.RETURN_TYPE.ERROR ) { |
|
168 |
return ERROR_OPTION; |
|
169 |
} |
|
170 |
return ERROR_OPTION; |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public int showSaveDialog(Component parent) { |
|
175 |
FileDialogChooserManager manager = ToolsUtilLocator.getFileDialogChooserManager(); |
|
176 |
File f = manager.getLastPath(fileChooserID, this.getCurrentDirectory()); |
|
177 |
this.jfc.setCurrentDirectory(f); |
|
178 |
VFSJFileChooser.RETURN_TYPE r = this.jfc.showSaveDialog(parent); |
|
179 |
if( r == VFSJFileChooser.RETURN_TYPE.CANCEL ) { |
|
180 |
return CANCEL_OPTION; |
|
181 |
} |
|
182 |
if( r == VFSJFileChooser.RETURN_TYPE.APPROVE ) { |
|
183 |
manager.setLastPath(fileChooserID, this.getCurrentDirectory()); |
|
184 |
return APPROVE_OPTION; |
|
185 |
} |
|
186 |
if( r == VFSJFileChooser.RETURN_TYPE.ERROR ) { |
|
187 |
return ERROR_OPTION; |
|
188 |
} |
|
189 |
return ERROR_OPTION; |
|
190 |
} |
|
191 |
|
|
192 |
@Override |
|
193 |
public void setAcceptAllFileFilterUsed(boolean b) { |
|
194 |
this.jfc.setAcceptAllFileFilterUsed(b); |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public void addChoosableFileFilter(FileFilter next) { |
|
199 |
this.jfc.addChoosableFileFilter(new FileFilterAdapter(next)); |
|
200 |
} |
|
201 |
|
|
202 |
@Override |
|
203 |
public void addPropertyChangeListener(PropertyChangeListener listener) { |
|
204 |
this.jfc.addPropertyChangeListener(listener); |
|
205 |
} |
|
206 |
|
|
207 |
@Override |
|
208 |
public void setAccessory(JComponent newAccessory) { |
|
209 |
this.jfc.setAccessory(newAccessory); |
|
210 |
} |
|
211 |
|
|
212 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/filedialogchooser/impl/JFileChooserBased.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.filedialogchooser.impl; |
|
7 |
|
|
8 |
import java.awt.Component; |
|
9 |
import java.awt.HeadlessException; |
|
10 |
import java.io.File; |
|
11 |
import javax.swing.JFileChooser; |
|
12 |
import org.gvsig.filedialogchooser.FileDialogChooser; |
|
13 |
import org.gvsig.filedialogchooser.FileDialogChooserManager; |
|
14 |
import org.gvsig.tools.util.ToolsUtilLocator; |
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
public class JFileChooserBased extends JFileChooser implements FileDialogChooser { |
|
20 |
|
|
21 |
private static final long serialVersionUID = 2825200958209418322L; |
|
22 |
private final String fileChooserID; |
|
23 |
|
|
24 |
public JFileChooserBased(String fileChooserID) { |
|
25 |
super(); |
|
26 |
this.fileChooserID = fileChooserID; |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
public int showOpenDialog(Component parent) throws HeadlessException { |
|
31 |
FileDialogChooserManager manager = ToolsUtilLocator.getFileDialogChooserManager(); |
|
32 |
File f = this.getCurrentDirectory(); |
|
33 |
if( f==null ) { |
|
34 |
f = manager.getLastPath(fileChooserID, null); |
|
35 |
super.setCurrentDirectory(f); |
|
36 |
} |
|
37 |
int r = super.showOpenDialog(parent); |
|
38 |
if( r == JFileChooser.APPROVE_OPTION ) { |
|
39 |
manager.setLastPath(fileChooserID, this.getCurrentDirectory()); |
|
40 |
} |
|
41 |
return r; |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public int showSaveDialog(Component parent) throws HeadlessException { |
|
46 |
FileDialogChooserManager manager = ToolsUtilLocator.getFileDialogChooserManager(); |
|
47 |
File f = manager.getLastPath(fileChooserID, this.getCurrentDirectory()); |
|
48 |
super.setCurrentDirectory(f); int r = super.showSaveDialog(parent); |
|
49 |
if( r == JFileChooser.APPROVE_OPTION ) { |
|
50 |
manager.setLastPath(fileChooserID, this.getCurrentDirectory()); |
|
51 |
} |
|
52 |
return r; |
|
53 |
} |
|
54 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/filedialogchooser/impl/DefaultFileDialogChooserManager.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.filedialogchooser.impl; |
|
3 |
|
|
4 |
import java.io.File; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.Map; |
|
7 |
import org.gvsig.filedialogchooser.FileDialogChooser; |
|
8 |
import org.gvsig.filedialogchooser.FileDialogChooserManager; |
|
9 |
import org.gvsig.tools.ToolsLocator; |
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
public class DefaultFileDialogChooserManager implements FileDialogChooserManager { |
|
14 |
|
|
15 |
private Map<String,File> lastPaths; |
|
16 |
private boolean useNativeFileChooser = true; |
|
17 |
|
|
18 |
public DefaultFileDialogChooserManager() { |
|
19 |
this.lastPaths = new HashMap<>(); |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
public void setUseNativeFileChooser(boolean b) { |
|
24 |
useNativeFileChooser = b; |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public boolean useNativeFileChooser() { |
|
29 |
return useNativeFileChooser; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public FileDialogChooser create(String fileChooserID) { |
|
34 |
if( useNativeFileChooser ) { |
|
35 |
return new JFileChooserBased(fileChooserID); |
|
36 |
} |
|
37 |
return new VFSJFileChooserBased(fileChooserID); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public FileDialogChooser create() { |
|
42 |
String fileChooserID = "DEFAULT_ID"; |
|
43 |
if( useNativeFileChooser ) { |
|
44 |
return new JFileChooserBased(fileChooserID); |
|
45 |
} |
|
46 |
return new VFSJFileChooserBased(fileChooserID); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public File getLastPath(String fileChooserID, File defaultDirectory) { |
|
51 |
return ToolsLocator.getFoldersManager().getLastPath(fileChooserID, defaultDirectory); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public void setLastPath(String fileChooserID, File path) { |
|
56 |
ToolsLocator.getFoldersManager().setLastPath(fileChooserID, path); |
|
57 |
} |
|
58 |
|
|
59 |
|
|
60 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/imageviewer/DefaultImageViewerManager.java | ||
---|---|---|
1 |
package org.gvsig.imageviewer; |
|
2 |
|
|
3 |
|
|
4 |
public class DefaultImageViewerManager implements ImageViewerManager { |
|
5 |
|
|
6 |
@Override |
|
7 |
public ImageViewer createImageViewer() { |
|
8 |
return new DefaultImageViewer(); |
|
9 |
} |
|
10 |
|
|
11 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/imageviewer/DefaultImageViewer.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.imageviewer; |
|
3 |
|
|
4 |
import java.awt.BorderLayout; |
|
5 |
import java.awt.Dimension; |
|
6 |
import java.awt.Image; |
|
7 |
import java.io.File; |
|
8 |
import java.net.URL; |
|
9 |
import javax.swing.ImageIcon; |
|
10 |
import javax.swing.JComponent; |
|
11 |
import javax.swing.JLabel; |
|
12 |
import javax.swing.JPanel; |
|
13 |
|
|
14 |
|
|
15 |
@SuppressWarnings("UseSpecificCatch") |
|
16 |
public class DefaultImageViewer extends JPanel implements ImageViewer { |
|
17 |
|
|
18 |
private JLabel label; |
|
19 |
|
|
20 |
public DefaultImageViewer() { |
|
21 |
this.initComponents(); |
|
22 |
} |
|
23 |
|
|
24 |
private void initComponents() { |
|
25 |
this.label = new JLabel(); |
|
26 |
this.setLayout(new BorderLayout()); |
|
27 |
this.add(this.label, BorderLayout.CENTER); |
|
28 |
|
|
29 |
this.setPreferredSize( new Dimension(200,350)); |
|
30 |
} |
|
31 |
|
|
32 |
private void setImage(ImageIcon image) { |
|
33 |
this.label.setIcon(image); |
|
34 |
this.setPreferredSize(new Dimension(image.getIconWidth(), image.getIconHeight())); |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public void setImage(URL image) { |
|
39 |
ImageIcon img = new ImageIcon(image); |
|
40 |
this.setImage(img); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public void setImage(File image) { |
|
45 |
try { |
|
46 |
this.setImage(image.toURI().toURL()); |
|
47 |
} catch(Exception ex) { |
|
48 |
throw new IllegalArgumentException(ex); |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public void setImage(Image image) { |
|
54 |
ImageIcon img = new ImageIcon(image); |
|
55 |
this.setImage(img); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public JComponent asJComponent() { |
|
60 |
return this; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public void clean() { |
|
65 |
this.label.setIcon(null); |
|
66 |
} |
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.234/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/simplehttpservice/SimpleServerImpl.java | ||
---|---|---|
1 |
package org.gvsig.simplehttpservice; |
|
2 |
|
|
3 |
import java.net.MalformedURLException; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.HashSet; |
|
7 |
import java.util.LinkedHashMap; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Map; |
|
10 |
import java.util.Set; |
|
11 |
import java.util.concurrent.TimeUnit; |
|
12 |
import org.apache.commons.lang3.StringUtils; |
|
13 |
import org.apache.http.ExceptionLogger; |
|
14 |
import org.apache.http.impl.nio.bootstrap.HttpServer; |
|
15 |
import org.apache.http.impl.nio.bootstrap.ServerBootstrap; |
|
16 |
import org.apache.http.impl.nio.reactor.IOReactorConfig; |
|
17 |
import org.gvsig.simplehttpservice.commands.Command; |
|
18 |
import org.gvsig.simplehttpservice.commands.CommandFactory; |
|
19 |
import org.slf4j.Logger; |
|
20 |
import org.slf4j.LoggerFactory; |
|
21 |
|
|
22 |
@SuppressWarnings("UseSpecificCatch") |
|
23 |
public class SimpleServerImpl implements SimpleServer { |
|
24 |
|
|
25 |
private static final Logger LOG = LoggerFactory.getLogger(SimpleServerImpl.class); |
|
26 |
|
|
27 |
private static final List<HttpServer> SERVERS = new ArrayList<>(); |
|
28 |
|
|
29 |
static { |
|
30 |
|
|
31 |
Runtime.getRuntime().addShutdownHook(new Thread() { |
|
32 |
@Override |
|
33 |
public void run() { |
|
34 |
for (HttpServer server : SERVERS) { |
|
35 |
server.shutdown(5, TimeUnit.SECONDS); |
|
36 |
} |
|
37 |
} |
|
38 |
}); |
|
39 |
} |
|
40 |
|
|
41 |
private HttpServer server; |
|
42 |
private final Set<LoggerListener> loglisteners; |
|
43 |
private Map<String, Command> commands; |
|
44 |
private final SimpleServerConfig config; |
|
45 |
|
|
46 |
public SimpleServerImpl(SimpleServerConfig config) { |
|
47 |
this.config = config; |
|
48 |
this.loglisteners = new HashSet<>(); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public Map<String, Command> getCommands() { |
|
53 |
if (this.commands == null) { |
|
54 |
Map<String, Command>theCommands = new LinkedHashMap<>(); |
|
55 |
for (CommandFactory factory : this.config.getCommandFactories()) { |
|
56 |
theCommands.put(factory.getName(), factory.create(this)); |
|
57 |
} |
|
58 |
this.commands = theCommands; |
|
59 |
} |
|
60 |
return this.commands; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public Command getCommand(String commandName) { |
|
65 |
if (commandName == null) { |
|
66 |
return null; |
|
67 |
} |
|
68 |
Command command = this.getCommands().get(commandName.toLowerCase()); |
|
69 |
return command; |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public SimpleServerConfig getConfig() { |
|
74 |
return this.config; |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public void addLogListener(LoggerListener logger) { |
|
79 |
this.loglisteners.add(logger); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public void removeLogListener(LoggerListener logger) { |
|
84 |
this.loglisteners.remove(logger); |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public URL getURL(String path) { |
|
89 |
if( StringUtils.isBlank(path) ) { |
|
90 |
return null; |
|
91 |
} |
|
92 |
try { |
|
93 |
URL url = new URL("http", "localhost", this.config.getPort(),path); |
|
94 |
return url; |
|
95 |
} catch (MalformedURLException ex) { |
|
96 |
return null; |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
@Override |
|
101 |
public String getHost() { |
|
102 |
String host = "http://localhost:" + this.config.getPort(); |
|
103 |
return host; |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public void log(int level, String message) { |
|
108 |
switch (level) { |
|
109 |
default: |
|
110 |
case INFO: |
|
111 |
LOG.info(message); |
|
112 |
break; |
|
113 |
case WARN: |
|
114 |
LOG.warn(message); |
|
115 |
break; |
|
116 |
case DEBUG: |
|
117 |
LOG.debug(message); |
|
118 |
break; |
Also available in: Unified diff