Search in sources :

Example 6 with SwingTimerTask

use of org.jivesoftware.spark.util.SwingTimerTask in project Spark by igniterealtime.

the class UserManager method searchContacts.

public void searchContacts(String contact, final JFrame parent) {
    if (parents.get(parent) == null && parent.getGlassPane() != null) {
        parents.put(parent, parent.getGlassPane());
    }
    // Make sure we are using the default glass pane
    final Component glassPane = parents.get(parent);
    parent.setGlassPane(glassPane);
    final Map<String, ContactItem> contactMap = new HashMap<>();
    final List<ContactItem> contacts = new ArrayList<>();
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    for (ContactGroup contactGroup : contactList.getContactGroups()) {
        contactGroup.clearSelection();
        for (ContactItem contactItem : contactGroup.getContactItems()) {
            if (!contactMap.containsKey(contactItem.getJID())) {
                contacts.add(contactItem);
                contactMap.put(contactItem.getJID(), contactItem);
            }
        }
    }
    // Sort
    Collections.sort(contacts, itemComparator);
    final JContactItemField contactField = new JContactItemField(new ArrayList<>(contacts));
    JPanel layoutPanel = new JPanel();
    layoutPanel.setLayout(new GridBagLayout());
    JLabel enterLabel = new JLabel(Res.getString("label.contact.to.find"));
    enterLabel.setFont(new Font("dialog", Font.BOLD, 10));
    layoutPanel.add(enterLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    layoutPanel.add(contactField, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0));
    layoutPanel.setBorder(BorderFactory.createBevelBorder(0));
    contactField.addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent keyEvent) {
            if (keyEvent.getKeyChar() == KeyEvent.VK_ENTER) {
                if (ModelUtil.hasLength(contactField.getText())) {
                    ContactItem item = contactMap.get(contactField.getText());
                    if (item == null) {
                        item = contactField.getSelectedContactItem();
                    }
                    if (item != null) {
                        parent.setGlassPane(glassPane);
                        parent.getGlassPane().setVisible(false);
                        contactField.dispose();
                        SparkManager.getChatManager().activateChat(item.getJID(), item.getDisplayName());
                    }
                }
            } else if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) {
                parent.setGlassPane(glassPane);
                parent.getGlassPane().setVisible(false);
                contactField.dispose();
            }
        }
    });
    contactField.getList().addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                contactField.setSelectetIndex(e);
                ContactItem item = contactField.getSelectedContactItem();
                MouseEvent exx = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), e.getX() + 20, e.getY(), e.getClickCount(), false);
                SparkManager.getContactList().setSelectedUser(item.getJID());
                SparkManager.getContactList().showPopup(contactField.getPopup(), exx, item);
            }
            if (e.getClickCount() == 2) {
                if (ModelUtil.hasLength(contactField.getText())) {
                    ContactItem item = contactMap.get(contactField.getText());
                    if (item == null) {
                        item = contactField.getSelectedContactItem();
                    }
                    if (item != null) {
                        parent.setGlassPane(glassPane);
                        parent.getGlassPane().setVisible(false);
                        contactField.dispose();
                        SparkManager.getChatManager().activateChat(item.getJID(), item.getDisplayName());
                    }
                }
            }
        }
    });
    final JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setLayout(new GridBagLayout());
    mainPanel.add(layoutPanel, new GridBagConstraints(0, 0, 1, 1, 0.5, 0.5, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(SparkManager.getMainWindow().getTopToolBar().getHeight() + SparkManager.getWorkspace().getStatusBar().getHeight() + 47, 1, 5, 1), 200, 0));
    mainPanel.setOpaque(false);
    contactField.setText(contact);
    parent.setGlassPane(mainPanel);
    parent.getGlassPane().setVisible(true);
    contactField.focus();
    mainPanel.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent mouseEvent) {
            parent.setGlassPane(glassPane);
            parent.getGlassPane().setVisible(false);
            contactField.dispose();
        }
    });
    parent.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent windowEvent) {
            parent.setGlassPane(glassPane);
            parent.getGlassPane().setVisible(false);
            contactField.dispose();
            parent.removeWindowListener(this);
        }

        public void windowDeactivated(final WindowEvent windowEvent) {
            TimerTask task = new SwingTimerTask() {

                public void doRun() {
                    if (contactField.canClose()) {
                        windowClosing(windowEvent);
                    }
                }
            };
            TaskEngine.getInstance().schedule(task, 250);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) HashMap(java.util.HashMap) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) WindowAdapter(java.awt.event.WindowAdapter) Font(java.awt.Font) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) TimerTask(java.util.TimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) JContactItemField(org.jivesoftware.spark.component.JContactItemField) Component(java.awt.Component) MouseEvent(java.awt.event.MouseEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) ContactList(org.jivesoftware.spark.ui.ContactList) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) WindowEvent(java.awt.event.WindowEvent) ContactGroup(org.jivesoftware.spark.ui.ContactGroup)

