Exemple #1
0
  /**
   * Update the contents of the icon based on the SVG data in the associated "_iconDescription"
   * parameter, if there is one.
   */
  private void _updateContents() throws Exception {
    if (_description == null) {
      return;
    }

    String text = _description.value();
    Reader in = new StringReader(text);
    XmlDocument document = new XmlDocument((URL) null);
    XmlReader reader = new XmlReader();
    reader.parse(document, in);

    XmlElement root = document.getRoot();

    _generateContents(root);

    // FIXME: What to do about the _smallIconDescription?
  }
  /**
   * Return a new widget for configuring the container.
   *
   * @return A JPanel that is a text editor for editing the annotation text.
   */
  public Component createEditorPane() {
    _textArea = new JTextArea();
    _iconDescription = (ConfigurableAttribute) _container.getAttribute("_iconDescription");

    if (_iconDescription == null) {
      try {
        _iconDescription = new SingletonConfigurableAttribute(_container, "_iconDescription");
      } catch (KernelException ex) {
        // Cannot occur.
        throw new InternalErrorException(ex.toString());
      }
    }

    // Parse the SVG to find the text.
    String text = _iconDescription.getExpression();

    // Default font characteristics.
    _fontSize = "14";
    _fontFamily = "SansSerif";
    _fontColor = "blue";

    try {
      Reader in = new StringReader(text);

      // NOTE: Do we need a base here?
      XmlDocument document = new XmlDocument((URL) null);
      XmlReader reader = new XmlReader();
      reader.parse(document, in);

      XmlElement root = document.getRoot();
      String name = root.getType();

      if (name.equals("svg")) {
        Iterator children = root.elements();

        while (children.hasNext()) {
          XmlElement child = (XmlElement) children.next();
          name = child.getType();

          if (name.equals("text")) {
            text = child.getPCData();

            String style = (String) child.getAttributeMap().get("style");

            if (style != null) {
              StringTokenizer tokenizer = new StringTokenizer(style, ";");

              while (tokenizer.hasMoreTokens()) {
                String token = tokenizer.nextToken();
                int colon = token.indexOf(":");

                if (colon > 0) {
                  String property = token.substring(0, colon).trim();

                  if (property.equals("fill")) {
                    _fontColor = token.substring(colon + 1);
                  } else if (property.equals("font-size")) {
                    _fontSize = token.substring(colon + 1);
                  } else if (property.equals("font-family")) {
                    _fontFamily = token.substring(colon + 1);
                  }
                }
              }
            }

            // We are done once we find a text element.
            break;
          }
        }
      }
    } catch (Exception ex) {
      // If we fail, then we use the text as is.
    }

    _textArea.setText(text);

    AnnotationTextEditor editor = new AnnotationTextEditor(_textArea);
    return editor;
  }