Changeset 574 for trunk/src/org/expeditee/actions/Misc.java
- Timestamp:
- 12/05/13 16:55:01 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Misc.java
r573 r574 4 4 import java.awt.Desktop; 5 5 import java.awt.Image; 6 import java.awt.Polygon; 6 7 import java.awt.image.BufferedImage; 7 8 import java.awt.image.VolatileImage; … … 9 10 import java.io.FileNotFoundException; 10 11 import java.io.IOException; 12 import java.io.StringWriter; 13 import java.io.Writer; 11 14 import java.lang.reflect.Method; 12 15 import java.util.ArrayList; … … 16 19 17 20 import javax.imageio.ImageIO; 21 import javax.script.ScriptEngine; 22 import javax.script.ScriptEngineManager; 18 23 19 24 import org.expeditee.gui.AttributeUtils; … … 30 35 import org.expeditee.gui.TimeKeeper; 31 36 import org.expeditee.importer.FrameDNDTransferHandler; 37 import org.expeditee.io.JavaWriter; 32 38 import org.expeditee.items.Item; 33 39 import org.expeditee.items.ItemUtils; … … 1186 1192 1187 1193 public static void run(String command) throws Exception { 1194 if(command == null) { 1195 MessageBay.warningMessage("Please provide a command to run"); 1196 return; 1197 } 1188 1198 int firstSpace = command.indexOf(" "); 1189 1199 if(firstSpace == -1) { … … 1214 1224 1215 1225 public static void run(Item item) throws Exception { 1226 if(item == null) { 1227 MessageBay.warningMessage("Please provide a command to run"); 1228 return; 1229 } 1216 1230 run(((Text)item).getText()); 1217 1231 } 1232 1233 // Javascript stuff. Probably completely pointless since there is already a Javascript class, 1234 // but I couldn't get the existing Javascript engine to work for some reason 1235 private static ScriptEngineManager sem = new ScriptEngineManager(); 1236 private static ScriptEngine se = sem.getEngineByMimeType("application/javascript"); 1237 1238 private static String getScript(Frame frame) throws Exception { 1239 Writer writer = new StringWriter(); 1240 JavaWriter jw = new JavaWriter(); 1241 jw.writeFrame(frame, writer); 1242 writer.flush(); 1243 String script = writer.toString(); 1244 writer.close(); 1245 return script; 1246 } 1247 1248 public static void runJSFrame(Frame frame) throws Exception { 1249 se.eval(getScript(frame)); 1250 } 1251 1252 public static void runJSItem(Item item) throws Exception { 1253 // if the user clicked on the action without an item on their cursor 1254 if(item.hasAction()) { 1255 for(String s : item.getAction()) { 1256 if(!s.equalsIgnoreCase("runJSItem")) { 1257 return; 1258 } 1259 } 1260 1261 // Check if there is an arrow pointing from the action to a link 1262 // Seemed like a cool idea before I made it, but the arrows kind of get in the way when trying to click on the action 1263 Collection<Item> itemsWithin = item.getParentOrCurrentFrame().getItemsWithin(item.getPolygon()); 1264 for(Item i : itemsWithin) { 1265 if(i instanceof Line && itemsWithin.contains(((Line)i).getStartItem())) { 1266 Polygon p = ((Line)i).getEndItem().getPolygon(); 1267 for(Item j : ((Line)i).getEndItem().getParent().getAllItems()) { 1268 if(p.intersects(j.getArea().getBounds2D()) && j instanceof Text && j.hasLink()) { 1269 Frame child = j.getChild(); 1270 if(child == null) { 1271 continue; 1272 } 1273 runJSFrame(child); 1274 return; 1275 } 1276 } 1277 } 1278 } 1279 1280 runJSFrame(item.getParentOrCurrentFrame()); 1281 return; 1282 } 1283 Frame frame = item.getChild(); 1284 if(frame == null) { 1285 frame = FrameIO.CreateNewFrame(item); 1286 item.setLink("" + frame.getNumber()); 1287 frame.addText(100, 100, "print(\"test\");", null); 1288 FrameIO.SaveFrame(frame); 1289 } else { 1290 se.eval(getScript(frame)); 1291 } 1292 } 1218 1293 }
Note:
See TracChangeset
for help on using the changeset viewer.