Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Menu and Dialog Events problem
Menu and Dialog Events problem [message #448095] Sat, 01 January 2005 10:30 Go to next message
Eclipse UserFriend
Originally posted by: lancelim1.yahoo.com

Hi,

I have a problem with the dialog opening when the main menu drop down is
focused. For example, If I drop down any of the menu on the main menu, and
a dialog happens to pop up, the dialog although is focus, the mouse events
seem to be stuck the menu. This case eclipse to behave funny, none of the
mouse and key events can be delivered to both eclipse and dialog until the
dialog is closed and cannot gain focus on both eclipse and dialog.

I have no idea what is wrong. I am currently using eclipse 3.0

The dialog code is attached as below:
package test.views;

import java.awt.Dimension;
import java.awt.Toolkit;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;

public class ChatDialog {

private Shell shell = null;
private Display display;
private static final int HEIGHT = 300;
private static final int WIDTH = 400;

Composite chatComposite = null;

Text convArea = null;
Text inputArea = null;

private GridData caData = null;

Button sendButton;

Color backgroundColor = null;
Font bigFont = null;

public ChatDialog(Shell parentShell)
{
this.display = parentShell.getDisplay();

shell = new Shell(display, SWT.CLOSE| SWT.MIN | SWT.MAX | SWT.RESIZE);
shell.addFocusListener(new FocusListener()
{
public void focusGained(FocusEvent arg0) {
if (inputArea!=null)
inputArea.setFocus();
}
public void focusLost(FocusEvent arg0) {}

}
);

shell.setLayout(new RowLayout());
shell.setText("Test");
shell.setSize(WIDTH, HEIGHT);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
createPartControl(shell);
}

public void setFocus()
{
shell.setEnabled(true);
}
public void open()
{
if(shell != null)
{
shell.pack();
shell.open();

while (!shell.isDisposed())
{
if (!display.isDisposed())
if (!display.readAndDispatch())
{
display.sleep();
}
}
}
}

public void createPartControl(Composite parent)
{
backgroundColor = new Color(null, 255, 255, 255);

chatComposite = new Composite(parent, 0);
GridLayout rl = new GridLayout();
rl.makeColumnsEqualWidth = true;
rl.numColumns = 10;
rl.marginHeight = 0;
rl.marginWidth = 0;
rl.horizontalSpacing = 0;
rl.verticalSpacing = 0;
chatComposite.setLayout(rl);

GridData data;
if (convArea == null)
{
convArea = new Text(chatComposite, SWT.MULTI | SWT.WRAP |
SWT.V_SCROLL | SWT.READ_ONLY);
caData = new GridData ();
caData.horizontalAlignment = GridData.FILL;
caData.verticalAlignment = GridData.FILL;
caData.heightHint = HEIGHT - 65;
caData.widthHint = WIDTH - 30;
caData.horizontalSpan = 10;

caData.grabExcessHorizontalSpace = true;
caData.grabExcessVerticalSpace = true;
convArea.setLayoutData (caData);
convArea.setBackground(backgroundColor);
convArea.setText(strWelcomeMessage);
convArea.addFocusListener(new FocusListener()
{
public void focusGained(FocusEvent arg0) {
if (inputArea!=null)
inputArea.setFocus();
}

public void focusLost(FocusEvent arg0) {}

}
);
}

if (inputArea == null) {
inputArea = new Text(chatComposite, SWT.MULTI | SWT.V_SCROLL |
SWT.BORDER);
data = new GridData ();
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.horizontalSpan = 8;
data.grabExcessHorizontalSpace = true;
inputArea.setLayoutData(data);
inputArea.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.keyCode == SWT.CR) {
sendButtonClick();
}
}
});
}

convArea.setBackground(backgroundColor);

if (sendButton == null) {
sendButton = new Button(chatComposite, SWT.PUSH | SWT.FLAT);
sendButton.setText(strSendMessage);
data = new GridData ();

data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.horizontalSpan = 2;
sendButton.setLayoutData(data);

sendButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
sendButtonClick();
}
});
}

shell.addControlListener(new ControlListener()
{
public void controlMoved(ControlEvent e) {}

public void controlResized(ControlEvent e)
{
Rectangle rect = shell.getClientArea();
caData.heightHint = rect.height - 35;
caData.widthHint = rect.width - 30;
convArea.setLayoutData(caData);
chatComposite.layout(true);
}
}
);
}

