Ejemplo n.º 1
0
 private static SVGFormComponent[] getFormComponents(final InputStream svgInputStream) {
   NamedElementsContentHandler ch = new NamedElementsContentHandler();
   try {
     XMLReader parser = XMLReaderFactory.createXMLReader();
     parser.setContentHandler(ch);
     parser.setEntityResolver(ch);
     parser.parse(new InputSource(svgInputStream));
   } catch (IOException ex) {
     Debug.warning(ex);
   } catch (SAXException ex) {
     Debug.warning(ex);
   }
   return ch.getFoundElements();
 }
  public static PropertyValue createFromSuggested(
      DesignComponent component,
      String suggestedMainName,
      Collection<String> additionalReservedNames) {
    assert component.getDocument().getTransactionManager().isAccess();
    Collection<? extends CodeNamePresenter> presenters =
        component.getPresenters(CodeNamePresenter.class);
    if (presenters.isEmpty())
      Debug.warning("CodeNamePresenter is missing for", component); // NOI18N
    HashSet<String> names = new HashSet<String>();
    gatherNames(component.getDocument().getRootComponent(), component, names);
    if (additionalReservedNames != null) names.addAll(additionalReservedNames);

    suggestedMainName = checkForJavaIdentifierCompliant(suggestedMainName);
    if (checkIfNameAlreadyReserved(presenters, suggestedMainName, names)) {
      int index = suggestedMainName.length();
      while (index >= 1 && Character.isDigit(suggestedMainName.charAt(index - 1))) index--;
      int number =
          index < suggestedMainName.length()
              ? Integer.parseInt(suggestedMainName.substring(index))
              : 1;
      suggestedMainName = suggestedMainName.substring(0, index);

      suggestedMainName = findNumberedInstanceName(presenters, suggestedMainName, number, names);
    }
    return MidpTypes.createStringValue(suggestedMainName);
  }
 @Override
 public Collection<DesignComponent> getChildren() {
   PropertyValue itemsValue = getComponent().readProperty(FormCD.PROP_ITEMS);
   ArrayList<DesignComponent> items = new ArrayList<DesignComponent>();
   Debug.collectAllComponentReferences(itemsValue, items);
   return items;
 }