1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 01:45:33 +02:00

removed unsed hyperlink stuff which leaked cursors

This commit is contained in:
David Inglis 2002-11-27 18:57:44 +00:00
parent 6e2179b64b
commit 339d480d39
4 changed files with 28 additions and 229 deletions

View file

@ -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:

View file

@ -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.

View file

@ -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();
}
}

View file

@ -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);
}