]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - LightweightDialog.java
33a0d2781d7f968943bd9542e87ab25bc0020f16
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.eclipse
.ui
.dialogs
;
18 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.events
.FocusEvent
;
21 import org
.eclipse
.swt
.events
.FocusListener
;
22 import org
.eclipse
.swt
.events
.ShellAdapter
;
23 import org
.eclipse
.swt
.events
.ShellEvent
;
24 import org
.eclipse
.swt
.graphics
.Point
;
25 import org
.eclipse
.swt
.graphics
.Rectangle
;
26 import org
.eclipse
.swt
.layout
.GridData
;
27 import org
.eclipse
.swt
.layout
.GridLayout
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Control
;
30 import org
.eclipse
.swt
.widgets
.Display
;
31 import org
.eclipse
.swt
.widgets
.Shell
;
33 /** Generic lightweight dialog, not based on JFace. */
34 public class LightweightDialog
{
35 // private final static Log log = LogFactory.getLog(LightweightDialog.class);
37 private Shell parentShell
;
38 private Shell backgroundShell
;
41 /** Tries to find a display */
42 private static Display
getDisplay() {
44 Display display
= Display
.getCurrent();
48 return Display
.getDefault();
49 } catch (Exception e
) {
50 return Display
.getCurrent();
54 public LightweightDialog(Shell parentShell
) {
55 this.parentShell
= parentShell
;
60 throw new EclipseUiException("There is already a shell");
61 backgroundShell
= new Shell(parentShell
, SWT
.NO_TRIM
| SWT
.BORDER
| SWT
.ON_TOP
);
62 backgroundShell
.setMaximized(true);
63 backgroundShell
.setAlpha(128);
64 backgroundShell
.setBackground(getDisplay().getSystemColor(SWT
.COLOR_BLACK
));
65 backgroundShell
.open();
66 shell
= new Shell(backgroundShell
, SWT
.NO_TRIM
| SWT
.BORDER
| SWT
.ON_TOP
);
67 shell
.setLayout(new GridLayout());
68 // shell.setText("Error");
69 shell
.setSize(getInitialSize());
70 createDialogArea(shell
);
74 Rectangle shellBounds
= Display
.getCurrent().getBounds();// RAP
75 Point dialogSize
= shell
.getSize();
76 int x
= shellBounds
.x
+ (shellBounds
.width
- dialogSize
.x
) / 2;
77 int y
= shellBounds
.y
+ (shellBounds
.height
- dialogSize
.y
) / 2;
78 shell
.setLocation(x
, y
);
80 shell
.addShellListener(new ShellAdapter() {
81 private static final long serialVersionUID
= -2701270481953688763L;
84 public void shellDeactivated(ShellEvent e
) {
90 // after the foreground shell has been opened
91 backgroundShell
.addFocusListener(new FocusListener() {
92 private static final long serialVersionUID
= 3137408447474661070L;
95 public void focusLost(FocusEvent event
) {
99 public void focusGained(FocusEvent event
) {
105 protected void closeShell() {
112 if (backgroundShell
!= null) {
113 backgroundShell
.close();
114 backgroundShell
.dispose();
118 protected Point
getInitialSize() {
119 // if (exception != null)
120 // return new Point(800, 600);
122 return new Point(400, 400);
125 protected Control
createDialogArea(Composite parent
) {
126 Composite dialogarea
= new Composite(parent
, SWT
.NONE
);
127 dialogarea
.setLayout(new GridLayout());
128 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));