Ejemplo n.º 1
0
  private static Glyph readChild(Element parentElem)
      throws IllegalAccessException, InstantiationException {
    int type = Integer.parseInt(parentElem.getAttribute("type"));
    Glyph parentGlyph;
    Class className = ClassContainer.getClass(type);
    if (className.equals(ImageGlyph.class)) {
      parentGlyph = new ImageGlyph(type);
    } else if (className.equals(Ex_ImageGlyph_withText.class)) {
      parentGlyph = new Ex_ImageGlyph_withText(type);
    } else {
      parentGlyph = (Glyph) className.newInstance();
    }
    parentGlyph.setType(type);
    parentGlyph.setName(parentElem.getAttribute("name"));

    NodeList elemList = parentElem.getChildNodes();
    ArrayList<Point> pointList = new ArrayList<Point>();
    for (int i = 0; i < elemList.getLength(); i++) {
      Element pointElem = (Element) elemList.item(i);
      if (pointElem.getNodeName().equals("point")) {
        double x = Double.parseDouble(pointElem.getAttribute("x"));
        double y = Double.parseDouble(pointElem.getAttribute("y"));
        Point point = new Point();
        point.setLocation(x, y);
        pointList.add(point);
      }
    }
    Point[] aPoints = new Point[pointList.size()];
    pointList.toArray(aPoints);
    parentGlyph.setCoo(aPoints);

    parentGlyph.setAngle(Double.parseDouble(parentElem.getAttribute("angle")));
    parentGlyph.setText(parentElem.getAttribute("text"));
    parentGlyph.setEditable(Boolean.parseBoolean(parentElem.getAttribute("editable")));
    Color color = new Color(Integer.parseInt(parentElem.getAttribute("color")));
    parentGlyph.setColor(color);

    for (int i = 0; i < elemList.getLength(); i++) {
      Element pointElem = (Element) elemList.item(i);
      if (pointElem.getNodeName().equals("Glyph")) {
        Element childElem = (Element) elemList.item(i);
        Glyph childGlyph = readChild(childElem);
        parentGlyph.addChild(childGlyph);
      }
    }
    parentGlyph.recalc();
    return parentGlyph;
  }
Ejemplo n.º 2
0
  /**
   * Применить атрибут глифу
   *
   * @param glyph Глиф
   * @param attrId Аттрибут
   */
  protected void applyAttributeToGlyph(Glyph glyph, AttributeHolder.Attribute attrId) {
    HashMap attrMap = attrHolder.getAttrMap();
    switch (attrId) {
      case ATTR_UID:
        Integer uid = (Integer) attrMap.get(attrId);
        glyph.setId(uid);
        break;

      case ATTR_TYPE:
        Integer type = (Integer) attrMap.get(attrId);
        glyph.setType(type);
        break;

      case ATTR_COLOR:
        Color color = (Color) attrMap.get(attrId);
        glyph.setColor(color);
        break;

      case ATTR_TEXT:
        String text = (String) attrMap.get(attrId);
        glyph.setText(text);
        break;

      case ATTR_STATUS:
        Integer intVal = (Integer) attrMap.get(attrId);
        glyph.setStatus(intVal);
        break;

      case ATTR_COORDS:
        Point[] aPoints = (Point[]) attrMap.get(attrId);
        glyph.setCoo(aPoints);
        break;

      case ATTR_EDIT:
        Boolean b = (Boolean) attrMap.get(attrId);
        glyph.setEditable(b);
        break;
    }
  }