Example 7 with SwingTimerTask

use of org.jivesoftware.spark.util.SwingTimerTask in project Spark by igniterealtime.

the class BuzzRoomDecorator method actionPerformed.

public void actionPerformed(ActionEvent e) {
    final String jid = ((ChatRoomImpl) chatRoom).getParticipantJID();
    Message message = new Message();
    message.setTo(jid);
    message.addExtension(new BuzzPacket());
    try {
        SparkManager.getConnection().sendStanza(message);
    } catch (SmackException.NotConnectedException e1) {
        Log.warning("Unable to send stanza to " + jid, e1);
    }
    chatRoom.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.sent"), ChatManager.NOTIFICATION_COLOR);
    buzzButton.setEnabled(false);
    // Enable the button after 30 seconds to prevent abuse.
    final TimerTask enableTask = new SwingTimerTask() {

        public void doRun() {
            buzzButton.setEnabled(true);
        }
    };
    TaskEngine.getInstance().schedule(enableTask, 30000);
}
Also used : SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Message(org.jivesoftware.smack.packet.Message) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) TimerTask(java.util.TimerTask) SmackException(org.jivesoftware.smack.SmackException) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 8 with SwingTimerTask

use of org.jivesoftware.spark.util.SwingTimerTask in project Spark by igniterealtime.

the class NotificationPlugin method initialize.

public void initialize() {
    // Add the preferences
    NotificationsPreference notifications = new NotificationsPreference();
    SparkManager.getPreferenceManager().addPreference(notifications);
    notifications.load();
    final TimerTask registerTask = new SwingTimerTask() {

        public void doRun() {
            registerListener();
        }
    };
    TaskEngine.getInstance().schedule(registerTask, 5000);
}
Also used : SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) TimerTask(java.util.TimerTask)

Example 9 with SwingTimerTask

use of org.jivesoftware.spark.util.SwingTimerTask in project Spark by igniterealtime.

the class IncomingCall method showIncomingCall.

/**
 * Notifies user of an incoming call. The UI allows for users to either accept or reject
 * the incoming session.
 *
 * @param request the JingleSession.
 */
private void showIncomingCall(final JingleSessionRequest request) {
    toasterManager = new SparkToaster();
    toasterManager.setHidable(false);
    final IncomingCallUI incomingCall = new IncomingCallUI(request.getFrom());
    toasterManager.setToasterHeight(175);
    toasterManager.setToasterWidth(300);
    toasterManager.setDisplayTime(500000000);
    toasterManager.showToaster("Incoming Voice Chat", incomingCall);
    toasterManager.hideTitle();
    incomingCall.getAcceptButton().addActionListener(e -> acceptSession(request));
    incomingCall.getRejectButton().addActionListener(e -> rejectIncomingCall());
    // Start the ringing.
    final Runnable ringer = () -> ringing.loop();
    TaskEngine.getInstance().submit(ringer);
    // End after 30 seconds max.
    TimerTask endTask = new SwingTimerTask() {

        public void doRun() {
            if (!session.isFullyEstablished()) {
                rejectIncomingCall();
            }
        }
    };
    TaskEngine.getInstance().schedule(endTask, 30000);
}
Also used : SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) SparkToaster(org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster) TimerTask(java.util.TimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask)

Example 10 with SwingTimerTask

use of org.jivesoftware.spark.util.SwingTimerTask in project Spark by igniterealtime.

the class IncomingCall method sessionEstablished.

public void sessionEstablished(PayloadType payloadType, TransportCandidate transportCandidate, TransportCandidate transportCandidate1, JingleSession jingleSession) {
    established = true;
    mediaReceivedTask = new SwingTimerTask() {

        public void doRun() {
            if (!mediaReceived) {
                if (session != null) {
                    try {
                        session.terminate("No Media Received. This may be caused by firewall configuration problems.");
                    } catch (XMPPException | SmackException e) {
                        Log.error(e);
                    }
                }
            }
        }
    };
    TaskEngine.getInstance().schedule(mediaReceivedTask, WAIT_FOR_MEDIA_DELAY, WAIT_FOR_MEDIA_DELAY);
}
Also used : SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask)

Aggregations

SwingTimerTask (org.jivesoftware.spark.util.SwingTimerTask)12 TimerTask (java.util.TimerTask)8 Message (org.jivesoftware.smack.packet.Message)3 SmackException (org.jivesoftware.smack.SmackException)2 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)2 SwingWorker (org.jivesoftware.spark.util.SwingWorker)2 java.awt (java.awt)1 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 java.awt.event (java.awt.event)1 ActionEvent (java.awt.event.ActionEvent)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1