/**
  * Common event handling code - can handle desirable actions (such as buttons being clicked) and
  * undesirable actions (the window being closed) all in a common location.
  *
  * @param command a String representing the action that occurred.
  */
 private void processCommand(String command) {
   dialog.setVisible(false);
   if (CONNECT.equals(command)) {
     options.setValue(JOptionPane.OK_OPTION);
   } else {
     options.setValue(JOptionPane.CANCEL_OPTION);
   }
 }
예제 #2
0
 /**
  * Sets the dialog's value for further reference before changing its visibility status to
  * invisible.
  *
  * @param command the previously set command string to identify the source of this method
  *     invocation
  */
 private void leaveDialog(final String command) {
   JOptionPane optionPane = (JOptionPane) getContentPane();
   if (Text.OK.equals(command)) {
     optionPane.setValue(JOptionPane.OK_OPTION);
   } else {
     optionPane.setValue(JOptionPane.CANCEL_OPTION);
   }
   setVisible(false);
 }
예제 #3
0
    public void actionPerformed(ActionEvent e) {
      if (getName() == CLOSE) {
        JOptionPane optionPane = (JOptionPane) e.getSource();

        optionPane.setValue(Integer.valueOf(JOptionPane.CLOSED_OPTION));
      }
    }
예제 #4
0
파일: Main.java 프로젝트: nokutu/simpleChat
 @Override
 public void actionPerformed(ActionEvent arg0) {
   if (!dialog.username.getText().isEmpty() && Utils.validIP(dialog.serverIp.getText())) {
     try {
       serverIP = InetAddress.getByName(dialog.serverIp.getText());
       username = dialog.username.getText();
       LOGIN_RESULT result = Actions.login(serverIP, serverPort);
       if (result == LOGIN_RESULT.SUCCESSFUL) pane.setValue(JOptionPane.OK_OPTION);
       else if (result == LOGIN_RESULT.USERNAME_USED) {
         dialog.usernameLabel.setText("Username already in use.");
         dialog.username.setBorder(BorderFactory.createLineBorder(Color.RED));
       } else if (result == LOGIN_RESULT.INVALID_IP || result == null) {
         dialog.serverIpLabel.setText("Server IP is invalid.");
         dialog.serverIp.setBorder(BorderFactory.createLineBorder(Color.RED));
       }
     } catch (IOException e) {
       e.printStackTrace();
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   } else {
     if (dialog.username.getText().isEmpty())
       dialog.username.setBorder(BorderFactory.createLineBorder(Color.RED));
     if (!Utils.validIP(dialog.serverIp.getText()))
       dialog.serverIp.setBorder(BorderFactory.createLineBorder(Color.RED));
   }
 }
예제 #5
0
  public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible()
        && (e.getSource() == optionPane)
        && (JOptionPane.VALUE_PROPERTY.equals(prop)
            || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
      Object value = optionPane.getValue();

      if (value == JOptionPane.UNINITIALIZED_VALUE) return;
      optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

      if (button1.equals(value)) {
        try {
          double a = Double.parseDouble(left.getText());
          double b = Double.parseDouble(right.getText());
          double err = Double.parseDouble(error.getText());

          if (a > b) {
            JOptionPane.showMessageDialog(this, "A < B!!!", null, JOptionPane.ERROR_MESSAGE);
          } else {
            hideIt();
            graphic.startApplyingMethod(parentFrame.getSelectedMethod(), err, a, b);
          }
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this, "Trebuie sa fie numar real!", null, JOptionPane.ERROR_MESSAGE);
        }
      } else if (button2.equals(value)) {
        hideIt();
      }
    }
  }
