Search in sources :

Example 36 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class GraphicPanel method mousePressed.

public void mousePressed(MouseEvent evt) {
    requestFocusInWindow();
    _lastClickPoint = evt.getPoint();
    _lastOrigin = new Point(_origin);
    _mouseButtonPressed = evt.getButton();
    switch(evt.getButton()) {
        case SELECT_BUTTON:
            {
                if (!_bAllowsEditing)
                    break;
                if (_resizingGraphic != null && _resizeDirection != Compass.NONE)
                    break;
                _resizingGraphic = null;
                _movingGraphic = topGraphicAtPosition(evt.getPoint());
                if ((evt.getModifiers() & ActionEvent.CTRL_MASK) == 0) {
                    if (_movingGraphic == null || !_movingGraphic.isSelected())
                        unselectAllGraphics();
                }
                if (System.getProperty("os.name").startsWith("Mac OS X") && (evt.getModifiers() & ActionEvent.META_MASK) != 0)
                    setCursor(Cursor.HAND_CURSOR);
                if (_movingGraphic != null) {
                    if (!_movingGraphic.isSelected())
                        selectGraphic(_movingGraphic);
                    else if ((evt.getModifiers() & ActionEvent.CTRL_MASK) != 0)
                        unselectGraphic(_movingGraphic);
                } else {
                    Point p = evt.getPoint();
                    _multiSelectRect = new Rectangle(p.x, p.y, 0, 0);
                }
            }
            break;
        case DRAG_BUTTON:
        case DRAG_BUTTON_2:
            {
                setCursor(Cursor.HAND_CURSOR);
            }
            break;
    }
    repaint();
}
Also used : Rectangle(java.awt.Rectangle) Point(java.awt.Point)

Example 37 with Rectangle

use of java.awt.Rectangle in project hudson-2.x by hudson.

the class DependencyGraph method doGraph.

/**
     * Experimental visualization of project dependencies.
     */
public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
    // Require admin permission for now (avoid exposing project names with restricted permissions)
    Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
    try {
        // creates a dummy graphics just so that we can measure font metrics
        BufferedImage emptyImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = emptyImage.createGraphics();
        graphics.setFont(FONT);
        final FontMetrics fontMetrics = graphics.getFontMetrics();
        // TODO: timestamp check
        Layout<AbstractProject> layout = new Layout<AbstractProject>(new Navigator<AbstractProject>() {

            public Collection<AbstractProject> vertices() {
                // only include projects that have some dependency
                List<AbstractProject> r = new ArrayList<AbstractProject>();
                for (AbstractProject p : Hudson.getInstance().getAllItems(AbstractProject.class)) {
                    if (!getDownstream(p).isEmpty() || !getUpstream(p).isEmpty())
                        r.add(p);
                }
                return r;
            }

            public Collection<AbstractProject> edge(AbstractProject p) {
                return getDownstream(p);
            }

            public Dimension getSize(AbstractProject p) {
                int w = fontMetrics.stringWidth(p.getDisplayName()) + MARGIN * 2;
                return new Dimension(w, fontMetrics.getHeight() + MARGIN * 2);
            }
        }, Direction.LEFTRIGHT);
        Rectangle area = layout.calcDrawingArea();
        // give it a bit of margin
        area.grow(4, 4);
        BufferedImage image = new BufferedImage(area.width, area.height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        g2.setTransform(AffineTransform.getTranslateInstance(-area.x, -area.y));
        g2.setPaint(Color.WHITE);
        g2.fill(area);
        g2.setFont(FONT);
        g2.setPaint(Color.BLACK);
        for (AbstractProject p : layout.vertices()) {
            final Point sp = center(layout.vertex(p));
            for (AbstractProject q : layout.edges(p)) {
                Point cur = sp;
                for (Point pt : layout.edge(p, q)) {
                    g2.drawLine(cur.x, cur.y, pt.x, pt.y);
                    cur = pt;
                }
                final Point ep = center(layout.vertex(q));
                g2.drawLine(cur.x, cur.y, ep.x, ep.y);
            }
        }
        int diff = fontMetrics.getAscent() + fontMetrics.getLeading() / 2;
        for (AbstractProject p : layout.vertices()) {
            Rectangle r = layout.vertex(p);
            g2.setPaint(Color.WHITE);
            g2.fillRect(r.x, r.y, r.width, r.height);
            g2.setPaint(Color.BLACK);
            g2.drawRect(r.x, r.y, r.width, r.height);
            g2.drawString(p.getDisplayName(), r.x + MARGIN, r.y + MARGIN + diff);
        }
        rsp.setContentType("image/png");
        ServletOutputStream os = rsp.getOutputStream();
        ImageIO.write(image, "PNG", os);
        os.close();
    } catch (HeadlessException e) {
        // not available. send out error message
        rsp.sendRedirect2(req.getContextPath() + "/images/headless.png");
    }
}
Also used : HeadlessException(java.awt.HeadlessException) ServletOutputStream(javax.servlet.ServletOutputStream) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D) Layout(org.kohsuke.graph_layouter.Layout) FontMetrics(java.awt.FontMetrics) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 38 with Rectangle

