Ejemplo n.º 1
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));
  }
Ejemplo n.º 2
0
 public void reload() {
   userhp.setMaximum(battle.user.leader.health.max);
   userhp.setValue(battle.user.leader.health.cur);
   userhp.setToolTipText(battle.user.leader.health.cur + "/" + battle.user.leader.health.max);
   enemyhp.setMaximum(battle.enemy.leader.health.max);
   enemyhp.setValue(battle.enemy.leader.health.cur);
   enemyhp.setToolTipText(battle.enemy.leader.health.cur + "/" + battle.enemy.leader.health.max);
   userxp.setMaximum(battle.user.leader.xpNeeded());
   userxp.setValue(battle.user.leader.xp);
   userpic.setIcon(new ImageIcon(Tools.findImage(battle.user.leader)));
   enemypic.setIcon(new ImageIcon(Tools.findImage(battle.enemy.leader)));
   username.setText(battle.user.party.leader().name + " Lvl." + battle.user.leader.level);
   enemyname.setText(battle.enemy.leader.name + " Lvl." + battle.enemy.leader.level);
   userstatus.setText(battle.user.leader.status.toString());
   enemystatus.setText(battle.enemy.leader.status.toString());
   Tools.game.repaint();
 }
Ejemplo n.º 3
0
  private void initTask(String cryptoki) {

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

    task.go();

    progressBar.setMaximum(ReadCertsTask.READ_CERTS);
    timer.start();
  }
Ejemplo n.º 4
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();
    }
Ejemplo n.º 5
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());
              }
            });
      }
    }
  public acceuil() {
    f = new JFrame("Espace Liaison FTTx");
    f.setSize(700, 700);
    c = f.getContentPane();
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    f.setLocation(dim.width / 2 - f.getWidth() / 2, dim.height / 2 - f.getHeight() / 2);
    progressbar1 = new JProgressBar();
    progressbar1.setMinimum(1);
    progressbar1.setMaximum(100);

    ImageIcon icon = new ImageIcon(".\\src\\images\\icon.png");
    ImageIcon iconc = new ImageIcon(".\\src\\images\\iconc.png");

    b1 = new JButton(icon);
    b2 = new JButton(iconc);
    p1 = new JPanel(new BorderLayout());
    p2 = new JPanel(new BorderLayout());
    p3 = new JPanel();
    lhaut = new JLabel(new ImageIcon(".\\src\\images\\telecom.jpg"));

    p1.add(lhaut, BorderLayout.NORTH);
    p2.add(progressbar1, BorderLayout.NORTH);
    p3.add(b2);
    p3.add(b1);
    p2.add(p3, BorderLayout.CENTER);
    p1.add(p2, BorderLayout.CENTER);
    c.add(p1);

    b1.addActionListener(this);
    b2.addActionListener(this);
    b1.setEnabled(false);
    b2.setEnabled(false);
    f.setResizable(false);
    f.setVisible(true);
    f.pack();
    progress();
    b1.setEnabled(true);
    b2.setEnabled(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
Ejemplo n.º 7
0
    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());
         }
         });
         }
      */
    }
Ejemplo n.º 8
0
  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
          }
        });
  }
