Search in sources :

Example 96 with Timer

use of javax.swing.Timer in project Universal-G-Code-Sender by winder.

the class MainWindow method sendButtonActionPerformed.

// GEN-LAST:event_pauseButtonActionPerformed
private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_sendButtonActionPerformed
    // Timer for updating duration labels.
    ActionListener actionListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            java.awt.EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    try {
                        durationValueLabel.setText(Utils.formattedMillis(backend.getSendDuration()));
                        remainingTimeValueLabel.setText(Utils.formattedMillis(backend.getSendRemainingDuration()));
                        // sentRowsValueLabel.setText(""+sentRows);
                        sentRowsValueLabel.setText("" + backend.getNumSentRows());
                        remainingRowsValueLabel.setText("" + backend.getNumRemainingRows());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    };
    this.resetTimerLabels();
    if (timer != null) {
        timer.stop();
    }
    timer = new Timer(1000, actionListener);
    try {
        this.backend.send();
        this.resetSentRowLabels(backend.getNumRows());
        timer.start();
    } catch (Exception e) {
        timer.stop();
        logger.log(Level.INFO, "Exception in sendButtonActionPerformed.", e);
        displayErrorDialog(e.getMessage());
    }
}
Also used : ActionListener(java.awt.event.ActionListener) Timer(javax.swing.Timer) ActionEvent(java.awt.event.ActionEvent) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 97 with Timer

use of javax.swing.Timer in project zencash-swing-wallet-ui by ZencashOfficial.

the class SendCashPanel method sendCash.

