示例#1
1
  // --------------------------------actionHost---------------------------------
  private void actionHost() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    JFileChooser oFC = new JFileChooser(DEFAULT_MAP_DIRECTORY);
    int nReturn = oFC.showOpenDialog(frame);

    if (nReturn == JFileChooser.CANCEL_OPTION) {
      return;
    }

    int nPort = Integer.parseInt((String) (DialogManager.show(DialogManager.HOST, frame)));

    JDialog dlgBox = (JDialog) (DialogManager.show(DialogManager.WAITING_FOR_CONN, frame));
    dlgBox.pack();
    try {
      oConn.host(nPort);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(frame, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    dlgBox.setVisible(false);
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();

    try {
      oMap.loadMap(oFC.getSelectedFile());
      oConn.send("loadmap", oFC.getName(oFC.getSelectedFile()));
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }
示例#2
0
 public char[] askPassword() {
   char[] password = null;
   final JDialog dlg = new JDialog(frm, "Password", true);
   final JPasswordField jpf = new JPasswordField(15);
   final JButton[] btns = {new JButton("Enter"), new JButton("Cancel")};
   for (int i = 0; i < btns.length; i++) {
     btns[i].addActionListener(
         new ActionListener() {
           public void actionPerformed(ActionEvent e) {
             dlg.setVisible(false);
           }
         });
   }
   Object[] prts = new Object[] {"Please input a password:"******"Invalid password, passwords must be " + PASSWORD_MIN + " characters long");
     System.exit(1);
   }
   return password;
 }
  /*
   * The following method creates the color chooser dialog box
   */
  public void createColorDialog() {
    colorDialog = new JDialog(this, new String("Choose a color"), true);
    colorDialog.getContentPane().add(createColorPicker(), BorderLayout.CENTER);

    JButton okButton = new JButton("OK");

    // This class is used to create a special ActionListener for
    //    the ok button
    class ButtonListener implements ActionListener {
      /*
       * This method is called whenever the ok button is clicked
       */
      public void actionPerformed(ActionEvent event) {
        currentChoice.changeColor(color_panel.getColor());
        currentChoice.repaint();
        fontColor = color_panel.getColor();
        colorDialog.hide();
      } // end actionPerformed method
    }
    ActionListener listener = new ButtonListener();
    okButton.addActionListener(listener);

    // Add the four font control panels to one big panel using
    //  a grid layout
    JPanel buttonPanel = new JPanel();

    buttonPanel.add(okButton);

    // Add the button panel to the content pane of the ColorDialogue
    colorDialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH);

    colorDialog.pack();
  }
