List of usage examples for java.awt Rectangle getHeight
public double getHeight()
From source file:org.pmedv.blackboard.commands.ConvertToSymbolCommand.java
@Override public void execute(ActionEvent e) { // which editor do we have? final BoardEditor editor = EditorUtils.getCurrentActiveEditor(); final List<Item> items = editor.getSelectedItems(); final List<Item> preserveItems = new ArrayList<Item>(); for (Item item : items) { if (item instanceof Symbol || item instanceof Resistor || item instanceof Diode) { ErrorUtils//from w w w . j a va 2s . c om .showErrorDialog(new IllegalStateException(resources.getResourceByKey("error.onlyshapes"))); return; } } // first we need to check all items and determine min_x, min_y, max_x, max_y as well as height and width int min_x = Integer.MAX_VALUE; int min_y = Integer.MAX_VALUE; int max_x = Integer.MIN_VALUE; int max_y = Integer.MIN_VALUE; for (Item item : items) { if (item instanceof Line) { final Line line = (Line) item; final Rectangle boundingBox = line.getBoundingBox(); int x1 = (int) boundingBox.getLocation().getX(); int y1 = (int) boundingBox.getLocation().getY(); int x2 = x1 + (int) boundingBox.getWidth(); int y2 = y1 + (int) boundingBox.getHeight(); if (x1 < min_x) min_x = x1; if (y1 < min_y) min_y = y1; if (x2 > max_x) max_x = x2; if (y2 > max_y) max_y = y2; } else { if (item.getXLoc() + item.getWidth() > max_x) max_x = item.getXLoc() + item.getWidth(); if (item.getYLoc() + item.getHeight() > max_y) max_y = item.getYLoc() + item.getHeight(); if (item.getXLoc() < min_x) min_x = item.getXLoc(); if (item.getYLoc() < min_y) min_y = item.getYLoc(); } } int width = max_x - min_x; int height = max_y - min_y; final Symbol symbol = new Symbol(); symbol.setWidth(width); symbol.setHeight(height); // sort items by z-index Collections.sort(items); symbol.setLayer(items.get(0).getLayer()); for (final Item item : items) { // preserve old position and set new position and render, since we need to convert the coordinates // of the item to the newly calculated drawing area if (item instanceof Line) { final Line line = (Line) item; line.getOldstart().setLocation(line.getStart().getX(), line.getStart().getY()); line.getOldEnd().setLocation(line.getEnd().getX(), line.getEnd().getY()); line.getStart().setLocation(line.getStart().getX() - min_x, line.getStart().getY() - min_y); line.getEnd().setLocation(line.getEnd().getX() - min_x, line.getEnd().getY() - min_y); } else { item.setOldXLoc(item.getXLoc()); item.setOldYLoc(item.getYLoc()); item.setXLoc(item.getXLoc() - min_x); item.setYLoc(item.getYLoc() - min_y); } item.setOpacity(item.getOpacity()); // restore position if (item instanceof Line) { final Line line = (Line) item; line.getStart().setLocation(line.getOldstart().getX(), line.getOldstart().getY()); line.getEnd().setLocation(line.getOldEnd().getX(), line.getOldEnd().getY()); } else { item.setXLoc(item.getOldXLoc()); item.setYLoc(item.getOldYLoc()); } symbol.getItems().add(item); } // now get a new index int max = 0; for (final Layer layer : editor.getModel().getLayers()) { for (Item item : layer.getItems()) { if (item.getIndex() > max) max = item.getIndex(); } } max++; symbol.setIndex(max); // remove original items and replace with created symbol if (editor.getSelectedItems().size() > 1) { editor.clearSelectionBorder(); preserveItems.addAll(editor.getSelectedItems()); for (Item item : editor.getSelectedItems()) { for (Layer layer : editor.getModel().getLayers()) layer.getItems().remove(item); } editor.getSelectedItems().clear(); symbol.setXLoc(min_x); symbol.setYLoc(min_y); editor.getModel().getCurrentLayer().getItems().add(symbol); editor.setSelectedItem(symbol); UndoManager undoManager = editor.getUndoManager(); if (!undoManager.addEdit(new ConvertToSymbolEdit(preserveItems, symbol))) { log.info("Could not add edit " + this.getClass()); } editor.setFileState(FileState.DIRTY); AppContext.getContext().getBean(RedoCommand.class).setEnabled(undoManager.canRedo()); AppContext.getContext().getBean(UndoCommand.class).setEnabled(undoManager.canUndo()); editor.refresh(); } }
From source file:org.squidy.designer.Designer.java
/** * @param view//from w w w .j a v 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. com*/ 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
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 {/*w w w.j a v a 2s . 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(); }