[Buix-commits] r1118 - in lutinjaxx/branches/storm_1: jaxx-compiler-swing/src/main/java/jaxx/tags/swing jaxx-runtime-swing jaxx-runtime-swing/src/main/java/jaxx/runtime/swing
Author: tchemit Date: 2009-01-05 08:43:05 +0000 (Mon, 05 Jan 2009) New Revision: 1118 Modified: lutinjaxx/branches/storm_1/jaxx-compiler-swing/src/main/java/jaxx/tags/swing/CellHandler.java lutinjaxx/branches/storm_1/jaxx-runtime-swing/changelog.txt lutinjaxx/branches/storm_1/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/CardLayout2.java Log: improve CardLayout2 reformat code in CellHandler Modified: lutinjaxx/branches/storm_1/jaxx-compiler-swing/src/main/java/jaxx/tags/swing/CellHandler.java =================================================================== --- lutinjaxx/branches/storm_1/jaxx-compiler-swing/src/main/java/jaxx/tags/swing/CellHandler.java 2009-01-02 11:02:06 UTC (rev 1117) +++ lutinjaxx/branches/storm_1/jaxx-compiler-swing/src/main/java/jaxx/tags/swing/CellHandler.java 2009-01-05 08:43:05 UTC (rev 1118) @@ -21,12 +21,12 @@ import java.io.IOException; public class CellHandler implements TagHandler { - public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { compileChildrenFirstPass(tag, compiler); } - public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { Node parent = tag.getParentNode(); if (parent.getNodeType() != Node.ELEMENT_NODE || !parent.getLocalName().equals("row")) { compiler.reportError("cell tag may only appear within row tag"); @@ -43,50 +43,54 @@ public static void setAttribute(GridBagConstraints c, String name, String value) throws CompilerException { value = value.trim(); - if (name.equals("insets")) + if (name.equals("insets")) { c.insets = (Insets) TypeManager.convertFromString(value, Insets.class); - else if (name.equals("weightx")) + } else if (name.equals("weightx")) { c.weightx = Double.parseDouble(value); - else if (name.equals("weighty")) + } else if (name.equals("weighty")) { c.weighty = Double.parseDouble(value); - else if (name.equals("columns")) + } else if (name.equals("columns")) { c.gridwidth = Integer.parseInt(value); - else if (name.equals("rows")) + } else if (name.equals("rows")) { c.gridheight = Integer.parseInt(value); - else if (name.equals("fill")) { - if (value.equals("none")) + } else if (name.equals("fill")) { + if (value.equals("none")) { c.fill = GridBagConstraints.NONE; - else if (value.equals("horizontal")) + } else if (value.equals("horizontal")) { c.fill = GridBagConstraints.HORIZONTAL; - else if (value.equals("vertical")) + } else if (value.equals("vertical")) { c.fill = GridBagConstraints.VERTICAL; - else if (value.equals("both")) + } else if (value.equals("both")) { c.fill = GridBagConstraints.BOTH; - else + } else { throw new IllegalArgumentException("invalid value for fill attribute: '" + value + "'"); + } } else if (name.equals("anchor")) { - if (value.equals("north")) + //todo use a converter + if (value.equals("north")) { c.anchor = GridBagConstraints.NORTH; - else if (value.equals("northeast")) + } else if (value.equals("northeast")) { c.anchor = GridBagConstraints.NORTHEAST; - else if (value.equals("east")) + } else if (value.equals("east")) { c.anchor = GridBagConstraints.EAST; - else if (value.equals("southeast")) + } else if (value.equals("southeast")) { c.anchor = GridBagConstraints.SOUTHEAST; - else if (value.equals("south")) + } else if (value.equals("south")) { c.anchor = GridBagConstraints.SOUTH; - else if (value.equals("southwest")) + } else if (value.equals("southwest")) { c.anchor = GridBagConstraints.SOUTHWEST; - else if (value.equals("west")) + } else if (value.equals("west")) { c.anchor = GridBagConstraints.WEST; - else if (value.equals("northwest")) + } else if (value.equals("northwest")) { c.anchor = GridBagConstraints.NORTHWEST; - else if (value.equals("center")) + } else if (value.equals("center")) { c.anchor = GridBagConstraints.CENTER; - else + } else { throw new IllegalArgumentException("invalid value for anchor attribute: '" + value + "'"); - } else + } + } else { throw new UnsupportedAttributeException(name); + } } @@ -96,13 +100,14 @@ Attr attribute = (Attr) children.item(i); String name = attribute.getName(); String value = attribute.getValue(); - if (!name.startsWith("xmlns") && !JAXXCompiler.JAXX_INTERNAL_NAMESPACE.equals(attribute.getNamespaceURI())) + if (!name.startsWith("xmlns") && !JAXXCompiler.JAXX_INTERNAL_NAMESPACE.equals(attribute.getNamespaceURI())) { setAttribute(c, name, value); + } } } - protected void compileChildrenFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + protected void compileChildrenFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { NodeList children = tag.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); @@ -110,17 +115,17 @@ if (nodeType == Node.ELEMENT_NODE) { Element child = (Element) node; compileChildTagFirstPass(child, compiler); - } else - if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { + } else if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { String text = ((Text) node).getData().trim(); - if (text.length() > 0) + if (text.length() > 0) { compiler.reportError("tag '" + tag.getLocalName() + "' may not contain text ('" + ((Text) node).getData().trim() + "')"); + } } } } - protected void compileChildrenSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + protected void compileChildrenSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { NodeList children = tag.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); @@ -128,22 +133,22 @@ if (nodeType == Node.ELEMENT_NODE) { Element child = (Element) node; compileChildTagSecondPass(child, compiler); - } else - if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { + } else if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { String text = ((Text) node).getData().trim(); - if (text.length() > 0) + if (text.length() > 0) { compiler.reportError("tag '" + tag.getLocalName() + "' may not contain text ('" + ((Text) node).getData().trim() + "')"); + } } } } - protected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + protected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { compiler.compileFirstPass(tag); } - protected void compileChildTagSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + protected void compileChildTagSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { compiler.compileSecondPass(tag); } } \ No newline at end of file Modified: lutinjaxx/branches/storm_1/jaxx-runtime-swing/changelog.txt =================================================================== --- lutinjaxx/branches/storm_1/jaxx-runtime-swing/changelog.txt 2009-01-02 11:02:06 UTC (rev 1117) +++ lutinjaxx/branches/storm_1/jaxx-runtime-swing/changelog.txt 2009-01-05 08:43:05 UTC (rev 1118) @@ -1,5 +1,5 @@ -1.0 ???? 200812?? - +1.0 ???? 2009012?? + * 20090105 [chemit] - improve CardLayout2 0.8 ??? 200812?? * 20081228 [chemit] - generify ClassDescriptor - introduce StylesheetHelper helper class to detach Stylesheet, Rule and Selector classes from Modified: lutinjaxx/branches/storm_1/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/CardLayout2.java =================================================================== --- lutinjaxx/branches/storm_1/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/CardLayout2.java 2009-01-02 11:02:06 UTC (rev 1117) +++ lutinjaxx/branches/storm_1/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/CardLayout2.java 2009-01-05 08:43:05 UTC (rev 1118) @@ -6,6 +6,8 @@ import java.awt.CardLayout; import java.awt.Component; import java.awt.Container; +import java.awt.Dimension; +import java.awt.Insets; import java.io.Serializable; import java.util.LinkedList; import java.util.List; @@ -34,6 +36,13 @@ /** list of already loaded context (since the {@link #vector} attribute is package visible... */ protected List<Serializable> contexts = new LinkedList<Serializable>(); + /** + * A flag to compute dimension only on visible component. + * <p/> + * This is usefull when we only care of the visible component. + */ + protected boolean useOnlyVisibleComponentDimension; + @Override public void addLayoutComponent(Component comp, Object constraints) { super.addLayoutComponent(comp, constraints); @@ -83,5 +92,113 @@ return container.getComponents()[index]; } + /** + * Determines the preferred size of the container argument using + * this card layout. + * + * @param parent the parent container in which to do the layout + * @return the preferred dimensions to lay out the subcomponents + * of the specified container + * @see java.awt.Container#getPreferredSize + * @see java.awt.CardLayout#minimumLayoutSize + */ + @Override + public Dimension preferredLayoutSize(Container parent) { + Dimension dimension = null; + if (useOnlyVisibleComponentDimension) { + Component comp = getVisibleComponent(parent); + if (comp != null) { + dimension = comp.getPreferredSize(); + } + } + if (dimension == null) { + dimension = super.preferredLayoutSize(parent); + } + return dimension; + } + /** + * Calculates the minimum size for the specified panel. + * + * @param parent the parent container in which to do the layout + * @return the minimum dimensions required to lay out the + * subcomponents of the specified container + * @see java.awt.Container#doLayout + * @see java.awt.CardLayout#preferredLayoutSize + */ + @Override + public Dimension minimumLayoutSize(Container parent) { + Dimension dimension = null; + if (useOnlyVisibleComponentDimension) { + Component comp = getVisibleComponent(parent); + if (comp != null) { + dimension = comp.getMinimumSize(); + } + } + if (dimension == null) { + dimension = super.minimumLayoutSize(parent); + } + return dimension; + } + + /** + * Returns the maximum dimensions for this layout given the components + * in the specified target container. + * + * @param target the component which needs to be laid out + * @see java.awt.Container + * @see #minimumLayoutSize + * @see #preferredLayoutSize + */ + @Override + public Dimension maximumLayoutSize(Container target) { + Dimension dimension = null; + if (useOnlyVisibleComponentDimension) { + Component comp = getVisibleComponent(target); + if (comp != null) { + dimension = comp.getMaximumSize(); + } + } + if (dimension == null) { + dimension = super.maximumLayoutSize(target); + } + return dimension; + } + + /** + * Lays out the specified container using this card layout. + * <p/> + * Each component in the <code>parent</code> container is reshaped + * to be the size of the container, minus space for surrounding + * insets, horizontal gaps, and vertical gaps. + * + * @param parent the parent container in which to do the layout + * @see java.awt.Container#doLayout + */ + @Override + public void layoutContainer(Container parent) { + Dimension dimension = null; + if (useOnlyVisibleComponentDimension) { + Component comp = getVisibleComponent(parent); + if (comp != null) { + //dimension = comp.getMinimumSize(); + Insets insets = parent.getInsets(); + comp.setBounds(getHgap() + insets.left, getVgap() + insets.top, + parent.getWidth() - (getHgap() * 2 + insets.left + insets.right), + parent.getHeight() - (getVgap() * 2 + insets.top + insets.bottom)); + } else { + super.layoutContainer(parent); + } + } else { + super.layoutContainer(parent); + } + } + + public boolean isUseOnlyVisibleComponentDimension() { + return useOnlyVisibleComponentDimension; + } + + public void setUseOnlyVisibleComponentDimension(boolean useOnlyVisibleComponentDimension) { + this.useOnlyVisibleComponentDimension = useOnlyVisibleComponentDimension; + } }
participants (1)
-
tchemit@users.labs.libre-entreprise.org