/** * Copyright 1999-2009 The Pegadi Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.pegadi.storysketch.views; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Polygon; import org.jgraph.JGraph; import org.jgraph.graph.CellMapper; import org.jgraph.graph.CellViewRenderer; import org.jgraph.graph.GraphConstants; import org.jgraph.graph.VertexRenderer; import org.jgraph.graph.VertexView; public class PlaceView extends VertexView { static PlaceRenderer renderer = new PlaceRenderer(); // Constructor for Superclass public PlaceView(Object cell, JGraph graph,CellMapper cm) { super(cell, graph, cm); } /* // Returns Perimeter Point for Places public Point getPerimeterPoint(Point source, Point p) { ... } */ // Returns the Renderer for this View public CellViewRenderer getRenderer() { return renderer; } // Define the Renderer for an PlaceView static class PlaceRenderer extends VertexRenderer { public void paint(Graphics g) { int b = borderWidth; Graphics2D g2 = (Graphics2D) g; Dimension d = getSize(); int w = (int)d.getWidth()-2; int h = (int)d.getHeight() -2; boolean tmp = selected; Polygon p = new Polygon(); int corner = w/4; p.addPoint(0,0); p.addPoint(w-corner/2,0); p.addPoint(w,corner/2); p.addPoint(w,h); p.addPoint(0,h); if (super.isOpaque()) { g.setColor(super.getBackground()); g.fillPolygon(p); } try { setBorder(null); setOpaque(false); selected = false; super.paint(g); } finally { selected = tmp; } if (bordercolor != null) { g.setColor(bordercolor); g2.setStroke(new BasicStroke(b)); drawPlace(g2,p,w,corner); if (selected) { g2.setStroke(GraphConstants.SELECTION_STROKE); g.setColor(graph.getHighlightColor()); drawPlace(g2,p,w,corner); } } } public void drawPlace(Graphics2D g, Polygon p, int w, int corner) { g.drawPolygon(p); // Draw the clock // Background g.setColor(Color.white); g.fillOval(w-corner,0,corner,corner); g.setColor(super.getBackground()); // Outline g.setColor(bordercolor); g.drawOval(w-corner,0,corner,corner); for(int i = 0; corner-2*i > 0; i+=corner/6) g.drawArc(w-corner+i,0,corner-2*i,corner,90,180); for(int i = 0; corner-2*i > 0; i+=corner/6) g.drawArc(w-corner+i,0,corner-2*i,corner,-90,180); } } }