Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Misc.java

    r1079 r1102  
    1919package org.expeditee.actions;
    2020
    21 import java.awt.Color;
    22 import java.awt.Desktop;
    23 import java.awt.Image;
    24 import java.awt.image.BufferedImage;
    25 import java.awt.image.VolatileImage;
    2621import java.io.BufferedReader;
    2722import java.io.File;
     
    3126import java.io.InputStreamReader;
    3227import java.lang.reflect.Method;
    33 import java.net.URI;
    34 import java.net.URISyntaxException;
    3528import java.net.URL;
    3629import java.net.URLClassLoader;
     
    3932import java.util.LinkedList;
    4033import java.util.List;
    41 import java.util.Map;
    4234import java.util.Map.Entry;
    43 import java.util.Set;
    4435import java.util.jar.Attributes;
    4536import java.util.jar.JarFile;
    4637
    47 import javax.imageio.ImageIO;
    48 
     38import org.expeditee.core.Colour;
     39import org.expeditee.core.Image;
     40import org.expeditee.core.Point;
     41import org.expeditee.gio.EcosystemManager;
     42import org.expeditee.gio.gesture.StandardGestureActions;
    4943import org.expeditee.gui.AttributeUtils;
    50 import org.expeditee.gui.Browser;
    5144import org.expeditee.io.Conversion;
    52 import org.expeditee.gui.DisplayIO;
     45import org.expeditee.gui.DisplayController;
    5346import org.expeditee.io.ExpReader;
    5447import org.expeditee.gui.Frame;
    5548import org.expeditee.gui.FrameGraphics;
    5649import org.expeditee.gui.FrameIO;
    57 import org.expeditee.gui.FrameKeyboardActions;
    58 import org.expeditee.gui.FrameMouseActions;
    5950import org.expeditee.gui.FrameUtils;
    6051import org.expeditee.gui.FreeItems;
     
    6354import org.expeditee.gui.Reminders;
    6455import org.expeditee.gui.TimeKeeper;
    65 import org.expeditee.importer.FrameDNDTransferHandler;
    6656import org.expeditee.items.Item;
    6757import org.expeditee.items.ItemUtils;
     
    6959import org.expeditee.items.Text;
    7060import org.expeditee.items.XRayable;
    71 import org.expeditee.items.widgets.InteractiveWidget;
     61import org.expeditee.items.widgets.Widget;
    7262import org.expeditee.items.widgets.WidgetCorner;
    7363import org.expeditee.items.widgets.WidgetEdge;
     
    8373import org.nfunk.jep.ParseException;
    8474
    85 import com.lowagie.text.Font;
    86 
    8775
    8876
    8977/**
    90  * A list of miscellaneous Actions and Actions specific to Expeditee
     78 * A list of miscellaneous Actions specific to Expeditee
    9179 *
    9280 */
     
    9684         * Causes the system to beep
    9785         */
    98         public static void beep() {
    99                 java.awt.Toolkit.getDefaultToolkit().beep();
     86        public static void beep()
     87        {
     88                EcosystemManager.getMiscManager().beep();
    10089        }
    10190       
     
    161150         * Treats a string as a URL and attempts to open it
    162151         */
    163         public static void openURL(String siteURL){
    164                
    165                 try {
    166                         URL check = new URL(siteURL);                   
    167                         Desktop.getDesktop().browse(new URI(siteURL));
    168                        
    169                 } catch (IOException| URISyntaxException e) {
    170                
    171                         MessageBay.displayMessage("'" + siteURL + "' is not a valid URL");
    172                 }               
     152        public static void openURL(String siteURL)
     153        {
     154                boolean success = EcosystemManager.getMiscManager().browse(siteURL);
     155               
     156                if (!success) MessageBay.displayMessage("'" + siteURL + "' is not a valid URL");       
    173157        }
    174158        /**
     
    177161        public static void setRestorePoint()
    178162        {
    179                 Frame current = DisplayIO.getCurrentFrame();
     163                Frame current = DisplayController.getCurrentFrame();
    180164                current.change();
    181165                FrameIO.SaveFrameAsRestore(current, true, true);               
     
    185169         */
    186170        public static void display() {
    187                 FrameGraphics.refresh(false);
     171                DisplayController.requestRefresh(false);
    188172        }
    189173       
    190174        public static String getWindowSize() {
    191                 return Browser.getWindows()[0].getSize().toString();
     175                return EcosystemManager.getGraphicsManager().getWindowSize().toString();
    192176        }
    193177
     
    205189         */
    206190        public static void toggleAudienceMode() {
    207                 FrameGraphics.ToggleAudienceMode();
     191                DisplayController.ToggleAudienceMode();
    208192        }
    209193
     
    212196         */
    213197        public static void toggleTwinFramesMode() {
    214                 DisplayIO.ToggleTwinFrames();
     198                DisplayController.toggleTwinFrames();
    215199        }
    216200
     
    227211                        for (String action : actions) {
    228212                                if (!action.equalsIgnoreCase("runitem")) {
    229                                         Actions.PerformAction(DisplayIO.getCurrentFrame(), current,
     213                                        Actions.PerformAction(DisplayController.getCurrentFrame(), current,
    230214                                                        action);
    231215                                }
     
    249233                        String deletedFrameName = FrameIO.DeleteFrame(toDelete);
    250234                        if (deletedFrameName != null) {
    251                                 DisplayIO.Back();
     235                                DisplayController.Back();
    252236                                // Remove any links on the previous frame to the one being
    253237                                // deleted
    254                                 Frame current = DisplayIO.getCurrentFrame();
     238                                Frame current = DisplayController.getCurrentFrame();
    255239                                for (Item i : current.getItems())
    256240                                        if (i.getLink() != null
     
    312296                        // copy the item and switch
    313297                        item = item.copy();
    314                         item.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
     298                        item.setPosition(DisplayController.getMousePosition());
    315299                }
    316300                return item;
     
    327311                Collection<Item> copies = ItemUtils.CopyItems(items);
    328312                Item first = items.iterator().next();
    329                 float deltaX = DisplayIO.getMouseX() - first.getX();
    330                 float deltaY = FrameMouseActions.getY() - first.getY();
     313                float deltaX = DisplayController.getMouseX() - first.getX();
     314                float deltaY = DisplayController.getMouseY() - first.getY();
    331315                for (Item i : copies) {
    332316                        if (i.isVisible())
     
    334318                        i.setParent(null);
    335319                }
    336                 FrameMouseActions.pickup(copies);
    337                 FrameGraphics.Repaint();
     320                StandardGestureActions.pickup(copies);
     321                DisplayController.requestRefresh(true);
    338322        }
    339323       
     
    347331         *            The Color to give the Item.
    348332         */
    349         public static void SetItemBackgroundColor(Item toChange, Color toUse) {
     333        public static void SetItemBackgroundColor(Item toChange, Colour toUse) {
    350334                if (toChange == null)
    351335                        return;
    352336
    353337                toChange.setBackgroundColor(toUse);
    354                 FrameGraphics.Repaint();
     338                DisplayController.requestRefresh(true);
    355339        }
    356340
     
    364348         *            The Color to give the Item.
    365349         */
    366         public static void SetItemColor(Item toChange, Color toUse) {
     350        public static void SetItemColor(Item toChange, Colour toUse) {
    367351                if (toChange == null)
    368352                        return;
    369353
    370354                toChange.setColor(toUse);
    371                 FrameGraphics.Repaint();
     355                DisplayController.requestRefresh(true);
    372356        }
    373357
     
    428412        public static void attachStatsToCursor(String itemText) {
    429413                SessionStats.CreatedText();
    430                 Frame current = DisplayIO.getCurrentFrame();
     414                Frame current = DisplayController.getCurrentFrame();
    431415                Item text = current.getStatsTextItem(itemText);
    432                 FrameMouseActions.pickup(text);
    433                 FrameGraphics.Repaint();
     416                StandardGestureActions.pickup(text);
     417                DisplayController.requestRefresh(true);
    434418        }
    435419
    436420        public static void attachTextToCursor(String itemText) {
    437421                SessionStats.CreatedText();
    438                 Frame current = DisplayIO.getCurrentFrame();
     422                Frame current = DisplayController.getCurrentFrame();
    439423                Item text = current.getTextItem(itemText);
    440                 FrameMouseActions.pickup(text);
    441                 FrameGraphics.Repaint();
     424                StandardGestureActions.pickup(text);
     425                DisplayController.requestRefresh(true);
    442426        }
    443427       
     
    494478                }
    495479
    496                 for (Entry<String, java.awt.Font> entry: Text.FONT_WHEEL_ADDITIONAL_LOOKUP.entrySet()){
     480                for (Entry<String, org.expeditee.core.Font> entry: Text.FONT_WHEEL_ADDITIONAL_LOOKUP.entrySet()){
    497481                       
    498482                        String fontName = entry.getKey();
     
    585569         */
    586570        public static void jpegFrame() {
    587                 ImageFrame(DisplayIO.getCurrentFrame().getName(), "JPEG");
     571                ImageFrame(DisplayController.getCurrentFrame().getName(), "JPEG");
    588572        }
    589573
     
    610594        }
    611595
    612         public static String SaveImage(BufferedImage screen, String format,
     596        public static String SaveImage(Image screen, String format,
    613597                        String directory, String fileName) {
    614598                String suffix = "." + format.toLowerCase();
     
    633617
    634618                        // If the image is successfully written out return the fileName
    635                         if (ImageIO.write(screen, format, out))
     619                        if (screen.writeToDisk(format, out))
    636620                                return fileName;
    637621
     
    647631                Image oldBuffer = frame.getBuffer();
    648632                frame.setBuffer(null);
    649                 // Jpeg only works properly with volitile frames
     633                // Jpeg only works properly with volatile frames
    650634                // Png transparency only works with bufferedImage form
    651                 Image frameBuffer = FrameGraphics.getBuffer(frame, false, format
    652                                 .equalsIgnoreCase("jpeg"));
    653                 // Make sure overlay stuff doesnt disapear on the frame visible on the
     635                Image frameBuffer = FrameGraphics.getFrameImage(frame, null, null, false, format.equalsIgnoreCase("jpeg"));
     636                // Make sure overlay stuff doesnt disappear on the frame visible on the
    654637                // screen
    655638                frame.setBuffer(oldBuffer);
    656                 BufferedImage screen = null;
    657 
    658                 if (frameBuffer instanceof VolatileImage) {
    659                         // If its the current frame it will be a volitive image
    660                         screen = ((VolatileImage) frameBuffer).getSnapshot();
    661                 } else {
    662                         assert (frameBuffer instanceof BufferedImage);
    663                         screen = (BufferedImage) frameBuffer;
    664                 }
    665                 return SaveImage(screen, format, directory, frame.getExportFileName());
     639               
     640                return SaveImage(frameBuffer, format, directory, frame.getExportFileName());
    666641        }
    667642
     
    842817                current.setActions(null);
    843818
    844                 FrameGraphics.Repaint();
     819                DisplayController.requestRefresh(true);
    845820        }
    846821
     
    932907                                text.setFormula(formulaFullCase);
    933908                                if (text.isFloating()) {
    934                                         text.setPosition(FrameMouseActions.MouseX,
    935                                                         FrameMouseActions.MouseY);
    936                                         FrameMouseActions.resetOffset();
     909                                        Point cursorPos = EcosystemManager.getInputManager().getCursorPosition();
     910                                        text.setPosition(cursorPos.x, cursorPos.y);
     911                                        StandardGestureActions.resetOffset();
    937912                                } else {
    938913                                        text.getParentOrCurrentFrame().change();
     
    956931        public static void attachToCursor(Item item) {
    957932                item.setParent(null);
    958                 FrameMouseActions.pickup(item);
    959                 FrameGraphics.Repaint();
     933                StandardGestureActions.pickup(item);
     934                DisplayController.requestRefresh(true);
    960935        }
    961936
     
    965940                        i.invalidateAll();
    966941                }
    967                 FrameMouseActions.pickup(items);
     942                StandardGestureActions.pickup(items);
    968943                // TODO figure out why this isnt repainting stuff immediately
    969944                // All of text item doesnt repaint until the cursor is moved
    970                 FrameGraphics.requestRefresh(true);
     945                DisplayController.requestRefresh(true);
    971946        }
    972947
     
    980955                }
    981956                try {
    982                         FrameDNDTransferHandler.getInstance().importFileList(files,
    983                                         FrameMouseActions.getPosition());
     957                        EcosystemManager.getDragAndDropManager().importFileList(files, EcosystemManager.getInputManager().getCursorPosition());
    984958                } catch (Exception e) {
    985959                }
     
    990964                if (file.exists()) {
    991965                        try {
    992                                 FrameDNDTransferHandler.getInstance().importFile(file,
    993                                                 FrameMouseActions.getPosition());
     966                                EcosystemManager.getDragAndDropManager().importFile(file, EcosystemManager.getInputManager().getCursorPosition());
    994967                        } catch (Exception e) {
    995968                                e.printStackTrace();
     
    1021994                }
    1022995
    1023                 float curX = FrameMouseActions.MouseX;
    1024                 float curY = FrameMouseActions.MouseY;
     996                Point cursorPos = DisplayController.getMousePosition();
     997                float curX = cursorPos.x;
     998                float curY = cursorPos.y;
    1025999
    10261000                Collection<Item> newItems = new LinkedList<Item>();
    10271001                Item[] d = new Item[sides];
    10281002                // create dots
    1029                 Frame current = DisplayIO.getCurrentFrame();
     1003                Frame current = DisplayController.getCurrentFrame();
    10301004                for (int i = 0; i < d.length; i++) {
    10311005                        d[i] = current.createDot();
     
    10531027                }
    10541028
    1055                 Color newColor = item.getColor();
     1029                Colour newColor = item.getColor();
    10561030                if (newColor != null) {
    10571031                        d[0].setColor(item.getColor());
     
    10681042
    10691043                ItemUtils.EnclosedCheck(newItems);
    1070                 FrameGraphics.refresh(false);
     1044                DisplayController.requestRefresh(false);
    10711045
    10721046                return d[0];
     
    10771051        }
    10781052
    1079         public static void print(String file) {
    1080                 try {
    1081                         if (Browser._theBrowser.isMinimumVersion6()) {
    1082                                 if (Desktop.isDesktopSupported()) {
    1083                                         Desktop.getDesktop().print(new File(file));
    1084                                 }
    1085                         }
    1086                 } catch (Exception e) {
    1087                         MessageBay.errorMessage("Printing error: " + e.getMessage());
    1088                 }
     1053        public static void print(String file)
     1054        {       
     1055                String errorMessage = EcosystemManager.getMiscManager().print(file);
     1056               
     1057                if (errorMessage != null) MessageBay.errorMessage("Printing error: " + errorMessage);
    10891058        }
    10901059
     
    11291098         * @throws Exception
    11301099         */
    1131         public static void startLoboBrowser(Item text) throws Exception {
     1100/*      public static void startLoboBrowser(Item text) throws Exception {
    11321101                if (!(text instanceof Text)) {
    11331102                        MessageBay.errorMessage("Must be a text item.");
     
    11541123                       
    11551124                FrameMouseActions.pickup(browser.getItems());                                   // attach browser widget to mouse
    1156         }
     1125        }*/
    11571126       
    11581127        /**
     
    11611130         * @throws Exception
    11621131         */
    1163         public static void startLoboBrowserNewFrame(Item text) throws Exception {
     1132        public static void startLoboBrowserNewFrame(Item text) throws Exception
     1133        {
    11641134                if (!(text instanceof Text)) {
    11651135                        MessageBay.errorMessage("Must be a text item.");
    11661136                        return;
    11671137                }
     1138               
    11681139                if(text.getLink() != null) {                                                                                    // text item can't already have a link
    11691140                        MessageBay.errorMessage("Text item already has link.");
     
    11761147                FrameUtils.Parse(frame);
    11771148               
    1178                 for(InteractiveWidget iw : frame.getInteractiveWidgets()) {     // may be other widgets on frame
     1149                for(Widget iw : frame.getInteractiveWidgets()) {        // may be other widgets on frame
    11791150                        if(iw instanceof org.expeditee.items.widgets.Browser) {
    11801151                                // Set browser to 'full screen'
    1181                                 iw.setSize(-1, -1, -1, -1, Browser._theBrowser.getWidth(), Browser._theBrowser.getHeight()
    1182                                                 - MessageBay.MESSAGE_BUFFER_HEIGHT - 80);
     1152                                iw.setSize(-1, -1, -1, -1, DisplayController.getFramePaintArea().getWidth(), DisplayController.getFramePaintArea().getHeight() - 80);
    11831153                               
    11841154                                // If there is a text item attached to cursor use it as url for browser
    1185                                 if(FreeItems.textOnlyAttachedToCursor()) {
     1155                                if (FreeItems.textOnlyAttachedToCursor()) {
    11861156                                        text.setLink("" + frame.getNumber());
    11871157                                        ((org.expeditee.items.widgets.Browser)iw).navigate(text.getText());
     
    11901160                                        ((org.expeditee.items.widgets.Browser)iw).navigate("http://www.waikato.ac.nz");
    11911161                                        Text t = new Text("http://www.waikato.ac.nz");
    1192                                         t.setParent(DisplayIO.getCurrentFrame());               // set parent of text source for InteractiveWidget.createWidget()
    1193                                         t.setXY(FrameMouseActions.getX(), FrameMouseActions.getY());
     1162                                        t.setParent(DisplayController.getCurrentFrame());               // set parent of text source for InteractiveWidget.createWidget()
     1163                                        t.setXY(DisplayController.getFloatMouseX(), DisplayController.getFloatMouseY());
    11941164                                        t.setLink("" + frame.getNumber());                              // link url text to new browser frame
    1195                                         FrameMouseActions.pickup(t);                                    // Attach new text link to cursor
     1165                                        StandardGestureActions.pickup(t);                                       // Attach new text link to cursor
    11961166                                }
    11971167                        }
     
    12011171        }
    12021172       
    1203         private static boolean startWidget(String name) throws Exception {
     1173        private static boolean startWidget(String name) throws Exception
     1174        {
    12041175                String fullName = Actions.getClassName(name);
    12051176                if(fullName == null) {
     
    12101181                FreeItems.getInstance().clear();
    12111182                Text wt = new Text("@iw:" + fullName);                                                  // create new text item for browser widget
    1212                 wt.setParent(DisplayIO.getCurrentFrame());                                              // set parent of text source for InteractiveWidget.createWidget()
    1213                 wt.setXY(FrameMouseActions.getX(), FrameMouseActions.getY());   // move to the mouse cursor
    1214                 InteractiveWidget widget = InteractiveWidget.createWidget(wt);
    1215                 FrameMouseActions.pickup(widget.getItems());
     1183                wt.setParent(DisplayController.getCurrentFrame());                                              // set parent of text source for InteractiveWidget.createWidget()
     1184                wt.setXY(DisplayController.getMouseX(), DisplayController.getMouseY()); // move to the mouse cursor
     1185                Widget widget = Widget.createWidget(wt);
     1186                StandardGestureActions.pickup(widget.getItems());
    12161187               
    12171188                return true;
     
    12231194                }
    12241195               
    1225                 Actions.PerformAction(DisplayIO.getCurrentFrame(), null, command);
     1196                Actions.PerformAction(DisplayController.getCurrentFrame(), null, command);
    12261197        }
    12271198       
     
    12411212                if(name == "action" || name == "agent") {
    12421213                        if(args.length() > 0) {
    1243                                 Actions.PerformAction(DisplayIO.getCurrentFrame(), null, args);
     1214                                Actions.PerformAction(DisplayController.getCurrentFrame(), null, args);
    12441215                        } else {
    12451216                                MessageBay.displayMessage("Please specify an action/agent name");
     
    13241295                        if (i instanceof WidgetEdge || i instanceof WidgetCorner) {
    13251296                                continue;
    1326                         }
    1327                         else {
     1297                        } else {
    13281298                                int new_x = i.getX();
    13291299                                int new_y = i.getY();
     
    13451315                        }
    13461316                        // update the polygon, otherwise stuff moves but leaves it's outline behind
    1347                         i.updatePolygon();
    1348                 }
    1349 
    1350                 for (InteractiveWidget iw : frame.getInteractiveWidgets()) {
     1317                        i.invalidateBounds();
     1318                }
     1319
     1320                for (Widget iw : frame.getInteractiveWidgets()) {
    13511321
    13521322                        int new_x = iw.getX();
     
    13681338                frame.change();
    13691339                // redraw everything
    1370                 FrameKeyboardActions.Refresh();
     1340                StandardGestureActions.Refresh();
    13711341        }
    13721342       
     
    15051475    public static void GitPushFrame() {
    15061476
    1507         FrameKeyboardActions.Save();
    1508        
    1509         Frame current = DisplayIO.getCurrentFrame();
     1477        StandardGestureActions.Save();
     1478       
     1479        Frame current = DisplayController.getCurrentFrame();
    15101480        String userName = UserSettings.ProfileName.get();
    15111481
     
    15441514
    15451515    public static void GitPullFrame() {
    1546         Frame current = DisplayIO.getCurrentFrame();
     1516        Frame current = DisplayController.getCurrentFrame();
    15471517
    15481518        List<String> cmd_array = new ArrayList<String>();
     
    15541524       
    15551525        FrameIO.Reload();
    1556         FrameKeyboardActions.Refresh();
     1526        StandardGestureActions.Refresh();
    15571527    }
    15581528
Note: See TracChangeset for help on using the changeset viewer.