Ignore:
Timestamp:
11/02/08 13:05:01 (16 years ago)
Author:
ra33
Message:
 
File:
1 edited

Legend:

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

    r362 r376  
    1717import javax.imageio.ImageIO;
    1818
    19 import org.expeditee.agents.wordprocessing.JSpellChecker;
     19import org.expeditee.gui.AttributeUtils;
    2020import org.expeditee.gui.Browser;
    2121import org.expeditee.gui.DisplayIO;
     
    3535import org.expeditee.simple.SString;
    3636import org.expeditee.stats.CometStats;
    37 import org.expeditee.stats.DocumentStats;
     37import org.expeditee.stats.DocumentStatsFast;
    3838import org.expeditee.stats.SessionStats;
    3939import org.expeditee.stats.StatsLogger;
     
    274274
    275275        }
    276        
     276
    277277        public static String GetDocumentStats(Frame frame) {
    278278                TimeKeeper timer = new TimeKeeper();
    279279                MessageBay.displayMessage("Computing document stats...");
    280 
    281                 DocumentStats docStats = new DocumentStats(frame);
     280                FrameIO.ForceSaveFrame(frame);
     281                DocumentStatsFast docStats = new DocumentStatsFast(frame.getName(),
     282                                frame.getTitle());
    282283                String result = docStats.toString();
    283                
     284
    284285                MessageBay.overwriteMessage("Document stats time: "
    285286                                + timer.getElapsedStringSeconds());
     
    436437         * PNGFrame(currentFrame.getName())
    437438         */
    438         public static void PNGFrame() {
    439                 ImageFrame(DisplayIO.getCurrentFrame().getName(), "PNG");
     439        public static void PNGFrame(Frame frame) {
     440                ImageFrame(frame.getName(), "PNG");
    440441        }
    441442
    442443        public static String SaveImage(BufferedImage screen, String format,
    443444                        String directory, String fileName) {
     445                String suffix = "." + format.toLowerCase();
     446                String shortFileName = fileName;
    444447                // Check if we need to append the suffix
    445448                if (fileName.indexOf('.') < 0)
    446                         fileName += "." + format.toLowerCase();
     449                        fileName += suffix;
     450                else
     451                        shortFileName = fileName.substring(0, fileName.length() - suffix.length());
    447452
    448453                try {
     454                        int count = 2;
    449455                        // set up the file for output
    450                         String fullFileName = directory + fileName;
    451                         File out = new File(fullFileName);
     456                        File out = new File(directory + fileName);
     457                        while (out.exists()) {
     458                                fileName = shortFileName + "_" + count++ + suffix;
     459                                out = new File(directory + fileName);
     460                        }
     461
    452462                        if (!out.getParentFile().exists())
    453463                                out.mkdirs();
     
    910920        }
    911921
    912         public static String checkSpelling(String word) {
    913                 try {
    914                         return JSpellChecker.getInstance().getSuggestions(word);
    915                 } catch (FileNotFoundException e) {
    916                         MessageBay.errorMessage("Could not find dictionary: "
    917                                         + e.getMessage());
    918                 } catch (IOException e) {
    919                         // TODO Auto-generated catch block
    920                         e.printStackTrace();
    921                 }
    922                 return null;
    923         }
    924        
    925         public static String spellCheck(String word) {
    926                 return checkSpelling(word);
    927         }
    928        
    929922        public static int wordCount(String paragraph) {
    930923                return paragraph.trim().split("\\s+").length + 1;
    931924        }
    932        
     925
    933926        public static int wordCount(Frame frame) {
    934927                int count = 0;
    935                
    936                 for(Text t: frame.getBodyTextItems(false)){
     928
     929                for (Text t : frame.getBodyTextItems(false)) {
    937930                        count += wordCount(t.getText());
    938931                }
    939                
     932
    940933                return count;
    941934        }
    942        
    943         public static void moveToPublic(Frame frame){
     935
     936        public static void moveToPublic(Frame frame) {
    944937                FrameIO.moveFrameset(frame.getFramesetName(), FrameIO.PUBLIC_PATH);
    945938        }
    946        
    947         public static void moveToPrivate(Frame frame){
     939
     940        public static void moveToPrivate(Frame frame) {
    948941                FrameIO.moveFrameset(frame.getFramesetName(), FrameIO.FRAME_PATH);
    949942        }
     943
     944        /**
     945         * Returns the value of a specified item attribute.
     946         *
     947         * @param item
     948         *            from which to extract the value
     949         * @param attribute
     950         *            name of an items attribute
     951         * @return the value of the attribute
     952         */
     953        public static String extract(Item item, String attribute) {
     954                return AttributeUtils.getAttribute(item, attribute);
     955        }
    950956}
Note: See TracChangeset for help on using the changeset viewer.