1// BEGIN LICENSE BLOCK 2// Version: CMPL 1.1 3// 4// The contents of this file are subject to the Cisco-style Mozilla Public 5// License Version 1.1 (the "License"); you may not use this file except 6// in compliance with the License. You may obtain a copy of the License 7// at www.eclipse-clp.org/license. 8// 9// Software distributed under the License is distributed on an "AS IS" 10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11// the License for the specific language governing rights and limitations 12// under the License. 13// 14// The Original Code is The ECLiPSe Constraint Logic Programming System. 15// The Initial Developer of the Original Code is Cisco Systems, Inc. 16// Portions created by the Initial Developer are 17// Copyright (C) 2006 Cisco Systems, Inc. All Rights Reserved. 18// 19// Contributor(s): 20// 21// END LICENSE BLOCK 22 23package com.parctechnologies.eclipse.visualisation.viewers; 24 25import com.parctechnologies.eclipse.*; 26import com.parctechnologies.eclipse.visualisation.*; 27 28import java.awt.Rectangle; 29import java.awt.Shape; 30import java.awt.geom.*; 31import java.awt.Color; 32import java.awt.Component; 33import java.util.*; 34import java.awt.event.ActionEvent; 35import javax.swing.*; 36import javax.swing.table.*; 37import att.grappa.*; 38 39public class CustRenderer extends GrappaShape implements CustomRenderer { 40 /** Stores copy of element for which this Custom Renderer was 41 created */ 42 protected Element element; 43 44 /** 45 * This constructor is called by the GrappaNexus updateShape method */ 46 public CustRenderer(Element element, 47 double x, double y, double w, double h) { 48 super(CUSTOM_SHAPE, x+(w/2), y+(h/2), w, h, 49 4, 50 1, 51 0.0, 52 0.0, 53 0.0, 54 false, 55 false, 56 null); 57 this.element = element; 58 } 59 60 /** 61 * Retrieves the viewletData which this renderer must display. 62 * 63 * <p> Requires that element.object is a two element array 64 * containing the ContainerViewer and the element index for this 65 * viewlet. 66 **/ 67 public ViewletData getViewletData() { 68 return (ViewletData)element.object; 69 } 70 71 /** 72 * The method called when the element needs to be drawn. 73 * When used with an extention of <i>GrappaShape</i>, 74 * the default behavior is obtained by: 75 * <pre> 76 * public void draw(java.awt.Graphics2D g2d) { 77 * g2d.draw(this); 78 * } 79 * </pre> 80 * 81 * @param g2d the Graphics2D context to be used for drawing 82 */ 83 public void draw(java.awt.Graphics2D g2d) { 84 g2d.draw(this); 85 } 86 87 /** 88 * The method called when the element needs to be filled. 89 * When used with an extention of <i>GrappaShape</i>, 90 * the default behavior is obtained by: 91 * <pre> 92 * public void fill(java.awt.Graphics2D g2d) { 93 * g2d.fill(this); 94 * } 95 * </pre> 96 * 97 * @param g2d the Graphics2D context to be used for drawing 98 */ 99 public void fill(java.awt.Graphics2D g2d) { 100 g2d.fill(this); 101 } 102 103 /** 104 * The method called when the element needs to draw its background 105 * image. 106 * When used with an extention of <i>GrappaShape</i> that provides 107 * the underlying element as a global variable, the default behavior 108 * is obtained by: 109 * <pre> 110 * public void drawImage(java.awt.Graphics2D g2d) { 111 * Rectangle sbox = this.getBounds(); 112 * Shape clip = g2d.getClip(); 113 * g2d.clip(this); 114 * g2d.drawImage(element.getGrappaNexus().getImage(), sbox.x, sbox.y, sbox.width, sbox.height, null); 115 * g2d.setClip(clip); 116 * } 117 * </pre> 118 * 119 * @param g2d the Graphics2D context to be used for drawing 120 */ 121 public void drawImage(java.awt.Graphics2D g2d) { 122 Rectangle sbox = this.getBounds(); 123 Shape clip = g2d.getClip(); 124 g2d.clip(this); 125 g2d.drawImage(element.getGrappaNexus().getImage(), 126 sbox.x, sbox.y, sbox.width, sbox.height, null); 127 g2d.setClip(clip); 128 } 129} 130