示例#4
0
  static void tell(String question, String btnText) {
    final JDialog d = new JDialog();
    d.setLocationRelativeTo(null);
    JPanel bpane = new JPanel(new FlowLayout());
    JLabel l = new JLabel(question);

    JPanel cp = (JPanel) d.getContentPane();

    cp.setLayout(new FlowLayout());
    cp.add(l, BorderLayout.CENTER);
    cp.add(bpane, BorderLayout.SOUTH);

    JButton b1 = new JButton("OK");
    bpane.add(b1);

    d.pack();

    d.setVisible(true);

    b1.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            ans = ((JButton) e.getSource()).getText();
            d.dispose();
          }
        });
  }
 /** Show the filter dialog */
 public void showDialog() {
   empty_border = new EmptyBorder(5, 5, 0, 5);
   indent_border = new EmptyBorder(5, 25, 5, 5);
   include_panel =
       new ServiceFilterPanel("Include messages based on target service:", filter_include_list);
   exclude_panel =
       new ServiceFilterPanel("Exclude messages based on target service:", filter_exclude_list);
   status_box = new JCheckBox("Filter messages based on status:");
   status_box.addActionListener(this);
   status_active = new JRadioButton("Active messages only");
   status_active.setSelected(true);
   status_active.setEnabled(false);
   status_complete = new JRadioButton("Complete messages only");
   status_complete.setEnabled(false);
   status_group = new ButtonGroup();
   status_group.add(status_active);
   status_group.add(status_complete);
   if (filter_active || filter_complete) {
     status_box.setSelected(true);
     status_active.setEnabled(true);
     status_complete.setEnabled(true);
     if (filter_complete) {
       status_complete.setSelected(true);
     }
   }
   status_options = new JPanel();
   status_options.setLayout(new BoxLayout(status_options, BoxLayout.Y_AXIS));
   status_options.add(status_active);
   status_options.add(status_complete);
   status_options.setBorder(indent_border);
   status_panel = new JPanel();
   status_panel.setLayout(new BorderLayout());
   status_panel.add(status_box, BorderLayout.NORTH);
   status_panel.add(status_options, BorderLayout.CENTER);
   status_panel.setBorder(empty_border);
   ok_button = new JButton("Ok");
   ok_button.addActionListener(this);
   cancel_button = new JButton("Cancel");
   cancel_button.addActionListener(this);
   buttons = new JPanel();
   buttons.setLayout(new FlowLayout());
   buttons.add(ok_button);
   buttons.add(cancel_button);
   panel = new JPanel();
   panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
   panel.add(include_panel);
   panel.add(exclude_panel);
   panel.add(status_panel);
   panel.add(buttons);
   dialog = new JDialog();
   dialog.setTitle("SOAP Monitor Filter");
   dialog.setContentPane(panel);
   dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
   dialog.setModal(true);
   dialog.pack();
   Dimension d = dialog.getToolkit().getScreenSize();
   dialog.setLocation((d.width - dialog.getWidth()) / 2, (d.height - dialog.getHeight()) / 2);
   ok_pressed = false;
   dialog.show();
 }
 public JDialog createFileChooserDialog(JFileChooser jfilechooser, String s, Container container) {
   JDialog jdialog = new JDialog(frame, s, true);
   jdialog.setDefaultCloseOperation(2);
   jdialog.add(jfilechooser);
   jdialog.pack();
   jdialog.setLocationRelativeTo(container);
   return jdialog;
 }
  private void initComponents() {

    final SimpleDateFormat dateFrmt = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
    panel = new JPanel();
    panel.setLayout(new BorderLayout());
    JPanel north = new JPanel();
    north.setLayout(new BoxLayout(north, BoxLayout.X_AXIS));
    JLabel dateLbl = new JLabel("検査日:");
    north.add(dateLbl);
    dateFld = new JTextField(10);
    dateFld.setMaximumSize(dateFld.getPreferredSize());
    dateFld.setEditable(false);
    dateFld.setText(dateFrmt.format(new Date()));
    north.add(dateFld);
    north.add(Box.createHorizontalGlue());
    editCheck = new JCheckBox("項目編集");
    north.add(editCheck);
    panel.add(north, BorderLayout.NORTH);

    JPanel south = new JPanel();
    south.setLayout(new FlowLayout());
    deleteBtn = new JButton("削除", deleteIcon);
    deleteBtn.setEnabled(false);
    south.add(deleteBtn);
    closeBtn = new JButton("閉じる", closeIcon);
    south.add(closeBtn);
    saveBtn = new JButton("保存", saveIcon);
    south.add(saveBtn);
    panel.add(south, BorderLayout.SOUTH);

    setTable = new JTable();
    JScrollPane scroll = new JScrollPane(setTable);
    centerPanel = new JPanel();
    centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.X_AXIS));
    centerPanel.add(scroll);
    panel.add(centerPanel, BorderLayout.CENTER);

    templateTable = new JTable();
    templateTable.setToolTipText("DnDで左の施設内検査項目テーブルに追加してください。");
    rtScroll = new JScrollPane(templateTable);
    Dimension d = new Dimension(200, 200);
    rtScroll.setPreferredSize(d);
    d = new Dimension(200, Integer.MAX_VALUE);
    rtScroll.setMaximumSize(d);

    dialog = new JDialog();
    String title = ClientContext.getFrameTitle("院内検査項目追加");
    dialog.setTitle(title);
    dialog.setModal(true);
    dialog.setContentPane(panel);
    ClientContext.setDolphinIcon(dialog);

    dialog.pack();
    dialog.setLocationRelativeTo(chart.getFrame());
  }
示例#8
0
  public DatePicker(JFrame parent) {
    d = new JDialog();
    d.setModal(true);
    String[] header = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"};
    JPanel p1 = new JPanel(new GridLayout(7, 7));
    p1.setPreferredSize(new Dimension(430, 120));

    for (int x = 0; x < button.length; x++) {
      final int selection = x;
      button[x] = new JButton();
      button[x].setFocusPainted(false);
      button[x].setBackground(Color.white);
      if (x > 6)
        button[x].addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
                day = button[selection].getActionCommand();
                d.dispose();
              }
            });
      if (x < 7) {
        button[x].setText(header[x]);
        button[x].setForeground(Color.red);
      }
      p1.add(button[x]);
    }
    JPanel p2 = new JPanel(new GridLayout(1, 3));
    JButton previous = new JButton("<< Previous");
    previous.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            month--;
            displayDate();
          }
        });
    p2.add(previous);
    p2.add(l);
    JButton next = new JButton("Next >>");
    next.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            month++;
            displayDate();
          }
        });
    p2.add(next);
    d.add(p1, BorderLayout.CENTER);
    d.add(p2, BorderLayout.SOUTH);
    d.pack();
    d.setLocationRelativeTo(parent);
    displayDate();
    d.setVisible(true);
  }
 public void actionPerformed(ActionEvent evt) {
   JDialog parent = GUIUtilities.getParentDialog(ColorWellButton.this);
   JDialog dialog;
   if (parent != null) {
     dialog = new ColorPickerDialog(parent, jEdit.getProperty("colorChooser.title"), true);
   } else {
     dialog =
         new ColorPickerDialog(
             JOptionPane.getFrameForComponent(ColorWellButton.this),
             jEdit.getProperty("colorChooser.title"),
             true);
   }
   dialog.pack();
   dialog.setVisible(true);
 }
示例#10
0
  public void runCalculatorDialog(MouseEvent e) {
    if (calculatorDialog == null) {
      JFrame frame = null;
      Container container = getTopLevelAncestor();

      if (container instanceof JFrame) {
        frame = (JFrame) container;
      }

      calculatorDialog = new JDialog(frame, "Rechner", true);
      calculator = new Calculator();
      calculator.getOKButton().addActionListener(this);
      calculatorDialog.getContentPane().add(calculator);
      calculatorDialog.pack();
    }

    // Set calculator's init value

    Money money = getValue();

    if (money != null) {
      calculator.setValue(money.getValue());
    } else {
      calculator.setValue(0.0);
    }

    // calculate POP (point of presentation)

    Point point = ((JComponent) e.getSource()).getLocationOnScreen();
    int x = point.x + e.getX();
    int y = point.y + e.getY();

    // ensure that it does not exceed the screen limits

    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension dim = calculatorDialog.getPreferredSize();
    if (x + dim.width >= screenDim.width) {
      x = screenDim.width - dim.width - 1;
    }
    if (y + dim.height >= screenDim.height) {
      y = screenDim.height - dim.height - 1;
    }

    // make it visible at wanted location

    calculatorDialog.setLocation(x, y);
    calculatorDialog.show();
  }
