Skip to content

Commit

Permalink
feat: Support Snippet menu (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
unknowIfGuestInDream committed Jun 16, 2024
1 parent 91b0e97 commit 5c5acba
Show file tree
Hide file tree
Showing 373 changed files with 30,896 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
Expand Down Expand Up @@ -103,7 +104,7 @@ org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverridin
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=error
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=error
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
Expand Down
4 changes: 3 additions & 1 deletion examples/org.eclipse.swt.snippets/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Bundle-Version: 3.4.0
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.swt,
org.eclipse.ui
org.eclipse.ui,
org.eclipse.osgi,
org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: org.eclipse.swt.snippets
Bundle-ActivationPolicy: lazy
3 changes: 2 additions & 1 deletion examples/org.eclipse.swt.snippets/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ bin.includes = META-INF/,\
previews/,\
plugin.xml,\
plugin.properties,\
about.html
about.html,\
source/
36 changes: 36 additions & 0 deletions examples/org.eclipse.swt.snippets/source/Snippet1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2000, 2012 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;

/*
* example snippet: Hello World
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.widgets.*;

public class Snippet1 {

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell(display);
shell.setText("Snippet 1");
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
68 changes: 68 additions & 0 deletions examples/org.eclipse.swt.snippets/source/Snippet10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;

/*
* Draw using transformations, paths and alpha blending
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*
* @since 3.1
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Snippet10 {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Advanced Graphics");
FontData fd = shell.getFont().getFontData()[0];
final Font font = new Font(display, fd.getName(), 60, SWT.BOLD | SWT.ITALIC);
final Image image = new Image(display, 640, 480);
final Rectangle rect = image.getBounds();
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillOval(rect.x, rect.y, rect.width, rect.height);
gc.dispose();
shell.addListener(SWT.Paint, event -> {
GC gc1 = event.gc;
Transform tr = new Transform(display);
tr.translate(50, 120);
tr.rotate(-30);
gc1.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2);
gc1.setAlpha(100);
gc1.setTransform(tr);
Path path = new Path(display);
path.addString("SWT", 0, 0, font);
gc1.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
gc1.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
gc1.fillPath(path);
gc1.drawPath(path);
tr.dispose();
path.dispose();
});
shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
image.dispose();
font.dispose();
display.dispose();
}
}
51 changes: 51 additions & 0 deletions examples/org.eclipse.swt.snippets/source/Snippet100.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;

/*
* Font example snippet: create a large font for use by a text widget
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Snippet100 {

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Snippet 100");
shell.setBounds(10, 10, 200, 200);
Text text = new Text(shell, SWT.MULTI);
Rectangle clientArea = shell.getClientArea();
text.setBounds(clientArea.x + 10, clientArea.y + 10, 150, 150);
Font initialFont = text.getFont();
FontData[] fontData = initialFont.getFontData();
for (FontData element : fontData) {
element.setHeight(24);
}
Font newFont = new Font(display, fontData);
text.setFont(newFont);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
newFont.dispose();
display.dispose();
}
}
50 changes: 50 additions & 0 deletions examples/org.eclipse.swt.snippets/source/Snippet101.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;

/*
* Table example snippet: insert a table item (at an index)
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Snippet101 {

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setText("Snippet 101");
Table table = new Table (shell, SWT.BORDER | SWT.MULTI);
Rectangle clientArea = shell.getClientArea ();
table.setBounds (clientArea.x, clientArea.y, 200, 200);
for (int i=0; i<12; i++) {
TableItem item = new TableItem (table, SWT.NONE);
item.setText ("Item " + i);
}
TableItem item = new TableItem (table, SWT.NONE, 1);
item.setText ("*** New Item " + table.indexOf (item) + " ***");
shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

}

52 changes: 52 additions & 0 deletions examples/org.eclipse.swt.snippets/source/Snippet102.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;

/*
* Tree example snippet: insert a tree item (at an index)
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Snippet102 {

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setText("Snippet 102");
Tree tree = new Tree (shell, SWT.BORDER | SWT.MULTI);
Rectangle clientArea = shell.getClientArea ();
tree.setBounds (clientArea.x, clientArea.y, 200, 200);
for (int i=0; i<12; i++) {
TreeItem item = new TreeItem (tree, SWT.NONE);
item.setText ("Item " + i);
}
TreeItem item = new TreeItem (tree, SWT.NONE, 1);
TreeItem [] items = tree.getItems ();
int index = 0;
while (index < items.length && items [index] != item) index++;
item.setText ("*** New Item " + index + " ***");
shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

}
76 changes: 76 additions & 0 deletions examples/org.eclipse.swt.snippets/source/Snippet103.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;

/*
* Table example snippet: update table item text
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Snippet103 {

static char content = 'a';
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Snippet 103");
shell.setBounds(10, 10, 200, 240);
Table table = new Table(shell, SWT.NONE);
Rectangle clientArea = shell.getClientArea ();
table.setBounds (clientArea.x + 10, clientArea.y + 10, 160, 160);

final TableItem[] items = new TableItem[4];
for (int i = 0; i < 4; i++) {
new TableColumn(table, SWT.NONE).setWidth(40);
}
for (int i = 0; i < 4; i++) {
items[i] = new TableItem(table, SWT.NONE);
populateItem(items[i]);
}

Button button = new Button(shell, SWT.PUSH);
button.setText("Change");
button.pack();
button.setLocation(10, 180);
button.addListener(SWT.Selection, event -> {
for (int i = 0; i < 4; i++) {
populateItem(items[i]);
}
});

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

static void populateItem(TableItem item) {
String stringContent = String.valueOf(content);
item.setText(
new String[] {
stringContent,
stringContent,
stringContent,
stringContent });
content++;
if (content > 'z') content = 'a';
}

}
Loading

0 comments on commit 5c5acba

Please sign in to comment.