1 11 package org.eclipse.jface.resource; 12 13 import org.eclipse.swt.graphics.Device; 14 import org.eclipse.swt.graphics.Font; 15 import org.eclipse.swt.graphics.FontData; 16 17 22 final class ArrayFontDescriptor extends FontDescriptor { 23 24 private FontData[] data; 25 private Font originalFont = null; 26 27 37 public ArrayFontDescriptor(FontData[] data) { 38 this.data = data; 39 } 40 41 49 public ArrayFontDescriptor(Font originalFont) { 50 this(originalFont.getFontData()); 51 this.originalFont = originalFont; 52 } 53 54 57 public FontData[] getFontData() { 58 return copy(data); 60 } 61 62 63 66 public Font createFont(Device device) { 67 68 if (originalFont != null) { 71 if (originalFont.getDevice() == device) { 73 return originalFont; 74 } 75 } 76 77 return new Font(device, data); 78 } 79 80 83 public boolean equals(Object obj) { 84 if ((obj.getClass() == ArrayFontDescriptor.class)) { 85 ArrayFontDescriptor descr = (ArrayFontDescriptor)obj; 86 87 if (descr.originalFont != originalFont) { 88 return false; 89 } 90 91 if (originalFont != null) { 92 return true; 93 } 94 95 if (data.length != descr.data.length) { 96 return false; 97 } 98 99 for (int i = 0; i < data.length; i++) { 100 FontData fd = data[i]; 101 FontData fd2 = descr.data[i]; 102 103 if (!fd.equals(fd2)) { 104 return false; 105 } 106 } 107 108 return true; 109 } 110 111 return false; 112 } 113 114 117 public int hashCode() { 118 if (originalFont != null) { 119 return originalFont.hashCode(); 120 } 121 122 int code = 0; 123 124 for (int i = 0; i < data.length; i++) { 125 FontData fd = data[i]; 126 code += fd.hashCode(); 127 } 128 return code; 129 } 130 131 134 public void destroyFont(Font previouslyCreatedFont) { 135 if (previouslyCreatedFont == originalFont) { 136 return; 137 } 138 previouslyCreatedFont.dispose(); 139 } 140 141 } 142 | Popular Tags |