List of usage examples for java.awt Point Point
public Point(int x, int y)
From source file:com.openbravo.pos.util.ThumbNailBuilder.java
public Image getThumbNailText(Image img, String text) { /*/*from w w w. jav a 2 s .c om*/ * Create an image containing a thumbnail of the product image, * or default image. * * Then apply the text of the product name. Use text wrapping. * * If the product name is too big for the label, ensure that * the first part is displayed. */ img = getThumbNail(img); BufferedImage imgtext = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = imgtext.createGraphics(); // The text // <p style="width: 100px"> DOES NOT WORK PROPERLY. // use width= instead. String html = "<html><p style=\"text-align:center\" width=\"" + imgtext.getWidth() + "\">" + StringEscapeUtils.escapeHtml(text) + "</p>"; JLabel label = new JLabel(html); label.setOpaque(false); //label.setText("<html><center>Line1<br>Line2"); label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); label.setVerticalAlignment(javax.swing.SwingConstants.TOP); Dimension d = label.getPreferredSize(); label.setBounds(0, 0, imgtext.getWidth(), d.height); // The background Color c1 = new Color(0xff, 0xff, 0xff, 0x40); Color c2 = new Color(0xff, 0xff, 0xff, 0xd0); // Point2D center = new Point2D.Float(imgtext.getWidth() / 2, label.getHeight()); // float radius = imgtext.getWidth() / 3; // float[] dist = {0.1f, 1.0f}; // Color[] colors = {c2, c1}; // Paint gpaint = new RadialGradientPaint(center, radius, dist, colors); Paint gpaint = new GradientPaint(new Point(0, 0), c1, new Point(label.getWidth() / 2, 0), c2, true); g2d.drawImage(img, 0, 0, null); int ypos = imgtext.getHeight() - label.getHeight(); int ypos_min = -4; // todo: configurable if (ypos < ypos_min) ypos = ypos_min; // Clamp label g2d.translate(0, ypos); g2d.setPaint(gpaint); g2d.fillRect(0, 0, imgtext.getWidth(), label.getHeight()); label.paint(g2d); g2d.dispose(); return imgtext; }
From source file:com.lcdfx.pipoint.PiPoint.java
public PiPoint(String[] args) { this.addWindowListener(new WindowAdapter() { @Override/*from w w w . ja v a2 s . c om*/ public void windowClosing(WindowEvent ev) { shutDown(); } }); // add logging logger = Logger.getLogger(this.getClass().getName()); logger.log(Level.INFO, "PiPoint version " + PiPoint.class.getPackage().getImplementationVersion() + " running under " + System.getProperty("java.vm.name") + " v" + System.getProperty("java.vm.version")); // get command line options CommandLineParser parser = new BasicParser(); Map<String, String> cmdOptions = new HashMap<String, String>(); Options options = new Options(); options.addOption(new Option("f", "fullscreen", false, "fullscreen mode (no cursor)")); CommandLine cmd = null; try { cmd = parser.parse(options, args); for (Option option : cmd.getOptions()) { cmdOptions.put(option.getOpt(), option.getValue()); } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar pipoint.jar", options); System.exit(0); } if (cmd.hasOption("f")) { setUndecorated(true); BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor"); getContentPane().setCursor(blankCursor); } // instantiate the RendererManager mgr = new DlnaRendererManager(this); mgr.refreshDevices(); nowPlayingPanel = new NowPlayingPanel(this); mgr.getRenderer().addListener(nowPlayingPanel); devicePanel = new DevicePanel(this); this.getContentPane().setPreferredSize(new Dimension(DISPLAY_WIDTH, DISPLAY_HEIGHT)); this.getContentPane().add(devicePanel); }
From source file:TextFormat.java
/** * Lazy evaluation of the List of TextLayout objects corresponding to this * MText. Some things are approximations! *//* w w w. j av a 2 s . c om*/ private void getLayouts(Graphics g) { layouts = new ArrayList(); Point pen = new Point(10, 20); Graphics2D g2d = (Graphics2D) g; FontRenderContext frc = g2d.getFontRenderContext(); AttributedString attrStr = new AttributedString(text); attrStr.addAttribute(TextAttribute.FONT, font, 0, text.length()); LineBreakMeasurer measurer = new LineBreakMeasurer(attrStr.getIterator(), frc); float wrappingWidth; wrappingWidth = getSize().width - 15; while (measurer.getPosition() < text.length()) { TextLayout layout = measurer.nextLayout(wrappingWidth); layouts.add(layout); } }
From source file:com.mycompany.complexity.tool.mvn.TreeLayout.java
protected void buildTree() { this.m_currentPoint = new Point(size.width / 2, 20); int maxNumberOfParents = 0; Collection<V> roots = TreeUtils.getRoots(graph); if (roots.size() > 0 && graph != null) { calculateDimensionX(roots);// ww w.j a v a2s. c o m V firstV = null; for (V v : graph.getVertices()) { int temp = graph.inDegree(v); if (temp > maxNumberOfParents) { maxNumberOfParents = temp; } } for (V v : roots) { calculateDimensionX(v); if (firstV == null) { firstV = v; } //m_currentPoint.x += this.basePositions.get(v) / 2 + this.distX; buildTree(v, null, firstV, this.m_currentPoint.x, maxNumberOfParents); } } this.size = new Dimension(lastDimensionX(), lastDimensionY()); }
From source file:krasa.cpu.CpuUsagePanel.java
public CpuUsagePanel(Project project) { refreshColors();/*from w w w.j a v a 2s . co m*/ this.myProject = project; this.projectName = project.getName(); setOpaque(false); setFocusable(false); setToolTipText("IDE CPU usage / System CPU usage"); setBorder(StatusBarWidget.WidgetBorder.INSTANCE); updateUI(); new UiNotifyConnector(this, new Activatable() { @Override public void showNotify() { CpuUsageManager.register(CpuUsagePanel.this); } @Override public void hideNotify() { CpuUsageManager.unregister(CpuUsagePanel.this); } }); MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { CpuUsageManager.update(); final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this); ActionManager.getInstance().getAction("TakeThreadDump").actionPerformed(new AnActionEvent(e, context, ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0)); } else if (SwingUtilities.isRightMouseButton(e)) { final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this); ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, getActionGroup(), context, JBPopupFactory.ActionSelectionAid.MNEMONICS, false); Dimension dimension = popup.getContent().getPreferredSize(); Point at = new Point(0, -dimension.height); popup.show(new RelativePoint(e.getComponent(), at)); } } }; addMouseListener(mouseAdapter); }
From source file:com.kbot2.scriptable.methods.wrappers.Interface.java
public Point getCenter() { Rectangle area = getArea();//from w w w.j a va 2 s . co m return new Point((int) area.getCenterX(), (int) area.getCenterY()); }
From source file:edu.harvard.mcz.imagecapture.ImageZoomPanel.java
/** * This method initializes this//from w w w . jav a 2 s. co m * */ private void initialize() { this.setSize(new Dimension(553, 323)); this.setLayout(new BorderLayout()); this.add(getJPanel(), BorderLayout.NORTH); this.add(getJScrollPane(), BorderLayout.CENTER); URL cursorFile = this.getClass() .getResource("/edu/harvard/mcz/imagecapture/resources/magnifying_glass.gif"); try { log.debug(cursorFile.toString()); Image zoomCursorImage = ImageIO.read(cursorFile); Point hotPoint = new Point(5, 5); zoomCursor = Toolkit.getDefaultToolkit().createCustomCursor(zoomCursorImage, hotPoint, "ZoomCursor"); } catch (IOException e) { log.error("Unable to load ZoomCursor"); zoomCursor = null; } jLabel.addMouseListener(this); }
From source file:by.bsu.zmiecer.PieChartDemo1.java
/** * Creates a chart.// w w w . ja v a 2 s .c o m * * @param dataset the dataset. * * @return A chart. */ private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(" ", // chart title dataset, // data false, // no legend true, // tooltips false // no URL generation ); // set a custom background for the chart chart.setBackgroundPaint( new GradientPaint(new Point(0, 0), new Color(0, 255, 11), new Point(400, 200), Color.BLUE)); // customise the title position and font TextTitle t = chart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 26)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.04); plot.setOutlineVisible(false); // use gradients and white borders for the section colours //plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE)); //plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED)); //plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN)); //plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW)); plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 20)); plot.setLabelLinkPaint(Color.WHITE); plot.setLabelLinkStroke(new BasicStroke(2.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.WHITE); plot.setLabelBackgroundPaint(null); /* // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); */ return chart; }
From source file:org.jfree.chart.demo.ScatterPlotDemo3.java
/** * Callback method for receiving notification of a mouse click on a chart. * * @param event information about the event. *//*from w w w . j av a 2s . co m*/ public void chartMouseClicked(ChartMouseEvent event) { int x = event.getTrigger().getX(); int y = event.getTrigger().getY(); // the following translation takes account of the fact that the chart image may // have been scaled up or down to fit the panel... Point2D p = chartPanel.translateScreenToJava2D(new Point(x, y)); // now convert the Java2D coordinate to axis coordinates... XYPlot plot = chartPanel.getChart().getXYPlot(); Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); double xx = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge()); double yy = plot.getRangeAxis().java2DToValue(p.getY(), dataArea, plot.getRangeAxisEdge()); // just for fun, lets convert the axis coordinates back to component coordinates... double xxx = plot.getDomainAxis().valueToJava2D(xx, dataArea, plot.getDomainAxisEdge()); double yyy = plot.getRangeAxis().valueToJava2D(yy, dataArea, plot.getRangeAxisEdge()); Point2D p2 = chartPanel.translateJava2DToScreen(new Point2D.Double(xxx, yyy)); System.out .println("Mouse coordinates are (" + x + ", " + y + "), in data space = (" + xx + ", " + yy + ")."); System.out.println("--> (" + p2.getX() + ", " + p2.getY() + ")"); }
From source file:io.gameover.utilities.pixeleditor.Frame.java
private void findPointAux(int x, int y, int color, int tolerance, List<Point> ret, Set<Point> scanned) { Point p = new Point(x, y); if (!scanned.contains(p)) { scanned.add(p);/*from www . j a v a 2 s.co m*/ if (x >= 0 && x < argb.length && y >= 0 && y < argb[0].length && isColorClosed(getColor(x, y), color, tolerance)) { ret.add(p); findPointAux(x - 1, y, color, tolerance, ret, scanned); findPointAux(x + 1, y, color, tolerance, ret, scanned); findPointAux(x, y - 1, color, tolerance, ret, scanned); findPointAux(x, y + 1, color, tolerance, ret, scanned); } } }