private void sendCash() throws WalletCallException, IOException, InterruptedException {
    if (balanceAddressCombo.getItemCount() <= 0) {
        JOptionPane.showMessageDialog(SendCashPanel.this.getRootPane().getParent(), langUtil.getString("send.cash.panel.option.pane.no.funds.text"), langUtil.getString("send.cash.panel.option.pane.no.funds.title"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (this.balanceAddressCombo.getSelectedIndex() < 0) {
        JOptionPane.showMessageDialog(SendCashPanel.this.getRootPane().getParent(), langUtil.getString("send.cash.panel.option.pane.select.source.text"), langUtil.getString("send.cash.panel.option.pane.select.source.title"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    final String sourceAddress = this.lastAddressBalanceData[this.balanceAddressCombo.getSelectedIndex()][1];
    final String destinationAddress = this.destinationAddressField.getText();
    final String memo = this.destinationMemoField.getText();
    final String amount = this.destinationAmountField.getText();
    final String fee = this.transactionFeeField.getText();
    // Verify general correctness.
    String errorMessage = null;
    if ((sourceAddress == null) || (sourceAddress.trim().length() <= 20)) {
        errorMessage = langUtil.getString("send.cash.panel.option.pane.error.source.address.invalid");
    } else if (sourceAddress.length() > 512) {
        errorMessage = langUtil.getString("send.cash.panel.option.pane.error.source.address.too.long");
    }
    // TODO: full address validation
    if ((destinationAddress == null) || (destinationAddress.trim().length() <= 0)) {
        errorMessage = langUtil.getString("send.cash.panel.option.pane.error.destination.address.invalid");
    } else if (destinationAddress.trim().length() <= 20) {
        errorMessage = langUtil.getString("send.cash.panel.option.pane.error.destination.address.too.short");
    } else if (destinationAddress.length() > 512) {
        errorMessage = langUtil.getString("send.cash.panel.option.pane.error.destination.address.too.long");
    } else if (destinationAddress.trim().length() != destinationAddress.length()) {
        errorMessage = langUtil.getString("send.cash.panel.option.pane.error.destination.address.has.spaces");
    }
    if ((amount == null) || (amount.trim().length() <= 0)) {
        errorMessage = langUtil.getString("send.cash.panel.option.pane.error.amount.invalid");
    } else {
        try {
            double d = Double.valueOf(amount);
        } catch (NumberFormatException nfe) {
            errorMessage = langUtil.getString("send.cash.panel.option.pane.error.amount.not.number");
        }
    }
    if ((fee == null) || (fee.trim().length() <= 0)) {
        errorMessage = langUtil.getString("send.cash.panel.option.pane.error.fee.invalid");
    } else {
        try {
            double d = Double.valueOf(fee);
        } catch (NumberFormatException nfe) {
            errorMessage = langUtil.getString("send.cash.panel.option.pane.error.fee.not.number");
        }
    }
    if (errorMessage != null) {
        JOptionPane.showMessageDialog(SendCashPanel.this.getRootPane().getParent(), errorMessage, langUtil.getString("send.cash.panel.option.pane.error.incorrect.sending.parameters"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    // ZClassic compatibility
    if (!installationObserver.isOnTestNet()) {
        if (!(destinationAddress.startsWith("zc") || destinationAddress.startsWith("zn") || destinationAddress.startsWith("zs"))) {
            Object[] options = { "OK" };
            JOptionPane.showOptionDialog(SendCashPanel.this.getRootPane().getParent(), langUtil.getString("send.cash.panel.option.pane.error.destination.address.incorrect.text", destinationAddress), langUtil.getString("send.cash.panel.option.pane.error.destination.address.incorrect.title"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);
            // Do not send anything!
            return;
        }
    }
    // If a memo is specified, make sure the destination is a Z address.
    if ((!installationObserver.isOnTestNet()) && (!Util.stringIsEmpty(memo)) && (!Util.isZAddress(destinationAddress))) {
        int reply = JOptionPane.showConfirmDialog(SendCashPanel.this.getRootPane().getParent(), langUtil.getString("send.cash.panel.option.pane.error.destination.address.notz.text", destinationAddress), langUtil.getString("send.cash.panel.option.pane.error.destination.address.notz.title"), JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.NO_OPTION) {
            return;
        }
    }
    // Check for encrypted wallet
    final boolean bEncryptedWallet = this.clientCaller.isWalletEncrypted();
    if (bEncryptedWallet) {
        PasswordDialog pd = new PasswordDialog((JFrame) (SendCashPanel.this.getRootPane().getParent()));
        pd.setVisible(true);
        if (!pd.isOKPressed()) {
            return;
        }
        this.clientCaller.unlockWallet(pd.getPassword());
    }
    // Call the wallet send method
    operationStatusID = this.clientCaller.sendCash(sourceAddress, destinationAddress, amount, memo, fee);
    // Make sure the keypool has spare addresses
    if ((this.backupTracker.getNumTransactionsSinceLastBackup() % 5) == 0) {
        this.clientCaller.keypoolRefill(100);
    }
    // Disable controls after send
    sendButton.setEnabled(false);
    balanceAddressCombo.setEnabled(false);
    destinationAddressField.setEnabled(false);
    destinationAmountField.setEnabled(false);
    destinationMemoField.setEnabled(false);
    transactionFeeField.setEnabled(false);
    // Start a data gathering thread specific to the operation being executed - this is done is a separate
    // thread since the server responds more slowly during JoinSPlits and this blocks he GUI somewhat.
    final DataGatheringThread<Boolean> opFollowingThread = new DataGatheringThread<Boolean>(new DataGatheringThread.DataGatherer<Boolean>() {

        public Boolean gatherData() throws Exception {
            long start = System.currentTimeMillis();
            Boolean result = clientCaller.isSendingOperationComplete(operationStatusID);
            long end = System.currentTimeMillis();
            Log.info("Checking for operation " + operationStatusID + " status done in " + (end - start) + "ms.");
            return result;
        }
    }, this.errorReporter, 2000, true);
    // Start a timer to update the progress of the operation
    operationStatusCounter = 0;
    operationStatusTimer = new Timer(2000, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                // TODO: Handle errors in case of restarted server while wallet is sending ...
                Boolean opComplete = opFollowingThread.getLastData();
                if ((opComplete != null) && opComplete.booleanValue()) {
                    // End the special thread used to follow the operation
                    opFollowingThread.setSuspended(true);
                    SendCashPanel.this.reportCompleteOperationToTheUser(amount, sourceAddress, destinationAddress);
                    // Lock the wallet again
                    if (bEncryptedWallet) {
                        SendCashPanel.this.clientCaller.lockWallet();
                    }
                    // Restore controls etc.
                    operationStatusCounter = 0;
                    operationStatusID = null;
                    operationStatusTimer.stop();
                    operationStatusTimer = null;
                    operationStatusProhgressBar.setValue(0);
                    sendButton.setEnabled(true);
                    balanceAddressCombo.setEnabled(true);
                    destinationAddressField.setEnabled(true);
                    destinationAmountField.setEnabled(true);
                    transactionFeeField.setEnabled(true);
                    destinationMemoField.setEnabled(true);
                } else {
                    // Update the progress
                    operationStatusLabel.setText(langUtil.getString("send.cash.panel.operation.status.progress.label"));
                    operationStatusCounter += 2;
                    int progress = 0;
                    if (operationStatusCounter <= 100) {
                        progress = operationStatusCounter;
                    } else {
                        progress = 100 + (((operationStatusCounter - 100) * 6) / 10);
                    }
                    operationStatusProhgressBar.setValue(progress);
                }
                SendCashPanel.this.repaint();
            } catch (Exception ex) {
                Log.error("Unexpected error: ", ex);
                SendCashPanel.this.errorReporter.reportError(ex);
            }
        }
    });
    operationStatusTimer.setInitialDelay(0);
    operationStatusTimer.start();
}
Also used : ActionEvent(java.awt.event.ActionEvent) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) WalletCallException(com.vaklinov.zcashui.ZCashClientCaller.WalletCallException) Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener)

Example 98 with Timer

use of javax.swing.Timer in project ffx by mjschnie.

the class TinkerSimulation method connect.

/**
 * <p>
 * connect</p>
 *
 * @return a boolean.
 */
public boolean connect() {
    if (isFinished()) {
        return false;
    }
    if (isConnected()) {
        return true;
    }
    // Create a timer to regularly wake up this TinkerSimulation.
    if (timer == null) {
        timer = new Timer(delay, this);
        timer.setCoalesce(true);
        timer.setDelay(10);
        timer.start();
    }
    // Create the FFXClient to monitor messages to/from TINKER.
    if (client == null) {
        client = new FFXClient(address);
    }
    // Try to connect.
    client.connect();
    // If connected, change to our "steady-state" timer delay.
    if (client.isConnected()) {
        timer.setDelay(delay);
        return true;
    }
    // the timer wakes up.
    return false;
}
Also used : Timer(javax.swing.Timer) FFXClient(ffx.ui.commands.FFXClient)

Example 99 with Timer

use of javax.swing.Timer in project gate-core by GateNLP.

the class TextualDocumentView method initGUI.

/*
   * (non-Javadoc)
   * 
   * @see gate.gui.docview.AbstractDocumentView#initGUI()
   */
@Override
protected void initGUI() {
    // textView = new JEditorPane();
    // textView.setContentType("text/plain");
    // textView.setEditorKit(new RawEditorKit());
    textView = new JTextArea();
    textView.setAutoscrolls(false);
    textView.setLineWrap(true);
    textView.setWrapStyleWord(true);
    // the selection is hidden when the focus is lost for some system
    // like Linux, so we make sure it stays
    // it is needed when doing a selection in the search textfield
    textView.setCaret(new PermanentSelectionCaret());
    scroller = new JScrollPane(textView);
    textView.setText(document.getContent().toString());
    textView.getDocument().addDocumentListener(swingDocListener);
    // display and put the caret at the beginning of the file
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                if (textView.modelToView(0) != null) {
                    textView.scrollRectToVisible(textView.modelToView(0));
                }
                textView.select(0, 0);
                textView.requestFocus();
            } catch (BadLocationException e) {
                e.printStackTrace();
            }
        }
    });
    // contentPane = new JPanel(new BorderLayout());
    // contentPane.add(scroller, BorderLayout.CENTER);
    // //get a pointer to the annotation list view used to display
    // //the highlighted annotations
    // Iterator horizViewsIter = owner.getHorizontalViews().iterator();
    // while(annotationListView == null && horizViewsIter.hasNext()){
    // DocumentView aView = (DocumentView)horizViewsIter.next();
    // if(aView instanceof AnnotationListView)
    // annotationListView = (AnnotationListView)aView;
    // }
    highlightsMinder = new Timer(BLINK_DELAY, new UpdateHighlightsAction());
    highlightsMinder.setInitialDelay(HIGHLIGHT_DELAY);
    highlightsMinder.setDelay(BLINK_DELAY);
    highlightsMinder.setRepeats(true);
    highlightsMinder.setCoalesce(true);
    highlightsMinder.start();
    // blinker = new Timer(this.getClass().getCanonicalName() +
    // "_blink_timer",
    // true);
    // final BlinkAction blinkAction = new BlinkAction();
    // blinker.scheduleAtFixedRate(new TimerTask(){
    // public void run() {
    // blinkAction.actionPerformed(null);
    // }
    // }, 0, BLINK_DELAY);
    initListeners();
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) Timer(javax.swing.Timer) BadLocationException(javax.swing.text.BadLocationException)

Example 100 with Timer

use of javax.swing.Timer in project CodenameOne by codenameone.

the class PercentLayoutAnimator method start.

public void start() {
    animatorTimer = new Timer(15, this);
    animatorTimer.start();
}
Also used : Timer(javax.swing.Timer)

Aggregations

Timer (javax.swing.Timer)130 ActionEvent (java.awt.event.ActionEvent)66 ActionListener (java.awt.event.ActionListener)62 IOException (java.io.IOException)12 JPanel (javax.swing.JPanel)12 JLabel (javax.swing.JLabel)11 BorderLayout (java.awt.BorderLayout)9 Dimension (java.awt.Dimension)9 Point (java.awt.Point)9 Color (java.awt.Color)8 JCheckBox (javax.swing.JCheckBox)8 MouseEvent (java.awt.event.MouseEvent)7 JFrame (javax.swing.JFrame)7 MouseAdapter (java.awt.event.MouseAdapter)6 Window (java.awt.Window)5 JButton (javax.swing.JButton)5 JDialog (javax.swing.JDialog)5 JScrollPane (javax.swing.JScrollPane)5 File (java.io.File)4 Date (java.util.Date)4