@Override
 public void propertyChange(PropertyChangeEvent evt) {
   String strPropertyName = evt.getPropertyName();
   if ("progress".equals(strPropertyName)) {
     progressBar.setIndeterminate(false);
     int progress = (Integer) evt.getNewValue();
     progressBar.setValue(progress);
   }
 }
Beispiel #2
0
    @Override
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum((int) f.length());
        status.add(progress);
        status.revalidate();

        // try to start reading
        Reader in = new FileReader(f);
        char[] buff = new char[4096];
        int nch;
        while ((nch = in.read(buff, 0, buff.length)) != -1) {
          doc.insertString(doc.getLength(), new String(buff, 0, nch), null);
          progress.setValue(progress.getValue() + nch);
        }
      } catch (IOException e) {
        final String msg = e.getMessage();
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                JOptionPane.showMessageDialog(
                    getFrame(),
                    "Could not open file: " + msg,
                    "Error opening file",
                    JOptionPane.ERROR_MESSAGE);
              }
            });
      } catch (BadLocationException e) {
        System.err.println(e.getMessage());
      }
      doc.addUndoableEditListener(undoHandler);
      // we are done... get rid of progressbar
      status.removeAll();
      status.revalidate();

      resetUndoManager();

      if (elementTreePanel != null) {
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                elementTreePanel.setEditor(getEditor());
              }
            });
      }
    }
