private void addButtons() { if ((flags & SWT.CLOSE) != 0) { closeButton = new Label(composite, SWT.NONE); closeButton.setSize(getHeight(), getHeight()); closeButton.setImage(closeImage); closeButton.addListener(SWT.MouseUp, buttonListener); closeButton.addListener(SWT.MouseEnter, buttonListener); closeButton.addListener(SWT.MouseExit, buttonListener); } if ((flags & SWT.MIN) != 0) { minimizeButton = new Label(composite, SWT.PUSH | SWT.FLAT); minimizeButton.setSize(getHeight(), getHeight()); minimizeButton.setImage(minimizeImage); minimizeButton.addListener(SWT.MouseUp, buttonListener); minimizeButton.addListener(SWT.MouseEnter, buttonListener); minimizeButton.addListener(SWT.MouseExit, buttonListener); } if ((flags & SWT.MAX) != 0) { restoreButton = new Label(composite, SWT.PUSH | SWT.FLAT); restoreButton.setSize(getHeight(), getHeight()); restoreButton.setImage(restoreImage); restoreButton.addListener(SWT.MouseUp, buttonListener); restoreButton.addListener(SWT.MouseEnter, buttonListener); restoreButton.addListener(SWT.MouseExit, buttonListener); } setForeground(new Color(Display.getDefault(), 40, 40, 40)); setBackground(new Color(Display.getDefault(), 140, 140, 140)); }
/** * create Label and Combo width a Array of String. * * @param parent * @param labelStr * @param tip * @param item * @param horizontalSpan * @param isFill * @param style */ private void createLabelledCombo( final Composite parent, final String labelStr, final String tip, final String[] item, int horizontalSpan, boolean isFill, int style) { // label label = new Label(parent, SWT.LEFT); label.setText(labelStr); label.addListener( SWT.MouseEnter, new Listener() { public void handleEvent(final Event e) { checkbox.forceFocus(); } }); // checkbox checkbox = new Button(parent, SWT.CHECK); // combo GridData gridData; if (isFill) { gridData = new GridData(GridData.FILL_HORIZONTAL); } else { gridData = new GridData(); } gridData.horizontalSpan = horizontalSpan; combo = new Combo(parent, style); combo.setLayoutData(gridData); combo.setSize(A_100, A_20); for (int i = 0; i < item.length; i++) { combo.add(item[i]); } int visibleItemCount = combo.getItemCount(); if (visibleItemCount > MAX_VISIBLE_ITEM_COUNT) { visibleItemCount = MAX_VISIBLE_ITEM_COUNT; } combo.setVisibleItemCount(visibleItemCount); if (tip != null) { combo.setToolTipText(tip); } combo.setEnabled(false); addControls(parent); }
public NodeInspectableContainer(InspectorView parent, SceneNode target) { super(parent, target); int editorId = editorContext.editorId; addDisposeListener(e -> EventService.unsubscribe(editorId, this)); EventService.subscribe(editorId, this); addDisposeListener(e -> Workbench.deactivate(this)); Workbench.activate(this); FormToolkit toolkit = GurellaStudioPlugin.getToolkit(); toolkit.adapt(this); Composite body = getBody(); GridLayoutFactory.fillDefaults().numColumns(4).extendedMargins(0, 10, 4, 0).applyTo(body); Label nameLabel = toolkit.createLabel(body, " Name: "); nameLabel.setLayoutData(new GridData(BEGINNING, CENTER, false, false)); nameText = UiUtils.createText(body); nameText.setText(target.getName()); nameText.setLayoutData(new GridData(FILL, BEGINNING, true, false)); nameChangedlLstener = e -> nodeNameChanged(); nameText.addListener(SWT.Modify, nameChangedlLstener); enabledCheck = toolkit.createButton(body, "Enabled", CHECK); enabledCheck.setLayoutData(new GridData(END, CENTER, false, false)); enabledCheck.setSelection(target.isEnabled()); nodeEnabledListener = e -> nodeEnabledChanged(); enabledCheck.addListener(SWT.Selection, nodeEnabledListener); menuButton = toolkit.createLabel(body, " ", NONE); menuButton.setImage(GurellaStudioPlugin.createImage("icons/menu.png")); menuButton.setLayoutData(new GridData(END, CENTER, false, false)); menuButton.addListener(SWT.MouseUp, e -> showMenu()); componentsComposite = toolkit.createComposite(body); GridLayout componentsLayout = new GridLayout(1, false); componentsLayout.marginHeight = 0; componentsLayout.marginWidth = 0; componentsComposite.setLayout(componentsLayout); componentsComposite.setLayoutData(new GridData(FILL, FILL, true, true, 4, 1)); UiUtils.paintBordersFor(body); initComponentContainers(); layout(true, true); }
@SuppressWarnings("unchecked") public void prepareForOpen() { Point contentsSize = contents.getSize(); Point titleSize = new Point(0, 0); boolean showTitle = ((style & (SWT.CLOSE | SWT.TITLE)) != 0); if (showTitle) { if (titleLabel == null) { titleLabel = new Label(shell, SWT.NONE); titleLabel.setBackground(shell.getBackground()); titleLabel.setForeground(shell.getForeground()); FontData[] fds = shell.getFont().getFontData(); for (int i = 0; i < fds.length; i++) { fds[i].setStyle(fds[i].getStyle() | SWT.BOLD); } final Font font = new Font(shell.getDisplay(), fds); titleLabel.addListener( SWT.Dispose, new Listener() { @Override public void handleEvent(Event event) { font.dispose(); } }); titleLabel.setFont(font); selectionControls.add(titleLabel); } String titleText = shell.getText(); titleLabel.setText(titleText == null ? "" : titleText); titleLabel.pack(); titleSize = titleLabel.getSize(); final Image titleImage = shell.getImage(); if (titleImageLabel == null && shell.getImage() != null) { titleImageLabel = new Canvas(shell, SWT.NONE); titleImageLabel.setBackground(shell.getBackground()); titleImageLabel.setBounds(titleImage.getBounds()); titleImageLabel.addListener( SWT.Paint, new Listener() { @Override public void handleEvent(Event event) { event.gc.drawImage(titleImage, 0, 0); } }); Point tilSize = titleImageLabel.getSize(); titleSize.x += tilSize.x + titleWidgetSpacing; if (tilSize.y > titleSize.y) titleSize.y = tilSize.y; selectionControls.add(titleImageLabel); } if (systemControlsBar == null && (style & SWT.CLOSE) != 0) { // Color closeFG = shell.getForeground(), closeBG = shell.getBackground(); // Color closeFG = shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY), closeBG = // shell.getBackground(); Color closeFG = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND), closeBG = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); final Image closeImage = createCloseImage(shell.getDisplay(), closeBG, closeFG); shell.addListener( SWT.Dispose, new Listener() { @Override public void handleEvent(Event event) { closeImage.dispose(); } }); systemControlsBar = new ToolBar(shell, SWT.FLAT); systemControlsBar.setBackground(closeBG); systemControlsBar.setForeground(closeFG); ToolItem closeItem = new ToolItem(systemControlsBar, SWT.PUSH); closeItem.setImage(closeImage); closeItem.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { shell.close(); } }); systemControlsBar.pack(); Point closeSize = systemControlsBar.getSize(); titleSize.x += closeSize.x + titleWidgetSpacing; if (closeSize.y > titleSize.y) titleSize.y = closeSize.y; } titleSize.y += titleSpacing; if (titleSize.x > contentsSize.x) { contentsSize.x = titleSize.x; contents.setSize(contentsSize.x, contentsSize.y); } contentsSize.y += titleSize.y; } Rectangle screen = shell.getDisplay().getClientArea(); int anchor = preferredAnchor; if (anchor != SWT.NONE && autoAnchor && locX != Integer.MIN_VALUE) { if ((anchor & SWT.LEFT) != 0) { if (locX + contentsSize.x + marginLeft + marginRight - 16 >= screen.x + screen.width) anchor = anchor - SWT.LEFT + SWT.RIGHT; } else // RIGHT { if (locX - contentsSize.x - marginLeft - marginRight + 16 < screen.x) anchor = anchor - SWT.RIGHT + SWT.LEFT; } if ((anchor & SWT.TOP) != 0) { if (locY + contentsSize.y + 20 + marginTop + marginBottom >= screen.y + screen.height) anchor = anchor - SWT.TOP + SWT.BOTTOM; } else // BOTTOM { if (locY - contentsSize.y - 20 - marginTop - marginBottom < screen.y) anchor = anchor - SWT.BOTTOM + SWT.TOP; } } final Point shellSize = (anchor == SWT.NONE) ? new Point( contentsSize.x + marginLeft + marginRight, contentsSize.y + marginTop + marginBottom) : new Point( contentsSize.x + marginLeft + marginRight, contentsSize.y + marginTop + marginBottom + 20); if (shellSize.x < 54 + marginLeft + marginRight) shellSize.x = 54 + marginLeft + marginRight; if (anchor == SWT.NONE) { if (shellSize.y < 10 + marginTop + marginBottom) shellSize.y = 10 + marginTop + marginBottom; } else { if (shellSize.y < 30 + marginTop + marginBottom) shellSize.y = 30 + marginTop + marginBottom; } shell.setSize(shellSize); int titleLocY = marginTop + (((anchor & SWT.TOP) != 0) ? 20 : 0); contents.setLocation(marginLeft, titleSize.y + titleLocY); if (showTitle) { int realTitleHeight = titleSize.y - titleSpacing; if (titleImageLabel != null) { titleImageLabel.setLocation( marginLeft, titleLocY + (realTitleHeight - titleImageLabel.getSize().y) / 2); titleLabel.setLocation( marginLeft + titleImageLabel.getSize().x + titleWidgetSpacing, titleLocY + (realTitleHeight - titleLabel.getSize().y) / 2); } else titleLabel.setLocation( marginLeft, titleLocY + (realTitleHeight - titleLabel.getSize().y) / 2); if (systemControlsBar != null) systemControlsBar.setLocation( shellSize.x - marginRight - systemControlsBar.getSize().x, titleLocY + (realTitleHeight - systemControlsBar.getSize().y) / 2); } final Region region = new Region(); region.add(createOutline(shellSize, anchor, true)); shell.setRegion(region); shell.addListener( SWT.Dispose, new Listener() { @Override public void handleEvent(Event event) { region.dispose(); } }); final int[] outline = createOutline(shellSize, anchor, false); shell.addListener( SWT.Paint, new Listener() { @Override public void handleEvent(Event event) { event.gc.drawPolygon(outline); } }); if (locX != Integer.MIN_VALUE) { Point shellLoc = new Point(locX, locY); if ((anchor & SWT.BOTTOM) != 0) shellLoc.y = shellLoc.y - shellSize.y + 1; if ((anchor & SWT.LEFT) != 0) shellLoc.x -= 15; else if ((anchor & SWT.RIGHT) != 0) shellLoc.x = shellLoc.x - shellSize.x + 16; if (autoAnchor) { if (shellLoc.x < screen.x) shellLoc.x = screen.x; else if (shellLoc.x > screen.x + screen.width - shellSize.x) shellLoc.x = screen.x + screen.width - shellSize.x; if (anchor == SWT.NONE) { if (shellLoc.y < screen.y) shellLoc.y = screen.y; else if (shellLoc.y > screen.y + screen.height - shellSize.y) shellLoc.y = screen.y + screen.height - shellSize.y; } } shell.setLocation(shellLoc); } }
public TitleBar(final Window parent, final int size, int flags) { this.flags = flags; composite = new Composite(parent.getContentPanel(), SWT.NONE); composite.setSize(parent.getSize().x, size); buttonListener = new Listener() { public void handleEvent(Event event) { if (event.type == SWT.MouseUp) { // If the click is still on the button. if (event.x >= 0 && event.x < size && event.y >= 0 && event.y < size) { if (event.widget == closeButton) { parent.close(); } else if (event.widget == restoreButton) { dontSetX = true; parent.setMaximized(!parent.isMaximized()); } else if (event.widget == minimizeButton) { parent.setMinimized(true); } } } else if (event.type == SWT.MouseEnter) { Label button = (Label) event.widget; button.setBackground(hoverColor); } else if (event.type == SWT.MouseExit) { Label button = (Label) event.widget; button.setBackground(normalColor); } } }; addButtons(); titleLabel = new Label(composite, SWT.NONE); FontData fd = titleLabel.getFont().getFontData()[0]; fd.setHeight(14); titleLabel.setFont(new Font(Display.getDefault(), fd)); titleGC = new GC(titleLabel); setTitle(parent.getTitle()); iconLabel = new Label(composite, SWT.NONE); setIcon(parent.getIcon()); dontSetX = true; wasRestored = true; wasMaximized = parent.isMaximized(); ControlListener resizeListener = new ControlListener() { public void controlResized(ControlEvent e) { composite.setSize(parent.getClientArea().width, size); setTitleLocation(); layoutButtons(); if (parent.isMaximized()) { if (restoreButton != null) { restoreButton.setImage(restoreImage); } } else { if (wasMaximized && !dontSetX) { parent.setLocation(mouseX - parent.getSize().x / 2, parent.getLocation().y); } if (restoreButton != null) { restoreButton.setImage(maximizeImage); } } dontSetX = false; wasRestored = false; wasMaximized = false; if (parent.isFullscreen()) { if (minimizeButton != null) { minimizeButton.setEnabled(false); // .setVisible(false); } if (restoreButton != null) { restoreButton.setEnabled(false); // .setVisible(false); } } else { if (minimizeButton != null) { minimizeButton.setEnabled(true); // .setVisible(true); } if (restoreButton != null) { restoreButton.setEnabled(true); // .setVisible(true); } } } public void controlMoved(ControlEvent e) {} }; parent.addControlListener(resizeListener); final Tracker tracker = new Tracker(parent.getShell(), SWT.NONE); tracker.addControlListener( new ControlListener() { public void controlResized(ControlEvent e) {} public void controlMoved(ControlEvent e) { if (parent.isMaximized()) { parent.setMaximized(false); } Point loc = new Point( tracker.getRectangles()[0].x + 99999, tracker.getRectangles()[0].y + 99999); int dx = loc.x - startX; int dy = loc.y - startY; parent.setLocation(parent.getLocation().x + dx, parent.getLocation().y + dy); startX = loc.x; startY = loc.y; } }); Listener moveListener = new Listener() { public void handleEvent(Event event) { if (!parent.isFullscreen()) { if (event.type == SWT.MouseDown) { dragging = true; Control control = (Control) event.widget; mouseX = event.x + parent.getBorderSize() + control.getLocation().x; mouseY = event.y + parent.getBorderSize() + control.getLocation().y; wasMaximized = parent.isMaximized(); startX = 0; startY = 0; tracker.setRectangles(new Rectangle[] {new Rectangle(-99999, -99999, 0, 0)}); tracker.open(); tracker.close(); dragging = false; if (parent.getLocation().y + mouseY <= 0) { wasRestored = true; parent.setMaximized(true); } } else if (event.type == SWT.MouseDoubleClick) { dontSetX = true; wasRestored = true; parent.setMaximized(!parent.isMaximized()); } } } }; titleLabel.addListener(SWT.MouseDown, moveListener); titleLabel.addListener(SWT.MouseDoubleClick, moveListener); composite.addListener(SWT.MouseDown, moveListener); composite.addListener(SWT.MouseDoubleClick, moveListener); parent.addWindowListener( new WindowListener() { public boolean titleChanged(String newTitle) { setTitle(newTitle); return true; } public boolean iconChanged(Image newIcon) { setIcon(newIcon); return true; } }); composite.setBackgroundMode(SWT.INHERIT_DEFAULT); }
public UI(final Display display, final ArrayList<Mesh> meshes, final Transform transform) { this.transform = transform; final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER); shell.setSize(800, 600); // shell.setToolTipText("This is a window"); // how to make a tooltip // // Button quitBtn = new Button( shell, SWT.PUSH ); // how to make a button // // quitBtn.setText( "Quit" ); // quitBtn.setLayoutData( new RowData( 80, 30)); // centerWindow( shell ); //Generates strange problem final Label label = new Label(shell, SWT.CENTER); shell.addControlListener( new ControlAdapter() { public void controlResized(ControlEvent e) { label.setBounds(shell.getClientArea()); Rectangle rect = shell.getClientArea(); label.setImage(getCheckedImage(display, label, meshes, rect)); } }); Listener keyListener = new Listener() { public void handleEvent(Event event) { String string = event.type == SWT.KeyDown ? "DOWN:" : "UP :"; string += event.keyCode; System.out.println(string); switch (event.type) { case SWT.KeyDown: if (event.keyCode == 114) r = true; break; case SWT.KeyUp: if (event.keyCode == 114) r = false; break; } } }; shell.addListener(SWT.KeyDown, keyListener); shell.addListener(SWT.KeyUp, keyListener); Listener listener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.MouseDown: mouseDown = true; beginX = event.x; beginY = event.y; // prevX = event.x; // prevY = event.y; // currX = event.x; // currY = event.y; // System.out.println( beginX +", " +beginY ); // System.out.println("down:" + event); break; case SWT.MouseUp: mouseDown = false; endX = event.x; endY = event.y; Rectangle rect1 = shell.getClientArea(); label.setImage(getCheckedImage(display, label, meshes, rect1)); // transform.rotateZ( ( endX-beginX ) / 200 ); // transform.rotateX( ( endY-beginY ) / 200 ); // System.out.println( endX +", " +endY ); System.out.println("Up:" + event); break; } } }; label.addListener(SWT.MouseDown, listener); label.addListener(SWT.MouseUp, listener); Listener moveListener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.MouseMove: if (r) { // System.out.println("move:"+event); endX = event.x; endY = event.y; transform.rotateY(-((float) (beginX - endX)) / rotateDamper); // System.out.print( "X rotation = " +((beginX-endX)/rotateDamper) ); // //+".... beginX = " +beginX +" endX = " +endX ); transform.rotateX(((float) (beginY - endY)) / rotateDamper); // System.out.println( "Y rotation = " +((beginY-endY)/rotateDamper) // ); //+".... beginY = " +beginY +" endY = " +endY ); beginX = event.x; beginY = event.y; Rectangle rect = shell.getClientArea(); label.setImage(getCheckedImage(display, label, meshes, rect)); } break; } } }; label.addListener(SWT.MouseMove, moveListener); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }