private void initComponents() {
    jfxPanel = new JFXPanel();

    createScene();

    ActionListener al =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            loadURL(txtURL.getText());
          }
        };

    btnGo.addActionListener(al);
    txtURL.addActionListener(al);

    progressBar.setPreferredSize(new Dimension(150, 18));
    progressBar.setStringPainted(true);

    JPanel topBar = new JPanel(new BorderLayout(5, 0));
    topBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
    topBar.add(txtURL, BorderLayout.CENTER);
    topBar.add(btnGo, BorderLayout.EAST);

    JPanel statusBar = new JPanel(new BorderLayout(5, 0));
    statusBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
    statusBar.add(lblStatus, BorderLayout.CENTER);
    statusBar.add(progressBar, BorderLayout.EAST);

    panel.add(topBar, BorderLayout.NORTH);
    panel.add(jfxPanel, BorderLayout.CENTER);
    panel.add(statusBar, BorderLayout.SOUTH);

    frame.getContentPane().add(panel);
  }
  /**
   * Sets the index of the current animation frame to the specified value and requests that the
   * progress bar be repainted. Subclasses that don't use the default painting code might need to
   * override this method to change the way that the <code>repaint</code> method is invoked.
   *
   * @param newValue the new animation index; no checking is performed on its value
   * @see #incrementAnimationIndex
   * @since 1.4
   */
  protected void setAnimationIndex(int newValue) {
    if (animationIndex != newValue) {
      if (sizeChanged()) {
        animationIndex = newValue;
        maxPosition = 0; // needs to be recalculated
        delta = 0.0; // needs to be recalculated
        progressBar.repaint();
        return;
      }

      // Get the previous box drawn.
      nextPaintRect = getBox(nextPaintRect);

      // Update the frame number.
      animationIndex = newValue;

      // Get the next box to draw.
      if (nextPaintRect != null) {
        boxRect = getBox(boxRect);
        if (boxRect != null) {
          nextPaintRect.add(boxRect);
        }
      }
    } else { // animationIndex == newValue
      return;
    }

    if (nextPaintRect != null) {
      progressBar.repaint(nextPaintRect);
    } else {
      progressBar.repaint();
    }
  }
  /**
   * Paints the progress string.
   *
   * @param g Graphics used for drawing.
   * @param x x location of bounding box
   * @param y y location of bounding box
   * @param width width of bounding box
   * @param height height of bounding box
   * @param fillStart start location, in x or y depending on orientation, of the filled portion of
   *     the progress bar.
   * @param amountFull size of the fill region, either width or height depending upon orientation.
   * @param b Insets of the progress bar.
   */
  private void paintString(
      Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Graphics2D g2 = (Graphics2D) g;
    String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2, progressString, x, y, width, height);
    Rectangle oldClip = g2.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      g2.setColor(getSelectionBackground());
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
      g2.setColor(getSelectionForeground());
      g2.clipRect(fillStart, y, amountFull, height);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
    } else { // VERTICAL
      g2.setColor(getSelectionBackground());
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      g2.setFont(progressBar.getFont().deriveFont(rotate));
      renderLocation = getStringPlacement(g2, progressString, x, y, width, height);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
      g2.setColor(getSelectionForeground());
      g2.clipRect(x, fillStart, width, amountFull);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
    }
    g2.setClip(oldClip);
  }
 /**
  * Returns an enum indicating how the baseline of the component changes as the size changes.
  *
  * @throws NullPointerException {@inheritDoc}
  * @see javax.swing.JComponent#getBaseline(int, int)
  * @since 1.6
  */
 public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) {
   super.getBaselineResizeBehavior(c);
   if (progressBar.isStringPainted() && progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
     return Component.BaselineResizeBehavior.CENTER_OFFSET;
   }
   return Component.BaselineResizeBehavior.OTHER;
 }
