1 19 package jcckit.plot; 20 21 import java.awt.Color ; 22 23 import jcckit.graphic.GraphicAttributes; 24 import jcckit.graphic.ShapeAttributes; 25 import jcckit.util.ConfigParameters; 26 27 35 public class ShapeAttributesHint implements AttributesHint, Cloneable { 36 37 public static final String INITIAL_ATTRIBUTES_KEY = "initialAttributes", 38 FILL_COLOR_HSB_INCREMENT_KEY 39 = "fillColorHSBIncrement", 40 LINE_COLOR_HSB_INCREMENT_KEY 41 = "lineColorHSBIncrement", 42 LINE_THICKNESS_INCREMENT_KEY 43 = "lineThicknessIncrement"; 44 private static float[] extractHSB(Color color) { 45 return color == null ? null 46 : Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), 47 null); 48 } 49 50 private static Color createColor(float[] colorHSB) { 51 return colorHSB == null ? null 52 : Color.getHSBColor(colorHSB[0], colorHSB[1], colorHSB[2]); 53 } 54 55 private static float[] incrementColor(float[] colorHSB, 56 double[] increments) { 57 float[] result = null; 58 if (colorHSB != null) { 59 result = (float[]) colorHSB.clone(); 60 for (int i = 0; i < 3; i++) { 61 result[i] += increments[i]; 62 } 63 } 64 return result; 65 } 66 67 private float[] _fillColorHSB; 68 private float[] _lineColorHSB; 69 private double _lineThickness; 70 private double[] _linePattern; 71 private double[] _fillColorHSBIncrement; 72 private double[] _lineColorHSBIncrement; 73 private double _lineThicknessIncrement; 74 75 100 public ShapeAttributesHint(ConfigParameters config) { 101 ShapeAttributes attributes 102 = new ShapeAttributes(config.getNode(INITIAL_ATTRIBUTES_KEY)); 103 _fillColorHSB = extractHSB(attributes.getFillColor()); 104 _lineColorHSB = extractHSB(attributes.getLineColor()); 105 _lineThickness = attributes.getLineThickness(); 106 _linePattern = attributes.getLinePattern(); 107 108 _fillColorHSBIncrement 109 = config.getDoubleArray(FILL_COLOR_HSB_INCREMENT_KEY, new double[3]); 110 _lineColorHSBIncrement 111 = config.getDoubleArray(LINE_COLOR_HSB_INCREMENT_KEY, new double[3]); 112 _lineThicknessIncrement 113 = config.getDouble(LINE_THICKNESS_INCREMENT_KEY, 0); 114 } 115 116 120 public AttributesHint getNextHint() { 121 ShapeAttributesHint nextHint = null; 122 try { 123 nextHint = (ShapeAttributesHint) clone(); 124 } catch (CloneNotSupportedException e) {} 125 nextHint._fillColorHSB 126 = incrementColor(_fillColorHSB, _fillColorHSBIncrement); 127 nextHint._lineColorHSB 128 = incrementColor(_lineColorHSB, _lineColorHSBIncrement); 129 nextHint._lineThickness 130 = Math.max(0, _lineThickness + _lineThicknessIncrement); 131 return nextHint; 132 } 133 134 135 public GraphicAttributes getAttributes() { 136 return new ShapeAttributes(createColor(_fillColorHSB), 137 createColor(_lineColorHSB), 138 _lineThickness, _linePattern); 139 } 140 } 141 | Popular Tags |