List of usage examples for java.awt Point Point
public Point(int x, int y)
From source file:fr.fg.server.contract.NpcHelper.java
public static Point getNearestFreeTile(Area area, Point location) { boolean found = false; int x = 0, y = 0; for (int step = 0; step < 100 && !found; step++) for (int i = -step; i <= step && !found; i++) { if (area.isFreeTile(location.x + i, location.y - step, Area.NO_FLEETS | Area.NO_SYSTEMS, null)) { x = location.x + i;//from ww w . ja v a 2s . c om y = location.y - step; found = true; } else if (area.isFreeTile(location.x - step, location.y + i, Area.NO_FLEETS | Area.NO_SYSTEMS, null)) { x = location.x - step; y = location.y + i; found = true; } else if (area.isFreeTile(location.x + i, location.y + step, Area.NO_FLEETS | Area.NO_SYSTEMS, null)) { x = location.x + i; y = location.y + step; found = true; } else if (area.isFreeTile(location.x + step, location.y + i, Area.NO_FLEETS | Area.NO_SYSTEMS, null)) { x = location.x + step; y = location.y + i; found = true; } } if (!found) return null; return new Point(x, y); }
From source file:edu.purdue.cc.bionet.ui.HeatMap.java
/** * Scales to the given zoom level, 1.0 being 100%, centered on the * given point.// w w w . java 2 s . com * * @param level The level to zoom to. * @param center The center point for the scaling operation. * @return The new zoom level. */ public float scaleTo(float level, Point2D center) { float oldZoom = this.currentZoom; this.currentZoom = Math.max(level, 0.99f); Dimension viewSize; if (level < 1.0f) { viewSize = this.scrollPane.getSize(); } else { viewSize = this.scrollPane.getViewport().getExtentSize(); } Dimension newSize = new Dimension((int) (viewSize.width * currentZoom), (int) (viewSize.height * currentZoom)); this.setPreferredSize(newSize); this.setSize(newSize); // translate the new view position so the mouse is in the same place // on the scaled view. JViewport vp = this.scrollPane.getViewport(); double centerX = center.getX(); double centerY = center.getY(); double viewPortMouseX = centerX - vp.getViewPosition().getX(); double viewPortMouseY = centerY - vp.getViewPosition().getY(); centerX *= currentZoom / oldZoom; centerY *= currentZoom / oldZoom; viewPortMouseX = centerX - viewPortMouseX; viewPortMouseY = centerY - viewPortMouseY; vp.setViewPosition(new Point((int) viewPortMouseX, (int) viewPortMouseY)); return this.currentZoom; }
From source file:net.sf.maltcms.chromaui.charts.events.XYAnnotationAdder.java
/** * @param plot//from www.j a va 2 s . c om * @param xd * @param yd * @param label * @param notify */ public XYSelectableShapeAnnotation<Peak2D> addXYPeakAnnotation(final double xd, final double yd, final Peak2D p, final boolean notify) { //System.out.println("Adding XY Peak Annotation"); Peak2D peak = (p == null ? new Peak2D() : p); PeakArea2D pa = peak.getPeakArea(); if (pa == null) { pa = new PeakArea2D(new Point((int) xd, (int) yd), new ArrayDouble.D1(1), -1, -1, -1); peak.setPeakArea(pa); } else { Point s = pa.getSeedPoint(); if (s == null) { s = new Point((int) xd, (int) yd); pa.setSeedPoint(s); } } final XYSelectableShapeAnnotation<Peak2D> xypa = new XYSelectableShapeAnnotation<>(xd, yd, getCrosshairShape(xd, yd, 5, 5), "Peak @" + xd + "," + yd + " idx: " + peak.getIndex(), TextAnchor.BOTTOM_LEFT, peak); if (activeInstance != null) { activeInstance.setActive(false); } xypa.setActive(true); activeInstance = xypa; Point2D point = new Point2D.Double(xd, yd); qt.put(point, xypa); AEvent<XYAnnotation> e = new AEvent<>(xypa, this, "XYANNOTATION_ADD"); fireEvent(e); fireOverlayChanged(); // SwingUtilities.invokeLater(r); this.annotations.add(xypa); return xypa; }
From source file:net.bioclipse.model.ScatterPlotMouseHandler.java
public void mouseClicked(MouseEvent me) { Point2D p = null;//from w w w . j a va 2 s . c om ChartDescriptor cd = null; int[] indices = null; JFreeChart selectedChart = null; ChartPanel chartPanel = getChartPanel(me); p = chartPanel.translateScreenToJava2D(new Point(me.getX(), me.getY())); selectedChart = chartPanel.getChart(); cd = ChartUtils.getChartDescriptor(selectedChart); indices = cd.getSourceIndices(); XYPlot plot = (XYPlot) chartPanel.getChart().getPlot(); XYItemRenderer plotRenderer = plot.getRenderer(); if (!(plotRenderer instanceof ScatterPlotRenderer)) { throw new IllegalStateException( "Charts using ScatterPlotMouseHandler must use ScatterPlotRenderer as their renderer"); } renderer = (ScatterPlotRenderer) plot.getRenderer(); // now convert the Java2D coordinate to axis coordinates... Number xx = getDomainX(chartPanel, plot, p); Number yy = getRangeY(chartPanel, plot, p); //Find the selected point in the dataset //If shift is down, save old selections if (!me.isShiftDown() || currentSelection == null) { currentSelection = new ChartSelection(); } for (int j = 0; j < plot.getDataset().getItemCount(plot.getDataset().getSeriesCount() - 1); j++) { for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) { Number xK = plot.getDataset().getX(i, j); Number yK = plot.getDataset().getY(i, j); Number xKCheck = xK.doubleValue() - xx.doubleValue(); Number yKCheck = yK.doubleValue() - yy.doubleValue(); Number xxCheck = xKCheck.doubleValue() * xKCheck.doubleValue(); Number yyCheck = yKCheck.doubleValue() * yKCheck.doubleValue(); //Check distance from click and point, don't want to mark points that are too far from the click if (Math.sqrt(xxCheck.doubleValue()) <= 0.1 && Math.sqrt(yyCheck.doubleValue()) <= 0.1) { //Create a new selection PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel()); cp.setDataPoint(j, i); currentSelection.addPoint(cp); if (!me.isShiftDown()) renderer.clearMarkedPoints(); renderer.addMarkedPoint(j, i); selectedChart.plotChanged(new PlotChangeEvent(plot)); } } } currentSelection.setDescriptor(cd); ChartUtils.updateSelection(currentSelection); }
From source file:com.mirth.connect.client.ui.SettingsPanelDatabaseTasks.java
private void initComponents() { JPanel containerPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3, fill")); containerPanel.setBackground(getBackground()); containerPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(204, 204, 204)), "Database Tasks", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 1, 11))); containerPanel.add(new JLabel( "Cleanup or optimization tasks for the internal database. If no tasks are present, no action is necessary."), "top, wrap"); taskTable = new MirthTable(); taskTable/*from w w w.j ava2 s . com*/ .setModel(new RefreshTableModel(new Object[] { "Status", "Name", "Description", "Start Time" }, 0)); taskTable.setDragEnabled(false); taskTable.setRowSelectionAllowed(true); taskTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); taskTable.setRowHeight(UIConstants.ROW_HEIGHT); taskTable.setFocusable(false); taskTable.setOpaque(true); taskTable.getTableHeader().setReorderingAllowed(false); taskTable.setEditable(false); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { taskTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } taskTable.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 (taskTable.rowAtPoint(new Point(evt.getX(), evt.getY())) < 0) { taskTable.clearSelection(); setVisibleTasks(2, 3, false); } } }); taskTable.getColumnModel().getColumn(0).setMinWidth(75); taskTable.getColumnModel().getColumn(0).setMaxWidth(75); taskTable.getColumnModel().getColumn(0).setCellRenderer(new ImageCellRenderer()); taskTable.getColumnModel().getColumn(1).setMinWidth(45); taskTable.getColumnModel().getColumn(1).setPreferredWidth(250); taskTable.getColumnModel().getColumn(2).setMinWidth(75); taskTable.getColumnModel().getColumn(2).setPreferredWidth(475); taskTable.getColumnModel().getColumn(3).setMinWidth(95); taskTable.getColumnModel().getColumn(3).setMaxWidth(95); taskTable.getColumnModel().getColumn(3).setCellRenderer(new DateCellRenderer()); taskTable.getSelectionModel().addListSelectionListener(this); JScrollPane taskTableScrollPane = new JScrollPane(taskTable); containerPanel.add(taskTableScrollPane, "grow, push"); add(containerPanel, "grow, h 60%"); JPanel channelsPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3, fill")); channelsPanel.setBackground(getBackground()); channelsPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(204, 204, 204)), "Affected Channels", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 1, 11))); channelsTable = new MirthTable(); channelsTable.setModel(new RefreshTableModel(new Object[] { "Name", "Id" }, 0)); channelsTable.setDragEnabled(false); channelsTable.setRowSelectionAllowed(false); channelsTable.setRowHeight(UIConstants.ROW_HEIGHT); channelsTable.setFocusable(false); channelsTable.setOpaque(true); channelsTable.getTableHeader().setReorderingAllowed(false); channelsTable.setEditable(false); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { channelsTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } channelsPanel.add(new JScrollPane(channelsTable), "grow"); add(channelsPanel, "newline, grow, h 40%"); }
From source file:ScribbleDragAndDrop.java
/** * This method implements the DragGestureListener interface. It will be * invoked when the DragGestureRecognizer thinks that the user has initiated * a drag. If we're not in drawing mode, then this method will try to figure * out which Scribble object is being dragged, and will initiate a drag on * that object.//ww w . j ava 2s . c o m */ public void dragGestureRecognized(DragGestureEvent e) { // Don't drag if we're not in drag mode if (!dragMode) return; // Figure out where the drag started MouseEvent inputEvent = (MouseEvent) e.getTriggerEvent(); int x = inputEvent.getX(); int y = inputEvent.getY(); // Figure out which scribble was clicked on, if any by creating a // small rectangle around the point and testing for intersection. Rectangle r = new Rectangle(x - LINEWIDTH, y - LINEWIDTH, LINEWIDTH * 2, LINEWIDTH * 2); int numScribbles = scribbles.size(); for (int i = 0; i < numScribbles; i++) { // Loop through the scribbles Scribble s = (Scribble) scribbles.get(i); if (s.intersects(r)) { // The user started the drag on top of this scribble, so // start to drag it. // First, remember which scribble is being dragged, so we can // delete it later (if this is a move rather than a copy) beingDragged = s; // Next, create a copy that will be the one dragged Scribble dragScribble = (Scribble) s.clone(); // Adjust the origin to the point the user clicked on. dragScribble.translate(-x, -y); // Choose a cursor based on the type of drag the user initiated Cursor cursor; switch (e.getDragAction()) { case DnDConstants.ACTION_COPY: cursor = DragSource.DefaultCopyDrop; break; case DnDConstants.ACTION_MOVE: cursor = DragSource.DefaultMoveDrop; break; default: return; // We only support move and copys } // Some systems allow us to drag an image along with the // cursor. If so, create an image of the scribble to drag if (dragSource.isDragImageSupported()) { Rectangle scribbleBox = dragScribble.getBounds(); Image dragImage = this.createImage(scribbleBox.width, scribbleBox.height); Graphics2D g = (Graphics2D) dragImage.getGraphics(); g.setColor(new Color(0, 0, 0, 0)); // transparent background g.fillRect(0, 0, scribbleBox.width, scribbleBox.height); g.setColor(Color.black); g.setStroke(linestyle); g.translate(-scribbleBox.x, -scribbleBox.y); g.draw(dragScribble); Point hotspot = new Point(-scribbleBox.x, -scribbleBox.y); // Now start dragging, using the image. e.startDrag(cursor, dragImage, hotspot, dragScribble, this); } else { // Or start the drag without an image e.startDrag(cursor, dragScribble, this); } // After we've started dragging one scribble, stop looking return; } } }
From source file:de.fhg.igd.mapviewer.BasicMapKit.java
/** * Set the map kit's map server//from w w w . j a v a 2 s . c o m * * @param server the map server * @param skipZoom if zooming to the area visible in the last map shall be * skipped (makes sense when instead loading the state from file) */ public void setServer(final MapServer server, final boolean skipZoom) { this.server = server; // remember map area final Set<GeoPosition> gps = new HashSet<GeoPosition>(); gps.add(getMainMap().convertPointToGeoPosition(new Point((int) Math.round(getMainMap().getWidth() * 0.1), (int) Math.round(getMainMap().getHeight() * 0.1)))); gps.add(getMainMap().convertPointToGeoPosition(new Point((int) Math.round(getMainMap().getWidth() * 0.9), (int) Math.round(getMainMap().getHeight() * 0.9)))); onChangingServer(server); IJob<Void> job = new Job<Void>(Messages.BasicMapKit_0, new SwingCallback<Void>() { @Override protected void finished(Void result) { // dispose old map overlay Painter<?>[] oldOverlays = mapPainter.getPainters(); if (oldOverlays != null) { for (Painter<?> oldOverlay : oldOverlays) { if (oldOverlay instanceof MapPainter) { ((MapPainter) oldOverlay).dispose(); } } } // set the new map overlay MapPainter mapOverlay = server.getMapOverlay(); if (mapOverlay != null) { mapPainter.setPainters(mapOverlay); mapOverlay.setMapKit(BasicMapKit.this); } else { mapPainter.setPainters(); } getMainMap().setOverlayPainter(painter); if (!skipZoom) { // done in the step below - setCenterPosition(pos); zoomToPositions(gps); } revalidate(); } @Override protected void error(Throwable e) { log.error("Error configuring map", e); //$NON-NLS-1$ } }) { @Override public Void work(Progress progress) throws Exception { // configure the map kit BasicMapKit.this.setTileFactory(server.getTileFactory(cache)); return null; } }; Concurrency.startJob(job); }
From source file:ca.sqlpower.architect.swingui.TestPlayPen.java
/** * Test to ensure that when importing two copies of a self-referencing table, the * correct number of relationships get added, and furthermore, the relationships * all point to the correct table./* www. j a v a 2 s. c o m*/ * @throws Exception */ public void testImportTableCopyOnTwoCopiesOfSelfReferencingTable() throws Exception { SQLDatabase sourceDB = new SQLDatabase(); pp.getSession().getRootObject().addChild(sourceDB); SQLTable table = new SQLTable(sourceDB, true); table.setName("self_ref"); SQLColumn pkCol = new SQLColumn(table, "key", Types.INTEGER, 10, 0); table.addColumn(pkCol); table.addToPK(table.getColumn(0)); SQLColumn fkCol = new SQLColumn(table, "self_ref_column", Types.INTEGER, 10, 0); table.addColumn(fkCol); SQLRelationship rel = new SQLRelationship(); rel.attachRelationship(table, table, false); rel.addMapping(pkCol, fkCol); sourceDB.addChild(table); pp.importTableCopy(table, new Point(10, 10), ASUtils.createDuplicateProperties(pp.getSession(), table)); pp.importTableCopy(table, new Point(30, 30), ASUtils.createDuplicateProperties(pp.getSession(), table)); int relCount = 0; int tabCount = 0; int otherCount = 0; for (PlayPenComponent ppc : pp.getContentPane().getChildren()) { if (ppc instanceof Relationship) { relCount++; } else if (ppc instanceof TablePane) { tabCount++; } else { otherCount++; } } assertEquals("Expected two tables in pp", 2, tabCount); assertEquals("Expected two relationships in pp", 2, relCount); assertEquals("Found junk in playpen", 0, otherCount); for (SQLTable t : pp.getTables()) { List<SQLRelationship> exportedKeys = t.getExportedKeys(); List<SQLRelationship> importedKeys = SQLRelationship.getExportedKeys(t.getImportedKeys()); assertEquals("Expected only one exported key in table", 1, exportedKeys.size()); assertEquals("Expected only one imported key in table", 1, importedKeys.size()); SQLRelationship exportedKey = exportedKeys.get(0); SQLRelationship importedKey = importedKeys.get(0); assertEquals("Expected exported key PK and FK tables to be the same", exportedKey.getFkTable(), exportedKey.getPkTable()); assertEquals("Expected imported key PK and FK tables to be the same", importedKey.getFkTable(), importedKey.getPkTable()); assertEquals("Expected exported key and imported key tables to be the same", exportedKey.getPkTable(), importedKey.getPkTable()); } }
From source file:de.fhg.igd.mapviewer.server.ClippingTileProviderDecorator.java
/** * Constructor/*from w w w . java 2s.com*/ * * @param tileProvider the tile provider * @param topLeft the top left constraint * @param bottomRight the bottom right constraint * @param minRange the minimum visible range * @param customOverlayColor custom overlay color to use, may be * <code>null</code> */ public ClippingTileProviderDecorator(final TileProvider tileProvider, final GeoPosition topLeft, final GeoPosition bottomRight, int minRange, Color customOverlayColor) { super(tileProvider); if (minRange <= 0) minRange = 1; int zoom = tileProvider.getMinimumZoom(); boolean tryNextZoom = true; // determine valid zoom levels and their tile offsets/ranges while (tryNextZoom && zoom <= tileProvider.getMaximumZoom()) { try { Point2D topLeftPixel = tileProvider.getConverter().geoToPixel(topLeft, zoom); Point2D bottomRightPixel = tileProvider.getConverter().geoToPixel(bottomRight, zoom); int xMin = ((int) topLeftPixel.getX()) / tileProvider.getTileWidth(zoom); int yMin = ((int) topLeftPixel.getY()) / tileProvider.getTileHeight(zoom); int xMax = ((int) bottomRightPixel.getX()) / tileProvider.getTileWidth(zoom); int yMax = ((int) bottomRightPixel.getY()) / tileProvider.getTileHeight(zoom); // check for validity if (xMin <= xMax && yMin <= yMax && TileProviderUtils.isValidTile(tileProvider, xMin, yMin, zoom) && TileProviderUtils.isValidTile(tileProvider, xMax, yMax, zoom)) { // valid tiles, enter offset and ranges xTileOffset.add(xMin); xTileRange.add(xMax - xMin + 1); yTileOffset.add(yMin); yTileRange.add(yMax - yMin + 1); this.topLeft.add(new Point((int) topLeftPixel.getX() - xMin * tileProvider.getTileWidth(zoom), (int) topLeftPixel.getY() - yMin * tileProvider.getTileHeight(zoom))); this.bottomRight .add(new Point((int) bottomRightPixel.getX() - xMin * tileProvider.getTileWidth(zoom), (int) bottomRightPixel.getY() - yMin * tileProvider.getTileHeight(zoom))); if (xMax - xMin + 1 <= minRange || yMax - yMin + 1 <= minRange) tryNextZoom = false; // we reached the max zoom else zoom++; // prepare next zoom } else { // invalid tiles tryNextZoom = false; zoom--; // previous zoom } } catch (IllegalGeoPositionException e) { // invalid positions or conversion failed tryNextZoom = false; zoom--; // previous zoom } } if (zoom < getMinimumZoom()) { throw new IllegalArgumentException("No zoom levels are valid for clipping"); //$NON-NLS-1$ } else { maxZoom = zoom; painter = new ClippingPainter(customOverlayColor); log.info("Initialized ClippingTileProviderDecorator with minZoom = " //$NON-NLS-1$ + tileProvider.getMinimumZoom() + ", maxZoom = " + maxZoom); //$NON-NLS-1$ } }
From source file:GraphicsUtil.java
/** * Coerces <tt>ras</tt> to be writable. The returned Raster continues to * reference the DataBuffer from ras, so modifications to the returned * WritableRaster will be seen in ras.<p> * * You can specify a new location for the returned WritableRaster, this * is especially useful for constructing BufferedImages which require * the Raster to be at (0,0)./* w w w. j a va2 s. c om*/ * * This method should only be used if you need a WritableRaster due to * an interface (such as to construct a BufferedImage), but have no * intention of modifying the contents of the returned Raster. If * you have any doubt about other users of the data in <tt>ras</tt>, * use copyRaster (above). * * @param ras The raster to make writable. * * @param minX The x location for the upper left corner of the * returned WritableRaster. * * @param minY The y location for the upper left corner of the * returned WritableRaster. * * @return A Writable version of <tT>ras</tt> with it's upper left * hand coordinate set to minX, minY (shares it's DataBuffer * with <tt>ras</tt>). */ public static WritableRaster makeRasterWritable(Raster ras, int minX, int minY) { WritableRaster ret = Raster.createWritableRaster(ras.getSampleModel(), ras.getDataBuffer(), new Point(0, 0)); ret = ret.createWritableChild(ras.getMinX() - ras.getSampleModelTranslateX(), ras.getMinY() - ras.getSampleModelTranslateY(), ras.getWidth(), ras.getHeight(), minX, minY, null); return ret; }