/*---------------------------- Ingeneue source code ?Copyright 2000 by George von Dassow, Eli Meir, Edwin Munro, and Garrett Odell. Permission is granted for use by private individuals and by individuals and groups at all non-profit institutions, as long as those using the software or examining the code do not intend to make a profit from its use, and subject to all other conditions given on the website www.ingenenue.org. www.ingeneue.org contact@ingeneue.org ----------------------------*/ package main; import java.awt.*; import java.util.*; import java.io.*; import javax.swing.*; public class NodeTemplate { /** A vector of the affector templates for this nodes affectors. */ Vector affectors = new Vector(); /** The name of the node. */ String name; /** The number of the node. */ int nodeNum; /** 1 if this node is cytoplasmic. = num sides in cell if this node is membrane-bound. */ int numSides = 1; /** The color used to draw this node */ Color color = Color.pink; /** true if this node should be shown in Cell View. */ boolean show = false; /** The value at which this node is drawn at maximum brightness in the Cell view. */ float yScale = 1; public static final int RNA = 1, PROTEIN = 2, COMPLEX = 3, INPUT = 4, SUM = 5, RATIO = 6, WEIGHTEDSUM = 7, STEADYSTATE = 8; // SUM, RATIO, WEIGHTEDSUM, STEADYSTATE types are implemented in sub-class CalculatorNode /** The class of objects in which this node falls - RNA, PROTEIN, etc. */ int nodeType = RNA; CalculatorNode calculatorNode = null; public static final int POSITION_NOT_SET = -10000; // Indicates position of node is not yet set int xPos = POSITION_NOT_SET; int yPos = POSITION_NOT_SET; public NodeTemplate(String name, int num) { this.name = name; nodeNum = num; } public void addAffector(AffectorTemplate aff) { affectors.addElement(aff); } public Node makeNode() { Node node = null; if(calculatorNode != null) node = calculatorNode.copy(); else node = new Node(nodeNum, numSides); return node; } public boolean getShow() { return show; } public void setShow(boolean flag) { show = flag; } public Color getColor() { return color; } public void setColor(Color color) { this.color = color; } public int getType() { return nodeType; } public void setType(int node_type) { nodeType = node_type; } public float getYScale() { return yScale; } public void setYScale(float scale) { yScale = scale; } public int getXPos() { return xPos; } public void setXPos(int x) { xPos = x; } public int getYPos() { return yPos; } public void setYPos(int y) { yPos = y; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getNodeNum() { return nodeNum; } public void setNodeNum(int num) { nodeNum = num; } public void setCalculatorNode(boolean b) { if(b) { calculatorNode = new CalculatorNode(nodeNum, numSides); } else calculatorNode = null; } /** Returns the ImagIcon that is used to represnt this type of node for various editors and viewers. @return ImageIcon - The icon. @author WJS */ public ImageIcon getIcon() { switch (nodeType) { case RNA: return(new ImageIcon("icons/MSEGeneIcon.gif")); case PROTEIN: return(new ImageIcon("icons/MSEProteinIcon.gif")); case COMPLEX: return(new ImageIcon("icons/MSEComplexIcon.gif")); default: return(null); } } public Vector getAffectors() { return affectors; } public int getNumAffectors() { return numSides * affectors.size(); } public void readSetup(BetterTokenizer tokenizer) throws Exception { String info = GeneralInput.findNextIDToken(tokenizer); while(!info.equals("end" + name)) { loadParameter(info, tokenizer); info = GeneralInput.findNextIDToken(tokenizer); } // while info != end } protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { info = info.toUpperCase(); if(calculatorNode != null && calculatorNode.loadParameter(info, tokenizer)) { // done } else if(info.equals("LOCATION")) { GeneralInput.nextToken(tokenizer); if(tokenizer.sval.toUpperCase().equals("CYTO") || tokenizer.sval.toUpperCase().equals("CYTOPLASMIC")) numSides = 1; else if(tokenizer.sval.toUpperCase().equals("MEMBRANE")) numSides = Globals.cellNumSides; else throw new Exception("Location (cytoplasmic, membrane) of node " + name + " is not set correctly [" + tokenizer.sval + "]"); if(calculatorNode != null) calculatorNode.setNumSides(numSides); } else if(info.equals("COLOR")) { if(GeneralInput.nextToken(tokenizer) == BetterTokenizer.TT_NUMBER) { // Specifying color with r, g, b values int red = (int)tokenizer.nval; GeneralInput.nextToken(tokenizer); int green = (int)tokenizer.nval; GeneralInput.nextToken(tokenizer); int blue = (int)tokenizer.nval; color = new Color(red, green, blue); } else if(tokenizer.sval.toUpperCase().equals("WHITE")) color = Color.white; else if(tokenizer.sval.toUpperCase().equals("RED")) color = Color.red; else if(tokenizer.sval.toUpperCase().equals("GREEN")) color = Color.green; else if(tokenizer.sval.toUpperCase().equals("BLUE")) color = Color.blue; else if(tokenizer.sval.toUpperCase().equals("CYAN")) color = Color.cyan; else if(tokenizer.sval.toUpperCase().equals("MAGENTA")) color= Color.magenta; else if(tokenizer.sval.toUpperCase().equals("PINK")) color = Color.pink; else if(tokenizer.sval.toUpperCase().equals("YELLOW")) color = Color.yellow; else if(tokenizer.sval.toUpperCase().equals("ORANGE")) color = Color.orange; else color = Color.black; } else if(info.equals("SHOW")) { GeneralInput.nextToken(tokenizer); if(tokenizer.sval.toUpperCase().equals("ON") || tokenizer.sval.toUpperCase().equals("YES")) show = true; else if(tokenizer.sval.toUpperCase().equals("OFF") || tokenizer.sval.toUpperCase().equals("NO")) show = false; else throw new Exception("The show value for node " + name + " is not set correctly"); } else if(info.equals("SCALE")) { if(GeneralInput.nextToken(tokenizer) != BetterTokenizer.TT_NUMBER) throw new Exception("The scale for the node " + name + " is not set correctly"); yScale = (float)tokenizer.nval; } else if(info.equals("TYPE")) { GeneralInput.nextToken(tokenizer); if(tokenizer.sval.toUpperCase().equals("RNA")) nodeType = RNA; else if(tokenizer.sval.toUpperCase().equals("PROTEIN")) nodeType = PROTEIN; else if(tokenizer.sval.toUpperCase().equals("COMPLEX")) nodeType = COMPLEX; else if(tokenizer.sval.toUpperCase().equals("INPUT")) nodeType = INPUT; else if(tokenizer.sval.toUpperCase().equals("SUM")) nodeType = SUM; else if(tokenizer.sval.toUpperCase().equals("RATIO")) nodeType = RATIO; else if(tokenizer.sval.toUpperCase().equals("WEIGHTEDSUM")) nodeType = WEIGHTEDSUM; else if(tokenizer.sval.toUpperCase().equals("STEADYSTATE")) nodeType = STEADYSTATE; if(calculatorNode != null) calculatorNode.setType(nodeType); } else if(info.equals("XPOS")) { GeneralInput.nextToken(tokenizer); xPos = (int)tokenizer.nval; } else if(info.equals("YPOS")) { GeneralInput.nextToken(tokenizer); yPos = (int)tokenizer.nval; } else throw new Exception("Unrecognized token '" + info + "' while loading node " + name); } public void toString(PrintWriter pw, String indent) { pw.println(indent + "&" + name); if(numSides == 1) pw.println(indent + "\t&Location\tcyto"); else pw.println(indent + "\t&Location\tmembrane"); pw.println(indent + "\t&Color\t" + color.getRed() + "\t" + color.getGreen() + "\t" + color.getBlue()); if(show) pw.println(indent + "\t&Show\ton"); else pw.println(indent + "\t&Show\toff"); pw.println(indent + "\t&Scale\t" + yScale); if(nodeType == RNA) pw.println(indent + "\t&Type\tRNA"); else if(nodeType == PROTEIN) pw.println(indent + "\t&Type\tPROTEIN"); else if(nodeType == COMPLEX) pw.println(indent + "\t&Type\tCOMPLEX"); else if(nodeType == RNA) pw.println(indent + "\t&Type\tINPUT"); else if(nodeType == SUM) pw.println(indent + "\t&Type\tSUM"); else if(nodeType == RATIO) pw.println(indent + "\t&Type\tRATIO"); pw.println(indent + "\t&XPos\t" + xPos); pw.println(indent + "\t&YPos\t" + yPos); pw.println(indent + "&end" + name); } public void affectorsToString(PrintWriter pw, String indent) { int i; Enumeration enum = affectors.elements(); while(enum.hasMoreElements()) { AffectorTemplate aff = (AffectorTemplate)enum.nextElement(); String str = aff.getAffector().getClass().getName(); pw.print(indent + "&" + str.substring(str.indexOf(".") + 1)); aff.toString(pw, indent); } } }