/** * Constructs a new factory. */ public ThemedGradientFactory (ConfigurableFactory<?> parent, List<String> path) { super(ThemedGradient.class, parent, path); addProperty(THEME); addProperty(COLORS); addProperty(ALPHAS); }
/** * Parse a color from a string and return it. In the case of an error * this function will return the color white. * * @param color * The color definition in string form. * @return * The interpreted color or a default of white. */ public static Color getColor(String color) { return getColor(color, Color.WHITE); }
/** * Returns the theme name. * @return the theme name */ public String getTheme() throws ConfigurationException { return getPropertyValue(THEME); }
@Test public void testPropertyFileSerialization () throws ConfigurationException { FixedPointProperty prop = new FixedPointProperty("", ""); FixedPoint pt = new FixedPoint(3.0, 4.0); String encoded = prop.encode(pt); FixedPoint redux = prop.unencode(encoded); Assert.assertEquals(pt, redux); }
@Test public void testJSONSerialization () throws JSONException, ConfigurationException { FixedPointProperty prop = new FixedPointProperty("", ""); FixedPoint pt = new FixedPoint(3.0, 4.0); JSONObject root = new JSONObject(); JSONNode node = new JSONNode(root, "fixedpoint"); prop.encodeJSON(node, pt); FixedPoint redux = prop.unencodeJSON(node); Assert.assertEquals(pt, redux); } }
public BRColorRamp (boolean inverted, double opacity) { super(inverted, Arrays.asList(new FixedPoint(0.25, 0.0), new FixedPoint(0.50, 0.5), new FixedPoint(1.00, 1.0)), Arrays.asList(new FixedPoint(0.25, 0.0), new FixedPoint(0.375, 0.25), new FixedPoint(0.625, 0.25), new FixedPoint(0.75, 0.0)), Arrays.asList(new FixedPoint(0.00, 0.5), new FixedPoint(0.25, 1.0), new FixedPoint(0.75, 0.0)), null, opacity); } }
public static double valueFromFixedPoints(List<FixedPoint> values, double scale) { FixedPoint start = values.get(0); if (scale<start.getScale()) return start.getValue(); for (int i=1; i<values.size(); i++) { FixedPoint pt = values.get(i); if (scale<pt.getScale()) { return ((scale-start.getScale())*pt.getValue() + (pt.getScale()-scale)*start.getValue())/(pt.getScale()-start.getScale()); } start = pt; } return start.getValue(); }
private void readGradients(JSONArray gradients, List<ThemedGradientFactory> into) throws JSONException, ConfigurationException { for (int i=0; i<gradients.length(); i++) { final JSONObject node = gradients.getJSONObject(i); final List<String> nopath = Collections.emptyList(); final ThemedGradientFactory factory = new ThemedGradientFactory(null, nopath); factory.readConfiguration(node); into.add(factory); } }
public ColorRampFactory (ConfigurableFactory<?> parent, List<String> path) { super(ColorRamp.class, parent, path); addProperty(RAMP_TYPE); addProperty(OPACITY); addProperty(COLOR1); addProperty(ALPHA1); addProperty(COLOR2); addProperty(ALPHA2); addProperty(HUE1); addProperty(HUE2); addProperty(GRADIENTS); addProperty(THEME); }
/** * Parse a color from a string, combine it with separately defined alpha and return * it. In the case of an error this function will return the color white. * * @param color * The color definition in string form. * @param alpha * The alpha value (0-255) in int form. * * @return * The interpreted color or a default of white. */ public static Color getColorWithAlpha (String color, int alpha) { return getColorWithAlpha(color, alpha, Color.WHITE); }
public ImageRendererFactory (String name, ConfigurableFactory<?> parent, List<String> path) { super(name, getFactoryClass(), parent, path); addProperty(RENDERER_TYPE); addChildFactory(new ColorRampFactory(this, new ArrayList<String>())); }
public GreyColorRamp (boolean inverted, double opacity) { super(inverted, Arrays.asList(new FixedPoint(0.0, 0.0), new FixedPoint(1.0, 1.0)), Arrays.asList(new FixedPoint(0.0, 0.0), new FixedPoint(1.0, 1.0)), Arrays.asList(new FixedPoint(0.0, 0.0), new FixedPoint(1.0, 1.0)), null, opacity); } }
/** * Parse a color from a string, combine it with separately defined alpha and return * it. In the case of an error this function will return the color white. * * @param color * The color definition in string form. * @param alpha * The alpha value (0-255) in int form. * * @return * The interpreted color or a default of white. */ public static Color getColorWithAlpha (String color, int alpha, Color defaultColor) { Color base = getColor(color, defaultColor); alpha = Math.min(Math.max(alpha, 0), 255); return new Color(base.getRed(), base.getGreen(), base.getBlue(), alpha); } }
public WareColorRamp (boolean inverted, double opacity) { super(inverted, Arrays.asList(new FixedPoint(0, 0.25), new FixedPoint(0.25, 0.9), new FixedPoint(0.5, 0.1), new FixedPoint(0.75, 1)), new ArrayList<FixedPoint>(), Arrays.asList(new FixedPoint(0, 0.25), new FixedPoint(0.25, 0), new FixedPoint(0.85, 0), new FixedPoint(1, 1)), null, opacity); } }
public SingleGradientColorRamp (Color from, Color to) { super(false, Arrays.asList(new FixedPoint(0.0, from.getRed()/255.0), new FixedPoint(1.0, to.getRed()/255.0)), Arrays.asList(new FixedPoint(0.0, from.getGreen()/255.0), new FixedPoint(1.0, to.getGreen()/255.0)), Arrays.asList(new FixedPoint(0.0, from.getBlue()/255.0), new FixedPoint(1.0, to.getBlue()/255.0)), Arrays.asList(new FixedPoint(0.0, from.getAlpha()/255.0), new FixedPoint(1.0, to.getAlpha()/255.0)), 255); } }
public AbstractColorRamp (boolean inverted, List<FixedPoint> reds, List<FixedPoint> greens, List<FixedPoint> blues, List<FixedPoint> alphas, double opacity){ this.isInverted = inverted; this.reds = reds; this.greens = greens; this.blues = blues; if (null == alphas) { //there's no alphas, so initialize them with the single opacity field this.alphas = new ArrayList<>(); this.alphas.add(new FixedPoint(0, opacity)); this.alphas.add(new FixedPoint(1, opacity)); } else { this.alphas = alphas; } }
@Override public FixedPoint unencode (String string) throws ConfigurationException { String[] parts = string.split("by"); return new FixedPoint(Double.parseDouble(parts[0]), Double.parseDouble(parts[1])); }
@Override public FixedPoint unencodeJSON (JSONNode propertyNode) throws JSONException, ConfigurationException { JSONObject node = propertyNode.getAsJSONObject(); return new FixedPoint(node.getDouble("scale"), node.getDouble("value")); }