List of usage examples for java.awt Rectangle setBounds
public void setBounds(int x, int y, int width, int height)
From source file:com.lfv.lanzius.server.WorkspaceView.java
@Override protected void paintComponent(Graphics g) { int w = getWidth(); int h = getHeight(); Document doc = server.getDocument(); Color storedCol = g.getColor(); Font storedFont = g.getFont(); // Fill workspace area g.setColor(getBackground());//from ww w.j av a 2 s . com g.fillRect(0, 0, w, h); // Should the cached version be updated? int updateDocumentVersion = server.getDocumentVersion(); boolean update = (documentVersion != updateDocumentVersion); // Check if we have cached the latest document version, otherwise cache the terminals if (update) { log.debug("Updating view to version " + updateDocumentVersion); terminalMap.clear(); groupList.clear(); if (doc != null) { synchronized (doc) { // Clear the visible attribute on all groups // except the started or paused ones Element egd = doc.getRootElement().getChild("GroupDefs"); Iterator iter = egd.getChildren().iterator(); while (iter.hasNext()) { Element eg = (Element) iter.next(); boolean isVisible = !DomTools.getAttributeString(eg, "state", "stopped", false) .equals("stopped"); eg.setAttribute("visible", String.valueOf(isVisible)); } // Gather information about terminals and cache it Element etd = doc.getRootElement().getChild("TerminalDefs"); iter = etd.getChildren().iterator(); while (iter.hasNext()) { Element et = (Element) iter.next(); int tid = DomTools.getAttributeInt(et, "id", 0, false); if (tid > 0) { // Create terminal and add it to list Terminal t = new Terminal(tid, DomTools.getAttributeInt(et, "x", 0, false), DomTools.getAttributeInt(et, "y", 0, false), DomTools.getChildText(et, "Name", "T/" + tid, false), DomTools.getAttributeBoolean(et, "online", false, false), DomTools.getAttributeBoolean(et, "selected", false, false)); terminalMap.put(tid, t); // Is the terminal monitored? t.isMonitored = DomTools.getAttributeBoolean(et, "monitored", false, false); // Examine the Player element under PlayerSetup t.groupColor = null; Element ep = DomTools.getElementFromSection(doc, "PlayerSetup", "terminalid", String.valueOf(tid)); // Has linked player for this terminal if (ep != null) { StringBuffer sb = new StringBuffer(); // Append player name sb.append(DomTools.getChildText(ep, "Name", "P/?", true)); sb.append(" ("); // Append role list boolean hasRoles = false; Element ers = ep.getChild("RoleSetup"); if (ers != null) { Iterator iterr = ers.getChildren().iterator(); while (iterr.hasNext()) { Element er = (Element) iterr.next(); String id = er.getAttributeValue("id"); er = DomTools.getElementFromSection(doc, "RoleDefs", "id", id); if (er != null) { sb.append(DomTools.getChildText(er, "Name", "R/" + id, false)); sb.append(", "); hasRoles = true; } } if (hasRoles) { // Trim last comma int len = sb.length(); sb.setLength(Math.max(len - 2, 0)); } sb.append(")"); } t.roles = sb.toString(); // Is the player relocated? t.isRelocated = DomTools.getAttributeBoolean(ep, "relocated", false, false); // Get group name and color Element eg = DomTools.getElementFromSection(doc, "GroupDefs", "id", DomTools.getAttributeString(ep, "groupid", "0", true)); t.groupColor = Color.lightGray; if (eg != null) { String sc = DomTools.getChildText(eg, "Color", null, false); if (sc != null) { try { t.groupColor = Color.decode(sc); } catch (NumberFormatException ex) { log.warn("Invalid color attribute on Group node, defaulting to grey"); } } //t.name += " "+DomTools.getChildText(eg, "Name", "G/"+eg.getAttributeValue("id"), false); t.groupName = DomTools.getChildText(eg, "Name", "G/" + eg.getAttributeValue("id"), false); // This group should now be visible eg.setAttribute("visible", "true"); } else log.warn("Invalid groupid attribute on Player node, defaulting to grey"); } } else log.error("Invalid id attribute on Terminal node, skipping"); } // Gather information about groups and cache it iter = egd.getChildren().iterator(); while (iter.hasNext()) { Element eg = (Element) iter.next(); if (DomTools.getAttributeBoolean(eg, "visible", false, false)) { int gid = DomTools.getAttributeInt(eg, "id", 0, true); if (gid > 0) { Group grp = new Group(gid, DomTools.getChildText(eg, "Name", "G/" + gid, false), DomTools.getAttributeBoolean(eg, "selected", false, false)); groupList.add(grp); // group color String sc = DomTools.getChildText(eg, "Color", null, false); if (sc != null) { try { grp.color = Color.decode(sc); } catch (NumberFormatException ex) { log.warn("Invalid color attribute on Group node, defaulting to grey"); } } // state color grp.stateColor = Color.red; String state = DomTools.getAttributeString(eg, "state", "stopped", false); if (state.equals("started")) grp.stateColor = Color.green; else if (state.equals("paused")) grp.stateColor = Color.orange; } } } } } } if (doc == null) { g.setColor(Color.black); String text = "No configuration loaded. Select 'Load configuration...' from the file menu."; g.drawString(text, (w - SwingUtilities.computeStringWidth(g.getFontMetrics(), text)) / 2, h * 5 / 12); } else { g.setFont(new Font("Dialog", Font.BOLD, 13)); Iterator<Terminal> itert = terminalMap.values().iterator(); while (itert.hasNext()) { Terminal t = itert.next(); // Draw box int b = t.isSelected ? SERVERVIEW_SELECTION_BORDER : 1; g.setColor(Color.black); g.fillRect(t.x + SERVERVIEW_SELECTION_BORDER - b, t.y + SERVERVIEW_SELECTION_BORDER - b, SERVERVIEW_TERMINAL_WIDTH + 2 * b, SERVERVIEW_TERMINAL_HEIGHT + 2 * b); g.setColor(t.groupColor == null ? Color.white : t.groupColor); g.fillRect(t.x + SERVERVIEW_SELECTION_BORDER, t.y + SERVERVIEW_SELECTION_BORDER, SERVERVIEW_TERMINAL_WIDTH, SERVERVIEW_TERMINAL_HEIGHT); // Inner areas Rectangle r = new Rectangle(t.x + SERVERVIEW_SELECTION_BORDER + SERVERVIEW_TERMINAL_BORDER, t.y + SERVERVIEW_SELECTION_BORDER + SERVERVIEW_TERMINAL_BORDER, SERVERVIEW_TERMINAL_WIDTH - 2 * SERVERVIEW_TERMINAL_BORDER, g.getFontMetrics().getHeight() + 4); g.setColor(Color.white); g.fillRect(r.x, r.y, r.width, r.height); g.fillRect(r.x, r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 2, r.width, SERVERVIEW_TERMINAL_HEIGHT - 3 * SERVERVIEW_TERMINAL_BORDER - r.height - 2); g.setColor(Color.black); g.drawRect(r.x, r.y, r.width, r.height); g.drawRect(r.x, r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 2, r.width, SERVERVIEW_TERMINAL_HEIGHT - 3 * SERVERVIEW_TERMINAL_BORDER - r.height - 2); // Name of terminal and group if (server.isaClient(t.tid)) { g.drawImage(indicatorIsa.getImage(), r.x + r.width - 20, r.y + SERVERVIEW_TERMINAL_HEIGHT - 26, null); } g.drawString(t.name + " " + t.groupName, r.x + 4, r.y + r.height - 4); double px = r.x + 4; double py = r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 5; // Draw monitored indicator if (t.isMonitored) { g.drawImage(indicatorMonitored.getImage(), r.x + r.width - 9, r.y + 3, null); } // Draw relocated indicator if (t.isRelocated) { g.drawImage(indicatorRelocated.getImage(), r.x + r.width - 9, r.y + 13, null); } // Draw online indicator r.setBounds(r.x, r.y + r.height, r.width, 3); g.setColor(t.isOnline ? Color.green : Color.red); g.fillRect(r.x, r.y, r.width, r.height); g.setColor(Color.black); g.drawRect(r.x, r.y, r.width, r.height); // Roles if (t.roles.length() > 0) { LineBreakMeasurer lbm = new LineBreakMeasurer(new AttributedString(t.roles).getIterator(), new FontRenderContext(null, false, true)); TextLayout layout; while ((layout = lbm .nextLayout(SERVERVIEW_TERMINAL_WIDTH - 2 * SERVERVIEW_TERMINAL_BORDER)) != null) { if (py < t.y + SERVERVIEW_TERMINAL_HEIGHT) { py += layout.getAscent(); layout.draw((Graphics2D) g, (int) px, (int) py); py += layout.getDescent() + layout.getLeading(); } } } } // Draw group indicators int nbrGroupsInRow = w / (2 * Constants.SERVERVIEW_SELECTION_BORDER + 2 + Constants.SERVERVIEW_GROUP_WIDTH); if (nbrGroupsInRow < 1) nbrGroupsInRow = 1; int nbrGroupRows = (groupList.size() + nbrGroupsInRow - 1) / nbrGroupsInRow; int innerWidth = Constants.SERVERVIEW_GROUP_WIDTH; int innerHeight = g.getFontMetrics().getHeight() + 5; int outerWidth = innerWidth + 2 * Constants.SERVERVIEW_SELECTION_BORDER + 2; int outerHeight = innerHeight + 2 * Constants.SERVERVIEW_SELECTION_BORDER + 2; int x = 0; int y = h - outerHeight * nbrGroupRows; g.setColor(Color.white); g.fillRect(0, y, w, h - y); g.setColor(Color.black); g.drawLine(0, y - 1, w - 1, y - 1); Iterator<Group> iterg = groupList.iterator(); while (iterg.hasNext()) { Group grp = iterg.next(); // Group box grp.boundingRect.setBounds(x, y, outerWidth, outerHeight); int b = grp.isSelected ? Constants.SERVERVIEW_SELECTION_BORDER : 1; g.setColor(Color.black); g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER - b + 1, y + Constants.SERVERVIEW_SELECTION_BORDER - b + 1, innerWidth + 2 * b, innerHeight + 2 * b); g.setColor(grp.color); g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER + 1, y + Constants.SERVERVIEW_SELECTION_BORDER + 1, innerWidth, innerHeight); g.setColor(Color.black); g.drawString(grp.name, x + Constants.SERVERVIEW_SELECTION_BORDER + 4, y + Constants.SERVERVIEW_SELECTION_BORDER + innerHeight - 4 + 1); // Draw started indicator g.setColor(grp.stateColor); g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER + 1, y + Constants.SERVERVIEW_SELECTION_BORDER + 1, innerWidth, 2); g.setColor(Color.black); g.drawLine(x + Constants.SERVERVIEW_SELECTION_BORDER + 1, y + Constants.SERVERVIEW_SELECTION_BORDER + 3, x + Constants.SERVERVIEW_SELECTION_BORDER + 1 + innerWidth, y + Constants.SERVERVIEW_SELECTION_BORDER + 3); x += outerWidth; if ((x + outerWidth) > w) { x = 0; y += outerHeight; } } } // Store cached version documentVersion = updateDocumentVersion; g.setColor(storedCol); g.setFont(storedFont); }
From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java
public void drawTable(Graphics gr, Point UL, Dataset dataset, int[] selection, Graphics navgGr, int countNavUnit) { Font f = getTableFont(squareL - 1); AnnotationManager annManager = AnnotationManager.getAnnotationManager(); String[] rowIds = dataset.getRowIds(); Set<String> annotations = dataset.getRowAnnotationNamesInUse(); if (annotations == null) { annotations = annManager.getManagedRowAnnotationNames(); }/*ww w .ja v a 2s . c o m*/ String[][] inf; // row annotation matrix String[] headers; // header of the row annotation matrix if (annotations.isEmpty()) { inf = new String[dataset.getDataLength()][1]; for (int i = 0; i < inf.length; i++) { inf[i][0] = rowIds[i]; } headers = new String[] { "Row ID" }; } else { headers = annotations.toArray(new String[annotations.size()]); inf = new String[dataset.getDataLength()][annotations.size()]; for (int i = 0; i < headers.length; i++) { //ann manager need to re implemeinted? AnnotationLibrary anns = annManager.getRowAnnotations(headers[i]); for (int j = 0; j < inf.length; j++) { inf[j][i] = rowIds[j];//anns.getAnnotation(rowIds[j]);// } } } Graphics2D g2d = (Graphics2D) gr; Graphics2D g2dNav = (Graphics2D) navgGr; g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2dNav.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); int X = UL.x; int Y = UL.y; // int H = squareL; int L = dataset.getDataLength(); int W = headers.length; JLabel l = new JLabel(" "); JLabel lNav = new JLabel(" "); // l.setFont(f); // l.setIconTextGap(2); javax.swing.border.Border UB = javax.swing.BorderFactory.createMatteBorder(0, 0, 0, 0, Color.WHITE); javax.swing.border.Border LB = javax.swing.BorderFactory.createMatteBorder(0, 0, 0, 0, Color.WHITE); // Color borderColor = hex2Rgb("#e3e3e3"); javax.swing.border.Border navBorder = javax.swing.BorderFactory.createMatteBorder(2, 0, 0, 0, Color.WHITE); l.setMaximumSize(new Dimension(200, squareL)); lNav.setSize(new Dimension(2, 5)); lNav.setBorder(navBorder); boolean drawTableHeader = false; //if there is not enough room for a header.. skip header. // if (UL.y < squareL) { // drawTableHeader = false; // } if (Wd == null) { Wd = new int[inf[0].length]; WdSUM = new int[inf[0].length]; if (drawTableHeader) { for (int i = 0; i < headers.length; i++) { l.setText(headers[i]); l.validate(); if (l.getPreferredSize().width > Wd[i]) { Wd[i] = l.getPreferredSize().width + 16; } } } for (String[] inf1 : inf) { for (int j = 0; j < Wd.length; j++) { if (squareL < 6) { Wd[j] = 5; continue; } l.setText(inf1[j]); l.validate(); if (l.getPreferredSize().width > Wd[j]) { Wd[j] = l.getPreferredSize().width + 16; } } } WdSUM[0] = 0; for (int i = 0; i < Wd.length; i++) { WdSUM[i] = -1; for (int j = 0; j < i; j++) { WdSUM[i] += Wd[j] + 3; } } } Rectangle BNDS = new Rectangle(); l.setBackground(Color.WHITE); l.setOpaque(true); lNav.setBackground(Color.WHITE); lNav.setOpaque(true); if (sideTree == null) { return; } f = getTableFont(squareL - 1); l.setFont(f); int[] LArr = sideTree.arrangement; int Rindex = 0; //draw the table header.. (if wanted) // if (drawTableHeader) { // // l.setBackground(Color.WHITE); // l.setForeground(Color.white); // // for (int j = 0; j < W; j++) { // X = UL.x + WdSUM[j]; // Y = UL.y; // BNDS.setBounds(X, Y, Wd[j], squareL + 1); // // if (gr.getClipBounds() != null && !gr.getClipBounds().intersects(BNDS)) { // continue; // } // gr.translate(X, Y); // l.setBounds(0, 0, Wd[j] + 1, squareL + 1); // l.setBorder(LB); // // if (squareL >= 6) { // l.setText(headers[j]); // } // l.validate(); // l.paint(gr); // gr.translate(-X, -Y); // } // } l.setForeground(Color.WHITE); boolean[] sel = selectedRows((selection == null ? null : selection), dataset); boolean coloredNav = false; int navCounter = 0; for (int i = 0; i < L; i++) { Rindex = LArr[i]; for (int j = 0; j < W; j++) { X = UL.x + WdSUM[j]; Y = UL.y + (squareL * (i + 1)); BNDS.setBounds(X, Y, Wd[j], squareL + 1); if (gr.getClipBounds() != null && !gr.getClipBounds().intersects(BNDS)) { continue; } if (sel[LArr[i]]) { for (Group group : dataset.getRowGroups()) { if (group.isActive()) { if (group.hasMember(Rindex)) { l.setBackground(group.getColor()); if (!coloredNav) { lNav.setBackground(Color.RED); lNav.setForeground(Color.RED); coloredNav = true; } break; } } } // l.setBackground(new Color(225, 225, 255)); } else { // // if (!coloredNav) { // lNav.setBackground(Color.WHITE); // lNav.setForeground(Color.WHITE); // } l.setBackground(Color.WHITE); } if (i != 0) gr.translate(X, Y); l.setBounds(0, 0, Wd[j] + 1, squareL + 1); if (i < L - 1) { l.setBorder(UB); } else { l.setBounds(0, 0, Wd[j] + 1, squareL + 1); l.setBorder(LB); } if (squareL >= 6) { l.setText(inf[Rindex][j]); } l.validate(); l.paint(gr); gr.translate(-X, -Y); } if (navCounter >= countNavUnit) { navCounter = 0; lNav.validate(); lNav.paint(navgGr); navgGr.translate(2, 0); coloredNav = false; lNav.setBackground(Color.WHITE); lNav.setForeground(Color.WHITE); } navCounter++; } // if (squareL < 6) { // return; // } // // l.setBackground(Color.WHITE); // f = getTableFont(squareL - 2); // //f = new Font("Arial",1,squareL-2); // l.setFont(f); // // // for (int j = 0; j < W; j++) { // X = UL.x + WdSUM[j]; // Y = UL.y; // // BNDS.setBounds(X, Y, Wd[j], squareL + 1); // if (gr.getClipBounds() != null && !gr.getClipBounds().intersects(BNDS)) { // continue; // } // // gr.translate(X, Y); // l.setBounds(0, 0, Wd[j], squareL + 1); //// l.setBorder(javax.swing.BorderFactory.createLineBorder(GridCol)); // l.setText(headers[j]); // l.validate(); // gr.translate(-X, -Y); // } }
From source file:org.esa.nest.gpf.SliceAssemblyOp.java
/** * Called by the framework in order to compute a tile for the given target band. * <p>The default implementation throws a runtime exception with the message "not implemented".</p> * * @param targetBand The target band.//from w w w. j a v a 2s . c o m * @param targetTile The current tile associated with the target band to be computed. * @param pm A progress monitor which should be used to determine computation cancellation requests. * @throws org.esa.beam.framework.gpf.OperatorException If an error occurs during computation of the target raster. */ public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException { try { final Rectangle targetTileRectangle = targetTile.getRectangle(); final int tx0 = targetTileRectangle.x; final int ty0 = targetTileRectangle.y; final int maxY = ty0 + targetTileRectangle.height; final int maxX = tx0 + targetTileRectangle.width; final BandLines[] lines = bandLineMap.get(targetBand); final ProductData trgData = targetTile.getDataBuffer(); final TileIndex trgIndex = new TileIndex(targetTile); final Rectangle srcRect = new Rectangle(); //System.out.println("Do band = " + targetBand.getName() + ": tx0 = " + tx0 + " ty0 = " + ty0 + " maxX = " + maxX + " maxY = " + maxY); BandLines line = lines[0]; for (int y = ty0; y < maxY; ++y) { boolean validLine = y >= line.start && y < line.end; if (!validLine) { for (BandLines l : lines) { if (y >= l.start && y < l.end) { line = l; validLine = true; break; } } if (!validLine) { // should never get here throw new OperatorException("line " + y + " not found in slice products"); } } final int yy = y - line.start; srcRect.setBounds(targetTileRectangle.x, yy, targetTileRectangle.width, 1); final Tile sourceRaster = getSourceTile(line.band, srcRect); final ProductData srcData = sourceRaster.getDataBuffer(); final TileIndex srcIndex = new TileIndex(sourceRaster); trgIndex.calculateStride(y); srcIndex.calculateStride(yy); for (int x = tx0; x < maxX; ++x) { trgData.setElemDoubleAt(trgIndex.getIndex(x), srcData.getElemDoubleAt(srcIndex.getIndex(x))); } } //System.out.println("DONE band = " + targetBand.getName() + ": tx0 = " + tx0 + " ty0 = " + ty0 + " maxX = " + maxX + " maxY = " + maxY); } catch (Throwable e) { throw new OperatorException(e.getMessage()); } }
From source file:org.geowebcache.georss.GeometryRasterMaskBuilder.java
private MathTransform getWorldToGridTransform(final BoundingBox coverageBounds, final long[] coverage) { // ///* w ww . j ava 2 s . c o m*/ // // Convert the JTS envelope and get the transform // // // final Envelope2D genvelope = new Envelope2D(); { // genvelope.setCoordinateReferenceSystem(layerCrs); double x = coverageBounds.getMinX(); double y = coverageBounds.getMinY(); double width = coverageBounds.getWidth(); double height = coverageBounds.getHeight(); genvelope.setFrame(x, y, width, height); } final Rectangle paintArea = new Rectangle(); { int x = (int) coverage[0]; int y = (int) coverage[1]; int width = (int) (1 + coverage[2] - x); int height = (int) (1 + coverage[3] - y); paintArea.setBounds(x, y, width, height); // System.out // .println("Grid: " + JTS.toGeometry(new Envelope(x, x + width, y, y + height))); } final MathTransform worldToScreen; // // // // Get the transform // // // final GridToEnvelopeMapper mapper = new GridToEnvelopeMapper(); mapper.setPixelAnchor(PixelInCell.CELL_CORNER); mapper.setGridRange(new GridEnvelope2D(paintArea)); mapper.setEnvelope(genvelope); mapper.setSwapXY(false); try { worldToScreen = mapper.createTransform().inverse(); } catch (org.opengis.referencing.operation.NoninvertibleTransformException e) { throw new IllegalArgumentException(e); } catch (IllegalStateException e) { throw new IllegalArgumentException(e); } return worldToScreen; }
From source file:org.photovault.swingui.PhotoCollectionThumbView.java
@Override public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; Rectangle clipRect = g.getClipBounds(); Dimension compSize = getSize(); // columnCount = (int)(compSize.getWidth()/columnWidth); int photoCount = 0; if (photos != null) { photoCount = photos.size();//from www . ja va 2 s . c o m } // Determine the grid size based on couln & row count columnsToPaint = columnCount; // if columnCount is not specified determine it based on row count if (columnCount < 0) { if (rowCount > 0) { columnsToPaint = photoCount / rowCount; if (columnsToPaint * rowCount < photoCount) { columnsToPaint++; } } else { columnsToPaint = (int) (compSize.getWidth() / columnWidth); } } int col = 0; int row = 0; Rectangle thumbRect = new Rectangle(); for (PhotoInfo photo : photos) { thumbRect.setBounds(col * columnWidth, row * rowHeight, columnWidth, rowHeight); if (thumbRect.intersects(clipRect)) { if (photo != null) { paintThumbnail(g2, photo, col * columnWidth, row * rowHeight, selection.contains(photo)); } } col++; if (col >= columnsToPaint) { row++; col = 0; } } // Paint the selection rectangle if needed if (dragSelectionRect != null) { Stroke prevStroke = g2.getStroke(); Color prevColor = g2.getColor(); g2.setStroke(new BasicStroke(1.0f)); g2.setColor(Color.BLACK); g2.draw(dragSelectionRect); g2.setColor(prevColor); g2.setStroke(prevStroke); lastDragSelectionRect = dragSelectionRect; } }
From source file:org.safs.selenium.webdriver.lib.WDLibrary.java
/** * Get the screen rectangle for a WebElement object. * @param we WebElement, the webelement object to get screen rectangle * @return Rectangle, the screen rectangle of a webelement object * @throws SeleniumPlusException/*from www . j a v a 2s .c o m*/ */ public static Rectangle getRectangleOnScreen(WebElement we) throws SeleniumPlusException { Rectangle rectangle = null; try { Point p = getScreenLocation(we); org.openqa.selenium.Dimension dim = we.getSize(); rectangle = new Rectangle(); rectangle.setBounds(p.x, p.y, dim.getWidth(), dim.getHeight()); return rectangle; } catch (Exception e) { throw new SeleniumPlusException( "Fail get screen rectangle for webelement, due to " + StringUtils.debugmsg(e)); } }
From source file:org.squidy.designer.Designer.java
/** * @param view//from w w w . j a v a2 s. c om */ 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()); } } } }); }