diff options
| author | pnehrer | 2005-03-04 01:59:23 +0000 |
|---|---|---|
| committer | pnehrer | 2005-03-04 01:59:23 +0000 |
| commit | f47a92bcae0767a3915a40ad0b593004f8de7f88 (patch) | |
| tree | b80dd5b732883ac84079b174310d04fa1e6ea81c | |
| parent | 4a4f1a52b8d155091cd83ca26dbf1e645936bf0b (diff) | |
| download | org.eclipse.ecf-f47a92bcae0767a3915a40ad0b593004f8de7f88.tar.gz org.eclipse.ecf-f47a92bcae0767a3915a40ad0b593004f8de7f88.tar.xz org.eclipse.ecf-f47a92bcae0767a3915a40ad0b593004f8de7f88.zip | |
Fixed more NPEs.
| -rw-r--r-- | examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatWindow.java | 383 |
1 files changed, 193 insertions, 190 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatWindow.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatWindow.java index 10608d72d..40b9815ae 100644 --- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatWindow.java +++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatWindow.java @@ -1,13 +1,13 @@ /**************************************************************************** -* Copyright (c) 2004 Composent, Inc. and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Composent, Inc. - initial API and implementation -*****************************************************************************/ + * Copyright (c) 2004 Composent, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Composent, Inc. - initial API and implementation + *****************************************************************************/ package org.eclipse.ecf.example.collab.ui; @@ -35,198 +35,201 @@ import org.eclipse.swt.widgets.Shell; * */ public class ChatWindow extends ApplicationWindow { - - private static final long FLASH_INTERVAL = 600; - private LineChatClientView view; + private static final long FLASH_INTERVAL = 600; - private ChatTreeViewer tree; + private LineChatClientView view; - private String initText; + private ChatTreeViewer tree; - private ChatComposite chat; + private String initText; - private Image image; - - private Image blank; + private ChatComposite chat; - private boolean flashing; + private Image image; - private final Runnable flipImage = new Runnable() { - public void run() { - Shell shell = getShell(); - if (shell != null && !shell.isDisposed()) - if (blank == shell.getImage()) { - if (image != null && !image.isDisposed()) - shell.setImage(image); - } else { - if (blank != null && !blank.isDisposed()) - shell.setImage(blank); - } - } - }; + private Image blank; - private final Runnable showImageRunnable = new Runnable() { + private boolean flashing; + + private final Runnable flipImage = new Runnable() { public void run() { Shell shell = getShell(); - if (shell != null && !shell.isDisposed() && image != null - && !image.isDisposed()) - shell.setImage(image); + if (shell != null && !shell.isDisposed()) + if (blank == shell.getImage()) { + if (image != null && !image.isDisposed()) + shell.setImage(image); + } else { + if (blank != null && !blank.isDisposed()) + shell.setImage(blank); + } + } + }; + + private Flash flash; + + private class Flash implements Runnable { + + private final Display display; + + private boolean disposed; + + public Flash(Display display) { + this.display = display; + } + + public synchronized void dispose() { + if (!disposed) { + disposed = true; + notify(); + } + } + + public void run() { + while (true) { + synchronized (this) { + try { + while (!flashing && !disposed) + wait(); + } catch (InterruptedException e) { + break; + } + } + + if (disposed && display.isDisposed()) + break; + + display.syncExec(flipImage); + synchronized (this) { + try { + wait(FLASH_INTERVAL); + } catch (InterruptedException e) { + break; + } + } + } } }; - private Flash flash; - - private class Flash implements Runnable { - - private final Display display; - - public Flash(Display display) { - this.display = display; - } - - public void run() { - while (true) { - synchronized (this) { - try { - while (!flashing) - wait(); - } catch (InterruptedException e) { - break; - } - } - - if (display.isDisposed()) - break; - - display.syncExec(flipImage); - synchronized (this) { - try { - wait(FLASH_INTERVAL); - } catch (InterruptedException e) { - break; - } - } - } - } - }; - - public ChatWindow(LineChatClientView view, Composite parent, - ChatTreeViewer tree, String initText) { - super(null); - this.view = view; - this.tree = tree; - this.initText = initText; - addStatusLine(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) - */ - protected void configureShell(final Shell newShell) { - super.configureShell(newShell); - newShell.setText("Team Chat: " + view.name); - image = ImageDescriptor.createFromURL( - ClientPlugin.getDefault().find(new Path("icons/person.gif"))) - .createImage(); - newShell.setImage(image); - RGB[] colors = new RGB[2]; - colors[0] = new RGB(0, 0, 0); - colors[1] = new RGB(255, 255, 255); - ImageData data = new ImageData(16, 16, 1, new PaletteData(colors)); - data.transparentPixel = 0; - blank = new Image(newShell.getDisplay(), data); - - flash = new Flash(newShell.getDisplay()); - new Thread(flash).start(); - - newShell.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - flash(); - if (image != null) - image.dispose(); - - if (blank != null) - blank.dispose(); - } - }); - - newShell.addShellListener(new ShellAdapter() { - public void shellActivated(ShellEvent e) { - stopFlashing(); - if (!chat.isDisposed()) - chat.textinput.setFocus(); - } - }); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite) - */ - protected Control createContents(Composite parent) { - chat = new ChatComposite(view, parent, tree, SWT.NORMAL, initText, this); - chat.setLayoutData(new GridData(GridData.FILL_BOTH)); - chat.setFont(parent.getFont()); - return chat; - } - - ChatComposite getChat() { - return chat; - } - - boolean hasFocus() { - if (getShell().isDisposed()) - return false; - else - return hasFocus(getShell()); - } - - private boolean hasFocus(Composite composite) { - if (composite.isFocusControl()) - return true; - else { - Control[] children = composite.getChildren(); - for (int i = 0; i < children.length; ++i) - if (children[i] instanceof Composite - && hasFocus((Composite) children[i])) - return true; - else if (children[i].isFocusControl()) - return true; - } - - return false; - } - - void flash() { - synchronized (flash) { - if (!flashing) { - flashing = true; - flash.notify(); - } - } - } - - private void stopFlashing() { - synchronized (flash) { - if (flashing) { - flashing = false; - if (!getShell().isDisposed() && image != null && !image.isDisposed()) - getShell().setImage(image); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.window.Window#handleShellCloseEvent() - */ - protected void handleShellCloseEvent() { - if (!getShell().isDisposed()) - getShell().setVisible(false); - } + public ChatWindow(LineChatClientView view, Composite parent, + ChatTreeViewer tree, String initText) { + super(null); + this.view = view; + this.tree = tree; + this.initText = initText; + addStatusLine(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + protected void configureShell(final Shell newShell) { + super.configureShell(newShell); + newShell.setText("Team Chat: " + view.name); + image = ImageDescriptor.createFromURL( + ClientPlugin.getDefault().find(new Path("icons/person.gif"))) + .createImage(); + newShell.setImage(image); + RGB[] colors = new RGB[2]; + colors[0] = new RGB(0, 0, 0); + colors[1] = new RGB(255, 255, 255); + ImageData data = new ImageData(16, 16, 1, new PaletteData(colors)); + data.transparentPixel = 0; + blank = new Image(newShell.getDisplay(), data); + + flash = new Flash(newShell.getDisplay()); + new Thread(flash).start(); + + newShell.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + if (flash != null) + flash.dispose(); + + if (image != null) + image.dispose(); + + if (blank != null) + blank.dispose(); + } + }); + + newShell.addShellListener(new ShellAdapter() { + public void shellActivated(ShellEvent e) { + stopFlashing(); + if (!chat.isDisposed()) + chat.textinput.setFocus(); + } + }); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite) + */ + protected Control createContents(Composite parent) { + chat = new ChatComposite(view, parent, tree, SWT.NORMAL, initText, this); + chat.setLayoutData(new GridData(GridData.FILL_BOTH)); + chat.setFont(parent.getFont()); + return chat; + } + + ChatComposite getChat() { + return chat; + } + + boolean hasFocus() { + if (getShell().isDisposed()) + return false; + else + return hasFocus(getShell()); + } + + private boolean hasFocus(Composite composite) { + if (composite.isFocusControl()) + return true; + else { + Control[] children = composite.getChildren(); + for (int i = 0; i < children.length; ++i) + if (children[i] instanceof Composite + && hasFocus((Composite) children[i])) + return true; + else if (children[i].isFocusControl()) + return true; + } + + return false; + } + + void flash() { + synchronized (flash) { + if (!flashing) { + flashing = true; + flash.notify(); + } + } + } + + private void stopFlashing() { + synchronized (flash) { + if (flashing) { + flashing = false; + if (!getShell().isDisposed() && image != null + && !image.isDisposed()) + getShell().setImage(image); + } + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.window.Window#handleShellCloseEvent() + */ + protected void handleShellCloseEvent() { + if (!getShell().isDisposed()) + getShell().setVisible(false); + } }
\ No newline at end of file |
