コード例 #1
0
  private void removeItem(Object obj, Field field, int index) {
    final JScrollBar sb = genericTagPropertiesEditPanelScrollPanel.getVerticalScrollBar();
    final int val = sb.getValue(); // save scroll top
    SWFType swfType = field.getAnnotation(SWFType.class);
    if (swfType != null
        && !swfType
            .countField()
            .isEmpty()) { // Fields with same countField must be removed from too
      Field[] fields = obj.getClass().getDeclaredFields();
      for (int f = 0; f < fields.length; f++) {
        SWFType fieldSwfType = fields[f].getAnnotation(SWFType.class);
        if (fieldSwfType != null && fieldSwfType.countField().equals(swfType.countField())) {
          ReflectionTools.removeFromField(obj, fields[f], index);
        }
      }
      try {
        // If countField exists, decrement, otherwise do nothing
        Field countField = obj.getClass().getDeclaredField(swfType.countField());
        int cnt = countField.getInt(obj);
        cnt--;
        countField.setInt(obj, cnt);
      } catch (NoSuchFieldException
          | SecurityException
          | IllegalArgumentException
          | IllegalAccessException ex) {
        // ignored
      }
    } else {
      ReflectionTools.removeFromField(obj, field, index);
    }

    generateEditControls(editedTag, false);

    // Restore scroll top after some time. TODO: Handle this better. I don't know how :-(.
    new Thread() {

      @Override
      public void run() {
        try {
          Thread.sleep(500);
        } catch (InterruptedException ex) {
          logger.log(Level.SEVERE, null, ex);
        }

        View.execInEventDispatch(
            () -> {
              genericTagPropertiesEditPanelScrollPanel.getVerticalScrollBar().setValue(val);
            });
      }
    }.start();
    revalidate();
    repaint();
  }
コード例 #2
0
 private void setTagText(Tag tag) {
   clear();
   generateEditControls(tag, true);
   StringBuilder val = new StringBuilder();
   for (String key : keys) {
     GenericTagEditor ed = editors.get(key);
     if (((Component) ed).isVisible()) {
       val.append(key).append(" : ").append(ed.getReadOnlyValue()).append("<br>");
     }
   }
   // HTML for colors:
   val.insert(0, "<html>").append("</html>");
   genericTagPropertiesEditorPane.setContentType("text/html");
   genericTagPropertiesEditorPane.setText(val.toString());
   genericTagPropertiesEditorPane.setCaretPosition(0);
   hdr.setText(tag.toString());
 }
コード例 #3
0
  public void setEditMode(boolean edit, Tag tag) {
    if (tag == null) {
      tag = this.tag;
    }

    this.tag = tag;
    this.editedTag = Helper.deepCopy(tag);
    generateEditControls(editedTag, !edit);

    if (edit) {
      remove(genericTagPropertiesEditorPaneScrollPanel);
      add(genericTagPropertiesEditPanelScrollPanel, BorderLayout.CENTER);
    } else {
      genericTagPropertiesEditPanel.removeAll();
      genericTagPropertiesEditPanel.setSize(0, 0);
      remove(genericTagPropertiesEditPanelScrollPanel);
      add(genericTagPropertiesEditorPaneScrollPanel, BorderLayout.CENTER);
      setTagText(this.tag);
    }
    revalidate();
    repaint();
  }