Author: yradtsevich
Date: 2009-08-06 12:39:18 -0400 (Thu, 06 Aug 2009)
New Revision: 16992
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/SplitToolBar.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/BlockFormatController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/ColorFormatController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/ComboFormatController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java
Log:
issue JBIDE-4075: Make Text Formatting toolbar expanded
https://jira.jboss.org/jira/browse/JBIDE-4075
- now the toolbar has a chevron with a drop-down menu
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2009-08-06
15:58:09 UTC (rev 16991)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2009-08-06
16:39:18 UTC (rev 16992)
@@ -301,15 +301,15 @@
@Override
public void createPartControl(final Composite parent) {
//Setting Layout for the parent Composite
- parent.setLayout(new FillLayout());
+// parent.setLayout(new FillLayout());
/*
*
https://jira.jboss.org/jira/browse/JBIDE-4062
* Creating scrollable eclipse element.
*/
- ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL |
SWT.BORDER);
- sc.setLayout(new FillLayout());
- Composite composite = new Composite(sc, SWT.NATIVE);
+// ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL |
SWT.BORDER);
+// sc.setLayout(new FillLayout());
+// Composite composite = new Composite(parent, SWT.NATIVE);
GridLayout layout = new GridLayout(2,false);
layout.marginHeight = 0;
@@ -317,12 +317,13 @@
layout.verticalSpacing = 2;
layout.horizontalSpacing = 2;
layout.marginBottom = 0;
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ parent.setLayout(layout);
+// composite.setLayout(layout);
+// composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// Editors and Toolbar composite
- Composite cmpEdTl = new Composite(composite, SWT.NONE);
+ Composite cmpEdTl = new Composite(parent, SWT.NONE);
GridLayout layoutEdTl = new GridLayout(1, false);
layoutEdTl.verticalSpacing = 0;
layoutEdTl.marginHeight = 0;
@@ -467,11 +468,11 @@
*
https://jira.jboss.org/jira/browse/JBIDE-4062
* Computing elements sizes to set up scroll bars.
*/
- Point totalSize = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- sc.setContent(composite);
- sc.setExpandHorizontal(true);
- sc.setExpandVertical(true);
- sc.setMinSize(totalSize);
+// Point totalSize = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+// sc.setContent(composite);
+// sc.setExpandHorizontal(true);
+// sc.setExpandVertical(true);
+// sc.setMinSize(totalSize);
}
/**
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/SplitToolBar.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/SplitToolBar.java 2009-08-06
15:58:09 UTC (rev 16991)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/SplitToolBar.java 2009-08-06
16:39:18 UTC (rev 16992)
@@ -10,29 +10,136 @@
******************************************************************************/
package org.jboss.tools.vpe.editor.toolbar;
+import java.util.Arrays;
+import java.util.List;
+
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.ShellAdapter;
+import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.CoolBar;
+import org.eclipse.swt.widgets.CoolItem;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.Widget;
/**
* @author Erick
* Created on 14.07.2005
+ * @author yradtsevich
+ *
* @see IVpeToolBar
* This class create a toolBar and store all his item in the array of IItems
* @see IItems
*/
public abstract class SplitToolBar implements IVpeToolBar {
- public abstract IItems[] createItems(ToolBar bar);
+ protected CoolBar coolBar;
+ public abstract void createItems(ToolBar bar);
public void createToolBarControl(Composite parent) {
final Composite comp = new Composite(parent, SWT.NONE);
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ comp.setLayout(new GridLayout());
+ coolBar = new CoolBar(comp, SWT.FLAT | SWT.WRAP);
+ coolBar.setLayoutData(new GridData(GridData.FILL_BOTH));
- final ToolBar horBar = new ToolBar(comp, SWT.FLAT);
- createItems(horBar);
+ final ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT | SWT.WRAP);
+ createItems(toolBar);
+ CoolItem coolItem = new CoolItem(coolBar, SWT.DROP_DOWN);
+ coolItem.setControl(toolBar);
+ Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ Point coolSize = coolItem.computeSize(size.x, size.y);
+ coolItem.setSize(coolSize);
+ coolItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ if (event.detail == SWT.ARROW) {
+ CoolItem item = (CoolItem) event.widget;
+ Rectangle itemBounds = item.getBounds();
+ Point pt = coolBar.toDisplay(new Point(itemBounds.x,
+ itemBounds.y));
+ itemBounds.x = pt.x;
+ itemBounds.y = pt.y;
+ ToolBar bar = (ToolBar) item.getControl();
+ ToolItem[] tools = bar.getItems();
+
+ int i = 0;
+ while (i < tools.length) {
+ Rectangle toolBounds = tools[i].getBounds();
+ pt = bar.toDisplay(new Point(toolBounds.x, toolBounds.y));
+ toolBounds.x = pt.x;
+ toolBounds.y = pt.y;
+
+ /*
+ * Figure out the visible portion of the tool by looking
+ * at the intersection of the tool bounds with the cool
+ * item bounds.
+ */
+ Rectangle intersection = itemBounds
+ .intersection(toolBounds);
+
+ /*
+ * If the tool is not completely within the cool item
+ * bounds, then it is partially hidden, and all
+ * remaining tools are completely hidden.
+ */
+ if (!intersection.equals(toolBounds))
+ break;
+ i++;
+ }
+
+ /*
+ * Create a menu with items for each of the completely
+ * hidden buttons.
+ */
+ final Shell floatingShell = new Shell(coolBar.getShell(),
+ SWT.ON_TOP);
+ floatingShell.setLayout(new GridLayout());
+ final ToolBar floatingBar = new ToolBar(floatingShell,
+ SWT.FLAT | SWT.WRAP);
+ SelectionListener selectionListener = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ floatingShell.dispose();
+ }
+ };
+ for (int j = i; j < tools.length; j++) {
+ cloneToolItem(floatingBar, tools[j], selectionListener);
+ }
+
+ /*
+ * Drop down the menu below the chevron, with the left edges
+ * aligned.
+ */
+ pt = coolBar.toDisplay(new Point(event.x, event.y));
+ floatingShell.pack();
+ arrange(floatingShell, pt);
+ floatingShell.setVisible(true);
+ floatingShell.setFocus();
+ floatingShell.addShellListener(new ShellAdapter() {
+ public void shellDeactivated(ShellEvent e) {
+ e.widget.dispose();
+ }
+ });
+ }
+ }
+ });
+ coolBar.pack();
+// coolBar.layout();
+
// final Button button = new Button(parent, SWT.FLAT|SWT.PUSH);
// button.setImage(ImageDescriptor.createFromFile(MozillaEditor.class,
"icons/arrow_more.gif").createImage());
// button.setVisible(false);
@@ -86,7 +193,7 @@
// }
// }
// });
- horBar.pack(true);
+ toolBar.pack(true);
}
// public Menu setMenu(Composite cmp, Button btn){
@@ -123,4 +230,116 @@
// }
// return menu;
// }
-}
\ No newline at end of file
+
+ /**
+ * Creates a copy of {@code item} in the {@code destBar} and
+ * adds given {@code selectionListener} to the created control.
+ */
+ protected void cloneToolItem(ToolBar destBar, ToolItem item,
+ SelectionListener selectionListener) {
+ int style = item.getStyle();
+
+ if ((style & SWT.SEPARATOR) != 0) {
+ Control control = item.getControl();
+ if (control instanceof Combo) {
+ Combo combo = (Combo) control;
+ Combo copiedCombo = createComboToolItem(destBar, combo.getStyle(),
+ combo.getToolTipText(),
+ Arrays.asList(combo.getItems()),
+ combo.getSelectionIndex());
+ copiedCombo.setEnabled(combo.getEnabled());
+ copiedCombo.setVisible(combo.getVisible());
+ copySelectionListeners(combo, copiedCombo);
+ copiedCombo.addSelectionListener(selectionListener);
+ }
+ } else {
+ ToolItem copiedItem = createToolItem(destBar, item.getStyle(),
+ item.getImage(), item.getToolTipText());
+ copiedItem.setEnabled(item.getEnabled());
+ copiedItem.setSelection(item.getSelection());
+ copySelectionListeners(item, copiedItem);
+ copiedItem.addSelectionListener(selectionListener);
+ }
+ }
+
+ /**
+ * Copies all selection listeners from {@code src} to {@code dest}.
+ */
+ protected void copySelectionListeners(Widget src, Widget dest) {
+ Listener[] listeners = src.getListeners(SWT.Selection);
+ for (Listener listener : listeners) {
+ dest.addListener(SWT.Selection, listener);
+ }
+ }
+
+ /**
+ * Creates and returns new {@code ToolItem} in the
+ * {@code bar}.
+ */
+ protected ToolItem createToolItem(ToolBar bar, int style,
+ Image image, String toolTipText) {
+ ToolItem item = null;
+ item = new ToolItem(bar, style);
+ item.setImage(image);
+ item.setToolTipText(toolTipText);
+
+ return item;
+ }
+
+ /**
+ * Creates and returns new {@code Combo} in the
+ * {@code bar}.
+ */
+ protected Combo createComboToolItem(ToolBar bar, int style,
+ String toolTipText, List<String> comboItems, int selectionIndex) {
+ Combo combo = createCombo(bar, style, comboItems);
+ ToolItem sep = new ToolItem(bar, SWT.SEPARATOR);
+ sep.setWidth(combo.getSize().x);
+ combo.setToolTipText(toolTipText);
+ combo.select(selectionIndex);
+ sep.setControl(combo);
+
+ return combo;
+ }
+
+ protected Combo createCombo(Composite parent, int style,
+ List<String> comboItems) {
+ Combo combo = new Combo(parent, style);
+ combo.setLayoutData(new RowData());
+ combo.setItems(comboItems.toArray(new String[comboItems.size()]));
+ combo.pack();
+ return combo;
+ }
+
+ /**
+ * Arranges {@code control} on the display near the {@code point}.
+ */
+ private void arrange(Control control, Point point) {
+ Point size = control.getSize();
+ Rectangle bounds = new Rectangle(point.x, point.y, size.x, size.y);
+ control.setBounds(arrange(bounds, control.getDisplay().getBounds()));
+ }
+
+ /**
+ * Returns the nearest {@code Rectangle} to the given {@code bounds},
+ * which is fully placed in the {@code clientArea}.
+ */
+ private Rectangle arrange(Rectangle bounds, Rectangle clientArea) {
+ Rectangle result = new Rectangle(bounds.x, bounds.y,
+ bounds.width, bounds.height);
+ if (result.x + result.width > clientArea.x + clientArea.width) {
+ result.x = clientArea.x + clientArea.width - result.width;
+ }
+ if (result.x < clientArea.x) {
+ result.x = clientArea.x;
+ }
+ if (result.y + result.height > clientArea.y + clientArea.height) {
+ result.y = clientArea.y + clientArea.height - result.height;
+ }
+ if (result.y < clientArea.y) {
+ result.y = clientArea.y;
+ }
+
+ return result;
+ }
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java 2009-08-06
15:58:09 UTC (rev 16991)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeToolBarManager.java 2009-08-06
16:39:18 UTC (rev 16992)
@@ -17,14 +17,16 @@
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.jboss.tools.vpe.VpePlugin;
-import org.jboss.tools.vpe.editor.util.Constants;
import org.jboss.tools.vpe.messages.VpeUIMessages;
/**
@@ -48,7 +50,7 @@
public Composite createToolBarComposite(Composite parent) {
splitter = new Splitter(parent, SWT.NONE) {
- // if there is not visual children then return Point(0,0)
+ // if there are no visual children then return Point(0,0)
public Point computeSize(int hint, int hint2, boolean changed) {
int countVisibleChild = 0;
@@ -63,16 +65,24 @@
return super.computeSize(hint, hint2, changed);
}
};
-
+ splitter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
return splitter;
}
public void addToolBar(IVpeToolBar bar) {
Composite cmpToolBar = new Composite(splitter, SWT.NONE);
+ splitter.getParent().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
+ splitter.getParent().setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
+ FormData data = new FormData();
+ data.left = new FormAttachment(0);
+ data.right = new FormAttachment(100);
+ data.top = new FormAttachment(0);
+
+ cmpToolBar.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
GridLayout layoutTl = new GridLayout(2, false);
layoutTl.marginBottom = 0;
- layoutTl.marginHeight = 2;
+ layoutTl.marginHeight = 0;
layoutTl.marginWidth = 0;
layoutTl.verticalSpacing = 0;
layoutTl.horizontalSpacing = 0;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/BlockFormatController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/BlockFormatController.java 2009-08-06
15:58:09 UTC (rev 16991)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/BlockFormatController.java 2009-08-06
16:39:18 UTC (rev 16992)
@@ -73,8 +73,8 @@
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event event) {
- selectionIndex = comboBlockFormat.getSelectionIndex();
- selectionText = comboBlockFormat.getText();
+ selectionIndex = ((Combo)event.widget).getSelectionIndex();
+ selectionText = ((Combo)event.widget).getText();
tagName = (String) TEXTS.get(selectionText);
if (tagName == null) {
tagName = "normal"; //$NON-NLS-1$
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/ColorFormatController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/ColorFormatController.java 2009-08-06
15:58:09 UTC (rev 16991)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/ColorFormatController.java 2009-08-06
16:39:18 UTC (rev 16992)
@@ -40,9 +40,8 @@
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event event) {
- Shell shell = new Shell(Display.getCurrent());
- shell.setLocation(shell.getDisplay().getBounds().width / 2 - 111,
shell.getDisplay().getBounds().height / 2 - 162);
- ColorDialog cd = new ColorDialog(shell, SWT.APPLICATION_MODAL);
+ ColorDialog cd = new ColorDialog(toolItem.getParent().getShell(),
+ SWT.APPLICATION_MODAL);
cd.setText(getColorDialogTitle());
cd.setRGB(new RGB(255, 255, 255));
RGB newColor = cd.open();
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/ComboFormatController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/ComboFormatController.java 2009-08-06
15:58:09 UTC (rev 16991)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/ComboFormatController.java 2009-08-06
16:39:18 UTC (rev 16992)
@@ -36,8 +36,8 @@
}
public void handleEvent(Event event) {
- selectionIndex = comboBlockFormat.getSelectionIndex();
- selectionText = comboBlockFormat.getText();
+ selectionIndex = ((Combo)event.widget).getSelectionIndex();
+ selectionText = ((Combo)event.widget).getText();
super.handleEvent(event);
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java 2009-08-06
15:58:09 UTC (rev 16991)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java 2009-08-06
16:39:18 UTC (rev 16992)
@@ -12,27 +12,32 @@
import java.awt.GraphicsEnvironment;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
-import org.jboss.tools.vpe.editor.toolbar.IItems;
import org.jboss.tools.vpe.editor.toolbar.SplitToolBar;
import org.jboss.tools.vpe.messages.VpeUIMessages;
/**
- * @author Erick
+ * The Text Formatting toolbar class.
+ *
+ * @author Erick.
* Created on 14.07.2005
- * The Text Formatting toolbar class.
+ *
+ * @author yradtsevich
*/
public class TextFormattingToolBar extends SplitToolBar {
@@ -42,10 +47,13 @@
private static String[] FONT_ARRAY = { "Arial", "Courier New",
"Times New Roman", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
"Comic Sans", "MS Serif", "Tahoma",
"Verdana" }; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
-
- private Composite composite;
+ private ToolBar toolBar;
+ private ToolBar floatingBar;
private FormatControllerManager formatControllerManager;
+ private List<Image> imagesList = new ArrayList<Image>();
+
+
public TextFormattingToolBar(FormatControllerManager formatControllerManager) {
this.formatControllerManager = formatControllerManager;
}
@@ -58,117 +66,106 @@
return ID;
}
- private ToolItem createToolItem(ToolBar parent, int type, String image, String
toolTipText) {
- ToolItem item = new ToolItem(parent, type);
- item.setImage(ImageDescriptor.createFromFile(MozillaEditor.class,
image).createImage());
- item.setToolTipText(toolTipText);
-
- // add dispose listener
- item.addDisposeListener(new DisposeListener() {
+ public Composite getComposite(){
+ return toolBar;
+ }
+ public void createItems(ToolBar parent) {
+// ArrayList<ToolItemDescriptor> itemDescriptors
+// = new ArrayList<ToolItemDescriptor>();
+ this.toolBar = parent;
+ toolBar.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
- // dispose tollitem's image
- ((ToolItem) e.widget).getImage().dispose();
-
+ for (Image image : imagesList) {
+ image.dispose();
+ }
+ imagesList.clear();
}
});
- return item;
- }
-
- public Composite getComposite(){
- return composite;
- }
-
- public IItems[] createItems(ToolBar horBar) {
- ArrayList itemDescriptors = new ArrayList();
-
- ToolItem sep = new ToolItem(horBar, SWT.SEPARATOR);
- Combo comboBlockFormat = new Combo(horBar, SWT.READ_ONLY);
- comboBlockFormat.add("Normal"); //$NON-NLS-1$
-// comboBlockFormat.add("Formatted");
- comboBlockFormat.add("Address"); //$NON-NLS-1$
+ /* If a separator comes first in a ToolBar, it can not
+ * be hidden. An empty separator is created to ensure
+ * that any ToolItem can be hidden. */
+ ToolItem emptySeparator = new ToolItem(toolBar, SWT.SEPARATOR);
+ Label emptyLabel = new Label(toolBar, SWT.NONE);
+ emptySeparator.setControl(emptyLabel);
+ emptySeparator.setWidth(1);
+
+ List<String> blockFormatItems = new ArrayList<String>();
+ blockFormatItems.add("Normal"); //$NON-NLS-1$
+ blockFormatItems.add("Address"); //$NON-NLS-1$
+// blockFormatItems.add("Numbered List");
+// blockFormatItems.add("Bulleted List");
+// blockFormatItems.add("Directory List");
for (int i = 1; i < 7; i++) {
- comboBlockFormat.add("Heading " + i); //$NON-NLS-1$
+ blockFormatItems.add("Heading " + i); //$NON-NLS-1$
}
-// comboBlockFormat.add("Numbered List");
-// comboBlockFormat.add("Bulleted List");
-// comboBlockFormat.add("Directory List");
- comboBlockFormat.setToolTipText(VpeUIMessages.BLOCK_FORMAT);
- comboBlockFormat.select(0);
- comboBlockFormat.pack();
- comboBlockFormat.setLayoutData(new RowData());
+ Combo comboBlockFormat = createComboToolItem(toolBar, SWT.READ_ONLY,
+ VpeUIMessages.BLOCK_FORMAT, blockFormatItems, 0);
comboBlockFormat.addListener(SWT.Selection, new
BlockFormatController(formatControllerManager, comboBlockFormat));
- sep.setWidth(comboBlockFormat.getSize().x);
- sep.setControl(comboBlockFormat);
- itemDescriptors.add(new ToolItemDescriptor(sep, false, null, false));
+// itemDescriptors.add(new ToolItemDescriptor(sep, false, null, false));
- sep = new ToolItem(horBar, SWT.SEPARATOR);
-
- Combo comboFont = new Combo(horBar, SWT.READ_ONLY);
- String[] font = null;
+ List<String> fonts = new ArrayList<String>();
+ fonts.add(NORMAL_FONT);
try {
- font =
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
+ fonts.addAll(Arrays.asList(
+ GraphicsEnvironment.getLocalGraphicsEnvironment()
+ .getAvailableFontFamilyNames()));
} catch (Error ex) {
VpePlugin.getPluginLog().logWarning(ex);
- font = FONT_ARRAY;
+ fonts.addAll(Arrays.asList(FONT_ARRAY));
}
- comboFont.setItems(font);
- comboFont.add(NORMAL_FONT, 0);
- comboFont.select(0);
- comboFont.pack();
- comboFont.setToolTipText(VpeUIMessages.FONT_NAME);
+ Combo comboFont = createComboToolItem(toolBar, SWT.READ_ONLY, VpeUIMessages.FONT_NAME,
fonts, 0);
comboFont.addListener(SWT.Selection, new
FontNameFormatController(formatControllerManager, comboFont, NORMAL_FONT));
- sep.setWidth(comboFont.getSize().x);
- sep.setControl(comboFont);
- itemDescriptors.add(new ToolItemDescriptor(sep, false, null, false));
+// itemDescriptors.add(new ToolItemDescriptor(sep, false, null, false));
- sep = new ToolItem(horBar, SWT.SEPARATOR);
- Combo comboFontSize = new Combo(horBar, SWT.DROP_DOWN|SWT.COLOR_LIST_BACKGROUND );
+ List<String> fontSizes = new ArrayList<String>();
+ fontSizes.add(NORMAL_FONT);
for (int i = 1; i < 8; i++) {
- comboFontSize.add("" + i); //$NON-NLS-1$
+ fontSizes.add(Integer.toString(i)); //$NON-NLS-1$
}
- comboFontSize.add(NORMAL_FONT, 0);
- comboFontSize.setToolTipText(VpeUIMessages.FONT_SIZE);
- comboFontSize.select(2);
- comboFontSize.pack();
+ Combo comboFontSize = createComboToolItem(toolBar,
+ SWT.DROP_DOWN | SWT.COLOR_LIST_BACKGROUND,
+ VpeUIMessages.FONT_SIZE, fontSizes, 2);
comboFontSize.addListener(SWT.Selection, new
FontSizeFormatController(formatControllerManager, comboFontSize));
- sep.setWidth(comboFontSize.getSize().x);
- sep.setControl(comboFontSize);
- itemDescriptors.add(new ToolItemDescriptor(sep, false, null, false));
+// itemDescriptors.add(new ToolItemDescriptor(sep, false, null, false));
- sep = new ToolItem(horBar, SWT.SEPARATOR);
- itemDescriptors.add(new ToolItemDescriptor(sep, false, null, false));
+// itemDescriptors.add(new ToolItemDescriptor(sep, false, null, false));
- ToolItem item = createToolItem(horBar, SWT.CHECK, "icons/bold.gif",
VpeUIMessages.BOLD); //$NON-NLS-1$
+ ToolItem item = createToolItem(toolBar, SWT.CHECK,
+ createImage("icons/bold.gif"), VpeUIMessages.BOLD);//$NON-NLS-1$
Listener listener = new BoldFormatController(formatControllerManager, item);
item.addListener(SWT.Selection, listener);
- itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
+// itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
- item = createToolItem(horBar, SWT.CHECK, "icons/italic.gif",
VpeUIMessages.ITALIC); //$NON-NLS-1$
+ item = createToolItem(toolBar, SWT.CHECK,
+ createImage("icons/italic.gif"), //$NON-NLS-1$
+ VpeUIMessages.ITALIC);
listener = new ItalicFormatController(formatControllerManager, item);
item.addListener(SWT.Selection, listener);
- itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
+// itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
- item = createToolItem(horBar, SWT.CHECK, "icons/uderline.gif",
VpeUIMessages.UNDERLINE); //$NON-NLS-1$
+ item = createToolItem(toolBar, SWT.CHECK,
+ createImage("icons/uderline.gif"), VpeUIMessages.UNDERLINE); //$NON-NLS-1$
listener = new UnderlineFormatController(formatControllerManager, item);
item.addListener(SWT.Selection, listener);
- itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
+// itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
- sep = new ToolItem(horBar, SWT.SEPARATOR);
- itemDescriptors.add(new ToolItemDescriptor(sep, false, null, true));
+// itemDescriptors.add(new ToolItemDescriptor(sep, false, null, true));
- item = createToolItem(horBar, SWT.PUSH, "icons/background.gif",
VpeUIMessages.BACKGROUND_COLOR); //$NON-NLS-1$
+ item = createToolItem(toolBar, SWT.CHECK,
+ createImage("icons/background.gif"), VpeUIMessages.BACKGROUND_COLOR);
//$NON-NLS-1$
listener = new BackgroundColorFormatController(formatControllerManager, item);
item.addListener(SWT.Selection, listener);
- itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
+// itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
- item = createToolItem(horBar, SWT.PUSH, "icons/foreground.gif",
VpeUIMessages.FOREGROUND_COLOR); //$NON-NLS-1$
+ item = createToolItem(toolBar, SWT.CHECK,
+ createImage("icons/foreground.gif"), VpeUIMessages.FOREGROUND_COLOR);
//$NON-NLS-1$
listener = new ForegroundColorFormatController(formatControllerManager, item);
item.addListener(SWT.Selection, listener);
- itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
+// itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
// sep = new ToolItem(horBar, SWT.SEPARATOR);
//
@@ -191,7 +188,15 @@
//
// item = createToolItem(horBar, SWT.PUSH, "icons/numbering.gif",
VpeToolbarFormatMessages.getInstance().getString(NUMBERING_KEY));
// item.addListener(SWT.Selection, new
NumberingFormatController(formatControllerManager, item));
+
+// return (IItems[])itemDescriptors.toArray(new IItems[itemDescriptors.size()]);
+ }
+
+ private Image createImage(String path) {
+ Image image = ImageDescriptor.createFromFile(MozillaEditor.class, path)
+ .createImage();
+ imagesList.add(image);
- return (IItems[])itemDescriptors.toArray(new IItems[itemDescriptors.size()]);
+ return image;
}
}
\ No newline at end of file