- Timestamp:
- 2003-05-27T15:49:22+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/help/HelpFrame.java
r4293 r4365 75 75 */ 76 76 public class HelpFrame 77 78 79 80 77 extends JFrame { 78 /** The html rendering pane. */ 79 private CalHTMLPane view = null; 80 private ContentModel model = null; 81 81 82 83 84 85 86 87 88 89 90 91 92 82 private JSplitPane split_pane = null; 83 /** A contents tree for the left of the frame. */ 84 private JTree contents = null; 85 /** The size of a button on this pane. */ 86 static final Dimension BUTTON_SIZE = new Dimension(100,50); 87 /** The minimum size of any component in this frame. */ 88 static final Dimension MIN_SIZE = new Dimension(100,100); 89 /** The size of the frame itself. */ 90 static final Dimension SIZE = new Dimension(760,560); 91 /** Constructor. 92 * @param file_name The file name, as a <Strong>String</strong> of the help page to initially show. 93 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 94 public HelpFrame() { 95 setDefaultCloseOperation(HIDE_ON_CLOSE); 96 setSize(SIZE); 97 model = new ContentModel(); 98 contents = new JTree(model); 99 contents.addTreeSelectionListener(new ContentsListener()); 100 contents.setExpandsSelectedPaths(true); 101 view = new CalHTMLPane(); 102 // Creation 103 JPanel content_pane = (JPanel) this.getContentPane(); 104 split_pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); 105 JScrollPane index_scroll = new JScrollPane(contents); 106 JScrollPane view_scroll = new JScrollPane(view); 107 // Layout 108 split_pane.add(index_scroll, JSplitPane.LEFT); 109 split_pane.add(view_scroll, JSplitPane.RIGHT); 110 content_pane.setLayout(new BorderLayout()); 111 content_pane.add(split_pane, BorderLayout.CENTER); 112 // Center 113 Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize(); 114 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); 115 } 116 /** Destructor. Removes all listeners, closes streams and explicitly sets data members to null. */ 117 public void destroy() { 118 view = null; 119 contents = null; 120 } 121 public void setView(String index) { 122 try { 123 123 // Retrieve the node at index 124 125 126 127 128 129 130 131 132 133 134 124 HelpItem current = (HelpItem) model.getRoot(); 125 StringTokenizer tokenizer = new StringTokenizer(index, "."); 126 while(tokenizer.hasMoreTokens()) { 127 String token = tokenizer.nextToken(); 128 int position = Integer.parseInt(token); 129 if(position > 0 && position <= current.getChildCount()) { 130 current = (HelpItem) current.getChildAt(position - 1); 131 } 132 token = null; 133 } 134 tokenizer = null; 135 135 // Ensure path is selected 136 137 138 139 136 TreePath path = new TreePath(current.getPath()); 137 contents.setSelectionPath(path); 138 contents.scrollPathToVisible(path); 139 path = null; 140 140 // Build url 141 142 141 URL url = current.getURL(); 142 current = null; 143 143 // Show help dialog 144 145 144 show(); 145 split_pane.setDividerLocation(0.2); 146 146 // Display help page 147 148 149 150 151 152 153 154 155 156 147 if(url != null) { 148 view.showHTMLDocument(url); 149 } 150 url = null; 151 } 152 catch (Exception error) { 153 show(); 154 split_pane.setDividerLocation(0.2); 155 } 156 } 157 157 158 158 /** This listener is used to lister for selection changes in the contents tree, and to show the appropriate page as required. 159 159 */ 160 161 162 163 160 private class ContentsListener 161 implements TreeSelectionListener { 162 /** Any implementation of <i>TreeSelectionListener</i> must include this method so we can be informed when the tree selection changes. 163 * @param event A <strong>TreeSelectionEvent</strong> containing al the relevant information about the event itself. 164 164 */ 165 166 167 168 169 170 171 172 173 165 public void valueChanged(TreeSelectionEvent event) { 166 TreePath path = event.getPath(); 167 HelpItem node = (HelpItem)path.getLastPathComponent(); 168 URL url = node.getURL(); 169 if(url != null) { 170 view.showHTMLDocument(url); 171 } 172 } 173 } 174 174 }
Note:
See TracChangeset
for help on using the changeset viewer.