001 /* 002 * Copyright (C) 2008-2010 by Holger Arndt 003 * 004 * This file is part of the Universal Java Matrix Package (UJMP). 005 * See the NOTICE file distributed with this work for additional 006 * information regarding copyright ownership and licensing. 007 * 008 * UJMP is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation; either version 2 011 * of the License, or (at your option) any later version. 012 * 013 * UJMP is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public 019 * License along with UJMP; if not, write to the 020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 021 * Boston, MA 02110-1301 USA 022 */ 023 024 package org.ujmp.gui.util; 025 026 import org.ujmp.core.Coordinates; 027 import org.ujmp.core.Matrix; 028 import org.ujmp.core.util.MathUtil; 029 import org.ujmp.core.util.StringUtil; 030 import org.ujmp.gui.MatrixGUIObject; 031 032 public abstract class TooltipUtil { 033 034 public static String getTooltip(MatrixGUIObject matrix, long... coordinates) { 035 String toolTip = "<html><b>[" + Coordinates.toString(coordinates) 036 + "]</b>"; 037 038 String columnLabel = null; 039 try { 040 columnLabel = matrix 041 .getColumnName((int) coordinates[Matrix.COLUMN]); 042 } catch (Exception e) { 043 } 044 if (columnLabel != null) { 045 toolTip += " <b>(" + columnLabel + ")</b>"; 046 } 047 048 toolTip += "<br><br>"; 049 050 toolTip += "<table cellpadding=1 cellspacing=1>"; 051 052 toolTip += "<tr>"; 053 toolTip += "<td>"; 054 toolTip += "<b>Object:</b>"; 055 toolTip += "</td>"; 056 toolTip += "<td>"; 057 058 Object o = null; 059 try { 060 o = matrix.getValueAt((int) coordinates[0], (int) coordinates[1]); 061 } catch (Exception e) { 062 } 063 064 if (o != null) { 065 toolTip += o.getClass(); 066 } else { 067 toolTip += "[null]"; 068 } 069 toolTip += "</td>"; 070 toolTip += "</tr>"; 071 072 toolTip += "<tr>"; 073 toolTip += "<td>"; 074 toolTip += "<b>String:</b>"; 075 toolTip += "</td>"; 076 toolTip += "<td>"; 077 try { 078 String s = StringUtil.getString(o); 079 if (s != null && s.length() > 25) { 080 s = s.substring(0, 25); 081 } 082 toolTip += s; 083 } catch (Exception e) { 084 } 085 toolTip += "</td>"; 086 toolTip += "</tr>"; 087 088 toolTip += "<tr>"; 089 toolTip += "<td>"; 090 toolTip += "<b>Double:</b>"; 091 toolTip += "</td>"; 092 toolTip += "<td>"; 093 try { 094 toolTip += MathUtil.getDouble(o); 095 } catch (Exception e) { 096 } 097 toolTip += "</td>"; 098 toolTip += "</tr>"; 099 100 toolTip += "<tr>"; 101 toolTip += "<td>"; 102 toolTip += "<b>Float:</b>"; 103 toolTip += "</td>"; 104 toolTip += "<td>"; 105 try { 106 toolTip += MathUtil.getFloat(o); 107 } catch (Exception e) { 108 } 109 toolTip += "</td>"; 110 toolTip += "</tr>"; 111 112 toolTip += "<tr>"; 113 toolTip += "<td>"; 114 toolTip += "<b>Long:</b>"; 115 toolTip += "</td>"; 116 toolTip += "<td>"; 117 try { 118 toolTip += MathUtil.getLong(o); 119 } catch (Exception e) { 120 } 121 toolTip += "</td>"; 122 toolTip += "</tr>"; 123 124 toolTip += "<tr>"; 125 toolTip += "<td>"; 126 toolTip += "<b>Short:</b>"; 127 toolTip += "</td>"; 128 toolTip += "<td>"; 129 try { 130 toolTip += MathUtil.getShort(o); 131 } catch (Exception e) { 132 } 133 toolTip += "</td>"; 134 toolTip += "</tr>"; 135 136 toolTip += "<tr>"; 137 toolTip += "<td>"; 138 toolTip += "<b>Int:</b>"; 139 toolTip += "</td>"; 140 toolTip += "<td>"; 141 try { 142 toolTip += MathUtil.getInt(o); 143 } catch (Exception e) { 144 } 145 toolTip += "</td>"; 146 toolTip += "</tr>"; 147 148 toolTip += "<tr>"; 149 toolTip += "<td>"; 150 toolTip += "<b>Byte:</b>"; 151 toolTip += "</td>"; 152 toolTip += "<td>"; 153 try { 154 toolTip += MathUtil.getByte(o); 155 } catch (Exception e) { 156 } 157 toolTip += "</td>"; 158 toolTip += "</tr>"; 159 160 toolTip += "<tr>"; 161 toolTip += "<td>"; 162 toolTip += "<b>Char:</b>"; 163 toolTip += "</td>"; 164 toolTip += "<td>"; 165 try { 166 toolTip += MathUtil.getChar(o); 167 } catch (Exception e) { 168 } 169 toolTip += "</td>"; 170 toolTip += "</tr>"; 171 172 toolTip += "<tr>"; 173 toolTip += "<td>"; 174 toolTip += "<b>Boolean:</b>"; 175 toolTip += "</td>"; 176 toolTip += "<td>"; 177 try { 178 toolTip += MathUtil.getBoolean(o); 179 } catch (Exception e) { 180 } 181 toolTip += "</td>"; 182 toolTip += "</tr>"; 183 184 toolTip += "<tr>"; 185 toolTip += "<td>"; 186 toolTip += "<b>Date:</b>"; 187 toolTip += "</td>"; 188 toolTip += "<td>"; 189 try { 190 toolTip += MathUtil.getDate(o); 191 } catch (Exception e) { 192 } 193 toolTip += "</td>"; 194 toolTip += "</tr>"; 195 196 toolTip += "</table>"; 197 198 toolTip += "</html>"; 199 return toolTip; 200 } 201 }