View Javadoc

1   package com.melloware.jukes.gui.tool.help;
2   
3   import java.net.URL;
4   
5   import javax.swing.Icon;
6   
7   import com.jgoodies.uif.util.ResourceUtils;
8   
9   
10  
11  /**
12   * Instances of this class define help nodes in the dynamic help.
13   * A help node is either a chapter or topic, where only topics have
14   * an attached URL.
15   * <p>
16   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
17   * @author Emil A. Lefkof III <info@melloware.com>
18   * @version 4.0
19   */
20  public final class HelpNode {
21  
22      public static final int CHAPTER_ITEM = 0;
23      public static final int TOPIC_ITEM = 1;
24  
25      private static final String BOOK_ICON_ID = "com.jgoodies.help.openBook.icon";
26  
27      private static final String TOPIC_ICON_ID = "com.jgoodies.help.topic.icon";
28  
29      private static final Icon BOOK_ICON = ResourceUtils.getIcon(BOOK_ICON_ID);
30  
31      private static final Icon TOPIC_ICON = ResourceUtils.getIcon(TOPIC_ICON_ID);
32      private final int type;
33  
34      private final String name;
35      private final URL url;
36  
37      /**
38       * Constructs a <code>HelpNode</code> with the given name, type, and URL.
39       */
40      private HelpNode(String name, int type, URL url) {
41          this.name = name;
42          this.type = type;
43          this.url = url;
44      }
45  
46      public Icon getIcon(boolean sel) {
47          return isChapter() ? BOOK_ICON : TOPIC_ICON;
48      }
49  
50      public URL getURL() {
51          return url;
52      }
53  
54      public boolean isChapter() {
55          return type == CHAPTER_ITEM;
56      }
57  
58      public String toString() {
59          return name;
60      }
61  
62      /**
63       * Creates and returns a chapter help node with the given name.
64       */
65      static HelpNode createChapter(String name) {
66          return new HelpNode(name, CHAPTER_ITEM, null);
67      }
68  
69      /**
70       * Creates and returns the help root node.
71       */
72      static HelpNode createRoot() {
73          return createChapter("root");
74      }
75  
76      /**
77       * Creates and returns a topic help node with the given name and path.
78       */
79      static HelpNode createTopic(String name, String path) {
80          URL url = ResourceUtils.getURL(path);
81          return new HelpNode(name, TOPIC_ITEM, url);
82      }
83  
84      boolean matches(URL aUrl) {
85          return aUrl.equals(getURL());
86      }
87  
88  }