Пример #1
0
  @Override
  public JComponent createUI(
      DescriptionType inputOrOutput, Map<URI, Object> dataMap, Orientation orientation) {
    // Create the main panel
    JComponent component = new JPanel(new MigLayout("fill"));

    boolean isOptional = false;
    if (inputOrOutput instanceof InputDescriptionType) {
      isOptional =
          ((InputDescriptionType) inputOrOutput).getMinOccurs().equals(new BigInteger("0"));
    }
    // Display the SourceCA into a JTextField
    JTextField jtf = new JTextField();
    jtf.setToolTipText(inputOrOutput.getAbstract().get(0).getValue());
    // "Save" the CA inside the JTextField
    jtf.getDocument().putProperty(DATA_MAP_PROPERTY, dataMap);
    URI uri = URI.create(inputOrOutput.getIdentifier().getValue());
    jtf.getDocument().putProperty(URI_PROPERTY, uri);
    // add the listener for the text changes in the JTextField
    jtf.getDocument()
        .addDocumentListener(
            EventHandler.create(DocumentListener.class, this, "saveDocumentText", "document"));
    if (isOptional) {
      if (dataMap.containsKey(uri)) {
        jtf.setText(dataMap.get(uri).toString());
      }
    }

    GeometryData geometryData = null;
    if (inputOrOutput instanceof InputDescriptionType) {
      geometryData =
          (GeometryData) ((InputDescriptionType) inputOrOutput).getDataDescription().getValue();
    }
    // If the DescriptionType is an output, there is nothing to show, so exit
    if (geometryData == null) {
      return null;
    }

    component.add(jtf, "growx");

    if (orientation.equals(Orientation.VERTICAL)) {
      JPanel buttonPanel = new JPanel(new MigLayout());

      // Create the button Browse
      JButton pasteButton = new JButton(ToolBoxIcon.getIcon(ToolBoxIcon.PASTE));
      // "Save" the sourceCA and the JTextField in the button
      pasteButton.putClientProperty(TEXT_FIELD_PROPERTY, jtf);
      pasteButton.setBorderPainted(false);
      pasteButton.setContentAreaFilled(false);
      pasteButton.setMargin(new Insets(0, 0, 0, 0));
      // Add the listener for the click on the button
      pasteButton.addActionListener(EventHandler.create(ActionListener.class, this, "onPaste", ""));
      buttonPanel.add(pasteButton);

      component.add(buttonPanel, "dock east");
    }

    return component;
  }
Пример #2
0
 @Override
 public ImageIcon getIconFromData(DescriptionType inputOrOutput) {
   return ToolBoxIcon.getIcon(ToolBoxIcon.RAW_DATA);
 }