Ejemplo n.º 5
0
  /**
   * And now for a little assembly. Put together the buttons, progress bar and status text field.
   */
  Example1(String name) {
    setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), name));

    progressBar.setMaximum(NUMLOOPS);

    startButton = new JButton("Start");
    startButton.addActionListener(startListener);
    startButton.setEnabled(true);

    interruptButton = new JButton("Cancel");
    interruptButton.addActionListener(interruptListener);
    interruptButton.setEnabled(false);

    JComponent buttonBox = new JPanel();
    buttonBox.add(startButton);
    buttonBox.add(interruptButton);

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    add(buttonBox);
    add(progressBar);
    add(statusField);
    statusField.setAlignmentX(CENTER_ALIGNMENT);

    buttonBox.setBorder(spaceBelow);
    Border pbBorder = progressBar.getBorder();
    progressBar.setBorder(BorderFactory.createCompoundBorder(spaceBelow, pbBorder));
  }
  protected void installListeners() {
    // Listen for changes in the progress bar's data.
    changeListener = getHandler();
    progressBar.addChangeListener(changeListener);

    // Listen for changes between determinate and indeterminate state.
    progressBar.addPropertyChangeListener(getHandler());
  }
Ejemplo n.º 7
0
 @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);
   }
 }
 /**
  * Returns the baseline.
  *
  * @throws NullPointerException {@inheritDoc}
  * @throws IllegalArgumentException {@inheritDoc}
  * @see javax.swing.JComponent#getBaseline(int, int)
  * @since 1.6
  */
 public int getBaseline(JComponent c, int width, int height) {
   super.getBaseline(c, width, height);
   if (progressBar.isStringPainted() && progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
     FontMetrics metrics = progressBar.getFontMetrics(progressBar.getFont());
     Insets insets = progressBar.getInsets();
     int y = insets.top;
     height = height - insets.top - insets.bottom;
     return y + (height + metrics.getAscent() - metrics.getLeading() - metrics.getDescent()) / 2;
   }
   return -1;
 }
Ejemplo n.º 9
0
 public void status_Proses(boolean sukses, String status, int nilaiProsesBar) {
   statusProses.setText(status);
   prosesBar.setValue(prosesBar.getValue() + nilaiProsesBar);
   if (proses == false) {
     JOptionPane.showMessageDialog(null, "Gagal Login\nKarena" + statusGagal);
     removeAll();
     dispose();
     new LoginDialog_Database().show();
   }
   proses = sukses;
   statusGagal = status;
 }
Ejemplo n.º 10
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());
              }
            });
      }
    }
Ejemplo n.º 11
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();
    }
  /**
   * This determines the amount of the progress bar that should be filled based on the percent done
   * gathered from the model. This is a common operation so it was abstracted out. It assumes that
   * your progress bar is linear. That is, if you are making a circular progress indicator, you will
   * want to override this method.
   */
  protected int getAmountFull(Insets b, int width, int height) {
    int amountFull = 0;
    BoundedRangeModel model = progressBar.getModel();

    if ((model.getMaximum() - model.getMinimum()) != 0) {
      if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        amountFull = (int) Math.round(width * progressBar.getPercentComplete());
      } else {
        amountFull = (int) Math.round(height * progressBar.getPercentComplete());
      }
    }
    return amountFull;
  }
