KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > swing > resourcetree > formresourcetree > FormTreeMouseListener


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.swing.resourcetree.formresourcetree;
20
21 import javax.swing.event.*;
22 import javax.swing.tree.*;
23
24 import org.openharmonise.him.swing.resourcetree.TreeNode;
25
26
27
28 /**
29  * Mouse listener for {@link org.openharmonise.him.swing.resourcetree.formresourcetree.FormResourceTree}.
30  *
31  * @author Matthew Large
32  * @version $Revision: 1.1 $
33  *
34  */

35 public class FormTreeMouseListener extends DefaultTreeSelectionModel implements TreeSelectionListener, TreeSelectionModel {
36
37     /**
38      * Tree to listen to.
39      */

40     private FormResourceTree m_tree;
41
42     /**
43      * Re-entry check.
44      */

45     private boolean m_bReEntryStop = false;
46     
47     /**
48      * Constructs a new form tree mouse listener.
49      *
50      * @param tree tree to listen to.
51      */

52     public FormTreeMouseListener(FormResourceTree tree) {
53         super();
54         this.m_tree = tree;
55     }
56
57     /* (non-Javadoc)
58      * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
59      */

60     public void valueChanged(TreeSelectionEvent tse) {
61         if(!m_bReEntryStop) {
62             TreeNode node = (TreeNode)tse.getPath().getLastPathComponent();
63             FormTreeCell cell = this.m_tree.getCellForPath(node.getFilePath());
64             if(cell.isEnabled()) {
65                 cell.mouseClicked(null);
66                 m_bReEntryStop = true;
67                 this.clearSelection();
68                 m_bReEntryStop = false;
69             }
70         }
71     }
72 }
73
Popular Tags