Source code: edu/ou/kmi/buddyspace/gui/BSAutoScrollTextPane.java
1 package edu.ou.kmi.buddyspace.gui;
2
3 /*
4 * BSAutoScrollTextPane.java
5 *
6 * Project: BuddySpace
7 * (C) Copyright Knowledge Media Institute 2002
8 *
9 *
10 * Created on 13 December 2002, 9:51
11 */
12
13 import javax.swing.*;
14 import java.awt.*;
15 import java.awt.event.*;
16 import javax.swing.text.*;
17
18 import org.jabber.jabberbeans.util.*;
19
20 import edu.ou.kmi.buddyspace.utils.*;
21
22 /**
23 * <code>BSAutoScrollTextPane</code> extends <code>AutoScrollTextPane</code>
24 * and provides additional BuddySpace styles and calls directly to BSMainFrame.
25 *
26 * @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
27 */
28 public class BSAutoScrollTextPane extends AutoScrollTextPane
29 implements ActionListener {
30
31 public static final String URL_BUTTON_STYLE = "urlButton";
32
33 protected BSMainFrame mainFrame = null;
34
35 public BSAutoScrollTextPane(boolean autoScrollDown) {
36
37 super(autoScrollDown);
38 }
39
40
41 protected void initStyles() {
42 super.initStyles();
43
44 Style regularStyle = StyleContext.getDefaultStyleContext().
45 getStyle(REGULAR_STYLE);
46
47 Style s = addStyle(URL_BUTTON_STYLE, regularStyle);
48 }
49
50
51 /** Sets BSMainFrame to allow calling of actions */
52 public void setMainFrame(BSMainFrame mainFrame) {
53 this.mainFrame = mainFrame;
54 }
55
56
57 /** Overloaded append function, which scrolls down */
58 public void append(String str, String styleName) {
59
60 if (URL_STYLE.equals(styleName)) {
61 appendURLImpl(str);
62 scroll();
63 }
64 else
65 super.append(str, styleName);
66 }
67
68
69 protected void appendURLImpl(String url) {
70 //appendImpl(url, URL_STYLE);
71 ImageIcon icon = new ImageIcon(ClassLoader.getSystemResource("images/collapse2.gif"));
72 BSJIDActionButton button = new BSJIDActionButton(icon, new JID(url));
73 button.setMargin(new Insets(0,0,0,0));
74 button.addActionListener(this);
75 StyleConstants.setComponent(getStyle(URL_BUTTON_STYLE), button);
76 appendImpl(" ", URL_BUTTON_STYLE);
77 appendImpl("\n", REGULAR_STYLE);
78 }
79
80 public void actionPerformed(ActionEvent evt) {
81 if (evt.getSource() instanceof BSJIDActionButton) {
82 BSJIDActionButton button = (BSJIDActionButton) evt.getSource();
83 JID jid = button.getJID();
84 String namespace = "http";
85 if (mainFrame != null)
86 mainFrame.performAction(jid, namespace);
87 }
88 }
89
90 }