Esempio n. 1
0
  private void updateEditorView() {
    editorPane.setText("");
    numParameters = 0;
    try {
      java.util.List elements = editableTemplate.getPrintfElements();
      for (Iterator it = elements.iterator(); it.hasNext(); ) {
        PrintfUtil.PrintfElement el = (PrintfUtil.PrintfElement) it.next();
        if (el.getFormat().equals(PrintfUtil.PrintfElement.FORMAT_NONE)) {
          appendText(el.getElement(), PLAIN_ATTR);
        } else {
          insertParameter(
              (ConfigParamDescr) paramKeys.get(el.getElement()),
              el.getFormat(),
              editorPane.getDocument().getLength());
        }
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          this,
          "Invalid Format: " + ex.getMessage(),
          "Invalid Printf Format",
          JOptionPane.ERROR_MESSAGE);

      selectedPane = 1;
      printfTabPane.setSelectedIndex(selectedPane);
      updatePane(selectedPane);
    }
  }
Esempio n. 2
0
  public PrintfEditor(Frame frame, String title) {
    super(frame, title, false);

    originalTemplate = new PrintfTemplate();
    editableTemplate = new PrintfTemplate();
    try {
      jbInit();
      pack();
      initMatches();
    } catch (Exception exc) {
      String logMessage = "Could not set up the printf editor";
      logger.critical(logMessage, exc);
      JOptionPane.showMessageDialog(frame, logMessage, "Printf Editor", JOptionPane.ERROR_MESSAGE);
    }
  }
Esempio n. 3
0
  void okButton_actionPerformed(ActionEvent e) {
    int num_rows = filtersTable.getRowCount();
    EditableDefinablePlugin edp = m_data.getPlugin();
    for (int row = 0; row < num_rows; row++) {
      String mimeType = (String) filtersTable.getValueAt(row, 0);
      String mimeTypeValue = (String) filtersTable.getValueAt(row, 1);

      try {
        mimeTypeEditorBuilder.checkValue(edp, mimeType, mimeTypeValue);
      } catch (DynamicallyLoadedComponentException dlce) {
        String logMessage =
            "Failed to set the "
                + mimeTypeEditorBuilder.getValueName()
                + " for MIME type "
                + mimeType
                + " to "
                + mimeTypeValue;
        logger.error(logMessage, dlce);
        if (!EDPInspectorTableModel.handleDynamicallyLoadedComponentException(this, dlce)) {
          return;
        } else {
          logger.debug("User override; allow " + mimeTypeValue);
        }
      }
    }
    mimeTypeEditorBuilder.clear(edp);
    for (int row = 0; row < num_rows; row++) {
      String mimeType = (String) filtersTable.getValueAt(row, 0);
      String mimeTypeValue = (String) filtersTable.getValueAt(row, 1);

      try {
        mimeTypeEditorBuilder.put(edp, mimeType, mimeTypeValue);
      } catch (DynamicallyLoadedComponentException dlce) {
        String logMessage =
            "Internal error; MIME type " + mimeType + " not set to " + mimeTypeValue;
        logger.error(logMessage, dlce);
      } catch (PluginException.InvalidDefinition ex) {
        JOptionPane.showMessageDialog(
            this,
            ex.getMessage(),
            WordUtils.capitalize(mimeTypeEditorBuilder.getValueName()) + " Warning",
            JOptionPane.WARNING_MESSAGE);
      }
    }
    setVisible(false);
  }
Esempio n. 4
0
 public MimeTypeEditor(
     MimeTypeEditorBuilder mimeTypeEditorBuilder, Frame frame, String title, boolean modal) {
   super(frame, title, modal);
   this.mimeTypeEditorBuilder = mimeTypeEditorBuilder;
   this.m_model = new MimeTypeTableModel();
   try {
     jbInit();
     pack();
   } catch (Exception exc) {
     String logMessage =
         "Could not set up the " + mimeTypeEditorBuilder.getValueName() + " editor";
     logger.critical(logMessage, exc);
     JOptionPane.showMessageDialog(
         frame,
         logMessage,
         WordUtils.capitalize(mimeTypeEditorBuilder.getValueName()) + " Editor",
         JOptionPane.ERROR_MESSAGE);
   }
 }
Esempio n. 5
0
 void insertMatchButton_actionPerformed(ActionEvent e) {
   String key = (String) matchComboBox.getSelectedItem();
   String format = (String) matchesKeys.get(key);
   if (key.equals(STRING_LITERAL)) {
     format =
         escapeReservedChars(
             (String)
                 JOptionPane.showInputDialog(
                     this,
                     "Enter the string you wish to match",
                     "String Literal Input",
                     JOptionPane.OK_CANCEL_OPTION));
     if (StringUtil.isNullString(format)) {
       return;
     }
   }
   if (selectedPane == 0) {
     insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
   } else {
     // add the combobox data value to the edit box
     int pos = formatTextArea.getCaretPosition();
     formatTextArea.insert(format, pos);
   }
 }
Esempio n. 6
0
  void insertButton_actionPerformed(ActionEvent e) {
    Object selected = paramComboBox.getSelectedItem();
    ConfigParamDescr descr;
    String key;
    int type = 0;
    String format = "";
    if (selected instanceof ConfigParamDescr) {
      descr = (ConfigParamDescr) selected;
      key = descr.getKey();
      type = descr.getType();
      switch (type) {
        case ConfigParamDescr.TYPE_STRING:
        case ConfigParamDescr.TYPE_URL:
        case ConfigParamDescr.TYPE_BOOLEAN:
          format = "%s";
          break;
        case ConfigParamDescr.TYPE_INT:
        case ConfigParamDescr.TYPE_LONG:
        case ConfigParamDescr.TYPE_POS_INT:
          NumericPaddingDialog dialog = new NumericPaddingDialog();
          Point pos = this.getLocationOnScreen();
          dialog.setLocation(pos.x, pos.y);
          dialog.pack();
          dialog.setVisible(true);
          StringBuilder fbuf = new StringBuilder("%");
          int width = dialog.getPaddingSize();
          boolean is_zero = dialog.useZero();
          if (width > 0) {
            fbuf.append(".");
            if (is_zero) {
              fbuf.append(0);
            }
            fbuf.append(width);
          }
          if (type == ConfigParamDescr.TYPE_LONG) {
            fbuf.append("ld");
          } else {
            fbuf.append("d");
          }
          format = fbuf.toString();
          break;
        case ConfigParamDescr.TYPE_YEAR:
          if (key.startsWith(DefinableArchivalUnit.PREFIX_AU_SHORT_YEAR)) {
            format = "%02d";
          } else {
            format = "%d";
          }
          break;
        case ConfigParamDescr.TYPE_RANGE:
        case ConfigParamDescr.TYPE_NUM_RANGE:
        case ConfigParamDescr.TYPE_SET:
          format = "%s";
          break;
      }
      if (selectedPane == 0) {
        insertParameter(descr, format, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        int pos = formatTextArea.getCaretPosition();
        formatTextArea.insert(format, pos);

        pos = parameterTextArea.getCaretPosition();
        parameterTextArea.insert(", " + key, pos);
      }
    } else {
      key = selected.toString();
      format =
          escapePrintfChars(
              (String)
                  JOptionPane.showInputDialog(
                      this,
                      "Enter the string you wish to input",
                      "String Literal Input",
                      JOptionPane.OK_CANCEL_OPTION));
      if (StringUtil.isNullString(format)) {
        return;
      }
      if (selectedPane == 0) {
        insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        formatTextArea.insert(format, formatTextArea.getCaretPosition());
      }
    }
  }