- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/widgets/HeavyDutyInteractiveWidget.java
r1046 r1102 19 19 package org.expeditee.items.widgets; 20 20 21 import java.awt.Color;22 21 import java.awt.Font; 23 22 import java.awt.FontMetrics; … … 33 32 import javax.swing.SwingUtilities; 34 33 34 import org.expeditee.core.Colour; 35 import org.expeditee.gio.swing.SwingConversions; 36 import org.expeditee.gio.swing.SwingGraphicsManager; 37 import org.expeditee.gio.swing.SwingMiscManager; 35 38 import org.expeditee.gui.Browser; 36 import org.expeditee.gui.DisplayIO; 37 import org.expeditee.gui.FrameGraphics; 39 import org.expeditee.gui.DisplayController; 38 40 import org.expeditee.gui.FreeItems; 39 41 import org.expeditee.items.Item; … … 53 55 * until expeditee allocates a thread to begin loading. The swing component is set as not-visible. 54 56 * 55 * At the the loading stage, a loadable widget proc cesses its load task and renders a57 * At the the loading stage, a loadable widget processes its load task and renders a 56 58 * load message/bar. 57 59 * … … 59 61 * 60 62 * When a HeavyDutyInteractiveWidget becomes visible / is anchored, it will register itself for saving at the next 61 * save point according to SaveEntityManager. Heav ey duty widgets will only save at the save points63 * save point according to SaveEntityManager. Heavy duty widgets will only save at the save points 62 64 * if the widget still belongs to a frame (i.e. is not removed) and is anchored. 63 65 * 64 * Heav ey duty widgets can also have an expiry on how long they should stay cached for. If they do have an66 * Heavy duty widgets can also have an expiry on how long they should stay cached for. If they do have an 65 67 * expiry then it they unload once expired, and will re-load once in view again. Must take care for 66 68 * unloadable widgets because you must check your unloadable elements to whether they are unloaded or not 67 * every time your widget accesses sthem.69 * every time your widget accesses them. 68 70 * 69 71 * When a heavy duty widget is deleted - any data consuming memory can be dumped temporarily if needed. … … 72 74 * 73 75 */ 74 public abstract class HeavyDutyInteractiveWidget extends InteractiveWidget implements LoadableEntity, SaveableEntity {76 public abstract class HeavyDutyInteractiveWidget extends SwingWidget implements LoadableEntity, SaveableEntity { 75 77 76 78 /** load finished */ … … 90 92 private static final String PENDING_MESSAGE = "Pending"; 91 93 92 private static final Colo r LOAD_BAR_PROGRESS_COLOR = new Color(103, 171, 203);93 private static final Colo r LOAD_BAR_INDETERM_COLOR = Color.ORANGE;94 private static final Colo r LOAD_BAR_HIGHLIGHT_COLOR = new Color(240, 240, 240);95 private static final Colo r LOAD_SCREEN_COLOR = Color.LIGHT_GRAY;96 private static final Colo r 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; 97 99 98 100 private static final Font LOAD_NORMAL_FONT = new Font("Arial", Font.BOLD, 12); … … 140 142 */ 141 143 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 { 143 146 super(source, component, minWidth, maxWidth, minHeight, maxHeight); 144 147 … … 173 176 * 174 177 * @param percent 175 * Must be between 0.0 and 1.0 inclusive for percentage. Or ne agtive if indeterminant.178 * Must be between 0.0 and 1.0 inclusive for percentage. Or negative if indeterminate. 176 179 * 177 180 * @throws IllegalArgumentException … … 182 185 * 183 186 */ 184 protected final void updateLoadPercentage(float percent) { 187 protected final void updateLoadPercentage(float percent) 188 { 185 189 if (percent > 1.0f) 186 190 throw new IllegalArgumentException("loadState is larger than 1.0"); … … 199 203 * @return The current load state. 200 204 */ 201 protected float getLoadState() { 205 protected float getLoadState() 206 { 202 207 return loadState; 203 208 } … … 206 211 * @return True if in a loading phase. 207 212 */ 208 protected boolean isInLoadProgress() { 213 protected boolean isInLoadProgress() 214 { 209 215 return loadState <= 1.0f; 210 216 } … … 226 232 227 233 // Re-render loading state 228 FrameGraphics.invalidateArea(_swingComponent.getBounds());229 FrameGraphics.requestRefresh(true);234 DisplayController.invalidateArea(getBounds()); 235 DisplayController.requestRefresh(true); 230 236 } 231 237 232 238 @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); 236 242 } 237 243 238 244 @Override 239 public void paint(Graphics g) { 245 protected final void paintSwingWidget(Graphics2D g) 246 { 240 247 if (loadState == LOAD_STATE_COMPLETED) { 241 super.paint(g);248 paintHeavyDutyWidget(g); 242 249 } 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 251 263 * 252 264 * @param g 253 265 */ 254 private void paintLoadScreen( Graphics g, Color backgroundColor) {266 private void paintLoadScreen(Colour backgroundColor) { 255 267 256 268 if (Browser._theBrowser == null) return; 257 269 270 SwingGraphicsManager manager = SwingMiscManager.getIfUsingSwingGraphicsManager(); 271 Graphics g = manager.getCurrentSurface(); 272 258 273 // Render shaded window over widget 259 g.setColor( backgroundColor);274 g.setColor(SwingConversions.toSwingColor(backgroundColor)); 260 275 g.fillRect(getX(), getY(), getWidth(), getHeight()); 261 276 … … 291 306 Rectangle tmpClip = (clipBackUp != null) ? clipBackUp.getBounds() : 292 307 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()))); 297 312 298 313 … … 300 315 301 316 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)); 304 319 ((Graphics2D)g).setPaint(gp); 305 320 … … 311 326 312 327 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)); 315 330 ((Graphics2D)g).setPaint(gp); 316 331 … … 319 334 } 320 335 321 g.setColor( Color.DARK_GRAY);336 g.setColor(SwingConversions.toSwingColor(Colour.DARK_GREY)); 322 337 g.drawRect(barX, barY, barWidth, BAR_HEIGHT); 323 338 324 339 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)); 328 343 329 344 … … 638 653 // Re-render loading state - if not expired 639 654 if (!expired) { 640 FrameGraphics.invalidateArea(new Rectangle(getX(), getY(), getWidth(), getHeight()));641 FrameGraphics.requestRefresh(true);655 DisplayController.invalidateArea(getBounds()); 656 DisplayController.requestRefresh(true); 642 657 } 643 658 } … … 680 695 681 696 // Only load if in view 682 if (!isFloating() && getParentFrame() != Display IO.getCurrentFrame())697 if (!isFloating() && getParentFrame() != DisplayController.getCurrentFrame()) 683 698 return; 684 699
Note:
See TracChangeset
for help on using the changeset viewer.