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();
}
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");
}
}
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();
}
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);
}
}
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()));
}
Aggregations