use of org.eclipse.swt.widgets.CoolBar in project eclipse.platform.swt by eclipse.
the class Tab method refreshLayoutComposite.
/**
* Refreshes the composite and draws all controls
* in the layout example.
*/
void refreshLayoutComposite() {
/* Remove children that are already laid out */
children = layoutComposite.getChildren();
for (Control child : children) {
child.dispose();
}
/* Add all children listed in the table */
TableItem[] items = table.getItems();
children = new Control[items.length];
String[] itemValues = new String[] { LayoutExample.getResourceString("Item", new String[] { "1" }), LayoutExample.getResourceString("Item", new String[] { "2" }), LayoutExample.getResourceString("Item", new String[] { "3" }) };
for (int i = 0; i < items.length; i++) {
String control = items[i].getText(1);
String controlName = items[i].getText(0);
if (control.equals("Button")) {
Button button = new Button(layoutComposite, SWT.PUSH);
button.setText(controlName);
children[i] = button;
} else if (control.equals("Canvas")) {
Canvas canvas = new Canvas(layoutComposite, SWT.BORDER);
children[i] = canvas;
} else if (control.equals("Combo")) {
Combo combo = new Combo(layoutComposite, SWT.NONE);
combo.setItems(itemValues);
combo.setText(controlName);
children[i] = combo;
} else if (control.equals("Composite")) {
Composite composite = new Composite(layoutComposite, SWT.BORDER);
children[i] = composite;
} else if (control.equals("CoolBar")) {
CoolBar coolBar = new CoolBar(layoutComposite, SWT.NONE);
ToolBar toolBar = new ToolBar(coolBar, SWT.BORDER);
ToolItem item = new ToolItem(toolBar, 0);
item.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
item = new ToolItem(toolBar, 0);
item.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
CoolItem coolItem1 = new CoolItem(coolBar, 0);
coolItem1.setControl(toolBar);
toolBar = new ToolBar(coolBar, SWT.BORDER);
item = new ToolItem(toolBar, 0);
item.setText(LayoutExample.getResourceString("Item", new String[] { "3" }));
item = new ToolItem(toolBar, 0);
item.setText(LayoutExample.getResourceString("Item", new String[] { "4" }));
CoolItem coolItem2 = new CoolItem(coolBar, 0);
coolItem2.setControl(toolBar);
Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
coolItem1.setSize(coolItem1.computeSize(size.x, size.y));
coolItem2.setSize(coolItem2.computeSize(size.x, size.y));
coolBar.setSize(coolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT));
children[i] = coolBar;
} else if (control.equals("Group")) {
Group group = new Group(layoutComposite, SWT.NONE);
group.setText(controlName);
children[i] = group;
} else if (control.equals("Label")) {
Label label = new Label(layoutComposite, SWT.NONE);
label.setText(controlName);
children[i] = label;
} else if (control.equals("Link")) {
Link link = new Link(layoutComposite, SWT.NONE);
link.setText(controlName);
children[i] = link;
} else if (control.equals("List")) {
org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(layoutComposite, SWT.BORDER);
list.setItems(itemValues);
children[i] = list;
} else if (control.equals("ProgressBar")) {
ProgressBar progress = new ProgressBar(layoutComposite, SWT.NONE);
progress.setSelection(50);
children[i] = progress;
} else if (control.equals("Scale")) {
Scale scale = new Scale(layoutComposite, SWT.NONE);
children[i] = scale;
} else if (control.equals("Slider")) {
Slider slider = new Slider(layoutComposite, SWT.NONE);
children[i] = slider;
} else if (control.equals("StyledText")) {
StyledText styledText = new StyledText(layoutComposite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
styledText.setText(controlName);
children[i] = styledText;
} else if (control.equals("Table")) {
Table table = new Table(layoutComposite, SWT.BORDER);
table.setLinesVisible(true);
TableItem item1 = new TableItem(table, 0);
item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
TableItem item2 = new TableItem(table, 0);
item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
children[i] = table;
} else if (control.equals("Text")) {
Text text = new Text(layoutComposite, SWT.BORDER);
text.setText(controlName);
children[i] = text;
} else if (control.equals("ToolBar")) {
ToolBar toolBar = new ToolBar(layoutComposite, SWT.BORDER);
ToolItem item1 = new ToolItem(toolBar, 0);
item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
ToolItem item2 = new ToolItem(toolBar, 0);
item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
children[i] = toolBar;
} else {
Tree tree = new Tree(layoutComposite, SWT.BORDER);
TreeItem item1 = new TreeItem(tree, 0);
item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
TreeItem item2 = new TreeItem(tree, 0);
item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
children[i] = tree;
}
}
}
use of org.eclipse.swt.widgets.CoolBar in project eclipse.platform.swt by eclipse.
the class TextEditor method createToolBar.
void createToolBar() {
coolBar = new CoolBar(shell, SWT.FLAT);
ToolBar styleToolBar = new ToolBar(coolBar, SWT.FLAT);
boldControl = new ToolItem(styleToolBar, SWT.CHECK);
boldControl.setImage(iBold);
// $NON-NLS-1$
boldControl.setToolTipText(getResourceString("Bold"));
boldControl.addSelectionListener(widgetSelectedAdapter(event -> setStyle(BOLD)));
italicControl = new ToolItem(styleToolBar, SWT.CHECK);
italicControl.setImage(iItalic);
// $NON-NLS-1$
italicControl.setToolTipText(getResourceString("Italic"));
italicControl.addSelectionListener(widgetSelectedAdapter(event -> setStyle(ITALIC)));
final Menu underlineMenu = new Menu(shell, SWT.POP_UP);
underlineSingleItem = new MenuItem(underlineMenu, SWT.RADIO);
// $NON-NLS-1$
underlineSingleItem.setText(getResourceString("Single_menuitem"));
underlineSingleItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (underlineSingleItem.getSelection()) {
setStyle(UNDERLINE_SINGLE);
}
}));
underlineSingleItem.setSelection(true);
underlineDoubleItem = new MenuItem(underlineMenu, SWT.RADIO);
// $NON-NLS-1$
underlineDoubleItem.setText(getResourceString("Double_menuitem"));
underlineDoubleItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (underlineDoubleItem.getSelection()) {
setStyle(UNDERLINE_DOUBLE);
}
}));
underlineSquiggleItem = new MenuItem(underlineMenu, SWT.RADIO);
// $NON-NLS-1$
underlineSquiggleItem.setText(getResourceString("Squiggle_menuitem"));
underlineSquiggleItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (underlineSquiggleItem.getSelection()) {
setStyle(UNDERLINE_SQUIGGLE);
}
}));
underlineErrorItem = new MenuItem(underlineMenu, SWT.RADIO);
// $NON-NLS-1$
underlineErrorItem.setText(getResourceString("Error_menuitem"));
underlineErrorItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (underlineErrorItem.getSelection()) {
setStyle(UNDERLINE_ERROR);
}
}));
MenuItem underlineColorItem = new MenuItem(underlineMenu, SWT.PUSH);
// $NON-NLS-1$
underlineColorItem.setText(getResourceString("Color_menuitem"));
underlineColorItem.addSelectionListener(widgetSelectedAdapter(event -> {
ColorDialog dialog = new ColorDialog(shell);
RGB rgb = underlineColor != null ? underlineColor.getRGB() : null;
dialog.setRGB(rgb);
RGB newRgb = dialog.open();
if (newRgb != null) {
if (!newRgb.equals(rgb)) {
disposeResource(underlineColor);
underlineColor = new Color(display, newRgb);
}
if (underlineSingleItem.getSelection())
setStyle(UNDERLINE_SINGLE);
else if (underlineDoubleItem.getSelection())
setStyle(UNDERLINE_DOUBLE);
else if (underlineErrorItem.getSelection())
setStyle(UNDERLINE_ERROR);
else if (underlineSquiggleItem.getSelection())
setStyle(UNDERLINE_SQUIGGLE);
}
}));
final ToolItem underlineControl = new ToolItem(styleToolBar, SWT.DROP_DOWN);
underlineControl.setImage(iUnderline);
// $NON-NLS-1$
underlineControl.setToolTipText(getResourceString("Underline"));
underlineControl.addSelectionListener(widgetSelectedAdapter(event -> {
if (event.detail == SWT.ARROW) {
Rectangle rect = underlineControl.getBounds();
Point pt = new Point(rect.x, rect.y + rect.height);
underlineMenu.setLocation(display.map(underlineControl.getParent(), null, pt));
underlineMenu.setVisible(true);
} else {
if (underlineSingleItem.getSelection())
setStyle(UNDERLINE_SINGLE);
else if (underlineDoubleItem.getSelection())
setStyle(UNDERLINE_DOUBLE);
else if (underlineErrorItem.getSelection())
setStyle(UNDERLINE_ERROR);
else if (underlineSquiggleItem.getSelection())
setStyle(UNDERLINE_SQUIGGLE);
}
}));
ToolItem strikeoutControl = new ToolItem(styleToolBar, SWT.DROP_DOWN);
strikeoutControl.setImage(iStrikeout);
// $NON-NLS-1$
strikeoutControl.setToolTipText(getResourceString("Strikeout"));
strikeoutControl.addSelectionListener(widgetSelectedAdapter(event -> {
if (event.detail == SWT.ARROW) {
ColorDialog dialog = new ColorDialog(shell);
RGB rgb = strikeoutColor != null ? strikeoutColor.getRGB() : null;
dialog.setRGB(rgb);
RGB newRgb = dialog.open();
if (newRgb == null)
return;
if (!newRgb.equals(rgb)) {
disposeResource(strikeoutColor);
strikeoutColor = new Color(display, newRgb);
}
}
setStyle(STRIKEOUT);
}));
final Menu borderMenu = new Menu(shell, SWT.POP_UP);
borderSolidItem = new MenuItem(borderMenu, SWT.RADIO);
// $NON-NLS-1$
borderSolidItem.setText(getResourceString("Solid"));
borderSolidItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (borderSolidItem.getSelection()) {
setStyle(BORDER_SOLID);
}
}));
borderSolidItem.setSelection(true);
borderDashItem = new MenuItem(borderMenu, SWT.RADIO);
// $NON-NLS-1$
borderDashItem.setText(getResourceString("Dash"));
borderDashItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (borderDashItem.getSelection()) {
setStyle(BORDER_DASH);
}
}));
borderDotItem = new MenuItem(borderMenu, SWT.RADIO);
// $NON-NLS-1$
borderDotItem.setText(getResourceString("Dot"));
borderDotItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (borderDotItem.getSelection()) {
setStyle(BORDER_DOT);
}
}));
MenuItem borderColorItem = new MenuItem(borderMenu, SWT.PUSH);
// $NON-NLS-1$
borderColorItem.setText(getResourceString("Color_menuitem"));
borderColorItem.addSelectionListener(widgetSelectedAdapter(event -> {
ColorDialog dialog = new ColorDialog(shell);
RGB rgb = borderColor != null ? borderColor.getRGB() : null;
dialog.setRGB(rgb);
RGB newRgb = dialog.open();
if (newRgb != null) {
if (!newRgb.equals(rgb)) {
disposeResource(borderColor);
borderColor = new Color(display, newRgb);
}
if (borderDashItem.getSelection())
setStyle(BORDER_DASH);
else if (borderDotItem.getSelection())
setStyle(BORDER_DOT);
else if (borderSolidItem.getSelection())
setStyle(BORDER_SOLID);
}
}));
final ToolItem borderControl = new ToolItem(styleToolBar, SWT.DROP_DOWN);
borderControl.setImage(iBorderStyle);
// $NON-NLS-1$
borderControl.setToolTipText(getResourceString("Box"));
borderControl.addSelectionListener(widgetSelectedAdapter(event -> {
if (event.detail == SWT.ARROW) {
Rectangle rect = borderControl.getBounds();
Point pt = new Point(rect.x, rect.y + rect.height);
borderMenu.setLocation(display.map(borderControl.getParent(), null, pt));
borderMenu.setVisible(true);
} else {
if (borderDashItem.getSelection())
setStyle(BORDER_DASH);
else if (borderDotItem.getSelection())
setStyle(BORDER_DOT);
else if (borderSolidItem.getSelection())
setStyle(BORDER_SOLID);
}
}));
ToolItem foregroundItem = new ToolItem(styleToolBar, SWT.DROP_DOWN);
foregroundItem.setImage(iTextForeground);
// $NON-NLS-1$
foregroundItem.setToolTipText(getResourceString("TextForeground"));
foregroundItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (event.detail == SWT.ARROW || textForeground == null) {
ColorDialog dialog = new ColorDialog(shell);
RGB rgb = textForeground != null ? textForeground.getRGB() : null;
dialog.setRGB(rgb);
RGB newRgb = dialog.open();
if (newRgb == null)
return;
if (!newRgb.equals(rgb)) {
disposeResource(textForeground);
textForeground = new Color(display, newRgb);
}
}
setStyle(FOREGROUND);
}));
ToolItem backgroundItem = new ToolItem(styleToolBar, SWT.DROP_DOWN);
backgroundItem.setImage(iTextBackground);
// $NON-NLS-1$
backgroundItem.setToolTipText(getResourceString("TextBackground"));
backgroundItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (event.detail == SWT.ARROW || textBackground == null) {
ColorDialog dialog = new ColorDialog(shell);
RGB rgb = textBackground != null ? textBackground.getRGB() : null;
dialog.setRGB(rgb);
RGB newRgb = dialog.open();
if (newRgb == null)
return;
if (!newRgb.equals(rgb)) {
disposeResource(textBackground);
textBackground = new Color(display, newRgb);
}
}
setStyle(BACKGROUND);
}));
ToolItem baselineUpItem = new ToolItem(styleToolBar, SWT.PUSH);
baselineUpItem.setImage(iBaselineUp);
// $NON-NLS-1$
String tooltip = "IncreaseFont";
// $NON-NLS-1$
if (USE_BASELINE)
tooltip = "IncreaseBaseline";
baselineUpItem.setToolTipText(getResourceString(tooltip));
baselineUpItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (USE_BASELINE) {
setStyle(BASELINE_UP);
} else {
adjustFontSize(1);
}
}));
ToolItem baselineDownItem = new ToolItem(styleToolBar, SWT.PUSH);
baselineDownItem.setImage(iBaselineDown);
// $NON-NLS-1$
tooltip = "DecreaseFont";
// $NON-NLS-1$
if (USE_BASELINE)
tooltip = "DecreaseBaseline";
baselineDownItem.setToolTipText(getResourceString(tooltip));
baselineDownItem.addSelectionListener(widgetSelectedAdapter(event -> {
if (USE_BASELINE) {
setStyle(BASELINE_DOWN);
} else {
adjustFontSize(-1);
}
}));
ToolItem linkItem = new ToolItem(styleToolBar, SWT.PUSH);
linkItem.setImage(iLink);
// $NON-NLS-1$
linkItem.setToolTipText(getResourceString("Link"));
linkItem.addSelectionListener(widgetSelectedAdapter(event -> setLink()));
CoolItem coolItem = new CoolItem(coolBar, SWT.NONE);
coolItem.setControl(styleToolBar);
Composite composite = new Composite(coolBar, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 1;
composite.setLayout(layout);
fontNameControl = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
fontNameControl.setItems(getFontNames());
fontNameControl.setVisibleItemCount(12);
fontSizeControl = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
fontSizeControl.setItems(FONT_SIZES);
fontSizeControl.setVisibleItemCount(8);
SelectionListener adapter = widgetSelectedAdapter(event -> {
String name = fontNameControl.getText();
int size = Integer.parseInt(fontSizeControl.getText());
disposeResource(textFont);
textFont = new Font(display, name, size, SWT.NORMAL);
setStyle(FONT);
});
fontSizeControl.addSelectionListener(adapter);
fontNameControl.addSelectionListener(adapter);
coolItem = new CoolItem(coolBar, SWT.NONE);
coolItem.setControl(composite);
ToolBar alignmentToolBar = new ToolBar(coolBar, SWT.FLAT);
blockSelectionItem = new ToolItem(alignmentToolBar, SWT.CHECK);
blockSelectionItem.setImage(iBlockSelection);
// $NON-NLS-1$
blockSelectionItem.setToolTipText(getResourceString("BlockSelection"));
blockSelectionItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.invokeAction(ST.TOGGLE_BLOCKSELECTION)));
leftAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO);
leftAlignmentItem.setImage(iLeftAlignment);
// $NON-NLS-1$
leftAlignmentItem.setToolTipText(getResourceString("AlignLeft"));
leftAlignmentItem.setSelection(true);
leftAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
Point selection = styledText.getSelection();
int lineStart = styledText.getLineAtOffset(selection.x);
int lineEnd = styledText.getLineAtOffset(selection.y);
styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.LEFT);
}));
leftAlignmentItem.setEnabled(false);
centerAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO);
centerAlignmentItem.setImage(iCenterAlignment);
// $NON-NLS-1$
centerAlignmentItem.setToolTipText(getResourceString("Center_menuitem"));
centerAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
Point selection = styledText.getSelection();
int lineStart = styledText.getLineAtOffset(selection.x);
int lineEnd = styledText.getLineAtOffset(selection.y);
styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.CENTER);
}));
centerAlignmentItem.setEnabled(false);
rightAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO);
rightAlignmentItem.setImage(iRightAlignment);
// $NON-NLS-1$
rightAlignmentItem.setToolTipText(getResourceString("AlignRight"));
rightAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
Point selection = styledText.getSelection();
int lineStart = styledText.getLineAtOffset(selection.x);
int lineEnd = styledText.getLineAtOffset(selection.y);
styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.RIGHT);
}));
rightAlignmentItem.setEnabled(false);
justifyAlignmentItem = new ToolItem(alignmentToolBar, SWT.CHECK);
justifyAlignmentItem.setImage(iJustifyAlignment);
// $NON-NLS-1$
justifyAlignmentItem.setToolTipText(getResourceString("Justify"));
justifyAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
Point selection = styledText.getSelection();
int lineStart = styledText.getLineAtOffset(selection.x);
int lineEnd = styledText.getLineAtOffset(selection.y);
styledText.setLineJustify(lineStart, lineEnd - lineStart + 1, justifyAlignmentItem.getSelection());
}));
justifyAlignmentItem.setEnabled(false);
ToolItem bulletListItem = new ToolItem(alignmentToolBar, SWT.PUSH);
bulletListItem.setImage(iBulletList);
// $NON-NLS-1$
bulletListItem.setToolTipText(getResourceString("BulletList"));
bulletListItem.addSelectionListener(widgetSelectedAdapter(event -> setBullet(ST.BULLET_DOT)));
ToolItem numberedListItem = new ToolItem(alignmentToolBar, SWT.PUSH);
numberedListItem.setImage(iNumberedList);
// $NON-NLS-1$
numberedListItem.setToolTipText(getResourceString("NumberedList"));
numberedListItem.addSelectionListener(widgetSelectedAdapter(event -> setBullet(ST.BULLET_NUMBER | ST.BULLET_TEXT)));
coolItem = new CoolItem(coolBar, SWT.NONE);
coolItem.setControl(alignmentToolBar);
composite = new Composite(coolBar, SWT.NONE);
layout = new GridLayout(4, false);
layout.marginHeight = 1;
composite.setLayout(layout);
Label label = new Label(composite, SWT.NONE);
// $NON-NLS-1$
label.setText(getResourceString("Indent"));
Spinner indent = new Spinner(composite, SWT.BORDER);
indent.addSelectionListener(widgetSelectedAdapter(event -> {
Spinner spinner = (Spinner) event.widget;
styledText.setIndent(spinner.getSelection());
}));
label = new Label(composite, SWT.NONE);
// $NON-NLS-1$
label.setText(getResourceString("Spacing"));
Spinner spacing = new Spinner(composite, SWT.BORDER);
spacing.addSelectionListener(widgetSelectedAdapter(event -> {
Spinner spinner = (Spinner) event.widget;
styledText.setLineSpacing(spinner.getSelection());
}));
coolItem = new CoolItem(coolBar, SWT.NONE);
coolItem.setControl(composite);
CoolItem[] coolItems = coolBar.getItems();
for (CoolItem item : coolItems) {
Control control = item.getControl();
Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
item.setMinimumSize(size);
size = item.computeSize(size.x, size.y);
item.setPreferredSize(size);
item.setSize(size);
}
coolBar.addControlListener(ControlListener.controlResizedAdapter(event -> handleResize(event)));
}
Aggregations