Example #1
0
 /** Adds a new label at the end */
 private void createNewLabel() {
   TagLabel tl = createTagLabel("");
   pTagValues.add(tl);
   refreshCommas();
   tlEditing = tl;
   tl.beginEdit();
 }
Example #2
0
 /** Tells all the labels to draw a comma after the tag value, except for the last one */
 private void refreshCommas() {
   for (int i = 0; i < pTagValues.getComponentCount(); i++) {
     JComponent c = (JComponent) pTagValues.getComponent(i);
     if (c instanceof TagLabel) {
       ((TagLabel) c).setAddComma(i < pTagValues.getComponentCount() - 1);
     }
   }
 }
Example #3
0
  /**
   * Creates a new TagLabel with the given tag value and subscribes to its events
   *
   * @param tagValue the text to show in the TagLabel
   * @return the created TagLabel
   */
  private TagLabel createTagLabel(String tagValue) {
    final TagLabel tl = new TagLabel(tagValue);
    tl.addTagLabelListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals(TagLabel.ACTION_COMMAND_BEGIN_EDIT)) {
              tlEditing = tl;
            } else if (e.getActionCommand().equals(TagLabel.ACTION_COMMAND_DELETE)) {
              pTagValues.remove(tl);
              refreshCommas();
            } else if (e.getActionCommand().equals(TagLabel.ACTION_COMMAND_END_EDIT)) {
              tlEditing = null;
            } else if (e.getActionCommand().equals(TagLabel.ACTION_COMMAND_NEW_TAGVALUE)) {
              tlEditing.applyEdit();
              createNewLabel();
            }

            // propagate every event
            fireActionEvent(e.getActionCommand());
          }
        });
    return tl;
  }