Example usage for java.awt Point Point

List of usage examples for java.awt Point Point

Introduction

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

Prototype

public Point(int x, int y) 

Source Link

Document

Constructs and initializes a point at the specified (x,y) location in the coordinate space.

Usage

From source file:edu.ku.brc.specify.plugins.imgproc.ImageProcessorPanel.java

/**
 * /*w  w w  .  j a  v  a2 s.c om*/
 */
protected void doProcLayout() {
    Dimension size = getSize();
    int margin = 20;

    Point p = new Point(margin, margin);
    for (int i = 0; i < 4; i++) {
        switch (i) {
        case 0:
            p.setLocation(margin, margin * 2);
            break;
        case 1:
            p.setLocation(size.width - PROC_ICON_SIZE - margin, margin * 2);
            break;
        case 2:
            p.setLocation(size.width - PROC_ICON_SIZE - margin, size.height - PROC_ICON_SIZE - margin);
            break;
        case 3:
            p.setLocation(margin, size.height - PROC_ICON_SIZE - margin);
            break;
        }
        add(procObjs.get(i));
        procObjs.get(i).setLocation(p);
        procObjs.get(i).setVisible(true);
    }
}

From source file:com.microsoft.alm.plugin.idea.common.ui.controls.HelpPanel.java

private void showToolTip(final boolean immediately) {
    // stop the hiding timer
    hideTooltipTimer.stop();//from   w w w  .jav  a  2 s . co  m

    if (tip != null && tip.isShowing()) {
        // It is already showing
        return;
    }

    if (tip == null) {
        final HelpToolTip toolTipPanel = new HelpToolTip(popupText, popupCommands, this.getWidth());
        tip = new HelpIdeTooltip(this, new Point(getWidth() / 2, 0), toolTipPanel);
    }
    if (immediately) {
        IdeTooltipManager.getInstance().show(tip, true);
    } else {
        // Start the showTooltipTimer to show the tooltip
        showTooltipTimer.start();
    }
}

From source file:modelibra.designer.metaconceptgraphic.MetaConceptGraphic.java

private Point getIntersectionPoint(int x1, int y1, int x2, int y2) {
    Rectangle rect = this.getRectangle();
    if (x2 == x1) /* vertical line */
        return new Point(x2, (y2 < y1 ? rect.y : rect.y + rect.height));
    if (y2 == y1) /* horizontal line */
        return new Point((x2 < x1 ? rect.x : rect.x + rect.width), y2);

    double m = (double) (y2 - y1) / (x2 - x1);
    int x = (x2 < x1 ? rect.x : rect.x + rect.width);
    double fy = m * (x - x2) + y2;
    int y;//from w w w.  j a v a2 s .  com
    /* float comparison, because fy may be bigger than the biggest integer */
    if (fy >= rect.y && fy <= rect.y + rect.height)
        y = (int) fy;
    else {
        y = (y2 < y1 ? rect.y : rect.y + rect.height);
        x = (int) ((y - y2) / m) + x2;
    }
    return new Point(x, y);
}

From source file:ColorSource.java

public void dragGestureRecognized(DragGestureEvent e) {
    // Create an image we can drag along with us.
    // Not all systems support this, but it doesn't hurt to try.
    Image colorblock = this.createImage(25, 25);
    Graphics g = colorblock.getGraphics();
    g.setColor(color);//  w w  w .ja  v a2 s .c o  m
    g.fillRect(0, 0, 25, 25);

    // Start dragging our transferable color object.
    e.startDrag(DragSource.DefaultMoveDrop, // The initial drag cursor
            colorblock, new Point(0, 0), // The image to drag
            tcolor, // The data being dragged
            this); // Who to notify during drag
}

From source file:de.dakror.villagedefense.util.SaveHandler.java