Ejemplo n.º 9
0
  /**
   * Inizialize frame components
   *
   * @throws CMSException
   * @throws FileNotFoundException
   * @throws IOException
   * @throws GeneralSecurityException
   */
  private void initComponents()
      throws CMSException, FileNotFoundException, IOException, GeneralSecurityException {

    // *********************************

    panel4 = new JPanel();
    label2 = new JLabel();
    textPane1 = new JTextPane();
    panel5 = new JPanel();
    textArea1 = new JTextArea();
    textArea2 = new JTextArea();

    progressBar = new JProgressBar();

    textPane2 = new JTextPane();
    textField1 = new JTextField();
    button1 = new JButton();
    panel6 = new JPanel();
    button2 = new JButton();
    button3 = new JButton();
    button4 = new JButton();
    GridBagConstraints gbc;
    // ======== this ========
    Container contentPane = getContentPane();
    contentPane.setLayout(new GridBagLayout());
    ((GridBagLayout) contentPane.getLayout()).columnWidths = new int[] {165, 0, 0};
    ((GridBagLayout) contentPane.getLayout()).rowHeights = new int[] {105, 50, 0};
    ((GridBagLayout) contentPane.getLayout()).columnWeights = new double[] {0.0, 1.0, 1.0E-4};
    ((GridBagLayout) contentPane.getLayout()).rowWeights = new double[] {1.0, 0.0, 1.0E-4};

    // ======== panel4 ========
    {
      panel4.setBackground(Color.white);
      panel4.setLayout(new GridBagLayout());
      ((GridBagLayout) panel4.getLayout()).columnWidths = new int[] {160, 0};
      ((GridBagLayout) panel4.getLayout()).rowHeights = new int[] {0, 0, 0};
      ((GridBagLayout) panel4.getLayout()).columnWeights = new double[] {0.0, 1.0E-4};
      ((GridBagLayout) panel4.getLayout()).rowWeights = new double[] {1.0, 1.0, 1.0E-4};

      // ---- label2 ----
      label2.setIcon(
          new ImageIcon(
              "images" + System.getProperty("file.separator") + "logo-freesigner-piccolo.png"));
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbc.insets.bottom = 5;
      panel4.add(label2, gbc);

      // ---- textPane1 ----
      textPane1.setFont(new Font("Verdana", Font.BOLD, 12));
      textPane1.setText("Lettura\ncertificati\nda token");
      textPane1.setEditable(false);
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 1;
      gbc.anchor = GridBagConstraints.NORTHWEST;
      panel4.add(textPane1, gbc);
    }
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets.bottom = 5;
    gbc.insets.right = 5;
    contentPane.add(panel4, gbc);

    // ======== panel5 ========
    {
      panel5.setBackground(Color.white);
      panel5.setLayout(new GridBagLayout());
      ((GridBagLayout) panel5.getLayout()).columnWidths = new int[] {0, 205, 0, 0};
      ((GridBagLayout) panel5.getLayout()).rowHeights = new int[] {100, 0, 30, 30, 0};
      ((GridBagLayout) panel5.getLayout()).columnWeights = new double[] {1.0, 0.0, 1.0, 1.0E-4};
      ((GridBagLayout) panel5.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0, 1.0, 1.0E-4};

      // ---- textArea1 ----
      textArea1.setFont(new Font("Verdana", Font.BOLD, 14));
      textArea1.setText("Lettura certificati da token");
      textArea1.setEditable(false);
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.gridwidth = 3;
      gbc.fill = GridBagConstraints.VERTICAL;
      gbc.insets.bottom = 5;
      panel5.add(textArea1, gbc);

      // ---- textArea2 ----
      textArea2.setFont(new Font("Verdana", Font.PLAIN, 12));
      textArea2.setText("Ricerca certificati...\n");
      textArea2.setEditable(false);
      textArea2.setColumns(30);
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 1;
      gbc.gridwidth = 3;
      gbc.fill = GridBagConstraints.BOTH;
      panel5.add(textArea2, gbc);
      progressBar.setValue(0);
      progressBar.setMaximum(1);
      progressBar.setStringPainted(true);
      progressBar.setBounds(0, 0, 300, 150);

      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 2;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbc.insets.bottom = 5;
      gbc.insets.right = 5;
      gbc.gridwidth = 3;
      panel5.add(progressBar, gbc);
    }
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets.bottom = 5;
    contentPane.add(panel5, gbc);

    // ======== panel6 ========
    {
      panel6.setBackground(Color.white);
      panel6.setLayout(new GridBagLayout());
      ((GridBagLayout) panel6.getLayout()).columnWidths = new int[] {0, 0, 0, 0};
      ((GridBagLayout) panel6.getLayout()).rowHeights = new int[] {0, 0};
      ((GridBagLayout) panel6.getLayout()).columnWeights = new double[] {1.0, 1.0, 1.0, 1.0E-4};
      ((GridBagLayout) panel6.getLayout()).rowWeights = new double[] {1.0, 1.0E-4};

      // ---- button2 ----
      button2.setText("Indietro");
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.insets.right = 5;
      button2.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {

              frame.hide();

              FreeSignerSignApplet nuovo = new FreeSignerSignApplet();
            }
          });

      // panel6.add(button2, gbc);

      // ---- button4 ----
      button4.setText("Annulla");
      gbc = new GridBagConstraints();
      gbc.gridx = 2;
      gbc.gridy = 0;
      // panel6.add(button4, gbc);
    }
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.BOTH;
    contentPane.add(panel6, gbc);
    contentPane.setBackground(Color.white);
    frame = new JFrame();
    frame.setContentPane(contentPane);
    frame.setTitle("Freesigner");
    frame.setSize(300, 150);
    frame.setResizable(false);
    frame.pack();
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getWidth()) / 2, (d.height - frame.getHeight()) / 2);

    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    timer =
        new Timer(
            10,
            new ActionListener() {

              public void actionPerformed(ActionEvent evt) {
                frame.show();
                if (task.getMessage() != null) {
                  String s = new String();
                  s = task.getMessage();
                  s = s.substring(0, Math.min(60, s.length()));

                  textArea2.setText(s + " ");
                  progressBar.setValue(task.getStatus());
                }
                if (task.isDone()) {
                  timer.stop();

                  // Finalizzo la cryptoki, onde evitare
                  // successivi errori PKCS11 "cryptoki alreadi initialized"

                  if ((task != null)) task.libFinalize();

                  ArrayList slotInfos = task.getSlotInfos();
                  if ((slotInfos == null) || slotInfos.isEmpty()) {

                    frame.show();

                    JOptionPane.showMessageDialog(
                        frame,
                        "Controllare la presenza sul sistema\n"
                            + "della libreria PKCS11 impostata.",
                        "Nessun lettore rilevato",
                        JOptionPane.WARNING_MESSAGE);

                    frame.hide();

                  } else {
                    String st = task.getCRLerror();

                    if (st.length() > 0) {
                      timer.stop();

                      JOptionPane.showMessageDialog(
                          frame,
                          "C'è stato un errore nella verifica CRL.\n" + st,
                          "Errore verifica CRL",
                          JOptionPane.ERROR_MESSAGE);
                      frame.hide();
                      FreeSignerSignApplet nuovo = new FreeSignerSignApplet();
                    }
                    if (task.getDifferentCerts() == 0) {
                      if (task.getCIr() != null) {
                        JOptionPane.showMessageDialog(
                            frame,
                            "La carta "
                                + task.getCardDescription()
                                + " nel lettore "
                                + conf.getReader()
                                + " non contiene certificati",
                            "Attenzione",
                            JOptionPane.WARNING_MESSAGE);

                      } else
                        JOptionPane.showMessageDialog(
                            frame, task.getMessage(), "Errore:", JOptionPane.ERROR_MESSAGE);
                    }

                    frame.hide();

                    // confFrame.createTreeAndTokenNodes(task.getSlotInfos());

                  }
                }
              }
            });
  }
