Example #1
0
  /**
   * Lets the user know that the text they entered is bad. Returns true if the user elects to revert
   * to the last good value. Otherwise, returns false, indicating that the user wants to continue
   * editing.
   */
  protected boolean userSaysRevert() {
    Toolkit.getDefaultToolkit().beep();
    ftf.selectAll();
    Object[] options = {"Editar", "Revertir"};
    String mensaje = "El valor debe ser ";
    if (minimum != null && maximum != null)
      mensaje += "mayor a " + minimum + " y menor a " + maximum;
    else {
      if (minimum != null) mensaje += "mayor a " + minimum;
      if (maximum != null) mensaje += "menor a " + maximum;
    }
    int answer =
        JOptionPane.showOptionDialog(
            SwingUtilities.getWindowAncestor(ftf),
            mensaje + ".\n" + "¿Deseas editar el número " + "o revertir los cambios?",
            "Valor ingresado no válido",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.ERROR_MESSAGE,
            null,
            options,
            options[1]);

    if (answer == 1) { // Revert!
      ftf.setValue(ftf.getValue());
      return true;
    }
    return false;
  }
Example #2
0
 /**
  * Moves piezo and slice together. Specify the factor by which the step size is multiplied by
  * (e.g. +/- 1).
  *
  * @param factor
  */
 private void stepPiezoAndGalvo(double factor) {
   try {
     double piezoPos = positions_.getUpdatedPosition(piezoImagingDeviceKey_);
     piezoPos += (factor * (Double) piezoDeltaField_.getValue());
     positions_.setPosition(piezoImagingDeviceKey_, piezoPos, true);
     double galvoPos = computeGalvoFromPiezo(piezoPos);
     positions_.setPosition(micromirrorDeviceKey_, Directions.Y, galvoPos, true);
   } catch (Exception ex) {
     MyDialogUtils.showError(ex);
   }
 }
Example #3
0
 private int getPort() throws SettingsException {
   int port;
   try {
     port = ((Number) portTextField.getValue()).intValue();
     if (port < 1 || port > 65535) {
       throw new Exception();
     }
   } catch (Exception x) {
     throw new SettingsException("Please specify a valid port number.", x);
   }
   return port;
 }
Example #4
0
 private int getMemoryLimit() throws SettingsException {
   int memoryLimit;
   try {
     memoryLimit = ((Number) memoryTextField.getValue()).intValue();
     if (memoryLimit < 5) {
       throw new Exception();
     }
   } catch (Exception x) {
     throw new SettingsException("Please specify a valid memory limit.", x);
   }
   return memoryLimit;
 }
Example #5
0
  public ProblemDescriptors getParameters() {
    if (Utils.isEmpty(problemSizeEdit.getText())
        || Utils.isEmpty(stockLengthEdit.getText())
        || Utils.isEmpty(orderLengthLowerBoundEdit.getText())
        || Utils.isEmpty(orderLengthUpperBoundEdit.getText())
        || Utils.isEmpty(averageDemandEdit.getText())) {
      return null;
    }

    int problemSize = ((Number) problemSizeEdit.getValue()).intValue();
    int stockLength = ((Number) stockLengthEdit.getValue()).intValue();
    double orderLengthLowerBound = ((Number) orderLengthLowerBoundEdit.getValue()).doubleValue();
    double orderLengthUpperBound = ((Number) orderLengthUpperBoundEdit.getValue()).doubleValue();
    int averageDemand = ((Number) averageDemandEdit.getValue()).intValue();

    ProblemDescriptors descriptors =
        new ProblemDescriptors(
            problemSize, stockLength, orderLengthLowerBound, orderLengthUpperBound, averageDemand);

    return descriptors;
  }
Example #6
0
 /** Performs "1-point" calibration updating the offset but not the slope. */
 private void updateCalibrationOffset() {
   try {
     double rate = (Double) rateField_.getValue();
     // bypass cached positions in positions_ in case they aren't current
     double currentScanner = positions_.getUpdatedPosition(micromirrorDeviceKey_, Directions.Y);
     double currentPiezo = positions_.getUpdatedPosition(piezoImagingDeviceKey_);
     double newOffset = currentPiezo - rate * currentScanner;
     offsetField_.setValue((Double) newOffset);
   } catch (Exception ex) {
     MyDialogUtils.showError(ex);
   }
 }
Example #7
0
 protected void save() {
   data.name = nameField.getText();
   try {
     costField.commitEdit();
     data.cost = ((Long) costField.getValue()).intValue();
   } catch (ParseException e) {
     data.cost = 0;
   }
   data.color = colorBox.getSelectedItem().toString();
   data.text = charField.getText();
   data.weight = Float.parseFloat(weightField.getText());
   if (spellBox.getSelectedItem() != null) {
     data.spell = spellBox.getSelectedItem().toString();
   }
   data.setPath(Editor.getStore().getActive().get("id"));
 }
