root / org.gvsig.hyperlink.app / trunk / org.gvsig.hyperlink.app / org.gvsig.hyperlink.app.extension / src / main / java / org / gvsig / hyperlink / app / extension / ShowPanel.java @ 15
History | View | Annotate | Download (5.54 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.awt.BorderLayout; |
26 |
import java.awt.event.ComponentEvent; |
27 |
import java.awt.event.ComponentListener; |
28 |
import java.io.File; |
29 |
import java.net.MalformedURLException; |
30 |
|
31 |
import javax.swing.JPanel; |
32 |
import javax.swing.JScrollPane; |
33 |
|
34 |
import org.gvsig.andami.PluginServices; |
35 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
36 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
37 |
|
38 |
/**
|
39 |
* This class extends JPanel. This class implements a Panel to show the content
|
40 |
* of the URI
|
41 |
* that the constructor of the class receives. This panel invokes a new one with
|
42 |
* the content
|
43 |
* of the URI. The type of the supported URI should be added like extension
|
44 |
* point in the
|
45 |
* initialization of the extension.
|
46 |
*
|
47 |
* @author Vicente Caballero Navarro
|
48 |
* @author Eustaquio Vercher
|
49 |
*
|
50 |
*/
|
51 |
public class ShowPanel extends JPanel implements IWindow, ComponentListener { |
52 |
|
53 |
private JScrollPane jScrollPane = null; |
54 |
private WindowInfo m_ViewInfo = null; |
55 |
private AbstractHyperLinkPanel contents = null; |
56 |
private static int xpos = 0; |
57 |
private static int ypos = 0; |
58 |
|
59 |
public ShowPanel(AbstractHyperLinkPanel contents) {
|
60 |
super();
|
61 |
this.contents = contents;
|
62 |
initialize(); |
63 |
} |
64 |
|
65 |
/**
|
66 |
* This method initializes this
|
67 |
*/
|
68 |
private void initialize() { |
69 |
this.setLayout(new BorderLayout()); |
70 |
this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
|
71 |
getJScrollPane().setViewportView(contents); |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Returns a Scroll Pane with the content of the HyperLink
|
76 |
*
|
77 |
* @return jScrollPane
|
78 |
*/
|
79 |
private JScrollPane getJScrollPane() { |
80 |
if (jScrollPane == null) { |
81 |
jScrollPane = new JScrollPane(); |
82 |
// jScrollPane.setPreferredSize(new java.awt.Dimension(300, 400));
|
83 |
} |
84 |
return jScrollPane;
|
85 |
} |
86 |
|
87 |
/*
|
88 |
* (non-Javadoc)
|
89 |
*
|
90 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
91 |
*/
|
92 |
public WindowInfo getWindowInfo() {
|
93 |
if (m_ViewInfo == null) { |
94 |
m_ViewInfo = |
95 |
new WindowInfo(WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE
|
96 |
| WindowInfo.ICONIFIABLE | WindowInfo.PALETTE); |
97 |
if (contents.getURI().toString().startsWith("file:") |
98 |
&& contents.getURI().isAbsolute()) { |
99 |
try {
|
100 |
File file = new File(contents.getURI().toURL().getFile()); |
101 |
m_ViewInfo.setTitle(PluginServices.getText(this,
|
102 |
"Hyperlink") + " - " + file.getName()); |
103 |
} catch (MalformedURLException e) { |
104 |
m_ViewInfo.setTitle(PluginServices.getText(this,
|
105 |
"Hyperlink") + " - " + contents.getURI().toString()); |
106 |
} catch (NullPointerException e) { |
107 |
m_ViewInfo.setTitle(PluginServices.getText(this,
|
108 |
"Hyperlink") + " - " + contents.getURI().toString()); |
109 |
} |
110 |
} else {
|
111 |
m_ViewInfo.setTitle(PluginServices.getText(this, "Hyperlink") |
112 |
+ " - " + contents.getURI().toString());
|
113 |
} |
114 |
int height = (int) contents.getPreferredSize().getHeight() + 15; |
115 |
if (height > 650) |
116 |
height = 650;
|
117 |
else
|
118 |
if (height < 450) |
119 |
height = 450;
|
120 |
int width = (int) contents.getPreferredSize().getWidth() + 20; |
121 |
if (width > 800) |
122 |
width = 800;
|
123 |
else
|
124 |
if (width < 450) |
125 |
width = 450;
|
126 |
m_ViewInfo.setWidth(width); |
127 |
m_ViewInfo.setHeight(height); |
128 |
m_ViewInfo.setX(xpos); |
129 |
xpos = (xpos + 20) % 270; |
130 |
m_ViewInfo.setY(ypos); |
131 |
ypos = (ypos + 15) % 150; |
132 |
} |
133 |
return m_ViewInfo;
|
134 |
} |
135 |
|
136 |
/*
|
137 |
* (non-Javadoc)
|
138 |
*
|
139 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.
|
140 |
* ComponentEvent)
|
141 |
*/
|
142 |
public void componentResized(ComponentEvent e) { |
143 |
|
144 |
} |
145 |
|
146 |
/*
|
147 |
* (non-Javadoc)
|
148 |
*
|
149 |
* @see
|
150 |
* java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent
|
151 |
* )
|
152 |
*/
|
153 |
public void componentMoved(ComponentEvent e) { |
154 |
|
155 |
} |
156 |
|
157 |
/*
|
158 |
* (non-Javadoc)
|
159 |
*
|
160 |
* @see
|
161 |
* java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent
|
162 |
* )
|
163 |
*/
|
164 |
public void componentShown(ComponentEvent e) { |
165 |
|
166 |
} |
167 |
|
168 |
/*
|
169 |
* (non-Javadoc)
|
170 |
*
|
171 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.
|
172 |
* ComponentEvent)
|
173 |
*/
|
174 |
public void componentHidden(ComponentEvent e) { |
175 |
|
176 |
} |
177 |
|
178 |
public Object getWindowProfile() { |
179 |
return WindowInfo.EDITOR_PROFILE;
|
180 |
} |
181 |
} |