KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > text > ListDisplay


1 package text;
2
3 import text.list.*;
4
5 import java.awt.*;
6 import java.awt.event.*;
7 import java.util.*;
8 import javax.swing.*;
9 import javax.swing.event.*;
10 import java.awt.font.*;
11 import java.awt.datatransfer.*;
12
13 import text.event.*;
14
15 import rero.config.*;
16
17 public class ListDisplay extends JComponent implements MouseWheelListener, MouseInputListener, ClientStateListener
18 {
19    protected ListDisplayComponent display;
20    protected JScrollBar scroller;
21
22    protected ListData data;
23    protected ListSelectionSpace select;
24
25    public ListElement getSelectedElement()
26    {
27       return select.getSelectedElement();
28    }
29
30    public LinkedList getSelectedElements()
31    {
32       return select.getSelectedElements();
33    }
34
35    public void propertyChanged(String JavaDoc a, String JavaDoc b) { data.dirty(); } // happens when ui.font changes...
36

37    public void mouseWheelMoved(MouseWheelEvent e)
38    {
39       // manipulate the scroll bar directly for this one..
40

41       if (e.getWheelRotation() >= 0) // up
42
{
43           scroller.setValue(scroller.getValue() + (e.getScrollAmount()));
44           repaint();
45       }
46       else // down
47
{
48           scroller.setValue(scroller.getValue() - (e.getScrollAmount()));
49           repaint();
50       }
51    }
52
53    public ListDisplay(ListData data)
54    {
55       scroller = new JScrollBar(JScrollBar.VERTICAL, 0, 0, 0, 0);
56       display = new ListDisplayComponent();
57
58       select = new ListSelectionSpace(this, data);
59       addMouseListener(select);
60       addMouseMotionListener(select);
61
62       this.data = data;
63
64       display.installDataSource(data);
65       scroller.setModel(data);
66
67       addMouseWheelListener(this);
68       addMouseListener(this);
69       addMouseMotionListener(this);
70    
71       data.addChangeListener(display);
72
73       setLayout(new BorderLayout());
74       add(scroller, BorderLayout.EAST);
75       add(display, BorderLayout.CENTER);
76
77       setOpaque(false);
78       setDoubleBuffered(false);
79
80       ClientState.getClientState().addClientStateListener("ui.font", this);
81    }
82
83    public void mousePressed(MouseEvent ev)
84    {
85    }
86
87    public void mouseReleased(MouseEvent ev)
88    {
89    }
90
91    public void mouseClicked(MouseEvent ev)
92    {
93       if (ev.isShiftDown() && ev.isControlDown())
94       {
95           ListElement temp = data.getElementAtLocation(ev.getY());
96           if (temp != null)
97           {
98               AttributedText attribs = temp.getAttributedText().getAttributesAt(ev.getX());
99               if (attribs != null)
100               {
101                  ModifyColorMapDialog.showModifyColorMapDialog(this, attribs.foreIndex);
102                  repaint();
103                  ev.consume();
104               }
105           }
106       }
107    }
108
109    public void mouseEntered(MouseEvent ev)
110    {
111       // we have nothing to do for this event...
112
}
113
114    public void mouseExited(MouseEvent ev)
115    {
116       // nothing to do for this event...
117
}
118
119    public void mouseDragged(MouseEvent ev)
120    {
121    }
122
123    public void mouseMoved(MouseEvent ev)
124    {
125       // again nothing to do for this event...
126
}
127
128 /* protected void finalize()
129    {
130       System.out.println("Finalizing the List Display");
131    } */

132 }
133
134
135
136
Popular Tags