Example #8
0
  private int getHttpsPort() throws SettingsException {
    if (!httpsPortCheckBox.isSelected()) {
      return 0;
    }

    int port;
    try {
      port = ((Number) httpsPortTextField.getValue()).intValue();
      if (port < 1 || port > 65535) {
        throw new Exception();
      }
    } catch (Exception x) {
      throw new SettingsException("Please specify a valid https port number.", x);
    }
    return port;
  }
 @Override
 public boolean stopCellEditing() {
   JFormattedTextField ftf = (JFormattedTextField) getComponent();
   if (ftf.isEditValid()) {
     try {
       ftf.commitEdit();
     } catch (java.text.ParseException exc) {
       // nothing to do
     }
   } else {
     if (!askEditOrRevert(ftf, null)) {
       return false;
     } else {
       ftf.setValue(ftf.getValue());
     }
   }
   return super.stopCellEditing();
 }
Example #10
0
 // Override to ensure that the value remains an Float.
 @Override
 public Object getCellEditorValue() {
   JFormattedTextField ftf1 = (JFormattedTextField) getComponent();
   Object o = ftf1.getValue();
   if (o instanceof Float) {
     return o;
   } else if (o instanceof Number) {
     return new Float(((Number) o).intValue());
   } else {
     if (DEBUG) {
       System.out.println("getCellEditorValue: o isn't a Number");
     }
     try {
       return floatFormat.parseObject(o.toString());
     } catch (ParseException exc) {
       System.err.println("getCellEditorValue: can't parse o: " + o);
       return null;
     }
   }
 }
Example #11
0
  private void createZoomTextField() {
    mZoomTextField = new JFormattedTextField(new DecimalFormat("##0.00%"));
    mZoomTextField.setFocusLostBehavior(JFormattedTextField.REVERT);
    mZoomTextField.setHorizontalAlignment(SwingConstants.CENTER);
    mZoomTextField.setColumns(6);
    mZoomTextField.setMinimumSize(mZoomTextField.getPreferredSize());

    mZoomTextField.addActionListener(
        (x) -> mImagePresentationModel.setZoom(((Number) mZoomTextField.getValue()).doubleValue()));

    mImagePresentationModel.addListener(
        new ImagePresentationModel.Listener() {
          @Override
          public void onVisibleImageContentUpdate() {
            mZoomTextField.setValue(mImagePresentationModel.getZoom());
          }

          @Override
          public void onImageChange() {
            onVisibleImageContentUpdate();
          }
        });
  }
