Пример #1
0
  public static Map[] showOpenMapDialog(final JFrame owner) throws IOException {
    final JFileChooser ch = new JFileChooser();
    if (config.getFile("mapLastOpenDir") != null) {
      ch.setCurrentDirectory(config.getFile("mapLastOpenDir"));
    }
    ch.setDialogType(JFileChooser.OPEN_DIALOG);
    ch.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (ch.showOpenDialog(MainFrame.getInstance()) != JFileChooser.APPROVE_OPTION) {
      return null;
    }
    final File dir = ch.getSelectedFile();
    config.set("mapLastOpenDir", dir);
    final String[] maps = dir.list(FILTER_TILES);
    for (int i = 0; i < maps.length; ++i) {
      maps[i] = maps[i].substring(0, maps[i].length() - MapIO.EXT_TILE.length());
    }
    final JDialog dialog = new JDialog(owner, Lang.getMsg("gui.chooser"));
    dialog.setModal(true);
    dialog.setLocationRelativeTo(null);
    dialog.setLayout(new BorderLayout());

    final JList list = new JList(maps);
    final JButton btn = new JButton(Lang.getMsg("gui.chooser.Ok"));

    btn.addActionListener(
        new AbstractAction() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            if (list.getSelectedValue() != null) {
              dialog.setVisible(false);
            }
          }
        });

    dialog.add(new JScrollPane(list), BorderLayout.CENTER);
    dialog.add(btn, BorderLayout.SOUTH);
    dialog.pack();
    dialog.setVisible(true);
    dialog.dispose();

    Map[] loadedMaps = new Map[list.getSelectedIndices().length];
    for (int i = 0; i < list.getSelectedIndices().length; i++) {
      loadedMaps[i] = MapIO.loadMap(dir.getPath(), (String) list.getSelectedValues()[i]);
    }
    return loadedMaps;
  }
Пример #2
0
  public static PlatePanel createPanelDialog(
      Plate plate, HeatMapModel heatmapModel, Window ownerDialog) {
    JDialog jDialog = new JDialog(ownerDialog);

    jDialog.setTitle("PlateViewer: " + plate.getBarcode());
    Random posJitter = new Random();
    jDialog.setBounds(200 + posJitter.nextInt(100), 200 + posJitter.nextInt(100), 700, 500);

    jDialog.setLayout(new BorderLayout());

    PlatePanel platePanel = new PlatePanel(plate, heatmapModel);
    jDialog.add(platePanel, BorderLayout.CENTER);

    jDialog.setVisible(true);

    return platePanel;
  }
  protected void handleExecute() {
    ImageView view = getSelectedView();

    if (view != null) {
      ColorBarAnnotation cbar =
          (ColorBarAnnotation) view.getAnnotation(view.getSelectedPlot(), ColorBarAnnotation.ID);

      if (cbar == null) {
        cbar = new ColorBarAnnotation(view.getModel());
        view.setAnnotation(view.getSelectedPlot(), cbar.getIdentifier(), cbar);
      }

      log.finest("retrieved color bar annotation for editing");

      ColorBarAnnotationPresenter presenter = new ColorBarAnnotationPresenter(cbar);
      Container c = JOptionPane.getFrameForComponent(view);

      final JButton okButton = new JButton("OK");
      okButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              dialog.setVisible(false);
              dialog.dispose();
            }
          });

      final JButton cancelButton = new JButton("Cancel");
      cancelButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              // view.setAnnotation(safeCopy);
              // icross.setLinePaint(safeCopy.getLinePaint());
              // icross.setLineWidth(safeCopy.getLineWidth());
              // icross.setGap(safeCopy.getGap());
              // icross.setVisible(safeCopy.isVisible());

              dialog.setVisible(false);
              dialog.dispose();
            }
          });

      final JButton applyButton = new JButton("Apply");

      dialog = new JDialog(JOptionPane.getFrameForComponent(view));
      dialog.setLayout(new BorderLayout());

      Point p = c.getLocation();

      JPanel mainPanel = new JPanel();
      mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 8, 15, 8));
      mainPanel.setLayout(new BorderLayout());
      JPanel buttonPanel =
          ButtonBarFactory.buildRightAlignedBar(okButton, cancelButton, applyButton);

      mainPanel.add(presenter.getComponent(), BorderLayout.CENTER);
      mainPanel.add(buttonPanel, BorderLayout.SOUTH);

      dialog.add(mainPanel, BorderLayout.CENTER);
      dialog.pack();
      dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
      dialog.setLocation(
          (int) (p.getX() + c.getWidth() / 2f), (int) (p.getY() + c.getHeight() / 2f));
      dialog.setVisible(true);
    }
  }
