Changeset 689


Ignore:
Timestamp:
01/13/14 17:01:03 (10 years ago)
Author:
jts21
Message:

Added progress bar, rewrote some of MessageBay

Location:
trunk/src/org/expeditee
Files:
3 edited

Legend:

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

    r668 r689  
    3737import org.expeditee.gui.FreeItems;
    3838import org.expeditee.gui.MessageBay;
     39import org.expeditee.gui.MessageBay.Progress;
    3940import org.expeditee.gui.Reminders;
    4041import org.expeditee.gui.TimeKeeper;
     
    15761577                FrameIO.SaveFrame(frame);
    15771578        }
     1579       
     1580        public static void testProgress() {
     1581                new Thread(new Runnable() {
     1582
     1583                        @Override
     1584            public void run() {
     1585                                Progress p = MessageBay.displayProgress("Loading something");
     1586                                for(int i = 1; i <= 100; i++) {
     1587                                try {
     1588                        Thread.sleep(100);
     1589                        p.set(i);
     1590                    } catch (Exception e) {
     1591                        e.printStackTrace();
     1592                    }
     1593                                }
     1594            }
     1595                       
     1596                }).start();
     1597        }
    15781598}
  • trunk/src/org/expeditee/gui/FrameIO.java

    r655 r689  
    139139                // do not display errors encountered to the user
    140140                // (they will be shown at load time)
    141                 MessageBay.supressMessages(true);
     141                MessageBay.suppressMessages(true);
    142142                // loading automatically caches the frame is caching is turned on
    143143                LoadFromDisk(framename, null, false);
    144                 MessageBay.supressMessages(false);
     144                MessageBay.suppressMessages(false);
    145145        }
    146146
  • trunk/src/org/expeditee/gui/MessageBay.java

    r678 r689  
    3636
    3737        // messages shown in the message window
    38         private static Text[] _messages = new Text[3];
     38        private static List<Item> _messages = new LinkedList<Item>();
    3939        private static Text _status = null;
    4040
     
    5252
    5353        // if true, error messages are not shown to the user
    54         private static boolean _supressMessages = false;
     54        private static boolean _suppressMessages = false;
    5555
    5656        // The link to the message frameset
     
    7373                _messageBuffer = null;
    7474
    75                 for (int i = 0; i < _messages.length; i++) {
    76                         if (_messages[i] != null) {
    77                                 _messages[i].setOffset(0,
    78                                                 -FrameGraphics.getMaxFrameSize().height);
    79                                 // _messages[i].setMaxWidth(FrameGraphics.getMaxFrameSize().width);
     75                for(Item i : _messages) {
     76                        if(i != null) {
     77                                i.setOffset(0, -FrameGraphics.getMaxFrameSize().height);
     78                                // i.setMaxWidth(FrameGraphics.getMaxFrameSize().width);
    8079                        }
    8180                }
     
    9493         */
    9594        public static boolean isMessageItem(Item i) {
    96                 if (_messages != null) {
    97                         for (Text txt : _messages) {
    98                                 if (txt == i)
    99                                         return true;
    100                         }
    101                 }
    102 
    103                 return i == _messageLink;
     95               
     96                return _messages.contains(i) || i == _messageLink;
    10497        }
    10598
     
    118111        }
    119112
    120         public synchronized static Text[] getMessages() {
     113        public synchronized static List<Item> getMessages() {
    121114                return _messages;
    122115        }
     
    184177                        Graphics g, Color background) {
    185178
     179                if(g == null)
     180                        return;
     181               
    186182                if (FrameGraphics.getMaxSize().width <= 0)
    187183                        return;
     
    217213                        // g.setClip(clip);
    218214
    219                         g.drawImage(_messageBuffer, 0,
    220                                         FrameGraphics.getMaxFrameSize().height, null);
     215                        g.drawImage(_messageBuffer, 0, FrameGraphics.getMaxFrameSize().height, null);
    221216                }
    222217
     
    270265                return displayMessage(message, link, actions, color, displayAlways);
    271266        }
    272 
    273         public synchronized static Text displayMessage(String message, String link,
    274                         List<String> actions, Color color, boolean displayAlways) {
    275 
     267       
     268        private static Text newMessage(String message, String link, List<String> actions, Color color) {
     269                Text t = new Text(getMessagePrefix(true) + message);
     270                t.setPosition(20, 15 + _messages.size() * 25);
     271                t.setOffset(0, -FrameGraphics.getMaxFrameSize().height);
     272                t.setColor(color);
     273                t.setLink(link);
     274                t.setActions(actions);
     275                t.setFont(_messageFont);
     276                _creator.addItem(t.copy(), true);
     277                if(link == null) t.setLink(_creator.getCurrent());
     278                return t;
     279        }
     280       
     281        private synchronized static Text displayMessage(String message, String link,
     282                        List<String> actions, Color color, boolean displayAlways, boolean redraw) {
    276283                System.out.println(message);
    277284                assert (message != null);
     
    280287                invalidateFullBay();
    281288
    282                 if (_supressMessages)
     289                if (_suppressMessages)
    283290                        return null;
    284291
     
    297304                updateLink();
    298305
    299                 // if the message slots have not all been used yet
    300                 if (_messageCount <= _messages.length) {
    301                         int pos = 15;
    302                         // find the next empty slot, and create the new message
    303                         for (int i = 0; i < _messages.length; i++) {
    304                                 if (_messages[i] == null) {
    305                                         _messages[i] = new Text(getMessagePrefix(true) + message);
    306                                         _messages[i].setPosition(20, pos);
    307                                         _messages[i].setOffset(0,
    308                                                         -FrameGraphics.getMaxFrameSize().height);
    309                                         // _messages[i].setMaxWidth(FrameGraphics.getMaxFrameSize().width);
    310                                         _messages[i].setColor(color);
    311                                         _messages[i].setLink(link);
    312                                         _messages[i].setActions(actions);
    313                                         _messages[i].setFont(_messageFont);
    314                                         _creator.addItem(_messages[i].copy(), true);
    315                                         _messageLink.setLink(_creator.getCurrent());
    316 
    317                                         Graphics g = FrameGraphics.createGraphics();
    318                                         if (g != null) {
    319                                                 refresh(false, g, Item.DEFAULT_BACKGROUND);
    320                                         }
    321                                         return _messages[i];
    322                                 }
    323 
    324                                 pos += 25;
     306                if(_messages.size() >= 3) {
     307                        _messages.remove(0);
     308                        for(Item i : _messages) {
     309                                i.setY(i.getY() - 25);
    325310                        }
    326311                }
    327 
    328                 // if we have not returned then all message slots are used
    329                 for (int i = 0; i < _messages.length - 1; i++) {
    330                         _messages[i].setText(_messages[i + 1].getFirstLine());
    331                         _messages[i].setColor(_messages[i + 1].getColor());
    332                         _messages[i].setLink(_messages[i + 1].getLink());
    333                         _messages[i].setActions(_messages[i + 1].getAction());
    334                 }
    335 
    336                 // show the new message
    337                 Text last = _messages[_messages.length - 1];
    338                 last.setColor(color);
    339                 // Set the text for the new message
    340                 last.setText(getMessagePrefix(true) + message);
    341                 last.setLink(link);
    342                 last.setActions(actions);
    343 
    344                 _creator.addItem(last.copy(), true);
     312               
     313                Text t = newMessage(message, link, actions, color);
     314               
     315                _messages.add(t);
     316               
    345317                // update the link to the latest message frame
    346318                _messageLink.setLink(_creator.getCurrent());
    347319
     320                if(redraw) {
     321                Graphics g = FrameGraphics.createGraphics();
     322                if (g != null) {
     323                    refresh(false, g, Item.DEFAULT_BACKGROUND);
     324                }
     325                }
     326
     327                return t;
     328        }
     329
     330        public synchronized static Text displayMessage(String message, String link,
     331                        List<String> actions, Color color, boolean displayAlways) {
     332                return displayMessage(message, link, actions, color, displayAlways, true);
     333        }
     334
     335        public synchronized static void overwriteMessage(String message) {
     336                overwriteMessage(message, null);
     337        }
     338
     339        public synchronized static void overwriteMessage(String message, Color color) {
     340                _messages.remove(_messages.size());
     341                Text t = newMessage(message, null, null, color);
     342                _messages.add(t);
    348343                Graphics g = FrameGraphics.createGraphics();
    349344                if (g != null) {
    350345                    refresh(false, g, Item.DEFAULT_BACKGROUND);
    351346                }
    352 
    353                 return last;
    354         }
    355 
    356         public synchronized static void overwriteMessage(String message) {
    357                 overwriteMessage(message, null);
    358         }
    359 
    360         public synchronized static void overwriteMessage(String message, Color color) {
    361                 for (int ind = _messages.length - 1; ind >= 0; ind--) {
    362                         if (_messages[ind] != null) {
    363                                 _messages[ind].setColor(color);
    364                                 _messages[ind].setText(getMessagePrefix(false) + message);
    365                                 refresh(false, FrameGraphics.createGraphics(),
    366                                                 Item.DEFAULT_BACKGROUND);
    367                                 return;
    368                         }
    369                 }
    370 
    371                 // if we have not returned, then there are no messages yet
    372                 displayMessage(message, Color.darkGray);
     347        }
     348       
     349        private static String getMessagePrefix(int counter) {
     350                return "@" + counter + ": ";
    373351        }
    374352
     
    376354                if (incrementCounter)
    377355                        _messageCount++;
    378                 return "@" + _messageCount + ": ";
     356                return getMessagePrefix(_messageCount);
    379357        }
    380358
     
    387365         */
    388366        public synchronized static Text linkedErrorMessage(String message) {
    389                 if (_supressMessages)
     367                if (_suppressMessages)
    390368                        return null;
    391369                Misc.beep();
     
    398376
    399377        public synchronized static Text errorMessage(String message) {
    400                 if (_supressMessages)
     378                if (_suppressMessages)
    401379                        return null;
    402380                Misc.beep();
     
    446424        }
    447425
    448         public synchronized static void supressMessages(boolean val) {
    449                 _supressMessages = val;
     426        public synchronized static void suppressMessages(boolean val) {
     427                _suppressMessages = val;
    450428        }
    451429       
     
    465443                }
    466444        }
     445       
     446        public static final class Progress {
     447               
     448                private static final String t = "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓";
     449                private static final String f = "░░░░░░░░░░░░░░░░░░░░";
     450               
     451                String message;
     452                Text text;
     453               
     454                protected Progress(String text) {
     455                        this.text = displayMessage(text, null, null, Color.BLACK, true, false);
     456                        //this.text.setFont(Font.decode(Text.MONOSPACED_FONT + "-16"));
     457                        this.message = this.text.getText();
     458                        this.text.setText(this.message + " [" + f + "] 0%");
     459                        refresh(false, FrameGraphics.createGraphics(), Item.DEFAULT_BACKGROUND);
     460                }
     461               
     462                /**
     463                 *
     464                 * @param progress progress value from 0 to 100
     465                 * @return true if the progress was updated, false if the progress was off the screen
     466                 * @throws Exception if progress out of bounds
     467                 */
     468                public boolean set(int progress) throws Exception {
     469                        if(progress < 0 || progress > 100) throw new Exception("Progress value out of bounds");
     470                        int p = progress / 5;
     471                        if(isMessageItem(this.text)) {
     472                                this.text.setText(this.message + " [" + t.substring(0, p) + f.substring(p) + "] " + progress + "%");
     473                                refresh(false, FrameGraphics.createGraphics(), Item.DEFAULT_BACKGROUND);
     474                                return true;
     475                        }
     476                return false;
     477        }
     478        }
     479       
     480        public synchronized static Progress displayProgress(String message) {
     481                return new Progress(message);
     482        }
    467483
    468484}
Note: See TracChangeset for help on using the changeset viewer.