示例#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
  }
  JPanel createCustomPanel() {
    Box p = new Box(BoxLayout.PAGE_AXIS);

    // left operand sink
    leftSink = new PartSink(PartType.EXPRESSION_PART);
    leftSink.addCombineListener(
        new CombineListener() {
          public void combined() {
            WorkspaceObject c = leftSink.getContainedPart();
            Object o = c.getPart();
            Expression exp = (Expression) o;
            op.setLeftOperand(exp);
          }

          public void split() {
            op.setLeftOperand(null);
          }
        });
    p.add(leftSink);

    JLabel eqLab = new JLabel("<html><b>&divide;</b></html>");
    p.add(eqLab);

    // right operand sink
    rightSink = new PartSink(PartType.EXPRESSION_PART);
    rightSink.addCombineListener(
        new CombineListener() {
          public void combined() {
            WorkspaceObject c = rightSink.getContainedPart();
            Object o = c.getPart();
            Expression exp = (Expression) o;
            op.setRightOperand(exp);
          }

          public void split() {
            op.setRightOperand(null);
          }
        });
    p.add(rightSink);

    JPanel retPanel = new JPanel();
    retPanel.setLayout(new BorderLayout());
    retPanel.add(p, BorderLayout.CENTER);
    return retPanel;
  }
    @Override
    protected void paintComponent(Graphics g) {

      super.paintComponent(g);

      if (resourceImage != null) {

        g.drawImage(resourceImage, 1, 1, this);
      }
    }
  JPanel createCustomPanel() {
    JPanel p = new JPanel();
    p.setLayout(new GridLayout(1, 1));
    sink = new PartSink(PartType.EXPRESSION_PART);
    sink.addCombineListener(
        new CombineListener() {
          public void combined() {
            WorkspaceObject c = sink.getContainedPart();
            Object o = c.getPart(); // we know this is an expression because of our sink restriction
            Expression exp = (Expression) o;
            randInt.setMax(exp);
          }

          public void split() {
            randInt.setMax(null);
          }
        });
    sink.setToolTipText("Maximum possible value of the random number");
    p.add(sink);
    return p;
  }
  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);
            });
  }
示例#6
0
  public DOMTreeView(Document dom) {
    super("TreeWalkerView ");

    document = dom;
    // jtree  UI setup
    jtree = new DOMTreeFull((Node) document);
    jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Listen for when the selection changes, call nodeSelected(node)
    jtree.addTreeSelectionListener(
        new TreeSelectionListener() {
          public void valueChanged(TreeSelectionEvent e) {
            TreePath path = (TreePath) e.getPath();
            TreeNode treeNode = (TreeNode) path.getLastPathComponent();
            if (jtree.getSelectionModel().isPathSelected(path)) nodeSelected(treeNode);
          }
        });

    treeScroll = new JScrollPane(jtree);
    treeScroll.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("DOM Tree View"),
            BorderFactory.createEmptyBorder(4, 4, 4, 4)));

    JPanel urlPanel = new JPanel();
    JLabel urlLabel = new JLabel("URL:");
    urlTextField = new JTextField(50);
    urlTextField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            Object source = evt.getSource();
            if (source == urlTextField) {
              reloadJTree(urlTextField.getText());
            }
          }
        });
    urlPanel.add(urlLabel);
    urlPanel.add(urlTextField);

    JPanel selectedXPathPanel = new JPanel();
    JLabel xpathLabel = new JLabel("XPath: ");
    selectedXPathTextField = new JTextField(50);
    selectedXPathTextField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            Object source = evt.getSource();
            if (source == selectedXPathTextField) {
              lookupByXPath(selectedXPathTextField.getText());
            }
          }
        });
    selectedXPathPanel.add(xpathLabel);
    selectedXPathPanel.add(selectedXPathTextField);

    JPanel lookupPanel = new JPanel();
    JLabel lookupLabel = new JLabel("look up:");
    lookupTextField = new JTextField(20);
    lookupTextField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            Object source = evt.getSource();
            if (source == lookupTextField) {
              lookup(lookupTextField.getText());
            }
          }
        });
    foundList = new JList();
    foundList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    foundList.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent evt) {
            Object source = evt.getSource();
            if (source == foundList) {
              FoundItem fi = (FoundItem) foundList.getSelectedValue();
              if (fi == null) return;
              jtree.setSelectionPath(fi.treePath);
              jtree.scrollPathToVisible(fi.treePath);
            }
          }
        });

    JScrollPane foundScroll = new JScrollPane(foundList);
    foundScroll.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Nodes found"),
            BorderFactory.createEmptyBorder(4, 4, 4, 4)));
    // foundScroll.set
    JPanel queryPanel = new JPanel();
    queryPanel.add(lookupLabel);
    queryPanel.add(lookupTextField);
    lookupPanel.setLayout(new BorderLayout());
    lookupPanel.add(queryPanel, BorderLayout.NORTH);
    lookupPanel.add(foundScroll, BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeScroll, lookupPanel);
    splitPane.setContinuousLayout(true);
    splitPane.setOneTouchExpandable(true);

    splitPane.setDividerLocation(400);

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.add(urlPanel, BorderLayout.NORTH);
    mainPanel.add(selectedXPathPanel, BorderLayout.SOUTH);
    mainPanel.add(splitPane, BorderLayout.CENTER);
    // mainPanel.add(treeScroll, BorderLayout.CENTER);
    // mainPanel.add(lookupPanel, BorderLayout.EAST);

    getContentPane().add(mainPanel);
  }
示例#7
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);
    }
  }