001 package sysModel.env;
002
003 import controller.IScrollAdapter;
004 import controller.IDisplayAdapter;
005 import model.ILambda;
006 import sysModel.NoOpLambda;
007 import sysModel.fish.IFishFactory;
008 import sysModel.fish.AFish;
009 import sysModel.parser.Lexer;
010
011 import java.awt.*;
012 import java.io.PrintWriter;
013
014 /**
015 * Dummy environment used if no other environment has been created or loaded yet.
016 *
017 * @author Mathias Ricken
018 */
019 public class NullEnv extends AGlobalEnv {
020 /**
021 * Singleton instance.
022 */
023 private static NullEnv _instance;
024
025 /**
026 * Return singleton instance.
027 *
028 * @return singleton instance
029 */
030 public static synchronized NullEnv instance() {
031 if (null == _instance) {
032 _instance = new NullEnv();
033 }
034 return _instance;
035 }
036
037 /**
038 * Private singleton constructor.
039 */
040 private NullEnv() {
041 super(null, null);
042 }
043
044 /**
045 * Add the fish to the global environment.
046 *
047 * @param localEnv local environment
048 * @param fish fish to add
049 */
050 public void addFishToInternalData(ALocalEnv localEnv, AFish fish) {
051 }
052
053 /**
054 * Remove the fish from the global environment.
055 *
056 * @param localEnv local environment
057 */
058 protected void removeFishFromInternalData(ALocalEnv localEnv) {
059 }
060
061 /**
062 * Edit the fish.
063 *
064 * @param localEnv local environment
065 * @param fishFactory
066 * @param button
067 * @return lambda to edit the fish
068 */
069 public ILambda editFish(ALocalEnv localEnv, IFishFactory fishFactory, int button) {
070 return NoOpLambda.instance();
071 }
072
073 /**
074 * Create a local environment for the position.
075 *
076 * @param p position
077 * @return local environment
078 */
079 public ALocalEnv makeLocalEnv(Point.Double p) {
080 return null;
081 }
082
083 /**
084 * Factory method for parsing a stream of tokens and creating a global environment from it.
085 *
086 * @param l lexer
087 * @return new global environment
088 */
089 public AGlobalEnv parseEnvironment(Lexer l) {
090 return NullEnv.instance();
091 }
092
093 /**
094 * Parse fish and add them to the environment.
095 *
096 * @param l parser to read from
097 */
098 protected void parseFish(Lexer l) {
099 }
100
101 /**
102 * Get the environment settings class.
103 *
104 * @return environment settings class
105 */
106 public AEnvFactory makeEnvFactory() {
107 return new AEnvFactory() {
108 public AGlobalEnv create() {
109 return NullEnv.instance();
110 }
111
112 public String toString() {
113 return NullEnv.class.getName();
114 }
115 };
116 }
117
118 /**
119 * Print file header.
120 *
121 * @param pw PrintWriter to use
122 */
123 protected void printHeader(PrintWriter pw) {
124 }
125
126 /**
127 * Get size of the display.
128 *
129 * @return size of the display in model coordinate units.
130 */
131 public Dimension getDisplaySize() {
132 return new Dimension();
133 }
134
135 /**
136 * The action to be executed if the display should return home.
137 *
138 * @param sa scroll adapter
139 */
140 public void returnHome(IScrollAdapter sa) {
141 }
142
143 /**
144 * Ask the model where to scroll, given where the user has scrolled. If the environment just acts like a normal
145 * panal, it should return pos without modification. If the environment recenters, it should return a position in
146 * the middle of the pan area. All coordinates are in model coordinate units.
147 *
148 * @param pos position where the user scrolled to
149 * @return position where the environment wants the view to be
150 * @see IDisplayAdapter#getPanDelta
151 */
152 public Point.Double getViewPosition(Point.Double pos) {
153 // the panel always gets recentered after moving it, so return the center position
154 return new Point.Double();
155 }
156
157 /**
158 * Ask the model how much to pan, given where the user scrolled. If the environment just acts like a normal panal,
159 * it should return (0,0). If the environment recenters, it should return delta without modification. All
160 * coordinates are in model coordinate units.
161 *
162 * @param delta how far the user scrolled
163 * @return how far the panel should scroll
164 * @see IDisplayAdapter#getViewPosition
165 */
166 public Point.Double getPanDelta(Point.Double delta) {
167 // we want the panel to keep track of the position, so return the delta as pan value
168 return new Point.Double();
169 }
170
171 /**
172 * Get a tool tip description for a specific place in the environment.
173 *
174 * @param p mouse coordinates
175 * @return lambda for the simulation controller to execute. Must return the tooltip string.
176 */
177 public ILambda getToolTipText(Point.Double p) {
178 return new ILambda() {
179 public Object apply(Object param) {
180 return "";
181 }
182 };
183 }
184 }