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/items/widgets/HeavyDutyInteractiveWidget.java

    r1046 r1102  
    1919package org.expeditee.items.widgets;
    2020
    21 import java.awt.Color;
    2221import java.awt.Font;
    2322import java.awt.FontMetrics;
     
    3332import javax.swing.SwingUtilities;
    3433
     34import org.expeditee.core.Colour;
     35import org.expeditee.gio.swing.SwingConversions;
     36import org.expeditee.gio.swing.SwingGraphicsManager;
     37import org.expeditee.gio.swing.SwingMiscManager;
    3538import org.expeditee.gui.Browser;
    36 import org.expeditee.gui.DisplayIO;
    37 import org.expeditee.gui.FrameGraphics;
     39import org.expeditee.gui.DisplayController;
    3840import org.expeditee.gui.FreeItems;
    3941import org.expeditee.items.Item;
     
    5355 * until expeditee allocates a thread to begin loading. The swing component is set as not-visible.
    5456 *
    55  * At the the loading stage, a loadable widget proccesses its load task and renders a
     57 * At the the loading stage, a loadable widget processes its load task and renders a
    5658 * load message/bar.
    5759 *
     
    5961 *
    6062 * When a HeavyDutyInteractiveWidget becomes visible / is anchored, it will register itself for saving at the next
    61  * save point according to SaveEntityManager. Heavey duty widgets will only save at the save points
     63 * save point according to SaveEntityManager. Heavy duty widgets will only save at the save points
    6264 * if the widget still belongs to a frame (i.e. is not removed) and is anchored.
    6365 *
    64  * Heavey duty widgets can also have an expiry on how long they should stay cached for. If they do have an
     66 * Heavy duty widgets can also have an expiry on how long they should stay cached for. If they do have an
    6567 * expiry then it they unload once expired, and will re-load once in view again. Must take care for
    6668 * unloadable widgets because you must check your unloadable elements to whether they are unloaded or not
    67  * every time your widget accessess them.
     69 * every time your widget accesses them.
    6870 *
    6971 * When a heavy duty widget is deleted - any data consuming memory can be dumped temporarily if needed.
     
    7274 *
    7375 */
    74 public abstract class HeavyDutyInteractiveWidget extends InteractiveWidget implements LoadableEntity, SaveableEntity {
     76public abstract class HeavyDutyInteractiveWidget extends SwingWidget implements LoadableEntity, SaveableEntity {
    7577       
    7678        /** load finished */
     
    9092        private static final String PENDING_MESSAGE = "Pending";
    9193       
    92         private static final Color LOAD_BAR_PROGRESS_COLOR = new Color(103, 171, 203);
    93         private static final Color LOAD_BAR_INDETERM_COLOR = Color.ORANGE;
    94         private static final Color LOAD_BAR_HIGHLIGHT_COLOR = new Color(240, 240, 240);
    95         private static final Color LOAD_SCREEN_COLOR = Color.LIGHT_GRAY;
    96         private static final Color LOAD_SCREEN_COLOR_FREESPACE = FREESPACE_BACKCOLOR;
     94        private static final Colour LOAD_BAR_PROGRESS_COLOR = Colour.FromRGB255(103, 171, 203);
     95        private static final Colour LOAD_BAR_INDETERM_COLOR = Colour.ORANGE;
     96        private static final Colour LOAD_BAR_HIGHLIGHT_COLOR = Colour.FromRGB255(240, 240, 240);
     97        private static final Colour LOAD_SCREEN_COLOR = Colour.LIGHT_GREY;
     98        private static final Colour LOAD_SCREEN_COLOR_FREESPACE = FREESPACE_BACKCOLOR;
    9799       
    98100        private static final Font LOAD_NORMAL_FONT = new Font("Arial", Font.BOLD, 12);
     
    140142         */
    141143        protected HeavyDutyInteractiveWidget(Text source, JComponent component,
    142                         int minWidth, int maxWidth, int minHeight, int maxHeight, int cacheDepth, boolean skipLoad) {
     144                        int minWidth, int maxWidth, int minHeight, int maxHeight, int cacheDepth, boolean skipLoad)
     145        {
    143146                super(source, component, minWidth, maxWidth, minHeight, maxHeight);
    144147               
     
    173176         *
    174177         * @param percent
    175          *              Must be between 0.0 and 1.0 inclusive for percentage. Or neagtive if indeterminant.
     178         *              Must be between 0.0 and 1.0 inclusive for percentage. Or negative if indeterminate.
    176179         *
    177180         * @throws IllegalArgumentException
     
    182185         *             
    183186         */
    184         protected final void updateLoadPercentage(float percent) {
     187        protected final void updateLoadPercentage(float percent)
     188        {
    185189                if (percent > 1.0f)
    186190                        throw new IllegalArgumentException("loadState is larger than 1.0");
     
    199203         * @return The current load state.
    200204         */
    201         protected float getLoadState() {
     205        protected float getLoadState()
     206        {
    202207                return loadState;
    203208        }
     
    206211         * @return True if in a loading phase.
    207212         */
    208         protected boolean isInLoadProgress() {
     213        protected boolean isInLoadProgress()
     214        {
    209215                return loadState <= 1.0f;
    210216        }
     
    226232               
    227233                // Re-render loading state
    228                 FrameGraphics.invalidateArea(_swingComponent.getBounds());
    229                 FrameGraphics.requestRefresh(true);
     234                DisplayController.invalidateArea(getBounds());
     235                DisplayController.requestRefresh(true);
    230236        }
    231237       
    232238        @Override
    233         public void paintInFreeSpace(Graphics g) {
    234                 if (loadState == LOAD_STATE_COMPLETED) super.paintInFreeSpace(g);
    235                 else paintLoadScreen(g, LOAD_SCREEN_COLOR_FREESPACE);
     239        public void paintInFreeSpace() {
     240                if (loadState == LOAD_STATE_COMPLETED) super.paintInFreeSpace();
     241                else paintLoadScreen(LOAD_SCREEN_COLOR_FREESPACE);
    236242        }
    237243
    238244        @Override
    239         public void paint(Graphics g) {
     245        protected final void paintSwingWidget(Graphics2D g)
     246        {
    240247                if (loadState == LOAD_STATE_COMPLETED) {
    241                         super.paint(g);
     248                        paintHeavyDutyWidget(g);
    242249                } else {
    243                         paintLoadScreen(g, LOAD_SCREEN_COLOR);
    244                         this.paintLink((Graphics2D)g);
    245                 }
    246                
    247         }
    248        
    249         /**
    250          * Rendersthe load bar / load messages
     250                        paintLoadScreen(LOAD_SCREEN_COLOR);
     251                }
     252               
     253        }
     254       
     255        /** Can be overridden to provide custom drawing. */
     256        protected void paintHeavyDutyWidget(Graphics2D g)
     257        {
     258                super.paintSwingWidget(g);
     259        }
     260       
     261        /**
     262         * Renders the load bar / load messages
    251263         *
    252264         * @param g
    253265         */
    254         private void paintLoadScreen(Graphics g, Color backgroundColor) {
     266        private void paintLoadScreen(Colour backgroundColor) {
    255267
    256268                if (Browser._theBrowser == null) return;
    257269               
     270                SwingGraphicsManager manager = SwingMiscManager.getIfUsingSwingGraphicsManager();
     271                Graphics g = manager.getCurrentSurface();
     272               
    258273                // Render shaded window over widget
    259                 g.setColor(backgroundColor);
     274                g.setColor(SwingConversions.toSwingColor(backgroundColor));
    260275                g.fillRect(getX(), getY(), getWidth(), getHeight());
    261276               
     
    291306                Rectangle tmpClip = (clipBackUp != null) ? clipBackUp.getBounds() :
    292307                        new Rectangle(0, 0,
    293                                         Browser._theBrowser.getContentPane().getWidth(),
    294                                         Browser._theBrowser.getContentPane().getHeight());
    295                        
    296                 g.setClip(tmpClip.intersection(getBounds()));
     308                                        manager.getContentPane().getWidth(),
     309                                        manager.getContentPane().getHeight());
     310                       
     311                g.setClip(tmpClip.intersection(SwingConversions.toSwingRectangle(getBounds())));
    297312       
    298313               
     
    300315
    301316                        GradientPaint gp = new GradientPaint(
    302                                         0, barY + (int)(BAR_HEIGHT * 0.8), LOAD_BAR_INDETERM_COLOR,
    303                                         0, barY, LOAD_BAR_HIGHLIGHT_COLOR);
     317                                        0, barY + (int)(BAR_HEIGHT * 0.8), SwingConversions.toSwingColor(LOAD_BAR_INDETERM_COLOR),
     318                                        0, barY, SwingConversions.toSwingColor(LOAD_BAR_HIGHLIGHT_COLOR));
    304319                        ((Graphics2D)g).setPaint(gp);
    305320               
     
    311326                       
    312327                        GradientPaint gp = new GradientPaint(
    313                                         0, barY + (int)(BAR_HEIGHT * 0.8), LOAD_BAR_PROGRESS_COLOR,
    314                                         0, barY, LOAD_BAR_HIGHLIGHT_COLOR);
     328                                        0, barY + (int)(BAR_HEIGHT * 0.8), SwingConversions.toSwingColor(LOAD_BAR_PROGRESS_COLOR),
     329                                        0, barY, SwingConversions.toSwingColor(LOAD_BAR_HIGHLIGHT_COLOR));
    315330                        ((Graphics2D)g).setPaint(gp);
    316331                       
     
    319334                }
    320335               
    321                 g.setColor(Color.DARK_GRAY);
     336                g.setColor(SwingConversions.toSwingColor(Colour.DARK_GREY));
    322337                g.drawRect(barX, barY, barWidth, BAR_HEIGHT);
    323338               
    324339                if (loadState == LOAD_STATE_FAILED)
    325                         g.setColor(Color.RED);
    326                
    327                 else g.setColor(Color.BLACK);
     340                        g.setColor(SwingConversions.toSwingColor(Colour.RED));
     341               
     342                else g.setColor(SwingConversions.toSwingColor(Colour.BLACK));
    328343               
    329344
     
    638653                        // Re-render loading state - if not expired
    639654                        if (!expired) {
    640                                 FrameGraphics.invalidateArea(new Rectangle(getX(), getY(), getWidth(), getHeight()));
    641                                 FrameGraphics.requestRefresh(true);
     655                                DisplayController.invalidateArea(getBounds());
     656                                DisplayController.requestRefresh(true);
    642657                        }
    643658                }
     
    680695                       
    681696                        // Only load if in view
    682                         if (!isFloating() && getParentFrame() != DisplayIO.getCurrentFrame())
     697                        if (!isFloating() && getParentFrame() != DisplayController.getCurrentFrame())
    683698                                return;
    684699                       
Note: See TracChangeset for help on using the changeset viewer.