svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / develtools / InfoPanel.java @ 47413
History | View | Annotate | Download (4.35 KB)
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 3
|
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 |
package org.gvsig.app.extension.develtools; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.io.File; |
31 |
import java.io.FileWriter; |
32 |
import java.io.IOException; |
33 |
import java.net.URL; |
34 |
|
35 |
import javax.swing.BorderFactory; |
36 |
import javax.swing.Box; |
37 |
import javax.swing.BoxLayout; |
38 |
import javax.swing.JButton; |
39 |
import javax.swing.JPanel; |
40 |
import javax.swing.JScrollPane; |
41 |
import javax.swing.JTextPane; |
42 |
import javax.swing.event.HyperlinkEvent; |
43 |
import javax.swing.event.HyperlinkListener; |
44 |
|
45 |
import org.gvsig.app.ApplicationLocator; |
46 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
47 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
48 |
import org.slf4j.Logger; |
49 |
import org.slf4j.LoggerFactory; |
50 |
|
51 |
public class InfoPanel extends JPanel { |
52 |
private static Logger logger = LoggerFactory.getLogger(InfoPanel.class); |
53 |
|
54 |
|
55 |
private static final long serialVersionUID = 7164653790859770568L; |
56 |
|
57 |
private JButton accept = null; |
58 |
private JButton copy = null; |
59 |
private JTextPane text = null; |
60 |
|
61 |
public static void showPanel(String title, WindowManager.MODE mode, |
62 |
String html) {
|
63 |
JPanel panel = new InfoPanel(html, null); |
64 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
65 |
wm.showWindow(panel, title, mode); |
66 |
} |
67 |
|
68 |
|
69 |
public static void showPanel(String title, WindowManager.MODE mode, |
70 |
String html, HyperlinkListener hyperlinkListener) { |
71 |
JPanel panel = new InfoPanel(html,hyperlinkListener); |
72 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
73 |
wm.showWindow(panel, title, mode); |
74 |
} |
75 |
|
76 |
|
77 |
public static void save2file(String name, String contents) { |
78 |
File file;
|
79 |
try {
|
80 |
file = File.createTempFile("gvsig-" + name + "-", ".html"); |
81 |
FileWriter fwriter = new FileWriter(file); |
82 |
fwriter.append(contents); |
83 |
fwriter.close(); |
84 |
} catch (IOException e) { |
85 |
logger.warn("Can't save contents to temp file gvsig-" + name, e);
|
86 |
} |
87 |
} |
88 |
|
89 |
public InfoPanel(final String html, HyperlinkListener hyperlinkListener) { |
90 |
this.setLayout(new BorderLayout()); |
91 |
this.setPreferredSize(new Dimension(500, 300)); |
92 |
this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); |
93 |
|
94 |
text = new JTextPane(); |
95 |
text.setContentType("text/html");
|
96 |
text.setEditable(false);
|
97 |
text.setText(html); |
98 |
text.setCaretPosition(0);
|
99 |
if( hyperlinkListener!=null ) { |
100 |
text.addHyperlinkListener(hyperlinkListener); |
101 |
} |
102 |
|
103 |
JScrollPane scrollPane = new JScrollPane(text); |
104 |
scrollPane.setPreferredSize(new Dimension(500, 220)); |
105 |
|
106 |
accept = new JButton("Accept"); |
107 |
accept.addActionListener(new ActionListener() { |
108 |
public void actionPerformed(ActionEvent arg0) { |
109 |
setVisible(false);
|
110 |
} |
111 |
}); |
112 |
copy = new JButton("Copy to clipboard"); |
113 |
copy.addActionListener(new ActionListener() { |
114 |
public void actionPerformed(ActionEvent arg0) { |
115 |
ToolsSwingLocator.getToolsSwingManager().putInClipboard( |
116 |
text.getText(), |
117 |
"html"
|
118 |
); |
119 |
} |
120 |
}); |
121 |
|
122 |
JPanel buttonsPanel = new JPanel(); |
123 |
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, |
124 |
BoxLayout.LINE_AXIS));
|
125 |
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
126 |
|
127 |
buttonsPanel.add(Box.createHorizontalGlue());
|
128 |
buttonsPanel.add(copy); |
129 |
buttonsPanel.add(accept); |
130 |
|
131 |
this.add(scrollPane, BorderLayout.CENTER); |
132 |
this.add(buttonsPanel, BorderLayout.SOUTH); |
133 |
this.setVisible(true); |
134 |
} |
135 |
|
136 |
} |