All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.blaisemath.style.StyleContext Maven / Gradle / Ivy

There is a newer version: 3.0.16
Show newest version
/*
 * StyleContext.java
 * Created Jan 22, 2011
 */
package com.googlecode.blaisemath.style;

import com.google.common.base.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Sets;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/*
 * #%L
 * BlaiseGraphics
 * --
 * Copyright (C) 2009 - 2019 Elisha Peterson
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

/**
 * 

* Maintains multiple types of styles within a single context, and also * contains logic for modifying the style attribute sets based on "hints". *

* * @author Elisha Peterson */ public final class StyleContext { /** Parent context. */ private final Optional parent; /** Modifiers that apply to the styles in this context. */ private final Set modifiers = Sets.newHashSet(); public StyleContext() { this(null); } public StyleContext(@Nullable StyleContext parent) { this.parent = Optional.fromNullable(parent); } // // // PROPERTY/COMPOSITE PATTERNS // /** * Get collection of style types supported by this context, not including * types supported by the parent. * @return types */ public Set getModifiers() { return modifiers; } public boolean addModifier(StyleModifier mod) { return modifiers.add(mod); } public boolean removeModifier(StyleModifier mod) { return modifiers.remove(mod); } // /** * Get collection of style types supported by this context, including * types supported by the parent context. * @return types */ public Set getAllModifiers() { return parent.isPresent() ? Sets.union(parent.get().getAllModifiers(), modifiers) : modifiers; } /** * Applies all modifiers in this context to the given style, returning the result. * @param style the style to modify * @param hints the hints to apply * @return the modified style */ @Nonnull public AttributeSet applyModifiers(AttributeSet style, AttributeSet hints) { checkNotNull(style); AttributeSet res = style; for (StyleModifier mod : getAllModifiers()) { res = mod.apply(res, hints); } return res; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy