001 /*
002 Copyright (c) 1996-2012, Damon Hart-Davis
003 All rights reserved.
004
005 Redistribution and use in source and binary forms, with or without
006 modification, are permitted provided that the following conditions are
007 met:
008
009 * Redistributions of source code must retain the above copyright
010 notice, this list of conditions and the following disclaimer.
011
012 * Redistributions in binary form must reproduce the above copyright
013 notice, this list of conditions and the following disclaimer in the
014 documentation and/or other materials provided with the
015 distribution.
016
017 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
018 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
019 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
020 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
021 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
022 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
023 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
024 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
025 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
027 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028 */
029
030 package org.hd.d.pg2k.webSvr.catalogue;
031
032 import java.awt.Dimension;
033
034 import org.hd.d.pg2k.svrCore.AllExhibitProperties;
035 import org.hd.d.pg2k.svrCore.ExhibitName;
036 import org.hd.d.pg2k.svrCore.ExhibitPropsComputable;
037 import org.hd.d.pg2k.svrCore.ImageUtils;
038 import org.hd.d.pg2k.svrCore.Name;
039 import org.hd.d.pg2k.svrCore.MIME.ExhibitMIME;
040 import org.hd.d.pg2k.webSvr.exhibit.Expr;
041 import org.hd.d.pg2k.webSvr.exhibit.FilterExpr;
042 import org.hd.d.pg2k.webSvr.exhibit.FilterIF;
043
044 /**
045 * Created by IntelliJ IDEA.
046 * User: Damon Hart-Davis
047 * Date: 04-Jul-2003
048 * Time: 20:19:11
049 */
050
051 /**Generates the "all icons" tree.
052 * This consists of all HTML-inlineable images of side no more than 64 pixels.
053 */
054 public final class TreeFilterServletAllIcons extends TreeFilterServletBase
055 {
056 /**Get (short) title text common catalogue name; null if none.
057 * The expanded text should be 7-bit printable ASCII,
058 * possibly with embedded entities and mark-up.
059 */
060 @Override
061 protected String getTitleCommonCatalogueName()
062 { return("common.virtCol.allIcons.title"); }
063
064 /**Get descriptive text (i18n-ed if possible); null if none.
065 * The expanded text should be 7-bit printable ASCII,
066 * possibly with embedded entities and mark-up.
067 * <p>
068 * Defaults to null (no descriptive text).
069 * <p>
070 * Override as needed in derived classes.
071 */
072 @Override
073 protected String getDescriptionCommonCatalogueName()
074 { return("common.virtCol.allIcons.description"); }
075
076 /**Get the filter expression to apply.
077 * Defaults to accept as icons as per the class description.
078 * <p>
079 * Should only be called once,
080 * so need not implement equals() and hashCode() in the class.
081 */
082 @Override
083 protected Expr getFilter()
084 {
085 return(new FilterExpr(null, (new FilterIF(){
086 public boolean accept(final AllExhibitProperties aep, final Name.ExhibitFull exhibitName)
087 {
088 // If the exhibit is not appropriate to inline in an HTML page
089 // then stop immediately.
090 final String extension =
091 ExhibitName.getExtensionComponent(exhibitName).toString();
092 final ExhibitMIME.ExhibitTypeParameters exhibitType =
093 ExhibitMIME.getExhibitType(extension);
094 if(!ImageUtils.canInlineInHTMLPageSimple(exhibitType))
095 { return(false); }
096
097 // Now get the image dimensions...
098 final ExhibitPropsComputable epc =
099 aep.getExhibitPropsComputable(exhibitName);
100 if(epc == null) { return(false); }
101 final Dimension xyDim = epc.getXyDimensions();
102
103 // Not valid if no dimensions or item not square...
104 if((xyDim == null) ||
105 (xyDim.width > 64) ||
106 (xyDim.height > 64))
107 { return(false); }
108
109 // // Right, now check if edge size is good for us...
110 // final int l = xyDim.width;
111 // return((l == 16) || (l == 32) || (l == 64));
112
113 return(true); // Seems OK.
114 }
115
116 /**Unique Serialisation class ID generated by http://random.hd.org/. */
117 private static final long serialVersionUID = 4157995688833159375L;
118 })));
119 }
120
121 /**Unique Serialisation class ID generated by http://random.hd.org/. */
122 private static final long serialVersionUID = -3815214610456191652L;
123 }