1 package net.sourceforge.jsh3modtool.gui.imagetable; 2 3 4 /*** 5 * A Table cell for an Image 6 * 7 * @author redsolo 8 */ 9 public class ImageCell extends BaseCell 10 { 11 private boolean triedToLoadImage = false; 12 private String loadImageErrorMessage; 13 14 private boolean isSelected; 15 16 private boolean isTooltipCached; 17 private String cachedTooltip; 18 19 private final ImageModel image; 20 21 /*** 22 * Creates a new instance of ImageCell 23 * @param imageProps the image 24 */ 25 public ImageCell(ImageModel image) 26 { 27 super(); 28 isTooltipCached = false; 29 this.image = image; 30 } 31 32 public String getName() 33 { 34 return image.getName(); 35 } 36 37 public ImageModel getImageModel() 38 { 39 return image; 40 } 41 42 /*** 43 * Returns if the ThumbnailLoader has tried to load the image, if it has 44 * and there still is no image, then an error has occurred 45 * @return true if it has tried to load the image 46 */ 47 public boolean hasTriedToLoadImage() 48 { 49 return triedToLoadImage; 50 } 51 52 /*** 53 * Sets if the ThumbnailLoader has tried to load the image 54 * @param triedToLoad if the image has been tried or not 55 */ 56 public void setHasTriedToLoadImage( final boolean triedToLoad ) 57 { 58 triedToLoadImage = triedToLoad; 59 } 60 61 /*** 62 * Returns the error message, if there is one 63 * @return a String containing the error; null otherwise 64 */ 65 public String getErrorMessage() 66 { 67 return loadImageErrorMessage; 68 } 69 70 /*** 71 * Sets the error message 72 * @param msg the error message 73 */ 74 public void setErrorMessage( final String msg ) 75 { 76 loadImageErrorMessage = msg; 77 } 78 79 /*** 80 * Returns if this image cell is selected or not 81 * @return true if the cell is selected; false otherwise 82 */ 83 public boolean isSelected() 84 { 85 return isSelected; 86 } 87 88 /*** 89 * Sets if the iamge cell is selected or not. 90 * @param selected if the image is selected. 91 */ 92 public void setSelected( final boolean selected ) 93 { 94 isSelected = selected; 95 } 96 97 /*** 98 * Toggle the selected status. 99 */ 100 public void toggleSelected() 101 { 102 isSelected = ( isSelected ? false : true ); 103 } 104 105 /*** 106 * Resets the tooltip, next time the GUI wants the tooltip then it is generated 107 * on the fly 108 */ 109 public void resetTooltip() 110 { 111 isTooltipCached = false; 112 } 113 114 /*** 115 * Returns the tooltip for this cell, the tooltip contains some IPTC fields 116 * and is cached for performance 117 * @return a String, never null 118 */ 119 public String getTooltip() 120 { 121 if ( ! isTooltipCached ) 122 { 123 final StringBuffer tipBuffer = new StringBuffer(); 124 125 tipBuffer.append("<html><body>"); 126 tipBuffer.append(image.getDescription()); 127 tipBuffer.append("</body></html>"); 128 cachedTooltip = tipBuffer.toString(); 129 isTooltipCached = true; 130 } 131 return cachedTooltip; 132 } 133 134 /*** 135 * {@inheritDoc} 136 */ 137 public int hashCode() 138 { 139 return image.hashCode(); 140 } 141 142 /*** 143 * {@inheritDoc} 144 */ 145 public boolean equals( final Object other ) 146 { 147 return image.equals(((ImageCell) other).image); 148 } 149 150 /*** 151 * Returns the name of the image. 152 * @return the name of the image. 153 */ 154 public String toString() 155 { 156 return image.getName(); 157 } 158 }