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:exploration.rendezvous.MultiPointRendezvousStrategy.java

public static Point getBetterCommLocation(Point point1, Point point2, RealAgent ag) {
    double curSignal = PropModel1.signalStrength(ag.getCommRange(), ag.getOccupancyGrid(), point1, point2);
    double origSignal = curSignal;
    Point curPoint = new Point(point1.x, point1.y);
    boolean foundNewPoint = true;
    while (foundNewPoint && (point1.distance(curPoint) < SimConstants.DEFAULT_SPEED)) {
        foundNewPoint = false;/*from   w  w w.  jav a  2s.  c  o m*/
        int oldX = curPoint.x;
        int oldY = curPoint.y;
        for (int x = oldX - SimConstants.DEFAULT_SPEED; x <= oldX + SimConstants.DEFAULT_SPEED; x++) {
            for (int y = oldY - SimConstants.DEFAULT_SPEED; y <= oldY + SimConstants.DEFAULT_SPEED; y++) {
                Point testPoint = new Point(x, y);
                if (ag.getOccupancyGrid().directLinePossible(point1, testPoint, true, false)) {
                    double newSignal = PropModel1.signalStrength(ag.getCommRange(), ag.getOccupancyGrid(),
                            testPoint, point2);
                    if (newSignal > curSignal) {
                        curPoint = testPoint;
                        curSignal = newSignal;
                        foundNewPoint = true;
                    }
                }
            }
        }
    }
    //if (!curPoint.equals(point1)) {
    if (SimConstants.DEBUG_OUTPUT) {
        System.out.println(ag + " getBetterCommLocation(" + point1 + ", " + point2 + "): " + "origSignal: "
                + origSignal + ", newSignal: " + curSignal + ", newPoint: " + curPoint);
    }
    return curPoint;
    //} else {
    //    return RandomWalk.takeStep(agent);
    //}
}

From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java

/**
 * Returns a generic banded WritableRaster
 * // ww w.  ja v a  2 s  .  c o  m
 * @param numElems
 * @param numLines
 * @param bandOffsets
 * @param dataType
 * @return
 */
public static WritableRaster makeGenericBandedWritableRaster(int numElems, int numLines, int numBands,
        int dataType) {
    int[] bandOffsets = new int[numBands];
    for (int i = 0; i < numBands; ++i)
        bandOffsets[i] = i;

    DataBuffer d = null;
    if (dataType == DataBuffer.TYPE_BYTE)
        d = new DataBufferByte(numElems * numLines * numBands);
    else if (dataType == DataBuffer.TYPE_FLOAT)
        d = new DataBufferFloat(numElems * numLines * numBands);
    else
        throw new IllegalArgumentException("Invalid datatype: " + dataType);

    BandedSampleModel bsm = new BandedSampleModel(dataType, numElems, numLines, bandOffsets.length, bandOffsets,
            bandOffsets);

    SunWritableRaster ras = new SunWritableRaster(bsm, d, new Point(0, 0));
    return ras;
}

From source file:ca.phon.plugins.praat.export.TextGridExportWizard.java

