Example #1
1
  public String getTextForGesture(long parId, Point topLeft, Point bottomRight) {

    try {
      Paragraph p = lockManager.getParFromId(parId);

      int parY = documentPanel.textPane.modelToView(p.getOffset()).y;

      topLeft.y = topLeft.y + parY;
      bottomRight.y = bottomRight.y + parY;

      int startOffset = documentPanel.textPane.viewToModel(topLeft);
      int endOffset = documentPanel.textPane.viewToModel(bottomRight);

      while (startOffset > 0
          && Character.isLetterOrDigit((document.getText(startOffset - 1, 1).charAt(0))))
        startOffset--;

      while (endOffset < document.getLength()
          && Character.isLetterOrDigit((document.getText(endOffset, 1).charAt(0)))) endOffset++;

      String text = document.getText(startOffset, endOffset - startOffset);
      return text;
    } catch (Exception e) {
      System.out.println("EditorClient: addGestureAction. error identifying text");
      e.printStackTrace();
      return "";
    }

    // return "PLACEBO";
  }
Example #2
0
    public void mouseDragged(MouseEvent e) {
      int mods = e.getModifiersEx();
      Point dragEnd = e.getPoint();
      boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) > 0;
      boolean ctrl = (mods & MouseEvent.CTRL_DOWN_MASK) > 0;
      boolean alt = shift & ctrl;
      ctrl = ctrl & (!alt);
      shift = shift & (!alt);
      boolean nomods = !(shift | ctrl | alt);

      if (dragBegin == null) dragBegin = dragEnd;

      nodrag = false;

      if ((mods & InputEvent.BUTTON3_DOWN_MASK) > 0 || true) {
        double dx = dragEnd.getX() - dragBegin.getX();
        double dy = dragEnd.getY() - dragBegin.getY();

        synchronized (JImage.this) {
          t.preConcatenate(AffineTransform.getTranslateInstance(dx, dy));
        }

        dragBegin = dragEnd;
        repaint();
      }
    }
 private void centerComponents() {
   Rectangle bounds = getBounds();
   Point point = imageComponent.getLocation();
   point.x = (bounds.width - imageComponent.getWidth()) / 2;
   point.y = (bounds.height - imageComponent.getHeight()) / 2;
   imageComponent.setLocation(point);
 }
  public Component add(JInternalFrame frame) {
    JInternalFrame[] array = getAllFrames();
    Point p;
    int w;
    int h;

    Component retval = super.add(frame);
    checkDesktopSize();
    if (array.length > 0) {
      p = array[0].getLocation();
      p.x = p.x + FRAME_OFFSET;
      p.y = p.y + FRAME_OFFSET;
    } else {
      p = new Point(0, 0);
    }
    frame.setLocation(p.x, p.y);
    /* Jimmy: this is a bit buggy (frames get constant size)
    if (frame.isResizable()) {
        w = getWidth() - (getWidth()/3);
        h = getHeight() - (getHeight()/3);
        if (w < frame.getMinimumSize().getWidth()) w = (int)frame.getMinimumSize().getWidth();
        if (h < frame.getMinimumSize().getHeight()) h = (int)frame.getMinimumSize().getHeight();
        frame.setSize(w, h);
    }*/
    moveToFront(frame);
    frame.setVisible(true);
    try {
      frame.setSelected(true);
    } catch (PropertyVetoException e) {
      frame.toBack();
    }
    return retval;
  }
Example #5
0
  /**
   * method to negotiate draganddrop when mouse is pressed
   *
   * @param e
   */
  public void mousePressed(MouseEvent e) {
    /** Set up click point and set ActivePanel */
    Point p = e.getPoint();
    System.out.println(p);
    if (!setActivePanel(p)) return;

    /** record where the initial click occurred */
    OriP = activePanel;

    /** Check whether click was over an image label */
    selectedComponent = getImageLabel(p);
    if (selectedComponent == null) return;

    /** Check whether click was over waste box */
    if (selectedComponent.getName().equals("WasteBox")) return;

    /**
     * remove selected component from active panel add it to the glass panel set the offset and
     * original position
     */
    Rectangle labelR = selectedComponent.getBounds();
    Rectangle panelR = activePanel.getBounds();
    //  if(labelR.contains(p.x - panelR.x, p.y - panelR.y))
    //  {
    activePanel.remove(selectedComponent);
    selected = true;
    glassPanel.add(selectedComponent);
    offset.x = p.x - labelR.x - panelR.x;
    offset.y = p.y - labelR.y - panelR.y;
    dragging = true;
    Original = labelR.getLocation();
    //  }
  }
