List of usage examples for java.awt Rectangle getY
public double getY()
From source file:Main.java
/** * Source: http://stackoverflow.com/questions/102171/method-that-returns-the-line-number-for-a-given-jtextpane-position * Returns an int containing the wrapped line index at the given position * @param component JTextPane//from w w w.j av a 2s. com * @param int pos * @return int */ public static int getLineNumber(JTextArea component, int pos) { int posLine; int y = 0; try { Rectangle caretCoords = component.modelToView(pos); y = (int) caretCoords.getY(); } catch (Exception ex) { } int lineHeight = component.getFontMetrics(component.getFont()).getHeight(); posLine = (y / lineHeight); return posLine; }
From source file:Main.java
/** * Returns the center position of the specified component. *///from w ww . j a v a2 s .c o m public static Point2D.Double getCenter(Component c) { if (c != null) { final Rectangle r = c.getBounds(); return new Point2D.Double(r.getX() + (r.getWidth() / 2d), r.getY() + (r.getHeight() / 2d)); } return new Point2D.Double(0d, 0d); }
From source file:com.SCI.centraltoko.utility.UtilityTools.java
public static void scroolTorect(JTable tabel, int nextRow) { Rectangle currenVisible = tabel.getVisibleRect(); Rectangle scroolTorect = tabel.getCellRect(nextRow, 0, true); if (scroolTorect.getY() > currenVisible.getY() + currenVisible.getHeight()) { scroolTorect.setLocation(0,/*from w w w . java2 s. co m*/ (int) (scroolTorect.getY() + currenVisible.getHeight() - scroolTorect.getHeight())); } tabel.scrollRectToVisible(scroolTorect); }
From source file:Main.java
public static Point positionToClickPoint(Container component, int caretPosition, Container invokedIn) { if (component == null) { return null; }/*from w w w . ja v a 2s . c om*/ //System.err.println("Checking: " + component.getClass().getName()); if (component.getClass().getName().indexOf("EditorPane") >= 0) { try { java.lang.reflect.Method pointGetter = component.getClass().getMethod("modelToView", new Class[] { Integer.TYPE }); Rectangle rec = (Rectangle) pointGetter.invoke(component, new Object[] { new Integer(caretPosition) }); //System.err.println("Before: " + (int)rec.getY()); // FIXME: somehow it fails here to convert point from scrollable component Point point = SwingUtilities.convertPoint(component, (int) rec.getX(), (int) rec.getY() + 10, invokedIn); // FIXME: ugly hack :( if (point.getY() > 1024) { point = new Point((int) point.getX(), 250); } //System.err.println("After: " + (int)point.getY()); return point; } catch (Exception e) { System.err.println("Method invocation exception caught"); e.printStackTrace(); //FIXME: BUG return null; //throw new RuntimeException("Method invocation exception caught"); } } for (int i = 0; i < component.getComponentCount(); i++) { java.awt.Component childComponent = component.getComponent(i); if (childComponent instanceof javax.swing.JComponent) { Point point = positionToClickPoint((javax.swing.JComponent) childComponent, caretPosition, invokedIn); if (point != null) { return point; } } } return null; }
From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java
/** * Construct the smallest rectangle,/* w w w .j a v a 2 s .c o m*/ * which include the positions of all statistics in view * @param viewId id of view * @return smallest Rectangle when an StatisticGrafic exist, * null otherwise. */ public static Rectangle getBoundsExternGlobal(Model model, String viewId) { boolean found = false; double minX = (double) Integer.MAX_VALUE / 2; double minY = (double) Integer.MAX_VALUE / 2; double maxX = (double) Integer.MIN_VALUE / 2; double maxY = (double) Integer.MIN_VALUE / 2; String[] id = model.getStatistics().getAllIds(); //System.out.println("Anz. Entities: "+id.length); for (int i = 0; i < id.length; i++) { Statistic statistic = model.getStatistics().get(id[i]); StatisticGrafic statistikGrafic = (StatisticGrafic) statistic.getGrafic(); if (statistikGrafic != null && statistikGrafic.getViewId().equals(viewId)) { found = true; Rectangle r = statistikGrafic.getBoundsExtern(); minX = Math.floor(Math.min(minX, r.getX())); minY = Math.floor(Math.min(minY, r.getY())); maxX = Math.ceil(Math.max(maxX, r.getX() + r.width)); maxY = Math.ceil(Math.max(maxY, r.getY() + r.height)); //System.out.println(statistic.getId()+" "+statistikGrafic.pointExtern.getX()+" "+statistikGrafic.pointExtern.getY()); } } Rectangle r = null; if (found) r = new Rectangle((int) Math.round(minX), (int) Math.round(minY), (int) Math.round(maxX - minX), (int) Math.round(maxY - minY)); //System.out.println("StatisticGrafic: BoundsExtern: "+r); return r; }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle r = new Rectangle(100, 100, 200, 200); g2.fill(r);//www . ja v a2s.c om System.out.println(r.getY()); }
From source file:CopyAreaPerformance.java
protected void paintComponent(Graphics g) { long startTime = System.nanoTime(); // prevVX is set to -10000 when first enabled if (useCopyArea && prevVX > -9999) { // Most of this code determines the proper areas to copy and clip int scrollX = viewX - prevVX; int scrollY = viewY - prevVY; int copyFromY, copyFromX; int clipFromY, clipFromX; if (scrollX == 0) { // vertical scroll if (scrollY < 0) { copyFromY = 0;/* w w w . j a va2 s. com*/ clipFromY = 0; } else { copyFromY = scrollY; clipFromY = getHeight() - scrollY; } // copy the old content, set the clip to the new area g.copyArea(0, copyFromY, getWidth(), getHeight() - Math.abs(scrollY), 0, -scrollY); g.setClip(0, clipFromY, getWidth(), Math.abs(scrollY)); } else { // horizontal scroll if (scrollX < 0) { copyFromX = 0; clipFromX = 0; } else { copyFromX = scrollX; clipFromX = getWidth() - scrollX; } // copy the old content, set the clip to the new area g.copyArea(copyFromX, 0, getWidth() - Math.abs(scrollX), getHeight(), -scrollX, 0); g.setClip(clipFromX, 0, Math.abs(scrollX), getHeight()); } } // Track previous view position for next scrolling operation prevVX = viewX; prevVY = viewY; // Get the clip in case we need it later Rectangle clipRect = g.getClip().getBounds(); int clipL = (int) (clipRect.getX()); int clipT = (int) (clipRect.getY()); int clipR = (int) (clipRect.getMaxX()); int clipB = (int) (clipRect.getMaxY()); g.setColor(Color.WHITE); g.fillRect(clipL, clipT, (int) clipRect.getWidth(), (int) clipRect.getHeight()); for (int column = 0; column < 256; ++column) { int x = column * (SMILEY_SIZE + PADDING) - viewX; if (useClip) { if (x > clipR || (x + (SMILEY_SIZE + PADDING)) < clipL) { // trivial reject; outside to the left or right continue; } } for (int row = 0; row < 256; ++row) { int y = row * (SMILEY_SIZE + PADDING) - viewY; if (useClip) { if (y > clipB || (y + (SMILEY_SIZE + PADDING)) < clipT) { // trivial reject; outside to the top or bottom continue; } } Color faceColor = new Color(column, row, 0); drawSmiley(g, faceColor, x, y); } } long stopTime = System.nanoTime(); System.out.println("Painted in " + ((stopTime - startTime) / 1000000) + " ms"); }
From source file:com.smash.revolance.ui.comparator.page.PageComparator.java
private boolean layoutEquals(PageBean reference, PageBean page) { List<Rectangle> layout = getLayout(page); for (Rectangle refElementRect : getLayout(reference)) { int matchCount = 0; for (Rectangle pageElementRect : layout) { if (refElementRect.getX() == pageElementRect.getX() && refElementRect.getY() == pageElementRect.getY() && refElementRect.getWidth() == pageElementRect.getWidth() && refElementRect.getHeight() == pageElementRect.getHeight()) { matchCount++;/* w w w. ja va 2s . co m*/ } } if (layout.size() == matchCount) { return true; } } return false; }
From source file:com.tulskiy.musique.system.configuration.Configuration.java
public void setRectangle(String key, Rectangle value) { if (value == null) remove(key);//from w w w . j a v a2 s.c o m else { String s = new Formatter().format("%d %d %d %d", (int) value.getX(), (int) value.getY(), (int) value.getWidth(), (int) value.getHeight()).toString(); put(key, s); } }
From source file:ja.lingo.application.gui.main.describer.DescriberGui.java
public void mouseClickedOnEditorPane(MouseEvent e) { if (!articlePanel.hasArticle()) { return;/*from w ww. j ava 2 s . c o m*/ } if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) { if (getSelectedTextTrimmed().length() > 0) { Rectangle rectangle; try { rectangle = articlePanel.getEditorPane() .modelToView(articlePanel.getEditorPane().getSelectionStart()); } catch (BadLocationException e1) { throw new RuntimeException(e1); } showMenuOnSelect(e.getX(), (int) (rectangle.getY() + rectangle.getHeight())); } return; } if (SwingUtilities.isRightMouseButton(e)) { if (getSelectedTextTrimmed().length() > 0) { showMenuOnSelect(e.getX(), e.getY()); } else { menu.show(articlePanel, e.getX(), e.getY()); } } }