예제 #1
0
  public FormatTestFrame() {
    JPanel buttonPanel = new JPanel();
    okButton = new JButton("Ok");
    buttonPanel.add(okButton);
    add(buttonPanel, BorderLayout.SOUTH);

    mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(0, 3));
    add(mainPanel, BorderLayout.CENTER);

    JFormattedTextField intField = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField.setValue(new Integer(100));
    addRow("Number:", intField);

    JFormattedTextField intField2 = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField2.setValue(new Integer(100));
    intField2.setFocusLostBehavior(JFormattedTextField.COMMIT);
    addRow("Number (Commit behavior):", intField2);

    JFormattedTextField intField3 =
        new JFormattedTextField(
            new InternationalFormatter(NumberFormat.getIntegerInstance()) {
              protected DocumentFilter getDocumentFilter() {
                return filter;
              }
            });
    intField3.setValue(new Integer(100));
    addRow("Filtered Number", intField3);

    JFormattedTextField intField4 = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField4.setValue(new Integer(100));
    intField4.setInputVerifier(
        new InputVerifier() {
          public boolean verify(JComponent component) {
            JFormattedTextField field = (JFormattedTextField) component;
            return field.isEditValid();
          }
        });
    addRow("Verified Number:", intField4);

    JFormattedTextField currencyField = new JFormattedTextField(NumberFormat.getCurrencyInstance());
    currencyField.setValue(new Double(10));
    addRow("Currency:", currencyField);

    JFormattedTextField dateField = new JFormattedTextField(DateFormat.getDateInstance());
    dateField.setValue(new Date());
    addRow("Date (default):", dateField);

    DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT);
    format.setLenient(false);
    JFormattedTextField dateField2 = new JFormattedTextField(format);
    dateField2.setValue(new Date());
    addRow("Date (short, not lenient):", dateField2);

    try {
      DefaultFormatter formatter = new DefaultFormatter();
      formatter.setOverwriteMode(false);
      JFormattedTextField urlField = new JFormattedTextField(formatter);
      urlField.setValue(new URL("http://java.sun.com"));
      addRow("URL:", urlField);
    } catch (MalformedURLException ex) {
      ex.printStackTrace();
    }

    try {
      MaskFormatter formatter = new MaskFormatter("###-##-####");
      formatter.setPlaceholderCharacter('0');
      JFormattedTextField ssnField = new JFormattedTextField(formatter);
      ssnField.setValue("078-05-1120");
      addRow("SSN Mask:", ssnField);
    } catch (ParseException ex) {
      ex.printStackTrace();
    }

    JFormattedTextField ipField = new JFormattedTextField(new IPAddressFormatter());
    ipField.setValue(new byte[] {(byte) 130, 65, 86, 66});
    addRow("IP Address:", ipField);
    pack();
  }
예제 #2
0
/**
 * This class is used in the model of the ACLTree. The MessageNode contains an ACLMessage, a
 * direction and a date/timestamp
 *
 * @author Chris van Aart - Acklin B.V., the Netherlands
 * @created April 26, 2002
 */
public class ACLMessageNode extends DefaultMutableTreeNode {

  /**
   * Constructor for the MessageNode object
   *
   * @param str Description of Parameter
   */
  ACLMessageNode(String str) {
    super(str);
  }

  /**
   * Gets the Message attribute of the MessageNode object
   *
   * @return The Message value
   */
  public ACLMessage getMessage() {
    return theMessage;
  }

  /**
   * Gets the Performative attribute of the MessageNode object
   *
   * @return The Performative value
   */
  public String getPerformative() {
    return theMessage.getPerformative(theMessage.getPerformative());
  }

  /**
   * Gets the SendTo attribute of the MessageNode object
   *
   * @return The SendTo value
   */
  public String getSendTo() {
    if (theMessage.getAllReceiver().hasNext()) {
      AID sender = (AID) theMessage.getAllReceiver().next();
      return sender.getName();
    }
    return "<unknown>";
  }

  /**
   * Gets the Ontology attribute of the MessageNode object
   *
   * @return The Ontology value
   */
  public String getOntology() {
    String ontology = theMessage.getOntology();
    if (ontology != null) {
      return ontology;
    }
    return "<unknown>";
  }

  /**
   * Gets the Direction attribute of the MessageNode object
   *
   * @return The Direction value
   */
  public String getDirection() {
    return direction;
  }

  public String getTime() {
    return time;
  }

  public Date getTheDate() {
    return theDate;
  }

  /**
   * Sets the Message attribute of the MessageNode object
   *
   * @param msg The new Message value
   */
  public void setMessage(ACLMessage msg) {
    theMessage = (ACLMessage) msg.clone();
  }

  /**
   * Sets the Direction attribute of the MessageNode object
   *
   * @param theDirection The new Direction value
   */
  public void setDirection(String theDirection) {
    direction = theDirection;
  }

  public void setTime(String theTime) {
    time = theTime;
    try {
      this.theDate = dateFormat.parse(time);
    } catch (Exception ex) {
      jade.util.Logger.getMyLogger(this.getClass().getName())
          .log(jade.util.Logger.WARNING, ex.getMessage());
    }
  }

  public void setTheDate(Date theTheDate) {
    theDate = theTheDate;
  }

  public String receivedFrom() {
    if (theMessage.getSender() != null) {
      AID sender = theMessage.getSender();
      return sender.getName();
    }
    return "<unknown>";
  }

  private static DateFormat dateFormat =
      DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
  private Date theDate = new Date();
  private ACLMessage theMessage;
  private String direction;
  private String time;
}