001 /*
002 Copyright (C) 2003 Adam Olsen
003
004 This program is free software; you can redistribute it and/or modify
005 it under the terms of the GNU General Public License as published by
006 the Free Software Foundation; either version 1, or (at your option)
007 any later version.
008
009 This program is distributed in the hope that it will be useful,
010 but WITHOUT ANY WARRANTY; without even the implied warranty of
011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 GNU General Public License for more details.
013
014 You should have received a copy of the GNU General Public License
015 along with this program; if not, write to the Free Software
016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
017 */
018
019 package com.valhalla.jbother;
020
021 import java.awt.Dimension;
022 import java.awt.Toolkit;
023 import java.awt.event.ActionEvent;
024 import java.awt.event.ActionListener;
025 import java.awt.event.KeyAdapter;
026 import java.awt.event.KeyEvent;
027 import java.awt.event.WindowAdapter;
028 import java.awt.event.WindowEvent;
029 import java.util.Date;
030 import java.util.Locale;
031 import java.util.ResourceBundle;
032
033 import javax.swing.BorderFactory;
034 import javax.swing.BoxLayout;
035 import javax.swing.JFrame;
036 import javax.swing.JMenuItem;
037 import javax.swing.JPopupMenu;
038 import javax.swing.JScrollPane;
039
040 import com.valhalla.gui.CopyPasteContextMenu;
041 import com.valhalla.gui.Standard;
042 import com.valhalla.jbother.jabber.BuddyStatus;
043 import com.valhalla.settings.Settings;
044 import com.valhalla.jbother.menus.*;
045
046 /**
047 * Handles Headline messages (server announces, RSS, etc.)
048 *
049 * @author Yury Soldak (tail)
050 * @version 1.0
051 */
052 public class HeadlinesPanel extends ConversationPanel {
053 private ResourceBundle resources = ResourceBundle.getBundle(
054 "JBotherBundle", Locale.getDefault());
055 private ConversationPopupMenu popMenu = new ConversationPopupMenu(this,
056 conversationArea);
057
058 /**
059 * Default constructor
060 *
061 * @param buddy
062 * the Buddy that this window corresponds to
063 * @param userId
064 * the user id of the buddy
065 * @param buddyName
066 * the buddy's alias
067 */
068 public HeadlinesPanel(BuddyStatus buddy) {
069 super(buddy);
070
071 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
072 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
073 conversationArea.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
074 add(conversationArea);
075 addListeners();
076 }
077
078 /**
079 **/
080 public void createFrame() {
081 stopTimer();
082
083 frame = new JFrame();
084 frame.setContentPane(this);
085 frame.pack();
086 frame.setSize(new Dimension(400, 420));
087 frame.setIconImage(Standard.getImage("frameicon.png"));
088
089 Standard.cascadePlacement(frame);
090
091 frame.addWindowListener(new WindowAdapter() {
092 public void windowClosing(WindowEvent e) {
093 if (Settings.getInstance().getProperty("preserveMessages") == null) {
094 closeHandler();
095 } else {
096 startTimer();
097 frame.setVisible(false);
098 }
099 }
100 });
101
102 frame.setTitle(buddy.getName() + " (" + buddy.getUser() + ")");
103 validate();
104 }
105
106 /**
107 * Adds the various event listeners for the components that are a part of
108 * this frame
109 */
110 private void addListeners() {
111 conversationArea.getTextPane().addKeyListener(new CTRLWHandler());
112 conversationArea.getTextPane().addMouseListener(new RightClickListener(popMenu));
113 CopyPasteContextMenu.registerComponent(conversationArea.getTextPane());
114 }
115
116 /**
117 * Closes the Window if CTRL+W is pressed
118 */
119 class CTRLWHandler extends KeyAdapter {
120 public void keyPressed(KeyEvent e) {
121 if (e.getKeyCode() == KeyEvent.VK_W
122 && e.getModifiers() == Toolkit.getDefaultToolkit()
123 .getMenuShortcutKeyMask()) {
124 checkCloseHandler();
125 }
126
127 if (e.getKeyCode() == KeyEvent.VK_K
128 && e.getModifiers() == Toolkit.getDefaultToolkit()
129 .getMenuShortcutKeyMask()) {
130 closeHandler();
131 }
132 }
133 }
134
135 /**
136 * Receives a message
137 *
138 * @param sbj
139 * the subject
140 * @param body
141 * the message
142 * @param resource
143 * the resource of the buddy
144 */
145 public void receiveMessage(String sbj, String delayInfo, String body, String resource,
146 Date date, boolean flag, boolean flag2) {
147
148 conversationArea.append(sbj + "\n\n", java.awt.Color.BLACK, true);
149 conversationArea.append(body + "\n\n");
150
151 super.receiveMessage();
152
153 }
154
155 }