private void setTitleLocation() { int textWidth = titleLabel.getSize().x; int textHeight = titleLabel.getSize().y; if ((flags & SWT.CENTER) != 0) { titleLabel.setLocation(getWidth() / 2 - textWidth / 2, 0); } else if ((flags & SWT.RIGHT) != 0) { titleLabel.setLocation(getWidth() - textWidth, 0); } else { titleLabel.setLocation(0, 0); } }
@Override protected void createControl(Composite parent) { Label label = new Label(parent, SWT.NONE); label.setText(getLabelText()); label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); Composite comp = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; comp.setLayout(layout); comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); fText = new Text(comp, SWT.SINGLE | SWT.BORDER); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = 200; fText.setLayoutData(data); // make sure rows are the same height on both panels. label.setSize(label.getSize().x, fText.getSize().y); if (getInitialValue() != null) { fText.setText(getInitialValue()); } fCurrentSelection = fText.getText(); fText.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { fCurrentSelection = fText.getText(); getDialog().validateFields(); } }); Button button = createButton(comp, IDialogConstants.IGNORE_ID, "&Browse...", false); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String selected = FileSelector.getFile( getDialog().getShell(), fText.getText(), fFileValidator, fFilter, fRoot, fCurrentDir); if (selected != null) { fCurrentSelection = fText.getText(); fText.setText(selected); getDialog().validateFields(); } } }); }
/** Performs layouting. */ private void layout() { // Disable redrawing toolbar.setRedraw(false); // Adjust size of items and composite Rectangle bounds = toolbar.getBounds(); int remaining = toolbar.getBounds().width; for (final ToolItem item : toolitems) { remaining -= item.getBounds().width; } remaining -= OFFSET; infoComposite.setSize(remaining, bounds.height); infoItem.setWidth(remaining); int locationY = (infoComposite.getBounds().height - labelSelected.getBounds().height) / 2; // Layout label int locationX = remaining - labelApplied.getSize().x; labelApplied.setLocation(locationX, locationY); if (locationX < 0) labelApplied.setVisible(false); else labelApplied.setVisible(true); // Layout label locationX -= labelSelected.getSize().x + OFFSET; labelSelected.setLocation(locationX, locationY); if (locationX < 0) labelSelected.setVisible(false); else labelSelected.setVisible(true); // Layout label locationX -= labelTransformations.getSize().x + OFFSET; labelTransformations.setLocation(locationX, locationY); if (locationX < 0) labelTransformations.setVisible(false); else labelTransformations.setVisible(true); // Layout label locationX -= labelAttribute.getSize().x + OFFSET; labelAttribute.setLocation(locationX, locationY); if (locationX < 0) labelAttribute.setVisible(false); else labelAttribute.setVisible(true); // Redraw toolbar.setRedraw(true); }
private void createAccessControl(Composite parent) throws JavaModelException { Composite access = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; access.setLayout(layout); final int[] availableVisibilities = getChangeMethodSignatureProcessor().getAvailableVisibilities(); int currentVisibility = getChangeMethodSignatureProcessor().getVisibility(); Label label = new Label(access, SWT.NONE); label.setText(RefactoringMessages.ChangeSignatureInputPage_access_modifier); final Combo combo = new Combo(access, SWT.DROP_DOWN | SWT.READ_ONLY); if (availableVisibilities.length == 0) { combo.setEnabled(false); } else { for (int i = 0; i < availableVisibilities.length; i++) { combo.add(getAccessModifierString(availableVisibilities[i])); } combo.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { int newVisibility = availableVisibilities[combo.getSelectionIndex()]; getChangeMethodSignatureProcessor().setVisibility(newVisibility); update(true); } }); } combo.setText(getAccessModifierString(currentVisibility)); combo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // ensure that "Access modifier:" and "Return type:" Labels are not too close: Dialog.applyDialogFont(access); access.pack(); int minLabelWidth = label.getSize().x + 3 * layout.horizontalSpacing; if (minLabelWidth > combo.getSize().x) label.setLayoutData(new GridData(minLabelWidth, label.getSize().y)); }
@Override public Point computeSizeHint() { updateInput(); final Point sizeConstraints = getSizeConstraints(); final Rectangle trim = computeTrim(); // int charWidth = 20; // if (fInput.detailInfo != null) { // final int count = Math.min(6, fInfoText.getLineCount()); // for (int i = 0; i < count; i++) { // charWidth = Math.max(charWidth, fInfoText.getLine(i).length()); // } // } int widthHint = fInfoText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x + LayoutUtil.defaultHSpacing(); final int widthMax2 = LayoutUtil.hintWidth(fInfoText, PREF_DETAIL_PANE_FONT, 80); final int widthMax = ((sizeConstraints != null && sizeConstraints.x != SWT.DEFAULT) ? sizeConstraints.x : widthMax2) - trim.width; fLayoutHint = true; final int titleHint = LayoutUtil.defaultHMargin() + fTitleImage.getSize().x + LayoutUtil.defaultHSpacing() + fTitleText.computeSize(SWT.DEFAULT, SWT.DEFAULT).x; fLayoutHint = false; if (titleHint > widthHint && widthMax2 > widthHint) { widthHint = Math.min(widthMax2, titleHint); } if (widthMax < widthHint) { widthHint = widthMax; } // avoid change of wrapping caused by scrollbar if (widthHint < titleHint && widthHint + fInfoText.computeTrim(0, 0, 0, 0).width >= titleHint) { widthHint = titleHint; } final int heightMax = ((sizeConstraints != null && sizeConstraints.y != SWT.DEFAULT) ? sizeConstraints.y : fInfoText.getLineHeight() * 12) - trim.height; final Point size = fContentComposite.computeSize(widthHint, SWT.DEFAULT, true); size.y += LayoutUtil.defaultVSpacing(); size.x = Math.max(Math.min(size.x, widthMax), 200) + trim.width; size.y = Math.max(Math.min(size.y, heightMax), 100) + trim.height; return size; }
private void layoutButtons() { int offset = 0; if (PROPERTIES.get("os.name").equals("macosx")) { if (closeButton != null && closeButton.isVisible()) { closeButton.setLocation(offset, 0); offset += getHeight() + 1; } if (minimizeButton != null && minimizeButton.isVisible()) { minimizeButton.setLocation(offset, 0); offset += getHeight() + 1; } if (restoreButton != null && restoreButton.isVisible()) { restoreButton.setLocation(offset, 0); offset += getHeight() + 1; } } else { if (closeButton != null && closeButton.isVisible()) { closeButton.setLocation(getWidth() - closeButton.getSize().x - offset, 0); offset += getHeight() + 1 + closeButton.getSize().x; } if (restoreButton != null && restoreButton.isVisible()) { restoreButton.setLocation(getWidth() - offset, 0); offset += getHeight() + 1; } if (minimizeButton != null && minimizeButton.isVisible()) { minimizeButton.setLocation(getWidth() - offset, 0); offset += getHeight() + 1; } } }
public Image getCheckedImage(Display display, Label l, ArrayList<Mesh> meshes, Rectangle r) { Point p = l.getSize(); Point c = new Point(r.width / 2, r.height / 2); Image image = new Image(display, p.x - 20, p.y - 20); GC gc = new GC(image); gc.drawLine((int) beginX, (int) beginY, (int) endX, (int) endY); // gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); // gc.fillOval(0, 0, p.x-20, p.y-20); // gc.setForeground(display.getSystemColor(SWT.COLOR_DARK_GREEN)); // gc.drawLine(0, 0, p.x-20, p.y-20); // gc.drawLine(p.x-20, 0, 0, p.y-20); gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); for (int i = 0; i < meshes.size(); i++) { drawMesh(meshes.get(i), gc, c); } gc.dispose(); return image; }
@Override public Control contribute(Composite parent) { Composite result = new Composite(parent, SWT.INHERIT_DEFAULT); result.setLayout(new FormLayout()); Label separator = new Label(result, SWT.NONE); separator.setData(RWT.CUSTOM_VARIANT, "footer_separator"); FormData separatorData = new FormData(); separator.setLayoutData(separatorData); separatorData.top = new FormAttachment(0, 0); separatorData.left = new FormAttachment(0, 0); separatorData.right = new FormAttachment(100, 0); separatorData.height = SEPARATOR_HEIGHT; Label versionInfo = new Label(result, SWT.NONE); versionInfo.setText(getVersionInfo()); versionInfo.pack(); FormData versionInfoData = new FormData(); versionInfo.setLayoutData(versionInfoData); Point size = versionInfo.getSize(); versionInfoData.top = new FormAttachment(50, -(size.y / 2) + (SEPARATOR_HEIGHT / 2)); versionInfoData.left = new FormAttachment(50, -(size.x / 2)); return result; }
@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); } }
/** Set the layout of widgets depending on whether the details are being shown or not. */ protected void setLayout() { // error icon FormData data = new FormData(); data.top = new FormAttachment(0, Settings.MARGIN_TOP); data.left = new FormAttachment(0, Settings.MARGIN_LEFT); data.height = 32; data.width = 32; errorIcon.setLayoutData(data); if (showDetails) { Point curSL; // error message label curSL = errorMessage.getSize(); data = new FormData(); data.top = new FormAttachment(0, Settings.MARGIN_TOP); data.left = new FormAttachment(0, Settings.MARGIN_LEFT + 32 + Settings.ITEM_SPACING_H); data.right = new FormAttachment(100, -Settings.MARGIN_RIGHT); data.height = curSL.y; errorMessage.setLayoutData(data); // the OK button data = new FormData(); curSL = okButton.getLocation(); data.top = new FormAttachment(0, curSL.y); data.right = new FormAttachment( 100, -Settings.MARGIN_RIGHT - Settings.BUTTON_WIDTH - Settings.ITEM_SPACING_H); data.height = Settings.BUTTON_HEIGHT; data.width = Settings.BUTTON_WIDTH; okButton.setLayoutData(data); // the Details button data = new FormData(); curSL = okButton.getLocation(); data.top = new FormAttachment(0, curSL.y); data.right = new FormAttachment(100, -Settings.MARGIN_RIGHT); data.height = Settings.BUTTON_HEIGHT; data.width = Settings.BUTTON_WIDTH; detailsButton.setLayoutData(data); // stack trace data = new FormData(); curSL = okButton.getLocation(); data.top = new FormAttachment(0, curSL.y + Settings.BUTTON_HEIGHT + Settings.ITEM_SPACING_V); data.left = new FormAttachment(0, Settings.MARGIN_LEFT); data.right = new FormAttachment(100, -Settings.MARGIN_RIGHT); data.bottom = new FormAttachment(100, -Settings.MARGIN_BOTTOM); stackTrace.setLayoutData(data); // if details have been switched on increase the window height if (detailsSwitched) { curSL = shell.getSize(); shell.setSize(curSL.x, curSL.y + detailsHeight + Settings.ITEM_SPACING_V); } } else { // if details have been switched off, decrease the window height if (detailsSwitched) { // remember last stack trace window height detailsHeight = stackTrace.getSize().y; Point curSL = shell.getSize(); shell.setSize(curSL.x, curSL.y - detailsHeight - Settings.ITEM_SPACING_V); } // error message label data = new FormData(); data.top = new FormAttachment(0, Settings.MARGIN_TOP); data.left = new FormAttachment(0, Settings.MARGIN_LEFT + 32 + Settings.ITEM_SPACING_H); data.right = new FormAttachment(100, -Settings.MARGIN_RIGHT); data.bottom = new FormAttachment( 100 - Settings.MARGIN_BOTTOM - Settings.BUTTON_HEIGHT - Settings.ITEM_SPACING_V); errorMessage.setLayoutData(data); // the OK button data = new FormData(); data.bottom = new FormAttachment(100, -Settings.MARGIN_BOTTOM); data.right = new FormAttachment( 100, -Settings.MARGIN_RIGHT - Settings.BUTTON_WIDTH - Settings.ITEM_SPACING_H); data.height = Settings.BUTTON_HEIGHT; data.width = Settings.BUTTON_WIDTH; okButton.setLayoutData(data); // the Details button data = new FormData(); data.bottom = new FormAttachment(100, -Settings.MARGIN_BOTTOM); data.right = new FormAttachment(100, -Settings.MARGIN_RIGHT); data.height = Settings.BUTTON_HEIGHT; data.width = Settings.BUTTON_WIDTH; detailsButton.setLayoutData(data); // stack trace (hidden) data = new FormData(); data.top = new FormAttachment(100, 1); data.height = detailsHeight; stackTrace.setLayoutData(data); } }