131 * <li>{@link Container#add(java.awt.Component, Object)}</li>
132 * <li>{@link Container#add(java.awt.Component, Object, int)}</li>
133 * </ul>
134 * using any of of them will cause {@code UnsupportedOperationException} to be thrown,
135 * to add a component to {@code JLayer}
136 * use {@link #setView(Component)} or {@link #setGlassPane(JPanel)}.
137 *
138 * @param <V> the type of {@code JLayer}'s view component
139 *
140 * @see #JLayer(Component)
141 * @see #setView(Component)
142 * @see #getView()
143 * @see javax.swing.plaf.LayerUI
144 * @see #JLayer(Component, LayerUI)
145 * @see #setUI(javax.swing.plaf.LayerUI)
146 * @see #getUI()
147 * @since 1.7
148 *
149 * @author Alexander Potochkin
150 */
151 public final class JLayer<V extends Component>
152 extends JComponent
153 implements Scrollable, PropertyChangeListener, Accessible {
154 private V view;
155 // this field is necessary because JComponent.ui is transient
156 // when layerUI is serializable
157 private LayerUI<? super V> layerUI;
158 private JPanel glassPane;
159 private long eventMask;
160 private transient boolean isPainting;
161 private transient boolean isPaintingImmediately;
162
163 private static final LayerEventController eventController =
164 new LayerEventController();
165
166 /**
167 * Creates a new {@code JLayer} object with a {@code null} view component
168 * and default {@link javax.swing.plaf.LayerUI}.
169 *
170 * @see #setView
670 public void removeNotify() {
671 super.removeNotify();
672 eventController.updateAWTEventListener(eventMask, 0);
673 }
674
675 /**
676 * Delegates its functionality to the {@link javax.swing.plaf.LayerUI#doLayout(JLayer)} method,
677 * if {@code LayerUI} is set.
678 */
679 public void doLayout() {
680 if (getUI() != null) {
681 getUI().doLayout(this);
682 }
683 }
684
685 /**
686 * Gets the AccessibleContext associated with this {@code JLayer}.
687 *
688 * @return the AccessibleContext associated with this {@code JLayer}.
689 */
690 public AccessibleContext getAccessibleContext() {
691 if (accessibleContext == null) {
692 accessibleContext = new AccessibleJComponent() {
693 public AccessibleRole getAccessibleRole() {
694 return AccessibleRole.PANEL;
695 }
696 };
697 }
698 return accessibleContext;
699 }
700
701 /**
702 * static AWTEventListener to be shared with all AbstractLayerUIs
703 */
704 private static class LayerEventController implements AWTEventListener {
705 private ArrayList<Long> layerMaskList =
706 new ArrayList<Long>();
707
708 private long currentEventMask;
709
808 id != MouseEvent.MOUSE_MOVED &&
809 id != MouseEvent.MOUSE_DRAGGED &&
810 id != MouseEvent.MOUSE_WHEEL &&
811 id >= MouseEvent.MOUSE_FIRST &&
812 id <= MouseEvent.MOUSE_LAST)
813 || ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 &&
814 id >= InputMethodEvent.INPUT_METHOD_FIRST &&
815 id <= InputMethodEvent.INPUT_METHOD_LAST)
816 || ((eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
817 id == HierarchyEvent.HIERARCHY_CHANGED)
818 || ((eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 &&
819 (id == HierarchyEvent.ANCESTOR_MOVED ||
820 id == HierarchyEvent.ANCESTOR_RESIZED)));
821 }
822 }
823
824 /**
825 * The default glassPane for the {@link javax.swing.JLayer}.
826 * It is a subclass of {@code JPanel} which is non opaque by default.
827 */
828 private static class DefaultLayerGlassPane extends JPanel {
829 /**
830 * Creates a new {@link DefaultLayerGlassPane}
831 */
832 public DefaultLayerGlassPane() {
833 setOpaque(false);
834 }
835
836 /**
837 * First, implementation of this method iterates through
838 * glassPane's child components and returns {@code true}
839 * if any of them is visible and contains passed x,y point.
840 * After that it checks if no mouseListeners is attached to this component
841 * and no mouse cursor is set, then it returns {@code false},
842 * otherwise calls the super implementation of this method.
843 *
844 * @param x the <i>x</i> coordinate of the point
845 * @param y the <i>y</i> coordinate of the point
846 * @return true if this component logically contains x,y
847 */
|
131 * <li>{@link Container#add(java.awt.Component, Object)}</li>
132 * <li>{@link Container#add(java.awt.Component, Object, int)}</li>
133 * </ul>
134 * using any of of them will cause {@code UnsupportedOperationException} to be thrown,
135 * to add a component to {@code JLayer}
136 * use {@link #setView(Component)} or {@link #setGlassPane(JPanel)}.
137 *
138 * @param <V> the type of {@code JLayer}'s view component
139 *
140 * @see #JLayer(Component)
141 * @see #setView(Component)
142 * @see #getView()
143 * @see javax.swing.plaf.LayerUI
144 * @see #JLayer(Component, LayerUI)
145 * @see #setUI(javax.swing.plaf.LayerUI)
146 * @see #getUI()
147 * @since 1.7
148 *
149 * @author Alexander Potochkin
150 */
151 @SuppressWarnings("serial") // Superclass is not serializable across versions
152 public final class JLayer<V extends Component>
153 extends JComponent
154 implements Scrollable, PropertyChangeListener, Accessible {
155 private V view;
156 // this field is necessary because JComponent.ui is transient
157 // when layerUI is serializable
158 private LayerUI<? super V> layerUI;
159 private JPanel glassPane;
160 private long eventMask;
161 private transient boolean isPainting;
162 private transient boolean isPaintingImmediately;
163
164 private static final LayerEventController eventController =
165 new LayerEventController();
166
167 /**
168 * Creates a new {@code JLayer} object with a {@code null} view component
169 * and default {@link javax.swing.plaf.LayerUI}.
170 *
171 * @see #setView
671 public void removeNotify() {
672 super.removeNotify();
673 eventController.updateAWTEventListener(eventMask, 0);
674 }
675
676 /**
677 * Delegates its functionality to the {@link javax.swing.plaf.LayerUI#doLayout(JLayer)} method,
678 * if {@code LayerUI} is set.
679 */
680 public void doLayout() {
681 if (getUI() != null) {
682 getUI().doLayout(this);
683 }
684 }
685
686 /**
687 * Gets the AccessibleContext associated with this {@code JLayer}.
688 *
689 * @return the AccessibleContext associated with this {@code JLayer}.
690 */
691 @SuppressWarnings("serial") // anonymous class
692 public AccessibleContext getAccessibleContext() {
693 if (accessibleContext == null) {
694 accessibleContext = new AccessibleJComponent() {
695 public AccessibleRole getAccessibleRole() {
696 return AccessibleRole.PANEL;
697 }
698 };
699 }
700 return accessibleContext;
701 }
702
703 /**
704 * static AWTEventListener to be shared with all AbstractLayerUIs
705 */
706 private static class LayerEventController implements AWTEventListener {
707 private ArrayList<Long> layerMaskList =
708 new ArrayList<Long>();
709
710 private long currentEventMask;
711
810 id != MouseEvent.MOUSE_MOVED &&
811 id != MouseEvent.MOUSE_DRAGGED &&
812 id != MouseEvent.MOUSE_WHEEL &&
813 id >= MouseEvent.MOUSE_FIRST &&
814 id <= MouseEvent.MOUSE_LAST)
815 || ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 &&
816 id >= InputMethodEvent.INPUT_METHOD_FIRST &&
817 id <= InputMethodEvent.INPUT_METHOD_LAST)
818 || ((eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
819 id == HierarchyEvent.HIERARCHY_CHANGED)
820 || ((eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 &&
821 (id == HierarchyEvent.ANCESTOR_MOVED ||
822 id == HierarchyEvent.ANCESTOR_RESIZED)));
823 }
824 }
825
826 /**
827 * The default glassPane for the {@link javax.swing.JLayer}.
828 * It is a subclass of {@code JPanel} which is non opaque by default.
829 */
830 @SuppressWarnings("serial") // Superclass is not serializable across versions
831 private static class DefaultLayerGlassPane extends JPanel {
832 /**
833 * Creates a new {@link DefaultLayerGlassPane}
834 */
835 public DefaultLayerGlassPane() {
836 setOpaque(false);
837 }
838
839 /**
840 * First, implementation of this method iterates through
841 * glassPane's child components and returns {@code true}
842 * if any of them is visible and contains passed x,y point.
843 * After that it checks if no mouseListeners is attached to this component
844 * and no mouse cursor is set, then it returns {@code false},
845 * otherwise calls the super implementation of this method.
846 *
847 * @param x the <i>x</i> coordinate of the point
848 * @param y the <i>y</i> coordinate of the point
849 * @return true if this component logically contains x,y
850 */
|