svn-gvsig-desktop / tags / v2_0_0_Build_2020 / extensions / org.gvsig.hyperlink.app / org.gvsig.hyperlink.app.extension / src / main / java / org / gvsig / hyperlink / app / extension / AbstractHyperLinkPanel.java @ 33968
History | View | Annotate | Download (2.97 KB)
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; |
24 |
|
25 |
import java.io.File; |
26 |
import java.io.IOException; |
27 |
import java.net.URI; |
28 |
|
29 |
import javax.swing.JPanel; |
30 |
|
31 |
import org.gvsig.andami.PluginServices; |
32 |
|
33 |
/**
|
34 |
* This class extends JPanel and implements IExtensioBuilder. Provides the
|
35 |
* methods that will be reimplemented by the descendant class. Creates a panel
|
36 |
* that shows the content of a URI. The necessary code that allows to show the
|
37 |
* content of the URI is provided by the descendant class. Implmenting
|
38 |
* IExtenssionBuilder this class and its the descendant provides a point of
|
39 |
* extension for other extensions.
|
40 |
*/
|
41 |
public abstract class AbstractHyperLinkPanel extends JPanel { |
42 |
|
43 |
protected URI document; |
44 |
|
45 |
public AbstractHyperLinkPanel(URI doc) { |
46 |
super();
|
47 |
document = doc; |
48 |
} |
49 |
|
50 |
public URI getURI() { |
51 |
return document;
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* Tries to make an absolute url from a relative one,
|
56 |
* and returns true if the URL is valid.
|
57 |
* false otherwise
|
58 |
*
|
59 |
* @return
|
60 |
*/
|
61 |
protected boolean checkAndNormalizeURI() { |
62 |
if (document == null) { |
63 |
PluginServices.getLogger().warn(PluginServices.getText(this,
|
64 |
"Hyperlink_linked_field_doesnot_exist"));
|
65 |
return false; |
66 |
} else
|
67 |
if (!document.isAbsolute()) {
|
68 |
try {
|
69 |
// try as a relative path
|
70 |
File file =
|
71 |
new File(document.toString()).getCanonicalFile(); |
72 |
if (!file.exists()) {
|
73 |
PluginServices.getLogger() |
74 |
.warn(PluginServices.getText(this,
|
75 |
"Hyperlink_linked_field_doesnot_exist"));
|
76 |
return false; |
77 |
} |
78 |
document = file.toURI(); |
79 |
} catch (IOException e) { |
80 |
PluginServices.getLogger() |
81 |
.warn(PluginServices.getText(this,
|
82 |
"Hyperlink_linked_field_doesnot_exist"));
|
83 |
return false; |
84 |
} |
85 |
} |
86 |
return true; |
87 |
} |
88 |
} |