@Override
public void finish() {
    final JPanel glassPane = new JPanel();
    glassPane.setLayout(null);//  w  w w  .  ja  v a2s .c o  m
    glassPane.setOpaque(false);

    final Rectangle exportsRect = exportsTree.getBounds();

    final JXBusyLabel busyLabel = new JXBusyLabel(new Dimension(32, 32));

    final Point busyPoint = new Point((exportsRect.x + exportsRect.width) - 42, 10);
    busyLabel.setLocation(busyPoint);
    glassPane.add(busyLabel);

    final PhonTaskListener busyListener = new PhonTaskListener() {

        @Override
        public void statusChanged(PhonTask task, TaskStatus oldstatus, TaskStatus status) {
            if (status == TaskStatus.RUNNING) {
                busyLabel.setBusy(true);
                glassPane.setVisible(true);
            } else {
                busyLabel.setBusy(false);
                glassPane.setVisible(false);

                generateTask.removeTaskListener(this);
                TextGridExportWizard.super.finish();
            }
        }

        @Override
        public void propertyChanged(PhonTask arg0, String arg1, Object arg2, Object arg3) {
        }
    };
    generateTask.addTaskListener(busyListener);

    final PhonWorker worker = PhonWorker.getInstance();
    worker.invokeLater(generateTask);
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.EditFormControlDlg.java

/**
 * Fills in the initial values.//  w w w .  j  av a2 s.  c  o m
 */
protected void fill() {
    if (xCoord == null) {
        createUI();
    }

    Point location = inputPanel.getLocation();
    xCoord.setValue(((Double) location.getX()).intValue());
    yCoord.setValue(((Double) location.getY()).intValue());
    labelTF.setText(StringUtils.strip(inputPanel.getLabelText(), ":"));

    origLabel = inputPanel.getLabelText();
    origLocation = new Point(location.x, location.y);

    if (isTextField) {
        if (textFieldType != null) {
            fieldTypeIndex = inputPanel.getComp() instanceof JTextField ? 0 : 1;
            textFieldType.setSelectedIndex(fieldTypeIndex);
        }

        if (fieldWidth != null) {
            int cols = inputPanel.getComp() instanceof JTextField
                    ? ((JTextField) inputPanel.getComp()).getColumns()
                    : ((JTextArea) inputPanel.getComp()).getColumns();
            fieldWidth.setValue(cols);
        }

        if (numRows != null) {
            adjustTextRowsUI();
            int rows = inputPanel.getComp() instanceof JTextArea ? ((JTextArea) inputPanel.getComp()).getRows()
                    : 1;
            numRows.setValue(rows);
        }
    }
    changeTracker.clear();
}

From source file:fr.landel.utils.commons.CollectionUtils2Test.java

/**
 * Test method for//from   w w  w  .j  a  v  a  2 s . c o m
 * {@link CollectionUtils2#transformIntoArray(java.lang.Iterable, Transformer)}
 * {@link CollectionUtils2#transformIntoArray(java.lang.Iterable, Function)}
 * .
 */
@Test
public void testTransformIntoArrayIterableOfITransformerOfIO() {
    try {
        List<Point> points = new ArrayList<>();
        points.add(new Point(1, 2));
        points.add(new Point(2, 0));
        points.add(null);

        String[] pointsArray = CollectionUtils2.transformIntoArray(points, TRANSFORMER);

        assertNotNull(pointsArray);
        assertTrue(pointsArray.length > 0);
        assertThat(pointsArray, Matchers.arrayContaining("1, 2", "2, 0", null));

        pointsArray = CollectionUtils2.transformIntoArray(points, FUNCTION);

        assertNotNull(pointsArray);
        assertTrue(pointsArray.length > 0);
        assertThat(pointsArray, Matchers.arrayContaining("1, 2", "2, 0", null));
    } catch (IllegalArgumentException e) {
        fail("The test isn't correct");
    }
}

From source file:net.cloudkit.relaxation.VerifyImage.java

public Point getFirstPoint(BufferedImage image) {
    int w = image.getWidth();
    int h = image.getHeight();

    for (int x = 0; x < w; ++x) {
        for (int y = 0; y < h; ++y) {
            int rgb = getRed(image.getRGB(x, y));
            if (rgb != 255) {
                return new Point(x, y);
            }/*w w w . j  a  va  2 s.c o  m*/
        }
    }

    return new Point(-1, -1);
}

From source file:de.fhg.igd.mapviewer.waypoints.CustomWaypointPainter.java

/**
 * Find a way-point at a given position//from   w  ww .j av a2 s  .c  o m
 * 
 * @param point the position
 * @return the way-point
 */
public W findWaypoint(Point point) {
    Rectangle viewPort = getMapKit().getMainMap().getViewportBounds();

    final int overlap = getMaxOverlap(); // the overlap is the reason why
    // the point is used instead of
    // a GeoPosition

    final int x = viewPort.x + point.x;
    final int y = viewPort.y + point.y;
    final int zoom = getMapKit().getMainMap().getZoom();
    final PixelConverter converter = getMapKit().getMainMap().getTileFactory().getTileProvider().getConverter();

    final Dimension mapSize = TileProviderUtils
            .getMapSize(getMapKit().getMainMap().getTileFactory().getTileProvider(), zoom);
    final int width = mapSize.width
            * getMapKit().getMainMap().getTileFactory().getTileProvider().getTileWidth(zoom);
    final int height = mapSize.height
            * getMapKit().getMainMap().getTileFactory().getTileProvider().getTileHeight(zoom);

    final GeoPosition topLeft = converter
            .pixelToGeo(new Point(Math.max(x - overlap, 0), Math.max(y - overlap, 0)), zoom);
    final GeoPosition bottomRight = converter
            .pixelToGeo(new Point(Math.min(x + overlap, width), Math.min(y + overlap, height)), zoom);

    BoundingBox searchBox;
    try {
        searchBox = createSearchBB(topLeft, bottomRight);

        Set<W> wps = waypoints.query(searchBox, new Verifier<W, BoundingBox>() {

            @Override
            public boolean verify(W wp, BoundingBox box) {
                try {
                    Point2D wpPixel = converter.geoToPixel(wp.getPosition(), zoom);

                    int relX = x - (int) wpPixel.getX();
                    int relY = y - (int) wpPixel.getY();

                    Area area = wp.getMarker().getArea(zoom);
                    if (area != null && area.contains(relX, relY)) {
                        // match
                        return true;
                    }
                } catch (IllegalGeoPositionException e) {
                    log.debug("Error converting waypoint position", e); //$NON-NLS-1$
                }

                return false;
            }
        });

        if (wps == null || wps.isEmpty()) {
            return null;
        } else {
            if (wps.size() == 1) {
                return wps.iterator().next();
            } else {
                List<W> sorted = new ArrayList<W>(wps);
                Collections.sort(sorted, new Comparator<W>() {

                    @Override
                    public int compare(W o1, W o2) {
                        double a1 = o1.getMarker().getArea(zoom).getArea();
                        double a2 = o2.getMarker().getArea(zoom).getArea();

                        // compare size
                        if (a1 < a2) {
                            return -1;
                        } else if (a2 < a1) {
                            return 1;
                        } else {
                            return 0;
                        }
                    }

                });
                return sorted.get(0);
            }
        }
    } catch (IllegalGeoPositionException e) {
        return null;
    }
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplateLibrariesPanel.java

private void initComponents(Channel channel) {
    setBackground(UIConstants.BACKGROUND_COLOR);

    selectAllLabel = new JLabel("<html><u>Select All</u></html>");
    selectAllLabel.setForeground(Color.BLUE);
    selectAllLabel.addMouseListener(new MouseAdapter() {
        @Override/*from   w  w w.j a v  a 2  s. c  o m*/
        public void mouseReleased(MouseEvent evt) {
            for (Enumeration<? extends MutableTreeTableNode> libraryNodes = ((MutableTreeTableNode) libraryTreeTable
                    .getTreeTableModel().getRoot()).children(); libraryNodes.hasMoreElements();) {
                MutableTreeTableNode libraryNode = libraryNodes.nextElement();
                Triple<String, String, Boolean> triple = (Triple<String, String, Boolean>) libraryNode
                        .getUserObject();
                libraryTreeTable.getTreeTableModel().setValueAt(
                        new MutableTriple<String, String, Boolean>(triple.getLeft(), triple.getMiddle(), true),
                        libraryNode, libraryTreeTable.getHierarchicalColumn());
            }
            libraryTreeTable.updateUI();
        }
    });

    selectSeparatorLabel = new JLabel("|");

    deselectAllLabel = new JLabel("<html><u>Deselect All</u></html>");
    deselectAllLabel.setForeground(Color.BLUE);
    deselectAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            for (Enumeration<? extends MutableTreeTableNode> libraryNodes = ((MutableTreeTableNode) libraryTreeTable
                    .getTreeTableModel().getRoot()).children(); libraryNodes.hasMoreElements();) {
                MutableTreeTableNode libraryNode = libraryNodes.nextElement();
                Triple<String, String, Boolean> triple = (Triple<String, String, Boolean>) libraryNode
                        .getUserObject();
                libraryTreeTable.getTreeTableModel().setValueAt(
                        new MutableTriple<String, String, Boolean>(triple.getLeft(), triple.getMiddle(), false),
                        libraryNode, libraryTreeTable.getHierarchicalColumn());
            }
            libraryTreeTable.updateUI();
        }
    });

    expandAllLabel = new JLabel("<html><u>Expand All</u></html>");
    expandAllLabel.setForeground(Color.BLUE);
    expandAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            libraryTreeTable.expandAll();
        }
    });

    expandSeparatorLabel = new JLabel("|");

    collapseAllLabel = new JLabel("<html><u>Collapse All</u></html>");
    collapseAllLabel.setForeground(Color.BLUE);
    collapseAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            libraryTreeTable.collapseAll();
        }
    });

    final TableCellEditor libraryCellEditor = new LibraryTreeCellEditor();

    libraryTreeTable = new MirthTreeTable() {
        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            if (isHierarchical(column)) {
                return libraryCellEditor;
            } else {
                return super.getCellEditor(row, column);
            }
        }
    };

    DefaultTreeTableModel model = new SortableTreeTableModel();
    DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode();
    model.setRoot(rootNode);

    libraryTreeTable.setLargeModel(true);
    libraryTreeTable.setTreeTableModel(model);
    libraryTreeTable.setOpenIcon(null);
    libraryTreeTable.setClosedIcon(null);
    libraryTreeTable.setLeafIcon(null);
    libraryTreeTable.setRootVisible(false);
    libraryTreeTable.setDoubleBuffered(true);
    libraryTreeTable.setDragEnabled(false);
    libraryTreeTable.setRowSelectionAllowed(true);
    libraryTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    libraryTreeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    libraryTreeTable.setFocusable(true);
    libraryTreeTable.setOpaque(true);
    libraryTreeTable.setEditable(true);
    libraryTreeTable.setSortable(false);
    libraryTreeTable.setAutoCreateColumnsFromModel(false);
    libraryTreeTable.setShowGrid(true, true);
    libraryTreeTable.setTableHeader(null);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        libraryTreeTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    libraryTreeTable.setTreeCellRenderer(new LibraryTreeCellRenderer());

    libraryTreeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelection(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelection(evt);
        }

        private void checkSelection(MouseEvent evt) {
            if (libraryTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())) < 0) {
                libraryTreeTable.clearSelection();
            }
        }
    });

    libraryTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                boolean visible = false;
                int selectedRow = libraryTreeTable.getSelectedRow();

                if (selectedRow >= 0) {
                    TreePath selectedPath = libraryTreeTable.getPathForRow(selectedRow);
                    if (selectedPath != null) {
                        visible = true;
                        Triple<String, String, Boolean> triple = (Triple<String, String, Boolean>) ((MutableTreeTableNode) selectedPath
                                .getLastPathComponent()).getUserObject();
                        String description = "";

                        if (selectedPath.getPathCount() == 2) {
                            description = libraryMap.get(triple.getLeft()).getDescription();
                        } else if (selectedPath.getPathCount() == 3) {
                            description = PlatformUI.MIRTH_FRAME.codeTemplatePanel.getCachedCodeTemplates()
                                    .get(triple.getLeft()).getDescription();
                        }

                        if (StringUtils.isBlank(description) || StringUtils.equals(description, CodeTemplateUtil
                                .getDocumentation(CodeTemplate.DEFAULT_CODE).getDescription())) {
                            descriptionTextPane.setText(
                                    "<html><body class=\"code-template-libraries-panel\"><i>No description.</i></body></html>");
                        } else {
                            descriptionTextPane.setText("<html><body class=\"code-template-libraries-panel\">"
                                    + MirthXmlUtil.encode(description) + "</body></html>");
                        }
                    }
                }

                descriptionScrollPane.setVisible(visible);
                updateUI();
            }
        }
    });

    libraryTreeTableScrollPane = new JScrollPane(libraryTreeTable);

    descriptionTextPane = new JTextPane();
    descriptionTextPane.setContentType("text/html");
    HTMLEditorKit editorKit = new HTMLEditorKit();
    StyleSheet styleSheet = editorKit.getStyleSheet();
    styleSheet.addRule(".code-template-libraries-panel {font-family:\"Tahoma\";font-size:11;text-align:top}");
    descriptionTextPane.setEditorKit(editorKit);
    descriptionTextPane.setEditable(false);
    descriptionScrollPane = new JScrollPane(descriptionTextPane);
    descriptionScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    descriptionScrollPane.setVisible(false);
}