示例#11
0
  public static JDialog createDialog(JComponent parent, OWLEditorKit editorKit) {
    JFrame parentFrame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, parent);
    final JDialog dialog = new JDialog(parentFrame, "Search", Dialog.ModalityType.MODELESS);

    final SearchDialogPanel searchDialogPanel = new SearchDialogPanel(editorKit);
    searchDialogPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

    searchDialogPanel
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "CLOSE_DIALOG");
    searchDialogPanel
        .getActionMap()
        .put(
            "CLOSE_DIALOG",
            new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent e) {
                dialog.setVisible(false);
              }
            });

    searchDialogPanel
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "CLOSE_DIALOG_WITH_ENTER");
    searchDialogPanel
        .getActionMap()
        .put(
            "CLOSE_DIALOG_WITH_ENTER",
            new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent e) {
                dialog.setVisible(false);
                searchDialogPanel.selectEntity();
              }
            });

    dialog.setContentPane(searchDialogPanel);
    dialog.setResizable(true);
    dialog.pack();
    dialog.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowOpened(WindowEvent e) {
            searchDialogPanel.searchField.requestFocusInWindow();
          }
        });
    return dialog;
  }
示例#12
0
 /** Create and show the gui */
 public void showDialog() {
   if (dialog == null) {
     JFrame parentFrame = persistenceManager.getIdv().getIdvUIManager().getFrame();
     dialog = new JDialog(parentFrame, "Loading Bundle");
     if (dialogTitle != null) {
       dialog.setTitle("Loading Bundle: " + dialogTitle);
     }
     dialog.getContentPane().add(contents);
   }
   dialog.pack();
   Point center = GuiUtils.getLocation(null);
   if (persistenceManager.getIdv().okToShowWindows()) {
     dialog.setLocation(20, 20);
     dialog.setVisible(true);
   }
 }
示例#13
0
  public void setPanel(Parameters pp, String s) {
    JPanel buttonsPanel = new JPanel();
    okButton = new JButton("确定");
    okButton.addActionListener(this);

    dialog = new JDialog(this, s + " 参数选择", true);

    Container contentPane = getContentPane();
    Container dialogContentPane = dialog.getContentPane();

    dialogContentPane.add(pp, BorderLayout.CENTER);
    dialogContentPane.add(buttonsPanel, BorderLayout.SOUTH);
    dialog.pack();
    buttonsPanel.add(okButton);
    dialog.setLocation(50, 330);
    dialog.show();
  }
  /**
   * Show tracker
   *
   * @param parent GUI parent widget
   */
  public final void show(final Component parent) {
    Frame frame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);

    dialog.getContentPane().setLayout(new BorderLayout());

    label = new JLabel(START_HTML + labelText + END_HTML);

    JPanel labelPanel = new JPanel();
    labelPanel.setLayout(new BorderLayout());
    labelPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    labelPanel.add(label, BorderLayout.CENTER);

    dialog.getContentPane().add(labelPanel, BorderLayout.CENTER);

    dialog.pack();
    Windows.centerOnScreen(dialog);
    dialog.show();
  }
示例#15
0
  @Override
  protected void fireActionPerformed(ActionEvent event) {
    try {
      this.setSelected(true);

      // create the dialog if this has not been done yet.
      if (this.dialog == null) {
        // Get the top level ancestor as parent for the new dialog.
        // This ensures that on Mac OS X the global menu bar remains
        // visible while the dialog is open.
        final Container parent = this.getTopLevelAncestor();
        dialog =
            JColorChooser.createDialog(
                parent,
                colorChooserTitle,
                true, // modal
                colorChooser,
                this, // OK button handler
                null); // no CANCEL button handler
        dialog.pack();
        dialog.setResizable(false);
      }

      // show the dialog
      colorChooser.setColor(color);
      dialog.setVisible(true);

      /* A simpler option that is displaying the ugly preview panel:
      Color newColor = JColorChooser.showDialog(this.getTopLevelAncestor(),
              colorChooserTitle, color);
      if (newColor != null){
          // only set color and fire an event when user did not cancel.
          this.setColor(newColor);
          super.fireActionPerformed(event);
      }*/
    } catch (Exception e) {
    } finally {
      this.setSelected(false);
    }
  }
示例#16
0
  private void mouseClicked_searchSource() {

    SourceSearchPanel ssp = new SourceSearchPanel();

    Point p = getLocation();
    orgSearchDialog.setLocation(p.x + 50, p.y + 50);

    ssp.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            Source source = (Source) e.getSource();

            setToAddress(source.getName() + " <" + source.getEmail() + ">");
            orgSearchDialog.dispose();
          }
        });

    orgSearchDialog.getContentPane().add(ssp);
    orgSearchDialog.pack();
    orgSearchDialog.setVisible(true);
  }