use of java.awt.Rectangle in project openblocks by mikaelhg.

the class StackExplorer method setDrawersCard.

/**
     * Reassigns this explorer to the new list of canvases and
     * reforms the location of each canvas's origin and destination
     * based on the current size of this explorer.
     * @param items
     */
public void setDrawersCard(List<? extends Canvas> items) {
    drawers.clear();
    this.removeAll();
    //total height of pane
    int h = this.getHeight();
    //number of drawers
    int n = items.size();
    for (int i = 0; i < n; i++) {
        Rectangle origin = new Rectangle(0, i * buttonHeight, this.getWidth(), this.getHeight() - n * buttonHeight);
        Rectangle destination = new Rectangle(0, i <= 0 ? 0 : h - buttonHeight * (n - i + 1), this.getWidth(), this.getHeight() - n * buttonHeight);
        Canvas item = items.get(i);
        StackCard drawer = new StackCard(item, this);
        this.add(drawer.getJComponent(), JLayeredPane.DEFAULT_LAYER);
        this.setLayer(drawer.getJComponent(), JLayeredPane.DEFAULT_LAYER, 0);
        drawer.setBounds(origin);
        drawer.reformDrawer(origin, destination);
        if (!drawers.add(drawer)) {
            throw new RuntimeException("Counldn't add drawer");
        }
    }
    this.revalidate();
    this.repaint();
}
Also used : Rectangle(java.awt.Rectangle)

Example 39 with Rectangle

use of java.awt.Rectangle in project openblocks by mikaelhg.

the class StackExplorer method reformView.

/**
     * reforms the location of each canvas's origin and destination
     * based on the current size of this explorer.
     */
public void reformView() {
    //total height of pane
    int h = this.getHeight();
    //number of drawers
    int n = drawers.size() - 1;
    for (int i = 0; i <= n; i++) {
        StackCard drawer = drawers.get(i);
        Rectangle origin = new Rectangle(0, i * buttonHeight, this.getWidth(), this.getHeight() - n * buttonHeight);
        Rectangle destination = new Rectangle(0, i <= 0 ? 0 : h - buttonHeight * (n - i + 1), this.getWidth(), this.getHeight() - n * buttonHeight);
        if (drawer.isDirectedToDestination()) {
            drawer.setBounds(destination);
        } else {
            drawer.setBounds(origin);
        }
        drawer.reformDrawer(origin, destination);
    }
}
Also used : Rectangle(java.awt.Rectangle)

Example 40 with Rectangle

use of java.awt.Rectangle in project openblocks by mikaelhg.

the class MiniMap method paint.

/**
     * @modifies this.bounds && this.blockCanvas && this.blocks && this.comments
     * @effects 1] Point this.blockCanvas to whatever current block
     * 			   canvas is in Workspace
     * 			2] Reset this.bounds to maintain aspect ratio and be
     * 			   16 pixels away from upper-right edge corner &&
     * 			3] Rerender this.blocks and this.comment toreflect
     * 			   real-time relative positions and dimension
     */
