List of usage examples for java.awt Rectangle getWidth
public double getWidth()
From source file:org.squidy.designer.Designer.java
/** * @param view//from w ww. j av a 2 s . c o m */ private void initializeView(PFrame view) { view.setTitle(VIEW_TITLE); view.setDefaultCloseOperation(PFrame.DO_NOTHING_ON_CLOSE); view.addWindowListener(new WindowAdapter() { /* * (non-Javadoc) * * @see java.awt.event.WindowAdapter#windowClosing(java.awt * .event.WindowEvent) */ @Override public void windowClosing(WindowEvent e) { super.windowClosing(e); // Remove view. PFrame view = (PFrame) e.getWindow(); views.remove(view); view.dispose(); if (LOG.isDebugEnabled()) { LOG.debug("Closing view. View count " + views.size()); } // Store data if last view has been closed. if (views.size() == 0) { store(data); System.exit(0); } } }); view.getCanvas().addInputEventListener(new PBasicInputEventHandler() { @Override public void mouseClicked(PInputEvent event) { super.mouseClicked(event); final PCamera camera = event.getCamera(); if (!event.isHandled() && event.isLeftMouseButton() && event.getClickCount() == 2) { Rectangle bounds = getCanvas().getBounds(); bounds.setBounds((int) (bounds.getX() - 30), ((int) bounds.getY() - 30), ((int) bounds.getWidth() + 30), ((int) bounds.getHeight() + 30)); camera.animateViewToCenterBounds(bounds, true, 1000); // Set all children of current node as draggable. for (Object child : getCanvas().getLayer().getChildrenReference()) { if (child instanceof Draggable) { ((Draggable) child).setDraggable(true); } } } } }); view.getCanvas().getCamera().addInputEventListener(new PBasicInputEventHandler() { /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseClicked * (edu.umd.cs.piccolo.event.PInputEvent) */ @Override public void mouseClicked(PInputEvent event) { super.mouseClicked(event); if (event.isRightMouseButton() && event.getClickCount() > 1) { PLayer layer = getCanvas().getLayer(); PCamera camera = new PCamera(); camera.addLayer(layer); layer.getRoot().addChild(camera); PCanvas canvas = new PSwingCanvas(); canvas.setCamera(camera); PFrame view = new PFrame("", false, canvas); views.add(view); initializeView(view); // view.setVisible(true); if (LOG.isDebugEnabled()) { LOG.debug("Created view. View count " + views.size()); } } } }); }
From source file:org.squidy.nodes.MouseIO.java
@Override public void onStart() { // Search minimum/maximum of x/y. GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); screenBounds = new Rectangle[devices.length]; for (int i = 0; i < devices.length; i++) { GraphicsDevice device = devices[i]; GraphicsConfiguration gc = device.getDefaultConfiguration(); Rectangle bounds = gc.getBounds(); screenBounds[i] = bounds;// w w w.j a v a 2s.co m double x, y; x = bounds.getX(); minX = Math.min(minX, x); x += bounds.getWidth(); maxX = Math.max(maxX, x); y = bounds.getY(); minY = Math.min(minY, y); y += bounds.getHeight(); maxY = Math.max(maxY, y); } width = Math.abs(minX) + Math.abs(maxX); height = Math.abs(minY) + Math.abs(maxY); try { robot = new Robot(); robot.setAutoDelay(0); } catch (AWTException e) { if (LOG.isErrorEnabled()) LOG.error("Could not initialize Robot."); publishFailure(e); } if (openInputWindow) { inputWindow = InputWindow.getInstance(); inputWindow.registerMouseListener(this); } if (directInput && isWindows) { if (cdim == null) { createDirectInputMouse(); if (cdim != null) { if (cdim.Init(0) != 0) { cdim = null; publishFailure(new SquidyException("Could not initialize DirectInput mouse.")); } } } if (cdim != null) { if (cdim.StartCapture() != 0) publishFailure(new SquidyException("Could not start DirectInput mouse.")); else new Thread(new Runnable() { public void run() { while (processing) { cdim.WaitForBufferedData(); if (processing) processDirectInputMouseBufferedData(); } } }, getId() + "_DIM").start(); } } }
From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java
private int drawText(Graphics2D graphics, String text, int hOffset) { Rectangle r = getTextBoundsRectangle(); Rectangle2D textBounds = graphics.getFontMetrics().getStringBounds(text, graphics); if (textBounds.getWidth() > r.getWidth() - 4) { int y = coords[1] + hOffset; AttributedString attributedString = new AttributedString(text); attributedString.addAttribute(TextAttribute.FONT, graphics.getFont()); AttributedCharacterIterator characterIterator = attributedString.getIterator(); LineBreakMeasurer measurer = new LineBreakMeasurer(characterIterator, graphics.getFontRenderContext()); while (measurer.getPosition() < characterIterator.getEndIndex()) { TextLayout textLayout = measurer.nextLayout((float) r.getWidth() - 4); y += textLayout.getAscent(); float x = (float) (r.getCenterX() + 2 - textLayout.getBounds().getCenterX()); textLayout.draw(graphics, x, y); y += textLayout.getDescent() + textLayout.getLeading(); }// w ww . j a v a2 s.com return y - coords[1]; } else { graphics.drawString(text, (float) (r.getCenterX() + 2 - textBounds.getCenterX()), (float) (coords[1] + textBounds.getHeight() + hOffset)); return (int) (textBounds.getHeight() + hOffset + 3); } }
From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java
protected AngleInfo getTransitionAngle(double x, double y) { Rectangle rect = getRectangle(); double cx = rect.getCenterX(); double cy = rect.getCenterY(); if (x == cx) { return y - cy > 0 ? new AngleInfo(Double.MAX_VALUE, AngleInfo.QUARTER_IV) : new AngleInfo(Double.MAX_VALUE, AngleInfo.QUARTER_II); } else {/*from w w w . jav a 2 s. com*/ double critAngle = rect.getHeight() / rect.getWidth(); AngleInfo angleInfo = new AngleInfo(); angleInfo.setAngle((y - cy) / (x - cx)); if (Math.abs(angleInfo.getAngle()) > critAngle) { if (y - cy > 0) { // IV angleInfo.setQuarter(AngleInfo.QUARTER_IV); } else { // II angleInfo.setQuarter(AngleInfo.QUARTER_II); } } else { if (x - cx > 0) { // I angleInfo.setQuarter(AngleInfo.QUARTER_I); } else { // III angleInfo.setQuarter(AngleInfo.QUARTER_III); } } return angleInfo; } }
From source file:smlm.util.SRutil.java
public static double area(Rectangle rectangle) { return rectangle.getHeight() * rectangle.getWidth(); }