Example #12
0
  public void actionPerformed(ActionEvent event) {

    // if clear button is pressed, clear all fields
    if (event.getSource() == clear_button) {
      // erase all fields

      taskname_field.setText("");
      taskdesc_field.setText("");

      priority_checkbox.setSelected(false);
      numberofdays_field.setText("");
      // isallocatedcheckbox.setSelected(false);
      duedate_field.setText("");
    }

    // if submit button is pressed, save all data onto database
    if (event.getSource() == submit_button) {
      try {
        {
          Calendar calendar = Calendar.getInstance();
          calendar.setTime(new Date()); // set to current date
          calendar.add(
              Calendar.DAY_OF_MONTH,
              Integer.parseInt(this.numberofdays_field.getText())
                  - 1); // add days required... then:
          // ^ subtract one day, because if task is created today and allocated tomorrow for one
          // day,
          // then it should be done by end of day tomorrow
          Date date = calendar.getTime(); // (see next *1) use this date to be the earliest
          // because of expected task duration

          /*This is a constraint
           * the date and the length of days that user expected to take
           * if not feasible then the program will say so
           * */
          // method compares the current date and the date that was entered by the user
          if (this.task_idfield.getText().length() != 7 // check chars
              || this.taskname_field.getText().length() > 50 // check chars
              || this.taskdesc_field.getText().length() > 50
              || ((Date) this.duedate_field.getValue()).compareTo(date)
                  < 0 // check that the date is possible (see last *1)
              || this.numberofdays_field.getText().length() > 2
              || this.numberofdays_field.getText().length() == 0 // check number of digits
              || Integer.parseInt(this.numberofdays_field.getText())
                  < 1) // check number of days required for task
          {
            JOptionPane.showMessageDialog(
                this,
                "Task ID has to be 7 chars; "
                    + "\n"
                    + "Description <= 50 chars; "
                    + "\n"
                    + "Because the expected duration of the task is "
                    + Integer.parseInt(this.numberofdays_field.getText())
                    + " days, the due date cannot be earlier than: "
                    + new StringBuffer(new SimpleDateFormat("dd/MM/yyyy").format(date)).toString()
                    + "; "
                    + "\n"
                    + "Task duration must be 2 digit number maximum and must be an integer greater than 0");
          } else

          // check if taskid_field is equals to any of the fields on the database

          if (task_idfield.equals("")) {
            JOptionPane.showMessageDialog(
                this, "Please insert an identification number for a task");

          } else // add constraint and tell customer to enter 7 values
          if (taskname_field.equals("")) {
            JOptionPane.showMessageDialog(this, "Please insert a name to identity the task");

          } else {

            // get all inputs from user inputs and store in variables
            taskid_input = task_idfield.getText();
            taskname_input = taskname_field.getText();
            taskdesc_input = taskdesc_field.getText();

            if (priority_checkbox.isSelected()) {
              priority_input = 1;
            } else {
              priority_input = 0;
            }

            // create and store date from user input
            date = (Date) duedate_field.getValue();

            // store number of days input from user
            numberofdays_input = Integer.parseInt(numberofdays_field.getText());

            // 	String[] column_names = { "Task ID", "Task Name", "Task Description", "Task
            // Priority", "Due Date", "Number of Days", "Is Allocated" , "Unallocateable" };

            task = new Object[8];
            task[0] = taskid_input;
            task[1] = taskname_input;
            task[2] = taskdesc_input;
            task[3] = priority_input;
            task[4] = date;
            task[5] = numberofdays_input;
            task[6] = 0;
            task[7] = 0;

            try {
              //
              SqlConnection.connect();

              SqlConnection.ps =
                  SqlConnection.connection.prepareStatement(
                      "INSERT  INTO TASK VALUES (?,?,?,?,?,?,?,?)");

              SqlConnection.ps.setString(1, taskid_input);
              SqlConnection.ps.setString(2, taskname_input);
              SqlConnection.ps.setString(3, taskdesc_input);
              SqlConnection.ps.setInt(4, priority_input);
              SqlConnection.ps.setDate(5, new java.sql.Date(date.getTime()));
              SqlConnection.ps.setInt(6, numberofdays_input);
              SqlConnection.ps.setInt(7, 0);
              SqlConnection.ps.setInt(8, 0);

              SqlConnection.ps.executeUpdate();

              // now enter skills into TASK SKILL database
              for (int i = 0; i < skill_list.size(); i++) {
                if (skill_list.get(i).isSelected()) {
                  String skillid = skill_list.get(i).getText();
                  SqlConnection.statement.executeUpdate(
                      "INSERT INTO TASKSKILL VALUES ('" + taskid_input + "', '" + skillid + "')");
                }
              }

              SqlConnection.ps.close();
            } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            // SqlConnection.ps.close();
            SqlConnection.closeConnection();
            this.setVisible(false);
          }
        }

      } catch (Exception exc) {
        JOptionPane.showMessageDialog(
            this,
            "Check your inputs:"
                + "\n"
                + "Priority has to be a 1-digit number;"
                + "\n"
                + "Date has to be in the format dd/MM/yyyy;"
                + "\n"
                + "Task length has to be 2-digit number");
        System.out.println(exc);
      }
    }
    // display dialog box asking task manager if they want to quit,
    // if task manager does not want to quit, go back to adding more tasks
    // if customer quits, close the dialog box and the frame

    // now close the window after saving
  }
  @Override
  protected void windowClosing() {
    jButtonCancel.requestFocusInWindow();

    jTextFieldDelay.setValue(jTextFieldDelay.getValue());
  }
Example #14
0
 @Override
 public Object getCellEditorValue() {
   JFormattedTextField ftf = (JFormattedTextField) getComponent();
   return ftf.getValue();
 }