public void paint(Graphics g) {
    //should paint super first then reset canvas.
    //using new canvas, find new height and ratio.
    super.paint(g);
    // draw shadow border
    for (int i = 0; i < BORDER_WIDTH; i++) {
        g.setColor(new Color(200, 200, 150, 50 * (i + 1)));
        g.drawRect(i, i, this.getWidth() - 1 - 2 * i, this.getHeight() - 1 - 2 * i);
    }
    //Aspect-Ratio Logic
    this.blockCanvas = workspace.getBlockCanvas();
    //MUST CAST MAPHEIGHT TO DOUBLE!!
    this.transformX = (double) (MAPWIDTH) / this.getCanvas().getWidth();
    this.transformY = (double) (MAPHEIGHT) / this.getCanvas().getHeight();
    g.translate(5, 5);
    for (Page page : this.blockCanvas.getPages()) {
        Color pageColor = page.getPageColor();
        g.setColor(new Color(pageColor.getRed(), pageColor.getGreen(), pageColor.getBlue(), 200));
        Rectangle pageRect = rescaleRect(page.getJComponent().getBounds());
        g.fillRect(pageRect.x, pageRect.y, pageRect.width, pageRect.height);
        g.setColor(Color.white);
        g.clipRect(pageRect.x, pageRect.y, pageRect.width, pageRect.height);
        g.drawString(page.getPageName(), pageRect.x + 1, pageRect.height - 3);
        if (page.getIcon() != null && expand) {
            g.drawImage(page.getIcon(), pageRect.x + 1, pageRect.height - 28, 15, 15, null);
        }
        g.setClip(null);
        for (Component component : page.getJComponent().getComponents()) {
            //re-render this.blocks and this.comments
            if (component instanceof RenderableBlock && component != null && component.isVisible()) {
                if (((RenderableBlock) component).isSearchResult()) {
                    g.setColor(Color.yellow);
                } else {
                    g.setColor(((RenderableBlock) component).getBLockColor());
                }
                drawBoundingBox(g, component);
            } else if (component instanceof Comment && component.isVisible()) {
                g.setColor(Color.yellow);
                drawBoundingBox(g, component);
            }
        }
    }
    for (Component component : this.getCanvas().getComponents()) {
        if (component instanceof PageDivider) {
            g.setColor(Color.GRAY);
            Rectangle dividerRect = rescaleRect(component.getBounds());
            g.fillRect(dividerRect.x, dividerRect.y, dividerRect.width + 1, dividerRect.height);
        }
    }
    for (Component component : workspace.getComponentsInLayer(Workspace.DRAGGED_BLOCK_LAYER)) {
        if (component instanceof RenderableBlock && component != null && component.isVisible()) {
            g.setColor(((RenderableBlock) component).getBLockColor());
            drawBoundingBox(g, component);
        } else if (component instanceof Comment && component.isVisible()) {
            g.setColor(Color.yellow);
            drawBoundingBox(g, component);
        }
    }
    g.setColor(Color.red);
    g.drawRect(rescaleX(blockCanvas.getHorizontalModel().getValue()), rescaleY(blockCanvas.getVerticalModel().getValue()), rescaleX(blockCanvas.getWidth()), rescaleY(blockCanvas.getHeight()));
}
Also used : Comment(edu.mit.blocks.renderable.Comment) RenderableBlock(edu.mit.blocks.renderable.RenderableBlock) Color(java.awt.Color) Rectangle(java.awt.Rectangle) JComponent(javax.swing.JComponent) Component(java.awt.Component) Point(java.awt.Point)

Aggregations

Rectangle (java.awt.Rectangle)809 Point (java.awt.Point)201 Dimension (java.awt.Dimension)81 BufferedImage (java.awt.image.BufferedImage)68 Graphics2D (java.awt.Graphics2D)65 Color (java.awt.Color)48 Insets (java.awt.Insets)47 ArrayList (java.util.ArrayList)37 Font (java.awt.Font)29 Test (org.junit.Test)28 IOException (java.io.IOException)27 GraphicsConfiguration (java.awt.GraphicsConfiguration)23 Paint (java.awt.Paint)23 GradientPaint (java.awt.GradientPaint)22 FontMetrics (java.awt.FontMetrics)21 Graphics (java.awt.Graphics)21 Rectangle2D (java.awt.geom.Rectangle2D)21 Robot (java.awt.Robot)19 File (java.io.File)19 PeakResult (gdsc.smlm.results.PeakResult)18