Beispiel #3
0
    @Override
    @SuppressWarnings("SleepWhileHoldingLock")
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum(doc.getLength());
        status.add(progress);
        status.revalidate();

        // start writing
        Writer out = new FileWriter(f);
        Segment text = new Segment();
        text.setPartialReturn(true);
        int charsLeft = doc.getLength();
        int offset = 0;
        while (charsLeft > 0) {
          doc.getText(offset, Math.min(4096, charsLeft), text);
          out.write(text.array, text.offset, text.count);
          charsLeft -= text.count;
          offset += text.count;
          progress.setValue(offset);
          try {
            Thread.sleep(10);
          } catch (InterruptedException e) {
            Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, e);
          }
        }
        out.flush();
        out.close();
      } catch (IOException e) {
        final String msg = e.getMessage();
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                JOptionPane.showMessageDialog(
                    getFrame(),
                    "Could not save file: " + msg,
                    "Error saving file",
                    JOptionPane.ERROR_MESSAGE);
              }
            });
      } catch (BadLocationException e) {
        System.err.println(e.getMessage());
      }
      // we are done... get rid of progressbar
      status.removeAll();
      status.revalidate();
    }
    protected void initComponents() {
      int border = 2;
      this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
      this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

      // Description label
      JPanel descriptionPanel = new JPanel(new GridLayout(0, 1, 0, 0));
      descriptionPanel.setBorder(BorderFactory.createEmptyBorder(border, border, border, border));
      String text = thread.getRetrievable().getName();
      text = text.length() > 40 ? text.substring(0, 37) + "..." : text;
      descriptionLabel = new JLabel(text);
      descriptionPanel.add(descriptionLabel);
      this.add(descriptionPanel);

      // Progrees and cancel button
      JPanel progressPanel = new JPanel();
      progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.X_AXIS));
      progressPanel.setBorder(BorderFactory.createEmptyBorder(border, border, border, border));
      progressBar = new JProgressBar(0, 100);
      progressBar.setPreferredSize(new Dimension(100, 16));
      progressPanel.add(progressBar);
      progressPanel.add(Box.createHorizontalStrut(8));
      cancelButton = new JButton("Cancel");
      cancelButton.setBackground(Color.RED);
      cancelButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              cancelButtonActionPerformed(event);
            }
          });
      progressPanel.add(cancelButton);
      this.add(progressPanel);
    }
  private static JComponent makeUI() {
    // final JProgressBar progressBar = new JProgressBar(SwingConstants.VERTICAL);
    final JProgressBar progressBar = new JProgressBar();
    progressBar.setOpaque(false);
    progressBar.setUI(new GradientPalletProgressBarUI());

    GridBagConstraints c = new GridBagConstraints();
    JPanel p = new JPanel(new GridBagLayout());
    p.setBorder(BorderFactory.createEmptyBorder(32, 8, 0, 8));

    c.gridheight = 1;
    c.gridwidth = 1;
    c.gridy = 0;

    c.gridx = 0;
    c.insets = new Insets(0, 0, 0, 4);
    c.weightx = 1d;
    c.fill = GridBagConstraints.HORIZONTAL;
    p.add(progressBar, c);

    c.gridx = 1;
    c.weightx = 0d;
    p.add(
        new JButton(
            new AbstractAction("Start") {
              @Override
              public void actionPerformed(ActionEvent e) {
                final JButton b = (JButton) e.getSource();
                b.setEnabled(false);
                SwingWorker<Void, Void> worker =
                    new Task() {
                      @Override
                      public void done() {
                        if (b.isDisplayable()) {
                          b.setEnabled(true);
                        }
                      }
                    };
                worker.addPropertyChangeListener(new ProgressListener(progressBar));
                worker.execute();
              }
            }),
        c);
    return p;
  }
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum((int) f2.length());
        status.add(progress);
        status.revalidate();

        // try to start reading
        Reader in = new FileReader(f2);
        char[] buff = new char[4096];
        int nch;
        while ((nch = in.read(buff, 0, buff.length)) != -1) {
          doc2.insertString(doc2.getLength(), new String(buff, 0, nch), null);
          progress.setValue(progress.getValue() + nch);
        }

        // we are done... get rid of progressbar
        // doc2.addUndoableEditListener(undoHandler);
        status.removeAll();
        status.revalidate();

        // resetUndoManager();
      } catch (IOException e) {
        System.err.println("TextViewer:FileLoader " + e.toString());
      } catch (BadLocationException e) {
        System.err.println("TextViewer:FileLoader " + e.getMessage());
      }
      /* aa
         if (elementTreePanel != null) {
         SwingUtilities.invokeLater(new Runnable() {
         public void run() {
         elementTreePanel.setEditor(getEditor());
         }
         });
         }
      */
    }
  public ProgressBarDemo() {
    jpb.setStringPainted(true); // Paint the percent in a string
    jpb.setValue(0);
    jpb.setMaximum(100);

    jtaResult.setWrapStyleWord(true);
    jtaResult.setLineWrap(true);

    JPanel panel = new JPanel();
    panel.add(new JLabel("Enter the prime number count"));
    panel.add(jtfPrimeCount);
    panel.add(jbtDisplayPrime);

    add(jpb, BorderLayout.NORTH);
    add(new JScrollPane(jtaResult), BorderLayout.CENTER);
    add(panel, BorderLayout.SOUTH);

    jbtDisplayPrime.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ComputePrime task =
                new ComputePrime(Integer.parseInt(jtfPrimeCount.getText()), jtaResult);

            task.addPropertyChangeListener(
                new PropertyChangeListener() {
                  public void propertyChange(PropertyChangeEvent e) {
                    if ("progress".equals(e.getPropertyName())) {
                      jpb.setValue((Integer) e.getNewValue());
                    }
                  }
                });

            task.execute(); // Execute SwingWorker
          }
        });
  }
  public ProcessFrame(Properties theProperties) {
    super(new BorderLayout());
    // myFile = theFile;
    myProperties = theProperties;
    Properties props = System.getProperties();
    props.put("http.proxyHost", myProperties.getProperty("PROXYHOST"));
    props.put("http.proxyPort", myProperties.getProperty("PROXYPORT"));

    // Create the demo's UI.
    StartButton = new JButton("Start");
    StartButton.setActionCommand("start");
    StartButton.addActionListener(this);
    cancelButton = new JButton("Cancel");
    cancelButton.setActionCommand("cancel");
    cancelButton.addActionListener(this);
    cancelButton.setEnabled(false);

    myDownloadOptions = new JComboBox(myDownloadOptionsStr);

    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    progressBar2 = new JProgressBar(0, 100);
    progressBar2.setValue(0);
    progressBar2.setStringPainted(true);
    progressBar3 = new JProgressBar(0, 100);
    progressBar4 = new JProgressBar(0, 100);
    progressBar5 = new JProgressBar(0, 100);
    progressBar3.setValue(0);
    progressBar3.setStringPainted(true);
    progressBar4.setValue(0);
    progressBar4.setStringPainted(true);
    progressBar5.setValue(0);
    progressBar5.setStringPainted(true);

    taskOutput = new JTextArea(5, 20);

    final JPopupMenu taskPopupMenu = new JPopupMenu();
    JMenuItem clearMenuItem = new JMenuItem("Clear");
    clearMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            if (actionEvent.getActionCommand().equals("Clear")) {
              taskOutput.setText("");
            }
          }
        });
    taskPopupMenu.add(clearMenuItem);
    taskOutput.setMargin(new Insets(5, 5, 5, 5));
    taskOutput.setEditable(false);
    taskOutput.addMouseListener(
        new MouseAdapter() {
          private void showIfPopupTrigger(MouseEvent mouseEvent) {
            if (mouseEvent.isPopupTrigger()) {
              taskPopupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
            }
          }

          public void mousePressed(MouseEvent mouseEvent) {
            showIfPopupTrigger(mouseEvent);
          }

          public void mouseReleased(MouseEvent mouseEvent) {
            showIfPopupTrigger(mouseEvent);
          }
        });

    JPanel panel = new JPanel();
    JPanel panel2 = new JPanel();
    panel.setLayout(new GridBagLayout());
    panel2.setLayout(new GridBagLayout());
    panel.add(
        progressBar4,
        new GridBagConstraints(
            2,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(11, 11, 0, 0),
            0,
            0));
    panel.add(
        new JLabel("TOTAL"),
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 11, 0, 0),
            0,
            0));
    panel.add(
        progressBar,
        new GridBagConstraints(
            2,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(11, 11, 0, 0),
            0,
            0));
    panel.add(
        new JLabel("REMOTE DOWNLOAD"),
        new GridBagConstraints(
            1,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 11, 0, 0),
            0,
            0));
    panel.add(
        progressBar2,
        new GridBagConstraints(
            2,
            3,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(11, 11, 0, 0),
            0,
            0));
    panel.add(
        new JLabel("REMOTE SPLIT"),
        new GridBagConstraints(
            1,
            3,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 11, 0, 0),
            0,
            0));
    panel.add(
        progressBar3,
        new GridBagConstraints(
            2,
            4,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(11, 11, 0, 0),
            0,
            0));
    panel.add(
        new JLabel("LOCAL DOWNLOAD"),
        new GridBagConstraints(
            1,
            4,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 11, 0, 0),
            0,
            0));
    panel.add(
        progressBar5,
        new GridBagConstraints(
            2,
            5,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(11, 11, 0, 0),
            0,
            0));
    panel.add(
        new JLabel("LOCAL JOIN"),
        new GridBagConstraints(
            1,
            5,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 11, 0, 0),
            0,
            0));
    panel2.add(
        myDownloadOptions,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(4, 13, 4, 0),
            0,
            0));
    panel2.add(
        StartButton,
        new GridBagConstraints(
            2,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(4, 13, 4, 0),
            0,
            0));
    panel2.add(
        cancelButton,
        new GridBagConstraints(
            3,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(4, 13, 4, 0),
            0,
            0));

    add(panel, BorderLayout.PAGE_START);
    add(panel2, BorderLayout.CENTER);
    add(new JScrollPane(taskOutput), BorderLayout.PAGE_END);

    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
  }
 public void progressBarInc() {
   progressBar.setValue(progressBar.getValue() + 1);
 }
 public void setProgressBarMax(int min) {
   progressBar.setMaximum(min);
 }
 public void reset() {
   progressBar.setValue(0);
   progressBar.setMinimum(0);
   progressBar.setMaximum(100);
   _stopped = false;
 }