Ignore:
Timestamp:
2003-05-27T15:49:22+12:00 (21 years ago)
Author:
mdewsnip
Message:

Fixed tabbing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/help/HelpFrame.java

    r4293 r4365  
    7575 */
    7676public class HelpFrame
    77     extends JFrame {
    78     /** The html rendering pane. */
    79     private CalHTMLPane view = null;
    80     private ContentModel model = null;
     77    extends JFrame {
     78    /** The html rendering pane. */
     79    private CalHTMLPane view = null;
     80    private ContentModel model = null;
    8181     
    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.
     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.
    9393      */
    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 {
     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 {
    123123                // Retrieve the node at index
    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;
     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;
    135135                // Ensure path is selected
    136                 TreePath path = new TreePath(current.getPath());
    137                 contents.setSelectionPath(path);
    138                 contents.scrollPathToVisible(path);
    139                 path = null;
     136        TreePath path = new TreePath(current.getPath());
     137        contents.setSelectionPath(path);
     138        contents.scrollPathToVisible(path);
     139        path = null;
    140140                // Build url
    141                 URL url = current.getURL();
    142                 current = null;
     141        URL url = current.getURL();
     142        current = null;
    143143                // Show help dialog
    144                 show();
    145                 split_pane.setDividerLocation(0.2);
     144        show();
     145        split_pane.setDividerLocation(0.2);
    146146                // Display help page
    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     }
     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    }
    157157
    158     /** This listener is used to lister for selection changes in the contents tree, and to show the appropriate page as required.
     158    /** This listener is used to lister for selection changes in the contents tree, and to show the appropriate page as required.
    159159      */
    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.
     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.
    164164            */
    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     }
     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    }
    174174}
Note: See TracChangeset for help on using the changeset viewer.