예제 #1
0
 // ------------------------------
 public void
     scrollToCaret() { // not called - fixed with putting visible scrollbars on JScrollPane
   //
   Rectangle rect1 = scroller1.getViewport().getViewRect();
   double x1 = rect1.getX();
   double y1 = rect1.getY();
   double r1height = rect1.getHeight();
   double r1width = rect1.getWidth();
   Caret caret1 = editor1.getCaret();
   Point pt2 = caret1.getMagicCaretPosition(); // the end of the string
   double x2 = pt2.getX();
   double y2 = pt2.getY();
   if (((x2 > x1) && (x2 < (x1 + r1width))) && ((y2 > y1) && (y2 < (y1 + r1height)))) {
     // inview
   } else {
     double newheight = r1height / 2;
     double newwidth = r1width / 2;
     double x3 = pt2.getX() - newwidth;
     double y3 = pt2.getY() - newheight;
     if (x3 < 0) x3 = 0;
     if (y3 < 0) y3 = 0;
     Rectangle rect3 = new Rectangle((int) x3, (int) y3, (int) newwidth, (int) newheight);
     editor1.scrollRectToVisible(rect3);
   }
 } // end scrollToCaret
예제 #2
0
 private void setGraphicsCenter(Graphics2D graphics2D, SpriteLocation center) {
   Rectangle screen = graphics2D.getClipBounds();
   SpriteLocation screenCenter =
       new SpriteLocation(
           screen.getX() + screen.getWidth() * 0.5, screen.getY() + screen.getHeight() * 0.5);
   center = screenCenter.sub(center);
   graphics2D.translate(center.getX(), center.getY());
 }
 /** Returns the coordinates of the top left corner of the value at the given index. */
 public Point getCoordinates(int index) {
   JScrollBar bar = scrollPane.getVerticalScrollBar();
   Rectangle r = pinsTable.getCellRect(index, 2, true);
   pinsTable.scrollRectToVisible(r);
   return new Point(
       (int) (r.getX() + topLevelLocation.getX()),
       (int) (r.getY() + topLevelLocation.getY() - bar.getValue()));
 }
예제 #4
0
 @NotNull
 private static List<EditorWindow> findWindowsInRow(
     @NotNull EditorWindow anchor, @NotNull List<EditorWindow> windows, final boolean vertical) {
   final Rectangle anchorRect = getEditorWindowRectangle(anchor);
   if (anchorRect != null) {
     final List<EditorWindow> result = new ArrayList<EditorWindow>();
     final double coord = vertical ? anchorRect.getX() : anchorRect.getY();
     for (EditorWindow window : windows) {
       final Rectangle rect = getEditorWindowRectangle(window);
       if (rect != null) {
         final double min = vertical ? rect.getX() : rect.getY();
         final double max = min + (vertical ? rect.getWidth() : rect.getHeight());
         if (coord >= min && coord <= max) {
           result.add(window);
         }
       }
     }
     Collections.sort(
         result,
         new Comparator<EditorWindow>() {
           @Override
           public int compare(EditorWindow window1, EditorWindow window2) {
             final Rectangle rect1 = getEditorWindowRectangle(window1);
             final Rectangle rect2 = getEditorWindowRectangle(window2);
             if (rect1 != null && rect2 != null) {
               final double diff =
                   vertical ? (rect1.getY() - rect2.getY()) : (rect1.getX() - rect2.getX());
               return diff < 0 ? -1 : diff > 0 ? 1 : 0;
             }
             return 0;
           }
         });
     return result;
   }
   return Collections.singletonList(anchor);
 }
  /**
   * Method to check that the current position is in the viewing area and if not scroll to center
   * the current position if possible
   */
  public void checkScroll() {
    // get the x and y position in pixels
    int xPos = (int) (colIndex * zoomFactor);
    int yPos = (int) (rowIndex * zoomFactor);

    // only do this if the image is larger than normal
    if (zoomFactor > 1) {

      // get the rectangle that defines the current view
      JViewport viewport = scrollPane.getViewport();
      Rectangle rect = viewport.getViewRect();
      int rectMinX = (int) rect.getX();
      int rectWidth = (int) rect.getWidth();
      int rectMaxX = rectMinX + rectWidth - 1;
      int rectMinY = (int) rect.getY();
      int rectHeight = (int) rect.getHeight();
      int rectMaxY = rectMinY + rectHeight - 1;

      // get the maximum possible x and y index
      int macolIndexX = (int) (picture.getWidth() * zoomFactor) - rectWidth - 1;
      int macolIndexY = (int) (picture.getHeight() * zoomFactor) - rectHeight - 1;

      // calculate how to position the current position in the middle of the viewing
      // area
      int viewX = xPos - (int) (rectWidth / 2);
      int viewY = yPos - (int) (rectHeight / 2);

      // reposition the viewX and viewY if outside allowed values
      if (viewX < 0) viewX = 0;
      else if (viewX > macolIndexX) viewX = macolIndexX;
      if (viewY < 0) viewY = 0;
      else if (viewY > macolIndexY) viewY = macolIndexY;

      // move the viewport upper left point
      viewport.scrollRectToVisible(new Rectangle(viewX, viewY, rectWidth, rectHeight));
    }
  }
예제 #6
0
  public void showDialog(boolean showReplace) {
    getReplaceLabel().setVisible(showReplace);
    getReplaceTextField().setVisible(showReplace);
    getReplaceButton().setVisible(showReplace);
    getReplaceAllButton().setVisible(showReplace);
    if (showReplace) {
      setTitle("Replace");
      getRootPane().setDefaultButton(getReplaceButton());
      getReplaceFindButton().setText("Find...");
      getReplaceFindButton().setMnemonic('d');
      getReplaceFindButton().setDisplayedMnemonicIndex(3);
    } else {
      setTitle("Find");
      getRootPane().setDefaultButton(getFindNextButton());
      getReplaceFindButton().setText("Replace...");
      getReplaceFindButton().setMnemonic('R');
      getReplaceFindButton().setDisplayedMnemonicIndex(0);
    }

    pack();

    if (!initLoc && editor != null) {
      Rectangle bounds = editor.getBounds();
      Dimension size = getSize();

      setLocation(
          (int) (bounds.getX() + (bounds.getWidth() - size.getWidth()) / 2),
          (int) (bounds.getY() + (bounds.getHeight() - size.getHeight()) / 2));
      initLoc = true;
    }

    // Bugfix [2664844] - Editor: Find (set cursor position)
    getFindTextField().requestFocus();

    setVisible(true);
  }
예제 #7
0
    public void paintComponent(Graphics g) {
      Rectangle selection = g.getClipBounds();

      // clear out the image
      Graphics2D g2 = (Graphics2D) g;
      g2.setBackground(backgroundColor);
      g2.clearRect(
          (int) selection.getX(),
          (int) selection.getY(),
          (int) selection.getWidth(),
          (int) selection.getHeight());

      // draw the selection if it exists
      if (selBeginPixel != -1 && selEndPixel != -1) {
        g2.setBackground(selectionColor);
        g2.clearRect(selBeginPixel, 0, selEndPixel - selBeginPixel + 1, this.getHeight());
      }

      if (this.points.size() > 0) {
        g2.setColor(waveColor);
        // draw the lines
        if (this.points.size() > stemThresh) {
          if (points.size() > frameWidth) { // draw contour
            // g2.setStroke(thickerStroke);
            for (int i = 0; i < this.points.size() - 1; i += 4) {
              Point2D.Float pt1 = points.get(i).getDispPoint();
              // Point2D.Float pt2  = new Point2D.Float(pt1.x, pt1.y/2);
              Point2D.Float pt2 = points.get(i + 1).getDispPoint();
              Point2D.Float pt3 = points.get(i + 2).getDispPoint();
              Point2D.Float pt4 = points.get(i + 3).getDispPoint();

              //							//Point2D.Float pt4  = new Point2D.Float(pt2.x, pt2.y/2);
              g2.draw(new Line2D.Float(pt1, pt2));
              // g2.setColor(waveLiteColor);
              g.setColor(waveLiteColor);
              g2.draw(new Line2D.Float(pt2, pt3));
              g2.setColor(waveColor);
              g2.draw(new Line2D.Float(pt3, pt4));
              //							g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
              //									this.points.get(i+1).getDispPoint()));
              //							g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
              //									this.points.get(i+1).getDispPoint()));
              //							g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
              //									this.points.get(i+1).getDispPoint()));
            }

          } else { // draw line
            g2.setStroke(stroke);
            for (int i = 0; i < this.points.size() - 1; i++) {
              g2.draw(
                  new Line2D.Float(
                      this.points.get(i).getDispPoint(), this.points.get(i + 1).getDispPoint()));
            }
          }
        } else { // stem plot
          for (int i = 0; i < this.points.size(); i++) {
            // draw the stem
            SoundSample sample = this.points.get(i);
            g2.setStroke(thickerStroke);
            Point2D.Double base =
                new Point2D.Double(
                    sample.getDispPoint().getX() + 10, Math.floor(this.getHeight()) / 2);
            Point2D.Double pt =
                new Point2D.Double(sample.getDispPoint().getX() + 10, sample.getDispPoint().getY());
            g2.draw(new Line2D.Float(base, pt));

            if (this.points.size() < zoomThresh) {
              // draw the sample value
              float sampleValue = (float) sample.getSampleValue();
              float y = (float) sample.getDispPoint().getY();
              g2.setFont(textFont);
              if (y < Math.floor(this.getHeight()) / 2) y = y - 10;
              else y = y + 10;
              // if (sample.getDispPoint().getX() > 0)
              g2.drawString(formatter.format(sampleValue), (float) sample.getDispPoint().getX(), y);
            }

            // draw the vertical bar in the array
            //						g2.setStroke(thickerStroke);
            //						base = new Point2D.Double(base.getX()-8, this.getHeight() - 10);
            //						pt = new Point2D.Double(base.getX(), this.getHeight() - 50);
            //						g2.draw(new Line2D.Double(base, pt));
            //						g2.drawString(formatter.format(points.get(i).getSampleIndex()),
            // (float)base.getX(), (float)base.getY() - 10 );
          }
          //
          //					g2.setStroke(wideStroke);
          //					//draw the array cells
          //					g2.draw(new Line2D.Double(selection.getX(),
          //							Math.floor(this.getHeight() - 30),
          //							selection.getX()+selection.getWidth()-1,
          //							Math.floor(this.getHeight() - 30)));
          //					//draw the array cells
          //					g2.draw(new Line2D.Double(selection.getX(),
          //							Math.floor(this.getHeight() - 10),
          //							selection.getX()+selection.getWidth()-1,
          //							Math.floor(this.getHeight() - 10)));
        }
      }

      // draw the center line
      g2.setColor(barColor);
      g2.setStroke(new BasicStroke(1));
      g2.draw(
          new Line2D.Double(
              selection.getX(),
              Math.floor(this.getHeight() / 2),
              selection.getX() + selection.getWidth() - 1,
              Math.floor(this.getHeight() / 2)));

      //			//draw the current position
      //			if (selection.getX()<currentPixelPosition &&
      //					currentPixelPosition<(selection.getX()+selection.getWidth()-1))
      //			{
      //				g2.setColor(barColor);
      //				g2.setStroke(new BasicStroke(1));
      //				g2.draw(new Line2D.Double(currentPixelPosition, 0,
      //						currentPixelPosition, frameHeight));
      //			}
    }
    private MouseEvent transformMouseEvent(MouseEvent event) {
      if (event == null) {
        throw new IllegalArgumentException("MouseEvent is null");
      }
      MouseEvent newEvent;
      if (event instanceof MouseWheelEvent) {
        MouseWheelEvent mouseWheelEvent = (MouseWheelEvent) event;
        newEvent =
            new MouseWheelEvent(
                mouseWheelEvent.getComponent(),
                mouseWheelEvent.getID(),
                mouseWheelEvent.getWhen(),
                mouseWheelEvent.getModifiers(),
                mouseWheelEvent.getX(),
                mouseWheelEvent.getY(),
                mouseWheelEvent.getClickCount(),
                mouseWheelEvent.isPopupTrigger(),
                mouseWheelEvent.getScrollType(),
                mouseWheelEvent.getScrollAmount(),
                mouseWheelEvent.getWheelRotation());
      } else {
        newEvent =
            new MouseEvent(
                event.getComponent(),
                event.getID(),
                event.getWhen(),
                event.getModifiers(),
                event.getX(),
                event.getY(),
                event.getClickCount(),
                event.isPopupTrigger(),
                event.getButton());
      }
      if (view != null && at.getDeterminant() != 0) {
        Rectangle viewBounds = getTransformedSize();
        Insets insets = JXTransformer.this.getInsets();
        int xgap = (getWidth() - (viewBounds.width + insets.left + insets.right)) / 2;
        int ygap = (getHeight() - (viewBounds.height + insets.top + insets.bottom)) / 2;

        double x = newEvent.getX() + viewBounds.getX() - insets.left;
        double y = newEvent.getY() + viewBounds.getY() - insets.top;
        Point2D p = new Point2D.Double(x - xgap, y - ygap);

        Point2D tp;
        try {
          tp = at.inverseTransform(p, null);
        } catch (NoninvertibleTransformException ex) {
          // can't happen, we check it before
          throw new AssertionError("NoninvertibleTransformException");
        }
        // Use transformed coordinates to get the current component
        mouseCurrentComponent =
            SwingUtilities.getDeepestComponentAt(view, (int) tp.getX(), (int) tp.getY());
        if (mouseCurrentComponent == null) {
          mouseCurrentComponent = JXTransformer.this;
        }
        Component tempComponent = mouseCurrentComponent;
        if (mouseDraggedComponent != null) {
          tempComponent = mouseDraggedComponent;
        }

        Point point =
            SwingUtilities.convertPoint(view, (int) tp.getX(), (int) tp.getY(), tempComponent);
        newEvent.setSource(tempComponent);
        newEvent.translatePoint(point.x - event.getX(), point.y - event.getY());
      }
      return newEvent;
    }
예제 #9
0
 public void scrollRects() {
   for (Rectangle i : rectList) {
     i.setLocation((int) (i.getX()), (int) (i.getY() + (int) (player1.getVelocity() * 0.3)));
   }
 }