Example #6
0
  public static void requestFocus(Project project, final boolean useRobot) {
    JFrame frame = WindowManager.getInstance().getFrame(project);

    // the only reliable way I found to bring it to the top
    boolean aot = frame.isAlwaysOnTop();
    frame.setAlwaysOnTop(true);
    frame.setAlwaysOnTop(aot);

    int frameState = frame.getExtendedState();
    if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) {
      // restore the frame if it is minimized
      frame.setExtendedState(frameState ^ Frame.ICONIFIED);
    }
    frame.toFront();
    frame.requestFocus();
    if (useRobot && runningOnWindows7()) {
      try {
        // remember the last location of mouse
        final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();

        // simulate a mouse click on title bar of window
        Robot robot = new Robot();
        robot.mouseMove(frame.getX(), frame.getY());
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

        // move mouse to old location
        robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
      } catch (Exception ex) {
        // just ignore exception, or you can handle it as you want
      } finally {
        frame.setAlwaysOnTop(false);
      }
    }
  }
Example #7
0
  /** Write file with position and size of the login box */
  public static void writePersistence() {

    Messages.postDebug("LoginBox", "LoginBox.writePersistence");
    // If the panel has not been created, don't try to write a file
    if (position == null) return;

    String filepath = FileUtil.savePath("USER/PERSISTENCE/LoginPanel");

    FileWriter fw;
    PrintWriter os;
    try {
      File file = new File(filepath);
      fw = new FileWriter(file);
      os = new PrintWriter(fw);
      os.println("Login Panel");

      os.println(height);
      os.println(width);
      double xd = position.getX();
      int xi = (int) xd;
      os.println(xi);
      double yd = position.getY();
      int yi = (int) yd;
      os.println(yi);

      os.close();
    } catch (Exception er) {
      Messages.postError("Problem creating  " + filepath);
      Messages.writeStackTrace(er);
    }
  }
  /*
   *  This method is called every time:
   *  - to make sure the viewport is returned to its default position
   *  - to remove the horizontal scrollbar when it is not wanted
   */
  private void checkHorizontalScrollBar(BasicComboPopup popup) {
    //  Reset the viewport to the left

    JViewport viewport = scrollPane.getViewport();
    Point p = viewport.getViewPosition();
    p.x = 0;
    viewport.setViewPosition(p);

    //  Remove the scrollbar so it is never painted

    if (!scrollBarRequired) {
      scrollPane.setHorizontalScrollBar(null);
      return;
    }

    //	Make sure a horizontal scrollbar exists in the scrollpane

    JScrollBar horizontal = scrollPane.getHorizontalScrollBar();

    if (horizontal == null) {
      horizontal = new JScrollBar(JScrollBar.HORIZONTAL);
      scrollPane.setHorizontalScrollBar(horizontal);
      scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    }

    //	Potentially increase height of scroll pane to display the scrollbar

    if (horizontalScrollBarWillBeVisible(popup, scrollPane)) {
      Dimension scrollPaneSize = scrollPane.getPreferredSize();
      scrollPaneSize.height += horizontal.getPreferredSize().height;
      scrollPane.setPreferredSize(scrollPaneSize);
      scrollPane.setMaximumSize(scrollPaneSize);
      scrollPane.revalidate();
    }
  }
