import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
private final boolean fullscreen;
private final boolean stacking;
+ private MiniDesktopImages images;
+
public MiniDesktopManager(boolean fullscreen, boolean stacking) {
this.fullscreen = fullscreen;
this.stacking = stacking;
}
public void init() {
+ Display.setAppName("Mini SWT Desktop");
display = Display.getCurrent();
if (display != null)
throw new IllegalStateException("Already a display " + display);
display = new Display();
+ if (display.getTouchEnabled()) {
+ System.out.println("Touch enabled.");
+ }
+
+ images = new MiniDesktopImages(display);
+
int toolBarSize = 48;
if (isFullscreen()) {
rootShell = new Shell(display, SWT.NO_TRIM);
rootShell.setFullScreen(true);
Rectangle bounds = display.getBounds();
+ rootShell.setLocation(0, 0);
rootShell.setSize(bounds.width, bounds.height);
} else {
- rootShell = new Shell(display, SWT.SHELL_TRIM);
+ rootShell = new Shell(display, SWT.CLOSE | SWT.RESIZE);
Rectangle shellArea = rootShell.computeTrim(200, 200, 800, 480);
rootShell.setSize(shellArea.width, shellArea.height);
+ rootShell.setText(Display.getAppName());
+ rootShell.setImage(images.terminalIcon);
}
rootShell.setLayout(noSpaceGridLayout(new GridLayout(2, false)));
} else {
toolBar = new ToolBar(toolBarArea, SWT.VERTICAL | SWT.FLAT | SWT.BORDER);
createDock(toolBar);
- toolBarArea.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+ toolBarArea.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
}
if (isStacking()) {
- tabFolder = new CTabFolder(rootShell, SWT.MULTI);
+ tabFolder = new CTabFolder(rootShell, SWT.MULTI | SWT.BORDER | SWT.BOTTOM);
+ tabFolder.setLayout(noSpaceGridLayout(new GridLayout()));
tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ Color selectionBackground = display.getSystemColor(SWT.COLOR_LIST_SELECTION);
+ tabFolder.setSelectionBackground(selectionBackground);
+
// background
Control background = createBackground(tabFolder);
- CTabItem noCloseItem = new CTabItem(tabFolder, SWT.NONE);
- noCloseItem.setText("Home");
- noCloseItem.setControl(background);
+ CTabItem homeTabItem = new CTabItem(tabFolder, SWT.NONE);
+ homeTabItem.setText("Home");
+ homeTabItem.setImage(images.homeIcon);
+ homeTabItem.setControl(background);
+ tabFolder.setFocus();
} else {
createBackground(rootShell);
}
// rootShell.layout(true, true);
if (toolBarShell != null) {
- toolBarShell.setLocation(new Point(0, 0));
+ int toolBarShellY = (display.getBounds().height - toolBar.getSize().y) / 2;
+ toolBarShell.setLocation(0, toolBarShellY);
toolBarShell.open();
}
}
protected void createDock(ToolBar toolBar) {
// Terminal
- addToolItem(toolBar, display.getSystemImage(SWT.ICON_INFORMATION), "Terminal", () -> {
+ addToolItem(toolBar, images.terminalIcon, "Terminal", () -> {
String url = System.getProperty("user.home");
- AppContext appContext = createAppParent();
+ AppContext appContext = createAppParent(images.terminalIcon);
new MiniTerminal(appContext.getAppParent(), url) {
@Override
});
// Web browser
- addToolItem(toolBar, display.getSystemImage(SWT.ICON_QUESTION), "Browser", () -> {
- String url = "https://duckduckgo.com/";
- AppContext appContext = createAppParent();
+ addToolItem(toolBar, images.browserIcon, "Browser", () -> {
+ String url = "https://start.duckduckgo.com/";
+ AppContext appContext = createAppParent(images.browserIcon);
new MiniBrowser(appContext.getAppParent(), url, false, false) {
@Override
protected void titleChanged(String title) {
});
// File explorer
- addToolItem(toolBar, display.getSystemImage(SWT.ICON_WARNING), "Explorer", () -> {
+ addToolItem(toolBar, images.explorerIcon, "Explorer", () -> {
String url = System.getProperty("user.home");
- AppContext appContext = createAppParent();
+ AppContext appContext = createAppParent(images.explorerIcon);
new MiniExplorer(appContext.getAppParent(), url) {
@Override
openApp(appContext);
});
+ // Separator
+ new ToolItem(toolBar, SWT.SEPARATOR);
+
// Exit
- addToolItem(toolBar, display.getSystemImage(SWT.ICON_ERROR), "Exit", () -> rootShell.dispose());
+ addToolItem(toolBar, images.exitIcon, "Exit", () -> rootShell.dispose());
toolBar.pack();
}
});
}
- protected AppContext createAppParent() {
+ protected AppContext createAppParent(Image icon) {
if (isStacking()) {
- Composite appParent = new Composite(tabFolder, SWT.NONE);
+ Composite appParent = new Composite(tabFolder, SWT.CLOSE);
appParent.setLayout(noSpaceGridLayout(new GridLayout()));
CTabItem item = new CTabItem(tabFolder, SWT.CLOSE);
+ item.setImage(icon);
item.setControl(appParent);
return new AppContext(item);
} else {
- Shell shell = new Shell(rootShell, SWT.SHELL_TRIM);
+ Shell shell = isFullscreen() ? new Shell(rootShell, SWT.SHELL_TRIM)
+ : new Shell(rootShell.getDisplay(), SWT.SHELL_TRIM);
+ shell.setImage(icon);
return new AppContext(shell);
}
}
shell.setSize(new Point(800, 480));
}
if (appContext.tabItem != null) {
+ tabFolder.setFocus();
tabFolder.setSelection(appContext.tabItem);
}
}
}
protected void initBackground(Composite backgroundArea) {
+ MiniHomePart homePart = new MiniHomePart() {
+
+ @Override
+ protected void fillAppsToolBar(ToolBar toolBar) {
+ createDock(toolBar);
+ }
+ };
+ homePart.createUiPart(backgroundArea, null);
}
public void run() {