Esempio n. 1
0
 public void setValue(Object value) {
   if (value == null) {
     value = "";
   }
   if (inputType_.equals("ALPHA") || inputType_.equals("KANJI") || inputType_.equals("NUMERIC")) {
     if (inputType_.equals("ALPHA") || inputType_.equals("KANJI")) {
       // ((JTextField)component).setText(value.toString());
       String strValue = value.toString();
       if (strValue.length() > size_) {
         strValue = strValue.substring(0, size_);
       }
       ((JTextField) component).setText(strValue);
     }
     if (inputType_.equals("NUMERIC")) {
       String stringValue = "";
       if (decimal_ == 0) {
         stringValue =
             XFUtility.getFormattedIntegerValue(
                 getStringNumber(value.toString()), new ArrayList<String>(), size_);
       } else {
         stringValue =
             XFUtility.getFormattedFloatValue(getStringNumber(value.toString()), decimal_);
       }
       ((JTextField) component).setText(stringValue);
     }
     if (isAutoSizing) {
       int width = this.getBounds().width - 130;
       if (metrics.stringWidth(value.toString()) > width) {
         this.setBounds(
             this.getBounds().x,
             this.getBounds().y,
             metrics.stringWidth(value.toString()) + 130,
             this.getBounds().height);
       }
     }
   }
   if (inputType_.equals("DATE")) {
     ((XFDateField) component).setValue(value.toString());
   }
   if (inputType_.equals("LISTBOX")) {
     for (int i = 0; i < valueList.size(); i++) {
       if (value == valueList.get(i) || value.toString().equals(valueList.get(i).toString())) {
         ((JComboBox) component).setSelectedIndex(i);
         break;
       }
     }
   }
   if (inputType_.equals("CHECKBOX")) {
     if (value == Boolean.TRUE || value.toString().equals("true")) {
       ((JCheckBox) component).setSelected(true);
     } else {
       ((JCheckBox) component).setSelected(false);
     }
   }
 }
 public String getStringNumber(String text) {
   String numberString = XFUtility.getStringNumber(text);
   if (numberString.equals("")) {
     if (decimal_ == 0) {
       numberString = "0";
     }
     if (decimal_ == 1) {
       numberString = "0.0";
     }
     if (decimal_ == 2) {
       numberString = "0.00";
     }
     if (decimal_ == 3) {
       numberString = "0.000";
     }
     if (decimal_ == 4) {
       numberString = "0.0000";
     }
     if (decimal_ == 5) {
       numberString = "0.00000";
     }
     if (decimal_ == 6) {
       numberString = "0.000000";
     }
   }
   return numberString;
 }
 public void setEditable(boolean isEditable) {
   isEditable_ = isEditable;
   if (inputType_.equals("ALPHA") || inputType_.equals("KANJI") || inputType_.equals("NUMERIC")) {
     ((JTextField) component).setEditable(isEditable_);
     ((JTextField) component).setFocusable(isEditable_);
   }
   if (inputType_.equals("DATE")) {
     ((XFDateField) component).setEditable(isEditable_);
     ((XFDateField) component).setFocusable(isEditable_);
     int fieldWidth = XFUtility.getWidthOfDateValue(dialog_.getSession().getDateFormat(), 14);
     if (isEditable_) {
       this.setBounds(
           this.getBounds().x, this.getBounds().y, 150 + fieldWidth, XFUtility.FIELD_UNIT_HEIGHT);
     } else {
       this.setBounds(
           this.getBounds().x, this.getBounds().y, 124 + fieldWidth, XFUtility.FIELD_UNIT_HEIGHT);
     }
   }
   if (inputType_.equals("LISTBOX")) {
     ((JComboBox) component).setEditable(isEditable_);
     ((JComboBox) component).setFocusable(isEditable_);
   }
   if (inputType_.equals("CHECKBOX")) {
     ((JCheckBox) component).setEnabled(isEditable_);
     ((JCheckBox) component).setFocusable(isEditable_);
   }
 }
 public XFInputDialogField(
     String fieldCaption, String inputType, String parmID, XFInputDialog dialog) {
   super();
   parmID_ = parmID;
   if (!inputType.equals("ALPHA")
       && !inputType.equals("KANJI")
       && !inputType.equals("NUMERIC")
       && !inputType.equals("DATE")
       && !inputType.equals("LISTBOX")
       && !inputType.equals("CHECKBOX")) {
     inputType_ = "ALPHA";
   }
   inputType_ = inputType;
   dialog_ = dialog;
   jLabelField.setText(fieldCaption + " ");
   jLabelField.setFocusable(false);
   jLabelField.setHorizontalAlignment(SwingConstants.RIGHT);
   jLabelField.setVerticalAlignment(SwingConstants.TOP);
   jLabelField.setFont(new java.awt.Font("Dialog", 0, 14));
   metrics = jLabelField.getFontMetrics(new java.awt.Font("Dialog", 0, 14));
   jLabelField.setPreferredSize(new Dimension(120, XFUtility.FIELD_UNIT_HEIGHT));
   if (metrics.stringWidth(fieldCaption) > 120) {
     jLabelField.setFont(new java.awt.Font("Dialog", 0, 12));
     metrics = jLabelField.getFontMetrics(new java.awt.Font("Dialog", 0, 12));
     if (metrics.stringWidth(fieldCaption) > 120) {
       jLabelField.setFont(new java.awt.Font("Dialog", 0, 10));
     }
   }
   if (inputType_.equals("ALPHA") || inputType_.equals("KANJI") || inputType_.equals("NUMERIC")) {
     JTextField field = new JTextField();
     field.addFocusListener(new ComponentFocusListener());
     if (inputType_.equals("NUMERIC")) {
       field.setHorizontalAlignment(SwingConstants.RIGHT);
       field.setDocument(new LimitedDocument(this));
     }
     component = field;
   }
   if (inputType_.equals("DATE")) {
     XFDateField field = new XFDateField(dialog_.getSession());
     component = field;
   }
   if (inputType_.equals("LISTBOX")) {
     JComboBox field = new JComboBox();
     component = field;
   }
   if (inputType_.equals("CHECKBOX")) {
     JCheckBox field = new JCheckBox();
     component = field;
   }
   component.setFont(new java.awt.Font("Monospaced", 0, 14));
   metrics = component.getFontMetrics(new java.awt.Font("Monospaced", 0, 14));
   this.setOpaque(false);
   if (inputType_.equals("DATE")) {
     int fieldWidth = XFUtility.getWidthOfDateValue(dialog_.getSession().getDateFormat(), 14);
     this.setBounds(
         this.getBounds().x, this.getBounds().y, 150 + fieldWidth, XFUtility.FIELD_UNIT_HEIGHT);
   } else {
     this.setBounds(this.getBounds().x, this.getBounds().y, 150, XFUtility.FIELD_UNIT_HEIGHT);
   }
   this.setLayout(new BorderLayout());
   this.add(jLabelField, BorderLayout.WEST);
   this.add(component, BorderLayout.CENTER);
 }