Changeset 933
- Timestamp:
- 11/15/14 17:51:01 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/MagneticConstraint/MagneticConstraints.java
r919 r933 19 19 package org.expeditee.items.MagneticConstraint; 20 20 21 import java.util.*; 22 //import java.util.concurrent.*; 23 21 24 import org.expeditee.items.Item; 22 25 23 26 public class MagneticConstraints { 27 public static List<String> log = new LinkedList<String>(); 28 24 29 private static MagneticConstraints instance = null; 25 30 26 31 private MagneticConstraintAction rightBorderHitAction = null; 27 32 private MagneticConstraintAction endOfLineHitAction = null; … … 29 34 private MagneticConstraintAction startOfLineHitAction = null; 30 35 private MagneticConstraintActionWithArguments<Float> textShrunkAction = null; 31 private MagneticConstraintActionWithArguments<Float> textGrownAction = null; 36 private MagneticConstraintActionWithArguments<Float> textGrownAction = null; 37 private MagneticConstraintAction topBorderHitAction = null; 38 private MagneticConstraintAction bottomBorderHitAction = null; 39 private Map<Integer, MagneticConstraintAction> keyEvents = new LinkedHashMap<Integer, MagneticConstraintAction>(); 40 41 // private final ExecutorService thread = Executors.newSingleThreadExecutor(); 42 43 // private boolean textShrunkRunnable = true; 44 // private boolean textGrownRunnable = true; 32 45 33 46 public static MagneticConstraints getInstance() { … … 38 51 return instance; 39 52 } 40 53 54 public static void Log(final Class<? extends MagneticConstraintAction> actionType, 55 final Item[] primaryInvolved, final Item[] line, final String additionalInfo) { 56 final String nl = System.getProperty("line.separator"); 57 58 final String heading = "Action type: " + actionType; 59 final String[] primaryInvolvedStringed = new String[primaryInvolved.length]; 60 for(int i = 0; i < primaryInvolved.length; i++) 61 primaryInvolvedStringed[i] = "\t" + "Primary item " + i + ". Text: " + primaryInvolved[i].getText(); 62 String lineContent = "\tLine content: "; 63 for(final Item i : line) lineContent += (i.getText() + " "); 64 String logContent = heading + nl; 65 for(final String s : primaryInvolvedStringed) logContent += (s + nl); 66 logContent += (lineContent + nl + additionalInfo + nl); 67 68 log.add(logContent); 69 } 70 71 public boolean keyHit(final int key, final Item item) { 72 final MagneticConstraintAction action = keyEvents.get(key); 73 if(action == null && key < 0 && keyEvents.get(-key) != null) { 74 return keyEvents.get(-key).invert(item); 75 } else if(action == null) return false; 76 else return action.exec(item); 77 } 78 79 public void setKeyAction(final int key, final MagneticConstraintAction action) { 80 keyEvents.put(key, action); 81 } 82 41 83 public boolean rightBorderHit(final Item item) { 42 if (rightBorderHitAction != null) 43 return rightBorderHitAction.exec(item); 44 else 45 return false; 46 } 84 if (rightBorderHitAction != null) 85 return rightBorderHitAction.exec(item); 86 else 87 return false; 88 } 89 90 // public boolean rightBorderHit(final Item item) { 91 // try { 92 // if(rightBorderHitAction != null) { 93 // final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { 94 // @Override 95 // public Boolean call() throws Exception { 96 // return rightBorderHitAction.exec(item); 97 // } 98 // }); 99 // thread.execute(future); 100 // return future.get(); 101 // } else return false; 102 // } catch (final Exception e) { 103 // System.err.println("Concurrent Exception caught during rightBorderHit action"); 104 // return false; 105 // } 106 // } 47 107 48 108 public void setRightBorderHitAction(final MagneticConstraintAction action) { … … 56 116 return false; 57 117 } 118 119 // public boolean endOfLineHit(final Item item) { 120 // try { 121 // if(endOfLineHitAction != null) { 122 // final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { 123 // @Override 124 // public Boolean call() throws Exception { 125 // return endOfLineHitAction.exec(item); 126 // } 127 // }); 128 // thread.execute(future); 129 // return future.get(); 130 // } else return false; 131 // } catch (final Exception e) { 132 // System.err.println("Concurrent Exception caught during endOfLineHit action"); 133 // return false; 134 // } 135 // } 58 136 59 137 public void setEndOfLineHitAction(final MagneticConstraintAction action) { … … 67 145 return false; 68 146 } 147 148 // public boolean leftBorderHit(final Item item) { 149 // try { 150 // if(leftBorderHitAction != null) { 151 // final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { 152 // @Override 153 // public Boolean call() throws Exception { 154 // return leftBorderHitAction.exec(item); 155 // } 156 // }); 157 // thread.execute(future); 158 // return future.get(); 159 // } else return false; 160 // } catch (final Exception e) { 161 // System.err.println("Concurrent Exception caught during leftBorderHit action"); 162 // return false; 163 // } 164 // } 69 165 70 166 public void setLeftBorderHitAction(final MagneticConstraintAction action) { … … 79 175 } 80 176 177 // public boolean startOfLineHit(final Item item) { 178 // try { 179 // if(startOfLineHitAction != null) { 180 // final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { 181 // @Override 182 // public Boolean call() throws Exception { 183 // return startOfLineHitAction.exec(item); 184 // } 185 // }); 186 // thread.execute(future); 187 // return future.get(); 188 // } else return false; 189 // } catch (final Exception e) { 190 // System.err.println("Concurrent Exception caught during startOfLineHit action"); 191 // return false; 192 // } 193 // } 194 81 195 public void setStartOfLineHitAction(final MagneticConstraintAction action) { 82 196 startOfLineHitAction = action; … … 84 198 85 199 public boolean textShrunk(final Item item, final float delta) { 86 if( textShrunkAction != null)200 if(/*textShrunkRunnable &&*/ textShrunkAction != null) 87 201 return textShrunkAction.exec(item, delta); 88 202 else return false; 89 203 } 90 204 205 // public void suspendTextShrunkAction() { 206 // textShrunkRunnable = false; 207 // } 208 // 209 // public void resumeTextShrunkAction() { 210 // textShrunkRunnable = true; 211 // } 212 213 // public boolean textShrunk(final Item item, final float delta) { 214 // try { 215 // if(textShrunkAction != null && textShrunkRunnable) { 216 // final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { 217 // @Override 218 // public Boolean call() throws Exception { 219 // return textShrunkAction.exec(item, delta); 220 // } 221 // }); 222 // thread.execute(future); 223 // return future.get(); 224 // } else return false; 225 // } catch (final Exception e) { 226 // System.err.println("Concurrent Exception caught during textShrunk action"); 227 // return false; 228 // } 229 // } 230 91 231 public void setTextShrunkAction(final MagneticConstraintActionWithArguments<Float> action) { 92 232 textShrunkAction = action; … … 94 234 95 235 public boolean textGrown(final Item item, final float delta) { 96 if( textGrownAction != null)236 if(/*textGrownRunnable &&*/ textGrownAction != null) 97 237 return textGrownAction.exec(item, delta); 98 238 else return false; 99 239 } 100 240 241 // public void suspendTextGrownAction() { 242 // textGrownRunnable = false; 243 // } 244 // 245 // public void resumeTextGrownAction() { 246 // textGrownRunnable = true; 247 // } 248 249 // public boolean textGrown(final Item item, final float delta) { 250 // try { 251 // if(textGrownAction != null && textGrownRunnable) { 252 // final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { 253 // @Override 254 // public Boolean call() throws Exception { 255 // return textGrownAction.exec(item, delta); 256 // } 257 // }); 258 // thread.execute(future); 259 // return future.get(); 260 // } else return false; 261 // } catch (final Exception e) { 262 // System.err.println("Concurrent Exception caught during textGrown action"); 263 // return false; 264 // } 265 // } 266 101 267 public void setTextGrownAction(final MagneticConstraintActionWithArguments<Float> action) { 102 268 textGrownAction = action; 103 269 } 270 271 public boolean topBorderHit(final Item item) { 272 if(topBorderHitAction != null) 273 return topBorderHitAction.exec(item); 274 else return false; 275 } 276 277 // public boolean topBorderHit(final Item item) { 278 // try { 279 // if(topBorderHitAction != null) { 280 // final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { 281 // @Override 282 // public Boolean call() throws Exception { 283 // return topBorderHitAction.exec(item); 284 // } 285 // }); 286 // thread.execute(future); 287 // return future.get(); 288 // } else return false; 289 // } catch (final Exception e) { 290 // System.err.println("Concurrent Exception caught during topBorderHit action"); 291 // return false; 292 // } 293 // } 294 295 public void setTopBorderHitAction(final MagneticConstraintAction action) { 296 topBorderHitAction = action; 297 } 298 299 public boolean bottomBorderHit(final Item item) { 300 if(bottomBorderHitAction != null) 301 return bottomBorderHitAction.exec(item); 302 else return false; 303 } 304 305 // public boolean bottomBorderHit(final Item item) { 306 // try { 307 // if(bottomBorderHitAction != null) { 308 // final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { 309 // @Override 310 // public Boolean call() throws Exception { 311 // return bottomBorderHitAction.exec(item); 312 // } 313 // }); 314 // thread.execute(future); 315 // return future.get(); 316 // } else return false; 317 // } catch (final Exception e) { 318 // System.err.println("Concurrent Exception caught during bottomBorderHit action"); 319 // return false; 320 // } 321 // } 322 323 public void setBottomBorderHitAction(final MagneticConstraintAction action) { 324 bottomBorderHitAction = action; 325 } 104 326 }
Note:
See TracChangeset
for help on using the changeset viewer.