From 339d480d394100714c399ceca4789a79dad3f9b0 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Wed, 27 Nov 2002 18:57:44 +0000 Subject: [PATCH] removed unsed hyperlink stuff which leaked cursors --- core/org.eclipse.cdt.ui/ChangeLog | 4 + .../cdt/utils/ui/controls/ControlFactory.java | 62 +++--- .../utils/ui/controls/HyperlinkHandler.java | 176 ------------------ .../utils/ui/controls/IHyperlinkListener.java | 15 -- 4 files changed, 28 insertions(+), 229 deletions(-) delete mode 100644 core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/HyperlinkHandler.java delete mode 100644 core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/IHyperlinkListener.java diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 77b8ad114c9..9ea9ba56c8f 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,7 @@ +2002-11-27 David Inglis + * utils.ui/.../controls/ControlFactory.java: + removed unsed hyperlink stuff since it was leaking Cursors. + 2002-11-27 Alain Magloire * src/.../internal/ui/preferences/CProjectPropertyPage.java: diff --git a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/ControlFactory.java b/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/ControlFactory.java index 5e989a01470..8a964f0ed5d 100644 --- a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/ControlFactory.java +++ b/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/ControlFactory.java @@ -5,32 +5,39 @@ package org.eclipse.cdt.utils.ui.controls; * All Rights Reserved. */ -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.layout.*; +import java.util.StringTokenizer; + import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.TableLayout; import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.ui.PlatformUI; import org.eclipse.swt.SWT; -import java.util.StringTokenizer; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; public class ControlFactory { - private static HyperlinkHandler defaultHyperlinkHandler = new HyperlinkHandler(); - - public static void dispose() { - defaultHyperlinkHandler.dispose(); - } - public static Control setParentColors(Control control) { Composite parent = control.getParent(); control.setBackground(parent.getBackground()); @@ -164,28 +171,7 @@ public class ControlFactory { return createLabel(parent, text, widthHint, heightHint, SWT.LEFT | SWT.WRAP); } - /** - * Utility method that creates a HyperLinkLabel instance - * and sets the default layout data. - * - * @param parent the parent for the new label - * @param text the text for the new label - * @param TypedListener click event listener - * @return the new label - */ - public static Label createHyperlinkLabel(Composite parent, String text, IHyperlinkListener listener, - HyperlinkHandler hyperlinkHandler) { - Label label = createLabel(parent, text); - turnIntoHyperlink(label, listener, - (null == hyperlinkHandler) ? defaultHyperlinkHandler : hyperlinkHandler); - return label; - } - public static void turnIntoHyperlink(Control control, IHyperlinkListener listener, - HyperlinkHandler hyperlinkHandler) { - hyperlinkHandler.registerHyperlink(control, listener); - } - /** * Creates an new checkbox instance and sets the default * layout data. diff --git a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/HyperlinkHandler.java b/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/HyperlinkHandler.java deleted file mode 100644 index eca37bbb67d..00000000000 --- a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/HyperlinkHandler.java +++ /dev/null @@ -1,176 +0,0 @@ -package org.eclipse.cdt.utils.ui.controls; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import java.util.*; -import org.eclipse.swt.*; - -public class HyperlinkHandler implements MouseListener, MouseTrackListener, PaintListener { - public static final int UNDERLINE_NEVER = 1; - public static final int UNDERLINE_ROLLOVER = 2; - public static final int UNDERLINE_ALWAYS = 3; - - private Cursor hyperlinkCursor; - private Cursor busyCursor; - private boolean hyperlinkCursorUsed=true; - private int hyperlinkUnderlineMode=UNDERLINE_ALWAYS; - private Color background; - private Color foreground; - private Color activeBackground; - private Color activeForeground; - private Hashtable hyperlinkListeners; - private Control lastLink; - -public HyperlinkHandler() { - hyperlinkListeners = new Hashtable(); - hyperlinkCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND); - busyCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_WAIT); -} -public void dispose() { - hyperlinkCursor.dispose(); - busyCursor.dispose(); -} -public org.eclipse.swt.graphics.Color getActiveBackground() { - return activeBackground; -} -public org.eclipse.swt.graphics.Color getActiveForeground() { - return activeForeground; -} -public org.eclipse.swt.graphics.Color getBackground() { - return background; -} -public org.eclipse.swt.graphics.Cursor getBusyCursor() { - return busyCursor; -} -public org.eclipse.swt.graphics.Color getForeground() { - return foreground; -} -public org.eclipse.swt.graphics.Cursor getHyperlinkCursor() { - return hyperlinkCursor; -} -public int getHyperlinkUnderlineMode() { - return hyperlinkUnderlineMode; -} -public org.eclipse.swt.widgets.Control getLastLink() { - return lastLink; -} -public boolean isHyperlinkCursorUsed() { - return hyperlinkCursorUsed; -} - public void mouseDoubleClick(MouseEvent e) { - } -public void mouseDown(MouseEvent e) { - if (e.button == 1) - return; - lastLink = (Control)e.widget; -} -public void mouseEnter(MouseEvent e) { - Control control = (Control) e.widget; - if (isHyperlinkCursorUsed()) - control.setCursor(hyperlinkCursor); - if (activeBackground != null) - control.setBackground(activeBackground); - if (activeForeground != null) - control.setForeground(activeForeground); - if (hyperlinkUnderlineMode==UNDERLINE_ROLLOVER) underline(control, true); - - IHyperlinkListener action = - (IHyperlinkListener) hyperlinkListeners.get(control); - if (action != null) - action.linkEntered(control); -} -public void mouseExit(MouseEvent e) { - Control control = (Control) e.widget; - if (isHyperlinkCursorUsed()) - control.setCursor(null); - if (hyperlinkUnderlineMode==UNDERLINE_ROLLOVER) - underline(control, false); - if (background != null) - control.setBackground(background); - if (foreground != null) - control.setForeground(foreground); - IHyperlinkListener action = - (IHyperlinkListener) hyperlinkListeners.get(control); - if (action != null) - action.linkExited(control); -} - public void mouseHover(MouseEvent e) { - } -public void mouseUp(MouseEvent e) { - if (e.button != 1) - return; - IHyperlinkListener action = - (IHyperlinkListener) hyperlinkListeners.get(e.widget); - if (action != null) { - Control c = (Control) e.widget; - c.setCursor(busyCursor); - action.linkActivated(c); - if (!c.isDisposed()) - c.setCursor(isHyperlinkCursorUsed()?hyperlinkCursor:null); - } -} -public void paintControl(PaintEvent e) { - Control label = (Control) e.widget; - if (hyperlinkUnderlineMode == UNDERLINE_ALWAYS) - HyperlinkHandler.underline(label, true); -} -public void registerHyperlink(Control control, IHyperlinkListener listener) { - if (background != null) - control.setBackground(background); - if (foreground != null) - control.setForeground(foreground); - control.addMouseListener(this); - control.addMouseTrackListener(this); - if (hyperlinkUnderlineMode == UNDERLINE_ALWAYS) - control.addPaintListener(this); - hyperlinkListeners.put(control, listener); - removeDisposedLinks(); -} -private void removeDisposedLinks() { - for (Enumeration keys = hyperlinkListeners.keys(); keys.hasMoreElements();) { - Control control = (Control)keys.nextElement(); - if (control.isDisposed()) { - hyperlinkListeners.remove(control); - } - } -} -public void reset() { - hyperlinkListeners.clear(); -} -public void setActiveBackground(org.eclipse.swt.graphics.Color newActiveBackground) { - activeBackground = newActiveBackground; -} -public void setActiveForeground(org.eclipse.swt.graphics.Color newActiveForeground) { - activeForeground = newActiveForeground; -} -public void setBackground(org.eclipse.swt.graphics.Color newBackground) { - background = newBackground; -} -public void setForeground(org.eclipse.swt.graphics.Color newForeground) { - foreground = newForeground; -} -public void setHyperlinkCursorUsed(boolean newHyperlinkCursorUsed) { - hyperlinkCursorUsed = newHyperlinkCursorUsed; -} -public void setHyperlinkUnderlineMode(int newHyperlinkUnderlineMode) { - hyperlinkUnderlineMode = newHyperlinkUnderlineMode; -} -public static void underline(Control control, boolean inside) { - if (!(control instanceof Label)) - return; - Composite parent = control.getParent(); - Rectangle bounds = control.getBounds(); - GC gc = new GC(parent); - Color color = inside? control.getForeground() : control.getBackground(); - gc.setForeground(color); - int y = bounds.y + bounds.height; - gc.drawLine(bounds.x, y, bounds.x+bounds.width, y); - gc.dispose(); -} -} diff --git a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/IHyperlinkListener.java b/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/IHyperlinkListener.java deleted file mode 100644 index 203c007f86c..00000000000 --- a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/IHyperlinkListener.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.eclipse.cdt.utils.ui.controls; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.swt.widgets.*; - -public interface IHyperlinkListener { - -public void linkActivated(Control linkLabel); -public void linkEntered(Control linkLabel); -public void linkExited(Control linkLabel); -}