?? internalshellexampleswt.java
字號:
package com.novocode.naf.example.ishell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import com.novocode.naf.gui.layout.FormDataCreator;
import com.novocode.naf.swt.custom.CustomSeparator;
import com.novocode.naf.swt.custom.ScaledImage;
import com.novocode.naf.swt.custom.ishell.DesktopForm;
import com.novocode.naf.swt.custom.ishell.InternalShell;
public class InternalShellExampleSWT
{
private static int nextWindowNumber = 1;
private static Image iconImage;
public static void main(String[] args)
{
Display display = new Display();
iconImage = new Image(display, InternalShellExampleSWT.class.getResourceAsStream("ishell.png"));
Image backgroundImage = new Image(display, InternalShellExampleSWT.class.getResourceAsStream("IMG_2006-a-fixed-seamless.jpg"));
Shell shell = new Shell(display);
shell.setImage(iconImage);
FormLayout layout = new FormLayout();
layout.spacing = 0;
layout.marginWidth = 0;
layout.marginHeight = 0;
shell.setLayout(layout);
shell.setText("Internal Shell Example (SWT)");
CustomSeparator sep = new CustomSeparator(shell, SWT.HORIZONTAL);
sep.setLayoutData(FormDataCreator.createFormData(sep, "0, 1, 0"));
final DesktopForm desktop = new DesktopForm(shell, SWT.NONE);
desktop.setShowMaximizedTitle(true);
desktop.setLayoutData(FormDataCreator.createFormData(desktop, "0, 1, :prev, 1"));
// Add a background image to the DesktopForm
final ScaledImage si = new ScaledImage(desktop, SWT.NONE);
si.setImage(backgroundImage);
si.setImagePlacement(ScaledImage.IMAGE_PLACEMENT_TILE);
// Note: Don't set a layout on a DesktopForm
si.setLocation(0, 0);
si.setSize(desktop.getSize());
desktop.addListener(SWT.Resize, new Listener()
{
public void handleEvent(Event event)
{
si.setSize(desktop.getSize());
}
});
createInternalShell(desktop, SWT.SHELL_TRIM, true, false);
shell.setSize(700, 500);
shell.open();
desktop.setFocus();
while(!shell.isDisposed())
{
if(!display.readAndDispatch()) display.sleep();
}
iconImage.dispose();
display.dispose();
}
private static String styleString(int style, boolean sizeGrip, boolean customMenu)
{
StringBuffer b = new StringBuffer();
if((style & SWT.CLOSE) != 0) b.append("|CLOSE");
if((style & SWT.RESIZE) != 0) b.append("|RESIZE");
if((style & SWT.MAX) != 0) b.append("|MAX");
if((style & SWT.MIN) != 0) b.append("|MIN");
if((style & SWT.TOOL) != 0) b.append("|TOOL");
if((style & SWT.ON_TOP) != 0) b.append("|ON_TOP");
String styleStr;
if(b.length() == 0) styleStr = "NONE";
else styleStr = b.substring(1);
if(sizeGrip) styleStr = styleStr + ", SizeGrip";
if(customMenu) styleStr = styleStr + ", Custom Menu";
return styleStr;
}
private static InternalShell createInternalShell(DesktopForm desktop, int style, boolean sizeGrip, boolean customMenu)
{
int windowNumber = nextWindowNumber++;
InternalShell ishell = new InternalShell(desktop, style);
ishell.setImage(iconImage);
ishell.setText("Internal Shell "+windowNumber);
if(customMenu)
{
Menu menu = new Menu(ishell);
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText("Custom Menu Item");
ishell.setCustomMenu(menu);
}
Composite ishellContent = ishell.getContentPane();
ishellContent.setLayout(new FormLayout());
CLabel label = new CLabel(ishellContent, SWT.NONE);
label.setText(windowNumber+". "+styleString(style, sizeGrip, customMenu));
Button b1 = new Button(ishellContent, SWT.NONE);
b1.setText(" 1 ");
Button b2 = new Button(ishellContent, SWT.NONE);
b2.setText(" 2 ");
Button b3 = new Button(ishellContent, SWT.NONE);
b3.setText(" 3 ");
new FormDataCreator(ishellContent)
.layout(label, "4px,-4px,4px,:next-4px")
.layout(b1, "4px,,,-4px")
.layout(b2, ":prev+4px,,,-4px")
.layout(b3, ":prev+4px,,,-4px");
if(sizeGrip) ishell.createSizeGrip(SWT.NONE);
ishell.pack();
ishell.open();
return ishell;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -