< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/synth/SynthContext.java

Print this page




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing.plaf.synth;
  26 
  27 import java.util.Queue;
  28 import java.util.concurrent.ConcurrentLinkedQueue;
  29 import javax.swing.JComponent;
  30 
  31 /**
  32  * An immutable transient object containing contextual information about
  33  * a <code>Region</code>. A <code>SynthContext</code> should only be
  34  * considered valid for the duration
  35  * of the method it is passed to. In other words you should not cache
  36  * a <code>SynthContext</code> that is passed to you and expect it to
  37  * remain valid.
  38  *
  39  * @since 1.5
  40  * @author Scott Violet
  41  */
  42 public class SynthContext {
  43     private static final Queue<SynthContext> queue = new ConcurrentLinkedQueue<>();
  44 
  45     private JComponent component;
  46     private Region region;
  47     private SynthStyle style;
  48     private int state;
  49 
  50     static SynthContext getContext(JComponent c, SynthStyle style, int state) {
  51         return getContext(c, SynthLookAndFeel.getRegion(c), style, state);
  52     }
  53 
  54     static SynthContext getContext(JComponent component,
  55                                    Region region, SynthStyle style,
  56                                    int state) {


  92 
  93     /**
  94      * Returns the hosting component containing the region.
  95      *
  96      * @return Hosting Component
  97      */
  98     public JComponent getComponent() {
  99         return component;
 100     }
 101 
 102     /**
 103      * Returns the Region identifying this state.
 104      *
 105      * @return Region of the hosting component
 106      */
 107     public Region getRegion() {
 108         return region;
 109     }
 110 
 111     /**
 112      * A convenience method for <code>getRegion().isSubregion()</code>.
 113      */
 114     boolean isSubregion() {
 115         return getRegion().isSubregion();
 116     }
 117 
 118     void setStyle(SynthStyle style) {
 119         this.style = style;
 120     }
 121 
 122     /**
 123      * Returns the style associated with this Region.
 124      *
 125      * @return SynthStyle associated with the region.
 126      */
 127     public SynthStyle getStyle() {
 128         return style;
 129     }
 130 
 131     void setComponentState(int state) {
 132         this.state = state;
 133     }
 134 
 135     /**
 136      * Returns the state of the widget, which is a bitmask of the
 137      * values defined in <code>SynthConstants</code>. A region will at least
 138      * be in one of
 139      * <code>ENABLED</code>, <code>MOUSE_OVER</code>, <code>PRESSED</code>
 140      * or <code>DISABLED</code>.
 141      *
 142      * @see SynthConstants
 143      * @return State of Component
 144      */
 145     public int getComponentState() {
 146         return state;
 147     }
 148 
 149     /**
 150      * Resets the state of the Context.
 151      */
 152     void reset(JComponent component, Region region, SynthStyle style,
 153                int state) {
 154         this.component = component;
 155         this.region = region;
 156         this.style = style;
 157         this.state = state;
 158     }
 159 
 160     void dispose() {


  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing.plaf.synth;
  26 
  27 import java.util.Queue;
  28 import java.util.concurrent.ConcurrentLinkedQueue;
  29 import javax.swing.JComponent;
  30 
  31 /**
  32  * An immutable transient object containing contextual information about
  33  * a {@code Region}. A {@code SynthContext} should only be
  34  * considered valid for the duration
  35  * of the method it is passed to. In other words you should not cache
  36  * a {@code SynthContext} that is passed to you and expect it to
  37  * remain valid.
  38  *
  39  * @since 1.5
  40  * @author Scott Violet
  41  */
  42 public class SynthContext {
  43     private static final Queue<SynthContext> queue = new ConcurrentLinkedQueue<>();
  44 
  45     private JComponent component;
  46     private Region region;
  47     private SynthStyle style;
  48     private int state;
  49 
  50     static SynthContext getContext(JComponent c, SynthStyle style, int state) {
  51         return getContext(c, SynthLookAndFeel.getRegion(c), style, state);
  52     }
  53 
  54     static SynthContext getContext(JComponent component,
  55                                    Region region, SynthStyle style,
  56                                    int state) {


  92 
  93     /**
  94      * Returns the hosting component containing the region.
  95      *
  96      * @return Hosting Component
  97      */
  98     public JComponent getComponent() {
  99         return component;
 100     }
 101 
 102     /**
 103      * Returns the Region identifying this state.
 104      *
 105      * @return Region of the hosting component
 106      */
 107     public Region getRegion() {
 108         return region;
 109     }
 110 
 111     /**
 112      * A convenience method for {@code getRegion().isSubregion()}.
 113      */
 114     boolean isSubregion() {
 115         return getRegion().isSubregion();
 116     }
 117 
 118     void setStyle(SynthStyle style) {
 119         this.style = style;
 120     }
 121 
 122     /**
 123      * Returns the style associated with this Region.
 124      *
 125      * @return SynthStyle associated with the region.
 126      */
 127     public SynthStyle getStyle() {
 128         return style;
 129     }
 130 
 131     void setComponentState(int state) {
 132         this.state = state;
 133     }
 134 
 135     /**
 136      * Returns the state of the widget, which is a bitmask of the
 137      * values defined in {@code SynthConstants}. A region will at least
 138      * be in one of
 139      * {@code ENABLED}, {@code MOUSE_OVER}, {@code PRESSED}
 140      * or {@code DISABLED}.
 141      *
 142      * @see SynthConstants
 143      * @return State of Component
 144      */
 145     public int getComponentState() {
 146         return state;
 147     }
 148 
 149     /**
 150      * Resets the state of the Context.
 151      */
 152     void reset(JComponent component, Region region, SynthStyle style,
 153                int state) {
 154         this.component = component;
 155         this.region = region;
 156         this.style = style;
 157         this.state = state;
 158     }
 159 
 160     void dispose() {
< prev index next >