📄 customtabletooltiphandler.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: CustomTableTooltipHandler.java
package org.gudy.azureus2.ui.swt.components;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;
public class CustomTableTooltipHandler
implements Listener
{
Shell toolTipShell;
Shell mainShell;
Label toolTipLabel;
private final Table table;
public CustomTableTooltipHandler(Table _table)
{
toolTipShell = null;
mainShell = null;
toolTipLabel = null;
table = _table;
mainShell = table.getShell();
table.addListener(12, this);
table.addListener(1, this);
table.addListener(5, this);
table.addListener(32, this);
mainShell.addListener(27, this);
table.addListener(27, this);
table.setToolTipText("");
}
public void handleEvent(Event event)
{
switch (event.type)
{
case 32: // ' '
if (toolTipShell != null && !toolTipShell.isDisposed())
toolTipShell.dispose();
TableItem item = table.getItem(new Point(event.x, event.y));
if (item == null)
return;
Object oToolTip = item.getData("tooltip");
if (oToolTip == null)
oToolTip = item.getText(0);
if (oToolTip == null || !(oToolTip instanceof String))
return;
String sToolTip = (String)oToolTip;
Display d = table.getDisplay();
if (d == null)
return;
toolTipShell = new Shell(table.getShell(), 16384);
FillLayout f = new FillLayout();
try
{
f.marginWidth = 3;
f.marginHeight = 1;
}
catch (NoSuchFieldError e) { }
toolTipShell.setLayout(f);
toolTipShell.setBackground(d.getSystemColor(29));
toolTipLabel = new Label(toolTipShell, 64);
toolTipLabel.setForeground(d.getSystemColor(28));
toolTipLabel.setBackground(d.getSystemColor(29));
toolTipLabel.setText(sToolTip.replaceAll("&", "&&"));
Point size = toolTipLabel.computeSize(-1, -1);
if (size.x > 600)
size = toolTipLabel.computeSize(600, -1, true);
size.x += toolTipShell.getBorderWidth() * 2 + 2;
size.y += toolTipShell.getBorderWidth() * 2;
try
{
size.x += toolTipShell.getBorderWidth() * 2 + f.marginWidth * 2;
size.y += toolTipShell.getBorderWidth() * 2 + f.marginHeight * 2;
}
catch (NoSuchFieldError e) { }
Point pt = table.toDisplay(event.x, event.y);
Rectangle displayRect;
try
{
displayRect = table.getMonitor().getClientArea();
}
catch (NoSuchMethodError e)
{
displayRect = table.getDisplay().getClientArea();
}
if (pt.x + size.x > displayRect.x + displayRect.width)
pt.x = (displayRect.x + displayRect.width) - size.x;
if (pt.y + size.y > displayRect.y + displayRect.height)
pt.y -= size.y + 2;
else
pt.y += 21;
if (pt.y < displayRect.y)
pt.y = displayRect.y;
toolTipShell.setBounds(pt.x, pt.y, size.x, size.y);
toolTipShell.setVisible(true);
break;
case 12: // '\f'
if (mainShell != null && !mainShell.isDisposed())
mainShell.removeListener(27, this);
if (table != null && !table.isDisposed())
mainShell.removeListener(27, this);
// fall through
default:
if (toolTipShell != null)
{
toolTipShell.dispose();
toolTipShell = null;
toolTipLabel = null;
}
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -