public void actionPerformed(ActionEvent e) {

          if ((e.getSource() instanceof JMenuItem)) {
            JMenuItem item = (JMenuItem) e.getSource();
            int lineNumber = Math.round(item.getAlignmentX() * 1000000);
            TextArea ta = OJ.editor.getTextArea();
            String txt = ta.getText();
            int lines = 0;
            int selBegin = 0;
            int selEnd = 0;
            for (int charPos = 0; charPos < txt.length(); charPos++) {
              if (txt.charAt(charPos) == '\n') {
                lines++;
                if (lines == (lineNumber + 1)) {
                  selEnd = charPos;
                  break;
                }
                selBegin = charPos;
              }
            }
            ij.IJ.showStatus("" + lineNumber);
            ta.select(selBegin + 1, selEnd + 1);
            IJ.wait(500);
            ta.setCaretPosition(selBegin + 1);
            ta.setVisible(true);
            ta.requestFocus();
            OJ.editor.setIsMacroWindow(true);
          }
        }
Example #2
0
  /*
   * (non-Javadoc)
   *
   * @see br.arca.morcego.Component#paint(java.awt.Graphics)
   */
  public void paint(Graphics g) {
    // TODO: paint a fancy textbox with description of node

    Graphics2D graphic = (Graphics2D) g;

    TextArea textArea = new TextArea(text);

    textArea.setLocation(0, 0);
    textArea.setVisible(true);

    Font font = new Font(null, Font.PLAIN, 10);

    FontRenderContext frc = new FontRenderContext(null, false, false);

    TextLayout l = new TextLayout(text, font, frc);

    Rectangle2D textBounds = l.getBounds();

    int margin = Config.getInteger(Config.descriptionMargin);
    int border = 1;
    int distX = 5;
    int distY = 5;

    int width = (int) textBounds.getWidth() + 2 * margin + 2 * border;
    int height = (int) textBounds.getHeight() + 2 * margin + 2 * border;

    int cornerX = originX - width - distX;
    int cornerY = originY - height - distY;

    if (cornerX < 0) {
      cornerX = 0;
    }
    if (cornerY < 0) {
      cornerY = 0;
    }

    graphic.setColor(Config.getColor(Config.descriptionBorder));
    graphic.fillRect(
        cornerX - margin - border,
        cornerY - margin - border,
        (int) textBounds.getWidth() + 2 * margin + 2 * border,
        (int) textBounds.getHeight() + 2 * margin + 2 * border);

    graphic.setColor(Config.getColor(Config.descriptionBackground));

    graphic.fillRect(
        cornerX - margin,
        cornerY - margin,
        (int) textBounds.getWidth() + 2 * margin,
        (int) textBounds.getHeight() + 2 * margin);

    graphic.setColor(Config.getColor(Config.descriptionColor));
    textArea.paint(g);

    l.draw(graphic, cornerX, cornerY + (int) textBounds.getHeight());
  }