001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.javadoc.search;
043:
044: import java.net.URL;
045: import java.util.Comparator;
046:
047: /**
048: * Represents one item found in document index.
049: * It's produced by {@link IndexSearchThread} and communicated
050: * back to {@link IndexSearch} UI.
051: *
052: * @author Petr Hrebejk
053: */
054: final class DocIndexItem extends Object {
055:
056: /** Standard comparators */
057: public static final Comparator REFERENCE_COMPARATOR = new ReferenceComparator();
058: public static final Comparator TYPE_COMPARATOR = new TypeComparator();
059: public static final Comparator ALPHA_COMPARATOR = new AlphaComparator();
060:
061: private String text = null;
062: private URL contextURL = null;
063: private String spec = null;
064: private String remark = null;
065: private String pckg = null;
066: private String declaringClass = null;
067:
068: private int iconIndex = DocSearchIcons.ICON_NOTRESOLVED;
069:
070: public DocIndexItem(String text, String remark, URL contextURL,
071: String spec) {
072: this .text = text;
073: this .remark = remark;
074: this .contextURL = contextURL;
075: this .spec = spec;
076: if (spec != null) { // spec format ../pckg/Classname.html
077: int offset = spec.startsWith("../") ? 3 : 0; // NOI18N
078: int length = spec.lastIndexOf('/');
079: length = length < 0 ? spec.length() : length + 1;
080: pckg = spec.substring(offset, length);
081: // System.out.println("DII.length: " + length);
082: // System.out.println("DII: " + length + ", " + pckg + " <- " + spec);
083: pckg = pckg.replace('/', '.');
084: }
085: }
086:
087: public URL getURL() throws java.net.MalformedURLException {
088: return contextURL != null ? new URL(contextURL, spec) : null;
089: }
090:
091: public String toString() {
092: if (remark != null)
093: return text + remark;
094: else
095: return text;
096: }
097:
098: public int getIconIndex() {
099: return iconIndex;
100: }
101:
102: public void setIconIndex(int iconIndex) {
103: this .iconIndex = iconIndex;
104: }
105:
106: public String getRemark() {
107: return remark;
108: }
109:
110: public void setRemark(String remark) {
111: this .remark = remark;
112: }
113:
114: public String getPackage() {
115: return pckg == null ? "" : pckg; // NOI18N
116: }
117:
118: public void setPackage(String pckg) {
119: // System.out.println("DII.set: " + pckg);
120: this .pckg = pckg;
121: }
122:
123: /** Getter for property declaringClass.
124: * @return Value of property declaringClass.
125: */
126: public java.lang.String getDeclaringClass() {
127: return declaringClass;
128: }
129:
130: /** Setter for property declaringClass.
131: * @param declaringClass New value of property declaringClass.
132: */
133: public void setDeclaringClass(java.lang.String declaringClass) {
134: this .declaringClass = declaringClass;
135: }
136:
137: /** Getter for property field.
138: * @return Value of property field.
139: */
140: public java.lang.String getField() {
141: return text != null ? text : ""; //NOI18N
142: }
143:
144: /** Setter for property field.
145: * @param Value of property field.
146: */
147: public void setField(String text) {
148: this .text = text;
149: }
150:
151: // COMPARATOR INNER CLASSES ----------------------------------------------------------------
152:
153: static final class ReferenceComparator implements
154: java.util.Comparator {
155:
156: public int compare(Object dii1, Object dii2) {
157: int res = ((DocIndexItem) dii1).getPackage().compareTo(
158: ((DocIndexItem) dii2).getPackage());
159:
160: return res != 0 ? res : DocIndexItem.ALPHA_COMPARATOR
161: .compare(dii1, dii2);
162: }
163:
164: public boolean equals(Object comp) {
165: return (comp instanceof ReferenceComparator);
166: }
167:
168: public int hashCode() {
169: return 353;
170: }
171:
172: }
173:
174: static final class TypeComparator implements java.util.Comparator {
175:
176: public int compare(Object dii1, Object dii2) {
177: return ((DocIndexItem) dii1).getIconIndex()
178: - ((DocIndexItem) dii2).getIconIndex();
179: }
180:
181: public boolean equals(Object comp) {
182: return (comp instanceof TypeComparator);
183: }
184:
185: public int hashCode() {
186: return -34;
187: }
188:
189: }
190:
191: static final class AlphaComparator implements java.util.Comparator {
192:
193: public int compare(Object dii1, Object dii2) {
194: return ((DocIndexItem) dii1).toString().compareTo(
195: ((DocIndexItem) dii2).toString());
196: }
197:
198: public boolean equals(Object comp) {
199: return (comp instanceof AlphaComparator);
200: }
201:
202: public int hashCode() {
203: return 33;
204: }
205: }
206: }
|