示例#17
0
  protected void populateDialog(JDialog dlg) {
    dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dlg.setResizable(false);
    dlg.setSize(new Dimension(350, 135));
    dlg.setTitle("New TurboVNC Connection");

    dlg.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            if (VncViewer.nViewers == 1) {
              if (cc.viewer instanceof VncViewer) {
                ((VncViewer) cc.viewer).exit(1);
              }
            } else {
              ret = false;
              endDialog();
            }
          }
        });

    dlg.getContentPane().setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.LINE_START;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.gridheight = 1;
    gbc.insets = new Insets(0, 0, 0, 0);
    gbc.ipadx = 0;
    gbc.ipady = 0;
    gbc.weightx = 1;
    gbc.weighty = 1;

    dlg.getContentPane().add(topPanel, gbc);
    dlg.getContentPane().add(buttonPanel);
    dlg.pack();
  }
示例#18
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);
  }
示例#19
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);
  }
示例#20
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);
  }
示例#21
0
文件: APropos.java 项目: sipi/memento
    @Override
    public void actionPerformed(ActionEvent e) {

      licence_text =
          new String(
              "This program is free software: you can redistribute it and/or modify\n"
                  + "it under the terms of the GNU General Public License as published by\n"
                  + "the Free Software Foundation, either version 3 of the License, or\n"
                  + "(at your option) any later version.\n"
                  + "\n"
                  + "This program is distributed in the hope that it will be useful,\n"
                  + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
                  + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
                  + "GNU General Public License for more details.\n"
                  + "\n"
                  + "You should have received a copy of the GNU General Public License\n"
                  + "along with this program.  If not, see <http://www.gnu.org/licenses/>.\n"
                  + "\n\n\n");

      try {
        InputStream ips = new FileInputStream(getClass().getResource("COPYING").getPath());
        InputStreamReader ipsr = new InputStreamReader(ips);
        BufferedReader br = new BufferedReader(ipsr);

        String line;
        while ((line = br.readLine()) != null) {
          licence_text += line + '\n';
        }
        br.close();
      } catch (Exception e1) {
      }

      Dimension dimension = new Dimension(600, 400);

      JDialog licence = new JDialog(memento, "Licence");

      JTextPane text_pane = new JTextPane();
      text_pane.setEditable(false);
      text_pane.setPreferredSize(dimension);
      text_pane.setSize(dimension);

      StyledDocument doc = text_pane.getStyledDocument();

      Style justified =
          doc.addStyle(
              "justified",
              StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE));
      StyleConstants.setAlignment(justified, StyleConstants.ALIGN_JUSTIFIED);

      try {
        doc.insertString(0, licence_text, justified);
      } catch (BadLocationException ble) {
        System.err.println("Couldn't insert initial text into text pane.");
      }
      Style logicalStyle = doc.getLogicalStyle(0);
      doc.setParagraphAttributes(0, licence_text.length(), justified, false);
      doc.setLogicalStyle(0, logicalStyle);

      JScrollPane paneScrollPane = new JScrollPane(text_pane);
      paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      paneScrollPane.setPreferredSize(dimension);
      paneScrollPane.setMinimumSize(dimension);

      JPanel pan = new JPanel();
      LayoutManager layout = new BorderLayout();
      pan.setLayout(layout);

      pan.add(new JScrollPane(paneScrollPane), BorderLayout.CENTER);
      JButton close = new JButton("Fermer");
      close.addActionListener(new ButtonCloseActionListener(licence));
      JPanel button_panel = new JPanel();
      FlowLayout button_panel_layout = new FlowLayout(FlowLayout.RIGHT, 20, 20);
      button_panel.setLayout(button_panel_layout);

      button_panel.add(close);
      pan.add(button_panel, BorderLayout.SOUTH);

      licence.add(pan);

      licence.pack();
      licence.setLocationRelativeTo(memento);
      licence.setVisible(true);
    }
