// XAAL toolkit // Copyright (C) 2009 Ville Karavirta // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package xaal.objects.graphical; import java.awt.Color; import xaal.util.XaalConstants; /** * @author vkaravir * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class Style implements Cloneable { private Color color = Color.BLACK; private boolean colorSet = false; //private String colorName; private Color fillColor; //private String fillColorName; private Font font; private String id; private Style uses; private boolean forwArrow = XaalConstants.DEFAULT_PROPERTY_FORWARDARROW; private boolean forwArrowSet = false; private boolean backwArrow = XaalConstants.DEFAULT_PROPERTY_BACKWARDARROW; private boolean backwArrowSet = false; private String strokeType; private int strokeWidth = -1; private static int count = 1; /** * */ public Style() { super(); count++; } public Style(Style parent) { this(); setUses(parent); } public Object clone() throws CloneNotSupportedException { Style copy = (Style) super.clone(); if (uses != null) copy.uses = (Style) uses.clone(); return copy; } /** * @return Returns the color. */ public Color getColor() { /*if (colorName != null) return getColor(colorName);*/ if ((color == null || !colorSet) && uses != null) return uses.getColor(); return color; } /** * @param color The color to set. */ public void setColor(Color color) { this.color = color; colorSet = true; } public void setColor(String colorName) { if (ColorConverter.isPredefinedColorName(colorName)) color = ColorConverter.getPredefinedColor(colorName); } /** * @return Returns the fillColor. */ public Color getFillColor() { /*if (fillColorName != null) return getColor(fillColorName); else*/ if (fillColor == null && uses != null) return uses.getFillColor(); else return fillColor; } /** * @param fillColor The fillColor to set. */ public void setFillColor(Color fillColor) { this.fillColor = fillColor; } public void setFillColor(String colorName) { if (ColorConverter.isPredefinedColorName(colorName)) { fillColor = ColorConverter.getPredefinedColor(colorName); } } /** * @return Returns the font. */ public Font getFont() { if (font == null && uses != null) return uses.getFont(); else if (font == null) return XaalConstants.getDefaultFont(); else return font; } /** * @param font The font to set. */ public void setFont(Font font) { this.font = font; } /** * Returns a jawa.awt.Color object corresponding the given color name, or * null if no such color exists. * * @param cName name of the color * @return a jawa.awt.Color object corresponding the given color name, or * null if no such color exists */ /* private Color getColor(String cName) { return ColorConverter.getPredefinedColor(cName); }*/ /** * @return Returns the id. */ public String getId() { if (id == null) { id = generateId(); } return id; } /** * @param id The id to set. */ public void setId(String id) { this.id = id; } /** * @return Returns the uses. */ public Style getUses() { return uses; } /** * @param uses The uses to set. */ public void setUses(Style uses) { this.uses = uses; } /** * @return Returns the backwArrow. */ public boolean isBackwardArrow() { if (!backwArrowSet && uses != null) return uses.isBackwardArrow(); else return backwArrow; } /** * @param backwArrow The backwArrow to set. */ public void setBackwardArrow(boolean backwArrow) { this.backwArrow = backwArrow; backwArrowSet = true; } /** * @return Returns the forwArrow. */ public boolean isForwardArrow() { if (!forwArrowSet && uses != null) return uses.isForwardArrow(); else return forwArrow; } /** * @param forwArrow The forwArrow to set. */ public void setForwardArrow(boolean forwArrow) { this.forwArrow = forwArrow; forwArrowSet = true; } /** * @return Returns the strokeType. */ public String getStrokeType() { if (strokeType == null && uses != null) return uses.getStrokeType(); if (strokeType == null) return XaalConstants.DEFAULT_PROPERTY_STROKETYPE; return strokeType; } /** * @param strokeType The strokeType to set. */ public void setStrokeType(String strokeType) { if (!strokeType.equalsIgnoreCase("solid") && !strokeType.equalsIgnoreCase("dashed") && !strokeType.equalsIgnoreCase("dotted")) { // TODO Common error logging - invalid stroke type return; } this.strokeType = strokeType; } /** * @return Returns the strokeWidth. */ public int getStrokeWidth() { if (strokeWidth == -1 && uses != null) return uses.getStrokeWidth(); if (strokeWidth == -1) return XaalConstants.DEFAULT_PROPERTY_STROKEWIDTH; return strokeWidth; } /** * @param strokeWidth The strokeWidth to set. */ public void setStrokeWidth(int strokeWidth) { this.strokeWidth = strokeWidth; } /** * Generates a unique id for this style. * * @return A unique id. */ protected String generateId() { return "style-auto-" + count++; } public boolean equalsIgnoreId(Style style) { if (getColor() != null && !getColor().equals(style.getColor())) { return false; } else if (getFillColor() != null && !getFillColor().equals(style.getFillColor())) { return false; } else if (isBackwardArrow() != style.isBackwardArrow() || isForwardArrow() != style.isForwardArrow()) { return false; } else if ((getUses() == null && style.getUses() != null) || (getUses() != null && style.getUses() == null)) { return false; } else if ((getUses() != null && style.getUses()!= null) && !getUses().getId().equals(style.getUses().getId())) { return false; } else if (getFont() != null && !getFont().equals(style.getFont())) { return false; } else if (!getStrokeType().equals(style.getStrokeType()) || getStrokeWidth() != style.getStrokeWidth()) { return false; } return true; } }