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"; }
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(); }
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(); } }
protected void movePolygon(Point previousMousePoint, Point mousePoint) { // Intersect a ray through each mouse point, with a geoid passing through the reference // elevation. // If either ray fails to intersect the geoid, then ignore this event. Use the difference // between the two // intersected positions to move the control point's location. View view = this.wwd.getView(); Globe globe = this.wwd.getModel().getGlobe(); Position refPos = this.polygon.getReferencePosition(); if (refPos == null) return; Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY()); Line previousRay = view.computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY()); Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), ray); Vec4 previousVec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), previousRay); if (vec == null || previousVec == null) { return; } Position pos = globe.computePositionFromPoint(vec); Position previousPos = globe.computePositionFromPoint(previousVec); LatLon change = pos.subtract(previousPos); this.polygon.move(new Position(change.getLatitude(), change.getLongitude(), 0.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); } }
// draw method public synchronized void draw(Graphics2D g) { int w = s.getWidth(); int h = s.getHeight(); image.x %= w; image.y %= h; if (image.x < 0) { image.x += w; } else { } if (image.y < 0) { image.y += h; } else { } int x = image.x; int y = image.y; g.drawImage(bg, x, y, null); g.drawImage(bg, x - w, y, null); g.drawImage(bg, x, y - h, null); g.drawImage(bg, x - w, y - h, null); }
/** * Calculates location of caret and displays the suggestion popup at the location. * * @param listModel * @param subWord */ protected void showSuggestion(DefaultListModel<CompletionCandidate> listModel, String subWord) { // new Exception(System.currentTimeMillis() + "").printStackTrace(System.out); hideSuggestion(); if (listModel.size() == 0) { Messages.log("TextArea: No suggestions to show."); } else { int position = getCaretPosition(); Point location = new Point(); try { location.x = offsetToX(getCaretLine(), position - getLineStartOffset(getCaretLine())); location.y = lineToY(getCaretLine()) + getPainter().getFontMetrics().getHeight() + getPainter().getFontMetrics().getDescent(); // log("TA position: " + location); } catch (Exception e2) { e2.printStackTrace(); return; } suggestion = new CompletionPanel(this, position, subWord, listModel, location, editor); requestFocusInWindow(); } }
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) { } }
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()); }
// ------------------------------ 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
/** * 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())); }
/** {@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; }
public Point getLocation() { if (inEditMode) { tmpLoc.x = defLoc.x; tmpLoc.y = defLoc.y; } else { tmpLoc.x = curLoc.x; tmpLoc.y = curLoc.y; } return tmpLoc; }
// 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())); }
public void setSizeRatio(double x, double y) { xRatio = x; yRatio = y; if (x > 1.0) xRatio = x - 1.0; if (y > 1.0) yRatio = y - 1.0; if (defDim.width <= 0) defDim = getPreferredSize(); curLoc.x = (int) ((double) defLoc.x * xRatio); curLoc.y = (int) ((double) defLoc.y * yRatio); curDim.width = (int) ((double) defDim.width * xRatio); curDim.height = (int) ((double) defDim.height * yRatio); if (!inEditMode) setBounds(curLoc.x, curLoc.y, curDim.width, curDim.height); }
// recenter the mouse using the robot public synchronized void recenterMouse() { Window w = s.getFullScreenWindow(); if (robot != null && w.isShowing()) { center.x = w.getWidth() / 2; center.y = w.getHeight() / 2; SwingUtilities.convertPointToScreen(center, w); centering = true; robot.mouseMove(center.x, center.y); } }
public Element getLineAtPoint(MouseEvent me) { Point p = me.getLocationOnScreen(); Point pp = getLocationOnScreen(); p.translate(-pp.x, -pp.y); int pos = viewToModel(p); Element root = getDocument().getDefaultRootElement(); int e = root.getElementIndex(pos); if (e == -1) { return null; } return root.getElement(e); }
private void processDrag(final MouseEvent e) { if (myDragCancelled) return; if (!isDraggingNow()) { if (myPressedPoint == null) return; if (isWithinDeadZone(e)) return; myDragPane = findLayeredPane(e); if (myDragPane == null) return; final BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); paint(image.getGraphics()); myDragButtonImage = new JLabel(new ImageIcon(image)) { public String toString() { return "Image for: " + StripeButton.this.toString(); } }; myDragPane.add(myDragButtonImage, JLayeredPane.POPUP_LAYER); myDragButtonImage.setSize(myDragButtonImage.getPreferredSize()); setVisible(false); myPane.startDrag(); myDragKeyEventDispatcher = new DragKeyEventDispatcher(); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addKeyEventDispatcher(myDragKeyEventDispatcher); } if (!isDraggingNow()) return; Point xy = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myDragPane); if (myPressedPoint != null) { xy.x -= myPressedPoint.x; xy.y -= myPressedPoint.y; } myDragButtonImage.setLocation(xy); SwingUtilities.convertPointToScreen(xy, myDragPane); final Stripe stripe = myPane.getStripeFor(new Rectangle(xy, myDragButtonImage.getSize()), (Stripe) getParent()); if (stripe == null) { if (myLastStripe != null) { myLastStripe.resetDrop(); } } else { if (myLastStripe != null && myLastStripe != stripe) { myLastStripe.resetDrop(); } stripe.processDropButton(this, myDragButtonImage, xy); } myLastStripe = stripe; }
/** * Returns an point which has been adjusted to take into account of the desktop bounds, taskbar * and multi-monitor configuration. * * <p>This adustment may be cancelled by invoking the application with * -Djavax.swing.adjustPopupLocationToFit=false */ Point adjustPopupLocationToFitScreen(int xPosition, int yPosition) { Point popupLocation = new Point(xPosition, yPosition); if (popupPostionFixDisabled == true || GraphicsEnvironment.isHeadless()) { return popupLocation; } // Get screen bounds Rectangle scrBounds; GraphicsConfiguration gc = getCurrentGraphicsConfiguration(popupLocation); Toolkit toolkit = Toolkit.getDefaultToolkit(); if (gc != null) { // If we have GraphicsConfiguration use it to get screen bounds scrBounds = gc.getBounds(); } else { // If we don't have GraphicsConfiguration use primary screen scrBounds = new Rectangle(toolkit.getScreenSize()); } // Calculate the screen size that popup should fit Dimension popupSize = JPopupMenu.this.getPreferredSize(); long popupRightX = (long) popupLocation.x + (long) popupSize.width; long popupBottomY = (long) popupLocation.y + (long) popupSize.height; int scrWidth = scrBounds.width; int scrHeight = scrBounds.height; if (!canPopupOverlapTaskBar()) { // Insets include the task bar. Take them into account. Insets scrInsets = toolkit.getScreenInsets(gc); scrBounds.x += scrInsets.left; scrBounds.y += scrInsets.top; scrWidth -= scrInsets.left + scrInsets.right; scrHeight -= scrInsets.top + scrInsets.bottom; } int scrRightX = scrBounds.x + scrWidth; int scrBottomY = scrBounds.y + scrHeight; // Ensure that popup menu fits the screen if (popupRightX > (long) scrRightX) { popupLocation.x = scrRightX - popupSize.width; if (popupLocation.x < scrBounds.x) { popupLocation.x = scrBounds.x; } } if (popupBottomY > (long) scrBottomY) { popupLocation.y = scrBottomY - popupSize.height; if (popupLocation.y < scrBounds.y) { popupLocation.y = scrBounds.y; } } return popupLocation; }
/** * Calculates the drop point for the cursor under the given coordinate. * * @param aCoordinate the coordinate to return the channel drop point for, cannot be <code>null * </code>. * @return a drop point, never <code>null</code>. */ private Point getCursorDropPoint(final Point aCoordinate) { Point dropPoint = new Point(aCoordinate); if (getModel().isSnapCursorMode()) { final MeasurementInfo signalHover = getModel().getSignalHover(aCoordinate); if ((signalHover != null) && !signalHover.isEmpty()) { dropPoint.x = signalHover.getMidSamplePos().intValue(); } } dropPoint.y = 0; return dropPoint; }
/** Constrains a point to the current grid. */ protected Point constrainPoint(Point p) { // constrain to view size Dimension size = getSize(); // p.x = Math.min(size.width, Math.max(1, p.x)); // p.y = Math.min(size.height, Math.max(1, p.y)); p.x = Geom.range(1, size.width, p.x); p.y = Geom.range(1, size.height, p.y); if (fConstrainer != null) { return fConstrainer.constrainPoint(p); } return p; }
public void setSizeRatio(double x, double y) { double rx = x; double ry = y; if (rx > 1.0) rx = x - 1.0; if (ry > 1.0) ry = y - 1.0; if (defDim.width <= 0) defDim = getPreferredSize(); curLoc.x = (int) ((double) defLoc.x * rx); curLoc.y = (int) ((double) defLoc.y * ry); curDim.width = (int) ((double) defDim.width * rx); curDim.height = (int) ((double) defDim.height * ry); if (!inEditMode) setBounds(curLoc.x, curLoc.y, curDim.width, curDim.height); twin.setSizeRatio(x, y); }
public void reshape(int x, int y, int w, int h) { if (inEditMode) { defLoc.x = x; defLoc.y = y; defDim.width = w; defDim.height = h; } curLoc.x = x; curLoc.y = y; curDim.width = w; curDim.height = h; super.reshape(x, y, w, h); }
public void setEditMode(boolean s) { twin.setEditMode(s); setOpaque(s); if (s) { addMouseListener(ml); curLoc.x = defLoc.x; curLoc.y = defLoc.y; defDim = getPreferredSize(); curDim.width = defDim.width; curDim.height = defDim.height; } else removeMouseListener(ml); inEditMode = s; }
/** * Returns the component in the currently selected path which contains sourcePoint. * * @param source The component in whose coordinate space sourcePoint is given * @param sourcePoint The point which is being tested * @return The component in the currently selected path which contains sourcePoint (relative to * the source component's coordinate space. If sourcePoint is not inside a component on the * currently selected path, null is returned. */ public Component componentForPoint(Component source, Point sourcePoint) { int screenX, screenY; Point p = sourcePoint; int i, c, j, d; Component mc; Rectangle r2; int cWidth, cHeight; MenuElement menuElement; MenuElement subElements[]; Vector<MenuElement> tmp; int selectionSize; SwingUtilities.convertPointToScreen(p, source); screenX = p.x; screenY = p.y; tmp = (Vector<MenuElement>) selection.clone(); selectionSize = tmp.size(); for (i = selectionSize - 1; i >= 0; i--) { menuElement = (MenuElement) tmp.elementAt(i); subElements = menuElement.getSubElements(); for (j = 0, d = subElements.length; j < d; j++) { if (subElements[j] == null) continue; mc = subElements[j].getComponent(); if (!mc.isShowing()) continue; if (mc instanceof JComponent) { cWidth = mc.getWidth(); cHeight = mc.getHeight(); } else { r2 = mc.getBounds(); cWidth = r2.width; cHeight = r2.height; } p.x = screenX; p.y = screenY; SwingUtilities.convertPointFromScreen(p, mc); /** * Return the deepest component on the selection path in whose bounds the event's point * occurs */ if (p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight) { return mc; } } } return null; }
public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; Component c; Point p; paintComponent(g); for (int i = 0; i < getComponentCount(); i++) { AffineTransform save = g.getTransform(); c = getComponent(i); p = c.getLocation(); g.translate((int) p.getX(), (int) p.getY()); c.paint(g); g.setTransform(save); } }
public void mousePressed(MouseEvent e) { requestFocus(); Point p = e.getPoint(); int size = Math.min( MAX_SIZE, Math.min( getWidth() - imagePadding.left - imagePadding.right, getHeight() - imagePadding.top - imagePadding.bottom)); p.translate(-(getWidth() / 2 - size / 2), -(getHeight() / 2 - size / 2)); if (mode == ColorPicker.BRI || mode == ColorPicker.SAT) { // the two circular views: double radius = ((double) size) / 2.0; double x = p.getX() - size / 2.0; double y = p.getY() - size / 2.0; double r = Math.sqrt(x * x + y * y) / radius; double theta = Math.atan2(y, x) / (Math.PI * 2.0); if (r > 1) r = 1; if (mode == ColorPicker.BRI) { setHSB((float) (theta + .25f), (float) (r), bri); } else { setHSB((float) (theta + .25f), sat, (float) (r)); } } else if (mode == ColorPicker.HUE) { float s = ((float) p.x) / ((float) size); float b = ((float) p.y) / ((float) size); if (s < 0) s = 0; if (s > 1) s = 1; if (b < 0) b = 0; if (b > 1) b = 1; setHSB(hue, s, b); } else { int x2 = p.x * 255 / size; int y2 = p.y * 255 / size; if (x2 < 0) x2 = 0; if (x2 > 255) x2 = 255; if (y2 < 0) y2 = 0; if (y2 > 255) y2 = 255; if (mode == ColorPicker.RED) { setRGB(red, x2, y2); } else if (mode == ColorPicker.GREEN) { setRGB(x2, green, y2); } else { setRGB(x2, y2, blue); } } }
public synchronized void mouseMoved(MouseEvent e) { if (centering && center.x == e.getX() && center.y == e.getY()) { centering = false; } else { int dx = e.getX() - mouse.x; int dy = e.getY() - mouse.y; image.x += dx; image.y += dy; recenterMouse(); } mouse.x = e.getX(); mouse.y = e.getY(); }