Skip to content

Commit f3ab357

Browse files
committed
DND controls examples
1 parent 7727b08 commit f3ab357

13 files changed

Lines changed: 594 additions & 1 deletion

File tree

com.vogella.eclipse.dndcontrols/com.vogella.eclipse.dndcontrols.product

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<plugin id="org.apache.batik.util.gui"/>
2727
<plugin id="org.apache.commons.jxpath"/>
2828
<plugin id="org.apache.commons.logging"/>
29+
<plugin id="org.apache.felix.gogo.command"/>
30+
<plugin id="org.apache.felix.gogo.runtime"/>
31+
<plugin id="org.apache.felix.scr"/>
2932
<plugin id="org.eclipse.core.commands"/>
3033
<plugin id="org.eclipse.core.contenttype"/>
3134
<plugin id="org.eclipse.core.databinding"/>
@@ -52,6 +55,7 @@
5255
<plugin id="org.eclipse.e4.core.di"/>
5356
<plugin id="org.eclipse.e4.core.di.annotations"/>
5457
<plugin id="org.eclipse.e4.core.di.extensions"/>
58+
<plugin id="org.eclipse.e4.core.di.extensions.supplier"/>
5559
<plugin id="org.eclipse.e4.core.services"/>
5660
<plugin id="org.eclipse.e4.emf.xpath"/>
5761
<plugin id="org.eclipse.e4.ui.bindings"/>
@@ -86,6 +90,7 @@
8690
<plugin id="org.eclipse.osgi"/>
8791
<plugin id="org.eclipse.osgi.compatibility.state" fragment="true"/>
8892
<plugin id="org.eclipse.osgi.services"/>
93+
<plugin id="org.eclipse.osgi.util"/>
8994
<plugin id="org.eclipse.swt"/>
9095
<plugin id="org.eclipse.swt.cocoa.macosx.x86_64" fragment="true"/>
9196
<plugin id="org.eclipse.swt.gtk.linux.ppc" fragment="true"/>

