예제 #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;
  }
예제 #2
0
  /**
   * Заполнить держатель атрибутов
   *
   * @param gl Глиф, с которого получаем атрибуты
   * @return Получить хранитель атрибутов
   */
  public static AttributeHolder fillAttributeHolder(Glyph gl) {
    AttributeHolder attributeHolder = new AttributeHolder();
    Integer uid = gl.getId();
    attributeHolder.addAttr(AttributeHolder.Attribute.ATTR_UID, uid);
    Integer type = gl.getType();
    attributeHolder.addAttr(AttributeHolder.Attribute.ATTR_TYPE, type);
    Color color = gl.getColor();
    attributeHolder.addAttr(AttributeHolder.Attribute.ATTR_COLOR, color);
    String text = gl.getText();
    if (text != null) {
      attributeHolder.addAttr(AttributeHolder.Attribute.ATTR_TEXT, text);
    }
    int status = gl.getStatus();
    attributeHolder.addAttr(AttributeHolder.Attribute.ATTR_STATUS, status);
    Point[] aPoints = gl.getCoo();
    if (aPoints == null) {
      // Для отладки
      throw new NullPointerException(gl + " :has got null point array");
    }
    if (aPoints.length > 0) {
      attributeHolder.addAttr(AttributeHolder.Attribute.ATTR_COORDS, aPoints);
    }
    Boolean bEditable = gl.isEditable();
    attributeHolder.addAttr(AttributeHolder.Attribute.ATTR_EDIT, bEditable);

    return attributeHolder;
  }
예제 #3
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;
    }
  }