Example #9
0
  /**
   * Spusti se pri zmacknuti tlacitka. Pokud je pod mysi obraz figury, zjisti, zda se muze pohnout
   * (pokud ano, upravi ho pro tahnuti, nastavi ho do figLabel) a zobrazi kontextovou napovedu.
   */
  private void eCatcherMousePressed(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_eCatcherMousePressed
    if (figLabel != null || finished) {
      return;
    }
    BoardSquare bsquare = (BoardSquare) eCatcher.getComponentAt(evt.getPoint());

    JPanel fsquare = (JPanel) figurePan.getComponent(bsquare.getIndex());
    sourceBSquare = bsquare;
    Point defLocation = fsquare.getLocation();
    xAdjustment = (int) defLocation.getX() - evt.getX();
    yAdjustment = (int) defLocation.getY() - evt.getY();
    if (fsquare.getComponentCount() == 0) {
      return;
    }
    figLabel = (JLabel) fsquare.getComponent(0);

    setFocus(gui.getFocus(bsquare.getColumn(), bsquare.getRow()));
    if (!gui.canMove(bsquare.getColumn(), bsquare.getRow())) {
      figLabel = null;
      return;
    }
    fsquare.remove(figLabel);
    boardPane.add(figLabel, 0);
    figLabel.setLocation(evt.getX() + xAdjustment, evt.getY() + yAdjustment);
    figLabel.setSize(figLabel.getWidth(), figLabel.getHeight());
  } // GEN-LAST:event_eCatcherMousePressed
 private boolean isOnNextStepButton(MouseEvent e) {
   final int index = myList.getSelectedIndex();
   final Rectangle bounds = myList.getCellBounds(index, index);
   final Point point = e.getPoint();
   return bounds != null
       && point.getX() > bounds.width + bounds.getX() - AllIcons.Icons.Ide.NextStep.getIconWidth();
 }
  private void showSliderMenu() {
    Point location = new Point(getX(), getY() + getHeight());

    SwingUtilities.convertPointToScreen(location, InputVolumeControlButton.this.getParent());

    if (isFullScreen()) {
      location.setLocation(
          location.getX(),
          location.getY() - sliderMenu.getPreferredSize().getHeight() - getHeight());
    }

    sliderMenu.setLocation(location);

    sliderMenu.addPopupMenuListener(
        new PopupMenuListener() {
          public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            sliderMenuIsVisible = true;
          }

          public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
            sliderMenuIsVisible = false;
          }

          public void popupMenuCanceled(PopupMenuEvent ev) {}
        });

    sliderMenu.setVisible(!sliderMenu.isVisible());
  }
Example #12
0
  /** Find location of character */
  public String findLocation(Point loc) {
    double x = loc.getX();
    double y = loc.getY();

    if (x >= 400 && y >= 100 && x <= 680 && y <= 180) {
      return "Wright Hall";
    } else if (x >= 120 && y >= 300 && x <= 210 && y <= 490) {
      return "Burton Hall";
    } else if (x >= 30 && y >= 230 && x <= 120 && y <= 490) {
      return "Sabin-Reed";
    } else if (x >= 30 && y >= 580 && x <= 210 && y <= 660) {
      return "McConnell";
    } else if (x >= 30 && y >= 700 && x <= 210 && y <= 770) {
      return "Tyler House";
    } else if (x >= 260 && y >= 580 && x <= 520 && y <= 670) {
      return "Bass";
    } else if (x >= 260 && y >= 670 && x <= 390 && y <= 750) {
      return "Young Science Library";
    } else if (x >= 600 && y >= 230 && x <= 750 && y <= 630) {
      return "Neilson Library";
    } else if (x >= 600 && y >= 700 && x <= 780 && y <= 790) {
      return "Corner Store";
    } else {
      return "";
    }
  }
 protected RelativePoint getPointToShowResults() {
   final int selectedRow = myTree.getSelectionRows()[0];
   final Rectangle rowBounds = myTree.getRowBounds(selectedRow);
   final Point location = rowBounds.getLocation();
   location.x += rowBounds.width;
   return new RelativePoint(myTree, location);
 }
Example #14
0
  private int getCurrentLineCenter(FilePanel fp) {
    JScrollPane scrollPane;
    BufferDocumentIF bd;
    JTextComponent editor;
    JViewport viewport;
    int line;
    Rectangle rect;
    int offset;
    Point p;

    editor = fp.getEditor();
    scrollPane = fp.getScrollPane();
    viewport = scrollPane.getViewport();
    p = viewport.getViewPosition();
    offset = editor.viewToModel(p);

    // Scroll around the center of the editpane
    p.y += getHeightOffset(fp);

    offset = editor.viewToModel(p);
    bd = fp.getBufferDocument();
    if (bd == null) {
      return -1;
    }
    line = bd.getLineForOffset(offset);

    return line;
  }
Example #15
0
 /**
  * Changes the frame's location to a more central screen location
  *
  * @param frame the frame to be moved
  * @param X how far right to move the frame
  * @param Y how far down to move the frame
  */
 public static void changeFrameLocation(Component frame, int X, int Y) {
   Point location = frame.getLocation(); // the window's current location
   // move the window over and down a certain amount of pixels
   location.translate(X, Y);
   // set the location
   frame.setLocation(location);
 }
