Ignore:
Timestamp:
08/01/08 16:38:58 (16 years ago)
Author:
ra33
Message:

Work on Bridging the Gap between SimpleStatements and Actions/Agents

File:
1 edited

Legend:

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

    r176 r181  
    99import java.io.IOException;
    1010import java.lang.reflect.Method;
    11 import java.text.NumberFormat;
    1211import java.util.ArrayList;
    1312import java.util.Collection;
    1413import java.util.List;
    15 import java.util.Observable;
    16 import java.util.Observer;
    1714
    1815import javax.imageio.ImageIO;
    1916
    20 import org.expeditee.gui.AttributeUtils;
    21 import org.expeditee.gui.AttributeValuePair;
    2217import org.expeditee.gui.DisplayIO;
    2318import org.expeditee.gui.Frame;
     
    2520import org.expeditee.gui.FrameIO;
    2621import org.expeditee.gui.FrameMouseActions;
    27 import org.expeditee.gui.FrameUtils;
    2822import org.expeditee.gui.MessageBay;
    2923import org.expeditee.gui.TimeKeeper;
     
    3731import org.expeditee.stats.TreeStats;
    3832import org.nfunk.jep.Node;
    39 import org.nfunk.jep.Variable;
    4033
    4134/**
     
    4740         * Causes the system to beep
    4841         */
    49         public static void Beep() {
     42        public static void beep() {
    5043                java.awt.Toolkit.getDefaultToolkit().beep();
    5144        }
     
    5447         * Forces a repaint of the current Frame
    5548         */
    56         public static void Display() {
    57                 FrameGraphics.ForceRepaint();
     49        public static void display() {
     50                FrameGraphics.refresh(false);
    5851        }
    5952
     
    6255         * hard disk
    6356         */
    64         public static void Restore() {
     57        public static void restore() {
    6558                FrameIO.Reload();
    6659                // MessageBay.displayMessage("Restoration complete.");
     
    7063         * Toggles AudienceMode on or off
    7164         */
    72         public static void ToggleAudienceMode() {
     65        public static void toggleAudienceMode() {
    7366                FrameGraphics.ToggleAudienceMode();
    7467        }
     
    7770         * Toggles TwinFrames mode on or off
    7871         */
    79         public static void ToggleTwinFramesMode() {
     72        public static void toggleTwinFramesMode() {
    8073                DisplayIO.ToggleTwinFrames();
    8174        }
     
    8881         *            The Item to read the Actions from
    8982         */
    90         public static void RunCurrentItem(Item current) {
     83        public static void runItem(Item current) throws Exception {
    9184                if (current instanceof Text) {
    9285                        List<String> actions = ((Text) current).getTextList();
    9386                        for (String action : actions) {
    94                                 if (!action.equalsIgnoreCase("runcurrentitem")) {
     87                                if (!action.equalsIgnoreCase("runitem")) {
    9588                                        Actions.PerformAction(DisplayIO.getCurrentFrame(), current,
    9689                                                        action);
     
    152145         *            from.
    153146         */
    154         public static void GetItemFromChildFrame(Item current) {
    155                 getFromChildFrame(current, false);
     147        public static Item GetItemFromChildFrame(Item current) {
     148                return getFromChildFrame(current, false);
    156149        }
    157150
     
    169162         *            from.
    170163         */
    171         public static void GetTextFromChildFrame(Item current) {
    172                 getFromChildFrame(current, true);
    173         }
    174 
    175         private static void getFromChildFrame(Item current, boolean textOnly) {
     164        public static Item GetTextFromChildFrame(Item current) {
     165                return getFromChildFrame(current, true);
     166        }
     167
     168        private static Item getFromChildFrame(Item current, boolean textOnly) {
    176169                Item item = getFirstBodyItemOnChildFrame(current, textOnly);
    177170                // if no item was found
    178                 if (item == null) {
    179                         return;
    180                 }
    181 
    182                 // copy the item and switch
    183                 item = item.copy();
    184                 item.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
    185                 item.setParent(null);
    186                 FrameMouseActions.pickup(item);
    187                 FrameGraphics.Repaint();
     171                if (item != null) {
     172                        // copy the item and switch
     173                        item = item.copy();
     174                        item.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());
     175                }
     176                return item;
    188177        }
    189178
     
    218207         *            The Color to give the Item.
    219208         */
    220         public static void SetCurrentItemBackgroundColor(Item toChange, Color toUse) {
     209        public static void SetItemBackgroundColor(Item toChange, Color toUse) {
    221210                if (toChange == null)
    222211                        return;
     
    235224         *            The Color to give the Item.
    236225         */
    237         public static void SetCurrentItemColor(Item toChange, Color toUse) {
     226        public static void SetItemColor(Item toChange, Color toUse) {
    238227                if (toChange == null)
    239228                        return;
     
    255244         * Creates a new Text Object containing statistics for the current tree.
    256245         */
    257         public static void GetCometStats(Frame frame) {
     246        public static String GetCometStats(Frame frame) {
    258247                TimeKeeper timer = new TimeKeeper();
    259248                MessageBay.displayMessage("Computing comet stats...");
    260 
    261249                CometStats cometStats = new CometStats(frame);
    262                 attachStatsToCursor(cometStats.toString());
     250                String result = cometStats.toString();
    263251                MessageBay.overwriteMessage("Comet stats time: "
    264252                                + timer.getElapsedStringSeconds());
    265         }
    266 
    267         public static void GetTreeStats(Frame frame) {
     253                return result;
     254        }
     255
     256        public static String GetTreeStats(Frame frame) {
    268257                TimeKeeper timer = new TimeKeeper();
    269258                MessageBay.displayMessage("Computing tree stats...");
    270259
    271260                TreeStats treeStats = new TreeStats(frame);
    272                 attachStatsToCursor(treeStats.toString());
     261                String result = treeStats.toString();
    273262                MessageBay.overwriteMessage("Tree stats time: "
    274263                                + timer.getElapsedStringSeconds());
     264                return result;
     265
    275266        }
    276267
     
    302293         * then attached to the cursor via FrameMouseActions.pickup(Item)
    303294         */
    304         public static void GetItemStats() {
    305                 attachStatsToCursor(SessionStats.getItemStats());
     295        public static String getItemStats() {
     296                return SessionStats.getItemStats();
    306297        }
    307298
     
    312303         * FrameMouseActions.pickup(Item)
    313304         */
    314         public static void GetEventStats() {
    315                 attachStatsToCursor(SessionStats.getEventStats());
     305        public static String getEventStats() {
     306                return SessionStats.getEventStats();
    316307        }
    317308
     
    320311         * file.
    321312         */
    322         public static void GetCurrentFrameFile() {
    323                 Frame current = DisplayIO.getCurrentFrame();
    324                 attachStatsToCursor(FrameIO.ForceSaveFrame(current));
     313        public static String getFrameFile(Frame frame) {
     314                return FrameIO.ForceSaveFrame(frame);
    325315        }
    326316
     
    328318         * Creates a new Text Object containing the available fonts.
    329319         */
    330         public static void getFontNames() {
    331 
     320        public static String getFontNames() {
    332321                Collection<String> availableFonts = Actions.getFonts().values();
    333322                StringBuilder fontsList = new StringBuilder();
     
    337326                fontsList.deleteCharAt(fontsList.length() - 1);
    338327
    339                 attachStatsToCursor(fontsList.toString());
    340         }
    341 
    342         public static void getUnicodeCharacters(int start, int finish) {
     328                return fontsList.toString();
     329        }
     330
     331        public static String getUnicodeCharacters(int start, int finish) {
    343332                if (start < 0 && finish < 0) {
    344333                        throw new RuntimeException("Parameters must be non negative");
     
    364353                        }
    365354                }
    366                 attachTextToCursor(charList.toString());
     355                return charList.toString();
    367356        }
    368357
     
    373362         *            the start of the block
    374363         */
    375         public static void getUnicodeCharacters(int start) {
    376                 getUnicodeCharacters(start, start + 256);
    377         }
    378 
    379         public static void getMathSymbols() {
    380                 getUnicodeCharacters('\u2200', '\u2300');
     364        public static String getUnicodeCharacters(int start) {
     365                return getUnicodeCharacters(start, start + 256);
     366        }
     367
     368        public static String getMathSymbols() {
     369                return getUnicodeCharacters('\u2200', '\u2300');
    381370        }
    382371
     
    384373         * Resets the statistics back to zero.
    385374         */
    386         public static void ResetStats() {
     375        public static void repaint() {
    387376                StatsLogger.WriteStatsFile();
    388377                SessionStats.resetStats();
     
    395384         *            The name of the Frame to save
    396385         */
    397         public static void JpegFrame(String framename) {
     386        public static void jpegFrame(String framename) {
    398387                ImageFrame(framename, "JPEG");
    399388        }
     
    403392         * JpegFrame(currentFrame.getName())
    404393         */
    405         public static void JpegFrame() {
     394        public static void jpegFrame() {
    406395                ImageFrame(DisplayIO.getCurrentFrame().getName(), "JPEG");
    407396        }
    408397
    409         public static void JPGFrame() {
    410                 JpegFrame();
     398        public static void jpgFrame() {
     399                jpegFrame();
    411400        }
    412401
     
    455444                assert (frame != null);
    456445
    457                 FrameGraphics.UpdateBuffer(frame, false);
    458 
     446                Image oldBuffer = frame.getBuffer();
     447                frame.setBuffer(null);
     448                // Jpeg only works properly with volitile frames
     449                // Png transparency only works with bufferedImage form
     450                Image frameBuffer = FrameGraphics.getBuffer(frame, false, format
     451                                .equalsIgnoreCase("jpeg"));
     452                // Make sure overlay stuff doesnt disapear on the frame visible on the
     453                // screen
     454                frame.setBuffer(oldBuffer);
    459455                BufferedImage screen = null;
    460                 Image frameBuffer = frame.getBuffer();
    461                 if (frame.getBuffer() instanceof BufferedImage) {
    462                         screen = (BufferedImage) frameBuffer;
    463                 } else if (frameBuffer instanceof VolatileImage) {
     456
     457                if (frameBuffer instanceof VolatileImage) {
     458                        // If its the current frame it will be a volitive image
    464459                        screen = ((VolatileImage) frameBuffer).getSnapshot();
    465460                } else {
    466                         assert (false);
     461                        assert (frameBuffer instanceof BufferedImage);
     462                        screen = (BufferedImage) frameBuffer;
    467463                }
    468464                return SaveImage(screen, format, directory, frame.getExportFileName());
     
    491487                                                + format + " format");
    492488                        // if the frame was not loaded successfully, alert the user
    493                 } else
     489                } else {
    494490                        MessageBay.displayMessage("Frame '" + framename
    495491                                        + "' could not be found.");
     492                }
    496493        }
    497494
     
    744741                }
    745742        }
     743
     744        /**
     745         * Attach an item to the cursor.
     746         *
     747         * @param item
     748         */
     749        public static void attachToCursor(Item item) {
     750                item.setParent(null);
     751                FrameMouseActions.pickup(item);
     752                FrameGraphics.Repaint();
     753        }
    746754}
Note: See TracChangeset for help on using the changeset viewer.