private void sendMessage(String mesg)
{
if (mesg == null)
return;

if (mesg.length() == 0)
{

convArea.append(); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
convArea.append(mesg);

}

void sendButtonClick()
{
sendMessage(inputArea.getText().trim());
inputArea.setText("");
inputArea.setFocus();
}

public void dispose()
{
shell.dispose();
}

}
Re: Menu and Dialog Events problem [message #448166 is a reply to message #448095] Tue, 04 January 2005 17:51 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Are you using a Mac? Try getting rid of the references to AWT.

"Lance" <lancelim1@yahoo.com> wrote in message
news:cr5u50$lnb$1@www.eclipse.org...
> Hi,
>
> I have a problem with the dialog opening when the main menu drop down is
> focused. For example, If I drop down any of the menu on the main menu, and
> a dialog happens to pop up, the dialog although is focus, the mouse events
> seem to be stuck the menu. This case eclipse to behave funny, none of the
> mouse and key events can be delivered to both eclipse and dialog until the
> dialog is closed and cannot gain focus on both eclipse and dialog.
>
> I have no idea what is wrong. I am currently using eclipse 3.0
>
> The dialog code is attached as below:
> package test.views;
>
> import java.awt.Dimension;
> import java.awt.Toolkit;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
>
> import org.eclipse.swt.events.ControlEvent;
> import org.eclipse.swt.events.ControlListener;
> import org.eclipse.swt.events.DisposeEvent;
> import org.eclipse.swt.events.DisposeListener;
> import org.eclipse.swt.events.FocusEvent;
> import org.eclipse.swt.events.FocusListener;
> import org.eclipse.swt.events.KeyAdapter;
> import org.eclipse.swt.events.KeyEvent;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.graphics.Color;
> import org.eclipse.swt.graphics.Font;
> import org.eclipse.swt.graphics.Point;
> import org.eclipse.swt.graphics.Rectangle;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.layout.RowLayout;
>
> public class ChatDialog {
>
> private Shell shell = null;
> private Display display;
> private static final int HEIGHT = 300;
> private static final int WIDTH = 400;
>
> Composite chatComposite = null;
>
> Text convArea = null;
> Text inputArea = null;
>
> private GridData caData = null;
>
> Button sendButton;
>
> Color backgroundColor = null;
> Font bigFont = null;
>
> public ChatDialog(Shell parentShell)
> {
> this.display = parentShell.getDisplay();
>
> shell = new Shell(display, SWT.CLOSE| SWT.MIN | SWT.MAX | SWT.RESIZE);
> shell.addFocusListener(new FocusListener()
> {
> public void focusGained(FocusEvent arg0) {
> if (inputArea!=null)
> inputArea.setFocus();
> }
> public void focusLost(FocusEvent arg0) {}
>
> }
> );
>
> shell.setLayout(new RowLayout());
> shell.setText("Test");
> shell.setSize(WIDTH, HEIGHT);
> Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
> createPartControl(shell);
> }
>
> public void setFocus()
> {
> shell.setEnabled(true);
> }
> public void open()
> {
> if(shell != null)
> {
> shell.pack();
> shell.open();
>
> while (!shell.isDisposed())
> {
> if (!display.isDisposed())
> if (!display.readAndDispatch())
> {
> display.sleep();
> }
> }
> }
> }
>
> public void createPartControl(Composite parent)
> {
> backgroundColor = new Color(null, 255, 255, 255);
>
> chatComposite = new Composite(parent, 0);
> GridLayout rl = new GridLayout();
> rl.makeColumnsEqualWidth = true;
> rl.numColumns = 10;
> rl.marginHeight = 0;
> rl.marginWidth = 0;
> rl.horizontalSpacing = 0;
> rl.verticalSpacing = 0;
> chatComposite.setLayout(rl);
>
> GridData data;
> if (convArea == null)
> {
> convArea = new Text(chatComposite, SWT.MULTI | SWT.WRAP |
> SWT.V_SCROLL | SWT.READ_ONLY);
> caData = new GridData ();
> caData.horizontalAlignment = GridData.FILL;
> caData.verticalAlignment = GridData.FILL;
> caData.heightHint = HEIGHT - 65;
> caData.widthHint = WIDTH - 30;
> caData.horizontalSpan = 10;
>
> caData.grabExcessHorizontalSpace = true;
> caData.grabExcessVerticalSpace = true;
> convArea.setLayoutData (caData);
> convArea.setBackground(backgroundColor);
> convArea.setText(strWelcomeMessage);
> convArea.addFocusListener(new FocusListener()
> {
> public void focusGained(FocusEvent arg0) {
> if (inputArea!=null)
> inputArea.setFocus();
> }
>
> public void focusLost(FocusEvent arg0) {}
>
> }
> );
> }
>
> if (inputArea == null) {
> inputArea = new Text(chatComposite, SWT.MULTI | SWT.V_SCROLL |
> SWT.BORDER);
> data = new GridData ();
> data.horizontalAlignment = GridData.FILL;
> data.verticalAlignment = GridData.FILL;
> data.horizontalSpan = 8;
> data.grabExcessHorizontalSpace = true;
> inputArea.setLayoutData(data);
> inputArea.addKeyListener(new KeyAdapter() {
> public void keyReleased(KeyEvent e) {
> if (e.keyCode == SWT.CR) {
> sendButtonClick();
> }
> }
> });
> }
>
> convArea.setBackground(backgroundColor);
>
> if (sendButton == null) {
> sendButton = new Button(chatComposite, SWT.PUSH | SWT.FLAT);
> sendButton.setText(strSendMessage);
> data = new GridData ();
>
> data.horizontalAlignment = GridData.FILL;
> data.verticalAlignment = GridData.FILL;
> data.horizontalSpan = 2;
> sendButton.setLayoutData(data);
>
> sendButton.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> sendButtonClick();
> }
> });
> }
>
> shell.addControlListener(new ControlListener()
> {
> public void controlMoved(ControlEvent e) {}
>
> public void controlResized(ControlEvent e)
> {
> Rectangle rect = shell.getClientArea();
> caData.heightHint = rect.height - 35;
> caData.widthHint = rect.width - 30;
> convArea.setLayoutData(caData);
> chatComposite.layout(true);
> }
> }
> );
> }
>
> private void sendMessage(String mesg)
> {
> if (mesg == null)
> return;
>
> if (mesg.length() == 0)
> {
>
> convArea.append(); //$NON-NLS-1$ //$NON-NLS-2$
> return;
> }
> convArea.append(mesg);
>
> }
>
> void sendButtonClick()
> {
> sendMessage(inputArea.getText().trim());
> inputArea.setText("");
> inputArea.setFocus();
> }
>
> public void dispose()
> {
> shell.dispose();
> }
>
> }
>
Re: Menu and Dialog Events problem [message #448182 is a reply to message #448166] Wed, 05 January 2005 02:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lancelim1.yahoo.com

No i am not. Using pure swt. After further meddling, the problem seem to
be that it is caught in
while (!shell.isDisposed())
{
if (!display.isDisposed())
if (!display.readAndDispatch())
{
display.sleep();
}
}.

It will loop till the shell is been disposed. This dialog is supposed to
pop up based on a timer event. So there is no way to tell when it will
come up. If I happen to be on the menu bar or if there happen to be
another dialog in front, the above loop will never exit. This somehow
cause the mouse event to be dangling between the main display and the
dialog.

Removing the loop seem to solve part of the problem, although I got no
idea why.

The more serious problem I am facing now is if the dialog happens together
with a browser dialog, such as one asking for password or javascript
error. This will cause the dialog not to be redraw and the dialog will
start taking up cpu resourceds. If I change the dialog to modal, it will
cause an unexpected exception in native code outside event.

The error is
An unexpected exception has been deced in native code outside the VM.
Unexpected Signal : EXECPTION_ACCESS_VIOLATION (0xc00000005) occurred at
PC=0x7736E95C
Function = CreateStatusWindowA+0x3846
Library=C:\WINDOWS\System32\COMCTL32.dll

Current Java Thread:
at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:139 1) ...

I have seen this problem in both eclipse 3.0 and 3.1M4

Steve Northover wrote:

> Are you using a Mac? Try getting rid of the references to AWT.

