Ejemplo n.º 1
0
 public void files(int n, int p, int np) {
   jProgressBarFiles.setMaximum(n);
   jProgressBarConvert.setMaximum(n);
   jProgressBarNoConvert.setMaximum(n);
   jProgressBarFiles.setValue(n);
   jProgressBarConvert.setValue(p);
   jProgressBarNoConvert.setValue(np);
   jProgressBarFiles.setString((new Integer(n)).toString());
   jProgressBarConvert.setString((new Integer(p)).toString());
   jProgressBarNoConvert.setString((new Integer(np)).toString());
 }
Ejemplo n.º 2
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.º 3
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.º 4
0
  private void initTask(String cryptoki) {

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

    task.go();

    progressBar.setMaximum(ReadCertsTask.READ_CERTS);
    timer.start();
  }
 private void rebuildPassesMap(@NotNull DaemonCodeAnalyzerStatus status) {
   passes.clear();
   for (ProgressableTextEditorHighlightingPass pass : status.passStati) {
     JProgressBar progressBar = new JProgressBar(0, MAX);
     progressBar.setMaximum(MAX);
     progressBar.putClientProperty("JComponent.sizeVariant", "mini");
     JLabel percLabel = new JLabel();
     percLabel.setText(TrafficProgressPanel.MAX_TEXT);
     passes.put(pass, Pair.create(progressBar, percLabel));
   }
 }
Ejemplo n.º 6
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.º 7
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.º 8
0
  public void setTaskProcess(StatusType type, int act, int max) {
    switch (type) {
      case ALPHABETIC_BRANCH_SEARCH:
        alphabet.setMinimum(0);
        alphabet.setMaximum(max);
        alphabet.setValue(act);
        alphabet.setString(act + "/" + max);
        break;
      case BRANCH_SEARCH:
        branchen.setMinimum(0);
        branchen.setMaximum(max);
        branchen.setValue(act);
        branchen.setString(act + "/" + max);
        break;
      case BUILDING_SEARCH:
        buildings.setMinimum(0);
        buildings.setMaximum(max);
        buildings.setValue(act);
        buildings.setString(act + "/" + max);
        break;
      case DB_WRITE:
        database.setMinimum(0);
        database.setMaximum(max);
        database.setValue(act);
        database.setString(act + "/" + max);
        break;
    }

    // long freeMem = Runtime.getRuntime().freeMemory();
    long totalMem = Runtime.getRuntime().totalMemory() / (1024 * 1024);
    long maxMem = Runtime.getRuntime().maxMemory() / (1024 * 1024);

    this.memConsumption.setString(totalMem + " MB / " + maxMem + " MB");
    this.memConsumption.setMinimum(0);
    this.memConsumption.setMaximum((int) maxMem);
    this.memConsumption.setValue((int) totalMem);
  }
  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.º 10
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.º 11
0
  public ifAccountTool(ImageIcon head, String name, int usingsp, int totalsp) {
    super("AccountTool", false, false, false, false);
    setLayout(null);
    lp_layer = this.getLayeredPane();

    head = ImageProcess.scaleImage(head, 230, ImageProcess.Auto);
    head = ImageProcess.cutImage(head, 0, 0, 230, 230);

    ifAT_iclblHead = new JLabel(head);
    ifAT_iclblHead.setBorder(BorderFactory.createLineBorder(Color.BLUE));
    ifAT_iclblHead.setBounds(20, 20, 230, 230);
    ifAT_iclblHead.setBackground(Color.BLACK);
    getContentPane().add(ifAT_iclblHead);

    lblName_ftName = new Font("微軟正黑體", Font.BOLD, 20);
    ifAT_lblName = new JLabel(name, JLabel.CENTER);
    ifAT_lblName.setFont(lblName_ftName);
    ifAT_lblName.setBounds(20, 210, 230, 130);
    getContentPane().add(ifAT_lblName);

    ifAT_pbSpace = new JProgressBar();
    ifAT_pbSpace.setMaximum(totalsp);
    ifAT_pbSpace.setMinimum(0);
    ifAT_pbSpace.setValue(usingsp);
    ifAT_pbSpace.setBorderPainted(true);
    ifAT_pbSpace.setStringPainted(true);
    ifAT_pbSpace.setBounds(20, 300, 230, 20);
    getContentPane().add(ifAT_pbSpace);

    ifAT_toolbar = new ToolBar();
    ifAT_toolbar.AddTool("aEdit", null);
    ifAT_toolbar.AddTool("Plus", null);
    ifAT_toolbar.AddTool("Logout", null);
    lp_layer.setLayout(new BorderLayout());
    lp_layer.add(ifAT_toolbar, BorderLayout.SOUTH, new Integer(2550));

    setVisible(true);
    getContentPane().setBackground(Color.WHITE);
  }
 private void initProgressFrame() {
   progressFrame = new JFrame("Progress");
   JPanel mainPanel = new JPanel();
   mainPanel.setLayout(new BorderLayout());
   progressBar = new JProgressBar();
   progressBar.setMinimum(0);
   progressBar.setMaximum(100);
   progressBar.setPreferredSize(new Dimension(500, 25));
   JPanel progressPanel = new JPanel();
   progressPanel.add(progressBar);
   progressPanel.setBorder(new EmptyBorder(10, 0, 0, 0));
   mainPanel.add(progressPanel, BorderLayout.NORTH);
   textArea = new JTextArea();
   textArea.setRows(20);
   textArea.setEditable(false);
   JScrollPane scrollPane = new JScrollPane(textArea);
   scrollPane.setBorder(new EmptyBorder(10, 10, 10, 10));
   mainPanel.add(scrollPane, BorderLayout.CENTER);
   doneButton = new JButton("Done");
   doneButton.setPreferredSize(new Dimension(495, 25));
   doneButton.setEnabled(false);
   doneButton.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           doneButton.setEnabled(false);
           progressFrame.setVisible(false);
           optionsFrame.setVisible(true);
         }
       });
   JPanel donePanel = new JPanel();
   donePanel.setLayout(new BorderLayout());
   donePanel.add(doneButton, BorderLayout.CENTER);
   donePanel.setBorder(new EmptyBorder(0, 10, 10, 10));
   mainPanel.add(donePanel, BorderLayout.SOUTH);
   progressFrame.getContentPane().add(mainPanel);
   progressFrame.pack();
   progressFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