Example #15
0
 /**
  * Uses computed offset/rate to get galvo position for specified piezo position
  *
  * @param pizeoPos
  * @return
  */
 private double computeGalvoFromPiezo(double piezoPos) {
   double offset = (Double) offsetField_.getValue();
   double rate = (Double) rateField_.getValue();
   return ((piezoPos - offset) / rate);
 }
  @Override
  public void actionPerformed(ActionEvent e) {

    if (e.getActionCommand().startsWith("FILTRU")) {
      int length = Integer.parseInt(e.getActionCommand().substring(6));
      for (int index = 0; index < selection.size(); index++) {
        JCheckBox chk1 = (JCheckBox) selection.get(index);
        int productLength = Integer.parseInt(chk1.getName().substring(6));
        if (!filtru2m.isSelected() && !filtru3m.isSelected() && !filtru4m.isSelected()) {
          chk1.getParent().setVisible(true);
          continue;
        }
        if (productLength < 3000 && productLength >= 2000 && filtru2m.isSelected()) {
          chk1.getParent().setVisible(true);
        } else if (productLength < 4000 && productLength >= 3000 && filtru3m.isSelected()) {
          chk1.getParent().setVisible(true);
        } else if (productLength < 5000 && productLength >= 4000 && filtru4m.isSelected()) {
          chk1.getParent().setVisible(true);
        } else {
          chk1.getParent().setVisible(false);
        }
      }
      this.revalidate();
      return;
    }
    boolean valid = true;

    JLabel lenLabel = (JLabel) ((JPanel) getComponent(0)).getComponent(0);
    JFormattedTextField lenRadius =
        (JFormattedTextField) ((JPanel) getComponent(0)).getComponent(1);
    JComboBox<String> lenRadiusMetric =
        (JComboBox<String>) ((JPanel) getComponent(0)).getComponent(2);
    lenLabel.setForeground(Color.black);
    if (lenRadius.getValue() == null) {
      valid = false;
      lenLabel.setForeground(Color.red);
    }
    JLabel smallLabel = (JLabel) ((JPanel) getComponent(1)).getComponent(0);
    JFormattedTextField smallRadius =
        (JFormattedTextField) ((JPanel) getComponent(1)).getComponent(1);
    JComboBox<String> smallRadiusMetric =
        (JComboBox<String>) ((JPanel) getComponent(1)).getComponent(2);
    smallLabel.setForeground(Color.black);
    if (smallRadius.getValue() == null) {
      valid = false;
      smallLabel.setForeground(Color.red);
    }

    JLabel bigLabel = (JLabel) ((JPanel) getComponent(2)).getComponent(0);
    JFormattedTextField bigRadius =
        (JFormattedTextField) ((JPanel) getComponent(2)).getComponent(1);
    JComboBox<String> bigRadiusMetric =
        (JComboBox<String>) ((JPanel) getComponent(2)).getComponent(2);
    bigLabel.setForeground(Color.black);
    if (bigRadius.getValue() == null) {
      valid = false;
      bigLabel.setForeground(Color.red);
    }

    double minimumValue =
        METRIC.toMilimeter((Long) smallRadius.getValue(), smallRadiusMetric.getSelectedIndex());
    double maxmimumValue =
        METRIC.toMilimeter((Long) bigRadius.getValue(), bigRadiusMetric.getSelectedIndex());

    if (minimumValue > maxmimumValue) {
      smallLabel.setForeground(Color.red);
      bigLabel.setForeground(Color.red);
      valid = false;
    }

    boolean one = false;
    for (JCheckBox chk : selection) {
      if (chk.isSelected()) {
        one = true;
        break;
      }
    }
    if (!one) {
      label2.setForeground(Color.red);
      valid = false;
    } else {
      label2.setForeground(Color.black);
    }

    if (!valid) {
      return;
    }

    List<Product> selectedProducts = new ArrayList<Product>();
    for (int index = 0; index < selection.size(); index++) {
      if (selection.get(index).isSelected()) {
        selectedProducts.add(products.get(index));
      }
    }

    Map<String, Object> targetData = new HashMap<String, Object>();
    targetData.put("IDPLATE_LABEL", "Test");
    targetData.put("SELECTED_PRODUCTS", selectedProducts);
    DefaultCutOptionsCalculatorData data = new DefaultCutOptionsCalculatorData();
    data.setSelectedProducts(selectedProducts);

    List<LumberStack> stacks = LumberStackDAO.getAllstack();
    List<LumberLog> lumberLogs = new ArrayList<>();
    for (long start = (Long) smallRadius.getValue(); start < (Long) bigRadius.getValue(); start++) {
      LumberLog lumberLog = new LumberLog();
      lumberLog.setSmallRadius((double) start);
      List<Double> middleRadius = new ArrayList<>();
      middleRadius.add((double) start);
      lumberLog.setMediumRadius(middleRadius);
      lumberLog.setBigRadius((double) start);
      double lengthValue =
          METRIC.toMilimeter((Long) lenRadius.getValue(), lenRadiusMetric.getSelectedIndex());
      lumberLog.setLength(lengthValue);
      lumberLog.setRealLength((long) lengthValue);
      IDPlate plate = new IDPlate();
      plate.setId(-1L);
      LumberStack stack = LumberLogUtil.findLumberStack(lumberLog, stacks);
      String label = "Diametru " + start;
      if (stack != null) {
        label += " " + stack.getName();
      }
      plate.setLabel(label);
      lumberLog.setPlate(plate);
      LumberLogUtil.calculateVolume(lumberLog);
      lumberLogs.add(lumberLog);
    }
    data.setLumberLogs(lumberLogs);
    new CutOptionsTargetFrame(targetData, data);
    GUITools.closeParentDialog(this);
  }