示例#22
0
  public static boolean showLicensing() {
    if (Config.getLicenseResource() == null) return true;
    ClassLoader cl = Main.class.getClassLoader();
    URL url = cl.getResource(Config.getLicenseResource());
    if (url == null) return true;

    String license = null;
    try {
      URLConnection con = url.openConnection();
      int size = con.getContentLength();
      byte[] content = new byte[size];
      InputStream in = new BufferedInputStream(con.getInputStream());
      in.read(content);
      license = new String(content);
    } catch (IOException ioe) {
      Config.trace("Got exception when reading " + Config.getLicenseResource() + ": " + ioe);
      return false;
    }

    // Build dialog
    JTextArea ta = new JTextArea(license);
    ta.setEditable(false);
    final JDialog jd = new JDialog(_installerFrame, true);
    Container comp = jd.getContentPane();
    jd.setTitle(Config.getLicenseDialogTitle());
    comp.setLayout(new BorderLayout(10, 10));
    comp.add(new JScrollPane(ta), "Center");
    Box box = new Box(BoxLayout.X_AXIS);
    box.add(box.createHorizontalStrut(10));
    box.add(new JLabel(Config.getLicenseDialogQuestionString()));
    box.add(box.createHorizontalGlue());
    JButton acceptButton = new JButton(Config.getLicenseDialogAcceptString());
    JButton exitButton = new JButton(Config.getLicenseDialogExitString());
    box.add(acceptButton);
    box.add(box.createHorizontalStrut(10));
    box.add(exitButton);
    box.add(box.createHorizontalStrut(10));
    jd.getRootPane().setDefaultButton(acceptButton);
    Box box2 = new Box(BoxLayout.Y_AXIS);
    box2.add(box);
    box2.add(box2.createVerticalStrut(5));
    comp.add(box2, "South");
    jd.pack();

    final boolean accept[] = new boolean[1];
    acceptButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            accept[0] = true;
            jd.hide();
            jd.dispose();
          }
        });

    exitButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            accept[0] = false;
            jd.hide();
            jd.dispose();
          }
        });

    // Apply any defaults the user may have, constraining to the size
    // of the screen, and default (packed) size.
    Rectangle size = new Rectangle(0, 0, 500, 300);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    size.width = Math.min(screenSize.width, size.width);
    size.height = Math.min(screenSize.height, size.height);
    // Center the window
    jd.setBounds(
        (screenSize.width - size.width) / 2,
        (screenSize.height - size.height) / 2,
        size.width,
        size.height);

    // Show dialog
    jd.show();

    return accept[0];
  }
  protected boolean exportApplicationPrompt() throws IOException, SketchException {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(Box.createVerticalStrut(6));

    // Box panel = Box.createVerticalBox();

    // Box labelBox = Box.createHorizontalBox();
    //    String msg = "<html>Click Export to Application to create a standalone, " +
    //      "double-clickable application for the selected plaforms.";

    //    String msg = "Export to Application creates a standalone, \n" +
    //      "double-clickable application for the selected plaforms.";
    String line1 = "Export to Application creates double-clickable,";
    String line2 = "standalone applications for the selected plaforms.";
    JLabel label1 = new JLabel(line1, SwingConstants.CENTER);
    JLabel label2 = new JLabel(line2, SwingConstants.CENTER);
    label1.setAlignmentX(Component.LEFT_ALIGNMENT);
    label2.setAlignmentX(Component.LEFT_ALIGNMENT);
    //    label1.setAlignmentX();
    //    label2.setAlignmentX(0);
    panel.add(label1);
    panel.add(label2);
    int wide = label2.getPreferredSize().width;
    panel.add(Box.createVerticalStrut(12));

    final JCheckBox windowsButton = new JCheckBox("Windows");
    // windowsButton.setMnemonic(KeyEvent.VK_W);
    windowsButton.setSelected(Preferences.getBoolean("export.application.platform.windows"));
    windowsButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            Preferences.setBoolean(
                "export.application.platform.windows", windowsButton.isSelected());
          }
        });

    final JCheckBox macosxButton = new JCheckBox("Mac OS X");
    // macosxButton.setMnemonic(KeyEvent.VK_M);
    macosxButton.setSelected(Preferences.getBoolean("export.application.platform.macosx"));
    macosxButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            Preferences.setBoolean("export.application.platform.macosx", macosxButton.isSelected());
          }
        });

    final JCheckBox linuxButton = new JCheckBox("Linux");
    // linuxButton.setMnemonic(KeyEvent.VK_L);
    linuxButton.setSelected(Preferences.getBoolean("export.application.platform.linux"));
    linuxButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            Preferences.setBoolean("export.application.platform.linux", linuxButton.isSelected());
          }
        });

    JPanel platformPanel = new JPanel();
    // platformPanel.setLayout(new BoxLayout(platformPanel, BoxLayout.X_AXIS));
    platformPanel.add(windowsButton);
    platformPanel.add(Box.createHorizontalStrut(6));
    platformPanel.add(macosxButton);
    platformPanel.add(Box.createHorizontalStrut(6));
    platformPanel.add(linuxButton);
    platformPanel.setBorder(new TitledBorder("Platforms"));
    // Dimension goodIdea = new Dimension(wide, platformPanel.getPreferredSize().height);
    // platformPanel.setMaximumSize(goodIdea);
    wide = Math.max(wide, platformPanel.getPreferredSize().width);
    platformPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(platformPanel);

    //  Box indentPanel = Box.createHorizontalBox();
    //  indentPanel.add(Box.createHorizontalStrut(new JCheckBox().getPreferredSize().width));
    final JCheckBox showStopButton = new JCheckBox("Show a Stop button");
    // showStopButton.setMnemonic(KeyEvent.VK_S);
    showStopButton.setSelected(Preferences.getBoolean("export.application.stop"));
    showStopButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            Preferences.setBoolean("export.application.stop", showStopButton.isSelected());
          }
        });
    showStopButton.setEnabled(Preferences.getBoolean("export.application.fullscreen"));
    showStopButton.setBorder(new EmptyBorder(3, 13, 6, 13));
    //  indentPanel.add(showStopButton);
    //  indentPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    final JCheckBox fullScreenButton = new JCheckBox("Full Screen (Present mode)");
    // fullscreenButton.setMnemonic(KeyEvent.VK_F);
    fullScreenButton.setSelected(Preferences.getBoolean("export.application.fullscreen"));
    fullScreenButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            boolean sal = fullScreenButton.isSelected();
            Preferences.setBoolean("export.application.fullscreen", sal);
            showStopButton.setEnabled(sal);
          }
        });
    fullScreenButton.setBorder(new EmptyBorder(3, 13, 3, 13));

    JPanel optionPanel = new JPanel();
    optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.Y_AXIS));
    optionPanel.add(fullScreenButton);
    optionPanel.add(showStopButton);
    //    optionPanel.add(indentPanel);
    optionPanel.setBorder(new TitledBorder("Options"));
    wide = Math.max(wide, platformPanel.getPreferredSize().width);
    // goodIdea = new Dimension(wide, optionPanel.getPreferredSize().height);
    optionPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    // optionPanel.setMaximumSize(goodIdea);
    panel.add(optionPanel);

    Dimension good;
    // label1, label2, platformPanel, optionPanel
    good = new Dimension(wide, label1.getPreferredSize().height);
    label1.setMaximumSize(good);
    good = new Dimension(wide, label2.getPreferredSize().height);
    label2.setMaximumSize(good);
    good = new Dimension(wide, platformPanel.getPreferredSize().height);
    platformPanel.setMaximumSize(good);
    good = new Dimension(wide, optionPanel.getPreferredSize().height);
    optionPanel.setMaximumSize(good);

    //    JPanel actionPanel = new JPanel();
    //    optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.X_AXIS));
    //    optionPanel.add(Box.createHorizontalGlue());

    //    final JDialog frame = new JDialog(editor, "Export to Application");

    //    JButton cancelButton = new JButton("Cancel");
    //    cancelButton.addActionListener(new ActionListener() {
    //      public void actionPerformed(ActionEvent e) {
    //        frame.dispose();
    //        return false;
    //      }
    //    });

    // Add the buttons in platform-specific order
    //    if (PApplet.platform == PConstants.MACOSX) {
    //      optionPanel.add(cancelButton);
    //      optionPanel.add(exportButton);
    //    } else {
    //      optionPanel.add(exportButton);
    //      optionPanel.add(cancelButton);
    //    }
    String[] options = {"Export", "Cancel"};
    final JOptionPane optionPane =
        new JOptionPane(
            panel,
            JOptionPane.PLAIN_MESSAGE,
            // JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION,
            null,
            options,
            options[0]);

    final JDialog dialog = new JDialog(this, "Export Options", true);
    dialog.setContentPane(optionPane);

    optionPane.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();

            if (dialog.isVisible()
                && (e.getSource() == optionPane)
                && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
              // If you were going to check something
              // before closing the window, you'd do
              // it here.
              dialog.setVisible(false);
            }
          }
        });
    dialog.pack();
    dialog.setResizable(false);

    Rectangle bounds = getBounds();
    dialog.setLocation(
        bounds.x + (bounds.width - dialog.getSize().width) / 2,
        bounds.y + (bounds.height - dialog.getSize().height) / 2);
    dialog.setVisible(true);

    Object value = optionPane.getValue();
    if (value.equals(options[0])) {
      return jmode.handleExportApplication(sketch);
    } else if (value.equals(options[1]) || value.equals(new Integer(-1))) {
      // closed window by hitting Cancel or ESC
      statusNotice("Export to Application canceled.");
    }
    return false;
  }
