示例#1
0
  /**
   * Creates new form SiteType
   *
   * @param title
   * @param type
   */
  public SiteTypes(String title, String type) {
    super(title, type);
    setMode(EDIT_MODE);
    initComponents();
    fillTypes();

    PlainDocument addNameDoc = (PlainDocument) tfAddName.getDocument();
    addNameDoc.setDocumentFilter(new utils.MyDocFilter(InputType.TEXT15));

    PlainDocument updateNameDoc = (PlainDocument) tfUpdateName.getDocument();
    updateNameDoc.setDocumentFilter(new utils.MyDocFilter(InputType.TEXT15));

    lstTypes.addListSelectionListener(
        new ListSelectionListener() {

          @Override
          public void valueChanged(ListSelectionEvent e) {
            boolean isItemSelected = lstTypes.getSelectedIndex() != -1;
            btnRemove.setEnabled(isItemSelected);
            btnUpdate.setEnabled(isItemSelected);
            if (isItemSelected) {
              tfUpdateName.setText(lstTypes.getSelectedValue().toString());
            }
          }
        });
    if (lstTypes.getModel().getSize() > 0) {
      lstTypes.setSelectedIndex(0);
    }
  }
  public static void setHexadecimalInputFilter(
      JTextComponent textComponent, int maximumInputLength) {
    PlainDocument plainDocument = (PlainDocument) textComponent.getDocument();
    plainDocument.setDocumentFilter(new HexadecimalInputFilter(maximumInputLength));

    String text = textComponent.getText();
    text = trimHexadecimal(text);

    if (text.length() > maximumInputLength) {
      textComponent.setText(text.substring(text.length() - maximumInputLength, text.length()));
    } else {
      while (text.length() < maximumInputLength) {
        text = "0" + text;
      }

      textComponent.setText(text);
    }
  }
  @Override
  protected Document createDefaultModel() {
    PlainDocument d = (PlainDocument) super.createDefaultModel();

    d.setDocumentFilter(
        new DocumentFilter() {
          @Override
          public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
              throws BadLocationException {
            replace(fb, offset, 0, string, attr);
          }

          @Override
          public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
            replace(fb, offset, length, "", null);
          }

          @Override
          public void replace(
              FilterBypass fb, int replOffset, int replLen, String string, AttributeSet attrs)
              throws BadLocationException {
            String s = JMathTextField.this.getText();
            boolean insertedDummyChar = false;
            boolean insertedBrackets = false;
            String replStr = s.substring(replOffset, replOffset + replLen);

            if (string.matches(" |\\)")
                && replOffset + 1 <= s.length()
                && s.substring(replOffset, replOffset + 1).equals(string)) {
              JMathTextField.this.setCaretPosition(replOffset + 1);
              return;
            }

            if (string.isEmpty() && replStr.equals(" ")) {
              JMathTextField.this.setCaretPosition(replOffset);
              return;
            }

            string = string.replace(" ", "");
            if (string.isEmpty() && replStr.equals("(")) {
              int count = 1;
              while (replOffset + replLen < s.length()) {
                replLen++;
                replStr =
                    s.substring(
                        replOffset,
                        replOffset + replLen); // just update in case we need it later again
                if (replStr.charAt(0) == '(') count++;
                else if (replStr.charAt(0) == ')') count--;
                if (count == 0) break;
              }
            } else if (string.isEmpty() && replStr.equals(")")) {
              int count = -1;
              while (replOffset > 0) {
                replOffset--;
                replLen++;
                replStr = s.substring(replOffset, replOffset + replLen);
                if (replStr.charAt(0) == '(') count++;
                else if (replStr.charAt(0) == ')') count--;
                if (count == 0) break;
              }
            }

            if (string.matches("\\+|-|\\*|/|\\^|=")) {
              if (s.substring(replOffset + replLen).matches("( *(\\+|-|∙|/|\\^|=|\\)).*)|")) {
                string = string + "_";
                insertedDummyChar = true;
              } else if (s.substring(replOffset + replLen).matches(" .*")) {
                string = "_" + string;
                insertedDummyChar = true;
              }
            } else if (string.matches("\\(")) {
              if (Utils.reveresedString(s.substring(0, replOffset))
                      .matches("( )*([^\\+\\-∙/\\^= ].*|)")
                  || replStr.equals("_")) {
                string = "(_)";
                insertedDummyChar = true;
              } else if (!replStr.isEmpty()) {
                string = "(" + replStr + ")";
                insertedBrackets = true;
              } else return; // ignore this
            } else if (string.matches("\\)")) return; // ignore that

            // situation: A = B, press DEL -> make it A = _
            if (string.isEmpty()
                && Utils.reveresedString(s.substring(0, replOffset))
                    .matches("( )*(\\+|-|∙|/|\\^|=).*")
                && !replStr.matches("_|\\+|-|∙|/|\\^|=")) {
              string = "_";
              insertedDummyChar = true;
            } else if (string.isEmpty()
                && Utils.reveresedString(s.substring(0, replOffset))
                    .matches("( )*(\\+|-|∙|/|\\^|=).*")
                && replStr.equals("_")) {
              while (s.substring(replOffset - 1, replOffset).equals(" ")) {
                replOffset--;
                replLen++;
              }
              replOffset--;
              replLen++; // go just before the op
              // just update in case we need it later again
              // noinspection UnusedAssignment
              replStr = s.substring(replOffset, replOffset + replLen);
            }

            setNewString(
                fb, s.substring(0, replOffset) + string + s.substring(replOffset + replLen));

            if (insertedDummyChar) {
              int p = JMathTextField.this.getText().indexOf('_');
              if (p >= 0) {
                JMathTextField.this.setCaretPosition(p);
                JMathTextField.this.moveCaretPosition(p + 1);
              }
            } else if (insertedBrackets) {
              // move just before the ')'
              if (JMathTextField.this.getCaretPosition() > 0)
                JMathTextField.this.setCaretPosition(JMathTextField.this.getCaretPosition() - 1);
            }
          }

          synchronized void setNewString(FilterBypass fb, String tempStr)
              throws BadLocationException {
            operatorTree = OTParser.parse(tempStr, null);
            JMathTextField.this.updateByOpTree(fb);
          }
        });

    return d;
  }