public static void loadSave(File f) {
    try {//from ww  w  . j av a  2s  .  co  m
        JSONObject o = new JSONObject(Compressor.decompressFile(f));
        Game.world.init(o.getInt("width"), o.getInt("height"));
        Game.world.setData((int) Math.ceil(o.getInt("width") / (float) (Chunk.SIZE * Tile.SIZE)),
                (int) Math.ceil(o.getInt("height") / (float) (Chunk.SIZE * Tile.SIZE)),
                Compressor.decompressRow(new BASE64Decoder().decodeBuffer(o.getString("tile"))));
        Game.currentGame.resources = new Resources(o.getJSONObject("resources"));

        if (o.has("created"))
            Game.currentGame.worldCreated = o.getInt("created");

        JSONArray researches = o.getJSONArray("researches");
        Game.currentGame.researches = new ArrayList<>();
        for (int i = 0; i < researches.length(); i++)
            Game.currentGame.researches.add(Researches.valueOf(researches.getString(i)));

        WaveManager.wave = o.getInt("wave") - 1;
        WaveManager.nextWave = o.getInt("time");

        WaveManager.init();

        JSONArray entities = o.getJSONArray("entities");

        HashMap<Integer, Creature> creaturesWithCustomData = new HashMap<>();
        for (int i = 0; i < entities.length(); i++) {
            JSONObject e = entities.getJSONObject(i);
            Entity entity = (Entity) Class.forName(e.getString("class")).getConstructor(int.class, int.class)
                    .newInstance(e.getInt("x"), e.getInt("y"));
            entity.setAttributes(new Attributes(e.getJSONObject("attributes")));
            entity.setResources(new Resources(e.getJSONObject("resources")));

            if (entity instanceof Creature) {
                Creature c = (Creature) entity;
                c.alpha = (float) e.getDouble("alpha");
                c.setSpawnPoint(new Point(e.getInt("spawnX"), e.getInt("spawnY")));

                if (!e.isNull("targetX") || !e.isNull("targetEntity") || !e.isNull("origin")) {
                    creaturesWithCustomData.put(i, c);
                    continue;
                }
            } else if (entity instanceof Struct) {
                JSONArray researches2 = e.getJSONArray("researches");

                ((Struct) entity).clearResearches();
                for (int j = 0; j < researches2.length(); j++)
                    ((Struct) entity).add(Researches.valueOf(researches2.getString(j)));

                ((Struct) entity).tx = e.getInt("tx");
                ((Struct) entity).ty = e.getInt("ty");
            }

            Game.world.addEntity2(entity, true);
        }

        // -- set creatures' custom data
        for (Iterator<Integer> iterator = creaturesWithCustomData.keySet().iterator(); iterator.hasNext();) {
            int index = iterator.next();
            JSONObject e = entities.getJSONObject(index);

            Entity entity = creaturesWithCustomData.get(index);

            if (!e.isNull("targetEntity")) {
                JSONObject tE = e.getJSONObject("targetEntity");
                for (Entity e1 : Game.world.entities) {
                    int x = (int) (e1 instanceof Creature ? e1.getX() : e1.getX() / Tile.SIZE);
                    int y = (int) (e1 instanceof Creature ? e1.getY() : e1.getY() / Tile.SIZE);
                    if (e1.getClass().getName().equals(tE.getString("class")) && tE.getInt("x") == x
                            && tE.getInt("y") == y) {
                        ((Creature) entity).setTarget(e1, false);
                        continue;
                    }
                }
            }
            if (!e.isNull("targetX")) {
                ((Creature) entity).setTarget(e.getInt("targetX"), e.getInt("targetY"), false);
            }
            if (!e.isNull("origin")) {
                JSONObject tE = e.getJSONObject("origin");
                for (Entity e1 : Game.world.entities) {
                    int x = (int) (e1 instanceof Creature ? e1.getX() : e1.getX() / Tile.SIZE);
                    int y = (int) (e1 instanceof Creature ? e1.getY() : e1.getY() / Tile.SIZE);
                    if (e1.getClass().getName().equals(tE.getString("class")) && tE.getInt("x") == x
                            && tE.getInt("y") == y) {
                        ((Creature) entity).setOrigin(e1);
                        continue;
                    }
                }
            }

            Game.world.addEntity2(entity, true);
        }

        Game.currentGame.state = 3;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.lmxm.ute.preferences.AbstractPreferences.java

/**
 * Gets the point.//from   w w w.  ja va  2 s.  co  m
 * 
 * @param key the key
 * @return the point
 */
protected final Point getPoint(final String key) {
    final String prefix = "getPoint() :";

    LOGGER.debug("{} entered, key={}", prefix, key);

    if (!doAllKeysExist(key + X_SUFFIX, key + Y_SUFFIX)) {
        LOGGER.debug("{} X or Y is missing, returning null", prefix);

        return null;
    }

    final int x = getInt(key + X_SUFFIX, 0);
    final int y = getInt(key + Y_SUFFIX, 0);

    if (x < 0 || y < 0) {
        LOGGER.debug("{} x or y is invalid, returning null", prefix);

        return null;
    }

    final Point point = new Point(x, y);

    LOGGER.debug("{} returning {}", prefix, point);

    return point;
}

From source file:ucar.unidata.idv.control.chart.ChartAnnotation.java

/**
 * Distance to the given point. This transforms our x/y
 * to the display space./*from ww w.  ja v a 2s. c o m*/
 *
 * @param x Mouse x
 * @param y Mouse y
 *
 * @return Distance to x/y
 */
public double distance(int x, int y) {
    if (transform != null) {
        Point p = (Point) transform.transform(new Point(getX(), getY()), new Point());
        return distance(p.x, p.y, x, y);
    }
    return distance(getX(), getY(), x, y);
}

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

/**
 * @param g2 graphics2D object/*w w  w .ja v  a 2 s  .com*/
 */
private static void plotColorScaleBar(Graphics2D g2) {
    // calculate color scale bar dimensions & location
    Point csBarTL = new Point(heatmapWidth + colorScaleHorizontalMargin, colorScaleVerticalMargin);
    Point csBarBL = new Point(heatmapWidth + colorScaleHorizontalMargin, fullHeight - colorScaleVerticalMargin);
    Rectangle csBar = new Rectangle(csBarTL.x, csBarTL.y, colorScaleWidth - 2 * colorScaleHorizontalMargin,
            fullHeight - 2 * colorScaleVerticalMargin);

    // plot the color scale linear gradient
    LinearGradientPaint gradient = new LinearGradientPaint(csBarTL, csBarBL, gradientFractions, gradientColors);
    g2.setPaint(gradient);
    g2.fill(csBar);

    // plot a border around color scale
    g2.setColor(Color.black);
    g2.drawRect(csBar.x, csBar.y, csBar.width, csBar.height);
}

From source file:com.eviware.loadui.ui.fx.util.NodeUtils.java

private static Point getMacMouseLocation() {
    Robot robot = MacRobotHolder.getRobot();
    return new Point(robot.getMouseX(), robot.getMouseY());
}

From source file:edu.ku.brc.ui.GradiantButton.java

/**
 * Draws the button body//ww  w .ja  v  a2s  . c o  m
 * @param g2 the graphics to be painted into
 * @param w the width of the control
 * @param h the height of the control
 * @param color the of the background
 */
protected void drawButtonBody(Graphics2D g2, int w, int h, Color color) {
    // draw the button body
    Color grad_top = color.brighter();
    Color grad_bot = color.darker();
    GradientPaint bg = new GradientPaint(new Point(0, 0), grad_top, new Point(0, h), grad_bot);
    g2.setPaint(bg);
    g2.fillRect(0, 0, w, h);
}