示例#24
0
  /**
   * Create a new ProjectionManager.
   *
   * @param parent JFrame (application) or JApplet (applet)
   * @param projections list of initial projections
   * @param makeDialog true to make this a dialog
   * @param helpId help id if dialog
   * @param maps List of MapData
   */
  public ProjectionManager(
      RootPaneContainer parent, List projections, boolean makeDialog, String helpId, List maps) {

    this.helpId = helpId;
    this.maps = maps;
    this.parent = parent;

    // manage NewProjectionListeners
    lm =
        new ListenerManager(
            "java.beans.PropertyChangeListener",
            "java.beans.PropertyChangeEvent",
            "propertyChange");

    // here's where the map will be drawn: but cant be changed/edited
    npViewControl = new NPController();
    if (maps == null) {
      maps = getDefaultMaps(); // we use the system default
    }
    for (int mapIdx = 0; mapIdx < maps.size(); mapIdx++) {
      MapData mapData = (MapData) maps.get(mapIdx);
      if (mapData.getVisible()) {
        npViewControl.addMap(mapData.getSource(), mapData.getColor());
      }
    }
    mapViewPanel = npViewControl.getNavigatedPanel();
    mapViewPanel.setPreferredSize(new Dimension(250, 250));
    mapViewPanel.setToolTipText("Shows the default zoom of the current projection");
    mapViewPanel.setChangeable(false);

    if ((projections == null) || (projections.size() == 0)) {
      projections = makeDefaultProjections();
    }

    // the actual list is a JTable subclass
    projTable = new JTableProjection(this, projections);

    JComponent listContents = new JScrollPane(projTable);

    JComponent buttons =
        GuiUtils.hbox(
            GuiUtils.makeButton("Edit", this, "doEdit"),
            GuiUtils.makeButton("New", this, "doNew"),
            GuiUtils.makeButton("Export", this, "doExport"),
            GuiUtils.makeButton("Delete", this, "doDelete"));

    mapLabel = new JLabel(" ");
    JComponent leftPanel = GuiUtils.inset(GuiUtils.topCenter(mapLabel, mapViewPanel), 5);

    JComponent rightPanel = GuiUtils.topCenter(buttons, listContents);
    rightPanel = GuiUtils.inset(rightPanel, 5);
    contents = GuiUtils.inset(GuiUtils.hbox(leftPanel, rightPanel), 5);

    // default current and working projection
    if (null != (current = projTable.getSelected())) {
      setWorkingProjection(current);
      projTable.setCurrentProjection(current);
      mapLabel.setText(current.getName());
    }

    /* listen for new working Projections from projTable */
    projTable.addNewProjectionListener(
        new NewProjectionListener() {
          public void actionPerformed(NewProjectionEvent e) {
            if (e.getProjection() != null) {
              setWorkingProjection(e.getProjection());
            }
          }
        });

    eventsOK = true;

    // put it together in the viewDialog
    if (makeDialog) {
      Container buttPanel = GuiUtils.makeApplyOkHelpCancelButtons(this);
      contents = GuiUtils.centerBottom(contents, buttPanel);
      viewDialog =
          GuiUtils.createDialog(GuiUtils.getApplicationTitle() + "Projection Manager", false);
      viewDialog.getContentPane().add(contents);
      viewDialog.pack();
      ucar.unidata.util.Msg.translateTree(viewDialog);
      viewDialog.setLocation(100, 100);
    }
  }
