@Override public void initialize() { ProviderManager.addIQProvider( GameOfferPacket.ELEMENT_NAME, GameOfferPacket.NAMESPACE, GameOfferPacket.class); ProviderManager.addExtensionProvider( MovePacket.ELEMENT_NAME, MovePacket.NAMESPACE, MovePacket.class); ProviderManager.addExtensionProvider( MoveAnswerPacket.ELEMENT_NAME, MoveAnswerPacket.NAMESPACE, MoveAnswerPacket.class); _gameofferListener = new StanzaListener() { @Override public void processPacket(Stanza stanza) { GameOfferPacket invitation = (GameOfferPacket) stanza; if (invitation.getType() == IQ.Type.get) { showInvitationInChat(invitation); } } }; SparkManager.getConnection() .addAsyncStanzaListener(_gameofferListener, new StanzaTypeFilter(GameOfferPacket.class)); _chatRoomListener = new ChatRoomOpeningListener(); SparkManager.getChatManager().addChatRoomListener(_chatRoomListener); }
public void initialize() { final MainWindow mainWindow = SparkManager.getMainWindow(); SparkManager.getMainWindow() .addMainWindowListener( new MainWindowListener() { public void shutdown() { int x = mainWindow.getX(); int y = mainWindow.getY(); int width = mainWindow.getWidth(); int height = mainWindow.getHeight(); LayoutSettings settings = LayoutSettingsManager.getLayoutSettings(); settings.setMainWindowHeight(height); settings.setMainWindowWidth(width); settings.setMainWindowX(x); settings.setMainWindowY(y); if (mainWindow.isDocked()) { settings.setSplitPaneDividerLocation( mainWindow.getSplitPane().getDividerLocation()); } else { settings.setSplitPaneDividerLocation(-1); } LayoutSettingsManager.saveLayoutSettings(); } public void mainWindowActivated() {} public void mainWindowDeactivated() {} }); }
/** Loads Preferences, either from server or locally. */ private void loadPreferences() { boolean serverPluginInstalled = SipAccountPacket.isSoftPhonePluginInstalled(SparkManager.getConnection()); if (serverPluginInstalled) { setupRemotePreferences(SparkManager.getConnection()); } }
public void sendMessage(String text) { final Message message = new Message(); if (threadID == null) { threadID = StringUtils.randomString(6); } message.setThread(threadID); // Set the body of the message using typedMessage message.setBody(text); // IF there is no body, just return and do nothing if (!ModelUtil.hasLength(text)) { return; } // Fire Message Filters SparkManager.getChatManager().filterOutgoingMessage(this, message); // Fire Global Filters SparkManager.getChatManager().fireGlobalMessageSentListeners(this, message); sendMessage(message); sendNotification = true; }
public void closeChatRoom() { // If already closed, don't bother. if (!active) { return; } super.closeChatRoom(); // Remove info listener infoButton.removeActionListener(this); addToRosterButton.removeActionListener(this); // Send a cancel notification event on closing if listening. if (!sendNotification) { // send cancel SparkManager.getMessageEventManager() .sendCancelledNotification(getParticipantJID(), threadID); sendNotification = true; } SparkManager.getChatManager().removeChat(this); SparkManager.getConnection().removePacketListener(this); if (typingTimerTask != null) { TaskEngine.getInstance().cancelScheduledTask(typingTimerTask); typingTimerTask = null; } active = false; }
public void initialize() { this.con = SparkManager.getConnection(); EventQueue.invokeLater( new Runnable() { @Override public void run() { addressLabel = new JLabel(); addressField = new JComboBox(); addressField.setEditable(true); addressField.addItem(con.getHost()); } }); SparkManager.getWorkspace() .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke("F8"), "showBrowser"); SparkManager.getWorkspace() .getActionMap() .put( "showBrowser", new AbstractAction("showBrowser") { private static final long serialVersionUID = 341826581565007606L; public void actionPerformed(ActionEvent evt) { display(); } }); }
private void loadHistory() { // Add VCard Panel final VCardPanel vcardPanel = new VCardPanel(participantJID); vcardPanel.setPreferredSize(new Dimension(10, 71)); vcardPanel.setMaximumSize(new Dimension(1100, 71)); vcardPanel.setMinimumSize(new Dimension(1100, 71)); getToolBar() .add( vcardPanel, new GridBagConstraints( 0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 2, 0, 2), 0, 0)); final LocalPreferences localPreferences = SettingsManager.getLocalPreferences(); if (!localPreferences.isChatHistoryEnabled()) { return; } if (!localPreferences.isPrevChatHistoryEnabled()) { return; } final String bareJID = StringUtils.parseBareAddress(getParticipantJID()); final ChatTranscript chatTranscript = ChatTranscripts.getCurrentChatTranscript(bareJID); final String personalNickname = SparkManager.getUserManager().getNickname(); for (HistoryMessage message : chatTranscript.getMessages()) { String nickname = SparkManager.getUserManager().getUserNicknameFromJID(message.getFrom()); String messageBody = message.getBody(); if (nickname.equals(message.getFrom())) { String otherJID = StringUtils.parseBareAddress(message.getFrom()); String myJID = SparkManager.getSessionManager().getBareAddress(); if (otherJID.equals(myJID)) { nickname = personalNickname; } else { nickname = StringUtils.parseName(nickname); } } if (ModelUtil.hasLength(messageBody) && messageBody.startsWith("/me ")) { messageBody = messageBody.replaceFirst("/me", nickname); } final Date messageDate = message.getDate(); getTranscriptWindow().insertHistoryMessage(nickname, messageBody, messageDate); } }
// I would normally use the command pattern, but // have no real use when dealing with just a couple options. public void actionPerformed(ActionEvent e) { if (e.getSource() == infoButton) { VCardManager vcard = SparkManager.getVCardManager(); vcard.viewProfile(participantJID, SparkManager.getChatManager().getChatContainer()); } else if (e.getSource() == addToRosterButton) { RosterDialog rosterDialog = new RosterDialog(); rosterDialog.setDefaultJID(participantJID); rosterDialog.setDefaultNickname(getParticipantNickname()); rosterDialog.showRosterDialog( SparkManager.getChatManager().getChatContainer().getChatFrame()); } else { super.actionPerformed(e); } }
/** * Prepares Spark for shutting down by first calling all {@link MainWindowListener}s and setting * the Agent to be offline. * * @param sendStatus true if Spark should send a presence with a status message. */ public void logout(boolean sendStatus) { final XMPPConnection con = SparkManager.getConnection(); String status = null; if (con.isConnected() && sendStatus) { final InputTextAreaDialog inputTextDialog = new InputTextAreaDialog(); status = inputTextDialog.getInput( Res.getString("title.status.message"), Res.getString("message.current.status"), SparkRes.getImageIcon(SparkRes.USER1_MESSAGE_24x24), this); } if (status != null || !sendStatus) { // Notify all MainWindowListeners try { // Set auto-login to false; SettingsManager.getLocalPreferences().setAutoLogin(false); SettingsManager.saveSettings(); fireWindowShutdown(); setVisible(false); } finally { closeConnectionAndInvoke(status); } } }
/** Displays the Spark error log. */ private void showErrorLog() { final File logDir = new File(Spark.getLogDirectory(), "errors.log"); // Read file and show final String errorLogs = URLFileSystem.getContents(logDir); final JFrame frame = new JFrame(Res.getString("title.client.logs")); frame.setLayout(new BorderLayout()); frame.setIconImage(SparkManager.getApplicationImage().getImage()); final JTextPane pane = new JTextPane(); pane.setBackground(Color.white); pane.setFont(new Font("Dialog", Font.PLAIN, 12)); pane.setEditable(false); pane.setText(errorLogs); frame.add(new JScrollPane(pane), BorderLayout.CENTER); final JButton copyButton = new JButton(Res.getString("button.copy.to.clipboard")); frame.add(copyButton, BorderLayout.SOUTH); copyButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { SparkManager.setClipboard(errorLogs); copyButton.setEnabled(false); } }); frame.pack(); frame.setSize(600, 400); GraphicUtils.centerWindowOnScreen(frame); frame.setVisible(true); }
/** Initializes the core phone objects. */ private void initializePhone() { // Load Preferences loadPreferences(); if (preferences == null) { return; } guiManager = new GuiManager(); guiManager.addUserActionListener(this); logManager = new LogManagerImpl(this); this.getLogManager().setRemoteLogging(true); try { EventQueue.invokeAndWait( new Runnable() { @Override public void run() { registerMenu = new JCheckBoxMenuItem(PhoneRes.getIString("phone.enabled")); } }); } catch (Exception e) { Log.error(e); } registerMenu.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (getStatus() == SipRegisterStatus.Unregistered || getStatus() == SipRegisterStatus.RegistrationFailed) { register(); } else { handleUnregisterRequest(); } } }); SIPConfig.setPreferredNetworkAddress(preferences.getPreferredAddress()); NetworkAddressManager.start(); try { EventQueue.invokeAndWait( new Runnable() { @Override public void run() { // Initialize Missed calls missedCalls = new MissedCalls(); } }); } catch (Exception e) { Log.error(e); } final JMenu actionsMenu = SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.actions")); actionsMenu.add(registerMenu); }
public void showDialog() { if (notesFrame != null && notesFrame.isVisible()) { return; } notesFrame = new JFrame(FpRes.getString("title.chat.notes")); notesFrame.setIconImage(SparkManager.getMainWindow().getIconImage()); notesFrame.getContentPane().setLayout(new BorderLayout()); notesFrame.getContentPane().add(new JScrollPane(this), BorderLayout.CENTER); notesFrame.pack(); notesFrame.setSize(500, 400); notesFrame.setLocationRelativeTo(SparkManager.getChatManager().getChatContainer()); notesFrame.setVisible(true); textPane.requestFocusInWindow(); }
/** Displays the About Box for Spark. */ private static void showAboutBox() { JOptionPane.showMessageDialog( SparkManager.getMainWindow(), Default.getString(Default.APPLICATION_NAME) + " " + JiveInfo.getVersion(), Res.getString("title.about"), JOptionPane.INFORMATION_MESSAGE, SparkRes.getImageIcon(SparkRes.MAIN_IMAGE)); }
private void hideOfflineUsers() { int i = 0; if (OfflineUsers.isSelected()) { final ContactList contactList = SparkManager.getWorkspace().getContactList(); i = 0; for (CheckNode node : nodes) { if (contactList.getContactItemByDisplayName(node.toString()).getPresence().getType() == Presence.Type.unavailable) { if (node.getParent() != null) { TreeNode parent = node.getParent(); TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent); ((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(node); checkTree.getTree().setSelectionPath(new TreePath(path)); NodesGroups.add(new ArrayList<Object>()); NodesGroups.get(i).add(parent); NodesGroups.get(i).add(node); i++; } } } for (int x = 0; x < groupNodes.size(); x++) { if (groupNodes.get(x).toString().equals(Res.getString("group.offline"))) { OfflineGroup = x; TreeNode parent = groupNodes.get(x).getParent(); TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent); ((DefaultTreeModel) checkTree.getTree().getModel()) .removeNodeFromParent(groupNodes.get(x)); checkTree.getTree().setSelectionPath(new TreePath(path)); } } } else { i = 0; DefaultMutableTreeNode child = groupNodes.get(OfflineGroup); ((DefaultTreeModel) checkTree.getTree().getModel()) .insertNodeInto(child, rosterNode, rosterNode.getChildCount()); TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(rosterNode); checkTree.getTree().expandPath(new TreePath(path)); checkTree.expandTree(); for (CheckNode node : nodes) { if (node.getParent() == null) { child = (CheckNode) NodesGroups.get(i).get(1); ((DefaultTreeModel) checkTree.getTree().getModel()) .insertNodeInto( child, ((CheckNode) NodesGroups.get(i).get(0)), ((CheckNode) NodesGroups.get(i).get(0)).getChildCount()); path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(node); checkTree.getTree().expandPath(new TreePath(path)); checkTree.expandTree(); i++; } } } }
private void showInvitationInChat(final GameOfferPacket invitation) { invitation.setType(IQ.Type.result); invitation.setTo(invitation.getFrom()); final ChatRoom room = SparkManager.getChatManager() .getChatRoom(XmppStringUtils.parseBareJid(invitation.getFrom())); String name = XmppStringUtils.parseLocalpart(invitation.getFrom()); final JPanel panel = new JPanel(); JLabel text = new JLabel("Game request from" + name); JLabel game = new JLabel("Battleships"); game.setFont(new Font("Dialog", Font.BOLD, 24)); game.setForeground(Color.RED); JButton accept = new JButton(Res.getString("button.accept").replace("&", "")); JButton decline = new JButton(Res.getString("button.decline").replace("&", "")); panel.add(text); panel.add(game); panel.add(accept); panel.add(decline); room.getTranscriptWindow().addComponent(panel); accept.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { SparkManager.getConnection().sendStanza(invitation); } catch (SmackException.NotConnectedException e1) { Log.warning("Unable to send invitation accept to " + invitation.getTo(), e1); } invitation.setStartingPlayer(!invitation.isStartingPlayer()); ChatRoomOpeningListener.createWindow(invitation, invitation.getFrom()); panel.remove(3); panel.remove(2); panel.repaint(); panel.revalidate(); } }); decline.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { invitation.setType(IQ.Type.error); try { SparkManager.getConnection().sendStanza(invitation); } catch (SmackException.NotConnectedException e1) { Log.warning("Unable to send invitation decline to " + invitation.getTo(), e1); } panel.remove(3); panel.remove(2); panel.repaint(); panel.revalidate(); } }); }
public void reconnectionSuccessful() { Presence usersPresence = PresenceManager.getPresence(getParticipantJID()); if (usersPresence.isAvailable()) { presence = usersPresence; } SparkManager.getChatManager().getChatContainer().fireChatRoomStateUpdated(this); getChatInputEditor().setEnabled(true); getSendButton().setEnabled(true); }
/** * Sends a message to the appropriate jid. The message is automatically added to the transcript. * * @param message the message to send. */ public void sendMessage(Message message) { lastActivity = System.currentTimeMillis(); try { getTranscriptWindow() .insertMessage(getNickname(), message, ChatManager.TO_COLOR, Color.white); getChatInputEditor().selectAll(); getTranscriptWindow().validate(); getTranscriptWindow().repaint(); getChatInputEditor().clear(); } catch (Exception ex) { Log.error("Error sending message", ex); } // Before sending message, let's add our full jid for full verification message.setType(Message.Type.chat); message.setTo(participantJID); message.setFrom(SparkManager.getSessionManager().getJID()); // Notify users that message has been sent fireMessageSent(message); addToTranscript(message, false); getChatInputEditor().setCaretPosition(0); getChatInputEditor().requestFocusInWindow(); scrollToBottom(); // No need to request displayed or delivered as we aren't doing anything // with this // information. MessageEventManager.addNotificationsRequests(message, true, false, false, true); // Send the message that contains the notifications request try { fireOutgoingMessageSending(message); SparkManager.getConnection().sendPacket(message); } catch (Exception ex) { Log.error("Error sending message", ex); } }
/** * Returns the url of the avatar belonging to this contact. * * @return the url of the avatar. * @throws MalformedURLException thrown if the address is invalid. */ public URL getAvatarURL() throws MalformedURLException { contactsDir.mkdirs(); if (ModelUtil.hasLength(hash)) { final File imageFile = new File(contactsDir, hash); if (imageFile.exists()) { return imageFile.toURI().toURL(); } } return SparkManager.getVCardManager().getAvatarURLIfAvailable(getJID()); }
/** Creating PrivacyListManager instance */ private PrivacyManager() { XMPPConnection conn = SparkManager.getConnection(); if (conn == null) { Log.error("Privacy plugin: Connection not initialized."); } _active = checkIfPrivacyIsSupported(conn); if (_active) { privacyManager = PrivacyListManager.getInstanceFor(conn); initializePrivacyLists(); } }
/** * Closes the current connection and restarts Spark. * * @param reason the reason for logging out. This can be if user gave no reason. */ public void closeConnectionAndInvoke(String reason) { final XMPPConnection con = SparkManager.getConnection(); if (con.isConnected()) { if (reason != null) { Presence byePresence = new Presence(Presence.Type.unavailable, reason, -1, null); con.disconnect(byePresence); } else { con.disconnect(); } } if (!restartApplicationWithScript()) { restartApplicationWithJava(); } }
/** * Returns the singleton instance of <CODE>MainWindow</CODE>, creating it if necessary. * * <p> * * @return the singleton instance of <Code>MainWindow</CODE> */ public static MainWindow getInstance() { // Synchronize on LOCK to ensure that we don't end up creating // two singletons. synchronized (LOCK) { if (null == singleton) { MainWindow controller = new MainWindow( Default.getString(Default.APPLICATION_NAME), SparkManager.getApplicationImage()); singleton = controller; } } return singleton; }
/** * Prepares Spark for shutting down by first calling all {@link MainWindowListener}s and setting * the Agent to be offline. */ public void shutdown() { final XMPPConnection con = SparkManager.getConnection(); if (con.isConnected()) { // Send disconnect. con.disconnect(); } // Notify all MainWindowListeners try { fireWindowShutdown(); } catch (Exception ex) { Log.error(ex); } // Close application. if (!Default.getBoolean("DISABLE_EXIT")) System.exit(1); }
/** * Calls an individual user by their VCard information. * * @param jid the users JID. */ public void callByJID(String jid) { if (getStatus() == SipRegisterStatus.Registered) { final VCard vcard = SparkManager.getVCardManager().getVCard(XmppStringUtils.parseBareJid(jid)); if (vcard != null) { String number = vcard.getPhoneWork("VOICE"); if (!ModelUtil.hasLength(number)) { number = vcard.getPhoneHome("VOICE"); } if (ModelUtil.hasLength(number)) { getDefaultGuiManager().dial(number); } } } }
private void checkEvents(String from, String packetID, MessageEvent messageEvent) { if (messageEvent.isDelivered() || messageEvent.isDisplayed()) { // Create the message to send Message msg = new Message(from); // Create a MessageEvent Package and add it to the message MessageEvent event = new MessageEvent(); if (messageEvent.isDelivered()) { event.setDelivered(true); } if (messageEvent.isDisplayed()) { event.setDisplayed(true); } event.setPacketID(packetID); msg.addExtension(event); // Send the packet SparkManager.getConnection().sendPacket(msg); } }
/** * Sends a broadcast message to all users selected. * * @param dlg */ private boolean sendBroadcasts(JDialog dlg) { final Set<String> jids = new HashSet<String>(); for (CheckNode node : nodes) { if (node.isSelected()) { String jid = (String) node.getAssociatedObject(); jids.add(jid); } } if (jids.size() == 0) { JOptionPane.showMessageDialog( dlg, Res.getString("message.broadcast.no.user.selected"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE); return false; } String text = messageBox.getText(); if (!ModelUtil.hasLength(text)) { JOptionPane.showMessageDialog( dlg, Res.getString("message.broadcast.no.text"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE); return false; } for (String jid : jids) { final Message message = new Message(); message.setTo(jid); message.setBody(text); if (normalMessageButton.isSelected()) { message.setType(Message.Type.normal); } else { message.setType(Message.Type.headline); } SparkManager.getConnection().sendPacket(message); } return true; }
private void loadLocalPreferences() { preference = new SipPreference(); PreferenceManager pm = SparkManager.getPreferenceManager(); pm.addPreference(preference); preferences = (SipPreferences) preference.getData(); SIPConfig.setUseStun(preferences.isUseStun()); SIPConfig.setStunServer(preferences.getStunServer()); SIPConfig.setStunPort(preferences.getStunPort()); SIPConfig.setPreferredNetworkAddress(preferences.getPreferredAddress()); preference.setCommitSettings(true); if (preferences.isRegisterAtStart()) { register(); } }
/** * The current SendField has been updated somehow. * * @param e - the DocumentEvent to respond to. */ public void insertUpdate(DocumentEvent e) { checkForText(e); if (!sendTypingNotification) { return; } lastTypedCharTime = System.currentTimeMillis(); // If the user pauses for more than two seconds, send out a new notice. if (sendNotification) { try { SparkManager.getMessageEventManager() .sendComposingNotification(getParticipantJID(), threadID); sendNotification = false; } catch (Exception exception) { Log.error("Error updating", exception); } } }
public PreferenceManager() { // Initialize base preferences ChatPreference chatPreferences = new ChatPreference(); addPreference(chatPreferences); chatPreferences.load(); GroupChatPreference groupChatPreferences = new GroupChatPreference(); addPreference(groupChatPreferences); groupChatPreferences.load(); MediaPreference preferenes = new MediaPreference(); addPreference(preferenes); preferenes.load(); // PrivacyPreferences privacy = new PrivacyPreferences(); // addPreference(privacy); // privacy.load(); LocalPreference localPreferences = new LocalPreference(); addPreference(localPreferences); localPreferences.load(); getPreferences(); SparkManager.getMainWindow() .addMainWindowListener( new MainWindowListener() { public void shutdown() { fireShutdown(); } public void mainWindowActivated() {} public void mainWindowDeactivated() {} }); }
public void actionPerformed(ActionEvent actionEvent) { if (hideChatHistory.isSelected()) { int ok = JOptionPane.showConfirmDialog( this, Res.getString("message.delete.all.history"), Res.getString("title.confirmation"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (ok == JOptionPane.YES_OPTION) { File transcriptDir = new File(SparkManager.getUserDirectory(), "transcripts"); File[] files = transcriptDir.listFiles(); hidePrevChatHistory.setEnabled(false); hidePrevChatHistory.setSelected(false); for (File transcriptFile : files) { transcriptFile.delete(); } } } else { hidePrevChatHistory.setEnabled(true); } }
/** * Invokes the Preferences Dialog. * * @param e the ActionEvent */ public void actionPerformed(ActionEvent e) { if (e.getSource().equals(preferenceMenuItem)) { SparkManager.getPreferenceManager().showPreferences(); } }