1 /* 2 * @(#)TreeItem.java 1.28 06/10/30 3 * 4 * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. Sun designates this 10 * particular file as subject to the "Classpath" exception as provided 11 * by Sun in the LICENSE file that accompanied this code. 12 * 13 * This code is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * version 2 for more details (a copy is included in the LICENSE file that 17 * accompanied this code). 18 * 19 * You should have received a copy of the GNU General Public License version 20 * 2 along with this work; if not, write to the Free Software Foundation, 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 24 * CA 95054 USA or visit www.sun.com if you need additional information or 25 * have any questions. 26 */ 27 28 package javax.help; 29 30 import javax.help.Map.ID; 31 import java.util.Locale; 32 import java.net.URL; 33 import java.io.Serializable; 34 import java.io.IOException; 35 36 /** 37 * The base items known to TOC, Index and Favorites Navigators. 38 * 39 * @author Roger D. Brinkley 40 * @author Eduardo Pelegri-Llopart 41 * @author Richard Gregor 42 * @version 1.28 10/30/06 43 */ 44 45 public class TreeItem implements Serializable 46 { 47 48 /** 49 * A state of expansion determined by the view 50 */ 51 public static final int DEFAULT_EXPANSION = -1; 52 53 /** 54 * Show the children of the node collapsed in the view 55 */ 56 public static final int COLLAPSE = 0; 57 58 /** 59 * Show the children of the node expanded in the view 60 */ 61 public static final int EXPAND = 1; 62 63 private String name; 64 private ID id; 65 protected Locale locale; 66 private String mergeType; 67 private int expand = DEFAULT_EXPANSION; 68 private String presentation; 69 private String presentationName; 70 private HelpSet hs; 71 72 /** 73 * Create an TreeItem. 74 * 75 * @param id ID for the item. The ID can be null. 76 * @param hs A HelpSet scoping this item. 77 * @param locale The locale for this item 78 */ TreeItem(ID id, HelpSet hs, Locale locale)79 public TreeItem(ID id, HelpSet hs, Locale locale) { 80 this.id = id; 81 this.hs = hs; 82 this.locale = locale; 83 } 84 85 /** 86 * Creates a TreeItem. 87 * 88 * @param id ID for the item. Null is a valid ID. 89 * @param The lang for this item. A null is valid and indicates the default 90 * locale. 91 */ TreeItem(ID id, Locale locale)92 public TreeItem(ID id, Locale locale){ 93 this (id, null, locale); 94 } 95 /** 96 * Creates a TreeItem. 97 * 98 * @param name The name for the item. 99 */ TreeItem(String name)100 public TreeItem(String name){ 101 this(null,null, null); 102 setName(name); 103 } 104 105 /** 106 * Creates an empty TreeItem. 107 */ TreeItem()108 public TreeItem(){ 109 this(null,null); 110 } 111 /** 112 * Sets the name of the item. 113 */ setName(String name)114 public void setName(String name) { 115 this.name = name; 116 } 117 118 /** 119 * Returns the name of the item. 120 */ getName()121 public String getName() { 122 return name; 123 } 124 125 /** 126 * Set the ID for the item. 127 */ setID(ID id)128 public void setID (ID id) { 129 this.id = id; 130 } 131 132 /** 133 * Returns the ID for the item. 134 */ getID()135 public ID getID() { 136 return id; 137 } 138 139 /** 140 * Returns the URL for the item. 141 */ getURL()142 public URL getURL() { 143 try { 144 return id.getURL(); 145 } catch (Exception e) { 146 return null; 147 } 148 } 149 150 /** 151 * Set the HelpSet for this TreeItem. 152 */ setHelpSet(HelpSet hs)153 public void setHelpSet(HelpSet hs) { 154 this.hs = hs; 155 } 156 157 /** 158 * Returns the HelpSet scoping this IndexItem. Will return the ID HelpSet 159 * if one exists. Null otherwise 160 */ getHelpSet()161 public HelpSet getHelpSet() { 162 return hs; 163 } 164 165 /** 166 * Returns the locale for the item. 167 */ getLocale()168 public Locale getLocale() { 169 return locale; 170 } 171 172 /** 173 * Sets the merge type 174 */ setMergeType(String mergeType)175 public void setMergeType(String mergeType){ 176 this.mergeType = mergeType; 177 } 178 179 /** 180 * Returns the merge type for the item 181 */ getMergeType()182 public String getMergeType(){ 183 return mergeType; 184 } 185 186 /** 187 * Sets the expansion type 188 * @throws IllegalArgumentException if not a valid type 189 */ setExpansionType(int type)190 public void setExpansionType(int type) { 191 if (type < DEFAULT_EXPANSION || type > EXPAND) { 192 throw new IllegalArgumentException("Invalid expansion type"); 193 } 194 expand = type; 195 } 196 197 /** 198 * Returns the exansion type 199 */ getExpansionType()200 public int getExpansionType() { 201 return expand; 202 } 203 204 /** 205 * Sets the presentation 206 * @see Presentation 207 */ setPresentation(String presentation)208 public void setPresentation(String presentation) { 209 this.presentation = presentation; 210 } 211 212 /** 213 * Returns the presentation 214 * @see Presentation 215 */ getPresentation()216 public String getPresentation() { 217 return presentation; 218 } 219 220 /** 221 * Sets the presentation name 222 * @see Presentation 223 */ setPresentationName(String presentationName)224 public void setPresentationName(String presentationName) { 225 this.presentationName = presentationName; 226 } 227 228 /** 229 * Returns the presentation name 230 * @see Presentation 231 */ getPresentationName()232 public String getPresentationName() { 233 return presentationName; 234 } 235 236 /** 237 * Returns a String used when displaying the object. 238 * Used by CellRenderers. 239 * 240 * @see TOCCellRenderer 241 */ toString()242 public String toString() { 243 return (id+"("+name+")"); 244 } 245 246 // for serialization writeObject(java.io.ObjectOutputStream out)247 private void writeObject(java.io.ObjectOutputStream out) throws IOException { 248 //ignore so that FavoritesItem will work 249 } 250 readObject(java.io.ObjectInputStream in)251 private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { 252 //ignore so that FavoritesItem will work 253 } 254 255 256 } 257 258