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.Component;
018 import java.awt.event.*;
019
020
021 import javax.swing.*;
022
023 import com.valhalla.jbother.jabber.BuddyStatus;
024
025
026 /**
027 * @author Andrey Zakirov
028 * @since April 10, 2005
029 */
030
031 public class Events {
032
033 private BuddyStatus buddy;
034
035
036 private JCheckBox checkDelivered = new JCheckBox();
037 private JCheckBox checkDisplayed = new JCheckBox();
038 private JCheckBox checkOffline = new JCheckBox();
039
040 public Events()
041 {
042 }
043
044 public boolean setEvents(JFrame window, BuddyStatus buddy ) {
045 this.buddy = buddy;
046 JDialog dialog = new JDialog(window);
047 JPanel panel = (JPanel) dialog.getContentPane();
048 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
049 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
050 JLabel label = new JLabel ("Notify when message is:");
051
052 checkDelivered.setText("delivered");
053 checkDelivered.setSelected(buddy.isAskForDelivered());
054 checkDisplayed.setText("displayed");
055 checkDisplayed.setSelected(buddy.isAskForDisplayed());
056 checkOffline.setText("offline");
057 checkOffline.setSelected(buddy.isAskForOffline());
058 dialog.getContentPane().add(label);
059 dialog.getContentPane().add(checkDelivered);
060 dialog.getContentPane().add(checkDisplayed);
061 dialog.getContentPane().add(checkOffline);
062 dialog.pack();
063 dialog.setLocationRelativeTo(window);
064 dialog.setVisible(true);
065 dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
066 dialog.addWindowListener(new WindowAdapter() {
067 public void windowClosing(WindowEvent e) {
068 closeHandler();
069 }
070 });
071 return true;
072 }
073
074
075
076
077 public void checkCloseHandler() {
078 closeHandler();
079 }
080
081 public void closeHandler() {
082 buddy.isAskForDelivered(checkDelivered.isSelected());
083 buddy.isAskForDisplayed(checkDisplayed.isSelected());
084 buddy.isAskForOffline(checkOffline.isSelected());
085 }
086
087
088 }
089