Пример #4
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);
    }
  }
Пример #5
0
  /**
   * Open the config dialog, send the config update to the robot, save it for future, and refresh
   * the preview tab.
   */
  public void UpdateConfig() {
    final JDialog driver = new JDialog(mainframe, "Configure Limits", true);
    driver.setLayout(new GridBagLayout());

    final JTextField mtop = new JTextField(String.valueOf(limit_top));
    final JTextField mbottom = new JTextField(String.valueOf(limit_bottom));
    final JTextField mleft = new JTextField(String.valueOf(limit_left));
    final JTextField mright = new JTextField(String.valueOf(limit_right));

    final JTextField ptop = new JTextField(String.valueOf(paper_top));
    final JTextField pbottom = new JTextField(String.valueOf(paper_bottom));
    final JTextField pleft = new JTextField(String.valueOf(paper_left));
    final JTextField pright = new JTextField(String.valueOf(paper_right));

    final JButton cancel = new JButton("Cancel");
    final JButton save = new JButton("Save");

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 3;
    c.gridy = 0;
    driver.add(mtop, c);
    c.gridx = 3;
    c.gridy = 5;
    driver.add(mbottom, c);
    c.gridx = 0;
    c.gridy = 3;
    driver.add(mleft, c);
    c.gridx = 5;
    c.gridy = 3;
    driver.add(mright, c);

    c.gridx = 3;
    c.gridy = 1;
    driver.add(ptop, c);
    c.gridx = 3;
    c.gridy = 4;
    driver.add(pbottom, c);
    c.gridx = 1;
    c.gridy = 3;
    driver.add(pleft, c);
    c.gridx = 4;
    c.gridy = 3;
    driver.add(pright, c);

    c.gridx = 4;
    c.gridy = 6;
    driver.add(save, c);
    c.gridx = 5;
    c.gridy = 6;
    driver.add(cancel, c);

    Dimension s = ptop.getPreferredSize();
    s.width = 80;
    ptop.setPreferredSize(s);
    pbottom.setPreferredSize(s);
    pleft.setPreferredSize(s);
    pright.setPreferredSize(s);
    mtop.setPreferredSize(s);
    mbottom.setPreferredSize(s);
    mleft.setPreferredSize(s);
    mright.setPreferredSize(s);

    ActionListener driveButtons =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            if (subject == save) {
              paper_top = Float.valueOf(ptop.getText());
              paper_bottom = Float.valueOf(pbottom.getText());
              paper_right = Float.valueOf(pright.getText());
              paper_left = Float.valueOf(pleft.getText());
              limit_top = Float.valueOf(mtop.getText());
              limit_bottom = Float.valueOf(mbottom.getText());
              limit_right = Float.valueOf(mright.getText());
              limit_left = Float.valueOf(mleft.getText());
              previewPane.setMachineLimits(limit_top, limit_bottom, limit_left, limit_right);
              previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right);
              SetRecentPaperSize();
              SaveConfig();
              SendConfig();
              driver.dispose();
            }
            if (subject == cancel) {
              driver.dispose();
            }
          }
        };

    save.addActionListener(driveButtons);
    cancel.addActionListener(driveButtons);
    SendLineToRobot("M114"); // "where" command
    driver.pack();
    driver.setVisible(true);
  }
Пример #6
0
  protected void JogMotors() {
    JDialog driver = new JDialog(mainframe, "Jog Motors", true);
    driver.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    final JButton buttonAneg = new JButton("IN");
    final JButton buttonApos = new JButton("OUT");
    final JCheckBox m1i = new JCheckBox("Invert", m1invert);

    final JButton buttonBneg = new JButton("IN");
    final JButton buttonBpos = new JButton("OUT");
    final JCheckBox m2i = new JCheckBox("Invert", m2invert);

    c.gridx = 0;
    c.gridy = 0;
    driver.add(new JLabel("L"), c);
    c.gridx = 0;
    c.gridy = 1;
    driver.add(new JLabel("R"), c);

    c.gridx = 1;
    c.gridy = 0;
    driver.add(buttonAneg, c);
    c.gridx = 1;
    c.gridy = 1;
    driver.add(buttonBneg, c);

    c.gridx = 2;
    c.gridy = 0;
    driver.add(buttonApos, c);
    c.gridx = 2;
    c.gridy = 1;
    driver.add(buttonBpos, c);

    c.gridx = 3;
    c.gridy = 0;
    driver.add(m1i, c);
    c.gridx = 3;
    c.gridy = 1;
    driver.add(m2i, c);

    ActionListener driveButtons =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            if (subject == buttonApos) SendLineToRobot("D00 L100");
            if (subject == buttonAneg) SendLineToRobot("D00 L-100");
            if (subject == buttonBpos) SendLineToRobot("D00 R100");
            if (subject == buttonBneg) SendLineToRobot("D00 R-100");
            SendLineToRobot("M114");
          }
        };

    ActionListener invertButtons =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            m1invert = m1i.isSelected();
            m2invert = m2i.isSelected();

            SaveConfig();
            SendConfig();
          }
        };

    buttonApos.addActionListener(driveButtons);
    buttonAneg.addActionListener(driveButtons);

    buttonBpos.addActionListener(driveButtons);
    buttonBneg.addActionListener(driveButtons);

    m1i.addActionListener(invertButtons);
    m2i.addActionListener(invertButtons);

    SendLineToRobot("M114");
    driver.pack();
    driver.setVisible(true);
  }
