예제 #1
0
  /**
   * @param path_ret where the file will be saved
   * @param a getting the information of current status of the editor
   * @param cnc_a getting the information of current status of the editor
   * @throws ParserConfigurationException
   * @throws IOException
   */
  public void save(String tempPath, counts a, connections cnc_a)
      throws ParserConfigurationException, IOException {
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactoryImpl.newInstance();
      // get an instance of builder
      DocumentBuilder db = dbf.newDocumentBuilder();
      // create an instance of DOM
      Document dom = db.newDocument();

      Element el_root = dom.createElement("circuit");
      dom.appendChild(el_root);

      // Root of the components
      Element cmp_root = dom.createElement("components");
      el_root.appendChild(cmp_root);
      for (component x : a.getComponent_list()) {
        Element cmpEle = this.createCmpEle(x, dom);
        cmp_root.appendChild(cmpEle);
      }

      // Root of the components
      Element wire_root = dom.createElement("wires");
      el_root.appendChild(wire_root);
      for (line x : cnc_a.getLine_logs()) {
        Element wireEle = null;
        if (x.getId() > 0) {
          wireEle = this.createWireEle(x, dom);
          wire_root.appendChild(wireEle);
        }
      }

      OutputFormat format = new OutputFormat();
      XMLSerializer serializer =
          new XMLSerializer(new FileOutputStream(new File(tempPath)), format);

      serializer.serialize(dom);
      this.changeTitle(new File(tempPath).getName());
      this.setSaved(true);
      this.setPath(tempPath);
      taskbar.setText("File is saved successfully.");
    } catch (FileNotFoundException ex) {
      Logger.getLogger(Pad_Draw.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
예제 #2
0
  /**
   * Creates an Element(or Node in XML in Document d) for single component
   *
   * @param x the component for which Element will be created
   * @param d Where the element will be added
   * @return the Element(for XML) created from component x
   */
  private Element createCmpEle(component x, Document d) {
    Element cmp_el = d.createElement("comp");
    cmp_el.setAttribute("id", String.valueOf(x.getId()));

    Element type_el = d.createElement("comp_type_id");
    Text type_txt = d.createTextNode(String.valueOf(x.getType().getId()));
    type_el.appendChild(type_txt);
    cmp_el.appendChild(type_el);

    Element pkg_el = d.createElement("pkg_name");
    Text pkg_txt = d.createTextNode(x.getType().getType_pkg_name());
    pkg_el.appendChild(pkg_txt);
    cmp_el.appendChild(pkg_el);

    Element pos_el = d.createElement("position");

    Element x_el = d.createElement("x");
    Text x_txt = d.createTextNode(String.valueOf(x.getPosition().x));
    x_el.appendChild(x_txt);
    pos_el.appendChild(x_el);

    Element y_el = d.createElement("y");
    Text y_txt = d.createTextNode(String.valueOf(x.getPosition().y));
    y_el.appendChild(y_txt);
    pos_el.appendChild(y_el);

    cmp_el.appendChild(pos_el);

    return cmp_el;
  }
예제 #3
0
  /**
   * Creates an Element(or Node in XML in Document d) for single line
   *
   * @param x the line for which Element will be created
   * @param d Where the element will be added
   * @return the Element(for XML) created from line x
   */
  private Element createWireEle(line x, Document d) {
    Element wire_el = d.createElement("wire");
    wire_el.setAttribute("id", String.valueOf(x.getId()));

    Element strt_el = d.createElement("start");
    Element strt_cmp_el = d.createElement("comp_id");
    Text strt_cmp_txt = d.createTextNode(String.valueOf(x.getStartCmpId()));
    strt_cmp_el.appendChild(strt_cmp_txt);
    Element strt_mrk_el = d.createElement("mark_point");
    Text strt_mrk_txt = d.createTextNode(String.valueOf(x.getStartMrkPt()));
    strt_mrk_el.appendChild(strt_mrk_txt);
    strt_el.appendChild(strt_cmp_el);
    strt_el.appendChild(strt_mrk_el);
    wire_el.appendChild(strt_el);

    Element inter_el = d.createElement("inter_point");
    inter_el.setAttribute("no", String.valueOf(x.getInter_Line_segs().size()));
    for (Point p : x.getInter_Line_segs()) {
      Element pos_el = d.createElement("position");

      Element x_el = d.createElement("x");
      Text x_txt = d.createTextNode(String.valueOf(p.x));
      x_el.appendChild(x_txt);
      pos_el.appendChild(x_el);
      Element y_el = d.createElement("y");
      Text y_txt = d.createTextNode(String.valueOf(p.y));
      y_el.appendChild(y_txt);
      pos_el.appendChild(y_el);

      inter_el.appendChild(pos_el);
    }
    wire_el.appendChild(inter_el);

    Element end_el = d.createElement("end");
    Element end_cmp_el = d.createElement("comp_id");
    Text end_cmp_txt = d.createTextNode(String.valueOf(x.getEndCmpId()));
    end_cmp_el.appendChild(end_cmp_txt);
    Element end_mrk_el = d.createElement("mark_point");
    Text end_mrk_txt = d.createTextNode(String.valueOf(x.getEndMrkPt()));
    end_mrk_el.appendChild(end_mrk_txt);
    end_el.appendChild(end_cmp_el);
    end_el.appendChild(end_mrk_el);
    wire_el.appendChild(end_el);

    return wire_el;
  }