Author: tchemit Date: 2010-06-14 17:16:22 +0200 (Mon, 14 Jun 2010) New Revision: 1967 Url: http://nuiton.org/repositories/revision/jaxx/1967 Log: - Evolution #685: Add import tag - improve tag handlers code (use constants, remove redundant initializers, ...) Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/spi/DefaultInitializer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/ScriptHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/StyleHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/CellHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/CompiledItemContainer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ItemHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSliderHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSpinnerHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSplitPaneHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JToolBarHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/RowHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TabHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/ColorConverter.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/InsetsConverter.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/KeyStrokeConverter.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/PrimitiveConverter.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/spi/DefaultInitializer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/spi/DefaultInitializer.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/spi/DefaultInitializer.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -25,44 +25,13 @@ package jaxx.compiler.spi; -import java.awt.Component; -import javax.swing.JCheckBox; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JEditorPane; -import javax.swing.JFormattedTextField; -import javax.swing.JFrame; -import javax.swing.JInternalFrame; -import javax.swing.JList; -import javax.swing.JMenu; -import javax.swing.JPasswordField; -import javax.swing.JPopupMenu; -import javax.swing.JProgressBar; -import javax.swing.JRadioButton; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JScrollPane; -import javax.swing.JSlider; -import javax.swing.JSpinner; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.JTextPane; -import javax.swing.JToggleButton; -import javax.swing.JToolBar; -import javax.swing.JTree; -import javax.swing.JWindow; -import javax.swing.text.JTextComponent; - import jaxx.compiler.JAXXCompiler; import jaxx.compiler.beans.BeanInfoUtil; - import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; - import jaxx.compiler.tags.DefaultComponentHandler; import jaxx.compiler.tags.DefaultObjectHandler; +import jaxx.compiler.tags.ImportHandler; import jaxx.compiler.tags.ScriptHandler; import jaxx.compiler.tags.StyleHandler; import jaxx.compiler.tags.TagHandler; @@ -98,8 +67,6 @@ import jaxx.compiler.tags.validator.BeanValidatorHandler; import jaxx.compiler.tags.validator.ExcludeFieldValidatorHandler; import jaxx.compiler.tags.validator.FieldValidatorHandler; - - import jaxx.runtime.swing.Application; import jaxx.runtime.swing.JAXXButtonGroup; import jaxx.runtime.swing.JAXXComboBox; @@ -111,7 +78,37 @@ import jaxx.runtime.swing.editor.LocaleEditor; import jaxx.runtime.validator.swing.SwingValidator; -/** +import javax.swing.JCheckBox; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JEditorPane; +import javax.swing.JFormattedTextField; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.JList; +import javax.swing.JMenu; +import javax.swing.JPasswordField; +import javax.swing.JPopupMenu; +import javax.swing.JProgressBar; +import javax.swing.JRadioButton; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JScrollPane; +import javax.swing.JSlider; +import javax.swing.JSpinner; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JTextPane; +import javax.swing.JToggleButton; +import javax.swing.JToolBar; +import javax.swing.JTree; +import javax.swing.JWindow; +import javax.swing.text.JTextComponent; +import java.awt.Component; + +/** * Initializes support provided from JAXX (java, swing and validation). * * @plexus.component role-hint="default" role="jaxx.compiler.spi.Initializer" @@ -124,28 +121,30 @@ BeanInfoUtil.addJaxxBeanInfoPath("jaxx.runtime.swing"); registerDefaultNamespace("javax.swing.*", - JEditorPane.class, - JFormattedTextField.class, - JPasswordField.class, - JTextArea.class, - JTextField.class, - JTextPane.class); + JEditorPane.class, + JFormattedTextField.class, + JPasswordField.class, + JTextArea.class, + JTextField.class, + JTextPane.class + ); // // Register tags // - registerTag(JAXXCompiler.JAXX_NAMESPACE, "script", new ScriptHandler()); - registerTag(JAXXCompiler.JAXX_NAMESPACE, "style", new StyleHandler()); + registerTag(JAXXCompiler.JAXX_NAMESPACE, ScriptHandler.TAG_NAME, new ScriptHandler()); + registerTag(JAXXCompiler.JAXX_NAMESPACE, StyleHandler.TAG_NAME, new StyleHandler()); + registerTag(JAXXCompiler.JAXX_NAMESPACE, ImportHandler.TAG_NAME, new ImportHandler()); //TC-20091005 why the namespace was on awt ? ButtonGroup is from javax.swing registerTag("javax.swing.*", "ButtonGroup", new DefaultObjectHandler(ClassDescriptorHelper.getClassDescriptor(JAXXButtonGroup.class))); // TagManager.registerTag("java.awt.*", "ButtonGroup", new DefaultObjectHandler(ClassDescriptorHelper.getClassDescriptor(JAXXButtonGroup.class))); - registerTag(JAXXCompiler.JAXX_NAMESPACE, "tab", new TabHandler()); - registerTag(JAXXCompiler.JAXX_NAMESPACE, "row", new RowHandler()); - registerTag(JAXXCompiler.JAXX_NAMESPACE, "cell", new CellHandler()); - registerTag(JAXXCompiler.JAXX_NAMESPACE, "item", new ItemHandler()); + registerTag(JAXXCompiler.JAXX_NAMESPACE, TabHandler.TAG_NAME, new TabHandler()); + registerTag(JAXXCompiler.JAXX_NAMESPACE, RowHandler.TAG_NAME, new RowHandler()); + registerTag(JAXXCompiler.JAXX_NAMESPACE, CellHandler.TAG_NAME, new CellHandler()); + registerTag(JAXXCompiler.JAXX_NAMESPACE, ItemHandler.TAG_NAME, new ItemHandler()); registerTag(JAXXCompiler.JAXX_NAMESPACE, BeanValidatorHandler.TAG, new BeanValidatorHandler(ClassDescriptorHelper.getClassDescriptor(SwingValidator.class))); @@ -213,7 +212,7 @@ Class<? extends TagHandler> handlerClass) { ClassDescriptor classDescriptor = ClassDescriptorHelper.getClassDescriptor(beanClass); - + TagManager.registerBean(classDescriptor, handlerClass); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/ScriptHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/ScriptHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/ScriptHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -45,6 +45,8 @@ */ public class ScriptHandler implements TagHandler { + public static final String TAG_NAME = "script"; + public static final String SOURCE_ATTRIBUTE = "source"; @Override Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/StyleHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/StyleHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/StyleHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -26,8 +26,8 @@ package jaxx.compiler.tags; import jaxx.compiler.CompilerException; +import jaxx.compiler.JAXXCompiler; import jaxx.compiler.UnsupportedAttributeException; -import jaxx.compiler.JAXXCompiler; import jaxx.compiler.css.StylesheetHelper; import jaxx.runtime.css.Stylesheet; import org.w3c.dom.Attr; @@ -39,7 +39,6 @@ import java.io.File; import java.io.IOException; -import java.io.StringWriter; /** * Handles the <code><style></code> tag. @@ -47,6 +46,9 @@ * @author Ethan Nicholas */ public class StyleHandler implements TagHandler { + + public static final String TAG_NAME = "style"; + public static final String SOURCE_ATTRIBUTE = "source"; @Override Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ApplicationHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -37,7 +37,10 @@ import javax.swing.WindowConstants; public class ApplicationHandler extends JWindowHandler { + public static final String ATTRIBUTE_LOOK_AND_FEEL = "lookAndFeel"; + public static final String ATTRIBUTE_DEFAULT_CLOSE_OPERATION = "defaultCloseOperation"; + public ApplicationHandler(ClassDescriptor beanClass) { super(beanClass); ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, Application.class); @@ -45,7 +48,7 @@ @Override public void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler) throws CompilerException { - if (propertyName.equals("lookAndFeel") && stringValue != null && !stringValue.trim().startsWith("{")) { + if (propertyName.equals(ATTRIBUTE_LOOK_AND_FEEL) && stringValue != null && !stringValue.trim().startsWith("{")) { compiler.appendBodyCode("{ " + object.getJavaCode() + ".setLookAndFeel(" + TypeManager.getJavaCode(stringValue) + "); }" + JAXXCompiler.getLineSeparator()); } else { super.setAttribute(object, propertyName, stringValue, inline, compiler); @@ -55,6 +58,6 @@ @Override protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) throws CompilerException { super.setDefaults(object, tag, compiler); - setAttribute(object, "defaultCloseOperation", String.valueOf(WindowConstants.EXIT_ON_CLOSE), false, compiler); + setAttribute(object, ATTRIBUTE_DEFAULT_CLOSE_OPERATION, String.valueOf(WindowConstants.EXIT_ON_CLOSE), false, compiler); } } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/CellHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/CellHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/CellHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -26,8 +26,8 @@ package jaxx.compiler.tags.swing; import jaxx.compiler.CompilerException; +import jaxx.compiler.JAXXCompiler; import jaxx.compiler.UnsupportedAttributeException; -import jaxx.compiler.JAXXCompiler; import jaxx.compiler.tags.TagHandler; import jaxx.compiler.types.TypeManager; import org.w3c.dom.Attr; @@ -43,6 +43,61 @@ public class CellHandler implements TagHandler { + public static final String TAG_NAME = "cell"; + + public static final String ATTRIBUTE_INSETS = "insets"; + + public static final String ATTRIBUTE_WEIGHTX = "weightx"; + + public static final String ATTRIBUTE_WEIGHTY = "weighty"; + + public static final String ATTRIBUTE_COLUMNS = "columns"; + + public static final String ATTRIBUTE_ROWS = "rows"; + + public static final String ATTRIBUTE_FILL = "fill"; + + enum Fill { + none(GridBagConstraints.NONE), + horizontal(GridBagConstraints.HORIZONTAL), + vertical(GridBagConstraints.VERTICAL), + both(GridBagConstraints.BOTH); + + private final int intValue; + + Fill(int intValue) { + this.intValue = intValue; + } + + public int getIntValue() { + return intValue; + } + } + + public static final String ATTRIBUTE_ANCHOR = "anchor"; + + enum Anchor { + north(GridBagConstraints.NORTH), + northeast(GridBagConstraints.NORTHEAST), + east(GridBagConstraints.EAST), + southeast(GridBagConstraints.SOUTHEAST), + south(GridBagConstraints.SOUTH), + southwest(GridBagConstraints.SOUTHEAST), + west(GridBagConstraints.WEST), + northwest(GridBagConstraints.NORTHWEST), + center(GridBagConstraints.CENTER); + + private final int intValue; + + Anchor(int intValue) { + this.intValue = intValue; + } + + public int getIntValue() { + return intValue; + } + } + @Override public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { compileChildrenFirstPass(tag, compiler); @@ -65,51 +120,49 @@ public static void setAttribute(GridBagConstraints c, String name, String value) throws CompilerException { value = value.trim(); - if (name.equals("insets")) { + if (name.equals(ATTRIBUTE_INSETS)) { c.insets = (Insets) TypeManager.convertFromString(value, Insets.class); - } else if (name.equals("weightx")) { + } else if (name.equals(ATTRIBUTE_WEIGHTX)) { c.weightx = Double.parseDouble(value); - } else if (name.equals("weighty")) { + } else if (name.equals(ATTRIBUTE_WEIGHTY)) { c.weighty = Double.parseDouble(value); - } else if (name.equals("columns")) { + } else if (name.equals(ATTRIBUTE_COLUMNS)) { c.gridwidth = Integer.parseInt(value); - } else if (name.equals("rows")) { + } else if (name.equals(ATTRIBUTE_ROWS)) { c.gridheight = Integer.parseInt(value); - } else if (name.equals("fill")) { - if (value.equals("none")) { - c.fill = GridBagConstraints.NONE; - } else if (value.equals("horizontal")) { - c.fill = GridBagConstraints.HORIZONTAL; - } else if (value.equals("vertical")) { - c.fill = GridBagConstraints.VERTICAL; - } else if (value.equals("both")) { - c.fill = GridBagConstraints.BOTH; - } else { - throw new IllegalArgumentException("invalid value for fill attribute: '" + value + "'"); + } else if (name.equals(ATTRIBUTE_FILL)) { + Fill fill = Fill.valueOf(value); + if (fill == null) { + throw new CompilerException("invalid value for fill attribute: '" + value + "'"); } - } else if (name.equals("anchor")) { - //todo use a converter - if (value.equals("north")) { - c.anchor = GridBagConstraints.NORTH; - } else if (value.equals("northeast")) { - c.anchor = GridBagConstraints.NORTHEAST; - } else if (value.equals("east")) { - c.anchor = GridBagConstraints.EAST; - } else if (value.equals("southeast")) { - c.anchor = GridBagConstraints.SOUTHEAST; - } else if (value.equals("south")) { - c.anchor = GridBagConstraints.SOUTH; - } else if (value.equals("southwest")) { - c.anchor = GridBagConstraints.SOUTHWEST; - } else if (value.equals("west")) { - c.anchor = GridBagConstraints.WEST; - } else if (value.equals("northwest")) { - c.anchor = GridBagConstraints.NORTHWEST; - } else if (value.equals("center")) { - c.anchor = GridBagConstraints.CENTER; - } else { - throw new IllegalArgumentException("invalid value for anchor attribute: '" + value + "'"); + c.fill = fill.getIntValue(); + } else if (name.equals(ATTRIBUTE_ANCHOR)) { + Anchor anchor = Anchor.valueOf(value); + if (anchor == null) { + throw new CompilerException("invalid value for anchor attribute: '" + value + "'"); } + c.anchor = anchor.getIntValue(); +// if (value.equals(ANCHOR_VALUE_NORTH)) { +// c.anchor = GridBagConstraints.NORTH; +// } else if (value.equals(ANCHOR_VALUE_NORTHEAST)) { +// c.anchor = GridBagConstraints.NORTHEAST; +// } else if (value.equals(ANCHOR_VALUE_EAST)) { +// c.anchor = GridBagConstraints.EAST; +// } else if (value.equals(ANCHOR_VALUE_SOUTHEAST)) { +// c.anchor = GridBagConstraints.SOUTHEAST; +// } else if (value.equals(ANCHOR_VALUE_SOUTH)) { +// c.anchor = GridBagConstraints.SOUTH; +// } else if (value.equals(ANCHOR_VALUE_SOUTHWEST)) { +// c.anchor = GridBagConstraints.SOUTHWEST; +// } else if (value.equals(ANCHOR_VALUE_WEST)) { +// c.anchor = GridBagConstraints.WEST; +// } else if (value.equals(ANCHOR_VALUE_NORTHWEST)) { +// c.anchor = GridBagConstraints.NORTHWEST; +// } else if (value.equals(ANCHOR_VALUE_CENTER)) { +// c.anchor = GridBagConstraints.CENTER; +// } else { +// throw new IllegalArgumentException("invalid value for anchor attribute: '" + value + "'"); +// } } else { throw new UnsupportedAttributeException(name); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/CompiledItemContainer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/CompiledItemContainer.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/CompiledItemContainer.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -56,7 +56,7 @@ } public void closeItem(Item item) { - if (openNodes.pop() != item) { + if (!item.equals(openNodes.pop())) { throw new IllegalArgumentException(item + " was not at the top of the item stack"); } } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ItemHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ItemHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/ItemHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -44,8 +44,12 @@ public class ItemHandler implements TagHandler { + public static final String TAG_NAME = "item"; + private String DATA_BINDING = "<data binding has not been processed yet>"; + public static final String ATTRIBUTE_ID = "id"; + @Override public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { compileChildrenFirstPass(tag, compiler); @@ -53,7 +57,7 @@ @Override public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { - String id = tag.getAttribute("id"); + String id = tag.getAttribute(ATTRIBUTE_ID); if (id == null || id.length() == 0) { id = compiler.getAutoId(Item.class.getSimpleName()); // id = compiler.getAutoId(ClassDescriptorHelper.getClassDescriptor(Item.class)); @@ -67,7 +71,7 @@ Attr attribute = (Attr) children.item(i); String name = attribute.getName(); String attrValue = attribute.getValue(); - if (name.equals("id")) { + if (name.equals(ATTRIBUTE_ID)) { // already handled continue; } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSliderHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSliderHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSliderHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -38,6 +38,7 @@ import javax.swing.event.ChangeListener; public class JSliderHandler extends DefaultComponentHandler { + public static final String ATTRIBUTE_VALUE = "value"; public JSliderHandler(ClassDescriptor beanClass) { super(beanClass); @@ -48,7 +49,7 @@ @Override protected int getAttributeOrdering(Attr attr) { - if (attr.getName().equals("value")) { + if (attr.getName().equals(ATTRIBUTE_VALUE)) { return 1; } else { return super.getAttributeOrdering(attr); @@ -58,7 +59,7 @@ @Override protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) throws CompilerException { super.setDefaults(object, tag, compiler); - setAttribute(object, "value", "0", false, compiler); + setAttribute(object, ATTRIBUTE_VALUE, "0", false, compiler); } @Override Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSpinnerHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSpinnerHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSpinnerHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -49,9 +49,9 @@ public static class CompiledSpinner extends CompiledObject { - Integer minimum = null; - Integer maximum = null; - Integer value = null; + Integer minimum; + Integer maximum; + Integer value; public CompiledSpinner(String id, ClassDescriptor objectClass, JAXXCompiler compiler) throws CompilerException { super(id, objectClass, compiler); @@ -99,7 +99,7 @@ compiler.reportError("constructorParams and minimum/maximum may not both be specified for the same JSpinner"); } if (spinner.minimum == null) { - spinner.minimum = Math.min(0, spinner.maximum != null ? spinner.maximum.intValue() : 0); + spinner.minimum = Math.min(0, spinner.maximum != null ? spinner.maximum : 0); } if (spinner.maximum == null) { spinner.maximum = Math.max(100, spinner.minimum.intValue()); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSplitPaneHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSplitPaneHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSplitPaneHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -25,27 +25,35 @@ package jaxx.compiler.tags.swing; +import jaxx.compiler.CompiledObject; import jaxx.compiler.CompilerException; -import jaxx.compiler.CompiledObject; import jaxx.compiler.JAXXCompiler; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.compiler.tags.DefaultComponentHandler; -import org.w3c.dom.Element; import javax.swing.JSplitPane; -import java.awt.Component; public class JSplitPaneHandler extends DefaultComponentHandler { + public static final String ATTRIBUTE_ORIENTATION = "orientation"; + + public static final String ORIENTATION_VALUE_HORIZONTAL = "horizontal"; + + public static final String ORIENTATION_VALUE_VERTICAL = "vertical"; + + public static final String ORIENTATION_VALUE_VERTICAL_SPLIT = "vertical_split"; + + public static final String ORIENTATION_VALUE_HORIZONTAL_SPLIT = "horizontal_split"; + public JSplitPaneHandler(ClassDescriptor beanClass) { super(beanClass); ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, JSplitPane.class); } - protected Component createRawComponent(Element tag) { - return new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); - } +// protected Component createRawComponent(Element tag) { +// return new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); +// } /** * Add support for <code>orientation="vertical"</code> and <code>orientation="horizontal"</code>. The @@ -54,12 +62,12 @@ */ @Override protected int constantValue(String key, String value) { - if (key.equals("orientation")) { + if (key.equals(ATTRIBUTE_ORIENTATION)) { value = value.trim().toLowerCase(); - if (value.equals("horizontal") || value.equals("horizontal_split")) { + if (value.equals(ORIENTATION_VALUE_HORIZONTAL) || value.equals(ORIENTATION_VALUE_HORIZONTAL_SPLIT)) { return JSplitPane.HORIZONTAL_SPLIT; } - if (value.equals("vertical") || value.equals("vertical_split")) { + if (value.equals(ORIENTATION_VALUE_VERTICAL) || value.equals(ORIENTATION_VALUE_VERTICAL_SPLIT)) { return JSplitPane.VERTICAL_SPLIT; } throw new IllegalArgumentException("orientation must be 'horizontal' or 'vertical', found '" + value + "'"); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -25,8 +25,8 @@ package jaxx.compiler.tags.swing; +import jaxx.compiler.CompiledObject; import jaxx.compiler.CompilerException; -import jaxx.compiler.CompiledObject; import jaxx.compiler.I18nHelper; import jaxx.compiler.JAXXCompiler; import jaxx.compiler.reflect.ClassDescriptor; @@ -43,6 +43,10 @@ public class JTabbedPaneHandler extends DefaultComponentHandler { + public static final String ATTRIBUTE_TITLE = "title"; + + public static final String ATTRIBUTE_TOOL_TIP_TEXT = "toolTipText"; + public JTabbedPaneHandler(ClassDescriptor beanClass) { super(beanClass); ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, JTabbedPane.class); @@ -51,9 +55,12 @@ public static class CompiledTabbedPane extends CompiledObject { private static final TabInfo USED = new TabInfo("ALREADY USED"); + int tabCount; + TabInfo tabInfo; + public CompiledTabbedPane(String id, ClassDescriptor objectClass, JAXXCompiler compiler) throws CompilerException { super(id, objectClass, compiler); } @@ -69,7 +76,7 @@ if (tabInfo == null) { compiler.reportError("JTabbedPaneHandler may only have 'tab' tags as children (found " + child.getObjectClass() + ")"); return; - } else if (tabInfo == USED) { + } else if (USED.equals(tabInfo)) { compiler.reportError("<tab> tags may only have one child component"); return; } @@ -79,10 +86,10 @@ String title = tabInfo.getTitle(); if (title != null) { - if (I18nHelper.isI18nAttribute("title")) { + if (I18nHelper.isI18nAttribute(ATTRIBUTE_TITLE)) { if (!title.startsWith("_(\"")) { // we did not have the invocation code, add it - title = I18nHelper.addI18nInvocation(getId(), "title", TypeManager.getJavaCode(title), compiler); + title = I18nHelper.addI18nInvocation(getId(), ATTRIBUTE_TITLE, TypeManager.getJavaCode(title), compiler); } } else { title = TypeManager.getJavaCode(title); @@ -92,10 +99,10 @@ String toolTipText = tabInfo.getToolTipText(); if (toolTipText != null) { - if (I18nHelper.isI18nAttribute("toolTipText")) { + if (I18nHelper.isI18nAttribute(ATTRIBUTE_TOOL_TIP_TEXT)) { if (!toolTipText.startsWith("_(\"")) { // we did not have the invocation code, add it - toolTipText = I18nHelper.addI18nInvocation(getId(), "toolTipText", TypeManager.getJavaCode(toolTipText), compiler); + toolTipText = I18nHelper.addI18nInvocation(getId(), ATTRIBUTE_TOOL_TIP_TEXT, TypeManager.getJavaCode(toolTipText), compiler); } } else { toolTipText = TypeManager.getJavaCode(toolTipText); @@ -138,7 +145,7 @@ appendAdditionCode(getId() + ".setDisabledIconAt(" + tabIndex + ", " + disabledIcon + ");"); } - String tabComponent= tabInfo.getTabComponentStr(); + String tabComponent = tabInfo.getTabComponentStr(); if (tabComponent != null) { appendAdditionCode(getId() + ".setTabComponentAt(" + tabIndex + ", " + tabComponent + ");"); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -25,8 +25,8 @@ package jaxx.compiler.tags.swing; +import jaxx.compiler.CompiledObject; import jaxx.compiler.CompilerException; -import jaxx.compiler.CompiledObject; import jaxx.compiler.JAXXCompiler; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; @@ -43,6 +43,14 @@ private static final int DEFAULT_COLUMNS = 15; + public static final String ATTRIBUTE_LINE_WRAP = "lineWrap"; + + public static final String ATTRIBUTE_WRAP_STYLE_WORD = "wrapStyleWord"; + + public static final String ATTRIBUTE_COLUMNS = "columns"; + + public static final String ATTRIBUTE_TEXT = "text"; + public JTextComponentHandler(ClassDescriptor beanClass) { super(beanClass); ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, JTextComponent.class); @@ -53,20 +61,20 @@ super.setDefaults(object, tag, compiler); try { object.getObjectClass().getMethodDescriptor("setColumns", ClassDescriptorHelper.getClassDescriptor(int.class)); - setAttribute(object, "columns", String.valueOf(DEFAULT_COLUMNS), false, compiler); + setAttribute(object, ATTRIBUTE_COLUMNS, String.valueOf(DEFAULT_COLUMNS), false, compiler); } catch (NoSuchMethodException e) { // ignore ? } if (ClassDescriptorHelper.getClassDescriptor(JTextArea.class).isAssignableFrom(object.getObjectClass())) { - setAttribute(object, "lineWrap", "true", false, compiler); - setAttribute(object, "wrapStyleWord", "true", false, compiler); + setAttribute(object, ATTRIBUTE_LINE_WRAP, "true", false, compiler); + setAttribute(object, ATTRIBUTE_WRAP_STYLE_WORD, "true", false, compiler); } } @Override public String getSetPropertyCode(String id, String name, String valueCode, JAXXCompiler compiler) throws CompilerException { - if (name.equals("text")) { + if (name.equals(ATTRIBUTE_TEXT)) { return SwingUtil.class.getName() + ".setText(" + id + ", " + valueCode + ");\n"; //return "jaxx.runtime.swing.Utils.setText(" + id + ", " + valueCode + ");\n"; } @@ -77,7 +85,7 @@ protected int getAttributeOrdering(Attr attr) { // delay text in case other attributes affect how it's processed, as is the case // with JEditorPane's contentType - if (attr.getName().equals("text")) { + if (attr.getName().equals(ATTRIBUTE_TEXT)) { return 1; } return super.getAttributeOrdering(attr); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JToolBarHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JToolBarHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JToolBarHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -25,6 +25,7 @@ package jaxx.compiler.tags.swing; +import jaxx.compiler.CompilerException; import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorHelper; import jaxx.compiler.tags.DefaultComponentHandler; @@ -32,7 +33,24 @@ import javax.swing.JToolBar; public class JToolBarHandler extends DefaultComponentHandler { + public static final String ATTRIBUTE_ORIENTATION = "orientation"; + + enum Orientation { + horizontal(JToolBar.HORIZONTAL), + vertical(JToolBar.VERTICAL); + + private final int intValue; + + Orientation(int intValue) { + this.intValue = intValue; + } + + public int getIntValue() { + return intValue; + } + } + public JToolBarHandler(ClassDescriptor beanClass) { super(beanClass); ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, JToolBar.class); @@ -45,15 +63,13 @@ */ @Override protected int constantValue(String key, String value) { - if (key.equals("orientation")) { + if (key.equals(ATTRIBUTE_ORIENTATION)) { value = value.trim().toLowerCase(); - if (value.equals("horizontal")) { - return JToolBar.HORIZONTAL; + Orientation fill = Orientation.valueOf(value); + if (fill == null) { + throw new CompilerException("invalid value for orientation attribute: '" + value + "'"); } - if (value.equals("vertical")) { - return JToolBar.VERTICAL; - } - throw new IllegalArgumentException("orientation must be 'horizontal' or 'vertical', found '" + value + "'"); + return fill.getIntValue(); } return super.constantValue(key, value); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/RowHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/RowHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/RowHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -40,6 +40,8 @@ public class RowHandler implements TagHandler { + public static final String TAG_NAME = "row"; + @Override public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { compileChildrenFirstPass(tag, compiler); @@ -66,7 +68,7 @@ int nodeType = node.getNodeType(); if (nodeType == Node.ELEMENT_NODE) { Element child = (Element) node; - if (!child.getLocalName().equals("cell")) { + if (!child.getLocalName().equals(CellHandler.TAG_NAME)) { compiler.reportError("tag '" + tag.getLocalName() + "' may only contain cell tags as children"); } compileChildTagFirstPass(child, compiler); @@ -86,7 +88,7 @@ int nodeType = node.getNodeType(); if (nodeType == Node.ELEMENT_NODE) { Element child = (Element) node; - if (!child.getLocalName().equals("cell")) { + if (!child.getLocalName().equals(CellHandler.TAG_NAME)) { compiler.reportError("tag '" + tag.getLocalName() + "' may only contain cell tags as children"); } compileChildTagSecondPass(child, compiler); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TabHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TabHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TabHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -25,8 +25,8 @@ package jaxx.compiler.tags.swing; +import jaxx.compiler.CompiledObject; import jaxx.compiler.CompilerException; -import jaxx.compiler.CompiledObject; import jaxx.compiler.I18nHelper; import jaxx.compiler.JAXXCompiler; import jaxx.compiler.binding.DataBindingHelper; @@ -49,6 +49,30 @@ public class TabHandler implements TagHandler { + public static final String TAG_NAME = "tab"; + + public static final String ATTRIBUTE_ID = "id"; + + public static final String ATTRIBUTE_TITLE = "title"; + + public static final String ATTRIBUTE_TOOL_TIP_TEXT = "toolTipText"; + + public static final String ATTRIBUTE_ICON = "icon"; + + public static final String ATTRIBUTE_ENABLED = "enabled"; + + public static final String ATTRIBUTE_DISABLED_ICON = "disabledIcon"; + + public static final String ATTRIBUTE_MNEMONIC = "mnemonic"; + + public static final String ATTRIBUTE_DISPLAYED_MNEMONIC_INDEX = "displayedMnemonicIndex"; + + public static final String ATTRIBUTE_FOREGROUND = "foreground"; + + public static final String ATTRIBUTE_BACKGROUND = "background"; + + public static final String ATTRIBUTE_TAB_COMPONENT = "tabComponent"; + @Override public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { compileChildrenFirstPass(tag, compiler); @@ -63,7 +87,7 @@ JTabbedPaneHandler.CompiledTabbedPane tabs = (JTabbedPaneHandler.CompiledTabbedPane) compiler.getOpenComponent(); - String id = tag.getAttribute("id"); + String id = tag.getAttribute(ATTRIBUTE_ID); if (id == null || id.length() == 0) { id = compiler.getAutoId(TabInfo.class.getSimpleName()); // id = compiler.getAutoId(ClassDescriptorHelper.getClassDescriptor(TabInfo.class)); @@ -95,45 +119,45 @@ if (I18nHelper.isI18nableAttribute(name, compiler)) { value = valueCode = I18nHelper.addI18nInvocation(id, name, valueCode, compiler); } - if (name.equals("id")) { + if (name.equals(ATTRIBUTE_ID)) { // ignore, already handled - } else if (name.equals("title")) { + } else if (name.equals(ATTRIBUTE_TITLE)) { tabInfo.setTitle(value); compiledTabInfo.appendInitializationCode(id + ".setTitle(" + valueCode + ");"); //compiledTabInfo.appendInitializationCode(id + ".setTitle(" + TypeManager.getJavaCode(value) + ");"); - } else if (name.equals("toolTipText")) { + } else if (name.equals(ATTRIBUTE_TOOL_TIP_TEXT)) { tabInfo.setToolTipText(value); compiledTabInfo.appendInitializationCode(id + ".setToolTipText(" + valueCode + ");"); //compiledTabInfo.appendInitializationCode(id + ".setToolTipText(" + TypeManager.getJavaCode(value) + ");"); - } else if (name.equals("icon")) { + } else if (name.equals(ATTRIBUTE_ICON)) { Icon icon = (Icon) TypeManager.convertFromString(value, Icon.class); tabInfo.setIcon(icon); compiledTabInfo.appendInitializationCode(id + ".setIcon(" + TypeManager.getJavaCode(icon) + ");"); - } else if (name.equals("enabled")) { + } else if (name.equals(ATTRIBUTE_ENABLED)) { boolean enabled = (Boolean) TypeManager.convertFromString(value, Boolean.class); tabInfo.setEnabled(enabled); compiledTabInfo.appendInitializationCode(id + ".setEnabled(" + enabled + ");"); - } else if (name.equals("disabledIcon")) { + } else if (name.equals(ATTRIBUTE_DISABLED_ICON)) { Icon disabledIcon = (Icon) TypeManager.convertFromString(value, Icon.class); tabInfo.setDisabledIcon(disabledIcon); compiledTabInfo.appendInitializationCode(id + ".setDisabledIcon(" + TypeManager.getJavaCode(disabledIcon) + ");"); - } else if (name.equals("mnemonic")) { + } else if (name.equals(ATTRIBUTE_MNEMONIC)) { int mnemonic = (Character) TypeManager.convertFromString(value, char.class); tabInfo.setMnemonic(mnemonic); compiledTabInfo.appendInitializationCode(id + ".setMnemonic(" + mnemonic + ");"); - } else if (name.equals("displayedMnemonicIndex")) { + } else if (name.equals(ATTRIBUTE_DISPLAYED_MNEMONIC_INDEX)) { int displayedMnemonicIndex = (Integer) TypeManager.convertFromString(value, int.class); tabInfo.setDisplayedMnemonicIndex(displayedMnemonicIndex); compiledTabInfo.appendInitializationCode(id + ".setDisplayedMnemonicIndex(" + displayedMnemonicIndex + ");"); - } else if (name.equals("foreground")) { + } else if (name.equals(ATTRIBUTE_FOREGROUND)) { Color foreground = (Color) TypeManager.convertFromString(value, Color.class); tabInfo.setForeground(foreground); compiledTabInfo.appendInitializationCode(id + ".setForeground(" + TypeManager.getJavaCode(foreground) + ");"); - } else if (name.equals("background")) { + } else if (name.equals(ATTRIBUTE_BACKGROUND)) { Color background = (Color) TypeManager.convertFromString(value, Color.class); tabInfo.setBackground(background); compiledTabInfo.appendInitializationCode(id + ".setBackground(" + TypeManager.getJavaCode(background) + ");"); - } else if (name.equals("tabComponent")) { + } else if (name.equals(ATTRIBUTE_TAB_COMPONENT)) { tabInfo.setTabComponentStr(TypeManager.getJavaCode(value)); compiledTabInfo.appendInitializationCode(id + ".setTabComponent(" + TypeManager.getJavaCode(value) + ");"); } else { Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/TableHandler.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -66,8 +66,8 @@ private List<Integer> rowSpans = new ArrayList<Integer>(); private GridBagConstraints tableConstraints; - private GridBagConstraints rowConstraints = null; - private GridBagConstraints cellConstraints = null; + private GridBagConstraints rowConstraints; + private GridBagConstraints cellConstraints; private boolean emptyCell; public CompiledTable(String id, ClassDescriptor objectClass, JAXXCompiler compiler) throws CompilerException { Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/ColorConverter.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/ColorConverter.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/ColorConverter.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -45,7 +45,7 @@ @Override public Object convertFromString(String string, Class<?> type) { - if (type != Color.class) { + if (!Color.class.equals(type)) { throw new IllegalArgumentException("unsupported type: " + type); } if (string.length() == 7 && string.charAt(0) == '#') { Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/InsetsConverter.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/InsetsConverter.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/InsetsConverter.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -43,7 +43,7 @@ @Override public Object convertFromString(String string, Class<?> type) { - if (type != Insets.class) { + if (!Insets.class.equals(type)) { throw new IllegalArgumentException("unsupported type: " + type); } StringTokenizer tokenizer = new StringTokenizer(string, ","); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/KeyStrokeConverter.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/KeyStrokeConverter.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/KeyStrokeConverter.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -41,7 +41,7 @@ @Override public Object convertFromString(String string, Class<?> type) { - if (type != KeyStroke.class) { + if (!KeyStroke.class.equals(type)) { throw new IllegalArgumentException("unsupported type: " + type); } return KeyStroke.getKeyStroke(string); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/PrimitiveConverter.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/PrimitiveConverter.java 2010-06-14 12:07:18 UTC (rev 1966) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/types/PrimitiveConverter.java 2010-06-14 15:16:22 UTC (rev 1967) @@ -84,13 +84,13 @@ @Override public Object convertFromString(String string, Class<?> type) { - if (type == String.class || type == Object.class || type == null) { + if (String.class.equals(type) || Object.class.equals(type) || type == null) { return string; } - if (type == int.class || type == Integer.class) { + if (int.class.equals(type) || Integer.class.equals(type)) { return Integer.valueOf(string); } - if (type == boolean.class || type == Boolean.class) { + if (boolean.class.equals(type) || Boolean.class.equals(type)) { if (string.toLowerCase().equals("true")) { return Boolean.TRUE; } @@ -99,22 +99,22 @@ } throw new IllegalArgumentException("expected 'true' or 'false', found '" + string + "'"); } - if (type == byte.class || type == Byte.class) { + if (byte.class.equals(type) || Byte.class.equals(type)) { return Byte.valueOf(string); } - if (type == short.class || type == Short.class) { + if (short.class.equals(type) || Short.class.equals(type)) { return Short.valueOf(string); } - if (type == long.class || type == Long.class) { + if (long.class.equals(type) || Long.class.equals(type)) { return Long.valueOf(string); } - if (type == float.class || type == Float.class) { + if (float.class.equals(type) || Float.class.equals(type)) { return Float.valueOf(string); } - if (type == double.class || type == Double.class) { + if (double.class.equals(type) || Double.class.equals(type)) { return Double.valueOf(string); } - if (type == char.class || type == Character.class) { + if (char.class.equals(type) || Character.class.equals(type)) { if (string.length() == 1) { return string.charAt(0); }