Exemple #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
  }
 private JButton makeGoButton(
     @NotNull final String toolTipText, @NotNull final Icon icon, final int direction) {
   final JButton button = new JButton(icon);
   button.setEnabled(false);
   button.addMouseListener(
       new MouseAdapter() {
         @Override
         public void mouseClicked(MouseEvent e) {
           if (e.getClickCount() == 1) {
             Platform.runLater(() -> myEngine.getHistory().go(direction));
           }
         }
       });
   button.setToolTipText(toolTipText);
   return button;
 }
Exemple #3
0
 public void parseButton(Element elm) {
   JButton btn = new JButton();
   String title = elm.getAttribute("title");
   if (title != null) {
     btn.setText(title);
   }
   SpazPosition lp = parseSpazPosition(elm);
   if (lp == null) {
     return;
   }
   this.add(btn, lp);
   parseBorder(btn, elm);
   parseAttributes(elm, btn);
   String action = elm.getAttribute("action");
   if (action.length() > 0) {
     actions.put(btn, action);
     btn.addActionListener(this);
   }
 }
 private void addButtonsAvailabilityListeners(JButton backButton, JButton forwardButton) {
   Platform.runLater(
       () ->
           myEngine
               .getLoadWorker()
               .stateProperty()
               .addListener(
                   (ov, oldState, newState) -> {
                     if (newState == Worker.State.SUCCEEDED) {
                       final WebHistory history = myEngine.getHistory();
                       boolean isGoBackAvailable = history.getCurrentIndex() > 0;
                       boolean isGoForwardAvailable =
                           history.getCurrentIndex() < history.getEntries().size() - 1;
                       ApplicationManager.getApplication()
                           .invokeLater(
                               () -> {
                                 backButton.setEnabled(isGoBackAvailable);
                                 forwardButton.setEnabled(isGoForwardAvailable);
                               });
                     }
                   }));
 }
  public void addBackAndOpenButtons() {
    ApplicationManager.getApplication()
        .invokeLater(
            () -> {
              final JPanel panel = new JPanel();
              panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

              final JButton backButton =
                  makeGoButton("Click to go back", AllIcons.Actions.Back, -1);
              final JButton forwardButton =
                  makeGoButton("Click to go forward", AllIcons.Actions.Forward, 1);
              final JButton openInBrowser = new JButton(AllIcons.Actions.Browser_externalJavaDoc);
              openInBrowser.addActionListener(e -> BrowserUtil.browse(myEngine.getLocation()));
              openInBrowser.setToolTipText("Click to open link in browser");
              addButtonsAvailabilityListeners(backButton, forwardButton);

              panel.setMaximumSize(new Dimension(40, getPanel().getHeight()));
              panel.add(backButton);
              panel.add(forwardButton);
              panel.add(openInBrowser);

              add(panel, BorderLayout.PAGE_START);
            });
  }
Exemple #6
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);
    }
  }