Examples of SwingWorker


Examples of net.java.sip.communicator.util.swing.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);
                String msgStore = chatString;

                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 msgStore;
            }
        };
        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

Examples of net.xoetrope.xui.helper.SwingWorker

        // notify the change due
        output.print(UtilProperties.getMessage(PosTransaction.resource,"PosChange",defaultLocale) + " " + UtilFormatOut.formatPrice(this.getTotalDue().negate()));

        // threaded drawer/receipt printing
        final PosTransaction currentTrans = this;
        final SwingWorker worker = new SwingWorker() {
            public Object construct() {
                // open the drawer
                currentTrans.popDrawer();

                // print the receipt
                DeviceLoader.receipt.printReceipt(currentTrans, true);

                return null;
            }
        };
        worker.start();

        // save the TX Log
        txLog.set("statusId", "POSTX_SOLD");
        txLog.set("orderId", orderId);
        txLog.set("itemCount", new Long(cart.size()));
View Full Code Here

Examples of net.xoetrope.xui.helper.SwingWorker

        }
        final String buttonName = ButtonEventConfig.getButtonName(event);
        final ClassLoader cl = this.getClassLoader(pos);

        if (buttonName != null) {
            final SwingWorker worker = new SwingWorker() {
                public Object construct() {
                    if (cl != null) {
                        Thread.currentThread().setContextClassLoader(cl);
                    }
                    try {
                        ButtonEventConfig.invokeButtonEvent(buttonName, pos, event);
                    } catch (ButtonEventConfig.ButtonEventNotFound e) {
                        Debug.logWarning(e, "Button not found - " + buttonName, module);
                    } catch (ButtonEventConfig.ButtonEventException e) {
                        Debug.logError(e, "Button invocation exception - " + buttonName, module);
                    }
                    return null;
                }
            };
            worker.start();
        } else {
            Debug.logWarning("No button name found for buttonPressed event", module);
        }
    }
View Full Code Here

Examples of net.xoetrope.xui.helper.SwingWorker

        // notify the change due
        output.print(UtilProperties.getMessage(resource, "PosChange",locale) + " " + UtilFormatOut.formatPrice(this.getTotalDue().negate()));

        // threaded drawer/receipt printing
        final PosTransaction currentTrans = this;
        final SwingWorker worker = new SwingWorker() {
            @Override
            public Object construct() {
                // open the drawer
                currentTrans.popDrawer();

                // print the receipt
                DeviceLoader.receipt.printReceipt(currentTrans, true);

                return null;
            }
        };
        worker.start();

        // save the TX Log
        txLog.set("statusId", "POSTX_SOLD");
        txLog.set("orderId", orderId);
        txLog.set("itemCount", new Long(cart.size()));
View Full Code Here

Examples of net.xoetrope.xui.helper.SwingWorker

        }
        final String buttonName = ButtonEventConfig.getButtonName(event);
        final ClassLoader cl = this.getClassLoader(pos);

        if (buttonName != null) {
            final SwingWorker worker = new SwingWorker() {
                @Override
                public Object construct() {
                    if (cl != null) {
                        Thread.currentThread().setContextClassLoader(cl);
                    }
                    try {
                        ButtonEventConfig.invokeButtonEvent(buttonName, pos, event);
                    } catch (ButtonEventConfig.ButtonEventNotFound e) {
                        Debug.logWarning(e, "Button not found - " + buttonName, module);
                    } catch (ButtonEventConfig.ButtonEventException e) {
                        Debug.logError(e, "Button invocation exception - " + buttonName, module);
                    }
                    return null;
                }
            };
            worker.start();
        } else {
            Debug.logWarning("No button name found for buttonPressed event", module);
        }
    }
View Full Code Here

Examples of net.xoetrope.xui.helper.SwingWorker

        // notify the change due
        output.print(UtilProperties.getMessage(PosTransaction.resource,"PosChange",defaultLocale) + " " + UtilFormatOut.formatPrice(this.getTotalDue().negate()));

        // threaded drawer/receipt printing
        final PosTransaction currentTrans = this;
        final SwingWorker worker = new SwingWorker() {
            public Object construct() {
                // open the drawer
                currentTrans.popDrawer();

                // print the receipt
                DeviceLoader.receipt.printReceipt(currentTrans, true);

                return null;
            }
        };
        worker.start();

        // save the TX Log
        txLog.set("statusId", "POSTX_SOLD");
        txLog.set("orderId", orderId);
        txLog.set("itemCount", new Long(cart.size()));
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.