From source file:it.unibas.spicygui.controllo.provider.intermediatezone.WidgetCreator.java

public Widget createAttributeGroupWidget(Scene scene, LayerWidget mainLayer, LayerWidget connectionLayer,
        JPanel pannelloPrincipale, Point point, GraphSceneGlassPane glassPane) {
    AttributeGroupWidget rootWidget = new AttributeGroupWidget(scene, point);
    CaratteristicheWidgetInterAttributeGroup caratteristicheWidget = new CaratteristicheWidgetInterAttributeGroup();
    caratteristicheWidget.setTreeType(Costanti.INTERMEDIE);
    //        rootWidget.getActions().addAction(ActionFactory.createPopupMenuAction(new MyPopupProviderDeleteAttributeGroup(glassPane)));

    CaratteristicheBarra caratteristicheBarra = new CaratteristicheBarra(rootWidget, Costanti.INTERMEDIE_BARRA);
    IconNodeWidget barra = new IconNodeWidget(scene);
    barra.setImage(ImageUtilities.loadImage(Costanti.ICONA_MOVE));
    Point pointBarra = new Point(rootWidget.getPreferredLocation().x - Costanti.OFF_SET_X_WIDGET_BARRA,
            rootWidget.getPreferredLocation().y - Costanti.OFF_SET_Y_WIDGET_BARRA);
    barra.setPreferredLocation(pointBarra);
    IntermediateMoveProvider moveProvider = new IntermediateMoveProvider(pannelloPrincipale);
    barra.getActions().addAction(ActionFactory.createMoveAction(moveProvider, moveProvider));
    caratteristicheWidget.setWidgetBarra(barra);

    mainLayer.addChild(rootWidget, caratteristicheWidget);
    mainLayer.addChild(barra, caratteristicheBarra);

    //        glassPane.addAttributeGroup(rootWidget);
    //        glassPane.addAttributeGroup(barra);

    return rootWidget;
}

