KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > util > ColumnModelReport


1 /*
2  * $Id: ColumnModelReport.java,v 1.3 2005/01/24 13:21:14 kleopatra Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing.util;
9
10 import java.util.LinkedList JavaDoc;
11 import java.util.List JavaDoc;
12
13 import javax.swing.event.ChangeEvent JavaDoc;
14 import javax.swing.event.ListSelectionEvent JavaDoc;
15 import javax.swing.event.TableColumnModelEvent JavaDoc;
16 import javax.swing.event.TableColumnModelListener JavaDoc;
17
18 /**
19  * A TableColumnListener that stores the received TableColumnEvents.
20  */

21 public class ColumnModelReport implements TableColumnModelListener JavaDoc {
22
23     /**
24      * Holds a list of all received ValueChangeEvents.
25      */

26     private List JavaDoc removedEvents = new LinkedList JavaDoc();
27     private List JavaDoc addedEvents = new LinkedList JavaDoc();
28     private List JavaDoc movedEvents = new LinkedList JavaDoc();
29     
30     private List JavaDoc selectionEvents = new LinkedList JavaDoc();
31     private List JavaDoc changeEvents = new LinkedList JavaDoc();
32
33 //------------------------ implement TableColumnModelListener
34
public void columnAdded(TableColumnModelEvent JavaDoc e) {
35         addedEvents.add(0, e);
36
37     }
38     public void columnMarginChanged(ChangeEvent JavaDoc e) {
39         changeEvents.add(0, e);
40
41     }
42     public void columnMoved(TableColumnModelEvent JavaDoc e) {
43         movedEvents.add(0, e);
44
45     }
46     public void columnRemoved(TableColumnModelEvent JavaDoc e) {
47         removedEvents.add(0, e);
48
49     }
50     public void columnSelectionChanged(ListSelectionEvent JavaDoc e) {
51         selectionEvents.add(0, e);
52
53     }
54     //---------------------- implement ValueChangeListener
55

56
57     public int getEventCount() {
58         return addedEvents.size() + removedEvents.size() + movedEvents.size() +
59           changeEvents.size() + selectionEvents.size();
60     }
61
62     public boolean hasRemovedEvent() {
63         return !removedEvents.isEmpty();
64     }
65     
66     public TableColumnModelEvent JavaDoc getLastRemoveEvent() {
67         return removedEvents.isEmpty() ? null : (TableColumnModelEvent JavaDoc) removedEvents.get(0);
68      }
69
70     public boolean hasAddedEvent() {
71         return !addedEvents.isEmpty();
72     }
73     
74     public TableColumnModelEvent JavaDoc getLastAddEvent() {
75         return addedEvents.isEmpty() ? null : (TableColumnModelEvent JavaDoc) addedEvents.get(0);
76      }
77     
78     public boolean hasEvents() {
79         return getEventCount() > 0;
80     }
81
82
83     public void clear() {
84         addedEvents.clear();
85         removedEvents.clear();
86         movedEvents.clear();
87         changeEvents.clear();
88         selectionEvents.clear();
89     }
90 }
Popular Tags