Example usage for java.awt Point translate

List of usage examples for java.awt Point translate

Introduction

In this page you can find the example usage for java.awt Point translate.

Prototype

public void translate(int dx, int dy) 

Source Link

Document

Translates this point, at location (x,y) , by dx along the x axis and dy along the y axis so that it now represents the point (x+dx,y+dy) .

Usage

From source file:MainClass.java

public static void main(String[] args) {
    Point aPoint = new Point(); // Initialize to 0,0
    Point bPoint = new Point(50, 25);
    Point cPoint = new Point(bPoint);
    System.out.println("aPoint is located at: " + aPoint);
    aPoint.move(100, 50); // Change to position 100,50
    bPoint.x = 110;//from  w  w  w  .jav  a 2 s .co  m
    bPoint.y = 70;
    aPoint.translate(10, 20); // Move by 10 in x and 20 in y
    System.out.println("aPoint is now at: " + aPoint);
    if (aPoint.equals(bPoint))
        System.out.println("aPoint and bPoint are at the same location.");
}

From source file:Main.java

public static void main(String[] args) {
    Point aPoint = new Point();
    Point bPoint = new Point(50, 25);
    Point cPoint = new Point(bPoint);

    System.out.println("cPoint is located at: " + cPoint);

    System.out.println("aPoint is located at: " + aPoint);
    aPoint.move(100, 50);/*from   w w w  . j  a v  a  2 s  .c o  m*/

    bPoint.x = 110;
    bPoint.y = 70;

    aPoint.translate(10, 20);
    System.out.println("aPoint is now at: " + aPoint);

    if (aPoint.equals(bPoint))
        System.out.println("aPoint and bPoint are at the same location.");
}

From source file:Main.java

/**
 * <p>/*w  ww .j ava  2 s.c o m*/
 * getCenter.
 * </p>
 *
 * @param component
 *            a {@link java.awt.Component} object.
 * @return a {@link java.awt.Point} object.
 */
public static Point getCenter(final Component component) {
    final Point point = component.getLocation();
    point.translate( //
            (int) Math.floor((component.getWidth() + 0.5) / 2.0), //
            (int) Math.floor((component.getHeight() + 0.5) / 2.0));
    return point;
}

From source file:Main.java

/**
 * @param owner//from ww  w  . jav a  2  s.co  m
 * @param newConfigDialog
 */
public static void centerRelative(java.awt.Window main, java.awt.Window child) {
    java.awt.Dimension dim = main.getSize();
    Point _loc = center(dim, child);
    // Move the window
    _loc.translate(main.getX(), main.getY());
    child.setLocation(_loc);
}

From source file:Main.java

public static Point getPositionWithinWindow(Component component, Component parent, Point p) {
    Point[] pointCheck = new Point[] { (Point) p.clone(), (Point) p.clone(), (Point) p.clone(),
            (Point) p.clone() };//from w w w  .ja  va  2s .  c  o  m
    int w = component.getWidth();
    int h = component.getHeight();
    pointCheck[0].translate(w, h);
    pointCheck[1].translate(0, h);
    pointCheck[2].translate(w, 0);
    pointCheck[3].translate(0, 0);
    for (Point p2 : pointCheck) {
        if (parent.getBounds().contains(p2)) {
            p2.translate(-w, -h);
            return p2;
        }
    }
    return p;
}

From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java

/**
 * Draw the corner boxes and their values as calculated by apa overlayed above the existing heat map
 *
 * @param g2                   graphics2D oObject
 * @param map                  heat map object
 * @param regionCellDimensions dimensions for the corner regions to be plotted in units of cells, not pixels
 *                             where each cell corresponds to a data point, usually 20px-by-20px (default)
 * @param regionAPAValues      apa results for each region in order of TL TR BL BR
 *//* ww w .j  av a2s. c om*/
private static void drawCornerRegions(Graphics2D g2, HeatChart map, Dimension regionCellDimensions,
        double[] regionAPAValues) {
    // retrieve corners of heat map
    Point topLeft = map.getHeatMapTL();
    Point topRight = map.getHeatMapTR();
    Point bottomLeft = map.getHeatMapBL();
    Point bottomRight = map.getHeatMapBR();

    // calculate dimensions of corner regions
    Dimension cellSize = map.getCellSize();
    int cornerWidth = regionCellDimensions.width * cellSize.width,
            cornerHeight = regionCellDimensions.height * cellSize.height;

    // slide to top left corner within each region
    topRight.translate(-cornerWidth, 0);
    bottomLeft.translate(0, -cornerHeight);
    bottomRight.translate(-cornerWidth, -cornerHeight);

    // plot the four region TL TR BL BR and their values
    Point[] points = { topLeft, topRight, bottomLeft, bottomRight };
    g2.setColor(Color.black);
    for (int i = 0; i < 4; i++) {
        // plot rectangle from upper left corner
        Point currPoint = points[i];
        g2.drawRect(currPoint.x, currPoint.y, cornerWidth, cornerHeight);

        // translate to center of rectangle
        currPoint.translate(cornerWidth / 2, cornerHeight / 2);
        drawCenteredDouble(g2, regionAPAValues[i], currPoint);
    }
}