示例#25
0
 public void run() {
   while (connected) {
     try {
       Object obj = in.readObject();
       if (obj.toString().equals("-101")) {
         connected = false;
         in.close();
         out.close();
         socket.close();
         SwingUtilities.invokeLater(
             new Runnable() {
               public void run() {
                 Cashier.closee = true;
                 JOptionPane.showMessageDialog(
                     null,
                     "Disconnected from server. Please Restart",
                     "Error:",
                     JOptionPane.PLAIN_MESSAGE);
                 try {
                   m.stop();
                 } catch (Exception w) {
                 }
               }
             });
       } else if (obj.toString().split("::")[0].equals("broadcast")) {
         // System.out.println("braodcast received");
         bc.run(obj.toString().substring(obj.toString().indexOf("::") + 2));
       } else if (obj.toString().split("::")[0].equals("chat")) {
         // System.out.println("chat received:
         // "+obj.toString().substring(obj.toString().indexOf("::")+2));
         cc.run(obj.toString().substring(obj.toString().indexOf("::") + 2));
       } else if (obj.toString().split("::")[0].equals("rankings")) {
         String hhh = obj.toString().split("::")[1];
         final JDialog jd = new JDialog();
         jd.setUndecorated(false);
         JPanel pan = new JPanel(new BorderLayout());
         JLabel ppp = new JLabel();
         ppp.setFont(new Font("Arial", Font.BOLD, 20));
         ppp.setText(
             "<html><pre>Thanks for playing !!!<br/>1st: "
                 + hhh.split(":")[0]
                 + "<br/>2nd: "
                 + hhh.split(":")[1]
                 + "<br/>3rd: "
                 + hhh.split(":")[2]
                 + "</pre></html>");
         pan.add(ppp, BorderLayout.CENTER);
         JButton ok = new JButton("Ok");
         ok.addActionListener(
             new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                 jd.setVisible(false);
                 try {
                   m.stop();
                 } catch (Exception w) {
                 }
               }
             });
         pan.add(ok, BorderLayout.SOUTH);
         jd.setContentPane(pan);
         jd.setModalityType(JDialog.ModalityType.APPLICATION_MODAL);
         jd.pack();
         jd.setLocationRelativeTo(null);
         jd.setVisible(true);
       } else if (obj.toString().split("::")[0].equals("rank")) {
         rc.run(obj.toString().substring(obj.toString().indexOf("::") + 2));
       } else {
         User hhh = null;
         try {
           hhh = (User) obj;
           /*if(usrD==1)
           {
               reply=obj;
               ccl.interrupt();
           }
           else*/
           {
             try {
               m.ur.changeData((User) obj);
             } catch (Exception w) {
               try {
                 maain.ur.changeData((User) obj);
               } catch (Exception ppp) {
                 ppp.printStackTrace();
               }
             }
           }
         } catch (Exception p) {
           int iid = -1;
           try {
             iid = Integer.parseInt(obj.toString());
             obj = in.readObject();
             if (obj.toString().equals("-102")) {
               // ccl.interrupt();
               SwingUtilities.invokeLater(
                   new Runnable() {
                     public void run() {
                       Cashier.closee = true;
                       JOptionPane.showMessageDialog(
                           null, "Server Not Running.", "Error:", JOptionPane.PLAIN_MESSAGE);
                     }
                   });
             }
             // Thread th = ((Thread)rev.remove(iid));
             rev2.put(iid, obj);
             // System.out.println("Put: "+iid+"   :   "+obj.toString()+"   :
             // "+Thread.currentThread());
             // th.interrupt();
             // ccl.interrupt();
           } catch (Exception ppp) {
               /*ppp.printStackTrace();*/
             System.out.println(
                 "Shit: "
                     + iid
                     + "   :   "
                     + obj.toString()
                     + "   :   "
                     + Thread.currentThread());
           }
         }
       }
       try {
         Thread.sleep(500);
       } catch (Exception n) {
       }
     } catch (Exception m) {
     }
   }
 }
