Search in sources :

Example 51 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class TmDbManagerDialog method setShellSize.

/**
	 * Changes the shell size to the given size, ensuring that it is no larger than the display bounds.
	 * @param width
	 *            the shell width
	 * @param height
	 *            the shell height
	 */
private void setShellSize(int width, int height) {
    Rectangle preferred = getShell().getBounds();
    preferred.width = width;
    preferred.height = height;
    getShell().setBounds(getConstrainedShellBounds(preferred));
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 52 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class TextPainterWithPadding method getCellTextLayout.

private TextLayout getCellTextLayout(LayerCell cell) {
    int orientation = editor.getTable().getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
    TextLayout layout = new TextLayout(editor.getTable().getDisplay());
    layout.setOrientation(orientation);
    layout.setSpacing(Constants.SEGMENT_LINE_SPACING);
    layout.setFont(font);
    layout.setAscent(ascent);
    // 和 StyledTextEditor 同步
    layout.setDescent(descent);
    layout.setTabs(new int[] { tabWidth });
    Rectangle rectangle = cell.getBounds();
    int width = rectangle.width - leftPadding - rightPadding;
    width -= 1;
    if (wrapText && width > 0) {
        layout.setWidth(width);
    }
    String displayText = InnerTagUtil.resolveTag(innerTagFactory.parseInnerTag((String) cell.getDataValue()));
    if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
        displayText = displayText.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
        displayText = displayText.replaceAll("\\t", Constants.TAB_CHARACTER + "​");
        displayText = displayText.replaceAll(" ", Constants.SPACE_CHARACTER + "​");
    }
    layout.setText(displayText);
    List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
    for (InnerTagBean innerTagBean : innerTagBeans) {
        String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
        int start = displayText.indexOf(placeHolder);
        if (start == -1) {
            continue;
        }
        TextStyle style = new TextStyle();
        Point rect = tagRender.calculateTagSize(innerTagBean);
        style.metrics = new GlyphMetrics(rect.y, 0, rect.x + SEGMENT_LINE_SPACING * 2);
        layout.setStyle(style, start, start + placeHolder.length() - 1);
    }
    return layout;
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) Rectangle(org.eclipse.swt.graphics.Rectangle) InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 53 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class RTFCleanerDialog method createMenu.

/**
	 * 创建菜单 ;
	 */
private void createMenu() {
    Menu menu = new Menu(getShell(), SWT.BAR);
    getShell().setMenuBar(menu);
    getShell().pack();
    Rectangle screenSize = Display.getDefault().getClientArea();
    Rectangle frameSize = getShell().getBounds();
    getShell().setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    Menu fileMenu = new Menu(menu);
    MenuItem fileItem = new MenuItem(menu, SWT.CASCADE);
    fileItem.setMenu(fileMenu);
    fileItem.setText(Messages.getString("dialog.RTFCleanerDialog.fileMenu"));
    MenuItem addStylesItem = new MenuItem(fileMenu, SWT.PUSH);
    addStylesItem.setText(Messages.getString("dialog.RTFCleanerDialog.addStylesItem"));
    addStylesItem.setImage(new Image(Display.getDefault(), PluginUtil.getAbsolutePath(PluginConstants.PIC_OPEN_CSV_PATH)));
    addStylesItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            handleFile();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    new MenuItem(fileMenu, SWT.SEPARATOR);
    MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
    exitItem.setText(Messages.getString("dialog.RTFCleanerDialog.exitItem"));
    exitItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            close();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) Image(org.eclipse.swt.graphics.Image) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 54 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class JavaPropertiesViewerDialog method createMenu.

