示例#1
0
  /**
   * Adds the componentType buttons to the Panel of Main Window.
   *
   * @param pkg_name whose componentType buttons will be added
   * @param a needed for the addition of the ActionListener of respective buttons and calling method
   *     of Pad_Draw
   */
  public void add_componentType_buttons(package_cls pkg_name, final counts a) {
    int i;
    JLabel pkg_hdng = new JLabel(pkg_name.getName());
    panel.add(pkg_hdng);
    for (i = 0; i < pkg_name.getComponentType_list().size(); i++) {
      final componentType cmp_Types = pkg_name.getComponentType_list().get(i);
      int btnHeight, btnWidth;
      double scale = 0.5;
      btnWidth = (int) (scale * (double) cmp_Types.getWidth());
      btnHeight = (int) (scale * (double) cmp_Types.getHeight());
      ImageIcon myIcon = new ImageIcon(cmp_Types.getType_Img());

      BufferedImage bi = new BufferedImage(btnWidth, btnHeight, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g = bi.createGraphics();
      g.scale(scale, scale);
      myIcon.paintIcon(null, g, 0, 0);
      g.dispose();

      JButton strctButton = new JButton(new ImageIcon(bi));
      strctButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              drawPad.add_componentType(cmp_Types, a);
              taskbar.setText("Click to add a component");
            }
          });
      panel.add(strctButton);
    }
    panel.validate(); // Updates the Panel
  }
示例#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);
    }
  }