From source file:de.tor.tribes.ui.views.DSWorkbenchDoItYourselfAttackPlaner.java

@Override
public void resetView() {
    AttackManager.getSingleton().addManagerListener(this);
    //setup renderer and general view
    // ((DoItYourselfAttackTableModel) jAttackTable.getModel()).clear();

    HighlightPredicate.ColumnHighlightPredicate colu = new HighlightPredicate.ColumnHighlightPredicate(0, 1, 2,
            3, 6);//from  w w  w  .j a  v  a2  s.c  om
    jAttackTable.setRowHeight(24);
    jAttackTable.getTableHeader().setDefaultRenderer(new DefaultTableHeaderRenderer());
    jAttackTable.setHighlighters(new CompoundHighlighter(colu,
            HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B)));
    jAttackTable.setColumnControlVisible(true);
    jAttackTable.setDefaultEditor(UnitHolder.class, new UnitCellEditor());
    jAttackTable.setDefaultEditor(Village.class, new VillageCellEditor());
    jAttackTable.setDefaultRenderer(UnitHolder.class, new UnitCellRenderer());
    jAttackTable.setDefaultRenderer(Integer.class,
            new NoteIconCellRenderer(NoteIconCellRenderer.ICON_TYPE.NOTE));
    jAttackTable.setDefaultRenderer(Date.class, new ColoredDateCellRenderer());
    jAttackTable.setDefaultRenderer(Long.class, new ColoredCoutdownCellRenderer());
    jAttackTable.setDefaultEditor(Date.class, new DateSpinEditor());
    jAttackTable.setDefaultEditor(Integer.class, new NoteIconCellEditor(NoteIconCellEditor.ICON_TYPE.NOTE));
    BufferedImage back = ImageUtils.createCompatibleBufferedImage(5, 5, BufferedImage.BITMASK);
    Graphics2D g = back.createGraphics();
    GeneralPath p = new GeneralPath();
    p.moveTo(0, 0);
    p.lineTo(5, 0);
    p.lineTo(5, 5);
    p.closePath();
    g.setColor(Color.GREEN.darker());
    g.fill(p);
    g.dispose();
    jAttackTable.addHighlighter(new PainterHighlighter(HighlightPredicate.EDITABLE,
            new ImagePainter(back, HorizontalAlignment.RIGHT, VerticalAlignment.TOP)));

    DefaultComboBoxModel model = new DefaultComboBoxModel();
    DefaultComboBoxModel model2 = new DefaultComboBoxModel();
    for (UnitHolder unit : DataHolder.getSingleton().getUnits()) {
        model.addElement(unit);
        model2.addElement(unit);
    }
    jUnitBox.setModel(model);
    jUnitComboBox.setModel(model2);
    jUnitBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram"));
    jUnitComboBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram"));
    jUnitBox.setRenderer(new UnitListCellRenderer());
    jAttackTypeComboBox.setRenderer(new StandardAttackListCellRenderer());

    DefaultComboBoxModel typeModel = new DefaultComboBoxModel();

    for (ManageableType t : StandardAttackManager.getSingleton().getAllElements()) {
        StandardAttack a = (StandardAttack) t;
        typeModel.addElement(a);
    }
    jAttackTypeComboBox.setModel(typeModel);

    jUnitComboBox.setRenderer(new UnitListCellRenderer());

    jSourceVillage.setValue(new Point(500, 500));
    jTargetVillage.setValue(new Point(500, 500));
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            jSourceVillage.updateUI();
            jTargetVillage.updateUI();
        }
    });

}