List of usage examples for java.awt Point translate
public void translate(int dx, int dy)
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java
@Override public void keyPressed(KeyEvent ke) { Logger.getLogger(getClass().getName()).log(Level.INFO, "Received key event: {0}", ke.toString()); if (ke.isControlDown()) { modeSpinner.setValue(InstanceContentSelectionHandler.Mode.ON_HOVER.toString()); }/*from w ww .j a v a 2 s .com*/ if (getDataPoint() != null) { Logger.getLogger(getClass().getName()).info("Data point is not null!"); Point p = null; if (ke.getKeyCode() == KeyEvent.VK_RIGHT) { p = new Point(getDataPoint()); p.translate(1, 0); } else if (ke.getKeyCode() == KeyEvent.VK_LEFT) { p = new Point(getDataPoint()); p.translate(-1, 0); } else if (ke.getKeyCode() == KeyEvent.VK_UP) { p = new Point(getDataPoint()); p.translate(0, 1); } else if (ke.getKeyCode() == KeyEvent.VK_DOWN) { p = new Point(getDataPoint()); p.translate(0, -1); } setDataPoint(p); if (!ke.isShiftDown()) { // triggerMSUpdate(); } } }
From source file:edu.ku.brc.specify.utilapps.ERDVisualizer.java
public void calcLoc(final Point p, final Component src, final Component stop) { if (src != stop) { Point sp = src.getLocation(); p.translate(sp.x, sp.y); calcLoc(p, src.getParent(), stop); }/* ww w . j av a 2 s. c om*/ }
From source file:de.tor.tribes.ui.panels.MinimapPanel.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); try {/*from w ww . ja v a 2s . c o m*/ Graphics2D g2d = (Graphics2D) g; g2d.clearRect(0, 0, getWidth(), getHeight()); g2d.drawImage(mBuffer, 0, 0, null); if (iCurrentView == ID_MINIMAP) { g2d.setColor(Color.YELLOW); int mapWidth = rVisiblePart.width; int mapHeight = rVisiblePart.height; int w = (int) Math.rint(((double) getWidth() / mapWidth) * (double) iWidth); int h = (int) Math.rint(((double) getHeight() / mapHeight) * (double) iHeight); double posX = ((double) getWidth() / mapWidth * (double) (iX - rVisiblePart.x)) - w / 2; double posY = ((double) getHeight() / mapHeight * (double) (iY - rVisiblePart.y)) - h / 2; g2d.drawRect((int) Math.rint(posX), (int) Math.rint(posY), w, h); if (iCurrentCursor == ImageManager.CURSOR_SHOT) { if (rDrag != null) { g2d.setColor(Color.ORANGE); g2d.drawRect((int) rDrag.getMinX(), (int) rDrag.getMinY(), (int) (rDrag.getWidth() - rDrag.getX()), (int) (rDrag.getHeight() - rDrag.getY())); } } else if (iCurrentCursor == ImageManager.CURSOR_ZOOM) { if (rDrag != null) { g2d.setColor(Color.CYAN); g2d.drawRect((int) rDrag.getX(), (int) rDrag.getY(), (int) (rDrag.getWidth() - rDrag.getX()), (int) ((rDrag.getWidth() - rDrag.getX()) * ((double) getHeight()) / getWidth())); } } } if (showControls) { //g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .2f)); Rectangle r = minimapButtons.get(ID_MINIMAP); g2d.setColor(Color.WHITE); Point menuPos = r.getLocation(); menuPos.translate(-2, -2); //draw border g2d.fillRect(menuPos.x, menuPos.y, 88, 30); g2d.setColor(Color.BLACK); //check if mouse is inside minimap button if (getMousePosition() != null && r.contains(getMousePosition())) { g2d.setColor(Color.YELLOW); g2d.fillRect(r.x, r.y, r.width, r.height); g2d.setColor(Color.BLACK); } g2d.drawImage(minimapIcons.get(ID_MINIMAP), r.x, r.y, null); g2d.drawRect(r.x, r.y, r.width, r.height); r = minimapButtons.get(ID_ALLY_CHART); //check if mouse is inside ally chart button if (getMousePosition() != null && r.contains(getMousePosition())) { g2d.setColor(Color.YELLOW); g2d.fillRect(r.x, r.y, r.width, r.height); g2d.setColor(Color.BLACK); } g2d.drawImage(minimapIcons.get(ID_ALLY_CHART), r.x, r.y, null); g2d.drawRect(r.x, r.y, r.width, r.height); r = minimapButtons.get(ID_TRIBE_CHART); //check if mouse is inside tribe chart button if (getMousePosition() != null && r.contains(getMousePosition())) { g2d.setColor(Color.YELLOW); g2d.fillRect(r.x, r.y, r.width, r.height); g2d.setColor(Color.BLACK); } g2d.drawImage(minimapIcons.get(ID_TRIBE_CHART), r.x, r.y, null); g2d.drawRect(r.x, r.y, r.width, r.height); } g2d.dispose(); } catch (Exception e) { logger.error("Failed painting Minimap", e); } }
From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java
public void doAction(GhostActionable src) { if (src instanceof InputPanel) { InputPanel inputPanel = (InputPanel) src; Point offSet = src.getMouseInputAdapter().getOffsetFromStartPnt(); Point location = inputPanel.getLocation(); Point offset = ((GhostGlassPane) UIRegistry.get(UIRegistry.GLASSPANE)).getOffset(); location.translate(offSet.x - offset.x, offSet.y - offset.y); location.x = Math.max(0, location.x); location.y = Math.max(0, location.y); //System.out.println("***************************************"); inputPanel.setLocation(location); remove(inputPanel);// ww w . j a v a 2 s . c o m add(inputPanel); repaint(); validate(); doLayout(); adjustPanelSize(); // Update the template WorkbenchTemplateMappingItem wbtmi = inputPanel.getWbtmi(); wbtmi.setXCoord((short) location.x); wbtmi.setYCoord((short) location.y); workbenchPane.setChanged(true); UsageTracker.getUsageCount("WBLayoutFormDrop"); } }
From source file:de.tor.tribes.ui.panels.MinimapPanel.java
/** * Creates new form MinimapPanel/* w w w. j a va 2s . com*/ */ MinimapPanel() { initComponents(); setSize(300, 300); mMinimapListeners = new LinkedList<>(); mToolChangeListeners = new LinkedList<>(); setCursor(ImageManager.getCursor(iCurrentCursor)); mScreenshotPanel = new ScreenshotPanel(); minimapButtons.put(ID_MINIMAP, new Rectangle(2, 2, 26, 26)); minimapButtons.put(ID_ALLY_CHART, new Rectangle(30, 2, 26, 26)); minimapButtons.put(ID_TRIBE_CHART, new Rectangle(60, 2, 26, 26)); try { minimapIcons.put(ID_MINIMAP, ImageIO.read(new File("./graphics/icons/minimap.png"))); minimapIcons.put(ID_ALLY_CHART, ImageIO.read(new File("./graphics/icons/ally_chart.png"))); minimapIcons.put(ID_TRIBE_CHART, ImageIO.read(new File("./graphics/icons/tribe_chart.png"))); } catch (Exception ignored) { } jPanel1.add(mScreenshotPanel); rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension()); zoomed = false; MarkerManager.getSingleton().addManagerListener(this); TagManager.getSingleton().addManagerListener(this); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); if (!GlobalOptions.isMinimal()) { MinimapRepaintThread.getSingleton().start(); } addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (!showControls && e.getButton() != MouseEvent.BUTTON1) { //show controls Point p = e.getPoint(); p.translate(-5, -5); showControls(p); return; } if (!showControls && iCurrentView == ID_MINIMAP) { Point p = mousePosToMapPosition(e.getX(), e.getY()); DSWorkbenchMainFrame.getSingleton().centerPosition(p.getX(), p.getY()); MapPanel.getSingleton().getMapRenderer().initiateRedraw(MapRenderer.ALL_LAYERS); if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().toFront(); } } else { if (minimapButtons.get(ID_MINIMAP).contains(e.getPoint())) { iCurrentView = ID_MINIMAP; mBuffer = null; showControls = false; MinimapRepaintThread.getSingleton().update(); } else if (minimapButtons.get(ID_ALLY_CHART).contains(e.getPoint())) { iCurrentView = ID_ALLY_CHART; lastHash = 0; showControls = false; updateComplete(); } else if (minimapButtons.get(ID_TRIBE_CHART).contains(e.getPoint())) { iCurrentView = ID_TRIBE_CHART; lastHash = 0; showControls = false; updateComplete(); } } } @Override public void mousePressed(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } if (iCurrentCursor == ImageManager.CURSOR_SHOT || iCurrentCursor == ImageManager.CURSOR_ZOOM) { iXDown = e.getX(); iYDown = e.getY(); } } @Override public void mouseReleased(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } if (rDrag == null) { return; } if (iCurrentCursor == ImageManager.CURSOR_SHOT) { try { BufferedImage i = MinimapRepaintThread.getSingleton().getImage(); double widthFactor = ((double) ServerSettings.getSingleton().getMapDimension().width) / getWidth(); double heightFactor = ((double) ServerSettings.getSingleton().getMapDimension().height) / getHeight(); int x = (int) Math.rint(widthFactor * rDrag.getX()); int y = (int) Math.rint(heightFactor * rDrag.getY()); int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX())); int h = (int) Math.rint(heightFactor * (rDrag.getHeight() - rDrag.getY())); BufferedImage sub = i.getSubimage(x, y, w, h); mScreenshotPanel.setBuffer(sub); jPanel1.setSize(mScreenshotPanel.getSize()); jPanel1.setPreferredSize(mScreenshotPanel.getSize()); jPanel1.setMinimumSize(mScreenshotPanel.getSize()); jPanel1.setMaximumSize(mScreenshotPanel.getSize()); jScreenshotPreview.pack(); jScreenshotControl.pack(); jScreenshotPreview.setVisible(true); jScreenshotControl.setVisible(true); } catch (Exception ie) { logger.error("Failed to initialize mapshot", ie); } } else if (iCurrentCursor == ImageManager.CURSOR_ZOOM) { if (!zoomed) { Rectangle mapDim = ServerSettings.getSingleton().getMapDimension(); double widthFactor = ((double) mapDim.width) / getWidth(); double heightFactor = ((double) mapDim.height) / getHeight(); int x = (int) Math.rint(widthFactor * rDrag.getX() + mapDim.getMinX()); int y = (int) Math.rint(heightFactor * rDrag.getY() + mapDim.getMinY()); int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX())); if (w >= 10) { rVisiblePart = new Rectangle(x, y, w, w); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); redraw(); zoomed = true; } } else { rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension()); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); redraw(); zoomed = false; } MinimapZoomFrame.getSingleton().setVisible(false); } iXDown = 0; iYDown = 0; rDrag = null; } @Override public void mouseEntered(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } switch (iCurrentCursor) { case ImageManager.CURSOR_ZOOM: { MinimapZoomFrame.getSingleton().setVisible(true); } } } @Override public void mouseExited(MouseEvent e) { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } iXDown = 0; iYDown = 0; rDrag = null; } }); addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } switch (iCurrentCursor) { case ImageManager.CURSOR_MOVE: { Point p = mousePosToMapPosition(e.getX(), e.getY()); DSWorkbenchMainFrame.getSingleton().centerPosition(p.x, p.y); rDrag = null; break; } case ImageManager.CURSOR_SHOT: { rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY()); break; } case ImageManager.CURSOR_ZOOM: { rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY()); break; } } } @Override public void mouseMoved(MouseEvent e) { if (iCurrentView == ID_MINIMAP) { switch (iCurrentCursor) { case ImageManager.CURSOR_ZOOM: { if (!MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(true); } int mapWidth = (int) ServerSettings.getSingleton().getMapDimension().getWidth(); int mapHeight = (int) ServerSettings.getSingleton().getMapDimension().getHeight(); int x = (int) Math.rint((double) mapWidth / (double) getWidth() * (double) e.getX()); int y = (int) Math.rint((double) mapHeight / (double) getHeight() * (double) e.getY()); MinimapZoomFrame.getSingleton().updatePosition(x, y); break; } default: { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } } } } Point location = minimapButtons.get(ID_MINIMAP).getLocation(); location.translate(-2, -2); if (!new Rectangle(location.x, location.y, 88, 30).contains(e.getPoint())) { //hide controls showControls = false; repaint(); } } }); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { if (iCurrentView != ID_MINIMAP) { return; } iCurrentCursor += e.getWheelRotation(); if (iCurrentCursor == ImageManager.CURSOR_DEFAULT + e.getWheelRotation()) { if (e.getWheelRotation() < 0) { iCurrentCursor = ImageManager.CURSOR_SHOT; } else { iCurrentCursor = ImageManager.CURSOR_MOVE; } } else if (iCurrentCursor < ImageManager.CURSOR_MOVE) { iCurrentCursor = ImageManager.CURSOR_DEFAULT; } else if (iCurrentCursor > ImageManager.CURSOR_SHOT) { iCurrentCursor = ImageManager.CURSOR_DEFAULT; } if (iCurrentCursor != ImageManager.CURSOR_ZOOM) { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } } else { MinimapZoomFrame.getSingleton().setVisible(true); } setCurrentCursor(iCurrentCursor); } }); }
From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphNode.java
/** * Draws an arrow head at the correct angle * * @param g The Java2D Graphics//from w w w. ja va 2s .c om * @param tailX position X on target node * @param tailY position Y on target node * @param headX position X on source node * @param headY position Y on source node */ private static void drawArrow(final Graphics2D g, final int tailX, final int tailY, final int headX, final int headY) { final double t1 = Math.abs(headY - tailY); final double t2 = Math.abs(headX - tailX); double theta = Math.atan(t1 / t2); if (headX >= tailX) { if (headY > tailY) theta = Math.PI + theta; else theta = -(Math.PI + theta); } else if (headX < tailX && headY > tailY) theta = 2 * Math.PI - theta; final double cosTheta = FastMath.cos(theta); final double sinTheta = FastMath.sin(theta); final Point p2 = new Point(-8, -3); final Point p3 = new Point(-8, +3); int x = (int) Math.round((cosTheta * p2.x) - (sinTheta * p2.y)); p2.y = (int) Math.round((sinTheta * p2.x) + (cosTheta * p2.y)); p2.x = x; x = (int) Math.round((cosTheta * p3.x) - (sinTheta * p3.y)); p3.y = (int) Math.round((sinTheta * p3.x) + (cosTheta * p3.y)); p3.x = x; p2.translate(tailX, tailY); p3.translate(tailX, tailY); Stroke oldStroke = g.getStroke(); g.setStroke(new BasicStroke(2)); g.drawLine(tailX, tailY, headX, headY); g.drawLine(tailX, tailY, p2.x, p2.y); g.drawLine(p3.x, p3.y, tailX, tailY); g.setStroke(oldStroke); }
From source file:org.gtdfree.GTDFree.java
/** * This method initializes jMenuItem //from w w w . jav a 2 s . c o m * * @return javax.swing.JMenuItem */ private JMenuItem getAboutMenuItem() { if (aboutMenuItem == null) { aboutMenuItem = new JMenuItem(); aboutMenuItem.setText(Messages.getString("GTDFree.Help.About")); //$NON-NLS-1$ aboutMenuItem.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_about)); aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JDialog aboutDialog = getAboutDialog(); //aboutDialog.pack(); Point loc = getJFrame().getLocation(); loc.translate(20, 20); aboutDialog.setLocation(loc); aboutDialog.setVisible(true); } }); } return aboutMenuItem; }
From source file:org.monkeys.gui.PopupWindow.java
public void showPupup(final Component component, final int relX, final int relY) { final Point xy = component.getLocationOnScreen(); if (relX != 0 || relY != 0) { xy.translate(relX, relY); }//from w ww . ja v a 2 s . co m this.showPopup(xy.x, xy.y); }
From source file:org.nuclos.client.customcomp.resplan.ResPlanPanel.java
/** * Determines the current top-left area (resource/time) and creates a Runnable * which can be used to scroll the view to that area. */// w ww. j a v a2s. co m private Runnable createScrollToCurrentAreaRunnable() { Point pt = resPlan.getVisibleRect().getLocation(); pt.translate(5, 5); final Collectable resource = resPlan.getResourceAt(pt); final Interval<Date> timeInterval = resPlan.getTimeIntervalAt(pt); return new Runnable() { @Override public void run() { try { resPlan.scrollRectToArea(resource, timeInterval, true); } catch (Exception e) { LOG.error("createScrollToCurrentAreaRunnable failed: " + e, e); } } }; }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java
/** Displays the file set associated to the image. */ void displayFileset() { Point location = inplaceIcon.getLocation(); SwingUtilities.convertPointToScreen(location, inplaceIcon.getParent()); // as the inplaceIcon already is on the right edge of the window // move it a bit more to the left location.translate(-FilesetInfoDialog.DEFAULT_WIDTH + inplaceIcon.getWidth(), inplaceIcon.getHeight()); FilesetInfoDialog d = new FilesetInfoDialog(); d.setData(model.getFileset(), model.isInplaceImport()); d.open(location);//from www . j a v a 2s. co m }