- Timestamp:
- 11/21/13 14:36:24 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Misc.java
r504 r514 24 24 import org.expeditee.gui.FrameIO; 25 25 import org.expeditee.gui.FrameMouseActions; 26 import org.expeditee.gui.FrameUtils; 27 import org.expeditee.gui.FreeItems; 26 28 import org.expeditee.gui.MessageBay; 27 29 import org.expeditee.gui.Reminders; 28 30 import org.expeditee.gui.TimeKeeper; 29 31 import org.expeditee.importer.FrameDNDTransferHandler; 32 import org.expeditee.io.ExpClipReader; 30 33 import org.expeditee.items.Item; 31 34 import org.expeditee.items.ItemUtils; 32 35 import org.expeditee.items.Line; 33 36 import org.expeditee.items.Text; 37 import org.expeditee.items.widgets.InteractiveWidget; 34 38 import org.expeditee.math.ExpediteeJEP; 35 39 import org.expeditee.simple.SString; … … 1009 1013 return AttributeUtils.getAttribute(item, attribute); 1010 1014 } 1015 1016 /** 1017 * Launches items.widgets.Browser and uses Text item as URL. 1018 * @param text Text item which passes contents as URL for browser. 1019 * @throws Exception 1020 */ 1021 public static void startBrowser(Item text) throws Exception { 1022 if (text instanceof Text) { 1023 FreeItems.getInstance().clear(); // remove url text from cursor 1024 1025 Text wt = new Text("@iw:org.expeditee.items.widgets.Browser"); // create new text item for browser widget 1026 wt.setParent(DisplayIO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget() 1027 wt.setXY(FrameMouseActions.getX(), FrameMouseActions.getY()); 1028 // create widget from text item 1029 org.expeditee.items.widgets.Browser browser = (org.expeditee.items.widgets.Browser) InteractiveWidget.createWidget(wt); 1030 1031 if(FreeItems.textOnlyAttachedToCursor()) { // navigates to url specified by the text item 1032 browser.navigate(text.getText()); 1033 } else { 1034 browser.navigate("http://www.waikato.ac.nz"); 1035 } 1036 1037 FrameMouseActions.pickup(browser.getItems()); // attach browser widget to mouse 1038 } else { 1039 MessageBay.errorMessage("Must be a text item."); 1040 } 1041 } 1042 1043 /** 1044 * Text item becomes link to new frame containing items.widgets.Browser and uses Text item as URL for browser. 1045 * @param text Text item which passes contents as URL for browser and becomes link to the browser's new frame. 1046 * @throws Exception 1047 */ 1048 public static void startBrowserNewFrame(Item text) throws Exception { 1049 System.out.println("test"); 1050 if (!(text instanceof Text)) { 1051 MessageBay.errorMessage("Must be a text item."); 1052 return; 1053 } 1054 if(text.getLink() != null) { // text item can't already have a link 1055 MessageBay.errorMessage("Text item already has link."); 1056 return; 1057 } 1058 1059 Frame frame = FrameIO.CreateNewFrame(text); // create new frame for browser 1060 frame.addText(50, 50, "@iw:org.expeditee.items.widgets.Browser", null); // create new text item for browser widget 1061 FrameUtils.Parse(frame); // parse created frame; loads browser widget 1062 1063 for(InteractiveWidget iw : frame.getInteractiveWidgets()) { // may be other widgets on frame 1064 if(iw instanceof org.expeditee.items.widgets.Browser) { 1065 // If there is a text item attached to cursor use it as url for browser 1066 if(FreeItems.textOnlyAttachedToCursor()) { 1067 text.setLink("" + frame.getNumber()); 1068 ((org.expeditee.items.widgets.Browser)iw).navigate(text.getText()); 1069 } else { 1070 // Navigate to www.waikato.ac.nz by default if no url supplied and create new text item to be the link 1071 ((org.expeditee.items.widgets.Browser)iw).navigate("http://www.waikato.ac.nz"); 1072 Text t = new Text("http://www.waikato.ac.nz"); 1073 t.setParent(DisplayIO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget() 1074 t.setXY(FrameMouseActions.getX(), FrameMouseActions.getY()); 1075 t.setLink("" + frame.getNumber()); // link url text to new browser frame 1076 FrameMouseActions.pickup(t); // Attach new text link to cursor 1077 } 1078 } 1079 } 1080 1081 FrameIO.SaveFrame(frame); // save frame to disk 1082 } 1011 1083 }
Note:
See TracChangeset
for help on using the changeset viewer.