001    /*
002     Copyright (C) 2003 Adam Olsen
003     This program is free software; you can redistribute it and/or modify
004     it under the terms of the GNU General Public License as published by
005     the Free Software Foundation; either version 1, or (at your option)
006     any later version.
007     This program is distributed in the hope that it will be useful,
008     but WITHOUT ANY WARRANTY; without even the implied warranty of
009     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010     GNU General Public License for more details.
011     You should have received a copy of the GNU General Public License
012     along with this program; if not, write to the Free Software
013     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
014     */
015    package com.valhalla.jbother;
016    
017    import java.awt.Dimension;
018    import java.awt.GridLayout;
019    import java.awt.Toolkit;
020    import java.awt.event.*;
021    import java.beans.PropertyChangeEvent;
022    import java.beans.PropertyChangeListener;
023    import java.util.Date;
024    import java.util.Locale;
025    import java.util.ResourceBundle;
026    
027    import javax.swing.*;
028    import javax.swing.event.*;
029    
030    import com.valhalla.gui.CopyPasteContextMenu;
031    import com.valhalla.gui.MJTextArea;
032    import com.valhalla.gui.Standard;
033    import com.valhalla.jbother.jabber.BuddyStatus;
034    import com.valhalla.jbother.jabber.smack.Blank;
035    import com.valhalla.jbother.menus.ConversationPopupMenu;
036    import com.valhalla.settings.Settings;
037    
038    /**
039     * Handles XML packet exchange between client and server.
040     *
041     * @author Andrey Zakirov
042     * @created April 10, 2005
043     * @version 0.1
044     */
045    
046    public class EventPanel extends ConversationPanel {
047        private ResourceBundle resources = ResourceBundle.getBundle(
048                "JBotherBundle", Locale.getDefault());
049    
050        private JSplitPane container;
051    
052        private JScrollPane conversationScroll;
053    
054        private JPanel buttonPanel = new JPanel();
055    
056        private JPanel scrollPanel = new JPanel(new GridLayout(1, 0));
057    
058        private boolean divSetUp = false;
059    
060        private ConversationPopupMenu popMenu = new ConversationPopupMenu(this,
061                conversationArea);
062    
063    
064        /**
065         * Sets up the ConsolePanel - creates all visual components and adds event
066         * listeners
067         *
068         * @param buddy
069         *            the buddy to associate with
070         */
071        public EventPanel(BuddyStatus buddy) {
072            super(buddy);
073            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
074            setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
075            textEntryArea.setLineWrap(true);
076            textEntryArea.setWrapStyleWord(true);
077    
078    
079            scrollPanel.add(conversationArea);
080    
081            container = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPanel,
082                    new JScrollPane(textEntryArea)
083                                        );
084            container.setResizeWeight(1);
085    
086            JPanel containerPanel = new JPanel();
087            containerPanel
088                    .setLayout(new BoxLayout(containerPanel, BoxLayout.X_AXIS));
089            containerPanel.add(container);
090    
091            conversationArea.getTextPane().addMouseListener(new RightClickListener(popMenu));
092            CopyPasteContextMenu.registerComponent(conversationArea.getTextPane());
093            popMenu.disableBlock();
094    
095    //        add(containerPanel);
096            add(scrollPanel);
097    
098            addListeners();
099        }
100    
101        public void messageEvent(String text) {
102    
103                final String text2 = text;
104    
105                SwingUtilities.invokeLater(new Runnable() {
106                public void run() {
107                    receiveMessage();
108                    conversationArea.append(getDate(null) + " **** " + text2, ConversationArea.BLACK, true);
109                }
110            });
111    
112    
113           }
114    
115    
116        private String getMessageTemplate() {
117            return "<message id=\"\" to=\"\" type=\"\"><body></body></message>";
118        }
119    
120        /**
121         * @return the input area of this panel
122         */
123    
124        /**
125         * Adds the various event listeners for the components that are a part of
126         * this frame
127         */
128        private void addListeners() {
129    
130    
131            Action checkCloseAction = new AbstractAction() {
132                public void actionPerformed(ActionEvent e) {
133                    checkCloseHandler();
134                }
135            };
136    
137            Action closeAction = new AbstractAction() {
138                public void actionPerformed(ActionEvent e) {
139                    closeHandler();
140                }
141            };
142    
143    
144            //set it up so that if there isn't any selected text in the
145            // conversation area
146            //the textentryarea grabs the focus.
147            conversationArea.getTextPane().addMouseListener(new MouseAdapter() {
148                public void mouseReleased(MouseEvent e) {
149                    if (conversationArea.getSelectedText() == null) {
150                        textEntryArea.requestFocus();
151                    }
152                }
153            });
154    
155        }
156    
157        public String getPanelName() {
158            return resources.getString("eventConsole");
159        }
160    
161        /**
162         * Displays a "disconnected" message"
163         */
164    
165        /**
166         * Recieves a message
167         *
168         * @param sbj
169         *            Description of the Parameter
170         * @param message
171         *            Description of the Parameter
172         * @param resource
173         *            Description of the Parameter
174         * @param date
175         *            Description of the Parameter
176         */
177    
178        /**
179         * Sends the message in the TextEntryArea
180         */
181        /**
182         * Creates the containing frame
183         */
184        public void createFrame() {
185            frame = new JFrame();
186            frame.setContentPane(this);
187            frame.pack();
188    
189            frame.setIconImage(Standard.getImage("frameicon.png"));
190    
191            frame.addWindowListener(new WindowAdapter() {
192                public void windowClosing(WindowEvent e) {
193                    closeHandler();
194                }
195            });
196    
197            frame.setTitle(resources.getString("eventConsole"));
198            frame.pack();
199    
200            String stringWidth = Settings.getInstance().getProperty(
201                    "EventconversationWindowWidth");
202            String stringHeight = Settings.getInstance().getProperty(
203                    "EventconversationWindowHeight");
204    
205            if (stringWidth == null) {
206                stringWidth = "400";
207            }
208            if (stringHeight == null) {
209                stringHeight = "340";
210            }
211    
212            frame.setSize(new Dimension(Integer.parseInt(stringWidth), Integer
213                    .parseInt(stringHeight)));
214    
215            // add a resize window listener
216            frame.addComponentListener(new ComponentAdapter() {
217                public void componentResized(ComponentEvent e) {
218                    Dimension dim = frame.getSize();
219                    Settings.getInstance().setProperty(
220                            "EventconversationWindowWidth",
221                            new Integer((int) dim.getWidth()).toString());
222                    Settings.getInstance().setProperty(
223                            "EventconversationWindowHeight",
224                            new Integer((int) dim.getHeight()).toString());
225                }
226            });
227            Standard.cascadePlacement(frame);
228    
229            frame.setVisible(true);
230        }
231    
232        /**
233         * Description of the Method
234         */
235        public void checkCloseHandler() {
236            closeHandler();
237        }
238    
239    }
240    
241    
242