private void createMenu(Composite tparent) {
    Menu menuBar = new Menu(getShell(), SWT.BAR);
    getShell().setMenuBar(menuBar);
    getShell().pack();
    Rectangle screenSize = Display.getDefault().getClientArea();
    Rectangle frameSize = getShell().getBounds();
    getShell().setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    // 文件菜单
    Menu fileMenu = new Menu(menuBar);
    MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE);
    fileItem.setText(Messages.getString("dialog.JavaPropertiesViewerDialog.fileMenu"));
    fileItem.setMenu(fileMenu);
    MenuItem openFileItem = new MenuItem(fileMenu, SWT.PUSH);
    openFileItem.setText(Messages.getString("dialog.JavaPropertiesViewerDialog.openFileItem"));
    openFileItem.setImage(new Image(Display.getDefault(), openFilePath));
    openFileItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            openFile();
        }
    });
    new MenuItem(fileMenu, SWT.SEPARATOR);
    MenuItem quitItem = new MenuItem(fileMenu, SWT.PUSH);
    quitItem.setText(Messages.getString("dialog.JavaPropertiesViewerDialog.quitItem"));
    quitItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            close();
        }
    });
    // 帮助菜单
    Menu helpMenu = new Menu(menuBar);
    MenuItem helpItem = new MenuItem(menuBar, SWT.CASCADE);
    helpItem.setText(Messages.getString("dialog.JavaPropertiesViewerDialog.helpMenu"));
    helpItem.setMenu(helpMenu);
    MenuItem aboutItem = new MenuItem(helpMenu, SWT.PUSH);
    aboutItem.setText(Messages.getString("dialog.JavaPropertiesViewerDialog.aboutItem"));
    String aboutPath = PluginUtil.getAbsolutePath(PluginConstants.LOGO_PROERTIESVIEWER_MENU_PATH);
    aboutItem.setImage(new Image(Display.getDefault(), aboutPath));
    aboutItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            AboutDialog dialog = new AboutDialog(getShell(), Messages.getString("dialog.JavaPropertiesViewerDialog.aboutItemName"), imagePath, Messages.getString("dialog.JavaPropertiesViewerDialog.version"));
            dialog.open();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) Image(org.eclipse.swt.graphics.Image) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 55 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class Martif2TBXConverterDialog method createMenu.

/**
	 * 创建菜单 ;
	 */
private void createMenu() {
    Menu menu = new Menu(getShell(), SWT.BAR);
    getShell().setMenuBar(menu);
    getShell().pack();
    Rectangle screenSize = Display.getDefault().getClientArea();
    Rectangle frameSize = getShell().getBounds();
    getShell().setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    Menu fileMenu = new Menu(menu);
    MenuItem fileItem = new MenuItem(menu, SWT.CASCADE);
    fileItem.setText(Messages.getString("dialog.Martif2TBXConverterDialog.fileMenu"));
    fileItem.setMenu(fileMenu);
    MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
    exitItem.setText(Messages.getString("dialog.Martif2TBXConverterDialog.exitItem"));
    exitItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            close();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    Menu helpMenu = new Menu(menu);
    MenuItem helpItem = new MenuItem(menu, SWT.CASCADE);
    helpItem.setText(Messages.getString("dialog.Martif2TBXConverterDialog.helpMenu"));
    helpItem.setMenu(helpMenu);
    MenuItem aboutItem = new MenuItem(helpMenu, SWT.PUSH);
    aboutItem.setText(Messages.getString("dialog.Martif2TBXConverterDialog.aboutItem"));
    String imgPath = PluginUtil.getAbsolutePath(PluginConstants.LOGO_MARTIF2TBX_MENU_PATH);
    aboutItem.setImage(new Image(Display.getDefault(), imgPath));
    aboutItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            AboutDialog dialog = new AboutDialog(getShell(), Messages.getString("dialog.Martif2TBXConverterDialog.dialogName"), imagePath, Messages.getString("dialog.Martif2TBXConverterDialog.dialogVersion"));
            dialog.open();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) Image(org.eclipse.swt.graphics.Image) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

Rectangle (org.eclipse.swt.graphics.Rectangle)651 Point (org.eclipse.swt.graphics.Point)370 Image (org.eclipse.swt.graphics.Image)114 GC (org.eclipse.swt.graphics.GC)104 Test (org.junit.Test)80 Color (org.eclipse.swt.graphics.Color)61 Shell (org.eclipse.swt.widgets.Shell)54 Composite (org.eclipse.swt.widgets.Composite)53 SelectionEvent (org.eclipse.swt.events.SelectionEvent)51 TableItem (org.eclipse.swt.widgets.TableItem)47 GridLayout (org.eclipse.swt.layout.GridLayout)44 Display (org.eclipse.swt.widgets.Display)44 Button (org.eclipse.swt.widgets.Button)42 Menu (org.eclipse.swt.widgets.Menu)40 GridData (org.eclipse.swt.layout.GridData)38 Label (org.eclipse.swt.widgets.Label)37 SWT (org.eclipse.swt.SWT)34 Event (org.eclipse.swt.widgets.Event)34 Font (org.eclipse.swt.graphics.Font)30 Listener (org.eclipse.swt.widgets.Listener)29