X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=blobdiff_plain;f=swt%2Forg.argeo.swt.minidesktop%2Fsrc%2Forg%2Fargeo%2Fminidesktop%2FMiniDesktopManager.java;fp=swt%2Forg.argeo.swt.minidesktop%2Fsrc%2Forg%2Fargeo%2Fminidesktop%2FMiniDesktopManager.java;h=6604b4f3e313a8371ebbdab3c39eb5e9b9fb79af;hp=adb2a55ba95f6393857c8a45877981204bed1642;hb=b95462873703848193e56fcbe997693630db6121;hpb=55d88fba80cec198a0f11ba7545e19878c51fc5e diff --git a/swt/org.argeo.swt.minidesktop/src/org/argeo/minidesktop/MiniDesktopManager.java b/swt/org.argeo.swt.minidesktop/src/org/argeo/minidesktop/MiniDesktopManager.java index adb2a55ba..6604b4f3e 100644 --- a/swt/org.argeo.swt.minidesktop/src/org/argeo/minidesktop/MiniDesktopManager.java +++ b/swt/org.argeo.swt.minidesktop/src/org/argeo/minidesktop/MiniDesktopManager.java @@ -44,82 +44,100 @@ public class MiniDesktopManager { this.stacking = stacking; } + public MiniDesktopManager() { + this(false, false); + } + + public void start() { + init(); + } + + public void stop() { + dispose(); + if (display != null) { + display.dispose(); + display = null; + } + } + public void init() { Display.setAppName("Mini SWT Desktop"); display = Display.getCurrent(); if (display != null) throw new IllegalStateException("Already a display " + display); - display = new Display(); + display = Display.getDefault(); - if (display.getTouchEnabled()) { - System.out.println("Touch enabled."); - } - - images = new MiniDesktopImages(display); + display.syncExec(() -> { + if (display.getTouchEnabled()) { + System.out.println("Touch enabled."); + } - int toolBarSize = 48; + 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.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); + } - 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.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))); + Composite toolBarArea = new Composite(rootShell, SWT.NONE); + toolBarArea.setLayoutData(new GridData(toolBarSize, rootShell.getSize().y)); - rootShell.setLayout(noSpaceGridLayout(new GridLayout(2, false))); - Composite toolBarArea = new Composite(rootShell, SWT.NONE); - toolBarArea.setLayoutData(new GridData(toolBarSize, rootShell.getSize().y)); - - ToolBar toolBar; - if (isFullscreen()) { - toolBarShell = new Shell(rootShell, SWT.NO_TRIM | SWT.ON_TOP); - toolBar = new ToolBar(toolBarShell, SWT.VERTICAL | SWT.FLAT | SWT.BORDER); - createDock(toolBar); - toolBarShell.pack(); - toolBarArea.setLayoutData(new GridData(toolBar.getSize().x, toolBar.getSize().y)); - } else { - toolBar = new ToolBar(toolBarArea, SWT.VERTICAL | SWT.FLAT | SWT.BORDER); - createDock(toolBar); - toolBarArea.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); - } + ToolBar toolBar; + if (isFullscreen()) { + toolBarShell = new Shell(rootShell, SWT.NO_TRIM | SWT.ON_TOP); + toolBar = new ToolBar(toolBarShell, SWT.VERTICAL | SWT.FLAT | SWT.BORDER); + createDock(toolBar); + toolBarShell.pack(); + toolBarArea.setLayoutData(new GridData(toolBar.getSize().x, toolBar.getSize().y)); + } else { + toolBar = new ToolBar(toolBarArea, SWT.VERTICAL | SWT.FLAT | SWT.BORDER); + createDock(toolBar); + toolBarArea.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + } - if (isStacking()) { - 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 homeTabItem = new CTabItem(tabFolder, SWT.NONE); - homeTabItem.setText("Home"); - homeTabItem.setImage(images.homeIcon); - homeTabItem.setControl(background); - tabFolder.setFocus(); - } else { - createBackground(rootShell); - } + if (isStacking()) { + 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 homeTabItem = new CTabItem(tabFolder, SWT.NONE); + homeTabItem.setText("Home"); + homeTabItem.setImage(images.homeIcon); + homeTabItem.setControl(background); + tabFolder.setFocus(); + } else { + createBackground(rootShell); + } - rootShell.open(); - // rootShell.layout(true, true); + rootShell.open(); + // rootShell.layout(true, true); - if (toolBarShell != null) { - int toolBarShellY = (display.getBounds().height - toolBar.getSize().y) / 2; - toolBarShell.setLocation(0, toolBarShellY); - toolBarShell.open(); - } + if (toolBarShell != null) { + int toolBarShellY = (display.getBounds().height - toolBar.getSize().y) / 2; + toolBarShell.setLocation(0, toolBarShellY); + toolBarShell.open(); + } - long jvmUptime = ManagementFactory.getRuntimeMXBean().getUptime(); - System.out.println("SWT Mini Desktop Manager available in " + jvmUptime + " ms."); + long jvmUptime = ManagementFactory.getRuntimeMXBean().getUptime(); + System.out.println("SWT Mini Desktop Manager available in " + jvmUptime + " ms."); + }); } protected void createDock(ToolBar toolBar) {