Example #16
0
  public TabSpawnable spawn() {
    JFrame f = new JFrame();
    f.getContentPane().setLayout(new BorderLayout());
    f.setTitle(_title);
    TabSpawnable newPanel = (TabSpawnable) clone();
    if (newPanel == null) return null; // failed to clone
    newPanel.setTitle(_title);
    if (newPanel instanceof TabToDoTarget) {
      TabToDoTarget me = (TabToDoTarget) this;
      TabToDoTarget it = (TabToDoTarget) newPanel;
      it.setTarget(me.getTarget());
    } else if (newPanel instanceof TabModelTarget) {
      TabModelTarget me = (TabModelTarget) this;
      TabModelTarget it = (TabModelTarget) newPanel;
      it.setTarget(me.getTarget());
    }
    f.getContentPane().add(newPanel, BorderLayout.CENTER);
    Rectangle bounds = getBounds();
    bounds.height += OVERLAPP * 2;
    f.setBounds(bounds);

    Point loc = new Point(0, 0);
    SwingUtilities.convertPointToScreen(loc, this);
    loc.y -= OVERLAPP;
    f.setLocation(loc);
    f.setVisible(true);

    if (_tear && (getParent() instanceof JTabbedPane)) ((JTabbedPane) getParent()).remove(this);

    return newPanel;
  }
 @Override
 protected RelativePoint getPointToShowResults() {
   Rectangle rect = myEntryTable.getCellRect(myEntryTable.getSelectedRow(), 1, false);
   Point location = rect.getLocation();
   location.y += rect.height;
   return new RelativePoint(myEntryTable, location);
 }
Example #18
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
Example #19
0
    private void showJPopupMenu(MouseEvent e) {
      try {
        if (e.isPopupTrigger() && menu != null) {
          if (window == null) {

            if (isWindows) {
              window = new JDialog((Frame) null);
              ((JDialog) window).setUndecorated(true);
            } else {
              window = new JWindow((Frame) null);
            }
            window.setAlwaysOnTop(true);
            Dimension size = menu.getPreferredSize();

            Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
            if (e.getY() > centerPoint.getY()) window.setLocation(e.getX(), e.getY() - size.height);
            else window.setLocation(e.getX(), e.getY());

            window.setVisible(true);

            menu.show(((RootPaneContainer) window).getContentPane(), 0, 0);

            // popup works only for focused windows
            window.toFront();
          }
        }
      } catch (Exception ignored) {
      }
    }
Example #20
0
  /**
   * We generally draw lines to/from the <I>center</I> of components; this method finds the center
   * of the argument's enclosing rectangle
   *
   * @return Point at the center of <CODE>c</CODE>
   * @param c The component whose center point we wish to determine
   */
  protected Point getCenterLocation(Component c) {

    Point p1 = new Point();
    Point p2 = new Point();

    // start with the relative location...
    c.getLocation(p1);
    // get to the middle of the fractionsLabel
    Dimension d = c.getSize();
    p1.x += d.width / 2;
    p1.y += d.height / 2;

    Component parent = c.getParent();
    // System.err.println("parent=" + parent);

    while (parent != null) {
      parent.getLocation(p2);
      p1.x += p2.x;
      p1.y += p2.y;

      if (STOP.equals(parent.getName())) break;

      parent = parent.getParent();
    }
    return p1;
  }
