Examples of SwingWorker


Examples of jsky.util.SwingWorker

                }
            }
        }

        // Add any checked catalog dirs (this can take some time, so use background threads)
        new SwingWorker() {
            public Object construct() {
                try {
                    for (String urlStr : map.keySet()) {
                        String name = map.get(urlStr);
                        URL url = new URL(urlStr);
View Full Code Here

Examples of net.java.sip.communicator.plugin.desktoputil.SwingWorker

    */
    private void processReplacement(final String messageID,
                                    final String chatString,
                                    final String contentType)
    {
        SwingWorker worker = new SwingWorker()
        {
            /**
             * Called on the event dispatching thread (not on the worker thread)
             * after the <code>construct</code> method has returned.
             */
            public void finished()
            {
                String newMessage = (String) get();

                if (newMessage != null && !newMessage.equals(chatString))
                {
                    synchronized (scrollToBottomRunnable)
                    {
                        scrollToBottomIsPending = true;

                        try
                        {
                            Element elem = document.getElement(messageID);
                            document.setOuterHTML(elem, newMessage);
                        }
                        catch (BadLocationException ex)
                        {
                            logger.error("Could not replace chat message", ex);
                        }
                        catch (IOException ex)
                        {
                            logger.error("Could not replace chat message", ex);
                        }
                    }
                }
            }

            public Object construct() throws Exception
            {
                ConfigurationService cfg
                    = GuiActivator.getConfigurationService();
                boolean isEnabled
                    = cfg.getBoolean(
                            ReplacementProperty.REPLACEMENT_ENABLE,
                            true);
                Matcher divMatcher = DIV_PATTERN.matcher(chatString);
                String openingTag = "";
                String msgStore = chatString;
                String closingTag = "";
                if (divMatcher.find())
                {
                    openingTag = divMatcher.group(1);
                    msgStore = divMatcher.group(2);
                    closingTag = divMatcher.group(3);
                }

                for (Map.Entry<String, ReplacementService> entry
                        : GuiActivator.getReplacementSources().entrySet())
                {
                    ReplacementService source = entry.getValue();

                    boolean isSmiley
                        = source instanceof SmiliesReplacementService;

                    if (!(cfg.getBoolean(
                                ReplacementProperty.getPropertyName(
                                        source.getSourceName()),
                                true)
                            && (isEnabled || isSmiley)))
                        continue;

                    String sourcePattern = source.getPattern();
                    Pattern p
                        = Pattern.compile(
                                sourcePattern,
                                Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
                    Matcher m = p.matcher(msgStore);

                    StringBuilder msgBuff = new StringBuilder();
                    int startPos = 0;

                    while (m.find())
                    {
                        msgBuff.append(msgStore.substring(startPos, m.start()));
                        startPos = m.end();

                        String group = m.group();
                        String temp = source.getReplacement(group);
                        String group0 = m.group(0);

                        if(!temp.equals(group0)
                                || source.getSourceName().equals("DIRECTIMAGE"))
                        {
                            if(isSmiley)
                            {
                                msgBuff.append(
                                        ChatHtmlUtils.createEndPlainTextTag(
                                                contentType));
                                msgBuff.append("<IMG SRC=\"");
                            }
                            else
                            {
                                msgBuff.append(
                                    "<IMG HEIGHT=\"90\" WIDTH=\"120\" SRC=\"");
                            }

                            msgBuff.append(temp);
                            msgBuff.append("\" BORDER=\"0\" ALT=\"");
                            msgBuff.append(group0);
                            msgBuff.append("\"></IMG>");

                            if(isSmiley)
                                msgBuff.append(
                                    ChatHtmlUtils.createStartPlainTextTag(
                                        contentType));
                        }
                        else
                        {
                            msgBuff.append(group);
                        }
                    }

                    msgBuff.append(msgStore.substring(startPos));

                    /*
                     * replace the msgStore variable with the current replaced
                     * message before next iteration
                     */
                    String msgBuffString = msgBuff.toString();

                    if (!msgBuffString.equals(msgStore))
                        msgStore = msgBuffString;
                }
                return openingTag + msgStore + closingTag;
            }
        };
        worker.start();
    }
View Full Code Here

Examples of net.java.sip.communicator.util.swing.SwingWorker

    */
    private void processReplacement(final Element elem, final String chatString)
    {
       final String chatFinal = chatString;

       SwingWorker worker = new SwingWorker()
       {
           public Object construct() throws Exception
           {
               String temp = "", msgStore = chatFinal;

               boolean isEnabled
                   = GuiActivator.getConfigurationService().getBoolean(
                       ReplacementProperty.REPLACEMENT_ENABLE, true);

               Map<String, ReplacementService> listSources
                   = GuiActivator.getReplacementSources();

               Iterator<Entry<String, ReplacementService>> entrySetIter
                   = listSources.entrySet().iterator();

               for (int i = 0; i < listSources.size(); i++)
               {
                   Map.Entry<String, ReplacementService> entry
                       = entrySetIter.next();

                   ReplacementService source = entry.getValue();

                   boolean isSmiley
                       = source instanceof SmiliesReplacementService;

                   if (!(GuiActivator.getConfigurationService().getBoolean(
                       ReplacementProperty.getPropertyName(source
                       .getSourceName()), true) && (isEnabled || isSmiley)))
                       continue;

                   String sourcePattern = source.getPattern();
                   Pattern p = Pattern.compile(sourcePattern,
                                   Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

                   Matcher m = p.matcher(msgStore);

                   String startPlainTextTag = START_PLAINTEXT_TAG;
                   String endPlainTextTag = END_PLAINTEXT_TAG;

                   int count = 0, startPos = 0;
                   StringBuffer msgBuff = new StringBuffer();

                   while (m.find())
                   {
                       count++;
                       msgBuff.append(msgStore.substring(startPos, m.start()));
                       startPos = m.end();

                       temp = source.getReplacement(m.group());

                       if(!temp.equals(m.group(0)) || source.getSourceName()
                               .equals("DIRECTIMAGE"))
                       {
                           if(isSmiley)
                           {
                               msgBuff.append(endPlainTextTag);
                               msgBuff.append("<IMG SRC=\"");
                           }
                           else
                           {
                               msgBuff.append(
                                   "<IMG HEIGHT=\"90\" WIDTH=\"120\" SRC=\"");
                           }

                           msgBuff.append(temp);
                           msgBuff.append("\" BORDER=\"0\" ALT=\"");
                           msgBuff.append(m.group(0));
                           msgBuff.append("\"></IMG>");

                           if(isSmiley)
                               msgBuff.append(startPlainTextTag);
                       }
                       else
                       {
                           msgBuff.append(
                               msgStore.substring(m.start(), m.end()));
                       }
                   }

                   msgBuff.append(msgStore.substring(startPos));

                   /*
                    * replace the msgStore variable with the current replaced
                    * message before next iteration
                    */
                   if (!msgBuff.toString().equals(msgStore))
                   {
                       msgStore = msgBuff.toString();
                   }
               }

               if (!msgStore.equals(chatFinal))
               {
                   synchronized (scrollToBottomRunnable)
                   {
                       scrollToBottomIsPending = true;
                       document.setOuterHTML(elem, msgStore.toString()
                           .substring(msgStore.indexOf("<DIV")));
                   }
               }
               return "";
           }
       };
       worker.start();
    }
View Full Code Here

Examples of net.java.sip.communicator.util.swing.SwingWorker

        final ChatTransport sendFileTransport
            = this.findFileTransferChatTransport();

        this.setSelectedChatTransport(sendFileTransport);

        SwingWorker worker = new SwingWorker()
        {
            public Object construct()
                throws Exception
            {
                if(file.length() > sendFileTransport.getMaximumFileLength())
                {
                    addMessage(
                        chatSession.getCurrentChatTransport().getName(),
                        System.currentTimeMillis(),
                        Chat.ERROR_MESSAGE,
                        GuiActivator.getResources()
                            .getI18NString("service.gui.FILE_TOO_BIG",
                            new String[]{
                                sendFileTransport.getMaximumFileLength()/1024/1024
                                + " MB"}),
                        "",
                        "text");
                    fileComponent.setFailed();

                    return "";
                }

                final FileTransfer fileTransfer
                    = sendFileTransport.sendFile(file);

                addActiveFileTransfer(fileTransfer.getID(), fileTransfer);

                // Add the status listener that would notify us when the file
                // transfer has been completed and should be removed from
                // active components.
                fileTransfer.addStatusListener(ChatPanel.this);

                SwingUtilities.invokeLater(new Runnable()
                {
                    public void run()
                    {
                        fileComponent.setProtocolFileTransfer(fileTransfer);
                    }
                });

                return "";
            }

            public void catchException(Throwable ex)
            {
                logger.error("Failed to send file.", ex);

                if (ex instanceof IllegalStateException)
                {
                    addErrorMessage(
                        chatSession.getCurrentChatTransport().getName(),
                        GuiActivator.getResources().getI18NString(
                            "service.gui.MSG_SEND_CONNECTION_PROBLEM"));
                }
                else
                {
                    addErrorMessage(
                        chatSession.getCurrentChatTransport().getName(),
                        GuiActivator.getResources().getI18NString(
                            "service.gui.MSG_DELIVERY_ERROR",
                            new String[]{ex.getMessage()}));
                }
            }
        };

        worker.start();
    }
View Full Code Here

Examples of net.java.sip.communicator.util.swing.SwingWorker

     * @param escapedMessageID the id of the message to be ignored;
     * <tt>null</tt> if no message is to be ignored
     */
    public void loadHistory(final String escapedMessageID)
    {
        SwingWorker historyWorker = new SwingWorker()
        {
            private Collection<Object> historyList;

            public Object construct() throws Exception
            {
                // Load the history period, which initializes the
                // firstMessageTimestamp and the lastMessageTimeStamp variables.
                // Used to disable/enable history flash buttons in the chat
                // window tool bar.
                loadHistoryPeriod();

                // Load the last N=CHAT_HISTORY_SIZE messages from history.
                historyList = chatSession.getHistory(
                    ConfigurationManager.getChatHistorySize());

                return historyList;
            }

            /**
             * Called on the event dispatching thread (not on the worker thread)
             * after the <code>construct</code> method has returned.
             */
            public void finished()
            {
                if(historyList != null && historyList.size() > 0)
                {
                    processHistory(historyList, escapedMessageID);
                }
                isHistoryLoaded = true;

                // Add incoming events accumulated while the history was loading
                // at the end of the chat.
                addIncomingEvents();
            }
        };

        historyWorker.start();
    }
View Full Code Here

Examples of net.java.sip.communicator.util.swing.SwingWorker

                                    final String chatString,
                                    final String contentType)
    {
       final String chatFinal = chatString;

       SwingWorker worker = new SwingWorker()
       {
           public Object construct() throws Exception
           {
               String temp = "", msgStore = chatFinal;

               boolean isEnabled
                   = GuiActivator.getConfigurationService().getBoolean(
                       ReplacementProperty.REPLACEMENT_ENABLE, true);

               Map<String, ReplacementService> listSources
                   = GuiActivator.getReplacementSources();

               Iterator<Entry<String, ReplacementService>> entrySetIter
                   = listSources.entrySet().iterator();

               for (int i = 0; i < listSources.size(); i++)
               {
                   Map.Entry<String, ReplacementService> entry
                       = entrySetIter.next();

                   ReplacementService source = entry.getValue();

                   boolean isSmiley
                       = source instanceof SmiliesReplacementService;

                   if (!(GuiActivator.getConfigurationService().getBoolean(
                       ReplacementProperty.getPropertyName(source
                       .getSourceName()), true) && (isEnabled || isSmiley)))
                       continue;

                   String sourcePattern = source.getPattern();
                   Pattern p = Pattern.compile(sourcePattern,
                                   Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

                   Matcher m = p.matcher(msgStore);

                   String startPlainTextTag = "";
                   String endPlainTextTag = "";

                   if (!HTML_CONTENT_TYPE.equals(contentType))
                   {
                       startPlainTextTag = START_PLAINTEXT_TAG;
                       endPlainTextTag = END_PLAINTEXT_TAG;
                   }

                   int count = 0, startPos = 0;
                   StringBuffer msgBuff = new StringBuffer();

                   while (m.find())
                   {
                       count++;
                       msgBuff.append(msgStore.substring(startPos, m.start()));
                       startPos = m.end();

                       temp = source.getReplacement(m.group());

                       if(!temp.equals(m.group(0)) || source.getSourceName()
                               .equals("DIRECTIMAGE"))
                       {
                           if(isSmiley)
                           {
                               msgBuff.append(endPlainTextTag);
                               msgBuff.append("<IMG SRC=\"");
                           }
                           else
                           {
                               msgBuff.append(
                                   "<IMG HEIGHT=\"90\" WIDTH=\"120\" SRC=\"");
                           }

                           msgBuff.append(temp);
                           msgBuff.append("\" BORDER=\"0\" ALT=\"");
                           msgBuff.append(m.group(0));
                           msgBuff.append("\"></IMG>");

                           if(isSmiley)
                               msgBuff.append(startPlainTextTag);
                       }
                       else
                       {
                           msgBuff.append(
                               msgStore.substring(m.start(), m.end()));
                       }
                   }

                   msgBuff.append(msgStore.substring(startPos));

                   /*
                    * replace the msgStore variable with the current replaced
                    * message before next iteration
                    */
                   if (!msgBuff.toString().equals(msgStore))
                   {
                       msgStore = msgBuff.toString();
                   }
               }

               if (!msgStore.equals(chatFinal))
               {
                   synchronized (scrollToBottomRunnable)
                   {
                       scrollToBottomIsPending = true;
                       document.setOuterHTML(elem, msgStore.toString()
                           .substring(msgStore.indexOf("<DIV")));
                   }
               }
               return "";
           }
       };
       worker.start();
    }
View Full Code Here

Examples of net.java.sip.communicator.util.swing.SwingWorker

            fileComponent.setFailed();

            return;
        }

        SwingWorker worker = new SwingWorker()
        {
            public Object construct()
                throws Exception
            {
                final FileTransfer fileTransfer
                    = sendFileTransport.sendFile(file);

                addActiveFileTransfer(fileTransfer.getID(), fileTransfer);

                // Add the status listener that would notify us when the file
                // transfer has been completed and should be removed from
                // active components.
                fileTransfer.addStatusListener(ChatPanel.this);

                fileComponent.setProtocolFileTransfer(fileTransfer);

                return "";
            }

            public void catchException(Throwable ex)
            {
                logger.error("Failed to send file.", ex);

                if (ex instanceof IllegalStateException)
                {
                    addErrorMessage(
                        chatSession.getCurrentChatTransport().getName(),
                        GuiActivator.getResources().getI18NString(
                            "service.gui.MSG_SEND_CONNECTION_PROBLEM"));
                }
                else
                {
                    addErrorMessage(
                        chatSession.getCurrentChatTransport().getName(),
                        GuiActivator.getResources().getI18NString(
                            "service.gui.MSG_DELIVERY_ERROR",
                            new String[]{ex.getMessage()}));
                }
            }
        };

        worker.start();
    }
View Full Code Here

Examples of net.java.sip.communicator.util.swing.SwingWorker

     * @param escapedMessageID the id of the message to be ignored;
     * <tt>null</tt> if no message is to be ignored
     */
    public void loadHistory(final String escapedMessageID)
    {
        SwingWorker historyWorker = new SwingWorker()
        {
            private Collection<Object> historyList;

            public Object construct() throws Exception
            {
                // Load the history period, which initializes the
                // firstMessageTimestamp and the lastMessageTimeStamp variables.
                // Used to disable/enable history flash buttons in the chat
                // window tool bar.
                loadHistoryPeriod();

                // Load the last N=CHAT_HISTORY_SIZE messages from history.
                historyList = chatSession.getHistory(
                    ConfigurationManager.getChatHistorySize());

                return historyList;
            }

            /**
             * Called on the event dispatching thread (not on the worker thread)
             * after the <code>construct</code> method has returned.
             */
            public void finished()
            {
                if(historyList != null && historyList.size() > 0)
                {
                    processHistory(historyList, escapedMessageID);
                }
                isHistoryLoaded = true;

                // Add incoming events accumulated while the history was loading
                // at the end of the chat.
                addIncomingEvents();
            }
        };

        historyWorker.start();
    }
View Full Code Here

Examples of net.java.sip.communicator.util.swing.SwingWorker

        // here. The history service could be "disabled" from the user
        // through one of the configuration forms.
        if (chatHistory == null)
            return;

        SwingWorker worker = new SwingWorker()
        {
            public Object construct() throws Exception
            {
                ChatConversationPanel conversationPanel
                    = getChatConversationPanel();
                Date firstMsgDate
                    = conversationPanel.getPageFirstMsgTimestamp();
                Collection<Object> c = null;

                if(firstMsgDate != null)
                {
                    c = chatSession.getHistoryBeforeDate(
                        firstMsgDate,
                        MESSAGES_PER_PAGE);
                }

                if(c !=null && c.size() > 0)
                {
                    SwingUtilities.invokeLater(
                            new HistoryMessagesLoader(c));
                }

                return "";
            }

            public void finished()
            {
                getChatContainer().updateHistoryButtonState(ChatPanel.this);
            }
        };
        worker.start();
    }
View Full Code Here

Examples of net.java.sip.communicator.util.swing.SwingWorker

        // here. The history could be "disabled" from the user
        // through one of the configuration forms.
        if (chatHistory == null)
            return;

        SwingWorker worker = new SwingWorker()
        {
            public Object construct() throws Exception
            {
                Date lastMsgDate
                    = getChatConversationPanel().getPageLastMsgTimestamp();

                Collection<Object> c = null;
                if(lastMsgDate != null)
                {
                    c = chatSession.getHistoryAfterDate(
                        lastMsgDate,
                        MESSAGES_PER_PAGE);
                }

                if(c != null && c.size() > 0)
                    SwingUtilities.invokeLater(
                            new HistoryMessagesLoader(c));

                return "";
            }

            public void finished()
            {
                getChatContainer().updateHistoryButtonState(ChatPanel.this);
            }
        };
        worker.start();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.