1 43 44 package org.jfree.util; 45 46 import java.awt.Paint ; 47 import java.io.IOException ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutputStream ; 50 51 import org.jfree.io.SerialUtilities; 52 53 58 public class PaintList extends AbstractObjectList { 59 60 63 public PaintList() { 64 super(); 65 } 66 67 74 public Paint getPaint(final int index) { 75 return (Paint ) get(index); 76 } 77 78 84 public void setPaint(final int index, final Paint paint) { 85 set(index, paint); 86 } 87 88 95 public boolean equals(final Object obj) { 96 if (obj == null) { 97 return false; 98 } 99 if (obj == this) { 100 return true; 101 } 102 if (obj instanceof PaintList) { 103 PaintList that = (PaintList) obj; 104 int listSize = size(); 105 for (int i = 0; i < listSize; i++) { 106 if (!PaintUtilities.equal(getPaint(i), that.getPaint(i))) { 107 return false; 108 } 109 } 110 } 111 return true; 112 } 113 114 119 public int hashCode() { 120 return super.hashCode(); 121 } 122 123 130 private void writeObject(final ObjectOutputStream stream) throws IOException { 131 132 stream.defaultWriteObject(); 133 final int count = size(); 134 stream.writeInt(count); 135 for (int i = 0; i < count; i++) { 136 final Paint paint = getPaint(i); 137 if (paint != null) { 138 stream.writeInt(i); 139 SerialUtilities.writePaint(paint, stream); 140 } 141 else { 142 stream.writeInt(-1); 143 } 144 } 145 146 } 147 148 156 private void readObject(final ObjectInputStream stream) throws IOException , ClassNotFoundException { 157 158 stream.defaultReadObject(); 159 final int count = stream.readInt(); 160 for (int i = 0; i < count; i++) { 161 final int index = stream.readInt(); 162 if (index != -1) { 163 setPaint(index, SerialUtilities.readPaint(stream)); 164 } 165 } 166 167 } 168 169 } 170 171 | Popular Tags |