/**
* 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 EventView extends VertexView {
static EventRenderer renderer = new EventRenderer();
// Constructor for Superclass
public EventView(Object cell, JGraph graph,CellMapper cm) {
super(cell, graph, cm);
}
/*
// Returns Perimeter Point for Events
public Point getPerimeterPoint(Point source, Point p) { ...
}
*/
// Returns the Renderer for this Event
public CellViewRenderer getRenderer() {
return renderer;
}
// Define the Renderer for an EventView
static class EventRenderer 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));
drawEvent(g2,p,w,corner);
if (selected) {
g2.setStroke(GraphConstants.SELECTION_STROKE);
g.setColor(graph.getHighlightColor());
drawEvent(g2,p,w,corner);
}
}
}
public void drawEvent(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);
// "Viser 1"
double minDegrees = 45*Math.PI/180;
int dx = (int) (Math.cos(minDegrees)*corner/2*0.95);
int dy = (int) (Math.sin(minDegrees)*corner/2*0.95);
g.drawLine(w-corner/2,corner/2,w-corner/2+dx,corner/2-dy);
// "Viser 2"
double hourDegrees = 180*Math.PI/183;
dx = (int) (Math.cos(hourDegrees)*corner/2*0.7);
dy = (int) (Math.sin(hourDegrees)*corner/2*0.7);
g.drawLine(w-corner/2,corner/2,w-corner/2+dx,corner/2-dy);
}
}
}