> "Lance" <lancelim1@yahoo.com> wrote in message
> news:cr5u50$lnb$1@www.eclipse.org...
>> Hi,
>>
>> I have a problem with the dialog opening when the main menu drop down is
>> focused. For example, If I drop down any of the menu on the main menu, and
>> a dialog happens to pop up, the dialog although is focus, the mouse events
>> seem to be stuck the menu. This case eclipse to behave funny, none of the
>> mouse and key events can be delivered to both eclipse and dialog until the
>> dialog is closed and cannot gain focus on both eclipse and dialog.
>>
>> I have no idea what is wrong. I am currently using eclipse 3.0
>>
>> The dialog code is attached as below:
>> package test.views;
>>
>> import java.awt.Dimension;
>> import java.awt.Toolkit;
>>
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.widgets.Button;
>> import org.eclipse.swt.widgets.Composite;
>> import org.eclipse.swt.widgets.Display;
>> import org.eclipse.swt.widgets.Shell;
>> import org.eclipse.swt.widgets.Text;
>>
>> import org.eclipse.swt.events.ControlEvent;
>> import org.eclipse.swt.events.ControlListener;
>> import org.eclipse.swt.events.DisposeEvent;
>> import org.eclipse.swt.events.DisposeListener;
>> import org.eclipse.swt.events.FocusEvent;
>> import org.eclipse.swt.events.FocusListener;
>> import org.eclipse.swt.events.KeyAdapter;
>> import org.eclipse.swt.events.KeyEvent;
>> import org.eclipse.swt.events.SelectionAdapter;
>> import org.eclipse.swt.events.SelectionEvent;
>> import org.eclipse.swt.graphics.Color;
>> import org.eclipse.swt.graphics.Font;
>> import org.eclipse.swt.graphics.Point;
>> import org.eclipse.swt.graphics.Rectangle;
>> import org.eclipse.swt.layout.GridData;
>> import org.eclipse.swt.layout.GridLayout;
>> import org.eclipse.swt.layout.RowLayout;
>>
>> public class ChatDialog {
>>
>> private Shell shell = null;
>> private Display display;
>> private static final int HEIGHT = 300;
>> private static final int WIDTH = 400;
>>
>> Composite chatComposite = null;
>>
>> Text convArea = null;
>> Text inputArea = null;
>>
>> private GridData caData = null;
>>
>> Button sendButton;
>>
>> Color backgroundColor = null;
>> Font bigFont = null;
>>
>> public ChatDialog(Shell parentShell)
>> {
>> this.display = parentShell.getDisplay();
>>
>> shell = new Shell(display, SWT.CLOSE| SWT.MIN | SWT.MAX | SWT.RESIZE);
>> shell.addFocusListener(new FocusListener()
>> {
>> public void focusGained(FocusEvent arg0) {
>> if (inputArea!=null)
>> inputArea.setFocus();
>> }
>> public void focusLost(FocusEvent arg0) {}
>>
>> }
>> );
>>
>> shell.setLayout(new RowLayout());
>> shell.setText("Test");
>> shell.setSize(WIDTH, HEIGHT);
>> Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
>> createPartControl(shell);
>> }
>>
>> public void setFocus()
>> {
>> shell.setEnabled(true);
>> }
>> public void open()
>> {
>> if(shell != null)
>> {
>> shell.pack();
>> shell.open();
>>
>> while (!shell.isDisposed())
>> {
>> if (!display.isDisposed())
>> if (!display.readAndDispatch())
>> {
>> display.sleep();
>> }
>> }
>> }
>> }
>>
>> public void createPartControl(Composite parent)
>> {
>> backgroundColor = new Color(null, 255, 255, 255);
>>
>> chatComposite = new Composite(parent, 0);
>> GridLayout rl = new GridLayout();
>> rl.makeColumnsEqualWidth = true;
>> rl.numColumns = 10;
>> rl.marginHeight = 0;
>> rl.marginWidth = 0;
>> rl.horizontalSpacing = 0;
>> rl.verticalSpacing = 0;
>> chatComposite.setLayout(rl);
>>
>> GridData data;
>> if (convArea == null)
>> {
>> convArea = new Text(chatComposite, SWT.MULTI | SWT.WRAP |
>> SWT.V_SCROLL | SWT.READ_ONLY);
>> caData = new GridData ();
>> caData.horizontalAlignment = GridData.FILL;
>> caData.verticalAlignment = GridData.FILL;
>> caData.heightHint = HEIGHT - 65;
>> caData.widthHint = WIDTH - 30;
>> caData.horizontalSpan = 10;
>>
>> caData.grabExcessHorizontalSpace = true;
>> caData.grabExcessVerticalSpace = true;
>> convArea.setLayoutData (caData);
>> convArea.setBackground(backgroundColor);
>> convArea.setText(strWelcomeMessage);
>> convArea.addFocusListener(new FocusListener()
>> {
>> public void focusGained(FocusEvent arg0) {
>> if (inputArea!=null)
>> inputArea.setFocus();
>> }
>>
>> public void focusLost(FocusEvent arg0) {}
>>
>> }
>> );
>> }
>>
>> if (inputArea == null) {
>> inputArea = new Text(chatComposite, SWT.MULTI | SWT.V_SCROLL |
>> SWT.BORDER);
>> data = new GridData ();
>> data.horizontalAlignment = GridData.FILL;
>> data.verticalAlignment = GridData.FILL;
>> data.horizontalSpan = 8;
>> data.grabExcessHorizontalSpace = true;
>> inputArea.setLayoutData(data);
>> inputArea.addKeyListener(new KeyAdapter() {
>> public void keyReleased(KeyEvent e) {
>> if (e.keyCode == SWT.CR) {
>> sendButtonClick();
>> }
>> }
>> });
>> }
>>
>> convArea.setBackground(backgroundColor);
>>
>> if (sendButton == null) {
>> sendButton = new Button(chatComposite, SWT.PUSH | SWT.FLAT);
>> sendButton.setText(strSendMessage);
>> data = new GridData ();
>>
>> data.horizontalAlignment = GridData.FILL;
>> data.verticalAlignment = GridData.FILL;
>> data.horizontalSpan = 2;
>> sendButton.setLayoutData(data);
>>
>> sendButton.addSelectionListener(new SelectionAdapter() {
>> public void widgetSelected(SelectionEvent event) {
>> sendButtonClick();
>> }
>> });
>> }
>>
>> shell.addControlListener(new ControlListener()
>> {
>> public void controlMoved(ControlEvent e) {}
>>
>> public void controlResized(ControlEvent e)
>> {
>> Rectangle rect = shell.getClientArea();
>> caData.heightHint = rect.height - 35;
>> caData.widthHint = rect.width - 30;
>> convArea.setLayoutData(caData);
>> chatComposite.layout(true);
>> }
>> }
>> );
>> }
>>
>> private void sendMessage(String mesg)
>> {
>> if (mesg == null)
>> return;
>>
>> if (mesg.length() == 0)
>> {
>>
>> convArea.append(); //$NON-NLS-1$ //$NON-NLS-2$
>> return;
>> }
>> convArea.append(mesg);
>>
>> }
>>
>> void sendButtonClick()
>> {
>> sendMessage(inputArea.getText().trim());
>> inputArea.setText("");
>> inputArea.setFocus();
>> }
>>
>> public void dispose()
>> {
>> shell.dispose();
>> }
>>
>> }
>>
Re: Menu and Dialog Events problem [message #448189 is a reply to message #448182] Wed, 05 January 2005 14:51 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
You will need to post a smaller example that shows the problem. Your other
code WORKSFORME (after I hacked to fix the compile errors).

"lance" <lancelim1@yahoo.com> wrote in message
news:crfkcs$ur2$1@www.eclipse.org...
> No i am not. Using pure swt. After further meddling, the problem seem to
> be that it is caught in
> while (!shell.isDisposed())
> {
> if (!display.isDisposed())
> if (!display.readAndDispatch())
> {
> display.sleep();
> }
> }.
>
> It will loop till the shell is been disposed. This dialog is supposed to
> pop up based on a timer event. So there is no way to tell when it will
> come up. If I happen to be on the menu bar or if there happen to be
> another dialog in front, the above loop will never exit. This somehow
> cause the mouse event to be dangling between the main display and the
> dialog.
>
> Removing the loop seem to solve part of the problem, although I got no
> idea why.
>
> The more serious problem I am facing now is if the dialog happens together
> with a browser dialog, such as one asking for password or javascript
> error. This will cause the dialog not to be redraw and the dialog will
> start taking up cpu resourceds. If I change the dialog to modal, it will
> cause an unexpected exception in native code outside event.
>
> The error is
> An unexpected exception has been deced in native code outside the VM.
> Unexpected Signal : EXECPTION_ACCESS_VIOLATION (0xc00000005) occurred at
> PC=0x7736E95C
> Function = CreateStatusWindowA+0x3846
> Library=C:\WINDOWS\System32\COMCTL32.dll
>
> Current Java Thread:
> at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
> at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:139 1) ...
>
> I have seen this problem in both eclipse 3.0 and 3.1M4
>
> Steve Northover wrote:
>
> > Are you using a Mac? Try getting rid of the references to AWT.
>
> > "Lance" <lancelim1@yahoo.com> wrote in message
> > news:cr5u50$lnb$1@www.eclipse.org...
> >> Hi,
> >>
> >> I have a problem with the dialog opening when the main menu drop down
is
> >> focused. For example, If I drop down any of the menu on the main menu,
and
> >> a dialog happens to pop up, the dialog although is focus, the mouse
events
> >> seem to be stuck the menu. This case eclipse to behave funny, none of
the
> >> mouse and key events can be delivered to both eclipse and dialog until
the
> >> dialog is closed and cannot gain focus on both eclipse and dialog.
> >>
> >> I have no idea what is wrong. I am currently using eclipse 3.0
> >>
> >> The dialog code is attached as below:
> >> package test.views;
> >>
> >> import java.awt.Dimension;
> >> import java.awt.Toolkit;
> >>
> >> import org.eclipse.swt.SWT;
> >> import org.eclipse.swt.widgets.Button;
> >> import org.eclipse.swt.widgets.Composite;
> >> import org.eclipse.swt.widgets.Display;
> >> import org.eclipse.swt.widgets.Shell;
> >> import org.eclipse.swt.widgets.Text;
> >>
> >> import org.eclipse.swt.events.ControlEvent;
> >> import org.eclipse.swt.events.ControlListener;
> >> import org.eclipse.swt.events.DisposeEvent;
> >> import org.eclipse.swt.events.DisposeListener;
> >> import org.eclipse.swt.events.FocusEvent;
> >> import org.eclipse.swt.events.FocusListener;
> >> import org.eclipse.swt.events.KeyAdapter;
> >> import org.eclipse.swt.events.KeyEvent;
> >> import org.eclipse.swt.events.SelectionAdapter;
> >> import org.eclipse.swt.events.SelectionEvent;
> >> import org.eclipse.swt.graphics.Color;
> >> import org.eclipse.swt.graphics.Font;
> >> import org.eclipse.swt.graphics.Point;
> >> import org.eclipse.swt.graphics.Rectangle;
> >> import org.eclipse.swt.layout.GridData;
> >> import org.eclipse.swt.layout.GridLayout;
> >> import org.eclipse.swt.layout.RowLayout;
> >>
> >> public class ChatDialog {
> >>
> >> private Shell shell = null;
> >> private Display display;
> >> private static final int HEIGHT = 300;
> >> private static final int WIDTH = 400;
> >>
> >> Composite chatComposite = null;
> >>
> >> Text convArea = null;
> >> Text inputArea = null;
> >>
> >> private GridData caData = null;
> >>
> >> Button sendButton;
> >>
> >> Color backgroundColor = null;
> >> Font bigFont = null;
> >>
> >> public ChatDialog(Shell parentShell)
> >> {
> >> this.display = parentShell.getDisplay();
> >>
> >> shell = new Shell(display, SWT.CLOSE| SWT.MIN | SWT.MAX |
SWT.RESIZE);
> >> shell.addFocusListener(new FocusListener()
> >> {
> >> public void focusGained(FocusEvent arg0) {
> >> if (inputArea!=null)
> >> inputArea.setFocus();
> >> }
> >> public void focusLost(FocusEvent arg0) {}
> >>
> >> }
> >> );
> >>
> >> shell.setLayout(new RowLayout());
> >> shell.setText("Test");
> >> shell.setSize(WIDTH, HEIGHT);
> >> Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
> >> createPartControl(shell);
> >> }
> >>
> >> public void setFocus()
> >> {
> >> shell.setEnabled(true);
> >> }
> >> public void open()
> >> {
> >> if(shell != null)
> >> {
> >> shell.pack();
> >> shell.open();
> >>
> >> while (!shell.isDisposed())
> >> {
> >> if (!display.isDisposed())
> >> if (!display.readAndDispatch())
> >> {
> >> display.sleep();
> >> }
> >> }
> >> }
> >> }
> >>
> >> public void createPartControl(Composite parent)
> >> {
> >> backgroundColor = new Color(null, 255, 255, 255);
> >>
> >> chatComposite = new Composite(parent, 0);
> >> GridLayout rl = new GridLayout();
> >> rl.makeColumnsEqualWidth = true;
> >> rl.numColumns = 10;
> >> rl.marginHeight = 0;
> >> rl.marginWidth = 0;
> >> rl.horizontalSpacing = 0;
> >> rl.verticalSpacing = 0;
> >> chatComposite.setLayout(rl);
> >>
> >> GridData data;
> >> if (convArea == null)
> >> {
> >> convArea = new Text(chatComposite, SWT.MULTI | SWT.WRAP |
> >> SWT.V_SCROLL | SWT.READ_ONLY);
> >> caData = new GridData ();
> >> caData.horizontalAlignment = GridData.FILL;
> >> caData.verticalAlignment = GridData.FILL;
> >> caData.heightHint = HEIGHT - 65;
> >> caData.widthHint = WIDTH - 30;
> >> caData.horizontalSpan = 10;
> >>
> >> caData.grabExcessHorizontalSpace = true;
> >> caData.grabExcessVerticalSpace = true;
> >> convArea.setLayoutData (caData);
> >> convArea.setBackground(backgroundColor);
> >> convArea.setText(strWelcomeMessage);
> >> convArea.addFocusListener(new FocusListener()
> >> {
> >> public void focusGained(FocusEvent arg0) {
> >> if (inputArea!=null)
> >> inputArea.setFocus();
> >> }
> >>
> >> public void focusLost(FocusEvent arg0) {}
> >>
> >> }
> >> );
> >> }
> >>
> >> if (inputArea == null) {
> >> inputArea = new Text(chatComposite, SWT.MULTI | SWT.V_SCROLL |
> >> SWT.BORDER);
> >> data = new GridData ();
> >> data.horizontalAlignment = GridData.FILL;
> >> data.verticalAlignment = GridData.FILL;
> >> data.horizontalSpan = 8;
> >> data.grabExcessHorizontalSpace = true;
> >> inputArea.setLayoutData(data);
> >> inputArea.addKeyListener(new KeyAdapter() {
> >> public void keyReleased(KeyEvent e) {
> >> if (e.keyCode == SWT.CR) {
> >> sendButtonClick();
> >> }
> >> }
> >> });
> >> }
> >>
> >> convArea.setBackground(backgroundColor);
> >>
> >> if (sendButton == null) {
> >> sendButton = new Button(chatComposite, SWT.PUSH | SWT.FLAT);
> >> sendButton.setText(strSendMessage);
> >> data = new GridData ();
> >>
> >> data.horizontalAlignment = GridData.FILL;
> >> data.verticalAlignment = GridData.FILL;
> >> data.horizontalSpan = 2;
> >> sendButton.setLayoutData(data);
> >>
> >> sendButton.addSelectionListener(new SelectionAdapter() {
> >> public void widgetSelected(SelectionEvent event) {
> >> sendButtonClick();
> >> }
> >> });
> >> }
> >>
> >> shell.addControlListener(new ControlListener()
> >> {
> >> public void controlMoved(ControlEvent e) {}
> >>
> >> public void controlResized(ControlEvent e)
> >> {
> >> Rectangle rect = shell.getClientArea();
> >> caData.heightHint = rect.height - 35;
> >> caData.widthHint = rect.width - 30;
> >> convArea.setLayoutData(caData);
> >> chatComposite.layout(true);
> >> }
> >> }
> >> );
> >> }
> >>
> >> private void sendMessage(String mesg)
> >> {
> >> if (mesg == null)
> >> return;
> >>
> >> if (mesg.length() == 0)
> >> {
> >>
> >> convArea.append(); //$NON-NLS-1$ //$NON-NLS-2$
> >> return;
> >> }
> >> convArea.append(mesg);
> >>
> >> }
> >>
> >> void sendButtonClick()
> >> {
> >> sendMessage(inputArea.getText().trim());
> >> inputArea.setText("");
> >> inputArea.setFocus();
> >> }
> >>
> >> public void dispose()
> >> {
> >> shell.dispose();
> >> }
> >>
> >> }
> >>
>
>
Re: Menu and Dialog Events problem - display.readAndDispatch [message #448251 is a reply to message #448189] Thu, 06 January 2005 01:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lancelim1.yahoo.com

:)