Ejemplo n.º 10
0
  private void process() {
    int width = Integer.parseInt(xres.getText());
    int height = Integer.parseInt(yres.getText());
    boolean preserveAspect = aspect.isSelected();
    Color bg = new Color(red.getValue(), green.getValue(), blue.getValue());

    String outDir = output.getText();
    String suffix = ((String) format.getSelectedItem()).toLowerCase();
    String preText = prepend.getText();
    String appText = append.getText();

    int scaleType = -1;
    String alg = (String) algorithm.getSelectedItem();
    if (alg.equals("Smooth")) scaleType = Image.SCALE_SMOOTH;
    else if (alg.equals("Standard")) scaleType = Image.SCALE_DEFAULT;
    else if (alg.equals("Fast")) scaleType = Image.SCALE_FAST;
    else if (alg.equals("Replicate")) scaleType = Image.SCALE_REPLICATE;
    else if (alg.equals("Area averaging")) {
      scaleType = Image.SCALE_AREA_AVERAGING;
    }

    DefaultListModel model = (DefaultListModel) list.getModel();
    int size = model.size();
    progress.setValue(0);
    progress.setMaximum(4 * size);

    for (int i = 0; i < size; i++) {
      ThumbFile tf = (ThumbFile) model.elementAt(i);
      list.setSelectedValue(tf, true);
      String tail = " (" + (i + 1) + " of " + size + ")";

      progress.setValue(4 * i);
      progress.setString("Reading" + tail);

      // construct input and output filenames
      String inFile = tf.getPath();
      String outFile = outDir + SLASH + tf.getName();
      int ndx = outFile.lastIndexOf(SLASH);
      String s1 = outFile.substring(0, ndx + SLASH.length());
      String s2 = outFile.substring(ndx + SLASH.length());
      int dot_ndx = s2.lastIndexOf(".");
      if (dot_ndx >= 0) s2 = s2.substring(0, dot_ndx);

      // make the thumbnail file name
      outFile = s1 + preText + s2 + appText + "." + suffix;

      // read in the file to an image
      BufferedImage image = null;
      try {
        image = ImageIO.read(new File(inFile));
      } catch (IOException exc) {
        exc.printStackTrace();
      }

      progress.setValue(4 * i + 1);
      progress.setString("Resizing" + tail);

      // resize image
      int w, h;
      if (preserveAspect) {
        int ow = image.getWidth();
        int oh = image.getHeight();
        double oasp = (double) ow / oh;
        double tasp = (double) width / height;
        if (oasp > tasp) {
          w = width;
          h = (int) (w / oasp);
        } else {
          h = height;
          w = (int) (oasp * h);
        }
      } else {
        w = width;
        h = height;
      }
      Image resized = image.getScaledInstance(w, h, scaleType);

      progress.setValue(4 * i + 2);
      progress.setString("Painting" + tail);

      // create thumbnail
      BufferedImage thumb = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      Graphics2D g2d = thumb.createGraphics();
      g2d.setColor(bg);
      g2d.fillRect(0, 0, width, height);
      g2d.drawImage(resized, (width - w) / 2, (height - h) / 2, this);
      g2d.dispose();

      progress.setValue(4 * i + 3);
      progress.setString("Writing" + tail);

      // save thumbnail to disk
      File out = new File(outFile);
      File parent = out.getParentFile();
      if (parent != null && !parent.exists()) parent.mkdirs();
      try {
        ImageIO.write(thumb, suffix, out);
      } catch (IOException exc) {
        exc.printStackTrace();
      }
    }

    list.setSelectedIndices(new int[0]);
    progress.setValue(4 * size);
    progress.setString("Complete");
  }
Ejemplo n.º 11
0
 public void setProgressBarMax(int min) {
   progressBar.setMaximum(min);
 }
Ejemplo n.º 12
0
 public void reset() {
   progressBar.setValue(0);
   progressBar.setMinimum(0);
   progressBar.setMaximum(100);
   _stopped = false;
 }