Author: dsakovich
Date: 2008-04-10 12:33:44 -0400 (Thu, 10 Apr 2008)
New Revision: 7491
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/AttributeFormatController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/FontNameFormatController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/FontSizeFormatController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-1996
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/AttributeFormatController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/AttributeFormatController.java 2008-04-10
15:54:21 UTC (rev 7490)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/AttributeFormatController.java 2008-04-10
16:33:44 UTC (rev 7491)
@@ -57,6 +57,10 @@
if(FormatAttributeData.STYLE_TYPE.equals(templateData.getType())) {
manager.setIgnoreSelectionChanges(false);
setStyle(attribute, templateData);
+ if (!(attribute.getValue().length() > 0)) {
+ Element element = (Element) selectedNode;
+ element.removeAttributeNode(attribute);
+ }
return;
}
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/FontNameFormatController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/FontNameFormatController.java 2008-04-10
15:54:21 UTC (rev 7490)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/FontNameFormatController.java 2008-04-10
16:33:44 UTC (rev 7491)
@@ -7,82 +7,106 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor.toolbar.format;
import org.eclipse.swt.widgets.Combo;
-import org.w3c.dom.Attr;
-
import org.jboss.tools.vpe.editor.template.textformating.FormatAttributeData;
import org.jboss.tools.vpe.editor.toolbar.format.css.StyleAttribute;
import org.jboss.tools.vpe.editor.toolbar.format.css.StyleProperty;
+import org.w3c.dom.Attr;
/**
* @author Igels
*/
public class FontNameFormatController extends ComboFormatController {
- public static String TYPE = "FontNameFormat";
+ private static final String REPLACE_VALUE = "['\"]";
//$NON-NLS-1$
- private static String STYLE_PROPERTY_NAME = "FONT-FAMILY";
+ private static final String EMPTY = ""; //$NON-NLS-1$
- /**
- * @param manager
- * @param comboBlockFormat
- */
- public FontNameFormatController(FormatControllerManager manager, Combo comboBlockFormat)
{
- super(manager, comboBlockFormat);
- }
+ public static String TYPE = "FontNameFormat"; //$NON-NLS-1$
- /* (non-Javadoc)
- * @see org.jboss.tools.vpe.editor.toolbar.format.IFormatController#getType()
- */
- public String getType() {
- return TYPE;
- }
+ private static String STYLE_PROPERTY_NAME = "FONT-FAMILY"; //$NON-NLS-1$
- protected void setStyle(Attr styleAttribute, FormatAttributeData templateData) {
- String value = createStylePropertyValue();
- if(value!=null) {
- setSingleStyleProperty(styleAttribute, STYLE_PROPERTY_NAME, value);
- }
+ private String defaultFont = null;
+
+ /**
+ * @param manager
+ * @param comboBlockFormat
+ */
+ public FontNameFormatController(FormatControllerManager manager,
+ Combo comboBlockFormat, String defaultFont) {
+ super(manager, comboBlockFormat);
+ this.defaultFont = defaultFont;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.tools.vpe.editor.toolbar.format.IFormatController#getType()
+ */
+ public String getType() {
+ return TYPE;
+ }
+
+ protected void setStyle(Attr styleAttribute,
+ FormatAttributeData templateData) {
+ String value = createStylePropertyValue();
+ if (value != null) {
+ String fontName = value.replaceAll(REPLACE_VALUE, EMPTY);
+ if (fontName.equalsIgnoreCase(defaultFont)) {
+ StyleAttribute style = new StyleAttribute(styleAttribute);
+ style.removeStyleProperty(STYLE_PROPERTY_NAME);
+ String newStyle = style.toString().trim();
+ styleAttribute.setValue(newStyle);
+ return;
+ }
+ setSingleStyleProperty(styleAttribute, STYLE_PROPERTY_NAME, value);
}
+ }
- private String createStylePropertyValue() {
- if(selectionText!=null && selectionText.trim().length()>0) {
- return "'" + selectionText.trim() + "'";
- }
- return null;
+ private String createStylePropertyValue() {
+ if (selectionText != null && selectionText.trim().length() > 0) {
+ return "'" + selectionText.trim() + "'";
//$NON-NLS-1$//$NON-NLS-2$
}
+ return null;
+ }
- /* (non-Javadoc)
- * @see
org.jboss.tools.vpe.editor.toolbar.format.IFormatController#setToolbarItemEnabled(boolean
enabled)
- */
- public void setToolbarItemEnabled(boolean enabled) {
- comboBlockFormat.setEnabled(enabled);
- if(enabled) {
- Attr style = getStyleAttributeFromSelectedNode(true);
- if(style!=null) {
- StyleAttribute styleAttribute = new StyleAttribute(style);
- StyleProperty fontProperty = styleAttribute.getProperty(STYLE_PROPERTY_NAME);
- if(fontProperty!=null) {
- String fontName = fontProperty.getPropertyValue().getDirtyValue().trim();
- if(fontName!=null) {
- fontName = fontName.replaceAll("['\"]", "");
- if(getComboBlockFormat().getText().equalsIgnoreCase(fontName)) {
- return;
- }
- String[] items = this.getComboBlockFormat().getItems();
- for (int i = 0; i < items.length; i++) {
- if(items[i].equalsIgnoreCase(fontName)) {
- this.getComboBlockFormat().select(i);
- return;
- }
- }
- }
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.tools.vpe.editor.toolbar.format.IFormatController#setToolbarItemEnabled(boolean
+ * enabled)
+ */
+ public void setToolbarItemEnabled(boolean enabled) {
+ comboBlockFormat.setEnabled(enabled);
+ if (enabled) {
+ Attr style = getStyleAttributeFromSelectedNode(true);
+ if (style != null) {
+ StyleAttribute styleAttribute = new StyleAttribute(style);
+ StyleProperty fontProperty = styleAttribute
+ .getProperty(STYLE_PROPERTY_NAME);
+ if (fontProperty != null) {
+ String fontName = fontProperty.getPropertyValue()
+ .getDirtyValue().trim();
+ if (fontName != null) {
+ fontName = fontName.replaceAll(REPLACE_VALUE, EMPTY);
+ if (getComboBlockFormat().getText().equalsIgnoreCase(
+ fontName)) {
+ return;
}
+ String[] items = this.getComboBlockFormat().getItems();
+ for (int i = 0; i < items.length; i++) {
+ if (items[i].equalsIgnoreCase(fontName)) {
+ this.getComboBlockFormat().select(i);
+ return;
+ }
+ }
+ }
}
- getComboBlockFormat().deselectAll();
+ }
}
+ getComboBlockFormat().select(0);
+ }
}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/FontSizeFormatController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/FontSizeFormatController.java 2008-04-10
15:54:21 UTC (rev 7490)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/FontSizeFormatController.java 2008-04-10
16:33:44 UTC (rev 7491)
@@ -7,7 +7,7 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor.toolbar.format;
import java.util.HashMap;
@@ -24,76 +24,91 @@
*/
public class FontSizeFormatController extends ComboFormatController {
- public static String TYPE = "FontSizeFormat";
+ public static String TYPE = "FontSizeFormat"; //$NON-NLS-1$
- private static String STYLE_PROPERTY_NAME = "FONT-SIZE";
+ private static String STYLE_PROPERTY_NAME = "FONT-SIZE"; //$NON-NLS-1$
- private static HashMap SIZES = new HashMap();
- static {
- SIZES.put("1", "xx-small");
- SIZES.put("2", "x-small");
- SIZES.put("3", "small");
- SIZES.put("4", "medium");
- SIZES.put("5", "large");
- SIZES.put("6", "x-large");
- SIZES.put("7", "xx-large");
- }
+ private static HashMap<String, String> SIZES = new HashMap<String,
String>();
+ static {
+ SIZES.put("1", "xx-small"); //$NON-NLS-1$ //$NON-NLS-2$
+ SIZES.put("2", "x-small"); //$NON-NLS-1$ //$NON-NLS-2$
+ SIZES.put("3", "small"); //$NON-NLS-1$ //$NON-NLS-2$
+ SIZES.put("4", "medium"); //$NON-NLS-1$ //$NON-NLS-2$
+ SIZES.put("5", "large"); //$NON-NLS-1$ //$NON-NLS-2$
+ SIZES.put("6", "x-large"); //$NON-NLS-1$ //$NON-NLS-2$
+ SIZES.put("7", "xx-large"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
- /**
- * @param manager
- * @param comboBlockFormat
- */
- public FontSizeFormatController(FormatControllerManager manager, Combo comboBlockFormat)
{
- super(manager, comboBlockFormat);
- }
+ /**
+ * @param manager
+ * @param comboBlockFormat
+ */
+ public FontSizeFormatController(FormatControllerManager manager,
+ Combo comboBlockFormat) {
+ super(manager, comboBlockFormat);
+ }
- /* (non-Javadoc)
- * @see org.jboss.tools.vpe.editor.toolbar.format.IFormatController#getType()
- */
- public String getType() {
- return TYPE;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.tools.vpe.editor.toolbar.format.IFormatController#getType()
+ */
+ public String getType() {
+ return TYPE;
+ }
- protected void setStyle(Attr styleAttribute, FormatAttributeData templateData) {
- String value = createStylePropertyValue();
- if(value!=null) {
- setSingleStyleProperty(styleAttribute, STYLE_PROPERTY_NAME, value);
- }
+ protected void setStyle(Attr styleAttribute,
+ FormatAttributeData templateData) {
+ String value = createStylePropertyValue();
+ if (value != null) {
+ setSingleStyleProperty(styleAttribute, STYLE_PROPERTY_NAME, value);
+ } else {
+ StyleAttribute style = new StyleAttribute(styleAttribute);
+ style.removeStyleProperty(STYLE_PROPERTY_NAME);
+ String newStyle = style.toString().trim();
+ styleAttribute.setValue(newStyle);
}
+ }
- private String createStylePropertyValue() {
- if(selectionText!=null && selectionText.trim().length()>0) {
- return (String)SIZES.get(selectionText.trim());
- }
- return null;
+ private String createStylePropertyValue() {
+ if (selectionText != null && selectionText.trim().length() > 0) {
+ return (String) SIZES.get(selectionText.trim());
}
+ return null;
+ }
- /* (non-Javadoc)
- * @see
org.jboss.tools.vpe.editor.toolbar.format.IFormatController#setToolbarItemEnabled(boolean
enabled)
- */
- public void setToolbarItemEnabled(boolean enabled) {
- comboBlockFormat.setEnabled(enabled);
- if(enabled) {
- Attr style = getStyleAttributeFromSelectedNode(true);
- if(style!=null) {
- StyleAttribute styleAttribute = new StyleAttribute(style);
- StyleProperty fontProperty = styleAttribute.getProperty(STYLE_PROPERTY_NAME);
- if(fontProperty!=null) {
- String fontSize = fontProperty.getFirstSinglePropertyValue();
- if(fontSize!=null) {
- String[] items = this.getComboBlockFormat().getItems();
- for (int i = 0; i < items.length; i++) {
- if(SIZES.get(items[i]).equals(fontSize)) {
- if(this.getComboBlockFormat().getSelectionIndex()!=i) {
- this.getComboBlockFormat().select(i);
- }
- return;
- }
- }
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.tools.vpe.editor.toolbar.format.IFormatController#setToolbarItemEnabled(boolean
+ * enabled)
+ */
+ public void setToolbarItemEnabled(boolean enabled) {
+ comboBlockFormat.setEnabled(enabled);
+ if (enabled) {
+ Attr style = getStyleAttributeFromSelectedNode(true);
+ if (style != null) {
+ StyleAttribute styleAttribute = new StyleAttribute(style);
+ StyleProperty fontProperty = styleAttribute
+ .getProperty(STYLE_PROPERTY_NAME);
+ if (fontProperty != null) {
+ String fontSize = fontProperty
+ .getFirstSinglePropertyValue();
+ if (fontSize != null) {
+ String[] items = this.getComboBlockFormat().getItems();
+ for (int i = 1; i < items.length; i++) {
+ if (SIZES.get(items[i]).equals(fontSize)) {
+ if (this.getComboBlockFormat()
+ .getSelectionIndex() != i) {
+ this.getComboBlockFormat().select(i);
}
+ return;
+ }
}
+ }
}
- getComboBlockFormat().deselectAll();
+ }
}
+ getComboBlockFormat().select(0);
+ }
}
\ No newline at end of file
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 2008-04-10
15:54:21 UTC (rev 7490)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java 2008-04-10
16:33:44 UTC (rev 7491)
@@ -36,9 +36,11 @@
*/
public class TextFormattingToolBar extends SplitToolBar {
- private static String[] FONT_ARRAY = { "Arial", "Courier New",
"Times New Roman",
- "Comic Sans", "MS Serif", "Tahoma",
"Verdana" };
+ private static final String NORMAL_FONT = "Normal"; //$NON-NLS-1$
+ 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 FormatControllerManager formatControllerManager;
@@ -77,11 +79,11 @@
ToolItem sep = new ToolItem(horBar, SWT.SEPARATOR);
Combo comboBlockFormat = new Combo(horBar, SWT.READ_ONLY);
- comboBlockFormat.add("Normal");
+ comboBlockFormat.add("Normal"); //$NON-NLS-1$
// comboBlockFormat.add("Formatted");
- comboBlockFormat.add("Address");
+ comboBlockFormat.add("Address"); //$NON-NLS-1$
for (int i = 1; i < 7; i++) {
- comboBlockFormat.add("Heading " + i);
+ comboBlockFormat.add("Heading " + i); //$NON-NLS-1$
}
// comboBlockFormat.add("Numbered List");
// comboBlockFormat.add("Bulleted List");
@@ -107,10 +109,11 @@
font = FONT_ARRAY;
}
comboFont.setItems(font);
- comboFont.select(30);
+ comboFont.add(NORMAL_FONT, 0);
+ comboFont.select(0);
comboFont.pack();
comboFont.setToolTipText(VpeUIMessages.FONT_NAME);
- comboFont.addListener(SWT.Selection, new
FontNameFormatController(formatControllerManager, comboFont));
+ comboFont.addListener(SWT.Selection, new
FontNameFormatController(formatControllerManager, comboFont, NORMAL_FONT));
sep.setWidth(comboFont.getSize().x);
sep.setControl(comboFont);
@@ -119,8 +122,9 @@
sep = new ToolItem(horBar, SWT.SEPARATOR);
Combo comboFontSize = new Combo(horBar, SWT.DROP_DOWN|SWT.COLOR_LIST_BACKGROUND );
for (int i = 1; i < 8; i++) {
- comboFontSize.add("" + i);
+ comboFontSize.add("" + i); //$NON-NLS-1$
}
+ comboFontSize.add(NORMAL_FONT, 0);
comboFontSize.setToolTipText(VpeUIMessages.FONT_SIZE);
comboFontSize.select(2);
comboFontSize.pack();
@@ -132,17 +136,17 @@
sep = new ToolItem(horBar, SWT.SEPARATOR);
itemDescriptors.add(new ToolItemDescriptor(sep, false, null, false));
- ToolItem item = createToolItem(horBar, SWT.CHECK, "icons/bold.gif",
VpeUIMessages.BOLD);
+ ToolItem item = createToolItem(horBar, SWT.CHECK, "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));
- item = createToolItem(horBar, SWT.CHECK, "icons/italic.gif",
VpeUIMessages.ITALIC);
+ item = createToolItem(horBar, SWT.CHECK, "icons/italic.gif",
VpeUIMessages.ITALIC); //$NON-NLS-1$
listener = new ItalicFormatController(formatControllerManager, item);
item.addListener(SWT.Selection, listener);
itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
- item = createToolItem(horBar, SWT.CHECK, "icons/uderline.gif",
VpeUIMessages.UNDERLINE);
+ item = createToolItem(horBar, SWT.CHECK, "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));
@@ -150,12 +154,12 @@
sep = new ToolItem(horBar, SWT.SEPARATOR);
itemDescriptors.add(new ToolItemDescriptor(sep, false, null, true));
- item = createToolItem(horBar, SWT.PUSH, "icons/background.gif",
VpeUIMessages.BACKGROUND_COLOR);
+ item = createToolItem(horBar, SWT.PUSH, "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));
- item = createToolItem(horBar, SWT.PUSH, "icons/foreground.gif",
VpeUIMessages.FOREGROUND_COLOR);
+ item = createToolItem(horBar, SWT.PUSH, "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));