Ejemplo n.º 13
0
 public void tampilan_GUI() {
   this.getContentPane().setBackground(Color.yellow);
   this.getContentPane().setLayout(null);
   jLabel1.setFont(new java.awt.Font("Dialog", 1, 16));
   jLabel1.setText("Please Waiting...");
   jLabel1.setBounds(new Rectangle(14, 5, 187, 30));
   prosesBar.setBounds(new Rectangle(14, 40, 311, 16));
   prosesBar.setStringPainted(true);
   statusProses.setText("");
   statusProses.setBounds(new Rectangle(14, 60, 311, 16));
   this.getContentPane().add(jLabel1);
   this.getContentPane().add(prosesBar);
   this.getContentPane().add(statusProses);
 }
 /**
  * Returns the width (if HORIZONTAL) or height (if VERTICAL) of each of the individual cells/units
  * to be rendered in the progress bar. However, for text rendering simplification and aesthetic
  * considerations, this function will return 1 when the progress string is being rendered.
  *
  * @return the value representing the spacing between cells
  * @see #setCellLength
  * @see JProgressBar#isStringPainted
  */
 protected int getCellLength() {
   if (progressBar.isStringPainted()) {
     return 1;
   } else {
     return cellLength;
   }
 }
  /** Assumes that the component innards, max position, etc. are up-to-date. */
  private Rectangle getGenericBox(Rectangle r) {
    if (r == null) {
      r = new Rectangle();
    }

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      r.width = getBoxLength(componentInnards.width, componentInnards.height);
      if (r.width < 0) {
        r = null;
      } else {
        r.height = componentInnards.height;
        r.y = componentInnards.y;
      }
      // end of HORIZONTAL

    } else { // VERTICAL progress bar
      r.height = getBoxLength(componentInnards.height, componentInnards.width);
      if (r.height < 0) {
        r = null;
      } else {
        r.width = componentInnards.width;
        r.x = componentInnards.x;
      }
    } // end of VERTICAL

    return r;
  }
 /** Delegates painting to one of two methods: paintDeterminate or paintIndeterminate. */
 public void paint(Graphics g, JComponent c) {
   if (progressBar.isIndeterminate()) {
     paintIndeterminate(g, c);
   } else {
     paintDeterminate(g, c);
   }
 }
  /** Invoked by PropertyChangeHandler. */
  private void cleanUpIndeterminateValues() {
    // stop the animation thread if necessary
    if (progressBar.isDisplayable()) {
      stopAnimationTimer();
    }

    cycleTime = repaintInterval = 0;
    numFrames = animationIndex = 0;
    maxPosition = 0;
    delta = 0.0;

    boxRect = nextPaintRect = null;
    componentInnards = oldComponentInnards = null;

    progressBar.removeHierarchyListener(getHandler());
  }
 /**
  * Returns the spacing between each of the cells/units in the progress bar. However, for text
  * rendering simplification and aesthetic considerations, this function will return 0 when the
  * progress string is being rendered.
  *
  * @return the value representing the spacing between cells
  * @see #setCellSpacing
  * @see JProgressBar#isStringPainted
  */
 protected int getCellSpacing() {
   if (progressBar.isStringPainted()) {
     return 0;
   } else {
     return cellSpacing;
   }
 }
  /**
   * Stores the position and size of the bouncing box that would be painted for the current
   * animation index in <code>r</code> and returns <code>r</code>. Subclasses that add to the
   * painting performed in this class's implementation of <code>paintIndeterminate</code> -- to draw
   * an outline around the bouncing box, for example -- can use this method to get the location of
   * the bouncing box that was just painted. By overriding this method, you have complete control
   * over the size and position of the bouncing box, without having to reimplement <code>
   * paintIndeterminate</code>.
   *
   * @param r the Rectangle instance to be modified; may be <code>null</code>
   * @return <code>null</code> if no box should be drawn; otherwise, returns the passed-in rectangle
   *     (if non-null) or a new rectangle
   * @see #setAnimationIndex
   * @since 1.4
   */
  protected Rectangle getBox(Rectangle r) {
    int currentFrame = getAnimationIndex();
    int middleFrame = numFrames / 2;

    if (sizeChanged() || delta == 0.0 || maxPosition == 0.0) {
      updateSizes();
    }

    r = getGenericBox(r);

    if (r == null) {
      return null;
    }
    if (middleFrame <= 0) {
      return null;
    }

    // assert currentFrame >= 0 && currentFrame < numFrames
    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      if (currentFrame < middleFrame) {
        r.x = componentInnards.x + (int) Math.round(delta * (double) currentFrame);
      } else {
        r.x = maxPosition - (int) Math.round(delta * (currentFrame - middleFrame));
      }
    } else { // VERTICAL indeterminate progress bar
      if (currentFrame < middleFrame) {
        r.y = componentInnards.y + (int) Math.round(delta * currentFrame);
      } else {
        r.y = maxPosition - (int) Math.round(delta * (currentFrame - middleFrame));
      }
    }
    return r;
  }
    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);
    }