Example #21
0
 /**
  * Set the offset from the center for this <code>MetSymbol</code>.
  *
  * @param x x offset
  * @param y y offset
  */
 public void setOffset(int x, int y) {
   if (offset != null) {
     offset.x = x;
     offset.y = y;
   }
   bounds.x = x;
   bounds.y = y;
 }
 /** 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 = segmentTable.getCellRect(index, 1, true);
   segmentTable.scrollRectToVisible(r);
   setTopLevelLocation();
   return new Point(
       (int) (r.getX() + topLevelLocation.getX()), (int) (r.getY() + topLevelLocation.getY()));
 }
Example #23
0
  /** {@inheritDoc} */
  @Override
  public void mouseDragged(final MouseEvent aEvent) {
    final MouseEvent event = convertEvent(aEvent);
    final Point point = event.getPoint();

    // Update the selected channel while dragging...
    this.controller.setSelectedChannel(point);

    if (getModel().isCursorMode() && (this.movingCursor >= 0)) {
      this.controller.moveCursor(this.movingCursor, getCursorDropPoint(point));

      aEvent.consume();
    } else {
      if ((this.lastClickPosition == null)
          && ((aEvent.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)) {
        this.lastClickPosition = new Point(point);
      }

      final JScrollPane scrollPane =
          getAncestorOfClass(JScrollPane.class, (Component) aEvent.getSource());
      if ((scrollPane != null) && (this.lastClickPosition != null)) {
        final JViewport viewPort = scrollPane.getViewport();
        final Component signalView = this.controller.getSignalDiagram().getSignalView();

        boolean horizontalOnly = (aEvent.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0;
        boolean verticalOnly =
            horizontalOnly && ((aEvent.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0);

        int dx = aEvent.getX() - this.lastClickPosition.x;
        int dy = aEvent.getY() - this.lastClickPosition.y;

        Point scrollPosition = viewPort.getViewPosition();
        int newX = scrollPosition.x;
        if (!verticalOnly) {
          newX -= dx;
        }
        int newY = scrollPosition.y;
        if (verticalOnly || !horizontalOnly) {
          newY -= dy;
        }

        int diagramWidth = signalView.getWidth();
        int viewportWidth = viewPort.getWidth();
        int maxX = diagramWidth - viewportWidth - 1;
        scrollPosition.x = Math.max(0, Math.min(maxX, newX));

        int diagramHeight = signalView.getHeight();
        int viewportHeight = viewPort.getHeight();
        int maxY = diagramHeight - viewportHeight;
        scrollPosition.y = Math.max(0, Math.min(maxY, newY));

        viewPort.setViewPosition(scrollPosition);
      }

      // Use UNCONVERTED/ORIGINAL mouse event!
      handleZoomRegion(aEvent, this.lastClickPosition);
    }
  }
  @Override
  public Point getLocationOnScreen() {
    Dimension headerCorrectionSize = myLocateByContent ? myHeaderPanel.getPreferredSize() : null;
    Point screenPoint = myContent.getLocationOnScreen();
    if (headerCorrectionSize != null) {
      screenPoint.y -= headerCorrectionSize.height;
    }

    return screenPoint;
  }
Example #25
0
 protected void showInfoPopup(String info, int x, int y) {
   JPanel content = new JPanel();
   content.add(new JLabel(info));
   content.setBorder(BorderFactory.createLineBorder(Color.BLACK));
   Point location = getLocationOnScreen();
   location.x += x + 5;
   location.y += y + 5;
   popup = PopupFactory.getSharedInstance().getPopup(this, content, location.x, location.y);
   popup.show();
 }
Example #26
0
 public Point getLocation() {
   if (inEditMode) {
     tmpLoc.x = defLoc.x;
     tmpLoc.y = defLoc.y;
   } else {
     tmpLoc.x = curLoc.x;
     tmpLoc.y = curLoc.y;
   }
   return tmpLoc;
 }
Example #27
0
  public Point getDockingSpot(char location) {
    Point p = new Point(getWidth(), getHeight());
    int d = getDividerLocation() + getDividerSize() / 2;

    switch (location) {
      case DOCK_NORTH:
        p.x = d;
        p.y = 0;
        break;
      case DOCK_SOUTH:
        p.x = d;
        break;
      case DOCK_EAST:
        p.y = d;
        break;
      case DOCK_WEST:
        p.x = 0;
        p.y = d;
        break;
      case DOCK_CENTER:
        p.x /= 2;
        p.y /= 2;
        break;
    }

    return p;
  }
 /**
  * Draw a string at a given point.
  *
  * <p>The method returns the point where the next string should be drawn to seamlessly continue
  * the current string.
  *
  * @param s the string
  * @param point the position where to draw the string
  * @param fontname the font's name, should preferably be a logical name
  * @param fontsize the font size
  * @param color the color
  * @return the point where outputting string text should continue
  */
 public Point drawString(String s, Point point, String fontname, int fontsize, Color color) {
   Graphics g = this.image.getGraphics();
   g.setColor(color);
   g.setFont(new Font(fontname, Font.PLAIN, fontsize));
   g.drawString(s, point.x, point.y);
   FontMetrics f = g.getFontMetrics();
   Point newPoint = new Point(point);
   newPoint.x += f.stringWidth(s);
   this.repaint();
   return (newPoint);
 }
  //  Repaint the message at the new location
  public void paintComponent(Graphics page) {
    // use paintComponent method of its parent class
    // to have all graphics properties
    super.paintComponent(page);

    // change the page color and font
    page.setColor(Color.cyan);
    page.setFont(new Font("TimesRoman", Font.PLAIN, 24));

    page.drawString(message.getText(), (int) (location.getX()), (int) (location.getY()));
  }
Example #30
0
 public static void setPositionRelativeToParent(
     Window w, Component parent, int hOffset, int vOffset) {
   try {
     Point p = parent.getLocationOnScreen();
     int x = (int) p.getX() + hOffset;
     int y = (int) p.getY() + vOffset;
     w.setLocation(x, y);
     w.pack();
   } catch (Throwable t) {
   }
 }