src/share/classes/javax/swing/plaf/nimbus/State.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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


  55  * very quickly.</p>
  56  *
  57  * <p>For example, the following might be an implementation of a custom
  58  * "Indeterminate" state for JProgressBars:</p>
  59  *
  60  * <pre><code>
  61  *     public final class IndeterminateState extends State&lt;JProgressBar&gt; {
  62  *         public IndeterminateState() {
  63  *             super("Indeterminate");
  64  *         }
  65  *
  66  *         @Override
  67  *         protected boolean isInState(JProgressBar c) {
  68  *             return c.isIndeterminate();
  69  *         }
  70  *     }
  71  * </code></pre>
  72  */
  73 public abstract class State<T extends JComponent>{
  74     static final Map<String, StandardState> standardStates = new HashMap<String, StandardState>(7);
  75     static final State Enabled = new StandardState(SynthConstants.ENABLED);
  76     static final State MouseOver = new StandardState(SynthConstants.MOUSE_OVER);
  77     static final State Pressed = new StandardState(SynthConstants.PRESSED);
  78     static final State Disabled = new StandardState(SynthConstants.DISABLED);
  79     static final State Focused = new StandardState(SynthConstants.FOCUSED);
  80     static final State Selected = new StandardState(SynthConstants.SELECTED);
  81     static final State Default = new StandardState(SynthConstants.DEFAULT);
  82 
  83     private String name;
  84 
  85     /**
  86      * <p>Create a new custom State. Specify the name for the state. The name should
  87      * be unique within the states set for any one particular component.
  88      * The name of the state should coincide with the name used in UIDefaults.</p>
  89      *
  90      * <p>For example, the following would be correct:</p>
  91      * <pre><code>
  92      *     defaults.put("Button.States", "Enabled, Foo, Disabled");
  93      *     defaults.put("Button.Foo", new FooState("Foo"));
  94      * </code></pre>
  95      *
  96      * @param name a simple user friendly name for the state, such as "Indeterminate"
  97      *        or "EmbeddedPanel" or "Blurred". It is customary to use camel case,
  98      *        with the first letter capitalized.
  99      */
 100     protected State(String name) {
 101         this.name = name;


   1 /*
   2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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


  55  * very quickly.</p>
  56  *
  57  * <p>For example, the following might be an implementation of a custom
  58  * "Indeterminate" state for JProgressBars:</p>
  59  *
  60  * <pre><code>
  61  *     public final class IndeterminateState extends State&lt;JProgressBar&gt; {
  62  *         public IndeterminateState() {
  63  *             super("Indeterminate");
  64  *         }
  65  *
  66  *         @Override
  67  *         protected boolean isInState(JProgressBar c) {
  68  *             return c.isIndeterminate();
  69  *         }
  70  *     }
  71  * </code></pre>
  72  */
  73 public abstract class State<T extends JComponent>{
  74     static final Map<String, StandardState> standardStates = new HashMap<String, StandardState>(7);
  75     static final State<JComponent> Enabled = new StandardState(SynthConstants.ENABLED);
  76     static final State<JComponent> MouseOver = new StandardState(SynthConstants.MOUSE_OVER);
  77     static final State<JComponent> Pressed = new StandardState(SynthConstants.PRESSED);
  78     static final State<JComponent> Disabled = new StandardState(SynthConstants.DISABLED);
  79     static final State<JComponent> Focused = new StandardState(SynthConstants.FOCUSED);
  80     static final State<JComponent> Selected = new StandardState(SynthConstants.SELECTED);
  81     static final State<JComponent> Default = new StandardState(SynthConstants.DEFAULT);
  82 
  83     private String name;
  84 
  85     /**
  86      * <p>Create a new custom State. Specify the name for the state. The name should
  87      * be unique within the states set for any one particular component.
  88      * The name of the state should coincide with the name used in UIDefaults.</p>
  89      *
  90      * <p>For example, the following would be correct:</p>
  91      * <pre><code>
  92      *     defaults.put("Button.States", "Enabled, Foo, Disabled");
  93      *     defaults.put("Button.Foo", new FooState("Foo"));
  94      * </code></pre>
  95      *
  96      * @param name a simple user friendly name for the state, such as "Indeterminate"
  97      *        or "EmbeddedPanel" or "Blurred". It is customary to use camel case,
  98      *        with the first letter capitalized.
  99      */
 100     protected State(String name) {
 101         this.name = name;