Author: tchemit Date: 2010-05-23 15:35:09 +0200 (Sun, 23 May 2010) New Revision: 1930 Url: http://nuiton.org/repositories/revision/jaxx/1930 Log: Evolution #633: BlockingLayerUI can accept som component NOT to be blocked reformat code Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java 2010-05-23 13:29:53 UTC (rev 1929) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java 2010-05-23 13:35:09 UTC (rev 1930) @@ -24,6 +24,12 @@ */ package jaxx.runtime.swing; +import org.jdesktop.jxlayer.JXLayer; +import org.jdesktop.jxlayer.plaf.AbstractLayerUI; + +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JComponent; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Component; @@ -34,21 +40,17 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; -import javax.swing.Action; -import javax.swing.ImageIcon; -import javax.swing.JComponent; -import org.jdesktop.jxlayer.JXLayer; -import org.jdesktop.jxlayer.plaf.AbstractLayerUI; +import java.util.Arrays; +import java.util.List; /** - * * A JXLayer ui implementation that permits to block a component but still * allow an action when clicking on the right-top icon painted on the layer. - * + * <p/> * You can change the blocking and accepting icon. - * + * <p/> * To hook an click on the layer's icon, you can : - * + * <p/> * <ul><li>pass an Action via method {@link #setAcceptAction(Action)}</li> * <li>override the method {@link #acceptEvent(MouseEvent, JXLayer)}</li> * </ul> @@ -59,51 +61,50 @@ public class BlockingLayerUI extends AbstractLayerUI<JComponent> { public static final String CAN_CLICK_PROPERTY = "canClick"; + public static final String ACCEPT_ICON_PROPERTY = "acceptIcon"; + public static final String BLOCK_ICON_PROPERTY = "blockIcon"; + public static final String BLOCK_PROPERTY = "block"; // private static final long serialVersionUID = 1L; - /** - * Action to be treated when click on icon - */ + /** Action to be treated when click on icon */ protected Action acceptAction; - /** - * Icon when you can not click - */ + /** Icon when you can not click */ protected BufferedImage blockIcon; - /** - * Icon when you can click - */ + /** Icon when you can click */ protected BufferedImage acceptIcon; - /** - * Optinal color to put fill background when blocking - */ + /** Optinal color to put fill background when blocking */ protected Color blockingColor; - /** - * Internal state to known when we can accept click - */ + /** Internal state to known when we can accept click */ protected boolean canClick; /** * A flag to enable or disable the use of the icon. - * - * If set to false, no icon will be displayed and no action + * <p/> + * If set to false, no icon will be displayed and no action * will be possible. - * + * <p/> * By default, this is active. */ protected boolean useIcon = true; - /** - * Internal state when should block event and paint layer - */ + /** Internal state when should block event and paint layer */ protected boolean block; + /** Extra components names to accept even in block mode */ + protected List<String> acceptedComponentNames; + + public void setAcceptedComponentNames(String... acceptedComponentNames) { + this.acceptedComponentNames = Arrays.asList(acceptedComponentNames); + setDirty(true); + } + public void setAcceptAction(Action acceptAction) { this.acceptAction = acceptAction; } @@ -186,19 +187,46 @@ @Override protected void processKeyEvent(KeyEvent e, JXLayer<JComponent> l) { - if (useIcon || block) { + if (useIcon) { e.consume(); + return; } + + if (block) { + Object source = e.getSource(); + if (!(source instanceof JComponent)) { + e.consume(); + return; + } + JComponent comp = (JComponent) source; + String compName = comp.getName(); + if (acceptedComponentNames == null || + !acceptedComponentNames.contains(compName)) { + e.consume(); + } + } } @Override protected void processMouseMotionEvent(MouseEvent e, JXLayer<JComponent> l) { if (useIcon) { updateCanClickState(l, e); - } - if (useIcon || block) { e.consume(); } + + if (block) { + Object source = e.getSource(); + if (!(source instanceof JComponent)) { + e.consume(); + return; + } + JComponent comp = (JComponent) source; + String compName = comp.getName(); + if (acceptedComponentNames == null || + !acceptedComponentNames.contains(compName)) { + e.consume(); + } + } } @Override @@ -218,10 +246,36 @@ break; } } - if (useIcon || block) { + if (useIcon) { + e.consume(); + return; } + if (block) { + Object source = e.getSource(); + if (!(source instanceof JComponent)) { + e.consume(); + return; + } + JComponent comp = (JComponent) source; + String compName = comp.getName(); + if (acceptedComponentNames == null || + !acceptedComponentNames.contains(compName)) { + e.consume(); + return; + } + switch (e.getID()) { + case MouseEvent.MOUSE_ENTERED: + break; + case MouseEvent.MOUSE_EXITED: + break; + case MouseEvent.MOUSE_CLICKED: + acceptEvent(e, l); + break; + } + } + } @Override Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java 2010-05-23 13:29:53 UTC (rev 1929) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java 2010-05-23 13:35:09 UTC (rev 1930) @@ -24,6 +24,12 @@ */ package jaxx.runtime.swing; +import org.jdesktop.jxlayer.JXLayer; +import org.jdesktop.jxlayer.plaf.AbstractLayerUI; + +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JComponent; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Component; @@ -34,55 +40,46 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; -import javax.swing.Action; -import javax.swing.ImageIcon; -import javax.swing.JComponent; -import org.jdesktop.jxlayer.JXLayer; /** - * * A JXLayer ui implementation that permits to block a component but still * allow an action when clicking everywhere on the layer. - * + * <p/> * Moreover, an icon can be added on the right-top icon painted and changed * when the mouse is over the layer. - * + * <p/> * You can change the blocking and accepting icon. - * + * <p/> * To hook an click on the layer's icon, you can : - * + * <p/> * <ul><li>pass an Action via method {@link #setAcceptAction(Action)}</li> - * <li>override the method {@link #acceptEvent(java.awt.event.MouseEvent, org.jdesktop.jxlayer.JXLayer)}</li> + * <li>override the method {@link #acceptEvent(MouseEvent, JXLayer)}</li> * </ul> * * @author tchemit <chemit@codelutin.com> * @since 1.3 */ -public class BlockingLayerUI2 extends org.jdesktop.jxlayer.plaf.AbstractLayerUI<JComponent> { +public class BlockingLayerUI2 extends AbstractLayerUI<JComponent> { public static final String CAN_CLICK_PROPERTY = "canClick"; + public static final String ACCEPT_ICON_PROPERTY = "acceptIcon"; + public static final String BLOCK_ICON_PROPERTY = "blockIcon"; - private static final long serialVersionUID = 1L; - /** - * Action to be treated when click on icon - */ + + /** Action to be treated when click on icon */ protected Action acceptAction; - /** - * Icon when you can not click - */ + + /** Icon when you can not click */ protected BufferedImage blockIcon; - /** - * Icon when you can click - */ + + /** Icon when you can click */ protected BufferedImage acceptIcon; - /** - * Optinal color to put fill background when blocking - */ + + /** Optinal color to put fill background when blocking */ protected Color blockingColor; - /** - * Internal state to known when we can accept click - */ + + /** Internal state to known when we can accept click */ protected boolean canClick; public void setAcceptAction(Action acceptAction) { @@ -171,7 +168,7 @@ } break; } - e.consume(); + e.consume(); } @Override
participants (1)
-
tchemit@users.nuiton.org