01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: *
13: * @created Feb 01, 2006
14: * @author Michael D'Amour
15: */
16:
17: package org.pentaho.jfreereport.wizard.ui.swt;
18:
19: import java.util.HashMap;
20: import org.eclipse.swt.SWT;
21: import org.eclipse.swt.graphics.Point;
22: import org.eclipse.swt.graphics.Rectangle;
23: import org.eclipse.swt.layout.FillLayout;
24: import org.eclipse.swt.widgets.Event;
25: import org.eclipse.swt.widgets.Label;
26: import org.eclipse.swt.widgets.List;
27: import org.eclipse.swt.widgets.Listener;
28: import org.eclipse.swt.widgets.Shell;
29: import org.pentaho.jfreereport.wizard.utility.SWTUtility;
30:
31: public class FakeToolTipListListener implements Listener {
32: Shell tip = null;
33: Label label = null;
34: List list = null;
35: HashMap nameMap = null;
36:
37: public FakeToolTipListListener(List list, HashMap nameMap) {
38: setList(list);
39: this .nameMap = nameMap;
40: }
41:
42: public void setList(List list) {
43: this .list = list;
44: }
45:
46: public void handleEvent(Event event) {
47: switch (event.type) {
48: case SWT.Dispose:
49: case SWT.KeyDown:
50: case SWT.MouseMove: {
51: if (tip == null)
52: break;
53: tip.dispose();
54: tip = null;
55: label = null;
56: break;
57: }
58: case SWT.MouseHover: {
59: Point p = new Point(event.x, event.y);
60: String item = SWTUtility.getListItemForPoint(list, p);
61: if (item != null) {
62: if (tip != null && !tip.isDisposed())
63: tip.dispose();
64: tip = new Shell(list.getShell(), SWT.ON_TOP | SWT.TOOL);
65: tip.setLayout(new FillLayout());
66: label = new Label(tip, SWT.NONE);
67: label.setForeground(list.getDisplay().getSystemColor(
68: SWT.COLOR_INFO_FOREGROUND));
69: label.setBackground(list.getDisplay().getSystemColor(
70: SWT.COLOR_INFO_BACKGROUND));
71: String labelText = (String) nameMap.get(item);
72: if (labelText == null) {
73: labelText = item;
74: }
75: label.setText(labelText);
76: Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
77: Rectangle rect = event.getBounds();
78: Point pt = list.toDisplay(rect.x, rect.y);
79: tip.setBounds(pt.x + 20, pt.y + 20, size.x, size.y);
80: tip.setVisible(true);
81: }
82: }
83: }
84: }
85: }
|