Ejemplo n.º 21
0
  /** Get ready for a new game, given a letter list specification of the Boggle board. */
  public void newGame() {
    myBoard = BoggleBoardFactory.getBoard(myBoardSize);
    mySeconds = 0;
    myProgress.setValue(0);

    // set up views for new game

    if (myBoardSize == 4) {
      if (myBoardPanel != myBoardPanel4) {
        myBoardPanel = myBoardPanel4;
        getContentPane().remove(myBoardPanel5);
        getContentPane().add(myBoardPanel, BorderLayout.CENTER);
      }
    } else {
      if (myBoardPanel != myBoardPanel5) {
        myBoardPanel = myBoardPanel5;
        getContentPane().remove(myBoardPanel4);
        getContentPane().add(myBoardPanel, BorderLayout.CENTER);
      }
    }

    myBoardPanel.newGame();
    humanArea.setReady();
    computerArea.setReady();
    myBoardPanel.unHighlightAllDice();
    wordEntryField.setReady();
    ((JPanel) getContentPane()).revalidate();
    repaint();
    myTimer.start();
  }
Ejemplo n.º 22
0
    SwingProgress() {
      super(new BorderLayout());

      progress = new JProgressBar();
      progress.setStringPainted(true);

      SwingProgress.this.add(BorderLayout.NORTH, progress);
    }
 public void installUI(JComponent c) {
   progressBar = (JProgressBar) c;
   installDefaults();
   installListeners();
   if (progressBar.isIndeterminate()) {
     initIndeterminateValues();
   }
 }
 public void uninstallUI(JComponent c) {
   if (progressBar.isIndeterminate()) {
     cleanUpIndeterminateValues();
   }
   uninstallDefaults();
   uninstallListeners();
   progressBar = null;
 }
Ejemplo n.º 25
0
 public void gameOver() {
   myTimer.stop();
   mySeconds = myGameLength; // ensure over
   myProgress.setValue(myGameLength);
   repaint();
   wordEntryField.setUnready();
   computerPlay();
 }
Ejemplo n.º 26
0
  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 Dimension getMaximumSize(JComponent c) {
   Dimension pref = getPreferredSize(progressBar);
   if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
     pref.width = Short.MAX_VALUE;
   } else {
     pref.height = Short.MAX_VALUE;
   }
   return pref;
 }
Ejemplo n.º 28
0
  private void initTask(String cryptoki) {

    task = new ReadCertsTask(null, cryptoki, isDownloadCRLForced);

    task.go();

    progressBar.setMaximum(ReadCertsTask.READ_CERTS);
    timer.start();
  }
  /**
   * Designate the place where the progress string will be painted. This implementation places it at
   * the center of the progress bar (in both x and y). Override this if you want to right, left,
   * top, or bottom align the progress string or if you need to nudge it around for any reason.
   */
  protected Point getStringPlacement(
      Graphics g, String progressString, int x, int y, int width, int height) {
    FontMetrics fontSizer = SwingUtilities2.getFontMetrics(progressBar, g, progressBar.getFont());
    int stringWidth = SwingUtilities2.stringWidth(progressBar, fontSizer, progressString);

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      return new Point(
          x + Math.round(width / 2 - stringWidth / 2),
          y
              + ((height + fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent())
                  / 2));
    } else { // VERTICAL
      return new Point(
          x
              + ((width - fontSizer.getAscent() + fontSizer.getLeading() + fontSizer.getDescent())
                  / 2),
          y + Math.round(height / 2 - stringWidth / 2));
    }
  }
  /**
   * Invoked by PropertyChangeHandler.
   *
   * <p>NOTE: This might not be invoked until after the first paintIndeterminate call.
   */
  private void initIndeterminateValues() {
    initIndeterminateDefaults();
    // assert cycleTime/repaintInterval is a whole multiple of 2.
    numFrames = cycleTime / repaintInterval;
    initAnimationIndex();

    boxRect = new Rectangle();
    nextPaintRect = new Rectangle();
    componentInnards = new Rectangle();
    oldComponentInnards = new Rectangle();

    // we only bother installing the HierarchyChangeListener if we
    // are indeterminate
    progressBar.addHierarchyListener(getHandler());

    // start the animation thread if necessary
    if (progressBar.isDisplayable()) {
      startAnimationTimer();
    }
  }