예제 #6
0
  /** This method reacts to state changes in the option pane. */
  public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible()
        && (e.getSource() == optionPane)
        && (JOptionPane.VALUE_PROPERTY.equals(prop)
            || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
      Object value = optionPane.getValue();

      if (value == JOptionPane.UNINITIALIZED_VALUE) {
        // ignore reset
        return;
      }

      // Reset the JOptionPane's value.
      // If you don't do this, then if the user
      // presses the same button next time, no
      // property change event will be fired.
      optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

      if (btnString1.equals(value)) {
        String[] strings = new String[1];
        strings[0] = numPlatesTextField.getText();

        // make sure the inputed values are numbers only
        if (tools.MathOps.areNumbers(strings)) {

          int numP = Integer.parseInt(strings[0]);
          if (numRows != -1 && numCols != -1) {
            Model_Main TheMainModel = models.Model_Main.getModel();
            if (TheMainModel == null) TheMainModel = new Model_Main();

            boolean worked = TheMainModel.initNewPlates(numP, numRows, numCols);

            if (worked) {
              if (ParentFrame != null) ParentFrame.setVisible(false);

              MainGUI TheMainGUI = new MainGUI(TheMainModel);
              if (TheMainGUI != null)
                TheMainGUI.setTitle("Project: " + TheMainModel.getInputProjectPath());
              TheMainGUI.setVisible(true);
            }
          }

        } else {
          JOptionPane.showMessageDialog(
              null, "Please Enter a Valid Number of Plates ", "Error", JOptionPane.ERROR_MESSAGE);
          return;
        }
        clearAndHide();

      } else { // user closed dialog or clicked cancel
        clearAndHide();
      }
    }
  }
예제 #7
0
  /** This method reacts to state changes in the option pane. */
  public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible()
        && (e.getSource() == optionPane)
        && (JOptionPane.VALUE_PROPERTY.equals(prop)
            || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
      Object value = optionPane.getValue();

      if (value == JOptionPane.UNINITIALIZED_VALUE) {
        // ignore reset
        return;
      }

      // Reset the JOptionPane's value.
      // If you don't do this, then if the user
      // presses the same button next time, no
      // property change event will be fired.
      optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

      if (btnString1.equals(value)) {
        typedText = textField1.getText();
        String ucText = typedText.toUpperCase();
        if (magicWord.equals(ucText)) {
          // we're done; clear and dismiss the dialog
          clearAndHide();
        } else {
          // text was invalid
          textField1.selectAll();
          JOptionPane.showMessageDialog(
              iRuleDialog.this,
              "Sorry, \""
                  + typedText
                  + "\" "
                  + "isn't a valid response.\n"
                  + "Please enter "
                  + magicWord
                  + ".",
              "Try again",
              JOptionPane.ERROR_MESSAGE);
          typedText = null;
          textField1.requestFocusInWindow();
        }
      } else { // user closed dialog or clicked cancel
        mainGuiWindow.setLabel("It's OK.");
        typedText = null;
        clearAndHide();
      }
    }
  }
예제 #8
0
  /** This method reacts to state changes in the option pane. */
  public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible()
        && (e.getSource() == optionPane)
        && (JOptionPane.VALUE_PROPERTY.equals(prop)
            || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
      Object value = optionPane.getValue();

      if (value == JOptionPane.UNINITIALIZED_VALUE) {
        // ignore reset
        return;
      }

      // Reset the JOptionPane's value.
      // If you don't do this, then if the user
      // presses the same button next time, no
      // property change event will be fired.
      optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

      if (btnString1.equals(value)) {
        String[] strings = null;

        strings = new String[1];
        strings[0] = textField[0].getText().trim(); // zScore thresh

        // make sure the inputed values are numbers only
        if (tools.MathOps.areNumbers(strings)) {

          zScore_channel = (String) channelBox.getSelectedItem();
          zScore_threshold = Float.parseFloat(strings[0].trim());

          clearAndHide();

        } else {
          JOptionPane.showMessageDialog(
              null,
              "Error with inputed bounds!  Make sure numbers make sense ",
              "Thresholds",
              JOptionPane.ERROR_MESSAGE);
        }

      } else {
        // user closed dialog or clicked cancel
        typedText = null;
        clearAndHide();
      }
    }
  }
예제 #9
0
 public void propertyChange(PropertyChangeEvent e) {
   String prop = e.getPropertyName();
   if (isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
     Object value = optionPane.getValue();
     optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
     // If you were going to check something
     // before closing the window, you'd do
     // it here.
     if (value.equals("Close")) {
       setVisible(false);
       dispose();
     } else if (value.equals("Print")) {
       cp.createChartPrintJob();
     }
   }
 }