Ejemplo n.º 13
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.º 14
0
 public void reset() {
   progressBar.setValue(0);
   progressBar.setMinimum(0);
   progressBar.setMaximum(100);
   _stopped = false;
 }
Ejemplo n.º 15
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.º 16
0
 /**
  * Component initialization.
  *
  * @throws java.lang.Exception
  */
 private void jbInit() throws Exception {
   contentPane = (JPanel) getContentPane();
   contentPane.setLayout(xYLayoutServer);
   setSize(new Dimension(365, 327));
   setTitle("ProgDan® Codename Avalon: Parser Server v. 0.1");
   statusBar.setBorder(BorderFactory.createLoweredBevelBorder());
   statusBar.setText("Server stopped!");
   jPanelFiles.setBorder(BorderFactory.createEtchedBorder());
   jPanelFiles.setToolTipText("");
   jPanelFiles.setLayout(xYLayout1);
   jLabelFiles.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
   jLabelFiles.setText("Files received:");
   jLabelConverted.setText("Files converted:");
   jProgressBarConvert.setMaximum(0);
   jProgressBarConvert.setString("0");
   jProgressBarConvert.setStringPainted(true);
   jLabelNoConvert.setText("Files not converted:");
   jProgressBarNoConvert.setMaximum(0);
   jProgressBarNoConvert.setString("0");
   jProgressBarNoConvert.setStringPainted(true);
   jProgressBarNoConvert.addPropertyChangeListener(
       new FrameServer_jProgressBarNoConvert_propertyChangeAdapter(this));
   jButtonStart.setSelected(false);
   jButtonStart.setText("Start");
   jButtonStart.addActionListener(new FrameServer_jButtonStart_actionAdapter(this));
   jButtonStop.setEnabled(false);
   jButtonStop.setText("Stop");
   jButtonStop.addActionListener(new FrameServer_jButtonStop_actionAdapter(this));
   jButtonExit.setText("Exit");
   jButtonExit.addActionListener(new FrameServer_jButtonExit_actionAdapter(this));
   jButtonConfig.setText("Config");
   jButtonConfig.addActionListener(new FrameServer_jButtonConfig_actionAdapter(this));
   jLabelActiveConnections.setText("Active Connections:");
   jTextFieldConnections.setEditable(false);
   jTextFieldConnections.setText("0");
   jTextFieldConnections.setHorizontalAlignment(SwingConstants.CENTER);
   jProgressBarFiles.setMaximum(0);
   jProgressBarFiles.setString("0");
   jProgressBarFiles.setStringPainted(true);
   jButtonText.setEnabled(false);
   jButtonText.setText("...");
   jButtonText.addActionListener(new FrameServer_jButtonText_actionAdapter(this));
   jPanelLogo.setBorder(null);
   jPanelLogo.setMinimumSize(new Dimension(10, 10));
   jPanelLogo.setPreferredSize(new Dimension(10, 10));
   jPanelLogo.setLayout(null);
   jLabelTitle.setFont(new java.awt.Font("Dialog", Font.BOLD, 14));
   jLabelTitle.setText("ProgDan® Codename Avalon");
   jLabelApplication.setFont(new java.awt.Font("Dialog", Font.BOLD, 24));
   jLabelApplication.setForeground(Color.red);
   jLabelApplication.setText("Parser Server");
   jLabelRelease.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
   jLabelRelease.setForeground(Color.red);
   jLabelRelease.setText("Release 0.1 - Beta");
   jLabelCopyright.setText("Copyright 2004-2005 - ProgDan® Software");
   jPanelFiles.add(jLabelFiles, new XYConstraints(8, 5, -1, -1));
   jPanelFiles.add(jLabelNoConvert, new XYConstraints(8, 50, -1, -1));
   jPanelFiles.add(jLabelConverted, new XYConstraints(8, 28, -1, -1));
   jPanelFiles.add(jProgressBarFiles, new XYConstraints(108, 3, 160, -1));
   jPanelFiles.add(jProgressBarConvert, new XYConstraints(108, 26, 160, -1));
   jPanelFiles.add(jProgressBarNoConvert, new XYConstraints(108, 48, 160, -1));
   jPanelFiles.add(jButtonText, new XYConstraints(279, 46, -1, -1));
   contentPane.add(jTextFieldConnections, new XYConstraints(158, 118, 131, -1));
   contentPane.add(jLabelActiveConnections, new XYConstraints(45, 121, -1, -1));
   contentPane.add(jButtonExit, new XYConstraints(277, 238, 65, -1));
   contentPane.add(jButtonStart, new XYConstraints(11, 238, 65, -1));
   contentPane.add(jButtonStop, new XYConstraints(100, 238, 65, -1));
   contentPane.add(jButtonConfig, new XYConstraints(188, 238, 65, -1));
   contentPane.add(statusBar, new XYConstraints(6, 272, 344, -1));
   contentPane.add(jPanelFiles, new XYConstraints(13, 148, 327, 77));
   contentPane.add(jPanelLogo, new XYConstraints(13, 15, 112, 96));
   contentPane.add(jLabelTitle, new XYConstraints(141, 14, -1, -1));
   contentPane.add(jLabelApplication, new XYConstraints(165, 40, -1, -1));
   contentPane.add(jLabelRelease, new XYConstraints(250, 66, -1, -1));
   contentPane.add(jLabelCopyright, new XYConstraints(137, 95, -1, -1));
 }
