KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > text > list > ListData


1 package text.list;
2
3 import text.*;
4
5 import javax.swing.*;
6 import javax.swing.event.*;
7 import java.util.*;
8
9 public abstract class ListData implements BoundedRangeModel
10 {
11     protected ChangeEvent event;
12     protected LinkedList listeners;
13
14     protected int currentValue = 0;
15
16     protected boolean adjusting = false;
17
18     protected int extent = 1;
19
20     public ListData()
21     {
22        event = new ChangeEvent(this);
23        listeners = new LinkedList();
24     }
25
26     public ListElement getElementAtLocation(int pixely)
27     {
28        int _height = (TextSource.fontMetrics.getHeight() + 2);
29
30        int lineNo = ((pixely - (pixely % _height)) / _height) + currentValue;
31
32        return getElementAt(lineNo);
33     }
34
35     public void dirty() { }
36
37     public abstract int getSize();
38
39     public abstract ListElement head();
40     public abstract ListElement next();
41
42     public abstract ListElement getElementAt(int number);
43     public abstract Iterator dataIterator();
44
45     public Object JavaDoc getSynchronizationKeyOuter()
46     {
47         return null;
48     }
49
50     public Object JavaDoc getSynchronizationKeyInner()
51     {
52         return null;
53     }
54
55     public void fireChangeEvent()
56     {
57         ListIterator i = listeners.listIterator();
58         while (i.hasNext())
59         {
60            ChangeListener temp = (ChangeListener)i.next();
61            temp.stateChanged(event);
62         }
63     }
64
65     public void addChangeListener(ChangeListener x)
66     {
67         listeners.add(x);
68     }
69
70     public void removeChangeListener(ChangeListener x)
71     {
72         listeners.remove(x);
73     }
74
75     public int getExtent()
76     {
77         return extent;
78     }
79
80     public int getMaximum()
81     {
82         return getSize();
83     }
84
85     public int getMinimum()
86     {
87         return 0;
88     }
89
90     public int getValue()
91     {
92         if ( (currentValue + extent) > getSize() )
93         {
94            currentValue = getSize() - extent;
95         }
96
97         if (getSize() < extent)
98         {
99            currentValue = 0;
100         }
101
102         if (currentValue < getSize())
103         {
104            return currentValue;
105         }
106
107         currentValue = getSize() - 1;
108         return currentValue;
109     }
110
111     public boolean getValueIsAdjusting()
112     {
113         return adjusting;
114     }
115
116     public void setExtent(int x)
117     {
118         extent = x;
119     }
120
121     public void setMaximum(int x)
122     {
123     }
124
125     public void setMinimum(int x)
126     {
127     }
128
129     public void setRangeProperties(int newValue, int extent, int min, int max, boolean adjusting)
130     {
131     }
132
133     public void setValue (int newValue)
134     {
135         if (newValue < 0)
136         {
137            currentValue = 0;
138         }
139         else if (newValue < getSize())
140         {
141            currentValue = newValue;
142         }
143         else
144         {
145            currentValue = getSize() - 1;
146         }
147
148         fireChangeEvent();
149     }
150
151     public void setValueIsAdjusting(boolean b)
152     {
153         adjusting = b;
154     }
155 }
156
157
158
Popular Tags