Пример #7
0
  /** Open the config dialog, update the paper size, refresh the preview tab. */
  public void Drive() {
    JDialog driver = new JDialog(mainframe, "Manual Control", true);
    driver.setLayout(new GridBagLayout());

    JButton find = new JButton("FIND HOME");
    JButton home = new JButton("GO HOME");
    JButton center = new JButton("THIS IS HOME");

    JButton up1 = new JButton("Y1");
    JButton up10 = new JButton("Y10");
    JButton up100 = new JButton("Y100");

    JButton down1 = new JButton("Y-1");
    JButton down10 = new JButton("Y-10");
    JButton down100 = new JButton("Y-100");

    JButton left1 = new JButton("X-1");
    JButton left10 = new JButton("X-10");
    JButton left100 = new JButton("X-100");

    JButton right1 = new JButton("X1");
    JButton right10 = new JButton("X10");
    JButton right100 = new JButton("X100");

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 3;
    c.gridy = 0;
    driver.add(up100, c);
    c.gridx = 3;
    c.gridy = 1;
    driver.add(up10, c);
    c.gridx = 3;
    c.gridy = 2;
    driver.add(up1, c);
    c.gridx = 3;
    c.gridy = 4;
    driver.add(down1, c);
    c.gridx = 3;
    c.gridy = 5;
    driver.add(down10, c);
    c.gridx = 3;
    c.gridy = 6;
    driver.add(down100, c);

    c.gridx = 0;
    c.gridy = 3;
    driver.add(left100, c);
    c.gridx = 1;
    c.gridy = 3;
    driver.add(left10, c);
    c.gridx = 2;
    c.gridy = 3;
    driver.add(left1, c);
    c.gridx = 4;
    c.gridy = 3;
    driver.add(right1, c);
    c.gridx = 5;
    c.gridy = 3;
    driver.add(right10, c);
    c.gridx = 6;
    c.gridy = 3;
    driver.add(right100, c);

    c.gridx = 3;
    c.gridy = 3;
    driver.add(home, c);
    c.gridx = 6;
    c.gridy = 0;
    driver.add(center, c);
    c.gridx = 6;
    c.gridy = 1;
    driver.add(find, c);

    ActionListener driveButtons =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            JButton b = (JButton) subject;
            String t = b.getText();
            if (t == "GO HOME") {
              GoHome();
              SendLineToRobot("M114");
            } else if (t == "FIND HOME") {
              SendLineToRobot("G28");
            } else if (t == "THIS IS HOME") {
              SendLineToRobot("TELEPORT XO YO");
            } else {
              SendLineToRobot("G91");
              SendLineToRobot("G00 " + b.getText());
              SendLineToRobot("G90");
              SendLineToRobot("M114");
            }
          }
        };

    up1.addActionListener(driveButtons);
    up10.addActionListener(driveButtons);
    up100.addActionListener(driveButtons);
    down1.addActionListener(driveButtons);
    down10.addActionListener(driveButtons);
    down100.addActionListener(driveButtons);
    left1.addActionListener(driveButtons);
    left10.addActionListener(driveButtons);
    left100.addActionListener(driveButtons);
    right1.addActionListener(driveButtons);
    right10.addActionListener(driveButtons);
    right100.addActionListener(driveButtons);
    center.addActionListener(driveButtons);
    home.addActionListener(driveButtons);
    find.addActionListener(driveButtons);
    SendLineToRobot("M114");
    driver.pack();
    driver.setVisible(true);
  }