示例#4
0
 public void setDocumentFilter(JTextField textField, DocumentFilter filter) {
   PlainDocument pd = (PlainDocument) textField.getDocument();
   pd.setDocumentFilter(filter);
 }
  private void init() {
    emailSalon = new MyTextField("Email du salon");
    pointsPrix = new javax.swing.JRadioButton();
    pointsService = new javax.swing.JRadioButton();
    jLabel1 = new javax.swing.JLabel();
    prixParPoint = new MyTextField("0");
    pointsParCoupe = new MyTextField("0");
    pointsParCouleur = new MyTextField("0");
    pointsParCoiffure = new MyTextField("0");
    pointsParAutre = new MyTextField("0");
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    sauvegarder = new javax.swing.JButton();

    setPreferredSize(new java.awt.Dimension(970, 559));

    if (settings.isPointsPrix()) {
      refreshSelection(POINT_PRIX);
    } else if (settings.isPointsService()) refreshSelection(POINT_SERVICE);

    if (!settings.getEmailSalon().equals("")) {
      emailSalon.setText(settings.getEmailSalon());
      emailSalon.setForeground(Color.BLACK);
    }

    if (Float.toString(settings.getPrixParPoint()) != "") {
      prixParPoint.setText(Float.toString(settings.getPrixParPoint()));
      prixParPoint.setForeground(Color.BLACK);
    }

    if (Integer.toString(settings.getPointsParCoupe()) != "") {
      pointsParCoupe.setText(Integer.toString(settings.getPointsParCoupe()));
      pointsParCoupe.setForeground(Color.BLACK);
    }

    if (Integer.toString(settings.getPointsParCouleur()) != "") {
      pointsParCouleur.setText(Integer.toString(settings.getPointsParCouleur()));
      pointsParCouleur.setForeground(Color.BLACK);
    }

    if (Integer.toString(settings.getPointsParCoiffure()) != "") {
      pointsParCoiffure.setText(Integer.toString(settings.getPointsParCoiffure()));
      pointsParCoiffure.setForeground(Color.BLACK);
    }

    if (Integer.toString(settings.getPointsParAutre()) != "") {
      pointsParAutre.setText(Integer.toString(settings.getPointsParAutre()));
      pointsParAutre.setForeground(Color.BLACK);
    }

    pointsPrix.addMouseListener(clickListener);
    pointsService.addMouseListener(clickListener);

    PlainDocument plainDocument = (PlainDocument) pointsParAutre.getDocument();
    plainDocument.setDocumentFilter(new MyIntFilter(""));

    plainDocument = (PlainDocument) pointsParCoiffure.getDocument();
    plainDocument.setDocumentFilter(new MyIntFilter(""));

    plainDocument = (PlainDocument) pointsParCouleur.getDocument();
    plainDocument.setDocumentFilter(new MyIntFilter(""));

    plainDocument = (PlainDocument) pointsParCoupe.getDocument();
    plainDocument.setDocumentFilter(new MyIntFilter(""));

    emailSalon.setFont(new java.awt.Font("Calibri", 0, 36)); // NOI18N

    pointsPrix.setText("Points en fonction du prix");

    pointsService.setText("Points en fonction du service");

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
    jLabel1.setText("€ = 1 point");

    prixParPoint.setFont(new java.awt.Font("Calibri", 0, 24)); // NOI18N

    jLabel2.setText("points pour la coupe");

    jLabel3.setText("points pour la couleur");

    jLabel4.setText("points pour autre chose");

    jLabel5.setText("points pour la coiffure");

    sauvegarder.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
    sauvegarder.setText("Sauvegarder");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addGap(166, 166, 166)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(pointsPrix)
                                    .addGap(163, 163, 163)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(pointsService)
                                            .addGroup(
                                                layout
                                                    .createSequentialGroup()
                                                    .addGroup(
                                                        layout
                                                            .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment
                                                                    .TRAILING,
                                                                false)
                                                            .addComponent(pointsParCoupe)
                                                            .addComponent(pointsParCouleur)
                                                            .addComponent(pointsParCoiffure)
                                                            .addComponent(
                                                                pointsParAutre,
                                                                javax.swing.GroupLayout.Alignment
                                                                    .LEADING,
                                                                javax.swing.GroupLayout
                                                                    .PREFERRED_SIZE,
                                                                70,
                                                                javax.swing.GroupLayout
                                                                    .PREFERRED_SIZE))
                                                    .addGap(22, 22, 22)
                                                    .addGroup(
                                                        layout
                                                            .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment
                                                                    .LEADING)
                                                            .addComponent(jLabel2)
                                                            .addComponent(jLabel5)
                                                            .addComponent(jLabel3)
                                                            .addComponent(jLabel4)
                                                            .addComponent(
                                                                sauvegarder,
                                                                javax.swing.GroupLayout
                                                                    .PREFERRED_SIZE,
                                                                290,
                                                                javax.swing.GroupLayout
                                                                    .PREFERRED_SIZE)))))
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(
                                        prixParPoint,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        112,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel1))
                            .addComponent(
                                emailSalon,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                613,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(213, Short.MAX_VALUE)));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addGap(59, 59, 59)
                    .addComponent(
                        emailSalon,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        76,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(96, 96, 96)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(pointsPrix)
                            .addComponent(pointsService))
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addGap(36, 36, 36)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel1)
                                            .addComponent(
                                                prixParPoint,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                103,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addGap(35, 35, 35)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(
                                                pointsParCoupe,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel2))
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel3)
                                            .addComponent(
                                                pointsParCouleur,
                                                javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(
                                                pointsParCoiffure,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel5))))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(
                                pointsParAutre,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                    .addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED, 98, Short.MAX_VALUE)
                    .addComponent(
                        sauvegarder,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        62,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(42, 42, 42)));
  }