Ejemplo n.º 17
0
  @SuppressWarnings("deprecation")
  @Override
  public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("Выбрать")) {
      JFileChooser fileopen = new JFileChooser();
      int ret = fileopen.showDialog(null, "Открыть файл");
      file = fileopen.getSelectedFile();
      label.setText(file.getName());
    }
    if (ae.getActionCommand().equals("Послать")) {
      ou.setWayOfFile(file.getAbsolutePath());
      ou.setNameOfFile(file.getName());
      ou.setSizeOfFile(file.length());
      progressBar.setMaximum((int) file.length());
      b1.setVisible(false);
      b4.setEnabled(false);
      b2.setEnabled(false);
      ou.start(1);
    }
    if (ae.getActionCommand().equals("Соединить")) {
      ou.start(0);
      ou.stop();
    }
    if (ae.getActionCommand().equals("Разорвать")) {
      ou.start(2);
      ou.stop();
    }
    if (ae.getActionCommand().equals("Настройки")) {

      final JDialog jd = new JDialog(fr, "Настройки", true);

      JLabel label1 = new JLabel("COM порт");
      JLabel label2 = new JLabel("Скорость");
      JLabel label3 = new JLabel("Биты данных");
      JLabel label4 = new JLabel("Стоп биты");
      JLabel label5 = new JLabel("Четность");

      ArrayList<String> list = new ArrayList<String>();

      jd.setLayout(gbl);

      Enumeration portList = CommPortIdentifier.getPortIdentifiers();
      while (portList.hasMoreElements()) {
        CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
        list.add(portId.getName());
      }
      System.out.println(stopbits);
      final String[] speed1 = {"9600", "14400", "19200", "38400", "57600", "115200"};
      final String[] databits1 = {"5", "6", "7", "8"};
      final String[] stopbits1 = {"1", "1.5", "2"};
      String[] parity1 = {"нет", "нечет", "чет", "'1'", "'0'"};
      final JComboBox comboBox1 = new JComboBox(list.toArray());
      Iterator<String> it = list.iterator();
      int elem = 0;

      port = con.getPortNumber();
      speed = con.getSpeed();
      databits = con.getDatabits();
      stopbits = con.getStopBits();
      parity = con.getParity();

      while (it.hasNext()) {
        if (it.next().equals(port)) {

          comboBox1.setSelectedIndex(elem);
        }
        elem++;
      }
      final JComboBox comboBox2 = new JComboBox(speed1);
      for (int i = 0; i < speed1.length; i++) {
        if (speed1[i].equals(Integer.toString(speed))) {
          comboBox2.setSelectedIndex(i);
        }
      }

      final JComboBox comboBox3 = new JComboBox(databits1);
      for (int i = 0; i < databits1.length; i++) {
        if (databits1[i].equals(Integer.toString(databits))) {
          comboBox3.setSelectedIndex(i);
        }
      }

      final JComboBox comboBox4 = new JComboBox(stopbits1);
      for (int i = 0; i < stopbits1.length; i++) {
        if (stopbits == 1) {
          comboBox4.setSelectedIndex(0);
        }
        if (stopbits == 3) {
          comboBox4.setSelectedIndex(1);
        }
        if (stopbits == 2) {
          comboBox4.setSelectedIndex(2);
        }
      }
      final JComboBox comboBox5 = new JComboBox(parity1);
      for (int i = 0; i < 5; i++) {
        if (parity == i) {
          comboBox5.setSelectedIndex(i);
        }
      }

      JButton but = new JButton("OK");
      JButton but1 = new JButton("Подключиться к порту");

      locationX = (screenSize.width - 270) / 2;
      locationY = (screenSize.height - 300) / 2;
      jd.setBounds(locationX, locationY, 300, 270);

      ActionListener actionListener =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              if (e.getActionCommand().equals("comboBoxChanged")) {
                if ((JComboBox) e.getSource() == comboBox1) {
                  JComboBox box = (JComboBox) e.getSource();
                  port = (String) box.getSelectedItem();
                }
                if ((JComboBox) e.getSource() == comboBox2) {
                  JComboBox box = (JComboBox) e.getSource();
                  speed = Integer.parseInt((String) box.getSelectedItem());
                }
                if ((JComboBox) e.getSource() == comboBox3) {
                  JComboBox box = (JComboBox) e.getSource();
                  databits = Integer.parseInt((String) box.getSelectedItem());
                }
                if ((JComboBox) e.getSource() == comboBox4) {
                  JComboBox box = (JComboBox) e.getSource();
                  if ((String) box.getSelectedItem() == "1") {
                    stopbits = 1;
                  }
                  if ((String) box.getSelectedItem() == "2") {
                    stopbits = 2;
                  }
                  if ((String) box.getSelectedItem() == "1.5") {
                    stopbits = 3;
                  }
                }
                if ((JComboBox) e.getSource() == comboBox5) {
                  String setter;
                  JComboBox box = (JComboBox) e.getSource();
                  if ((String) box.getSelectedItem() == "нет") {
                    parity = 0;
                  }
                  if ((String) box.getSelectedItem() == "нечет") {
                    parity = 1;
                  }
                  if ((String) box.getSelectedItem() == "чет") {
                    parity = 2;
                  }
                  if ((String) box.getSelectedItem() == "'1'") {
                    parity = 3;
                  }
                  if ((String) box.getSelectedItem() == "'0'") {
                    parity = 4;
                  }
                }
              }
              if (e.getActionCommand().equals("OK")) {
                con.setPortParam(speed, databits, stopbits, parity, port);
                jd.setVisible(false);
              }

              if (e.getActionCommand().equals("Подключиться к порту")) {
                con.setPortParam(speed, databits, stopbits, parity, port);
                con.portConnect(port);
                ou = new Output(con, form);
                in = new Input(con, ou, form);
                //				        final JDialog jd1 = new JDialog(jd,"Сообщение",true);
                //				        GridBagLayout gbl=new GridBagLayout();
                //						jd1.setLayout(gbl);
                //				        JLabel label6 = new JLabel("Подключение выполнено");
                //				        jd1.add(label6);
                //				        locationX = (screenSize.width - 100) / 2;
                //				        locationY = (screenSize.height - 100) / 2;
                //				        jd1.setBounds(locationX, locationY, 180, 120);
                //				        jd1.show();
                JOptionPane optionPane = new JOptionPane();
                optionPane.setMessage("Подключение выполнено");
                optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
                JDialog dialog = optionPane.createDialog("Cообщение");
                dialog.show();
                b3.setEnabled(true);
                jd.setVisible(false);
              }
            }
          };

      comboBox1.addActionListener(actionListener);
      comboBox2.addActionListener(actionListener);
      comboBox3.addActionListener(actionListener);
      comboBox4.addActionListener(actionListener);
      comboBox5.addActionListener(actionListener);
      but.addActionListener(actionListener);
      but1.addActionListener(actionListener);

      gbc.insets = new Insets(10, 10, 0, 0);
      gbc.gridy = 1;
      gbc.gridwidth = 1;
      gbc.gridx = 1;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbl.setConstraints(label1, gbc);

      gbc.gridy = 2;
      gbl.setConstraints(label2, gbc);

      gbc.gridy = 3;
      gbl.setConstraints(label3, gbc);

      gbc.gridy = 4;
      gbl.setConstraints(label4, gbc);

      gbc.gridy = 5;
      gbl.setConstraints(label5, gbc);

      gbc.insets = new Insets(10, 20, 0, 0);
      gbc.gridy = 1;
      gbc.gridwidth = 1;
      gbc.gridx = 2;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbl.setConstraints(comboBox1, gbc);

      gbc.gridy = 2;
      gbl.setConstraints(comboBox2, gbc);

      gbc.gridy = 3;
      gbl.setConstraints(comboBox3, gbc);

      gbc.gridy = 4;
      gbl.setConstraints(comboBox4, gbc);

      gbc.gridy = 5;
      gbl.setConstraints(comboBox5, gbc);

      gbc.insets = new Insets(10, 10, 10, 0);
      gbc.gridy = 6;
      gbc.gridwidth = 1;
      gbc.gridx = 2;
      gbl.setConstraints(but, gbc);

      gbc.insets = new Insets(10, 10, 10, 0);
      gbc.gridx = 1;
      gbl.setConstraints(but1, gbc);

      jd.add(label1);
      jd.add(label2);
      jd.add(label3);
      jd.add(label4);
      jd.add(label5);
      jd.add(comboBox1);
      jd.add(comboBox2);
      jd.add(comboBox3);
      jd.add(comboBox4);
      jd.add(comboBox5);
      jd.add(but);
      jd.add(but1);
      jd.show();
    }
    if (ae.getActionCommand().equals("О программе")) {
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      int locationX = (screenSize.width - 100) / 2;
      int locationY = (screenSize.height - 100) / 2;
      final JDialog jd2 = new JDialog();
      GridBagLayout gbl = new GridBagLayout();
      jd2.setLayout(gbl);
      JLabel label6 = new JLabel("Курсовая работа по курсу 'Сетевые технологии'");
      gbc.fill = GridBagConstraints.CENTER;
      gbc.insets = new Insets(0, 0, 0, 0);
      gbc.gridy = 1;
      gbc.gridx = 1;
      gbl.setConstraints(label6, gbc);
      jd2.add(label6);

      JLabel label7 = new JLabel("Шевченко П.А.(ИУ5-74) и Федоров Д.Б.(ИУ5-79)");
      gbc.gridy = 2;
      gbc.gridx = 1;
      gbl.setConstraints(label7, gbc);
      jd2.add(label7);

      JLabel label8 = new JLabel("2011 г.");
      gbc.gridy = 3;
      gbc.gridx = 1;
      gbl.setConstraints(label8, gbc);
      jd2.add(label8);
      jd2.setBounds(locationX, locationY, 500, 120);
      jd2.show();
    }
    if (ae.getActionCommand().equals("Выход")) {
      System.exit(0);
    }
  }
 /**
  * Set the maxium limit, then show and reset the progress bar.
  *
  * @param max the maximum limit of the progress bar.
  */
 private void setProgressBarMax(final int max) {
   progressBar.setMaximum(max);
   resetProgressBar();
 }
Ejemplo n.º 19
0
 public void setProgressBarMax(int min) {
   progressBar.setMaximum(min);
 }
Ejemplo n.º 20
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());

                  }
                }
              }
            });
  }