Author: tchemit Date: 2011-02-16 21:57:24 +0100 (Wed, 16 Feb 2011) New Revision: 2210 Url: http://nuiton.org/repositories/revision/jaxx/2210 Log: Evolution #1339: Updates to JXLayer 3.0.4 Evolution #1343: Introduce a JXLayerHandler to deal with new api of JXLayer Added: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JXLayerHandler.java Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/AbstractBeanValidatorUI.java trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/IconValidationUI.java trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/ImageValidationUI.java trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/TranslucentValidationUI.java Added: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JXLayerHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JXLayerHandler.java (rev 0) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JXLayerHandler.java 2011-02-16 20:57:24 UTC (rev 2210) @@ -0,0 +1,87 @@ +package jaxx.compiler.tags.swing; + +import jaxx.compiler.CompiledObject; +import jaxx.compiler.CompilerException; +import jaxx.compiler.JAXXCompiler; +import jaxx.compiler.reflect.ClassDescriptor; +import jaxx.compiler.reflect.ClassDescriptorHelper; +import jaxx.compiler.tags.DefaultComponentHandler; +import org.apache.commons.collections.CollectionUtils; +import org.jdesktop.jxlayer.JXLayer; + +import java.awt.Component; + +/** + * To deal with JXLayer, since from version 3.0.4, we can not use any longer + * the {@link JXLayer#add(Component)} ! but must now use the + * method {@link JXLayer#setView(Component)}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.4 + */ +public class JXLayerHandler 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 JXLayerHandler(ClassDescriptor beanClass) { + super(beanClass); + ClassDescriptorHelper.checkSupportClass(getClass(), beanClass, JXLayer.class); + } + + @Override + public CompiledObject createCompiledObject(String id, JAXXCompiler compiler) throws CompilerException { + return new CompiledObject(id, getBeanClass(), compiler) { + + @Override + public void addChild(CompiledObject child, + String constraints, + JAXXCompiler compiler) throws CompilerException { + + if (constraints != null) { + compiler.reportError("JXLayer does not accept constraints"); + return; + } + if (CollectionUtils.isNotEmpty(getChilds())) { + + // already one child, authrozied only one child... + compiler.reportError("JXLayer is limited to one children"); + return; + } + super.addChild(child, constraints, compiler); + + } + + @Override + protected ChildRef newChildRef(CompiledObject child, String constraints, String delegateCode) { + return new ChildRef(child, + constraints, + child.getJavaCode(), + delegateCode) { + @Override + public void addToAdditionCode(StringBuffer buffer, boolean isRootObject) { + //TC-20091026 do not prefix if on root object + String prefix; + if (isRootObject) { + prefix = ""; + } else { + prefix = getJavaCode() + getDelegateCode() + "."; + } + buffer.append(prefix); + buffer.append("setView("); + buffer.append(getChildJavaCode()); + buffer.append(");"); + buffer.append(JAXXCompiler.getLineSeparator()); + } + }; + } + }; + } +} \ No newline at end of file Property changes on: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JXLayerHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2011-02-16 20:55:44 UTC (rev 2209) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2011-02-16 20:57:24 UTC (rev 2210) @@ -33,6 +33,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.jxlayer.JXLayer; +import org.jdesktop.jxlayer.plaf.LayerUI; import org.jdesktop.swingx.JXTreeTable; import javax.swing.DefaultComboBoxModel; @@ -399,13 +400,13 @@ * @param component the component to box * @return the {@link JXLayer} boxing the component */ - public static JXLayer<?> boxComponentWithJxLayer(JComponent component) { - JXLayer<?> layer = getLayer(component); + public static <V extends JComponent> JXLayer<V> boxComponentWithJxLayer(V component) { + JXLayer<V> layer = getLayer(component); if (layer != null) { return layer; } - layer = new JXLayer<JComponent>(); - layer.add(component); + layer = new JXLayer<V>(); + layer.setView(component); return layer; } @@ -426,14 +427,18 @@ return result; } - @SuppressWarnings("unchecked") - public static JXLayer<JComponent> getLayer(JComponent comp) { + public static <V extends JComponent> JXLayer<V> getLayer(V comp) { if (!isLayered(comp)) { return null; } - return (JXLayer<JComponent>) comp.getParent(); + return (JXLayer<V>) comp.getParent(); } + public static void setLayerUI(JComponent comp, LayerUI<JComponent> ui) { + JXLayer<JComponent> layer = getLayer(comp); + layer.setUI(ui); + } + public static boolean isLayered(JComponent comp) { Container parent = comp.getParent(); return parent != null && parent instanceof JXLayer<?>; Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java 2011-02-16 20:55:44 UTC (rev 2209) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java 2011-02-16 20:57:24 UTC (rev 2210) @@ -186,7 +186,7 @@ } @Override - protected void processKeyEvent(KeyEvent e, JXLayer<JComponent> l) { + protected void processKeyEvent(KeyEvent e, JXLayer<? extends JComponent> l) { if (useIcon) { e.consume(); return; @@ -208,7 +208,7 @@ } @Override - protected void processMouseMotionEvent(MouseEvent e, JXLayer<JComponent> l) { + protected void processMouseMotionEvent(MouseEvent e, JXLayer<? extends JComponent> l) { if (useIcon) { updateCanClickState(l, e); e.consume(); @@ -230,7 +230,7 @@ } @Override - protected void processMouseEvent(MouseEvent e, JXLayer<JComponent> l) { + protected void processMouseEvent(MouseEvent e, JXLayer<? extends JComponent> l) { if (useIcon) { switch (e.getID()) { case MouseEvent.MOUSE_ENTERED: @@ -279,7 +279,7 @@ } @Override - protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) { + protected void paintLayer(Graphics2D g2, JXLayer<? extends JComponent> l) { super.paintLayer(g2, l); if (block && blockingColor != null) { // to be in sync with the view if the layer has a border @@ -303,7 +303,7 @@ } } - protected void acceptEvent(MouseEvent e, JXLayer<JComponent> l) { + protected void acceptEvent(MouseEvent e, JXLayer<? extends JComponent> l) { if (acceptAction != null) { acceptAction.putValue("layer", l); Component source = l.getView(); @@ -325,7 +325,7 @@ return icon; } - protected void updateCanClickState(JXLayer<JComponent> l, MouseEvent e) { + protected void updateCanClickState(JXLayer<? extends JComponent> l, MouseEvent e) { // udpate toolTipText Point layerLocation = l.getView().getLocation(); Point mousePoint = e.getPoint(); Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java 2011-02-16 20:55:44 UTC (rev 2209) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java 2011-02-16 20:57:24 UTC (rev 2210) @@ -144,17 +144,17 @@ } @Override - protected void processKeyEvent(KeyEvent e, JXLayer<JComponent> l) { + protected void processKeyEvent(KeyEvent e, JXLayer<? extends JComponent> l) { e.consume(); } @Override - protected void processMouseMotionEvent(MouseEvent e, JXLayer<JComponent> l) { + protected void processMouseMotionEvent(MouseEvent e, JXLayer<? extends JComponent> l) { e.consume(); } @Override - protected void processMouseEvent(MouseEvent e, JXLayer<JComponent> l) { + protected void processMouseEvent(MouseEvent e, JXLayer<? extends JComponent> l) { switch (e.getID()) { case MouseEvent.MOUSE_ENTERED: setCanClick(true); @@ -172,7 +172,7 @@ } @Override - protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) { + protected void paintLayer(Graphics2D g2, JXLayer<? extends JComponent> l) { super.paintLayer(g2, l); if (blockingColor != null) { // to be in sync with the view if the layer has a border @@ -196,7 +196,7 @@ } } - protected void acceptEvent(MouseEvent e, JXLayer<JComponent> l) { + protected void acceptEvent(MouseEvent e, JXLayer<? extends JComponent> l) { if (acceptAction != null) { acceptAction.putValue("layer", l); Component source = l.getView(); Modified: trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/AbstractBeanValidatorUI.java =================================================================== --- trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/AbstractBeanValidatorUI.java 2011-02-16 20:55:44 UTC (rev 2209) +++ trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/AbstractBeanValidatorUI.java 2011-02-16 20:57:24 UTC (rev 2210) @@ -43,6 +43,8 @@ /** Logger */ private static final Log log = LogFactory.getLog(AbstractBeanValidatorUI.class); + private static final long serialVersionUID = 1L; + /** * Actual scope to display in the layer. * <p/> Modified: trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/IconValidationUI.java =================================================================== --- trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/IconValidationUI.java 2011-02-16 20:55:44 UTC (rev 2209) +++ trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/IconValidationUI.java 2011-02-16 20:57:24 UTC (rev 2210) @@ -45,6 +45,8 @@ */ public class IconValidationUI extends AbstractBeanValidatorUI { + private static final long serialVersionUID = 1L; + // The icon to be shown at the layer's corner protected EnumMap<NuitonValidatorScope, BufferedImage> icons; @@ -73,7 +75,7 @@ } @Override - protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) { + protected void paintLayer(Graphics2D g2, JXLayer<? extends JComponent> l) { super.paintLayer(g2, l); // There is no need to take insets into account for this painter NuitonValidatorScope scope = getScope(); Modified: trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/ImageValidationUI.java =================================================================== --- trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/ImageValidationUI.java 2011-02-16 20:55:44 UTC (rev 2209) +++ trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/ImageValidationUI.java 2011-02-16 20:57:24 UTC (rev 2210) @@ -45,6 +45,8 @@ */ public class ImageValidationUI extends AbstractBeanValidatorUI { + private static final long serialVersionUID = 1L; + protected EnumMap<NuitonValidatorScope, BufferedImage> icons; public ImageValidationUI(String field) { @@ -81,7 +83,7 @@ } @Override - protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) { + protected void paintLayer(Graphics2D g2, JXLayer<? extends JComponent> l) { super.paintLayer(g2, l); NuitonValidatorScope scope = getScope(); if (scope != null) { Modified: trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/TranslucentValidationUI.java =================================================================== --- trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/TranslucentValidationUI.java 2011-02-16 20:55:44 UTC (rev 2209) +++ trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/ui/TranslucentValidationUI.java 2011-02-16 20:57:24 UTC (rev 2210) @@ -44,12 +44,14 @@ */ public class TranslucentValidationUI extends AbstractBeanValidatorUI { + private static final long serialVersionUID = 1L; + public TranslucentValidationUI(String field) { super(field); } @Override - protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) { + protected void paintLayer(Graphics2D g2, JXLayer<? extends JComponent> l) { // paints the layer as is super.paintLayer(g2, l);