001 /** 002 * planningtool - A Planning Tool with Critiquing Support. 003 * 004 * Copyright (C) 2006 olale 005 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU General Public License 008 * as published by the Free Software Foundation; either version 2 009 * of the License, or (at your option) any later version. 010 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 016 * You should have received a copy of the GNU General Public License 017 * along with this program; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 020 * Contact information: 021 * E-mail: olale@ida.liu.se 022 * olale@lysator.liu.se 023 */ 024 package se.liu.ida.critiquer.gui.graph; 025 026 import java.awt.Color; 027 028 import org.tigris.gef.presentation.FigCircle; 029 import org.tigris.gef.presentation.FigNode; 030 import org.tigris.gef.presentation.FigRect; 031 import org.tigris.gef.presentation.FigText; 032 033 import se.liu.ida.critiquer.activities.AbstractParamChangedListener; 034 import se.liu.ida.critiquer.activities.Activity; 035 import se.liu.ida.critiquer.activities.parameters.CommanderParameter; 036 import se.liu.ida.critiquer.activities.parameters.NameParameter; 037 import se.liu.ida.critiquer.activities.parameters.Parameter; 038 039 /** 040 * Visual representation of an activity in the graph view 041 * 042 * @author olale 043 * 044 */ 045 public class ActivityFigNode extends FigNode { 046 047 /** 048 * 049 */ 050 private static final long serialVersionUID = 1L; 051 052 private FigRect figNodeFrame; 053 054 private FigCircle parentPortFig; 055 056 private FigCircle childPortFig; 057 058 private FigRect previousPortFig; 059 060 private FigRect nextPortFig; 061 062 private FigText descriptionFig; 063 064 public ActivityFigNode(ActivityNode node) { 065 super(node); 066 // Bind ports to objects used by this graphical representation 067 ActivityNode activityNode = (ActivityNode) node; 068 figNodeFrame = new FigRect(-50,-50,100,100,true); 069 addFig(figNodeFrame); 070 parentPortFig = new FigCircle( -10, -50, 20, 20, Color.black, Color.blue); 071 addFig(parentPortFig); 072 childPortFig = new FigCircle( -10, 30, 20, 20, Color.black, Color.blue); 073 addFig(childPortFig); 074 previousPortFig = new FigRect(-50, -10, 20, 20, Color.black, Color.green); 075 addFig(previousPortFig); 076 nextPortFig = new FigRect( 30, -10, 20, 20, Color.black, Color.green); 077 addFig(nextPortFig); 078 descriptionFig = new FigText( -40, -25, 90, 30); 079 descriptionFig.setLineWidth(0); 080 descriptionFig.setFontFamily("Tahoma"); 081 descriptionFig.setFontSize(11); 082 descriptionFig.setJustification(FigText.JUSTIFY_CENTER); 083 updateDescriptionText(); 084 addFig(descriptionFig); 085 086 bindPort(activityNode.getParentPort(), parentPortFig); 087 bindPort(activityNode.getChildPort(), childPortFig); 088 bindPort(activityNode.getPreviousPort(), previousPortFig); 089 bindPort(activityNode.getNextPort(), nextPortFig); 090 setResizable(false); 091 092 node.getActivity().addPrivateUpdateListener(new AbstractParamChangedListener() { 093 094 /** 095 * 096 */ 097 private static final long serialVersionUID = 1L; 098 099 @Override 100 public <T> void paramChanged(Activity activity, Parameter<T> p) { 101 if (p instanceof CommanderParameter) { 102 updateHighlight(activity); 103 104 } else if (p instanceof NameParameter) { 105 updateDescriptionText(); 106 } 107 getLayer().damageAll(); 108 } 109 110 111 112 }); 113 updateHighlight(node.getActivity()); 114 115 } 116 117 private void updateHighlight(Activity activity) { 118 if (activity.isAgentAssignable()) { 119 figNodeFrame.setFilled(true); 120 figNodeFrame.setFillColor(Color.LIGHT_GRAY); 121 } else { 122 figNodeFrame.setFillColor(Color.WHITE); 123 //figNodeFrame.setFilled(false); 124 } 125 } 126 127 private void updateDescriptionText() { 128 descriptionFig.setText(getActivityNode().getActivity().toString()); 129 } 130 131 public ActivityNode getActivityNode(){ 132 return (ActivityNode) getOwner(); 133 } 134 135 136 /* (non-Javadoc) 137 * @see java.lang.Object#toString() 138 */ 139 @Override 140 public String toString() { 141 return getActivityNode().getActivity().toString(); 142 } 143 144 145 146 }