package com.webcodepro.applecommander.ui.swt; /* * Copyright (c) 2000, 2003 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ import java.io.ByteArrayOutputStream; import java.io.PrintStream; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.DeviceData; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Region; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; /** * Instructions on how to use the Sleak tool with a standlaone SWT example: * * Modify the main method below to launch your application. * Run Sleak. * */ public class Sleak { Display display; Shell shell; List list; Canvas canvas; Button start, stop, check; Text text; Label label; Object [] oldObjects = new Object [0]; Error [] oldErrors = new Error [0]; Object [] objects = new Object [0]; Error [] errors = new Error [0]; public static void main (String [] args) { DeviceData data = new DeviceData(); data.tracking = true; Display display = new Display (data); Sleak sleak = new Sleak (); sleak.open (); // Launch your application here SwtAppleCommander ac = new SwtAppleCommander(); ac.launch(display); // End of AC code... while (!sleak.shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } void open () { display = Display.getCurrent (); shell = new Shell (display); shell.setText ("S-Leak"); //$NON-NLS-1$ list = new List (shell, SWT.BORDER | SWT.V_SCROLL); list.addListener (SWT.Selection, new Listener () { public void handleEvent (Event event) { refreshObject (); } }); text = new Text (shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); canvas = new Canvas (shell, SWT.BORDER); canvas.addListener (SWT.Paint, new Listener () { public void handleEvent (Event event) { paintCanvas (event); } }); check = new Button (shell, SWT.CHECK); check.setText ("Stack"); //$NON-NLS-1$ check.addListener (SWT.Selection, new Listener () { public void handleEvent (Event e) { toggleStackTrace (); } }); start = new Button (shell, SWT.PUSH); start.setText ("Snap"); //$NON-NLS-1$ start.addListener (SWT.Selection, new Listener () { public void handleEvent (Event event) { refreshAll (); } }); stop = new Button (shell, SWT.PUSH); stop.setText ("Diff"); //$NON-NLS-1$ stop.addListener (SWT.Selection, new Listener () { public void handleEvent (Event event) { refreshDifference (); } }); label = new Label (shell, SWT.BORDER); label.setText ("0 object(s)"); //$NON-NLS-1$ shell.addListener (SWT.Resize, new Listener () { public void handleEvent (Event e) { layout (); } }); check.setSelection (false); text.setVisible (false); Point size = shell.getSize (); shell.setSize (size.x / 2, size.y / 2); shell.open (); } void refreshLabel () { int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0, regions = 0; for (int i=0; i