src/org/objectweb/cjdbc/console/gui/jtools/JMultiLineToolTip.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.console.gui.jtools; 00026 00027 import java.awt.Dimension; 00028 import java.awt.Font; 00029 import java.awt.Graphics; 00030 00031 import javax.swing.CellRendererPane; 00032 import javax.swing.JComponent; 00033 import javax.swing.JTextArea; 00034 import javax.swing.JToolTip; 00035 import javax.swing.plaf.ComponentUI; 00036 import javax.swing.plaf.basic.BasicToolTipUI; 00037 00045 public class JMultiLineToolTip extends JToolTip 00046 { 00047 00051 public JMultiLineToolTip() 00052 { 00053 updateUI(); 00054 } 00055 00059 public void updateUI() 00060 { 00061 setUI(MultiLineToolTipUI.createUI(this)); 00062 } 00063 00069 public void setColumns(int columns) 00070 { 00071 this.columns = columns; 00072 this.fixedwidth = 0; 00073 } 00074 00080 public int getColumns() 00081 { 00082 return columns; 00083 } 00084 00090 public void setFixedWidth(int width) 00091 { 00092 this.fixedwidth = width; 00093 this.columns = 0; 00094 } 00095 00101 public int getFixedWidth() 00102 { 00103 return fixedwidth; 00104 } 00105 00106 protected int columns = 0; 00107 protected int fixedwidth = 0; 00108 } 00109 00110 class MultiLineToolTipUI extends BasicToolTipUI 00111 { 00112 static MultiLineToolTipUI sharedInstance = new MultiLineToolTipUI(); 00113 Font smallFont; 00114 static JToolTip tip; 00115 protected CellRendererPane rendererPane; 00116 00117 private static JTextArea textArea; 00118 00122 public static ComponentUI createUI(JComponent c) 00123 { 00124 return sharedInstance; 00125 } 00126 00130 public MultiLineToolTipUI() 00131 { 00132 super(); 00133 } 00134 00138 public void installUI(JComponent c) 00139 { 00140 super.installUI(c); 00141 tip = (JToolTip) c; 00142 rendererPane = new CellRendererPane(); 00143 c.add(rendererPane); 00144 } 00145 00149 public void uninstallUI(JComponent c) 00150 { 00151 super.uninstallUI(c); 00152 00153 c.remove(rendererPane); 00154 rendererPane = null; 00155 } 00156 00161 public void paint(Graphics g, JComponent c) 00162 { 00163 Dimension size = c.getSize(); 00164 textArea.setBackground(c.getBackground()); 00165 rendererPane.paintComponent(g, textArea, c, 1, 1, size.width - 1, 00166 size.height - 1, true); 00167 } 00168 00172 public Dimension getPreferredSize(JComponent c) 00173 { 00174 String tipText = ((JToolTip) c).getTipText(); 00175 if (tipText == null) 00176 return new Dimension(0, 0); 00177 textArea = new JTextArea(tipText); 00178 rendererPane.removeAll(); 00179 rendererPane.add(textArea); 00180 textArea.setWrapStyleWord(true); 00181 int width = ((JMultiLineToolTip) c).getFixedWidth(); 00182 int columns = ((JMultiLineToolTip) c).getColumns(); 00183 00184 if (columns > 0) 00185 { 00186 textArea.setColumns(columns); 00187 textArea.setSize(0, 0); 00188 textArea.setLineWrap(true); 00189 textArea.setSize(textArea.getPreferredSize()); 00190 } 00191 else if (width > 0) 00192 { 00193 textArea.setLineWrap(true); 00194 Dimension d = textArea.getPreferredSize(); 00195 d.width = width; 00196 d.height++; 00197 textArea.setSize(d); 00198 } 00199 else 00200 textArea.setLineWrap(false); 00201 00202 Dimension dim = textArea.getPreferredSize(); 00203 00204 dim.height += 1; 00205 dim.width += 1; 00206 return dim; 00207 } 00208 00212 public Dimension getMinimumSize(JComponent c) 00213 { 00214 return getPreferredSize(c); 00215 } 00216 00220 public Dimension getMaximumSize(JComponent c) 00221 { 00222 return getPreferredSize(c); 00223 } 00224 }

CJDBCversion1.0.4に対してTue Oct 12 15:15:58 2004に生成されました。 doxygen 1.3.8