From source file:cz.zeno.miner.ui.MinerUI.java

/**
 * Creates new form MinerUI/*  www. j  a v  a  2s.  co m*/
 */
public MinerUI() {
    //init GUI components
    initComponents();
    Point p = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    p.translate(-this.getWidth() / 2, -this.getHeight() / 2);
    setLocation(p);

    for (String s : Utils.getAvailableSerialPorts())
        device.addItem(s);
    //output, where status text is appended, should always show newest messages.. (shift automatically its caret)
    //        DefaultCaret caret = (DefaultCaret)output.getCaret();  
    //        caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); 
}

From source file:ec.ui.view.RevisionSaSeriesView.java

private void showRevisionPopup(ChartMouseEvent e) {
    XYItemEntity entity = (XYItemEntity) e.getEntity();
    TsPeriod start = firstPeriod.plus(entity.getSeriesIndex());
    popup.setTsData(history_.tsRevision(info_, start, start), null);
    Point p = e.getTrigger().getLocationOnScreen();
    p.translate(3, 3);
    popup.setLocation(p);/* w ww .j  a  v a 2 s  .  c  om*/
    popup.setChartTitle(info_.toUpperCase() + "[" + start.toString() + "] Revisions");
    popup.setVisible(true);
}

From source file:ec.ui.view.RevisionSaSeriesView.java

private void showSelectionPopup(Rectangle2D rectangle) {
    XYPlot plot = chartpanel_.getChart().getXYPlot();
    Rectangle2D dataArea = chartpanel_.getScreenDataArea();
    DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
    double minX = domainAxis.java2DToValue(rectangle.getMinX(), dataArea, plot.getDomainAxisEdge());
    double maxX = domainAxis.java2DToValue(rectangle.getMaxX(), dataArea, plot.getDomainAxisEdge());

    Date startDate = new Date((long) minX);
    Date endDate = new Date((long) maxX);
    TsPeriod start = new TsPeriod(firstPeriod.getFrequency(), startDate);
    TsPeriod end = new TsPeriod(firstPeriod.getFrequency(), endDate);

    if (end.minus(start) == 0) {
        return;/* ww  w.jav  a  2  s. c om*/
    }

    TsPeriodSelector sel = new TsPeriodSelector();
    sel.between(start.firstday(), end.lastday());
    List<TsData> listSeries = history_.Select(info_, startDate, endDate);
    List<TsData> revSeries = new ArrayList<>();

    for (TsData t : listSeries) {
        revSeries.add(t.select(sel));
    }

    Point pt = new Point((int) rectangle.getX(), (int) rectangle.getY());
    pt.translate(3, 3);
    SwingUtilities.convertPointToScreen(pt, chartpanel_);
    popup.setLocation(pt);
    popup.setChartTitle(info_.toUpperCase() + " First estimations");
    popup.setTsData(sRef.select(sel), revSeries);
    popup.setVisible(true);
    chartpanel_.repaint();
}

From source file:Main.java

private Element getHyperlinkElement(MouseEvent event) {
    Point p = event.getPoint();
    int selRow = tree.getRowForLocation(p.x, p.y);
    TreeCellRenderer r = tree.getCellRenderer();
    if (selRow == -1 || r == null) {
        return null;
    }//from   w  w  w  .ja v a  2 s  . c o  m
    TreePath path = tree.getPathForRow(selRow);
    Object lastPath = path.getLastPathComponent();
    Component rComponent = r.getTreeCellRendererComponent(tree, lastPath, tree.isRowSelected(selRow),
            tree.isExpanded(selRow), tree.getModel().isLeaf(lastPath), selRow, true);

    if (rComponent instanceof JEditorPane == false) {
        return null;
    }
    Rectangle pathBounds = tree.getPathBounds(path);
    JEditorPane editor = (JEditorPane) rComponent;
    editor.setBounds(tree.getRowBounds(selRow));
    p.translate(-pathBounds.x, -pathBounds.y);
    int pos = editor.getUI().viewToModel(editor, p);
    if (pos >= 0 && editor.getDocument() instanceof HTMLDocument) {
        HTMLDocument hdoc = (HTMLDocument) editor.getDocument();
        Element elem = hdoc.getCharacterElement(pos);
        if (elem.getAttributes().getAttribute(HTML.Tag.A) != null) {
            return elem;
        }
    }
    return null;
}