예제 #10
0
 private static void createNativesFolder(File folder) {
   if (folder.exists() && !folder.isDirectory()) {
     Desktop desktop = Desktop.getDesktop();
     JButton browseFolder;
     JButton ok = new JButton(UIManager.getString("OptionPane.okButtonText"));
     Object[] options;
     if (desktop.isSupported(Action.BROWSE)) {
       browseFolder = new JButton("Browse Folder");
       options = new Object[] {browseFolder, ok};
     } else {
       browseFolder = null;
       options = new Object[] {ok};
     }
     JOptionPane msg =
         new JOptionPane(
             "We must create this folder \""
                 + folder
                 + "\" and there is a file called natives in its place.\n"
                 + "Rename or move at this time or it will be deleted. Resistance is futile.",
             JOptionPane.INFORMATION_MESSAGE,
             JOptionPane.DEFAULT_OPTION,
             null,
             options);
     if (browseFolder != null) {
       browseFolder.addActionListener(
           action -> {
             try {
               Desktop.getDesktop().browse(folder.getParentFile().toURI());
             } catch (Exception e) {
               UIUtils.displayException("Unable to browse folder", e);
             }
           });
     }
     ok.addActionListener(action -> msg.setValue(0));
     JDialog dialog = msg.createDialog("Slyther");
     try (InputStream icon = ClientMain.class.getResourceAsStream("/textures/icon_32.png")) {
       dialog.setIconImage(ImageIO.read(icon));
     } catch (IOException e) {
     }
     dialog.setVisible(true);
     dialog.dispose();
     folder.delete();
   }
   folder.mkdirs();
 }
예제 #11
0
 @Override
 public void propertyChange(PropertyChangeEvent e) {
   String prop = e.getPropertyName();
   if (isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
     Object value = optionPane.getValue();
     optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
     // If you were going to check something
     // before closing the window, you'd do
     // it here.
     if (value.equals("Close")) {
       setVisible(false);
       dispose();
     } else if (value.equals("Print")) {
       chartPanel.createChartPrintJob();
     } else if (value.equals("Export GRAPH")) {
       File exportFile =
           GraphUtil.saveGraphics(chartPanel, XMAX.getConfiguration().getUserDir("GRAPH"));
       if (exportFile != null) {
         XMAX.getConfiguration().setUserDir("GRAPH", exportFile.getParent());
       }
     }
   }
 }
