KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > tree > SDefaultTreeSelectionModel


1 /*
2  * $Id: SDefaultTreeSelectionModel.java,v 1.3 2004/12/01 07:54:29 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.tree;
15
16 import javax.swing.event.TreeSelectionEvent JavaDoc;
17 import javax.swing.tree.DefaultTreeSelectionModel JavaDoc;
18 import javax.swing.tree.TreePath JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 /**
23  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
24  * @version $Revision: 1.3 $
25  */

26 public class SDefaultTreeSelectionModel
27         extends DefaultTreeSelectionModel JavaDoc
28         implements STreeSelectionModel {
29
30     /**
31      * indicates if we should fire event immediately when they arise, or if we
32      * should collect them for a later delivery
33      */

34     private boolean delayEvents = false;
35
36     /**
37      * got a delayed Event?
38      */

39     protected final ArrayList JavaDoc delayedEvents = new ArrayList JavaDoc();
40
41     public SDefaultTreeSelectionModel() {
42         super();
43     }
44
45     public boolean getDelayEvents() {
46         return delayEvents;
47     }
48
49     public void setDelayEvents(boolean b) {
50         delayEvents = b;
51     }
52
53     /**
54      * fire event with isValueIsAdjusting true
55      */

56     public void fireDelayedIntermediateEvents() {}
57
58     public void fireDelayedFinalEvents() {
59         for (Iterator JavaDoc iter = delayedEvents.iterator(); iter.hasNext();) {
60             TreeSelectionEvent JavaDoc e = (TreeSelectionEvent JavaDoc) iter.next();
61
62             fireValueChanged(e);
63         }
64         delayedEvents.clear();
65     }
66
67     protected void fireValueChanged(TreeSelectionEvent JavaDoc e) {
68         if (delayEvents) {
69             delayedEvents.add(e);
70         } else {
71             super.fireValueChanged(e);
72         }
73     }
74
75
76     /**
77      * Unique shared instance.
78      */

79     public static final SDefaultTreeSelectionModel NO_SELECTION_MODEL =
80             new SDefaultTreeSelectionModel() {
81                 /**
82                  * A null implementation that selects nothing
83                  */

84                 public void setSelectionPaths(TreePath JavaDoc[] pPaths) {
85                 }
86
87                 /**
88                  * A null implementation that adds nothing
89                  */

90                 public void addSelectionPaths(TreePath JavaDoc[] paths) {
91                 }
92
93                 /**
94                  * A null implementation that removes nothing
95                  */

96                 public void removeSelectionPaths(TreePath JavaDoc[] paths) {
97                 }
98
99                 // don't fire events, because there should be not state change
100
protected void fireValueChanged(TreeSelectionEvent JavaDoc e) {}
101
102             };
103
104 }
105
106
107
Popular Tags