Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
0
  /**
   * Set the value of panel
   *
   * @param newVar the new value of panel
   */
  private void setPanel(final counts a, final connections cnc_a) {

    // creates a JPanel
    panel = new JPanel();
    panel.setLayout(new ModifiedFlowLayout());

    JButton clearButton = new JButton("CLEAR");
    clearButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            drawPad.clear(a, cnc_a);
            taskbar.setText(null);
          }
        });

    JButton wireButton = new JButton("WIRE ");
    wireButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            drawPad.wire(cnc_a, a);
            taskbar.setText("Add Wire by Mouse click.");
          }
        });

    JButton slctButton = new JButton("SELECT");
    slctButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            drawPad.select(a, cnc_a);
            taskbar.setText("Press & Drag to move component");
          }
        });

    JButton showOutputButton = new JButton("Show Output");
    showOutputButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            drawPad.showOutputs(a, cnc_a);
            taskbar.setText("Click Hide Output, otherwise it will behave unpredictably");
          }
        });

    JButton hideOutputButton = new JButton("Hide Output");
    hideOutputButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            drawPad.hideOutputs(a, cnc_a);
            taskbar.setText("Hide the Circuit component Expressions");
          }
        });

    // adds the buttons to the panel
    panel.add(clearButton);
    panel.add(wireButton);
    panel.add(slctButton);
    panel.add(showOutputButton);
    panel.add(hideOutputButton);

    // Default System Packages have some componentType-s. Those buttons are installed
    for (package_cls x : a.getPackage_list()) {
      this.add_componentType_buttons(x, a);
    }
  }