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 @ 40558
History | View | Annotate | Download (3.64 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 |
|
34 |
import javax.swing.BorderFactory; |
35 |
import javax.swing.Box; |
36 |
import javax.swing.BoxLayout; |
37 |
import javax.swing.JButton; |
38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JScrollPane; |
40 |
import javax.swing.JTextPane; |
41 |
|
42 |
import org.gvsig.app.ApplicationLocator; |
43 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
44 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
|
48 |
public class InfoPanel extends JPanel { |
49 |
private static Logger logger = LoggerFactory.getLogger(InfoPanel.class); |
50 |
|
51 |
|
52 |
private static final long serialVersionUID = 7164653790859770568L; |
53 |
|
54 |
private JButton accept = null; |
55 |
private JButton copy = null; |
56 |
private JTextPane text = null; |
57 |
|
58 |
public static void showPanel(String title, WindowManager.MODE mode, |
59 |
String html) {
|
60 |
JPanel panel = new InfoPanel(html); |
61 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
62 |
wm.showWindow(panel, title, mode); |
63 |
} |
64 |
|
65 |
public static void save2file(String name, String contents) { |
66 |
File file;
|
67 |
try {
|
68 |
file = File.createTempFile("gvsig-" + name + "-", ".html"); |
69 |
FileWriter fwriter = new FileWriter(file); |
70 |
fwriter.append(contents); |
71 |
fwriter.close(); |
72 |
} catch (IOException e) { |
73 |
logger.warn("Can't save contents to temp file gvsig-" + name, e);
|
74 |
} |
75 |
} |
76 |
public InfoPanel(final String html) { |
77 |
this.setLayout(new BorderLayout()); |
78 |
this.setPreferredSize(new Dimension(500, 300)); |
79 |
this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); |
80 |
|
81 |
text = new JTextPane(); |
82 |
text.setContentType("text/html");
|
83 |
text.setEditable(false);
|
84 |
text.setText(html); |
85 |
text.setCaretPosition(0);
|
86 |
|
87 |
JScrollPane scrollPane = new JScrollPane(text); |
88 |
scrollPane.setPreferredSize(new Dimension(500, 220)); |
89 |
|
90 |
accept = new JButton("Accept"); |
91 |
accept.addActionListener(new ActionListener() { |
92 |
public void actionPerformed(ActionEvent arg0) { |
93 |
setVisible(false);
|
94 |
} |
95 |
}); |
96 |
copy = new JButton("Copy to clipboard"); |
97 |
copy.addActionListener(new ActionListener() { |
98 |
public void actionPerformed(ActionEvent arg0) { |
99 |
ApplicationLocator.getManager().putInClipboard( |
100 |
text.getText()); |
101 |
} |
102 |
}); |
103 |
|
104 |
JPanel buttonsPanel = new JPanel(); |
105 |
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, |
106 |
BoxLayout.LINE_AXIS));
|
107 |
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
108 |
|
109 |
buttonsPanel.add(Box.createHorizontalGlue());
|
110 |
buttonsPanel.add(copy); |
111 |
buttonsPanel.add(accept); |
112 |
|
113 |
this.add(scrollPane, BorderLayout.CENTER); |
114 |
this.add(buttonsPanel, BorderLayout.SOUTH); |
115 |
this.setVisible(true); |
116 |
} |
117 |
|
118 |
} |