private Timer canvasUpdateTimer;
private ViewUpdateTimerTask canvasUpdateTimerTask;
private RenderingContext renderingContext = null;
+
+ /**
+ * UI component that mouse is currently hovering over.
+ */
private MouseInteractionController currentMouseOverComponent;
+
+ /**
+ * Currently target FPS for this view. It can be changed at runtime. Also when nothing
+ * changes in the view, then frames are not really repainted.
+ */
+ private int targetFPS = 30;
+
/**
- * Currently target FPS for this view. It might change at runtime.
+ * Set to true if it is known than next frame reeds to be painted. Flag is cleared
+ * immediately after frame got updated.
*/
- private int targetFramerate = 30;
- private boolean repaintDuringNextViewUpdate = true;
+ private boolean viewRepaintNeeded = true;
public ViewPanel() {
viewRenderListeners.add(context.getAvatar());
initializePanelLayout();
- setFrameRate(targetFramerate);
+ setFrameRate(targetFPS);
addComponentListener(this);
}
@Override
public void componentResized(final ComponentEvent e) {
- repaintDuringNextViewUpdate = true;
+ viewRepaintNeeded = true;
}
@Override
public void componentShown(final ComponentEvent e) {
- repaintDuringNextViewUpdate = true;
+ viewRepaintNeeded = true;
}
public ViewContext getContext() {
if (currentMouseOverComponent == null) {
currentMouseOverComponent = renderingContext.clickedItem;
currentMouseOverComponent.mouseEntered();
- repaintDuringNextViewUpdate = true;
+ viewRepaintNeeded = true;
} else if (currentMouseOverComponent != renderingContext.clickedItem) {
currentMouseOverComponent.mouseExited();
currentMouseOverComponent = renderingContext.clickedItem;
currentMouseOverComponent.mouseEntered();
- repaintDuringNextViewUpdate = true;
+ viewRepaintNeeded = true;
}
} else {
// mouse click
renderingContext.clickedItem.mouseClicked();
- repaintDuringNextViewUpdate = true;
+ viewRepaintNeeded = true;
}
} else if (currentMouseOverComponent != null) {
currentMouseOverComponent.mouseExited();
- repaintDuringNextViewUpdate = true;
+ viewRepaintNeeded = true;
currentMouseOverComponent = null;
}
}
* repainted on first opportunity.
*/
public void repaintDuringNextViewUpdate() {
- repaintDuringNextViewUpdate = true;
+ viewRepaintNeeded = true;
}
public void setFrameRate(final int frameRate) {
canvasUpdateTimer = null;
}
- targetFramerate = frameRate;
+ targetFPS = frameRate;
if (frameRate > 0) {
canvasUpdateTimer = new Timer();
if ((getWidth() <= 0) || (getHeight() <= 0))
return;
- if (repaintDuringNextViewUpdate) {
- repaintDuringNextViewUpdate = false;
+ if (viewRepaintNeeded) {
+ viewRepaintNeeded = false;
reRenderFrame = true;
}