예제 #12
0
 /** This method handles events for the text field. */
 public void actionPerformed(ActionEvent e) {
   optionPane.setValue(btnString1);
 }
  /** This method reacts to state changes in the option pane. */
  public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible()
        && (e.getSource() == optionPane)
        && (JOptionPane.VALUE_PROPERTY.equals(prop)
            || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
      Object value = optionPane.getValue();

      if (value == JOptionPane.UNINITIALIZED_VALUE) {
        // ignore reset
        return;
      }

      // Reset the JOptionPane's value.
      // If you don't do this, then if the user
      // presses the same button next time, no
      // property change event will be fired.
      optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

      if (btnString1.equals(value)) {
        String[] strings = null;

        strings = new String[3];
        strings[0] = textField[0].getText(); // Nuc thresh
        strings[1] = textField[1].getText(); // Cyt Thresh
        strings[2] = textField[2].getText(); // Bkgd thresh

        // make sure the inputed values are numbers only
        if (tools.MathOps.areNumbers(strings)) {
          int NucBoundaryChannel = channelBox_nuc.getSelectedIndex();
          int CytoBoundaryChannel = channelBox_cyto.getSelectedIndex();
          float Thresh_Nuc_Value = Float.parseFloat(strings[0]);
          float Thresh_CellBoundary = Float.parseFloat(strings[1]);
          float Thresh_Bkgd_Value = Float.parseFloat(strings[2]);

          // Storing the Parameters for each Model_Field
          int len = TheWells.length;
          for (int i = 0; i < len; i++) {
            Model_Well well = TheWells[i];
            Model_Field[] fields = well.getFields();
            for (int p = 0; p < fields.length; p++) {

              Model_ParameterSet pset = fields[p].getParameterSet();
              pset.setParameter("Algorithm", "DefaultSegmentor_v1");

              // Threshold Channel Nucleus
              pset.setParameter(
                  "Thresh_Nuc_ChannelName",
                  "" + models.Model_Main.getModel().getTheChannelNames()[NucBoundaryChannel]);
              // Threshold Channel Cytoplasm
              pset.setParameter(
                  "Thresh_Cyt_ChannelName",
                  models.Model_Main.getModel().getTheChannelNames()[CytoBoundaryChannel]);
              // Nuc bound threshold
              pset.setParameter("Thresh_Nuc_Value", "" + Thresh_Nuc_Value);
              // Cell bound Threshold
              pset.setParameter("Thresh_Cyt_Value", "" + Thresh_CellBoundary);
              // Bkgd threshold
              pset.setParameter("Thresh_Bkgd_Value", "" + Thresh_Bkgd_Value);

              if (CoordsToSave == 0) pset.setParameter("CoordsToSaveToHDF", "BoundingBox");
              else if (CoordsToSave == 1) pset.setParameter("CoordsToSaveToHDF", "Centroid");
              else if (CoordsToSave == 2) pset.setParameter("CoordsToSaveToHDF", "Outlines");
              else if (CoordsToSave == 3) pset.setParameter("CoordsToSaveToHDF", "Everything");

              // Finding the index of this channel name
              for (int j = 0; j < models.Model_Main.getModel().getTheChannelNames().length; j++)
                if (models.Model_Main.getModel()
                    .getTheChannelNames()[j]
                    .equalsIgnoreCase(pset.getParameter_String("Thresh_Nuc_ChannelName")))
                  pset.setParameter("Thresh_Nuc_ChannelIndex", "" + j);
              // Finding the index of this channel name
              for (int j = 0; j < models.Model_Main.getModel().getTheChannelNames().length; j++)
                if (models.Model_Main.getModel()
                    .getTheChannelNames()[j]
                    .equalsIgnoreCase(pset.getParameter_String("Thresh_Cyt_ChannelName")))
                  pset.setParameter("Thresh_Cyt_ChannelIndex", "" + j);

              // Storing Parameters used to process this field
              String hdfPath = models.Model_Main.getModel().getOutputProjectPath() + "/Data.h5";
              try {
                pset.writeParameters(
                    hdfPath,
                    well.getPlate().getID(),
                    well.getWellIndex(),
                    fields[p].getIndexInWell());
              } catch (H5IO_Exception e1) {
                e1.printStackTrace();
              }
            }
          }
          if (Thresh_Bkgd_Value > 0) models.Model_Main.getModel().setBackgroundSubtract(true);

          // Only getting wells with Images that we can process
          int numWells = TheWells.length;
          ArrayList<Model_Well> wellsWIm = new ArrayList<Model_Well>();
          for (int i = 0; i < numWells; i++)
            if (TheWells[i].getFields() != null && TheWells[i].getFields().length > 0)
              wellsWIm.add(TheWells[i]);
          int numW = wellsWIm.size();
          Model_Well[] wellsWithImages = new Model_Well[numW];
          for (int i = 0; i < numW; i++) wellsWithImages[i] = wellsWIm.get(i);

          // File dir = models.Model_Main.getModel()
          // .getProjectDirectory();
          // File f = new File(dir.getAbsolutePath() + "/BatchJobs");
          // if (f.exists())
          // deleteDir(f);
          //
          // f = new File(dir.getAbsolutePath() + "/BatchJobs");
          // f.mkdir();
          // File f2 = new File(dir.getAbsolutePath() +
          // "/BatchResults");
          // if (f2.exists())
          // deleteDir(f2);
          // f2 = new File(dir.getAbsolutePath() + "/BatchResults");
          // f2.mkdir();

          if (models.Model_Main.getModel().isProcessing()) {
            JOptionPane.showMessageDialog(
                null,
                "Please wait till segmentation is complete before starting another process",
                "Be Patient",
                JOptionPane.ERROR_MESSAGE);
            return;
          }

          // Single thread run
          Processor_WriteParameters tasker = new Processor_WriteParameters(wellsWithImages, null);
          tasker.start();

        } else {
          JOptionPane.showMessageDialog(
              null,
              "Error with inputed bounds!  Make sure numbers make sense ",
              "Thresholds",
              JOptionPane.ERROR_MESSAGE);
          return;
        }
        clearAndHide();

      } else { // user closed dialog or clicked cancel
        clearAndHide();
      }
    }
  }