~vcs-imports/xena/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
 * @(#)TreeItem.java	1.28 06/10/30
 * 
 * Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 * 
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 * 
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

package javax.help;

import javax.help.Map.ID;
import java.util.Locale;
import java.net.URL;
import java.io.Serializable;
import java.io.IOException;

/**
 * The base items known to TOC, Index and Favorites Navigators.
 *
 * @author Roger D. Brinkley
 * @author Eduardo Pelegri-Llopart
 * @author Richard Gregor
 * @version   1.28     10/30/06
 */

public class TreeItem implements Serializable
{

    /**
     * A state of expansion determined by the view
     */
    public static final int DEFAULT_EXPANSION = -1;

    /**
     * Show the children of the node collapsed in the view
     */
    public static final int COLLAPSE = 0;

    /**
     * Show the children of the node expanded in the view
     */
    public static final int EXPAND = 1;

    private String name;
    private ID id;
    protected Locale locale;
    private String mergeType;
    private int expand = DEFAULT_EXPANSION;
    private String presentation;
    private String presentationName;
    private HelpSet hs;

     /**
     * Create an TreeItem.
     *
     * @param id ID for the item. The ID can be null.
     * @param hs A HelpSet scoping this item.
     * @param locale The locale for this item
     */
    public TreeItem(ID id, HelpSet hs, Locale locale) {
	this.id = id;
	this.hs = hs;
	this.locale = locale;
    }

   /**
     * Creates a TreeItem.
     *
     * @param id ID for the item. Null is a valid ID.
     * @param The lang for this item. A null is valid and indicates the default
     * locale.
     */
    public TreeItem(ID id, Locale locale){
	this (id, null, locale);
    }
    /**
     * Creates a TreeItem.
     *
     * @param name The name for the item.
     */
    public TreeItem(String name){
        this(null,null, null);
        setName(name);
    }
    
    /**
     * Creates an empty TreeItem.
     */
    public TreeItem(){
        this(null,null);        
    }
    /**
     * Sets the name of the item.
     */
    public void setName(String name) {
	this.name = name;
    }

    /**
     * Returns the name of the item.
     */
    public String getName() {
	return name;
    }
    
    /**
     * Set the ID for the item.
     */
    public void setID (ID id) {
	this.id = id;
    }

    /**
     * Returns the ID for the item.
     */
    public ID getID() {
	return id;
    }

    /**
     * Returns the URL for the item.
     */
    public URL getURL() {
        try {
            return id.getURL();
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * Set the HelpSet for this TreeItem.
     */
    public void setHelpSet(HelpSet hs) {
	this.hs = hs;
    }

    /**
     * Returns the HelpSet scoping this IndexItem. Will return the ID HelpSet
     * if one exists. Null otherwise
     */
    public HelpSet getHelpSet() {
	return hs;
    }
    
    /**
     * Returns the locale for the item.
     */
    public Locale getLocale() {
	return locale;
    }
    
    /**
     * Sets the merge type
     */
    public void setMergeType(String mergeType){
        this.mergeType = mergeType;
    }
    
    /**
     * Returns the merge type for the item
     */
    public String getMergeType(){
        return mergeType;
    }

    /**
     * Sets the expansion type
     * @throws IllegalArgumentException if not a valid type
     */
    public void setExpansionType(int type) {
	if (type < DEFAULT_EXPANSION || type > EXPAND) {
	    throw new IllegalArgumentException("Invalid expansion type");
	}
	expand = type;
    }

    /**
     * Returns the exansion type
     */
    public int getExpansionType() {
	return expand;
    }

    /**
     * Sets the presentation
     * @see Presentation
     */
    public void setPresentation(String presentation) {
	this.presentation = presentation;
    }

    /**
     * Returns the presentation
     * @see Presentation
     */
    public String getPresentation() {
	return presentation;
    }

    /**
     * Sets the presentation name
     * @see Presentation
     */
    public void setPresentationName(String presentationName) {
	this.presentationName = presentationName;
    }

    /**
     * Returns the presentation name
     * @see Presentation
     */
    public String getPresentationName() {
	return presentationName;
    }

    /**
     * Returns a String used when displaying the object.
     * Used by CellRenderers.
     *
     * @see TOCCellRenderer
     */
    public String toString() {
	return (id+"("+name+")");
    }

    // for serialization
     private void writeObject(java.io.ObjectOutputStream out) throws IOException {
         //ignore so that FavoritesItem will work
     }
     
     private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
         //ignore so that FavoritesItem will work
     }
 

}