com.vogella.swt.widgets/META-INF/MANIFEST.MF

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ Bundle-SymbolicName: com.vogella.swt.widgets
55
Bundle-Version: 1.0.0.qualifier
66
Bundle-Vendor: VOGELLA
77
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8-
Require-Bundle: org.eclipse.swt;bundle-version="3.106.0"
8+
Require-Bundle: org.eclipse.swt;bundle-version="3.106.0",
9+
org.eclipse.core.runtime;bundle-version="3.13.0",
10+
org.eclipse.jface;bundle-version="3.13.0"
745 Bytes
Loading
1.16 KB
Loading
712 Bytes
Loading
956 Bytes
Loading
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package com.vogella.swt.widgets.customwidgets;
2+
3+
import org.eclipse.swt.SWT;
4+
import org.eclipse.swt.graphics.Color;
5+
import org.eclipse.swt.layout.FillLayout;
6+
import org.eclipse.swt.layout.FormAttachment;
7+
import org.eclipse.swt.layout.FormData;
8+
import org.eclipse.swt.layout.FormLayout;
9+
import org.eclipse.swt.widgets.Composite;
10+
11+
/**
12+
* Instances of this class represent a composite with two layers
13+
*
14+
* The layers can contain arbitrary layouts and widgets
15+
* <p>
16+
*
17+
* <ul>
18+
* <li>{@link #getContentComposite()} allows to retrieve the Composite for the
19+
* main content</li>
20+
* <li>{@link #getOverlayComposite()} Retrieve the Composite for the
21+
* overlay</li>
22+
* </ul>
23+
*
24+
* </p>
25+
* <dl>
26+
* <dt><b>Styles:</b></dt>
27+
* <dd>TOP, BOTTOM, LEFT, RIGHT</dd>
28+
* </dl>
29+
* <p>
30+
* Note: Only one of the styles TOP, BOTTOM, RIGHT, and CENTER may be specified.
31+
* </p>
32+
* <p>
33+
* </p>
34+
*
35+
* @noextend This class is not intended to be subclassed by clients.
36+
*/
37+
38+
public class LayeredComposite extends Composite {
39+
private Color backgroundColor;
40+
private Composite mainContentArea;
41+
private Composite overlayComposite;
42+
43+
public LayeredComposite(Composite parent, int style) {
44+
super(parent, style);
45+
// Uncommend to test if the clients are fill the full area
46+
// backgroundColor = new Color(null, 255, 0, 0);
47+
// setBackground(backgroundColor);
48+
// this.addDisposeListener(e -> {
49+
// backgroundColor.dispose();
50+
// });
51+
52+
FormLayout formLayout = new FormLayout();
53+
this.setLayout(formLayout);
54+
mainContentArea = new Composite(this, SWT.NONE);
55+
mainContentArea.setLayout(new FillLayout());
56+
mainContentArea.setLayoutData(fillCompleteArea());
57+
58+
overlayComposite = new Composite(this, SWT.NONE);
59+
overlayComposite.setLayout(new FillLayout());
60+
overlayComposite.moveAbove(null);
61+
FormData formDataUpperLayer = definePosition(style);
62+
overlayComposite.setLayoutData(formDataUpperLayer);
63+
64+
}
65+
66+
/**
67+
* Retrieve the main Composite. Content of this composite maybe overlayed by
68+
* the overlayComposite
69+
*
70+
* @return Composite the Composite that represents the main content
71+
*/
72+
public Composite getContentComposite() {
73+
return mainContentArea;
74+
}
75+
76+
/**
77+
* Retrieve the overlay Composite.
78+
*
79+
* @return Composite the Composite that represents the main content
80+
*/
81+
82+
public Composite getOverlayComposite() {
83+
return overlayComposite;
84+
}
85+
86+
private FormData definePosition(int style) {
87+
checkStyle(style);
88+
FormData formDataUpperLayer = new FormData();
89+
if (style == SWT.BOTTOM) {
90+
formDataUpperLayer.bottom = new FormAttachment(100, 0);
91+
formDataUpperLayer.left = new FormAttachment(0, 0);
92+
formDataUpperLayer.right = new FormAttachment(100, 0);
93+
} else if (style == SWT.TOP) {
94+
formDataUpperLayer.top = new FormAttachment(0, 0);
95+
formDataUpperLayer.left = new FormAttachment(0, 0);
96+
formDataUpperLayer.right = new FormAttachment(100, 0);
97+
} else if (style == SWT.RIGHT) {
98+
formDataUpperLayer.top = new FormAttachment(0, 0);
99+
formDataUpperLayer.right = new FormAttachment(100, 0);
100+
} else if (style == SWT.LEFT) {
101+
formDataUpperLayer.top = new FormAttachment(0, 0);
102+
formDataUpperLayer.left = new FormAttachment(0, 0);
103+
formDataUpperLayer.right = new FormAttachment(100, 0);
104+
}
105+
106+
return formDataUpperLayer;
107+
}
108+
109+
/**
110+
* Ensure that only valid styles are passed to the container
111+
*
112+
* @param style
113+
*/
114+
static void checkStyle(int style) {
115+
if ((style & (SWT.BOTTOM | SWT.TOP | SWT.RIGHT | SWT.LEFT)) == 0) {
116+
throw new IllegalArgumentException("Style must be one of SWT.BOTTOM, SWT.TOP, SWT.RIGHT, SWT.LEFT");
117+
}
118+
}
119+
120+
private FormData fillCompleteArea() {
121+
FormData formData = new FormData();
122+
formData.top = new FormAttachment(0, 0);
123+
formData.bottom = new FormAttachment(100, 0);
124+
formData.left = new FormAttachment(0, 0);
125+
formData.right = new FormAttachment(100, 0);
126+
return formData;
127+
}
128+
129+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.vogella.swt.widgets.customwidgets;
2+
3+
import org.eclipse.swt.graphics.Color;
4+
import org.eclipse.swt.widgets.Canvas;
5+
import org.eclipse.swt.widgets.Composite;
6+
7+
public class PictureLabel extends Canvas {
8+
private Color white;
9+
10+
PictureLabel(Composite parent, int style) {
11+
super(parent, style);
12+
white = new Color(null, 255, 255, 255);
13+
setBackground(white);
14+
}
15+
16+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.vogella.swt.widgets.customwidgets;
2+
3+
import org.eclipse.swt.SWT;
4+
import org.eclipse.swt.layout.FillLayout;
5+
import org.eclipse.swt.layout.GridLayout;
6+
import org.eclipse.swt.widgets.Button;
7+
import org.eclipse.swt.widgets.Composite;
8+
import org.eclipse.swt.widgets.Display;
9+
import org.eclipse.swt.widgets.Shell;
10+
11+
public class TestLayeredComposite {
12+
public static void main(String[] args) {
13+
Display display = new Display();
14+
Shell shell = new Shell(display);
15+
FillLayout layout = new FillLayout();
16+
layout.marginHeight = 0;
17+
layout.marginWidth = 0;
18+
shell.setLayout(layout);
19+
LayeredComposite composite = new LayeredComposite(shell, SWT.BOTTOM);
20+
21+
// Build the main area of the user interface
22+
Composite mainComposite = new Composite(composite.getContentComposite(), SWT.NONE);
23+
mainComposite.setLayout(new GridLayout(1, false));
24+
25+
for (int i = 0; i < 20; i++) {
26+
Button button = new Button(mainComposite, SWT.CHECK);
27+
button.setText("Testing " + i);
28+
29+
}
30+
31+
// Build the top layer of the user interface
32+
Composite layeredComposite = new Composite(composite.getOverlayComposite(), SWT.NONE);
33+
layeredComposite.setLayout(new GridLayout(1, true));
34+
for (int i = 0; i < 3; i++) {
35+
Button button = new Button(layeredComposite, SWT.PUSH);
36+
button.setText("Control Center" + i);
37+
}
38+
39+
shell.setSize(800, 300);
40+
shell.open();
41+
while (!shell.isDisposed()) {
42+
if (!display.readAndDispatch()) {
43+
display.sleep();
44+
}
45+
}
46+
47+
}
48+
}

0 commit comments

Comments
 (0)