svn-gvsig-desktop / tags / v1_11_0_Build_1306 / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / panels / utils / MultilineToolTipUI.java @ 35731
History | View | Annotate | Download (4.41 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
package es.prodevelop.cit.gvsig.arcims.gui.panels.utils; |
44 |
|
45 |
import java.awt.Dimension; |
46 |
import java.awt.Font; |
47 |
import java.awt.Graphics; |
48 |
import java.awt.Insets; |
49 |
|
50 |
import javax.swing.CellRendererPane; |
51 |
import javax.swing.JComponent; |
52 |
import javax.swing.JTextArea; |
53 |
import javax.swing.JToolTip; |
54 |
import javax.swing.plaf.ComponentUI; |
55 |
import javax.swing.plaf.basic.BasicToolTipUI; |
56 |
|
57 |
|
58 |
/**
|
59 |
* This class allows nice multiline tool tips.
|
60 |
*
|
61 |
* @author Zafir Anjum
|
62 |
* @author jldominguez
|
63 |
*/
|
64 |
public class MultilineToolTipUI extends BasicToolTipUI { |
65 |
static MultilineToolTipUI sharedInstance = new MultilineToolTipUI(); |
66 |
|
67 |
// Dialog, SansSerif - similar to Arial
|
68 |
// DialogInput, Monospaced - similar to Courier
|
69 |
// Serif - similar to Times New Roman
|
70 |
static JToolTip tip; |
71 |
private static JTextArea textArea; |
72 |
Font smallFont = new Font("Dialog", Font.PLAIN, 12); |
73 |
protected CellRendererPane rendererPane; |
74 |
|
75 |
public MultilineToolTipUI() {
|
76 |
super();
|
77 |
} |
78 |
|
79 |
public static ComponentUI createUI(JComponent c) { |
80 |
return sharedInstance;
|
81 |
} |
82 |
|
83 |
public void installUI(JComponent c) { |
84 |
super.installUI(c);
|
85 |
tip = (JToolTip) c;
|
86 |
rendererPane = new CellRendererPane(); |
87 |
c.add(rendererPane); |
88 |
} |
89 |
|
90 |
public void uninstallUI(JComponent c) { |
91 |
super.uninstallUI(c);
|
92 |
|
93 |
c.remove(rendererPane); |
94 |
rendererPane = null;
|
95 |
} |
96 |
|
97 |
public void paint(Graphics g, JComponent c) { |
98 |
Dimension size = c.getSize();
|
99 |
rendererPane.paintComponent(g, textArea, c, 1, 1, size.width - 1, |
100 |
size.height - 1, true); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Overrides a method that is called by the system and,
|
105 |
* at the same time, creates a nice textarea and displays the tool tip in it.
|
106 |
*/
|
107 |
public Dimension getPreferredSize(JComponent c) { |
108 |
String tipText = ((JToolTip) c).getTipText(); |
109 |
|
110 |
if (tipText == null) { |
111 |
return new Dimension(0, 0); |
112 |
} |
113 |
|
114 |
textArea = new JTextArea(tipText); |
115 |
textArea.setMargin(new Insets(10, 10, 10, 10)); |
116 |
textArea.setBackground(tip.getBackground()); |
117 |
rendererPane.removeAll(); |
118 |
rendererPane.add(textArea); |
119 |
textArea.setWrapStyleWord(true);
|
120 |
textArea.setFont(smallFont); |
121 |
|
122 |
int width = ((JMultilineToolTip) c).getFixedWidth();
|
123 |
int columns = ((JMultilineToolTip) c).getColumns();
|
124 |
|
125 |
if (columns > 0) { |
126 |
textArea.setColumns(columns); |
127 |
textArea.setSize(0, 0); |
128 |
textArea.setLineWrap(true);
|
129 |
textArea.setSize(textArea.getPreferredSize()); |
130 |
} |
131 |
else if (width > 0) { |
132 |
textArea.setLineWrap(true);
|
133 |
|
134 |
Dimension d = textArea.getPreferredSize();
|
135 |
d.width = width; |
136 |
d.height++; |
137 |
textArea.setSize(d); |
138 |
} |
139 |
else
|
140 |
{ |
141 |
textArea.setLineWrap(false);
|
142 |
} |
143 |
|
144 |
Dimension dim = textArea.getPreferredSize();
|
145 |
|
146 |
dim.height += 1;
|
147 |
dim.width += 1;
|
148 |
|
149 |
return dim;
|
150 |
} |
151 |
|
152 |
public Dimension getMinimumSize(JComponent c) { |
153 |
return getPreferredSize(c);
|
154 |
} |
155 |
|
156 |
public Dimension getMaximumSize(JComponent c) { |
157 |
return getPreferredSize(c);
|
158 |
} |
159 |
} |