示例#26
0
  public void run() {

    // Collect some user data.
    dlg = new JDialog(console.frame, "Example 1 Setup", true);
    dlg.getContentPane().setLayout(new BorderLayout());

    // Properties area
    propPanel = new JPanel();
    dlg.getContentPane().add(propPanel, BorderLayout.CENTER);

    GridBagLayout gbl = new GridBagLayout();
    propPanel.setLayout(gbl);

    // List of voice resources
    DefaultListModel dlm = new DefaultListModel();
    for (int x = 1; ; x++) {
      try {
        int c = x % 4 == 0 ? 4 : x % 4;
        int b = c == 4 ? x / 4 : x / 4 + 1;
        String devName = "dxxxB" + b + "C" + c;
        int dev = dx.open(devName, 0);
        try {
          // If any of the voice resources _are not_ connected to
          // analog loop-start lines, then they will be suppressed
          // here because sethook() will not be supported.
          dx.sethook(dev, dx.DX_ONHOOK, dx.EV_SYNC);
          dlm.addElement(devName);
        } catch (Exception ignore) {
        }
        dx.close(dev);
      } catch (Exception ignore) {
        break;
      }
    }
    analogDxList = new JList(dlm);
    {
      GridBagConstraints gbc;
      // Choose a voice resource:
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.BOTH;
      JTextField t = new JTextField("Analog Voice Resource");
      t.setEditable(false);
      gbl.setConstraints(t, gbc);
      propPanel.add(t);
      gbc = new GridBagConstraints();
      gbc.gridx = 1;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.BOTH;
      JScrollPane s = new JScrollPane(analogDxList);
      gbl.setConstraints(s, gbc);
      propPanel.add(s);
    }

    // Dialog buttons at the bottom.
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    dlg.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    // "Run"
    {
      JButton b = new JButton("Run");
      b.addActionListener(
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              final Object[] dx = analogDxList.getSelectedValues();
              if (dx.length != 1) {
                // "Please select one, and only one, voice resource."
                JOptionPane.showMessageDialog(
                    dlg,
                    "Please select one, and only one, resource.",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
                return;
              }
              Thread t =
                  new Thread() {
                    public void run() {
                      runExample((String) dx[0]);
                    }
                  };
              t.start();
              dlg.dispose();
            }
          });
      buttonPanel.add(b);
    }
    // "Cancel"
    {
      JButton b = new JButton("Cancel");
      b.addActionListener(
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              dlg.dispose();
            }
          });
      buttonPanel.add(b);
    }

    // Pack and Show
    dlg.pack();
    dlg.setLocationRelativeTo(console.frame);
    dlg.setVisible(true);
  }
  MyCustomizableGUI() {

    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    textField = new JTextField(20);
    buttonPref = new JButton("Preferences");

    this.add(textField);
    this.add(buttonPref);

    buttonPref.addActionListener(evt -> prefDialog.setVisible(true));

    frame = new JFrame("My text editor");
    frame.setContentPane(this);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    // Preferences dialog box
    prefDialog = new JDialog(frame, "Dialog", true);
    prefDialog.setLayout(new BorderLayout());
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(3, 2));
    JPanel p2 = new JPanel();
    p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));

    buttonSave = new JButton("Save");
    buttonCancel = new JButton("Cancel");

    buttonSave.addActionListener(
        evtSave -> {
          String fontChosen;
          int fontSizeChosen;

          prefDialog.setVisible(false);

          if ((String) color.getSelectedItem() == "Red") {
            textField.setForeground(Color.red);
          } else if ((String) color.getSelectedItem() == "Green") {
            textField.setForeground(Color.green);
          } else if ((String) color.getSelectedItem() == "Blue") {
            textField.setForeground(Color.blue);
          } else if ((String) color.getSelectedItem() == "Cyan") {
            textField.setForeground(Color.cyan);
          } else if ((String) color.getSelectedItem() == "Magenta") {
            textField.setForeground(Color.magenta);
          } else if ((String) color.getSelectedItem() == "Yellow") {
            textField.setForeground(Color.yellow);
          } else if ((String) color.getSelectedItem() == "Black") {
            textField.setForeground(Color.black);
          }

          fontChosen = (String) font.getSelectedItem();
          fontSizeChosen = Integer.parseInt((String) fontSize.getSelectedItem());
          textField.setFont(new Font(fontChosen, Font.PLAIN, fontSizeChosen));

          UserPreferences userPrefs = new UserPreferences();
          userPrefs.setColor((String) color.getSelectedItem());
          userPrefs.setFont(fontChosen);
          userPrefs.setFontSize(fontSizeChosen);

          try (FileOutputStream fileOut = new FileOutputStream("preferences.ser");
              ObjectOutputStream objectOut = new ObjectOutputStream(fileOut); ) {

            objectOut.writeObject(userPrefs);

          } catch (IOException ioe) {
            System.out.println("I/O error: " + ioe.getMessage());
          }
        });

    buttonCancel.addActionListener(evt -> prefDialog.setVisible(false));

    colorLabel = new JLabel("Color:");
    fontLabel = new JLabel("Font:");
    fontSizeLabel = new JLabel("Font size:");
    color = new JComboBox(colorList);
    font = new JComboBox(fontList);
    fontSize = new JComboBox(fontSizeList);

    p1.add(colorLabel);
    p1.add(color);
    p1.add(fontLabel);
    p1.add(font);
    p1.add(fontSizeLabel);
    p1.add(fontSize);
    p2.add(buttonCancel);
    p2.add(buttonSave);

    prefDialog.add(BorderLayout.NORTH, p1);
    prefDialog.add(BorderLayout.SOUTH, p2);

    prefDialog.pack();
  }