@Override public void controlResized(final ControlEvent e) { final Rectangle area = this.parent.getClientArea(); final Point size = this.table.computeSize(SWT.DEFAULT, SWT.DEFAULT); final ScrollBar vBar = this.table.getVerticalBar(); int width = area.width - this.table.computeTrim(0, 0, 0, 0).width - vBar.getSize().x - this.usedWidth; if (size.y > area.height + this.table.getHeaderHeight()) { // Subtract the scrollbar width from the total column width // if a vertical scrollbar will be required final Point vBarSize = vBar.getSize(); width -= vBarSize.x; } final Point oldSize = this.table.getSize(); if (oldSize.x > area.width) { // table is getting smaller so make the columns // smaller first and then resize the table to // match the client area width this.column.setWidth(width); this.table.setSize(area.width, area.height); } else { // table is getting bigger so make the table // bigger first and then make the columns wider // to match the client area width this.table.setSize(area.width, area.height); this.column.setWidth(width); } }
public MatchPlayersGroup(Composite parent, int style) { super(parent, style & ~SWT.BORDER); this.setLayout(new FormLayout()); FormData formData; this.setText(Messages.getString("team")); this.setForeground(Colors.getBlueDescription()); this.setFont(ConfigBean.getFontMain()); matchPlayersTable = new MatchPlayersTable(this, SWT.FULL_SELECTION); ScrollBar bar = matchPlayersTable.getVerticalBar(); formData = new FormData(); formData.left = new FormAttachment(0, bar.getSize().x); formData.top = new FormAttachment(0, 5); formData.bottom = new FormAttachment(100, -5); formData.right = new FormAttachment(100, -5); matchPlayersTable.setLayoutData(formData); }
private Control createSyntaxPage(final Composite parent) { Composite colorComposite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; colorComposite.setLayout(layout); Link link = new Link(colorComposite, SWT.NONE); link.setText(PreferencesMessages.CEditorColoringConfigurationBlock_link); link.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null); } }); // TODO replace by link-specific tooltips when // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88866 gets fixed // link.setToolTipText(PreferencesMessages.CEditorColoringConfigurationBlock_link_tooltip); GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); gridData.widthHint = 150; // only expand further if anyone else requires it gridData.horizontalSpan = 2; link.setLayoutData(gridData); addFiller(colorComposite, 1); fEnableSemanticHighlightingCheckbox = addCheckBox( colorComposite, PreferencesMessages.CEditorColoringConfigurationBlock_enable_semantic_highlighting, PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED, 0); Label label; label = new Label(colorComposite, SWT.LEFT); label.setText(PreferencesMessages.CEditorColoringConfigurationBlock_coloring_element); label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Composite editorComposite = new Composite(colorComposite, SWT.NONE); layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; editorComposite.setLayout(layout); GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false); editorComposite.setLayoutData(gd); fListViewer = new TreeViewer(editorComposite, SWT.SINGLE | SWT.BORDER); fListViewer.setLabelProvider(new ColorListLabelProvider()); fListViewer.setContentProvider(new ColorListContentProvider()); fListViewer.setSorter( new ViewerSorter() { @Override public int category(Object element) { // don't sort the top level categories if (fCodeCategory.equals(element)) return 0; if (fAssemblyCategory.equals(element)) return 1; if (fCommentsCategory.equals(element)) return 2; if (fPreprocessorCategory.equals(element)) return 3; if (fDoxygenCategory.equals(element)) return 4; return 0; } }); gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true); gd.heightHint = convertHeightInCharsToPixels(9); int maxWidth = 0; for (HighlightingColorListItem item : fListModel) { maxWidth = Math.max(maxWidth, convertWidthInCharsToPixels(item.getDisplayName().length())); } ScrollBar vBar = ((Scrollable) fListViewer.getControl()).getVerticalBar(); if (vBar != null) maxWidth += vBar.getSize().x * 3; // scrollbars and tree indentation guess gd.widthHint = maxWidth; fListViewer.getControl().setLayoutData(gd); Composite stylesComposite = new Composite(editorComposite, SWT.NONE); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.numColumns = 2; stylesComposite.setLayout(layout); stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); fEnableCheckbox = new Button(stylesComposite, SWT.CHECK); fEnableCheckbox.setText(PreferencesMessages.CEditorColoringConfigurationBlock_enable); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.BEGINNING; gd.horizontalSpan = 2; fEnableCheckbox.setLayoutData(gd); fColorEditorLabel = new Label(stylesComposite, SWT.LEFT); fColorEditorLabel.setText(PreferencesMessages.CEditorColoringConfigurationBlock_color); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent = 20; fColorEditorLabel.setLayoutData(gd); fSyntaxForegroundColorEditor = new ColorSelector(stylesComposite); Button foregroundColorButton = fSyntaxForegroundColorEditor.getButton(); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); foregroundColorButton.setLayoutData(gd); fBoldCheckBox = new Button(stylesComposite, SWT.CHECK); fBoldCheckBox.setText(PreferencesMessages.CEditorColoringConfigurationBlock_bold); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent = 20; gd.horizontalSpan = 2; fBoldCheckBox.setLayoutData(gd); fItalicCheckBox = new Button(stylesComposite, SWT.CHECK); fItalicCheckBox.setText(PreferencesMessages.CEditorColoringConfigurationBlock_italic); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent = 20; gd.horizontalSpan = 2; fItalicCheckBox.setLayoutData(gd); fStrikethroughCheckBox = new Button(stylesComposite, SWT.CHECK); fStrikethroughCheckBox.setText( PreferencesMessages.CEditorColoringConfigurationBlock_strikethrough); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent = 20; gd.horizontalSpan = 2; fStrikethroughCheckBox.setLayoutData(gd); fUnderlineCheckBox = new Button(stylesComposite, SWT.CHECK); fUnderlineCheckBox.setText(PreferencesMessages.CEditorColoringConfigurationBlock_underline); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent = 20; gd.horizontalSpan = 2; fUnderlineCheckBox.setLayoutData(gd); label = new Label(colorComposite, SWT.LEFT); label.setText(PreferencesMessages.CEditorColoringConfigurationBlock_preview); label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Control previewer = createPreviewer(colorComposite); gd = new GridData(GridData.FILL_BOTH); gd.widthHint = convertWidthInCharsToPixels(20); gd.heightHint = convertHeightInCharsToPixels(5); previewer.setLayoutData(gd); fListViewer.addSelectionChangedListener( new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { handleSyntaxColorListSelection(); } }); foregroundColorButton.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { // do nothing } @Override public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item = getHighlightingColorListItem(); PreferenceConverter.setValue( getPreferenceStore(), item.getColorKey(), fSyntaxForegroundColorEditor.getColorValue()); } }); fBoldCheckBox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { // do nothing } @Override public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item = getHighlightingColorListItem(); getPreferenceStore().setValue(item.getBoldKey(), fBoldCheckBox.getSelection()); } }); fItalicCheckBox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { // do nothing } @Override public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item = getHighlightingColorListItem(); getPreferenceStore().setValue(item.getItalicKey(), fItalicCheckBox.getSelection()); } }); fStrikethroughCheckBox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { // do nothing } @Override public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item = getHighlightingColorListItem(); getPreferenceStore() .setValue(item.getStrikethroughKey(), fStrikethroughCheckBox.getSelection()); } }); fUnderlineCheckBox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { // do nothing } @Override public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item = getHighlightingColorListItem(); getPreferenceStore() .setValue(item.getUnderlineKey(), fUnderlineCheckBox.getSelection()); } }); fEnableCheckbox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { // do nothing } @Override public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item = getHighlightingColorListItem(); if (item instanceof SemanticHighlightingColorListItem) { boolean enable = fEnableCheckbox.getSelection(); getPreferenceStore() .setValue(((SemanticHighlightingColorListItem) item).getEnableKey(), enable); fEnableCheckbox.setSelection(enable); fSyntaxForegroundColorEditor.getButton().setEnabled(enable); fColorEditorLabel.setEnabled(enable); fBoldCheckBox.setEnabled(enable); fItalicCheckBox.setEnabled(enable); fStrikethroughCheckBox.setEnabled(enable); fUnderlineCheckBox.setEnabled(enable); uninstallSemanticHighlighting(); installSemanticHighlighting(); } } }); fEnableSemanticHighlightingCheckbox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { // do nothing } @Override public void widgetSelected(SelectionEvent e) { fListViewer.refresh(true); HighlightingColorListItem item = getHighlightingColorListItem(); if (item instanceof SemanticHighlightingColorListItem) { handleSyntaxColorListSelection(); uninstallSemanticHighlighting(); installSemanticHighlighting(); } } }); colorComposite.layout(false); return colorComposite; }
protected void layout(Composite composite, boolean flushCache) { if (inLayout) { return; } ScrolledComposite sc = (ScrolledComposite) composite; if (sc.content == null) { return; } ScrollBar hBar = sc.getHorizontalBar(); ScrollBar vBar = sc.getVerticalBar(); if (hBar != null) { if (hBar.getSize().y >= sc.getSize().y) { return; } } if (vBar != null) { if (vBar.getSize().x >= sc.getSize().x) { return; } } inLayout = true; Rectangle contentRect = sc.content.getBounds(); if (!sc.alwaysShowScroll) { boolean hVisible = sc.needHScroll(contentRect, false); boolean vVisible = sc.needVScroll(contentRect, hVisible); if (!hVisible && vVisible) { hVisible = sc.needHScroll(contentRect, vVisible); } if (hBar != null) { hBar.setVisible(hVisible); } if (vBar != null) { vBar.setVisible(vVisible); } } Rectangle hostRect = sc.getClientArea(); if (sc.expandHorizontal) { contentRect.width = Math.max(sc.minWidth, hostRect.width); } if (sc.expandVertical) { contentRect.height = Math.max(sc.minHeight, hostRect.height); } if (hBar != null) { hBar.setMaximum(contentRect.width); hBar.setThumb(Math.min(contentRect.width, hostRect.width)); int hPage = contentRect.width - hostRect.width; int hSelection = hBar.getSelection(); if (hSelection >= hPage) { if (hPage <= 0) { hSelection = 0; hBar.setSelection(0); } contentRect.x = -hSelection; } } if (vBar != null) { vBar.setMaximum(contentRect.height); vBar.setThumb(Math.min(contentRect.height, hostRect.height)); int vPage = contentRect.height - hostRect.height; int vSelection = vBar.getSelection(); if (vSelection >= vPage) { if (vPage <= 0) { vSelection = 0; vBar.setSelection(0); } contentRect.y = -vSelection; } } sc.content.setBounds(contentRect); inLayout = false; }
private Control createSyntaxPage(final Composite parent) { final Composite colorComposite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; colorComposite.setLayout(layout); final Link link = new Link(colorComposite, SWT.NONE); link.setText(PreferencesMessages.ErlEditorColoringConfigurationBlock_link); link.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null); } }); final GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); gridData.widthHint = 150; gridData.horizontalSpan = 2; link.setLayoutData(gridData); addFiller(colorComposite, 1); Label label; label = new Label(colorComposite, SWT.LEFT); label.setText(PreferencesMessages.ErlEditorPreferencePage_coloring_element); label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Composite editorComposite = new Composite(colorComposite, SWT.NONE); layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; editorComposite.setLayout(layout); GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false); editorComposite.setLayoutData(gd); fListViewer = new TreeViewer(editorComposite, SWT.SINGLE | SWT.BORDER); final Tree tree = fListViewer.getTree(); final GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1); gd_tree.widthHint = 100; tree.setLayoutData(gd_tree); fListViewer.setLabelProvider(new ColorListLabelProvider()); fListViewer.setContentProvider(new ColorListContentProvider()); fListViewer.setInput(fColors); fListViewer.setSelection(new StructuredSelection(fErlangCategory)); fListViewer.setSorter( new ViewerSorter() { @Override public int category(final Object element) { // don't sort the top level categories if (fErlangCategory.equals(element)) { return 0; } // if (fEdocCategory.equals(element)) { // return 1; // } // to sort semantic settings after partition based ones: // if (element instanceof SemanticHighlightingColorListItem) // return 1; return 0; } }); gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true); gd.heightHint = convertHeightInCharsToPixels(9); int maxWidth = 0; for (final TokenHighlight item : fColors.keySet()) { maxWidth = Math.max(maxWidth, convertWidthInCharsToPixels(item.getName().length())); } final ScrollBar vBar = ((Scrollable) fListViewer.getControl()).getVerticalBar(); if (vBar != null) { maxWidth += vBar.getSize().x * 3; // scrollbars and tree } // indentation guess gd.widthHint = maxWidth; fListViewer.getControl().setLayoutData(gd); fListViewer.expandAll(); final Composite stylesComposite = new Composite(editorComposite, SWT.NONE); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.numColumns = 2; stylesComposite.setLayout(layout); stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); fEnableCheckbox = new Button(stylesComposite, SWT.CHECK); fEnableCheckbox.setText(PreferencesMessages.ErlEditorPreferencePage_enable); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.BEGINNING; gd.horizontalSpan = 2; fEnableCheckbox.setLayoutData(gd); // TODO hide this until reworking the dialog fEnableCheckbox.setVisible(false); fColorEditorLabel = new Label(stylesComposite, SWT.LEFT); fColorEditorLabel.setText(PreferencesMessages.ErlEditorPreferencePage_color); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent = 20; fColorEditorLabel.setLayoutData(gd); fSyntaxForegroundColorEditor = new ColorSelector(stylesComposite); final Button foregroundColorButton = fSyntaxForegroundColorEditor.getButton(); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); foregroundColorButton.setLayoutData(gd); new Label(stylesComposite, SWT.NONE); fBoldCheckBox = new Button(stylesComposite, SWT.CHECK); fBoldCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_bold); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent = 20; gd.horizontalSpan = 2; fBoldCheckBox.setLayoutData(gd); fItalicCheckBox = new Button(stylesComposite, SWT.CHECK); fItalicCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_italic); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent = 20; gd.horizontalSpan = 2; fItalicCheckBox.setLayoutData(gd); fStrikethroughCheckBox = new Button(stylesComposite, SWT.CHECK); fStrikethroughCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_strikeout); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent = 20; gd.horizontalSpan = 2; fStrikethroughCheckBox.setLayoutData(gd); fUnderlineCheckBox = new Button(stylesComposite, SWT.CHECK); fUnderlineCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_underline); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent = 20; gd.horizontalSpan = 2; fUnderlineCheckBox.setLayoutData(gd); label = new Label(colorComposite, SWT.LEFT); label.setText( PreferencesMessages.ErlEditorPreferencePage_preview + "\n - Currently the preview doesn't work, but this dialog does." + "\n - Open files need to be reopened to refresh the coloring."); label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); final String content = loadPreviewContentFromFile(getClass(), "ColorSettingPreviewCode.txt"); // $NON-NLS-1$ fPreviewViewer = createErlangPreviewer(colorComposite, fColorManager, fColors, content); final Control previewer = fPreviewViewer.getControl(); gd = new GridData(GridData.FILL_BOTH); gd.widthHint = convertWidthInCharsToPixels(20); gd.heightHint = convertHeightInCharsToPixels(5); gd.grabExcessHorizontalSpace = true; previewer.setLayoutData(gd); fListViewer.addSelectionChangedListener( new ISelectionChangedListener() { @Override public void selectionChanged(final SelectionChangedEvent event) { handleSyntaxColorListSelection(); } }); foregroundColorButton.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(final SelectionEvent e) { // do nothing } @Override public void widgetSelected(final SelectionEvent e) { final TokenHighlight item = getHighlight(); final HighlightStyle data = fColors.get(item); if (data == null) { return; } data.setColor(fSyntaxForegroundColorEditor.getColorValue()); fPreviewViewer.invalidateTextPresentation(); } }); fBoldCheckBox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(final SelectionEvent e) { // do nothing } @Override public void widgetSelected(final SelectionEvent e) { final TokenHighlight item = getHighlight(); final HighlightStyle data = fColors.get(item); if (data == null) { return; } data.setStyle(SWT.BOLD, fBoldCheckBox.getSelection()); fPreviewViewer.invalidateTextPresentation(); } }); fItalicCheckBox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(final SelectionEvent e) { // do nothing } @Override public void widgetSelected(final SelectionEvent e) { final TokenHighlight item = getHighlight(); final HighlightStyle data = fColors.get(item); if (data == null) { return; } data.setStyle(SWT.ITALIC, fItalicCheckBox.getSelection()); fPreviewViewer.invalidateTextPresentation(); } }); fStrikethroughCheckBox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(final SelectionEvent e) { // do nothing } @Override public void widgetSelected(final SelectionEvent e) { final TokenHighlight item = getHighlight(); final HighlightStyle data = fColors.get(item); if (data == null) { return; } data.setStyle(TextAttribute.STRIKETHROUGH, fStrikethroughCheckBox.getSelection()); fPreviewViewer.invalidateTextPresentation(); } }); fUnderlineCheckBox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(final SelectionEvent e) { // do nothing } @Override public void widgetSelected(final SelectionEvent e) { final TokenHighlight item = getHighlight(); final HighlightStyle data = fColors.get(item); if (data == null) { return; } data.setStyle(TextAttribute.UNDERLINE, fUnderlineCheckBox.getSelection()); fPreviewViewer.invalidateTextPresentation(); } }); fEnableCheckbox.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(final SelectionEvent e) { // do nothing } @Override public void widgetSelected(final SelectionEvent e) { fEnableCheckbox.setSelection(true); // final TokenHighlight item = getHighlight(); // if (item instanceof SemanticHighlightingColorListItem) { // final boolean enable = fEnableCheckbox.getSelection(); // getPreferenceStore().setValue( // ((SemanticHighlightingColorListItem) item) // .getEnableKey(), enable); // fEnableCheckbox.setSelection(enable); // fSyntaxForegroundColorEditor.getButton().setEnabled(enable); // fColorEditorLabel.setEnabled(enable); // fBoldCheckBox.setEnabled(enable); // fItalicCheckBox.setEnabled(enable); // fStrikethroughCheckBox.setEnabled(enable); // fUnderlineCheckBox.setEnabled(enable); // } } }); colorComposite.layout(false); return colorComposite; }