Path: blob/master/src/java.desktop/share/classes/sun/swing/plaf/synth/StyleAssociation.java
41161 views
/*1* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.swing.plaf.synth;2526import javax.swing.plaf.synth.*;27import java.util.*;28import java.util.regex.*;2930/**31* <b>WARNING:</b> This class is an implementation detail and is only32* public so that it can be used by two packages. You should NOT consider33* this public API.34* <p>35* StyleAssociation is used to lookup a style for a particular36* component (or region).37*38* @author Scott Violet39*/40public class StyleAssociation {41/**42* The style43*/44private SynthStyle _style;4546/**47* Pattern used for matching.48*/49private Pattern _pattern;50/**51* Matcher used for testing if path matches that of pattern.52*/53private Matcher _matcher;5455/**56* Identifier for this association.57*/58private int _id;596061/**62* Returns a StyleAssociation that can be used to determine if63* a particular string matches the returned association.64*/65public static StyleAssociation createStyleAssociation(66String text, SynthStyle style)67throws PatternSyntaxException {68return createStyleAssociation(text, style, 0);69}7071/**72* Returns a StyleAssociation that can be used to determine if73* a particular string matches the returned association.74*/75public static StyleAssociation createStyleAssociation(76String text, SynthStyle style, int id)77throws PatternSyntaxException {78return new StyleAssociation(text, style, id);79}808182private StyleAssociation(String text, SynthStyle style, int id)83throws PatternSyntaxException {84_style = style;85_pattern = Pattern.compile(text);86_id = id;87}8889/**90* Returns the developer specified identifier for this association, will91* be <code>0</code> if an identifier was not specified when this92* <code>StyleAssociation</code> was created.93*/94public int getID() {95return _id;96}9798/**99* Returns true if this <code>StyleAssociation</code> matches the100* passed in CharSequence.101*102* @return true if this <code>StyleAssociation</code> matches the103* passed in CharSequence.if this StyleAssociation.104*/105public synchronized boolean matches(CharSequence path) {106if (_matcher == null) {107_matcher = _pattern.matcher(path);108}109else {110_matcher.reset(path);111}112return _matcher.matches();113}114115/**116* Returns the text used in matching the string.117*118* @return the text used in matching the string.119*/120public String getText() {121return _pattern.pattern();122}123124/**125* Returns the style this association is mapped to.126*127* @return the style this association is mapped to.128*/129public SynthStyle getStyle() {130return _style;131}132}133134135