Revision 1082
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/resources-plugin/config.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
2 | 2 |
<plugin-config> |
3 | 3 |
<depends plugin-name="org.gvsig.app.mainplugin" /> |
4 |
<depends plugin-name="org.gvsig.pdf.app.mainplugin" /> |
|
4 | 5 |
<resourceBundle name="text"/> |
5 | 6 |
<libraries library-dir="lib"/> |
6 | 7 |
<extensions> |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/AbstractHyperLinkPanel.java | ||
---|---|---|
19 | 19 |
* MA 02110-1301, USA. |
20 | 20 |
* |
21 | 21 |
*/ |
22 |
|
|
23 | 22 |
package org.gvsig.hyperlink.app.extension; |
24 | 23 |
|
25 | 24 |
import java.io.File; |
... | ... | |
32 | 31 |
|
33 | 32 |
import org.gvsig.andami.PluginServices; |
34 | 33 |
import org.gvsig.andami.messages.NotificationManager; |
34 |
import org.gvsig.tools.util.URLUtils; |
|
35 | 35 |
import org.slf4j.Logger; |
36 | 36 |
import org.slf4j.LoggerFactory; |
37 | 37 |
|
... | ... | |
45 | 45 |
*/ |
46 | 46 |
public abstract class AbstractHyperLinkPanel extends JPanel { |
47 | 47 |
|
48 |
protected static final Logger logger = LoggerFactory.getLogger(AbstractHyperLinkPanel.class);
|
|
49 |
|
|
48 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractHyperLinkPanel.class);
|
|
49 |
|
|
50 | 50 |
protected LinkTarget document; |
51 | 51 |
|
52 | 52 |
public AbstractHyperLinkPanel(LinkTarget linkTarget) { |
... | ... | |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
/** |
62 |
* Tries to make an absolute url from a relative one, |
|
63 |
* and returns true if the URL is valid. |
|
64 |
* false otherwise |
|
65 |
* |
|
62 |
* Tries to make an absolute url from a relative one, and returns true if |
|
63 |
* the URL is valid. false otherwise |
|
64 |
* |
|
66 | 65 |
* @return |
67 | 66 |
*/ |
68 | 67 |
protected boolean checkAndNormalizeURI() { |
69 | 68 |
if (document == null) { |
70 |
PluginServices.getLogger().warn(PluginServices.getText(this, |
|
71 |
"Hyperlink_linked_field_doesnot_exist")); |
|
69 |
LOGGER.warn("Hyperlink linked field does not exits"); |
|
72 | 70 |
return false; |
73 |
} else if (document.getURL()!=null) {
|
|
71 |
} else if (document.getURL() != null) {
|
|
74 | 72 |
try { |
75 | 73 |
if (!document.getURL().toURI().isAbsolute()) { |
76 | 74 |
try { |
77 | 75 |
// try as a relative path |
78 |
File file = |
|
79 |
new File(document.toString()).getCanonicalFile(); |
|
76 |
File file = this.document.toFile(); |
|
77 |
if (file == null) { |
|
78 |
LOGGER.warn("Hyperlink can't get file from '" + this.document.getURL() + "'."); |
|
79 |
return false; |
|
80 |
} |
|
81 |
file = file.getCanonicalFile(); |
|
80 | 82 |
if (!file.exists()) { |
81 |
PluginServices.getLogger() |
|
82 |
.warn(PluginServices.getText(this, |
|
83 |
"Hyperlink_linked_field_doesnot_exist")); |
|
83 |
LOGGER.warn("Hyperlink linked field, file '"+file+"' not exits"); |
|
84 | 84 |
return false; |
85 | 85 |
} |
86 |
document.setURL(file.toURI().toURL());
|
|
86 |
document.setURL(URLUtils.toURL(file));
|
|
87 | 87 |
return true; |
88 | 88 |
} catch (IOException e) { |
89 |
PluginServices.getLogger() |
|
90 |
.warn(PluginServices.getText(this, |
|
91 |
"Hyperlink_linked_field_doesnot_exist")); |
|
89 |
LOGGER.warn("Hyperlink linked field does not exits"); |
|
92 | 90 |
return false; |
93 | 91 |
} |
94 | 92 |
} |
95 |
} catch (URISyntaxException ex) { |
|
96 |
NotificationManager.addWarning(PluginServices.getText(this,
|
|
97 |
"Hyperlink_linked_field_doesnot_exist"), ex);
|
|
98 |
return false;
|
|
93 |
} catch (URISyntaxException ex) {
|
|
94 |
LOGGER.warn("Hyperlink linked field does not exits");
|
|
95 |
return false;
|
|
96 |
}
|
|
99 | 97 |
} |
100 |
} |
|
101 | 98 |
return true; |
102 | 99 |
} |
103 | 100 |
} |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/DefaultLinkTarget.java | ||
---|---|---|
25 | 25 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
26 | 26 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
27 | 27 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
28 |
import org.gvsig.tools.util.URLUtils; |
|
28 | 29 |
|
29 | 30 |
/** |
30 | 31 |
* |
... | ... | |
183 | 184 |
} |
184 | 185 |
|
185 | 186 |
@Override |
187 |
public File toFile() { |
|
188 |
return URLUtils.toFile(this.url); |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
186 | 192 |
public Object getFromProfile() { |
187 | 193 |
return this.content; |
188 | 194 |
} |
... | ... | |
196 | 202 |
public void setURL(URL url) { |
197 | 203 |
this.url = url; |
198 | 204 |
} |
199 |
|
|
205 |
|
|
206 |
@Override |
|
207 |
public URI toURI() { |
|
208 |
try { |
|
209 |
return this.url.toURI(); |
|
210 |
} catch (URISyntaxException ex) { |
|
211 |
return null; |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
200 | 215 |
} |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/AbstractActionManager.java | ||
---|---|---|
23 | 23 |
package org.gvsig.hyperlink.app.extension; |
24 | 24 |
|
25 | 25 |
import java.util.Map; |
26 |
import javax.swing.JOptionPane; |
|
27 |
import org.gvsig.tools.ToolsLocator; |
|
28 |
import org.gvsig.tools.i18n.I18nManager; |
|
29 |
import org.slf4j.Logger; |
|
30 |
import org.slf4j.LoggerFactory; |
|
26 | 31 |
|
27 | 32 |
public abstract class AbstractActionManager implements ILinkActionManager { |
28 | 33 |
|
34 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractActionManager.class); |
|
35 |
private final String actionCode; |
|
36 |
private final String name; |
|
37 |
private final String description; |
|
38 |
|
|
39 |
protected AbstractActionManager(String actionCode, String name, String description) { |
|
40 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
41 |
this.actionCode = actionCode; |
|
42 |
this.name = i18n.getTranslation(name); |
|
43 |
this.description = i18n.getTranslation(description); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public AbstractHyperLinkPanel createPanel(LinkTarget document) throws UnsupportedOperationException { |
|
48 |
return null; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public String getActionCode() { |
|
53 |
return actionCode; |
|
54 |
} |
|
55 |
|
|
29 | 56 |
public boolean hasPanel() { |
30 | 57 |
return false; |
31 | 58 |
} |
59 |
|
|
60 |
@Override |
|
61 |
public String getDescription() { |
|
62 |
return this.description; |
|
63 |
} |
|
32 | 64 |
|
65 |
@Override |
|
66 |
public String getName() { |
|
67 |
return this.name; |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public void showDocument(LinkTarget doc) throws UnsupportedOperationException { |
|
72 |
LOGGER.warn("showDocument not implemented in "+this.getClass().getSimpleName()); |
|
73 |
} |
|
74 |
|
|
33 | 75 |
public Object create() { |
34 | 76 |
return this; |
35 | 77 |
} |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/ImgPanel.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 |
|
|
23 |
package org.gvsig.hyperlink.app.extension.actions; |
|
24 |
|
|
25 |
import java.awt.BorderLayout; |
|
26 |
import java.awt.Dimension; |
|
27 |
import java.awt.Image; |
|
28 |
import java.awt.image.BufferedImage; |
|
29 |
import java.net.MalformedURLException; |
|
30 |
import java.net.URI; |
|
31 |
|
|
32 |
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel; |
|
33 |
import org.gvsig.hyperlink.app.extension.LinkTarget; |
|
34 |
|
|
35 |
import org.gvsig.imageviewer.ImageViewer; |
|
36 |
import org.gvsig.tools.swing.api.SimpleImage; |
|
37 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
38 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
|
39 |
import org.gvsig.tools.util.ToolsUtilLocator; |
|
40 |
|
|
41 |
/** |
|
42 |
* This class extends AbstractHyperLink, and provides suppot to open images of |
|
43 |
* many formats. |
|
44 |
* The common supported formats are JPG, ICO, BMP, TIFF, GIF and PNG. Implements |
|
45 |
* methods from |
|
46 |
* IExtensionBuilder to make it extending. |
|
47 |
* |
|
48 |
* @author Eustaquio Vercher (IVER) |
|
49 |
* @author Cesar Martinez Izquierdo (IVER) |
|
50 |
*/ |
|
51 |
public class ImgPanel extends AbstractHyperLinkPanel { |
|
52 |
|
|
53 |
private static final long serialVersionUID = -5200841105188251551L; |
|
54 |
|
|
55 |
private ImageViewer imageViewer; |
|
56 |
/** |
|
57 |
* Default constructor. |
|
58 |
* @param doc |
|
59 |
*/ |
|
60 |
public ImgPanel(LinkTarget doc) { |
|
61 |
super(doc); |
|
62 |
initialize(); |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* Initializes this panel. |
|
67 |
*/ |
|
68 |
private void initialize() { |
|
69 |
this.setLayout(new BorderLayout()); |
|
70 |
this.imageViewer = ToolsUtilLocator.getImageViewerManager().createImageViewer(); |
|
71 |
this.add(this.imageViewer.asJComponent(),BorderLayout.CENTER); |
|
72 |
this.setPreferredSize(new Dimension(400, 300)); |
|
73 |
showDocument(); |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Implements the necessary code to open images in this panel. |
|
78 |
*/ |
|
79 |
protected void showDocument() { |
|
80 |
if (!checkAndNormalizeURI()) { |
|
81 |
return; |
|
82 |
} |
|
83 |
if (document.getURL() != null) { |
|
84 |
this.imageViewer.setImage(document.getURL()); |
|
85 |
} else if (document.getFromProfile() != null) { |
|
86 |
try { |
|
87 |
Object profileContent = document.getFromProfile(); |
|
88 |
BufferedImage bufferedImage = null; |
|
89 |
if (profileContent instanceof SimpleImage) { |
|
90 |
bufferedImage = ((SimpleImage) profileContent).getBufferedImage(); |
|
91 |
this.imageViewer.setImage(bufferedImage); |
|
92 |
} else { |
|
93 |
try { |
|
94 |
this.imageViewer.setImage((Image) profileContent); |
|
95 |
} catch (Exception ex) { |
|
96 |
logger.warn("Not able to convert content from field into image"); |
|
97 |
} |
|
98 |
} |
|
99 |
} catch (Exception ex) { |
|
100 |
logger.warn("Not able to get buffered image from document"); |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
} |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/PdfHyperlinkPanel.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 |
|
|
23 |
package org.gvsig.hyperlink.app.extension.actions; |
|
24 |
|
|
25 |
import java.awt.BorderLayout; |
|
26 |
import java.awt.Component; |
|
27 |
import java.awt.Container; |
|
28 |
import java.awt.Dimension; |
|
29 |
import java.awt.FlowLayout; |
|
30 |
import java.awt.Toolkit; |
|
31 |
import java.awt.event.ActionEvent; |
|
32 |
import java.awt.event.ActionListener; |
|
33 |
import java.awt.print.PageFormat; |
|
34 |
import java.awt.print.Paper; |
|
35 |
import java.awt.print.PrinterException; |
|
36 |
import java.awt.print.PrinterJob; |
|
37 |
import java.beans.PropertyChangeEvent; |
|
38 |
import java.beans.PropertyChangeListener; |
|
39 |
import java.net.URI; |
|
40 |
import java.net.URL; |
|
41 |
|
|
42 |
import javax.print.attribute.HashPrintRequestAttributeSet; |
|
43 |
import javax.print.attribute.PrintRequestAttributeSet; |
|
44 |
import javax.print.attribute.SetOfIntegerSyntax; |
|
45 |
import javax.print.attribute.standard.PageRanges; |
|
46 |
import javax.swing.JButton; |
|
47 |
import javax.swing.JLabel; |
|
48 |
import javax.swing.JOptionPane; |
|
49 |
import javax.swing.JPanel; |
|
50 |
import javax.swing.JScrollPane; |
|
51 |
import javax.swing.JTextField; |
|
52 |
|
|
53 |
import org.gvsig.andami.IconThemeHelper; |
|
54 |
import org.gvsig.andami.PluginServices; |
|
55 |
import org.gvsig.andami.messages.NotificationManager; |
|
56 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
57 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
58 |
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel; |
|
59 |
import org.gvsig.hyperlink.app.extension.LinkTarget; |
|
60 |
import org.jpedal.Display; |
|
61 |
import org.jpedal.PdfDecoder; |
|
62 |
import org.jpedal.exception.PdfException; |
|
63 |
import org.jpedal.objects.PrinterOptions; |
|
64 |
|
|
65 |
public class PdfHyperlinkPanel extends AbstractHyperLinkPanel implements |
|
66 |
PropertyChangeListener, IWindow { |
|
67 |
|
|
68 |
private static final long serialVersionUID = 1L; |
|
69 |
private WindowInfo m_viewInfo; |
|
70 |
private PdfDecoder pf = null; |
|
71 |
|
|
72 |
private int currentPage = 1; |
|
73 |
private final JLabel pageCounter1 = new JLabel(" " |
|
74 |
+ PluginServices.getText(this, "Pagina") + " "); |
|
75 |
private JTextField pageCounter2 = new JTextField(4); |
|
76 |
private JLabel pageCounter3 = |
|
77 |
new JLabel(PluginServices.getText(this, "de")); |
|
78 |
|
|
79 |
public static void initializeIcons() { |
|
80 |
IconThemeHelper.registerIcon("toolbar-go", "go-next", PdfHyperlinkPanel.class); |
|
81 |
IconThemeHelper.registerIcon("toolbar-go", "go-previous", PdfHyperlinkPanel.class); |
|
82 |
IconThemeHelper.registerIcon("toolbar-go", "go-next-fast", PdfHyperlinkPanel.class); |
|
83 |
IconThemeHelper.registerIcon("toolbar-go", "go-previous-fast", PdfHyperlinkPanel.class); |
|
84 |
IconThemeHelper.registerIcon("toolbar-go", "go-first", PdfHyperlinkPanel.class); |
|
85 |
IconThemeHelper.registerIcon("toolbar-go", "go-last", PdfHyperlinkPanel.class); |
|
86 |
IconThemeHelper.registerIcon("action", "document-print", PdfHyperlinkPanel.class); |
|
87 |
} |
|
88 |
|
|
89 |
public PdfHyperlinkPanel(LinkTarget doc) { |
|
90 |
super(doc); |
|
91 |
initialize(); |
|
92 |
} |
|
93 |
|
|
94 |
private void initialize() { |
|
95 |
|
|
96 |
pf = new PdfDecoder(); |
|
97 |
|
|
98 |
try { |
|
99 |
if (document != null && document.getURL().toURI().isAbsolute()) { |
|
100 |
String urlString = document.getURL().toString(); |
|
101 |
// avoid the openPdfFileFromURL method in first term, to avoid |
|
102 |
// the download dialog |
|
103 |
if (urlString.startsWith("file:")) { |
|
104 |
urlString = urlString.replaceFirst("file:/*", "/"); // keep |
|
105 |
// just |
|
106 |
// one |
|
107 |
// slash |
|
108 |
// at |
|
109 |
// the |
|
110 |
// beginning |
|
111 |
urlString = urlString.replaceAll("%20", " "); // PdfDecoder |
|
112 |
// doesn't |
|
113 |
// correctly |
|
114 |
// digest %20 |
|
115 |
// spaces |
|
116 |
pf.openPdfFile(urlString); |
|
117 |
} else { |
|
118 |
pf.openPdfFileFromURL(urlString, true); |
|
119 |
} |
|
120 |
} else { |
|
121 |
PluginServices.getLogger().warn(PluginServices.getText(this, |
|
122 |
"Hyperlink_linked_field_doesnot_exist")); |
|
123 |
return; |
|
124 |
} |
|
125 |
|
|
126 |
// these 2 lines opens page 1 at 100% scaling |
|
127 |
pf.decodePage(currentPage); |
|
128 |
float scaling = (float) 1.5; |
|
129 |
pf.setPageParameters(scaling, 1); // values scaling (1=100%). page |
|
130 |
// number |
|
131 |
pf.setDisplayView(Display.SINGLE_PAGE, Display.DISPLAY_CENTERED); |
|
132 |
} catch (Exception e) { |
|
133 |
NotificationManager.addWarning(PluginServices.getText(this, |
|
134 |
"Hyperlink_linked_field_doesnot_exist"), e); |
|
135 |
return; |
|
136 |
} |
|
137 |
|
|
138 |
// setup our GUI display |
|
139 |
initializeViewer(); |
|
140 |
|
|
141 |
// set page number display |
|
142 |
pageCounter2.setText(currentPage + ""); |
|
143 |
pageCounter3.setText(PluginServices.getText(this, "de") + " " |
|
144 |
+ pf.getPageCount() + " "); |
|
145 |
} |
|
146 |
|
|
147 |
public void setCurrentLinkTarget(LinkTarget currentURL) { |
|
148 |
document = currentURL; |
|
149 |
} |
|
150 |
|
|
151 |
private void initializeViewer() { |
|
152 |
|
|
153 |
Container cPane = this; |
|
154 |
cPane.setLayout(new BorderLayout()); |
|
155 |
|
|
156 |
// JButton open = initOpenBut();//setup open button |
|
157 |
Component[] itemsToAdd = initChangerPanel();// setup page display and |
|
158 |
// changer |
|
159 |
|
|
160 |
JPanel topBar = new JPanel(); |
|
161 |
topBar.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); |
|
162 |
// topBar.add(pageChanger); |
|
163 |
for (int i = 0; i < itemsToAdd.length; i++) { |
|
164 |
topBar.add(itemsToAdd[i]); |
|
165 |
} |
|
166 |
|
|
167 |
cPane.add(topBar, BorderLayout.NORTH); |
|
168 |
|
|
169 |
JScrollPane display = getJPaneViewer();// setup scrollpane with pdf |
|
170 |
// display inside |
|
171 |
cPane.add(display, BorderLayout.CENTER); |
|
172 |
|
|
173 |
// pack(); |
|
174 |
|
|
175 |
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); |
|
176 |
setSize(screen.width / 2, screen.height / 2); |
|
177 |
// <start-13> |
|
178 |
// setLocationRelativeTo(null);//centre on screen |
|
179 |
// <end-13> |
|
180 |
setVisible(true); |
|
181 |
} |
|
182 |
|
|
183 |
private Component[] initChangerPanel() { |
|
184 |
|
|
185 |
Component[] list = new Component[12]; |
|
186 |
|
|
187 |
/** back to page 1 */ |
|
188 |
JButton start = new JButton(); |
|
189 |
start.setBorderPainted(false); |
|
190 |
start.setIcon( IconThemeHelper.getImageIcon("go-first")); |
|
191 |
start.setToolTipText(PluginServices.getText(this, "primera_pagina")); |
|
192 |
// currentBar1.add(start); |
|
193 |
list[0] = start; |
|
194 |
start.addActionListener(new ActionListener() { |
|
195 |
|
|
196 |
public void actionPerformed(ActionEvent e) { |
|
197 |
if (pf != null && currentPage != 1) { |
|
198 |
currentPage = 1; |
|
199 |
try { |
|
200 |
pf.decodePage(currentPage); |
|
201 |
pf.invalidate(); |
|
202 |
repaint(); |
|
203 |
} catch (Exception e1) { |
|
204 |
System.err.println("back to page 1"); |
|
205 |
e1.printStackTrace(); |
|
206 |
} |
|
207 |
|
|
208 |
// set page number display |
|
209 |
pageCounter2.setText(currentPage + ""); |
|
210 |
} |
|
211 |
} |
|
212 |
}); |
|
213 |
|
|
214 |
/** back 10 icon */ |
|
215 |
JButton fback = new JButton(); |
|
216 |
fback.setBorderPainted(false); |
|
217 |
fback.setIcon( IconThemeHelper.getImageIcon("go-previous-fast")); |
|
218 |
fback.setToolTipText(PluginServices.getText(this, "diez_paginas_atras")); |
|
219 |
// currentBar1.add(fback); |
|
220 |
list[1] = fback; |
|
221 |
fback.addActionListener(new ActionListener() { |
|
222 |
|
|
223 |
public void actionPerformed(ActionEvent e) { |
|
224 |
if (pf != null && currentPage > 10) { |
|
225 |
currentPage -= 10; |
|
226 |
try { |
|
227 |
pf.decodePage(currentPage); |
|
228 |
pf.invalidate(); |
|
229 |
repaint(); |
|
230 |
} catch (Exception e1) { |
|
231 |
System.err.println("back 10 pages"); |
|
232 |
e1.printStackTrace(); |
|
233 |
} |
|
234 |
|
|
235 |
// set page number display |
|
236 |
pageCounter2.setText(currentPage + ""); |
|
237 |
} |
|
238 |
} |
|
239 |
}); |
|
240 |
|
|
241 |
/** back icon */ |
|
242 |
JButton back = new JButton(); |
|
243 |
back.setBorderPainted(false); |
|
244 |
back.setIcon( IconThemeHelper.getImageIcon("go-previous")); |
|
245 |
|
|
246 |
back.setToolTipText(PluginServices.getText(this, "pagina_atras")); |
|
247 |
// currentBar1.add(back); |
|
248 |
list[2] = back; |
|
249 |
back.addActionListener(new ActionListener() { |
|
250 |
|
|
251 |
public void actionPerformed(ActionEvent e) { |
|
252 |
if (pf != null && currentPage > 1) { |
|
253 |
currentPage -= 1; |
|
254 |
try { |
|
255 |
pf.decodePage(currentPage); |
|
256 |
pf.invalidate(); |
|
257 |
repaint(); |
|
258 |
} catch (Exception e1) { |
|
259 |
System.err.println("back 1 page"); |
|
260 |
e1.printStackTrace(); |
|
261 |
} |
|
262 |
|
|
263 |
// set page number display |
|
264 |
pageCounter2.setText(currentPage + ""); |
|
265 |
} |
|
266 |
} |
|
267 |
}); |
|
268 |
|
|
269 |
pageCounter2.setEditable(true); |
|
270 |
pageCounter2.addActionListener(new ActionListener() { |
|
271 |
|
|
272 |
public void actionPerformed(ActionEvent a) { |
|
273 |
|
|
274 |
String value = pageCounter2.getText().trim(); |
|
275 |
int newPage; |
|
276 |
|
|
277 |
// allow for bum values |
|
278 |
try { |
|
279 |
newPage = Integer.parseInt(value); |
|
280 |
|
|
281 |
if ((newPage > pf.getPageCount()) | (newPage < 1)) { |
|
282 |
return; |
|
283 |
} |
|
284 |
|
|
285 |
currentPage = newPage; |
|
286 |
try { |
|
287 |
pf.decodePage(currentPage); |
|
288 |
pf.invalidate(); |
|
289 |
repaint(); |
|
290 |
} catch (Exception e) { |
|
291 |
System.err.println("page number entered"); |
|
292 |
e.printStackTrace(); |
|
293 |
} |
|
294 |
|
|
295 |
} catch (Exception e) { |
|
296 |
JOptionPane.showMessageDialog(null, |
|
297 |
">" + value + "< " |
|
298 |
+ PluginServices.getText(this, "valor_incorrecto") |
|
299 |
+ pf.getPageCount()); |
|
300 |
} |
|
301 |
|
|
302 |
} |
|
303 |
|
|
304 |
}); |
|
305 |
|
|
306 |
/** put page count in middle of forward and back */ |
|
307 |
// currentBar1.add(pageCounter1); |
|
308 |
// currentBar1.add(new JPanel());//add gap |
|
309 |
// currentBar1.add(pageCounter2); |
|
310 |
// currentBar1.add(new JPanel());//add gap |
|
311 |
// currentBar1.add(pageCounter3); |
|
312 |
list[3] = pageCounter1; |
|
313 |
list[4] = new JPanel(); |
|
314 |
list[5] = pageCounter2; |
|
315 |
list[6] = new JPanel(); |
|
316 |
list[7] = pageCounter3; |
|
317 |
|
|
318 |
/** forward icon */ |
|
319 |
JButton forward = new JButton(); |
|
320 |
forward.setBorderPainted(false); |
|
321 |
forward.setIcon( IconThemeHelper.getImageIcon("go-next")); |
|
322 |
forward.setToolTipText(PluginServices.getText(this, "pagina_delante")); |
|
323 |
// currentBar1.add(forward); |
|
324 |
list[8] = forward; |
|
325 |
forward.addActionListener(new ActionListener() { |
|
326 |
|
|
327 |
public void actionPerformed(ActionEvent e) { |
|
328 |
if (pf != null && currentPage < pf.getPageCount()) { |
|
329 |
currentPage += 1; |
|
330 |
try { |
|
331 |
pf.decodePage(currentPage); |
|
332 |
pf.invalidate(); |
|
333 |
repaint(); |
|
334 |
} catch (Exception e1) { |
|
335 |
System.err.println("forward 1 page"); |
|
336 |
e1.printStackTrace(); |
|
337 |
} |
|
338 |
|
|
339 |
// set page number display |
|
340 |
pageCounter2.setText(currentPage + ""); |
|
341 |
} |
|
342 |
} |
|
343 |
}); |
|
344 |
|
|
345 |
/** fast forward icon */ |
|
346 |
JButton fforward = new JButton(); |
|
347 |
fforward.setBorderPainted(false); |
|
348 |
fforward.setIcon( IconThemeHelper.getImageIcon("go-next-fast")); |
|
349 |
fforward.setToolTipText(PluginServices.getText(this, |
|
350 |
"10_paginas_delante")); |
|
351 |
// currentBar1.add(fforward); |
|
352 |
list[9] = fforward; |
|
353 |
fforward.addActionListener(new ActionListener() { |
|
354 |
|
|
355 |
public void actionPerformed(ActionEvent e) { |
|
356 |
if (pf != null && currentPage < pf.getPageCount() - 9) { |
|
357 |
currentPage += 10; |
|
358 |
try { |
|
359 |
pf.decodePage(currentPage); |
|
360 |
pf.invalidate(); |
|
361 |
repaint(); |
|
362 |
} catch (Exception e1) { |
|
363 |
System.err.println("forward 10 pages"); |
|
364 |
e1.printStackTrace(); |
|
365 |
} |
|
366 |
|
|
367 |
// set page number display |
|
368 |
pageCounter2.setText(currentPage + ""); |
|
369 |
} |
|
370 |
} |
|
371 |
}); |
|
372 |
|
|
373 |
/** goto last page */ |
|
374 |
JButton end = new JButton(); |
|
375 |
end.setBorderPainted(false); |
|
376 |
end.setIcon( IconThemeHelper.getImageIcon("go-last")); |
|
377 |
end.setToolTipText(PluginServices.getText(this, "ultima_pagina")); |
|
378 |
// currentBar1.add(end); |
|
379 |
list[10] = end; |
|
380 |
end.addActionListener(new ActionListener() { |
|
381 |
|
|
382 |
public void actionPerformed(ActionEvent e) { |
|
383 |
if (pf != null && currentPage < pf.getPageCount()) { |
|
384 |
currentPage = pf.getPageCount(); |
|
385 |
try { |
|
386 |
pf.decodePage(currentPage); |
|
387 |
pf.invalidate(); |
|
388 |
repaint(); |
|
389 |
} catch (Exception e1) { |
|
390 |
System.err.println("forward to last page"); |
|
391 |
e1.printStackTrace(); |
|
392 |
} |
|
393 |
|
|
394 |
// set page number display |
|
395 |
pageCounter2.setText(currentPage + ""); |
|
396 |
} |
|
397 |
} |
|
398 |
}); |
|
399 |
|
|
400 |
/** Print */ |
|
401 |
JButton print = new JButton(); |
|
402 |
print.setBorderPainted(false); |
|
403 |
print.setIcon( IconThemeHelper.getImageIcon("document-print")); |
|
404 |
print.setToolTipText(PluginServices.getText(this, "imprimir")); |
|
405 |
// currentBar1.add(end); |
|
406 |
list[11] = print; |
|
407 |
print.addActionListener(new ActionListener() { |
|
408 |
|
|
409 |
public void actionPerformed(ActionEvent e) { |
|
410 |
printPDF(); |
|
411 |
} |
|
412 |
}); |
|
413 |
return list; |
|
414 |
} |
|
415 |
|
|
416 |
public void printPDF() { |
|
417 |
PrinterJob printJob = PrinterJob.getPrinterJob(); |
|
418 |
|
|
419 |
printJob.setPageable(pf); |
|
420 |
// decode_pdf.setPageFormat(pf); |
|
421 |
|
|
422 |
/** |
|
423 |
* this additional functionality is available under printable interface |
|
424 |
*/ |
|
425 |
// setup default values to add into JPS |
|
426 |
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); |
|
427 |
aset.add(new PageRanges(1, pf.getPageCount())); |
|
428 |
|
|
429 |
boolean printFile = printJob.printDialog(aset); |
|
430 |
|
|
431 |
// set page range |
|
432 |
PageRanges r = (PageRanges) aset.get(PageRanges.class); |
|
433 |
if (r != null) |
|
434 |
try { |
|
435 |
PageFormat pformat = printJob.defaultPage(); |
|
436 |
|
|
437 |
Paper paper = new Paper(); |
|
438 |
paper.setSize(595, 842); // default A4 |
|
439 |
paper.setImageableArea(43, 43, 545, 792); // actual print 'zone' |
|
440 |
|
|
441 |
pformat.setPaper(paper); |
|
442 |
|
|
443 |
// pageable provides a method getPageFormat(int p) - this method |
|
444 |
// allows it to be set by JPedal |
|
445 |
pf.setPageFormat(pformat); |
|
446 |
pf.setPagePrintRange((SetOfIntegerSyntax) r); |
|
447 |
} catch (PdfException e) { |
|
448 |
// TODO Auto-generated catch block |
|
449 |
e.printStackTrace(); |
|
450 |
} |
|
451 |
|
|
452 |
/** |
|
453 |
* generic call to both Pageable and printable |
|
454 |
*/ |
|
455 |
if (printFile) |
|
456 |
try { |
|
457 |
pf.setPrintPageScalingMode(PrinterOptions.PAGE_SCALING_FIT_TO_PRINTER_MARGINS); |
|
458 |
printJob.print(); |
|
459 |
} catch (PrinterException e) { |
|
460 |
// TODO Auto-generated catch block |
|
461 |
e.printStackTrace(); |
|
462 |
} |
|
463 |
} |
|
464 |
|
|
465 |
private JScrollPane getJPaneViewer() { |
|
466 |
JScrollPane currentScroll = new JScrollPane(); |
|
467 |
currentScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
468 |
currentScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
|
469 |
|
|
470 |
currentScroll.setViewportView(pf); |
|
471 |
return currentScroll; |
|
472 |
} |
|
473 |
|
|
474 |
/** |
|
475 |
* This is not used by hyperlink, but it's kept as it may be |
|
476 |
* useful to get a quick PDF window in gvSIG. |
|
477 |
*/ |
|
478 |
public WindowInfo getWindowInfo() { |
|
479 |
if (m_viewInfo == null) { |
|
480 |
m_viewInfo = new WindowInfo(WindowInfo.PALETTE); |
|
481 |
m_viewInfo.setMaximizable(true); |
|
482 |
m_viewInfo.setWidth(this.getWidth()); |
|
483 |
m_viewInfo.setHeight(this.getHeight()); |
|
484 |
m_viewInfo.setTitle(PluginServices.getText(this, "pdf_viewer")); |
|
485 |
} |
|
486 |
return m_viewInfo; |
|
487 |
} |
|
488 |
|
|
489 |
public void propertyChange(PropertyChangeEvent arg0) { |
|
490 |
// TODO Auto-generated method stub |
|
491 |
|
|
492 |
} |
|
493 |
|
|
494 |
public Object getWindowProfile() { |
|
495 |
return WindowInfo.EDITOR_PROFILE; |
|
496 |
} |
|
497 |
} |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/TxtPanel.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 |
|
|
23 |
package org.gvsig.hyperlink.app.extension.actions; |
|
24 |
|
|
25 |
import java.awt.BorderLayout; |
|
26 |
import java.awt.Dimension; |
|
27 |
import java.net.MalformedURLException; |
|
28 |
import java.net.URI; |
|
29 |
import java.net.URISyntaxException; |
|
30 |
import java.net.URL; |
|
31 |
import java.util.logging.Level; |
|
32 |
import java.util.logging.Logger; |
|
33 |
|
|
34 |
import javax.swing.JTextPane; |
|
35 |
|
|
36 |
import org.gvsig.andami.PluginServices; |
|
37 |
import org.gvsig.andami.messages.NotificationManager; |
|
38 |
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel; |
|
39 |
import org.gvsig.hyperlink.app.extension.LinkTarget; |
|
40 |
import org.gvsig.webbrowser.WebBrowserFactory; |
|
41 |
import org.gvsig.webbrowser.WebBrowserPanel; |
|
42 |
|
|
43 |
/** |
|
44 |
* This class extends AbstractHyperLinkPanel. And provides support to open txt |
|
45 |
* files and |
|
46 |
* WWW. Implements methods from IExtensionBuilder to make it extending. |
|
47 |
* |
|
48 |
*/ |
|
49 |
public class TxtPanel extends AbstractHyperLinkPanel { |
|
50 |
|
|
51 |
private static final long serialVersionUID = 1408583183372898110L; |
|
52 |
|
|
53 |
/** |
|
54 |
* Default constructor. |
|
55 |
*/ |
|
56 |
public TxtPanel(LinkTarget doc) { |
|
57 |
super(doc); |
|
58 |
initialize(); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Initializes this panel. |
|
63 |
*/ |
|
64 |
void initialize() { |
|
65 |
this.setLayout(new BorderLayout()); |
|
66 |
showDocument(); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Implements the necessary code to show the content of the URI in this |
|
71 |
* panel. The content of the URI is a TXT or a WWW. |
|
72 |
*/ |
|
73 |
protected void showDocument() { |
|
74 |
WebBrowserPanel webbrowser = WebBrowserFactory.createWebBrowserPanel(); |
|
75 |
webbrowser.asJComponent().setPreferredSize(new Dimension(400, 220)); |
|
76 |
|
|
77 |
if (!checkAndNormalizeURI()) { |
|
78 |
return; |
|
79 |
} |
|
80 |
|
|
81 |
URL url = null; |
|
82 |
try { |
|
83 |
url = document.getURL().toURI().normalize().toURL(); |
|
84 |
} catch (MalformedURLException e1) { |
|
85 |
NotificationManager.addWarning(PluginServices.getText(this, |
|
86 |
"Hyperlink_linked_field_doesnot_exist"), e1); |
|
87 |
return; |
|
88 |
} catch (URISyntaxException ex) { |
|
89 |
NotificationManager.addWarning(PluginServices.getText(this, |
|
90 |
"Hyperlink_linked_field_doesnot_exist"), ex); |
|
91 |
return; |
|
92 |
} |
|
93 |
webbrowser.setPage(url); |
|
94 |
this.add(webbrowser.asJComponent(), BorderLayout.CENTER); |
|
95 |
} |
|
96 |
} |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/DesktopApi.java | ||
---|---|---|
1 |
package org.gvsig.hyperlink.app.extension.actions; |
|
2 |
|
|
3 |
/* |
|
4 |
* Based on portions of code of MightyPork, http://www.ondrovo.com/ |
|
5 |
* extracted from : |
|
6 |
* http://stackoverflow.com/questions/18004150/desktop-api-is-not-supported-on-the-current-platform |
|
7 |
*/ |
|
8 |
|
|
9 |
import java.awt.Desktop; |
|
10 |
import java.io.File; |
|
11 |
import java.io.IOException; |
|
12 |
import java.net.URL; |
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
import org.slf4j.Logger; |
|
16 |
import org.slf4j.LoggerFactory; |
|
17 |
|
|
18 |
public class DesktopApi { |
|
19 |
|
|
20 |
private static Logger logger = LoggerFactory.getLogger(DesktopApi.class); |
|
21 |
|
|
22 |
public static boolean browse(URL uri) { |
|
23 |
|
|
24 |
if ( browseDESKTOP(uri) ) { |
|
25 |
return true; |
|
26 |
} |
|
27 |
|
|
28 |
if ( openSystemSpecific(uri.toString()) ) { |
|
29 |
return true; |
|
30 |
} |
|
31 |
|
|
32 |
return false; |
|
33 |
} |
|
34 |
|
|
35 |
public static boolean open(File file) { |
|
36 |
|
|
37 |
if ( openDESKTOP(file) ) { |
|
38 |
return true; |
|
39 |
} |
|
40 |
|
|
41 |
if ( openSystemSpecific(file.getPath()) ) { |
|
42 |
return true; |
|
43 |
} |
|
44 |
|
|
45 |
return false; |
|
46 |
} |
|
47 |
|
|
48 |
public static boolean edit(File file) { |
|
49 |
|
|
50 |
if ( editDESKTOP(file) ) { |
|
51 |
return true; |
|
52 |
} |
|
53 |
|
|
54 |
if ( openSystemSpecific(file.getPath()) ) { |
|
55 |
return true; |
|
56 |
} |
|
57 |
|
|
58 |
return false; |
|
59 |
} |
|
60 |
|
|
61 |
private static boolean openSystemSpecific(String what) { |
|
62 |
|
|
63 |
EnumOS os = getOs(); |
|
64 |
|
|
65 |
if (os.isLinux()) { |
|
66 |
// if (runCommand("gnome-open", "%s", what)) { |
|
67 |
// return true; |
|
68 |
// } |
|
69 |
// if (runCommand("kde-open", "%s", what)) { |
|
70 |
// return true; |
|
71 |
// } |
|
72 |
if (runCommand("xdg-open", "%s", what)) { |
|
73 |
return true; |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
if ( os.isMac() ) { |
|
78 |
if ( runCommand("open", "%s", what) ) { |
|
79 |
return true; |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
if ( os.isWindows() ) { |
|
84 |
if ( runCommand("explorer", "%s", what) ) { |
|
85 |
return true; |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
return false; |
|
90 |
} |
|
91 |
|
|
92 |
private static boolean browseDESKTOP(URL uri) { |
|
93 |
|
|
94 |
logOut("Trying to use Desktop.getDesktop().browse() with " + uri.toString()); |
|
95 |
try { |
|
96 |
if ( !Desktop.isDesktopSupported() ) { |
|
97 |
logErr("Platform is not supported."); |
|
98 |
return false; |
|
99 |
} |
|
100 |
|
|
101 |
if ( !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE) ) { |
|
102 |
logErr("BROWSE is not supported."); |
|
103 |
return false; |
|
104 |
} |
|
105 |
|
|
106 |
Desktop.getDesktop().browse(uri.toURI()); |
|
107 |
|
|
108 |
return true; |
|
109 |
} catch (Throwable t) { |
|
110 |
logErr("Error using desktop browse.", t); |
|
111 |
return false; |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
private static boolean openDESKTOP(File file) { |
|
116 |
|
|
117 |
logOut("Trying to use Desktop.getDesktop().open() with " + file.toString()); |
|
118 |
try { |
|
119 |
if ( !Desktop.isDesktopSupported() ) { |
|
120 |
logErr("Platform is not supported."); |
|
121 |
return false; |
|
122 |
} |
|
123 |
|
|
124 |
if ( !Desktop.getDesktop().isSupported(Desktop.Action.OPEN) ) { |
|
125 |
logErr("OPEN is not supported."); |
|
126 |
return false; |
|
127 |
} |
|
128 |
|
|
129 |
Desktop.getDesktop().open(file); |
|
130 |
|
|
131 |
return true; |
|
132 |
} catch (Throwable t) { |
|
133 |
logErr("Error using desktop open.", t); |
|
134 |
return false; |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
private static boolean editDESKTOP(File file) { |
|
139 |
|
|
140 |
logOut("Trying to use Desktop.getDesktop().edit() with " + file); |
|
141 |
try { |
|
142 |
if ( !Desktop.isDesktopSupported() ) { |
|
143 |
logErr("Platform is not supported."); |
|
144 |
return false; |
|
145 |
} |
|
146 |
|
|
147 |
if ( !Desktop.getDesktop().isSupported(Desktop.Action.EDIT) ) { |
|
148 |
logErr("EDIT is not supported."); |
|
149 |
return false; |
|
150 |
} |
|
151 |
|
|
152 |
Desktop.getDesktop().edit(file); |
|
153 |
|
|
154 |
return true; |
|
155 |
} catch (Throwable t) { |
|
156 |
logErr("Error using desktop edit.", t); |
|
157 |
return false; |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
private static boolean runCommand(String command, String args, String file) { |
|
162 |
|
|
163 |
logOut("Trying to exec:\n cmd = " + command + "\n args = " + args + "\n %s = " + file); |
|
164 |
|
|
165 |
String[] parts = prepareCommand(command, args, file); |
|
166 |
|
|
167 |
try { |
|
168 |
Process p = Runtime.getRuntime().exec(parts); |
|
169 |
if ( p == null ) { |
|
170 |
return false; |
|
171 |
} |
|
172 |
|
|
173 |
try { |
|
174 |
int retval = p.exitValue(); |
|
175 |
if ( retval == 0 ) { |
|
176 |
logErr("Process ended immediately."); |
|
177 |
return false; |
|
178 |
} else { |
|
179 |
logErr("Process crashed."); |
|
180 |
return false; |
|
181 |
} |
|
182 |
} catch (IllegalThreadStateException itse) { |
|
183 |
logErr("Process is running."); |
|
184 |
return true; |
|
185 |
} |
|
186 |
} catch (IOException e) { |
|
187 |
logErr("Error running command.", e); |
|
188 |
return false; |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
private static String[] prepareCommand(String command, String args, String file) { |
|
193 |
|
|
194 |
List<String> parts = new ArrayList<String>(); |
|
195 |
parts.add(command); |
|
196 |
|
|
197 |
if ( args != null ) { |
|
198 |
for ( String s : args.split(" ") ) { |
|
199 |
s = String.format(s, file); // put in the filename thing |
|
200 |
|
|
201 |
parts.add(s.trim()); |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
return parts.toArray(new String[parts.size()]); |
|
206 |
} |
|
207 |
|
|
208 |
private static void logErr(String msg, Throwable t) { |
|
209 |
logger.warn(msg,t); |
|
210 |
} |
|
211 |
|
|
212 |
private static void logErr(String msg) { |
|
213 |
logger.warn(msg); |
|
214 |
} |
|
215 |
|
|
216 |
private static void logOut(String msg) { |
|
217 |
logger.info(msg); |
|
218 |
} |
|
219 |
|
|
220 |
public static enum EnumOS { |
|
221 |
|
|
222 |
linux, macos, solaris, unknown, windows; |
|
223 |
|
|
224 |
public boolean isLinux() { |
|
225 |
|
|
226 |
return this == linux || this == solaris; |
|
227 |
} |
|
228 |
|
|
229 |
public boolean isMac() { |
|
230 |
|
|
231 |
return this == macos; |
|
232 |
} |
|
233 |
|
|
234 |
public boolean isWindows() { |
|
235 |
|
|
236 |
return this == windows; |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 |
public static EnumOS getOs() { |
|
241 |
|
|
242 |
String s = System.getProperty("os.name").toLowerCase(); |
|
243 |
|
|
244 |
if ( s.contains("win") ) { |
|
245 |
return EnumOS.windows; |
|
246 |
} |
|
247 |
|
|
248 |
if ( s.contains("mac") ) { |
|
249 |
return EnumOS.macos; |
|
250 |
} |
|
251 |
|
|
252 |
if ( s.contains("solaris") ) { |
|
253 |
return EnumOS.solaris; |
|
254 |
} |
|
255 |
|
|
256 |
if ( s.contains("sunos") ) { |
|
257 |
return EnumOS.solaris; |
|
258 |
} |
|
259 |
|
|
260 |
if ( s.contains("linux") ) { |
|
261 |
return EnumOS.linux; |
|
262 |
} |
|
263 |
|
|
264 |
if ( s.contains("unix") ) { |
|
265 |
return EnumOS.linux; |
|
266 |
} else { |
|
267 |
return EnumOS.unknown; |
|
268 |
} |
|
269 |
} |
|
270 |
} |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/ExternTxtFormat.java | ||
---|---|---|
23 | 23 |
package org.gvsig.hyperlink.app.extension.actions; |
24 | 24 |
|
25 | 25 |
import java.io.Serializable; |
26 |
import java.net.URL; |
|
26 |
import java.net.URI; |
|
27 |
import java.net.URISyntaxException; |
|
28 |
import org.gvsig.desktopopen.DesktopOpen; |
|
27 | 29 |
|
28 |
import org.gvsig.andami.PluginServices; |
|
29 | 30 |
import org.gvsig.hyperlink.app.extension.AbstractActionManager; |
30 |
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel; |
|
31 | 31 |
import org.gvsig.hyperlink.app.extension.LinkTarget; |
32 |
import org.gvsig.tools.util.ToolsUtilLocator; |
|
32 | 33 |
|
33 | 34 |
public class ExternTxtFormat extends AbstractActionManager implements Serializable { |
34 | 35 |
|
35 |
public static final String actionCode = "TxtExtern_format"; |
|
36 |
|
|
37 |
@Override |
|
38 |
public AbstractHyperLinkPanel createPanel(LinkTarget doc) throws UnsupportedOperationException { |
|
39 |
return null; |
|
36 |
public static final String ACTION_CODE = "TxtExtern_format"; |
|
37 |
|
|
38 |
public ExternTxtFormat() { |
|
39 |
super(ACTION_CODE,"HTML_and_text_formats_in_system_application","Shows_HTML_or_text_files_in_system_application"); |
|
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
@Override |
43 |
public String getActionCode() { |
|
44 |
return actionCode; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public boolean hasPanel() { |
|
49 |
return false; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 | 43 |
public void showDocument(LinkTarget doc) { |
54 |
URL tourl = doc.getURL(); |
|
55 |
DesktopApi.browse(tourl); |
|
44 |
try { |
|
45 |
URI uri = doc.toURI(); |
|
46 |
DesktopOpen desktop = ToolsUtilLocator.getToolsUtilManager().createDesktopOpen(); |
|
47 |
desktop.browse(uri); |
|
48 |
} catch (Exception ex) { |
|
49 |
LOGGER.warn("Cant show document "+doc.getURL(),ex); |
|
50 |
} |
|
56 | 51 |
} |
57 |
|
|
58 |
@Override |
|
59 |
public String getDescription() { |
|
60 |
return PluginServices.getText(this, "Shows_HTML_or_text_files_in_system_application"); |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public String getName() { |
|
65 |
return PluginServices.getText(this, "HTML_and_text_formats_in_system_application"); |
|
66 |
} |
|
67 |
|
|
68 | 52 |
} |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/SvgPanel.java | ||
---|---|---|
31 | 31 |
import java.awt.geom.Rectangle2D; |
32 | 32 |
import java.awt.image.BufferedImage; |
33 | 33 |
import java.net.URI; |
34 |
import java.net.URL; |
|
34 | 35 |
|
35 | 36 |
import javax.swing.ImageIcon; |
36 | 37 |
import javax.swing.JLabel; |
... | ... | |
106 | 107 |
|
107 | 108 |
ImageIcon image; |
108 | 109 |
// try { |
109 |
image = new ImageIcon(getSvgAsImage(document.toString()));
|
|
110 |
image = new ImageIcon(getSvgAsImage(document.getURL()));
|
|
110 | 111 |
|
111 | 112 |
if (image == null) |
112 | 113 |
; // Incluir error |
... | ... | |
127 | 128 |
* @param file |
128 | 129 |
* , this file has been extracted from the URI |
129 | 130 |
*/ |
130 |
private Image getSvgAsImage(String uri) {
|
|
131 |
private Image getSvgAsImage(URL url) {
|
|
131 | 132 |
BufferedImage img = |
132 | 133 |
new BufferedImage(400, 400, BufferedImage.TYPE_INT_ARGB); |
133 | 134 |
Graphics2D g = img.createGraphics(); |
134 | 135 |
Rectangle2D rect = new Rectangle2D.Double(); |
135 | 136 |
rect.setFrame(0, 0, 400, 400); |
136 |
obtainStaticRenderer(uri);
|
|
137 |
obtainStaticRenderer(url);
|
|
137 | 138 |
drawSVG(g, rect, null); |
138 | 139 |
return img; |
139 | 140 |
} |
... | ... | |
144 | 145 |
* @param file |
145 | 146 |
* , this file has been extracted from the URI |
146 | 147 |
*/ |
147 |
private void obtainStaticRenderer(String uri) {
|
|
148 |
private void obtainStaticRenderer(URL url) {
|
|
148 | 149 |
try { |
149 | 150 |
UserAgentAdapter userAgent = new UserAgentAdapter(); |
150 | 151 |
DocumentLoader loader = new DocumentLoader(userAgent); |
151 | 152 |
ctx = new BridgeContext(userAgent, loader); |
152 | 153 |
// Document svgDoc = loader.loadDocument(file.toURI().toString()); |
153 |
Document svgDoc = loader.loadDocument(uri);
|
|
154 |
Document svgDoc = loader.loadDocument(url.toString());
|
|
154 | 155 |
gvtRoot = gvtBuilder.build(ctx, svgDoc); |
155 | 156 |
renderer.setTree(gvtRoot); |
156 | 157 |
elt = ((SVGDocument) svgDoc).getRootElement(); |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/PdfFormat.java | ||
---|---|---|
22 | 22 |
|
23 | 23 |
package org.gvsig.hyperlink.app.extension.actions; |
24 | 24 |
|
25 |
import java.io.IOException; |
|
25 | 26 |
import java.io.Serializable; |
26 |
import java.net.URI; |
|
27 |
import java.util.logging.Level; |
|
28 |
import java.util.logging.Logger; |
|
27 | 29 |
|
28 |
import org.gvsig.andami.PluginServices; |
|
29 | 30 |
import org.gvsig.hyperlink.app.extension.AbstractActionManager; |
30 |
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel; |
|
31 | 31 |
import org.gvsig.hyperlink.app.extension.LinkTarget; |
32 |
import org.gvsig.pdf.lib.api.PDFDocument; |
|
33 |
import org.gvsig.pdf.lib.api.PDFLocator; |
|
34 |
import org.gvsig.pdf.swing.api.PDFSwingLocator; |
|
35 |
import org.gvsig.pdf.swing.api.PDFViewer; |
|
36 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
37 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
|
38 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
32 | 39 |
|
33 | 40 |
public class PdfFormat extends AbstractActionManager implements Serializable { |
34 | 41 |
|
35 |
public static final String actionCode = "PDF_format";
|
|
42 |
public static final String ACTION_CODE = "PDF_format";
|
|
36 | 43 |
|
37 |
@Override |
|
38 |
public AbstractHyperLinkPanel createPanel(LinkTarget doc) throws UnsupportedOperationException { |
|
39 |
return new PdfHyperlinkPanel(doc); |
|
44 |
public PdfFormat() { |
|
45 |
super(ACTION_CODE, "PDF_format", "Shows_PDF_files_in_gvSIG"); |
|
40 | 46 |
} |
41 |
|
|
47 |
|
|
42 | 48 |
@Override |
43 |
public String getActionCode() { |
|
44 |
return actionCode; |
|
49 |
public void showDocument(LinkTarget document) { |
|
50 |
try { |
|
51 |
PDFDocument pdfdoc = PDFLocator.getPDFManager().createPDFDocument(); |
|
52 |
String title = "PDF"; |
|
53 |
if (document.getURL() != null) { |
|
54 |
title = document.getURL().toString(); |
|
55 |
pdfdoc.setSource(document.getURL()); |
|
56 |
} else if (document.getFromProfile() != null) { |
|
57 |
try { |
|
58 |
Object profileContent = document.getFromProfile(); |
|
59 |
if (!(profileContent instanceof PDFDocument)) { |
|
60 |
LOGGER.warn("Not able to convert content from field into pdf"); |
|
61 |
} |
|
62 |
pdfdoc = (PDFDocument) profileContent; |
|
63 |
} catch (Exception ex) { |
|
64 |
LOGGER.warn("Not able to get PDF from document"); |
|
65 |
} |
|
66 |
} |
|
67 |
PDFViewer viewer = PDFSwingLocator.getPDFSwingManager().createPDFViewer(); |
|
68 |
viewer.put(pdfdoc); |
|
69 |
ToolsSwingUtils.ensureRowsCols(viewer.asJComponent(), 20, 100, 40, 150); |
|
70 |
WindowManager windowManager = ToolsSwingLocator.getWindowManager(); |
|
71 |
windowManager.showWindow( |
|
72 |
viewer.asJComponent(), |
|
73 |
"Hyperlink"+": "+title, |
|
74 |
WindowManager.MODE.WINDOW |
|
75 |
); |
|
76 |
} catch (IOException ex) { |
|
77 |
Logger.getLogger(PdfFormat.class.getName()).log(Level.SEVERE, null, ex); |
|
78 |
} |
|
45 | 79 |
} |
46 | 80 |
|
47 |
@Override |
|
48 |
public boolean hasPanel() { |
|
49 |
return true; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public void showDocument(LinkTarget doc) { |
|
54 |
throw new UnsupportedOperationException(); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public String getDescription() { |
|
59 |
return PluginServices.getText(this, "Shows_PDF_files_in_gvSIG"); |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public String getName() { |
|
64 |
return PluginServices.getText(this, "PDF_format"); |
|
65 |
} |
|
66 | 81 |
} |
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/FolderFormat.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.hyperlink.app.extension.actions; |
25 | 25 |
|
26 |
import java.awt.Desktop; |
|
27 | 26 |
import java.io.File; |
28 |
import java.io.IOException; |
|
29 | 27 |
import java.io.Serializable; |
30 | 28 |
import java.net.URI; |
31 | 29 |
import javax.swing.JOptionPane; |
32 | 30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.desktopopen.DesktopOpen; |
|
33 | 32 |
import org.gvsig.hyperlink.app.extension.AbstractActionManager; |
34 |
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel; |
|
35 | 33 |
import org.gvsig.hyperlink.app.extension.LinkTarget; |
36 |
import org.slf4j.Logger; |
|
37 |
import org.slf4j.LoggerFactory; |
|
34 |
import org.gvsig.tools.util.ToolsUtilLocator; |
|
38 | 35 |
|
39 | 36 |
public class FolderFormat extends AbstractActionManager implements Serializable { |
40 | 37 |
|
41 |
/** |
|
42 |
* |
|
43 |
*/ |
|
44 |
private static final long serialVersionUID = 1L; |
|
45 |
public static final String actionCode = "Folder_format"; |
|
46 |
private static Logger logger = LoggerFactory.getLogger(FolderFormat.class); |
|
47 |
|
|
48 |
public String getActionCode() { |
|
49 |
return actionCode; |
|
38 |
public static final String ACTION_CODE = "Folder_format"; |
|
39 |
|
|
40 |
public FolderFormat() { |
|
41 |
super(ACTION_CODE,"Folder_formats","Shows_Folders_in_gvSIG"); |
|
50 | 42 |
} |
51 | 43 |
|
52 |
public boolean hasPanel() { |
|
53 |
return false; |
|
54 |
} |
|
55 |
|
|
44 |
@Override |
|
56 | 45 |
public void showDocument(LinkTarget doc) { |
57 |
File folder = new File(doc.getURL().getPath()); |
|
58 |
if ( folder.exists() ) { |
|
59 |
DesktopApi.browse(doc.getURL()); |
|
60 |
// DesktopApi.open(folder); |
|
61 |
// Desktop desktop = Desktop.getDesktop(); |
|
62 |
// try { |
|
63 |
// desktop.open(folder); |
|
64 |
// } catch (IOException e1) { |
|
65 |
// logger.error("Can't open folder '" + folder.getAbsolutePath() + "'.", e1); |
|
66 |
// } |
|
67 |
|
|
68 |
} else { |
|
46 |
File folder = doc.toFile(); |
|
47 |
if ( folder==null ) { |
|
48 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this, "Bad_path")); |
|
49 |
return; |
|
50 |
} |
|
51 |
if( !folder.exists() ) { |
|
69 | 52 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this, "Bad_path") + " : " + folder.getAbsolutePath()); |
53 |
return; |
|
70 | 54 |
} |
55 |
URI uri = doc.toURI(); |
|
56 |
DesktopOpen desktop = ToolsUtilLocator.getToolsUtilManager().createDesktopOpen(); |
|
57 |
desktop.browse(uri); |
|
71 | 58 |
} |
72 | 59 |
|
73 |
public String getDescription() { |
|
74 |
return PluginServices.getText(this, "Shows_Folders_in_gvSIG"); |
|
75 |
} |
|
76 |
|
|
77 |
public String getName() { |
|
78 |
return PluginServices.getText(this, "Folder_formats"); |
|
79 |
} |
|
80 |
|
|
81 |
public AbstractHyperLinkPanel createPanel(LinkTarget doc) |
|
82 |
throws UnsupportedOperationException { |
|
83 |
return null; |
|
84 |
} |
|
85 |
|
|
86 | 60 |
} |
87 | 61 |
|
org.gvsig.hyperlink.app/trunk/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/ImgFormat.java | ||
---|---|---|
24 | 24 |
|
Also available in: Unified diff