the code will work. but if i ask a timer event to start calling the
dialog, and I happen to be pulling down the menu bar, basically the ui
will go crazy. If I remove the shell.isDisposed loop, the behaviour will
not occur but the catch is if u happen to have a broswer view and it start
prompting for username and password, the dialog will be blank and I also
noticed that the dialog starts hogging the cpu processes. If the dialog
happens to be modal, high chances is that eclipse will crash.

I noticed that there is a discussion on readAndDispatch some time ago. I
can guess that the person is having a similar problem as what I have. The
discussion lead to a dead end. Someone mention that the shell already had
its own readAndDispatch loop and the dialog should not need to handle it.
If that is the case, why it starts hogging the cpu processes ?

Steve Northover wrote:

> You will need to post a smaller example that shows the problem. Your other
> code WORKSFORME (after I hacked to fix the compile errors).

> "lance" <lancelim1@yahoo.com> wrote in message
> news:crfkcs$ur2$1@www.eclipse.org...
>> No i am not. Using pure swt. After further meddling, the problem seem to
>> be that it is caught in
>> while (!shell.isDisposed())
>> {
>> if (!display.isDisposed())
>> if (!display.readAndDispatch())
>> {
>> display.sleep();
>> }
>> }.
>>
>> It will loop till the shell is been disposed. This dialog is supposed to
>> pop up based on a timer event. So there is no way to tell when it will
>> come up. If I happen to be on the menu bar or if there happen to be
>> another dialog in front, the above loop will never exit. This somehow
>> cause the mouse event to be dangling between the main display and the
>> dialog.
>>
>> Removing the loop seem to solve part of the problem, although I got no
>> idea why.
>>
>> The more serious problem I am facing now is if the dialog happens together
>> with a browser dialog, such as one asking for password or javascript
>> error. This will cause the dialog not to be redraw and the dialog will
>> start taking up cpu resourceds. If I change the dialog to modal, it will
>> cause an unexpected exception in native code outside event.
>>
>> The error is
>> An unexpected exception has been deced in native code outside the VM.
>> Unexpected Signal : EXECPTION_ACCESS_VIOLATION (0xc00000005) occurred at
>> PC=0x7736E95C
>> Function = CreateStatusWindowA+0x3846
>> Library=C:WINDOWSSystem32COMCTL32.dll
>>
>> Current Java Thread:
>> at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
>> at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:139 1) ...
>>
>> I have seen this problem in both eclipse 3.0 and 3.1M4
>>
>> Steve Northover wrote:
>>
>> > Are you using a Mac? Try getting rid of the references to AWT.
>>
>> > "Lance" <lancelim1@yahoo.com> wrote in message
>> > news:cr5u50$lnb$1@www.eclipse.org...
>> >> Hi,
>> >>
>> >> I have a problem with the dialog opening when the main menu drop down
> is
>> >> focused. For example, If I drop down any of the menu on the main menu,
> and
>> >> a dialog happens to pop up, the dialog although is focus, the mouse
> events
>> >> seem to be stuck the menu. This case eclipse to behave funny, none of
> the
>> >> mouse and key events can be delivered to both eclipse and dialog until
> the
>> >> dialog is closed and cannot gain focus on both eclipse and dialog.
>> >>
>> >> I have no idea what is wrong. I am currently using eclipse 3.0
>> >>
>> >> The dialog code is attached as below:
>> >> package test.views;
>> >>
>> >> import java.awt.Dimension;
>> >> import java.awt.Toolkit;
>> >>
>> >> import org.eclipse.swt.SWT;
>> >> import org.eclipse.swt.widgets.Button;
>> >> import org.eclipse.swt.widgets.Composite;
>> >> import org.eclipse.swt.widgets.Display;
>> >> import org.eclipse.swt.widgets.Shell;
>> >> import org.eclipse.swt.widgets.Text;
>> >>
>> >> import org.eclipse.swt.events.ControlEvent;
>> >> import org.eclipse.swt.events.ControlListener;
>> >> import org.eclipse.swt.events.DisposeEvent;
>> >> import org.eclipse.swt.events.DisposeListener;
>> >> import org.eclipse.swt.events.FocusEvent;
>> >> import org.eclipse.swt.events.FocusListener;
>> >> import org.eclipse.swt.events.KeyAdapter;
>> >> import org.eclipse.swt.events.KeyEvent;
>> >> import org.eclipse.swt.events.SelectionAdapter;
>> >> import org.eclipse.swt.events.SelectionEvent;
>> >> import org.eclipse.swt.graphics.Color;
>> >> import org.eclipse.swt.graphics.Font;
>> >> import org.eclipse.swt.graphics.Point;
>> >> import org.eclipse.swt.graphics.Rectangle;
>> >> import org.eclipse.swt.layout.GridData;
>> >> import org.eclipse.swt.layout.GridLayout;
>> >> import org.eclipse.swt.layout.RowLayout;
>> >>
>> >> public class ChatDialog {
>> >>
>> >> private Shell shell = null;
>> >> private Display display;
>> >> private static final int HEIGHT = 300;
>> >> private static final int WIDTH = 400;
>> >>
>> >> Composite chatComposite = null;
>> >>
>> >> Text convArea = null;
>> >> Text inputArea = null;
>> >>
>> >> private GridData caData = null;
>> >>
>> >> Button sendButton;
>> >>
>> >> Color backgroundColor = null;
>> >> Font bigFont = null;
>> >>
>> >> public ChatDialog(Shell parentShell)
>> >> {
>> >> this.display = parentShell.getDisplay();
>> >>
>> >> shell = new Shell(display, SWT.CLOSE| SWT.MIN | SWT.MAX |
> SWT.RESIZE);
>> >> shell.addFocusListener(new FocusListener()
>> >> {
>> >> public void focusGained(FocusEvent arg0) {
>> >> if (inputArea!=null)
>> >> inputArea.setFocus();
>> >> }
>> >> public void focusLost(FocusEvent arg0) {}
>> >>
>> >> }
>> >> );
>> >>
>> >> shell.setLayout(new RowLayout());
>> >> shell.setText("Test");
>> >> shell.setSize(WIDTH, HEIGHT);
>> >> Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
>> >> createPartControl(shell);
>> >> }
>> >>
>> >> public void setFocus()
>> >> {
>> >> shell.setEnabled(true);
>> >> }
>> >> public void open()
>> >> {
>> >> if(shell != null)
>> >> {
>> >> shell.pack();
>> >> shell.open();
>> >>
>> >> while (!shell.isDisposed())
>> >> {
>> >> if (!display.isDisposed())
>> >> if (!display.readAndDispatch())
>> >> {
>> >> display.sleep();
>> >> }
>> >> }
>> >> }
>> >> }
>> >>
>> >> public void createPartControl(Composite parent)
>> >> {
>> >> backgroundColor = new Color(null, 255, 255, 255);
>> >>
>> >> chatComposite = new Composite(parent, 0);
>> >> GridLayout rl = new GridLayout();
>> >> rl.makeColumnsEqualWidth = true;
>> >> rl.numColumns = 10;
>> >> rl.marginHeight = 0;
>> >> rl.marginWidth = 0;
>> >> rl.horizontalSpacing = 0;
>> >> rl.verticalSpacing = 0;
>> >> chatComposite.setLayout(rl);
>> >>
>> >> GridData data;
>> >> if (convArea == null)
>> >> {
>> >> convArea = new Text(chatComposite, SWT.MULTI | SWT.WRAP |
>> >> SWT.V_SCROLL | SWT.READ_ONLY);
>> >> caData = new GridData ();
>> >> caData.horizontalAlignment = GridData.FILL;
>> >> caData.verticalAlignment = GridData.FILL;
>> >> caData.heightHint = HEIGHT - 65;
>> >> caData.widthHint = WIDTH - 30;
>> >> caData.horizontalSpan = 10;
>> >>
>> >> caData.grabExcessHorizontalSpace = true;
>> >> caData.grabExcessVerticalSpace = true;
>> >> convArea.setLayoutData (caData);
>> >> convArea.setBackground(backgroundColor);
>> >> convArea.setText(strWelcomeMessage);
>> >> convArea.addFocusListener(new FocusListener()
>> >> {
>> >> public void focusGained(FocusEvent arg0) {
>> >> if (inputArea!=null)
>> >> inputArea.setFocus();
>> >> }
>> >>
>> >> public void focusLost(FocusEvent arg0) {}
>> >>
>> >> }
>> >> );
>> >> }
>> >>
>> >> if (inputArea == null) {
>> >> inputArea = new Text(chatComposite, SWT.MULTI | SWT.V_SCROLL |
>> >> SWT.BORDER);
>> >> data = new GridData ();
>> >> data.horizontalAlignment = GridData.FILL;
>> >> data.verticalAlignment = GridData.FILL;
>> >> data.horizontalSpan = 8;
>> >> data.grabExcessHorizontalSpace = true;
>> >> inputArea.setLayoutData(data);
>> >> inputArea.addKeyListener(new KeyAdapter() {
>> >> public void keyReleased(KeyEvent e) {
>> >> if (e.keyCode == SWT.CR) {
>> >> sendButtonClick();
>> >> }
>> >> }
>> >> });
>> >> }
>> >>
>> >> convArea.setBackground(backgroundColor);
>> >>
>> >> if (sendButton == null) {
>> >> sendButton = new Button(chatComposite, SWT.PUSH | SWT.FLAT);
>> >> sendButton.setText(strSendMessage);
>> >> data = new GridData ();
>> >>
>> >> data.horizontalAlignment = GridData.FILL;
>> >> data.verticalAlignment = GridData.FILL;
>> >> data.horizontalSpan = 2;
>> >> sendButton.setLayoutData(data);
>> >>
>> >> sendButton.addSelectionListener(new SelectionAdapter() {
>> >> public void widgetSelected(SelectionEvent event) {
>> >> sendButtonClick();
>> >> }
>> >> });
>> >> }
>> >>
>> >> shell.addControlListener(new ControlListener()
>> >> {
>> >> public void controlMoved(ControlEvent e) {}
>> >>
>> >> public void controlResized(ControlEvent e)
>> >> {
>> >> Rectangle rect = shell.getClientArea();
>> >> caData.heightHint = rect.height - 35;
>> >> caData.widthHint = rect.width - 30;
>> >> convArea.setLayoutData(caData);
>> >> chatComposite.layout(true);
>> >> }
>> >> }
>> >> );
>> >> }
>> >>
>> >> private void sendMessage(String mesg)
>> >> {
>> >> if (mesg == null)
>> >> return;
>> >>
>> >> if (mesg.length() == 0)
>> >> {
>> >>
>> >> convArea.append(); //$NON-NLS-1$ //$NON-NLS-2$
>> >> return;
>> >> }
>> >> convArea.append(mesg);
>> >>
>> >> }
>> >>
>> >> void sendButtonClick()
>> >> {
>> >> sendMessage(inputArea.getText().trim());
>> >> inputArea.setText("");
>> >> inputArea.setFocus();
>> >> }
>> >>
>> >> public void dispose()
>> >> {
>> >> shell.dispose();
>> >> }
>> >>
>> >> }
>> >>
>>
>>
Re: Menu and Dialog Events problem - display.readAndDispatch [message #448258 is a reply to message #448251] Thu, 06 January 2005 15:13 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
We can't do anything without code. Please hack up a simple example with a
timer or whatever that causes the ui to go crazy.

"lance" <lancelim1@yahoo.com> wrote in message
news:cri3nd$vgi$1@www.eclipse.org...
> :)
>
> the code will work. but if i ask a timer event to start calling the
> dialog, and I happen to be pulling down the menu bar, basically the ui
> will go crazy. If I remove the shell.isDisposed loop, the behaviour will
> not occur but the catch is if u happen to have a broswer view and it start
> prompting for username and password, the dialog will be blank and I also
> noticed that the dialog starts hogging the cpu processes. If the dialog
> happens to be modal, high chances is that eclipse will crash.
>
> I noticed that there is a discussion on readAndDispatch some time ago. I
> can guess that the person is having a similar problem as what I have. The
> discussion lead to a dead end. Someone mention that the shell already had
> its own readAndDispatch loop and the dialog should not need to handle it.
> If that is the case, why it starts hogging the cpu processes ?
>
> Steve Northover wrote:
>
> > You will need to post a smaller example that shows the problem. Your
other
> > code WORKSFORME (after I hacked to fix the compile errors).
>
> > "lance" <lancelim1@yahoo.com> wrote in message
> > news:crfkcs$ur2$1@www.eclipse.org...
> >> No i am not. Using pure swt. After further meddling, the problem seem
to
> >> be that it is caught in
> >> while (!shell.isDisposed())
> >> {
> >> if (!display.isDisposed())
> >> if (!display.readAndDispatch())
> >> {
> >> display.sleep();
> >> }
> >> }.
> >>
> >> It will loop till the shell is been disposed. This dialog is supposed
to
> >> pop up based on a timer event. So there is no way to tell when it will
> >> come up. If I happen to be on the menu bar or if there happen to be
> >> another dialog in front, the above loop will never exit. This somehow
> >> cause the mouse event to be dangling between the main display and the
> >> dialog.
> >>
> >> Removing the loop seem to solve part of the problem, although I got no
> >> idea why.
> >>
> >> The more serious problem I am facing now is if the dialog happens
together
> >> with a browser dialog, such as one asking for password or javascript
> >> error. This will cause the dialog not to be redraw and the dialog will
> >> start taking up cpu resourceds. If I change the dialog to modal, it
will
> >> cause an unexpected exception in native code outside event.
> >>
> >> The error is
> >> An unexpected exception has been deced in native code outside the VM.
> >> Unexpected Signal : EXECPTION_ACCESS_VIOLATION (0xc00000005) occurred
at
> >> PC=0x7736E95C
> >> Function = CreateStatusWindowA+0x3846
> >> Library=C:WINDOWSSystem32COMCTL32.dll
> >>
> >> Current Java Thread:
> >> at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
> >> at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:139 1)
....
> >>
> >> I have seen this problem in both eclipse 3.0 and 3.1M4
> >>
> >> Steve Northover wrote:
> >>
> >> > Are you using a Mac? Try getting rid of the references to AWT.
> >>
> >> > "Lance" <lancelim1@yahoo.com> wrote in message
> >> > news:cr5u50$lnb$1@www.eclipse.org...
> >> >> Hi,
> >> >>
> >> >> I have a problem with the dialog opening when the main menu drop
down
> > is
> >> >> focused. For example, If I drop down any of the menu on the main
menu,
> > and
> >> >> a dialog happens to pop up, the dialog although is focus, the mouse
> > events
> >> >> seem to be stuck the menu. This case eclipse to behave funny, none
of
> > the
> >> >> mouse and key events can be delivered to both eclipse and dialog
until
> > the
> >> >> dialog is closed and cannot gain focus on both eclipse and dialog.
> >> >>
> >> >> I have no idea what is wrong. I am currently using eclipse 3.0
> >> >>
> >> >> The dialog code is attached as below:
> >> >> package test.views;
> >> >>
> >> >> import java.awt.Dimension;
> >> >> import java.awt.Toolkit;
> >> >>
> >> >> import org.eclipse.swt.SWT;
> >> >> import org.eclipse.swt.widgets.Button;
> >> >> import org.eclipse.swt.widgets.Composite;
> >> >> import org.eclipse.swt.widgets.Display;
> >> >> import org.eclipse.swt.widgets.Shell;
> >> >> import org.eclipse.swt.widgets.Text;
> >> >>
> >> >> import org.eclipse.swt.events.ControlEvent;
> >> >> import org.eclipse.swt.events.ControlListener;
> >> >> import org.eclipse.swt.events.DisposeEvent;
> >> >> import org.eclipse.swt.events.DisposeListener;
> >> >> import org.eclipse.swt.events.FocusEvent;
> >> >> import org.eclipse.swt.events.FocusListener;
> >> >> import org.eclipse.swt.events.KeyAdapter;
> >> >> import org.eclipse.swt.events.KeyEvent;
> >> >> import org.eclipse.swt.events.SelectionAdapter;
> >> >> import org.eclipse.swt.events.SelectionEvent;
> >> >> import org.eclipse.swt.graphics.Color;
> >> >> import org.eclipse.swt.graphics.Font;
> >> >> import org.eclipse.swt.graphics.Point;
> >> >> import org.eclipse.swt.graphics.Rectangle;
> >> >> import org.eclipse.swt.layout.GridData;
> >> >> import org.eclipse.swt.layout.GridLayout;
> >> >> import org.eclipse.swt.layout.RowLayout;
> >> >>
> >> >> public class ChatDialog {
> >> >>
> >> >> private Shell shell = null;
> >> >> private Display display;
> >> >> private static final int HEIGHT = 300;
> >> >> private static final int WIDTH = 400;
> >> >>
> >> >> Composite chatComposite = null;
> >> >>
> >> >> Text convArea = null;
> >> >> Text inputArea = null;
> >> >>
> >> >> private GridData caData = null;
> >> >>
> >> >> Button sendButton;
> >> >>
> >> >> Color backgroundColor = null;
> >> >> Font bigFont = null;
> >> >>
> >> >> public ChatDialog(Shell parentShell)
> >> >> {
> >> >> this.display = parentShell.getDisplay();
> >> >>
> >> >> shell = new Shell(display, SWT.CLOSE| SWT.MIN | SWT.MAX |
> > SWT.RESIZE);
> >> >> shell.addFocusListener(new FocusListener()
> >> >> {
> >> >> public void focusGained(FocusEvent arg0) {
> >> >> if (inputArea!=null)
> >> >> inputArea.setFocus();
> >> >> }
> >> >> public void focusLost(FocusEvent arg0) {}
> >> >>
> >> >> }
> >> >> );
> >> >>
> >> >> shell.setLayout(new RowLayout());
> >> >> shell.setText("Test");
> >> >> shell.setSize(WIDTH, HEIGHT);
> >> >> Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
> >> >> createPartControl(shell);
> >> >> }
> >> >>
> >> >> public void setFocus()
> >> >> {
> >> >> shell.setEnabled(true);
> >> >> }
> >> >> public void open()
> >> >> {
> >> >> if(shell != null)
> >> >> {
> >> >> shell.pack();
> >> >> shell.open();
> >> >>
> >> >> while (!shell.isDisposed())
> >> >> {
> >> >> if (!display.isDisposed())
> >> >> if (!display.readAndDispatch())
> >> >> {
> >> >> display.sleep();
> >> >> }
> >> >> }
> >> >> }
> >> >> }
> >> >>
> >> >> public void createPartControl(Composite parent)
> >> >> {
> >> >> backgroundColor = new Color(null, 255, 255, 255);
> >> >>
> >> >> chatComposite = new Composite(parent, 0);
> >> >> GridLayout rl = new GridLayout();
> >> >> rl.makeColumnsEqualWidth = true;
> >> >> rl.numColumns = 10;
> >> >> rl.marginHeight = 0;
> >> >> rl.marginWidth = 0;
> >> >> rl.horizontalSpacing = 0;
> >> >> rl.verticalSpacing = 0;
> >> >> chatComposite.setLayout(rl);
> >> >>
> >> >> GridData data;
> >> >> if (convArea == null)
> >> >> {
> >> >> convArea = new Text(chatComposite, SWT.MULTI | SWT.WRAP |
> >> >> SWT.V_SCROLL | SWT.READ_ONLY);
> >> >> caData = new GridData ();
> >> >> caData.horizontalAlignment = GridData.FILL;
> >> >> caData.verticalAlignment = GridData.FILL;
> >> >> caData.heightHint = HEIGHT - 65;
> >> >> caData.widthHint = WIDTH - 30;
> >> >> caData.horizontalSpan = 10;
> >> >>
> >> >> caData.grabExcessHorizontalSpace = true;
> >> >> caData.grabExcessVerticalSpace = true;
> >> >> convArea.setLayoutData (caData);
> >> >> convArea.setBackground(backgroundColor);
> >> >> convArea.setText(strWelcomeMessage);
> >> >> convArea.addFocusListener(new FocusListener()
> >> >> {
> >> >> public void focusGained(FocusEvent arg0) {
> >> >> if (inputArea!=null)
> >> >> inputArea.setFocus();
> >> >> }
> >> >>
> >> >> public void focusLost(FocusEvent arg0) {}
> >> >>
> >> >> }
> >> >> );
> >> >> }
> >> >>
> >> >> if (inputArea == null) {
> >> >> inputArea = new Text(chatComposite, SWT.MULTI | SWT.V_SCROLL |
> >> >> SWT.BORDER);
> >> >> data = new GridData ();
> >> >> data.horizontalAlignment = GridData.FILL;
> >> >> data.verticalAlignment = GridData.FILL;
> >> >> data.horizontalSpan = 8;
> >> >> data.grabExcessHorizontalSpace = true;
> >> >> inputArea.setLayoutData(data);
> >> >> inputArea.addKeyListener(new KeyAdapter() {
> >> >> public void keyReleased(KeyEvent e) {
> >> >> if (e.keyCode == SWT.CR) {
> >> >> sendButtonClick();
> >> >> }
> >> >> }
> >> >> });
> >> >> }
> >> >>
> >> >> convArea.setBackground(backgroundColor);
> >> >>
> >> >> if (sendButton == null) {
> >> >> sendButton = new Button(chatComposite, SWT.PUSH | SWT.FLAT);
> >> >> sendButton.setText(strSendMessage);
> >> >> data = new GridData ();
> >> >>
> >> >> data.horizontalAlignment = GridData.FILL;
> >> >> data.verticalAlignment = GridData.FILL;
> >> >> data.horizontalSpan = 2;
> >> >> sendButton.setLayoutData(data);
> >> >>
> >> >> sendButton.addSelectionListener(new SelectionAdapter() {
> >> >> public void widgetSelected(SelectionEvent event) {
> >> >> sendButtonClick();
> >> >> }
> >> >> });
> >> >> }
> >> >>
> >> >> shell.addControlListener(new ControlListener()
> >> >> {
> >> >> public void controlMoved(ControlEvent e) {}
> >> >>
> >> >> public void controlResized(ControlEvent e)
> >> >> {
> >> >> Rectangle rect = shell.getClientArea();
> >> >> caData.heightHint = rect.height - 35;
> >> >> caData.widthHint = rect.width - 30;
> >> >> convArea.setLayoutData(caData);
> >> >> chatComposite.layout(true);
> >> >> }
> >> >> }
> >> >> );
> >> >> }
> >> >>
> >> >> private void sendMessage(String mesg)
> >> >> {
> >> >> if (mesg == null)
> >> >> return;
> >> >>
> >> >> if (mesg.length() == 0)
> >> >> {
> >> >>
> >> >> convArea.append(); //$NON-NLS-1$ //$NON-NLS-2$
> >> >> return;
> >> >> }
> >> >> convArea.append(mesg);
> >> >>
> >> >> }
> >> >>
> >> >> void sendButtonClick()
> >> >> {
> >> >> sendMessage(inputArea.getText().trim());
> >> >> inputArea.setText("");
> >> >> inputArea.setFocus();
> >> >> }
> >> >>
> >> >> public void dispose()
> >> >> {
> >> >> shell.dispose();
> >> >> }
> >> >>
> >> >> }
> >> >>
> >>
> >>
>
>
Previous Topic:Caret Position
Next Topic:how to cut a area in canvas to a Image
Goto Forum:
  


Current Time: Wed Oct 28 11:12:52 GMT 2020

Powered by FUDForum. Page generated in 0.02024 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top