package org.helioviewer.jhv.renderable.components;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.geom.Rectangle2D;

import javax.swing.SwingWorker;

import org.helioviewer.jhv.gui.UIGlobals;
import org.helioviewer.jhv.opengl.GL3DViewport;
import org.helioviewer.jhv.opengl.GLInfo;
import org.helioviewer.jhv.renderable.gui.Renderable;

import com.jogamp.opengl.GL2;
import com.jogamp.opengl.util.awt.TextRenderer;

public class RenderableDummy implements Renderable {

    private Font font;
    private final float baseFontSize = 16;
    private float fontSize;
    private TextRenderer textRenderer;
    private SwingWorker<?,?> worker;

    private final String name = "Loading...";

    public RenderableDummy(SwingWorker<?,?> _worker) {
        worker = _worker;
    }

    @Override
    public void render(GL2 gl, GL3DViewport vp) {
        int sx = GLInfo.pixelScale[0];
        int sy = GLInfo.pixelScale[1];
        if (textRenderer == null || fontSize != sy * baseFontSize) {
            fontSize = sy * baseFontSize;
            font = UIGlobals.UIFontRoboto.deriveFont(fontSize);
            if (textRenderer != null) {
                textRenderer.dispose();
            }
            textRenderer = new TextRenderer(font, true, true);
            textRenderer.setUseVertexArrays(true);
            textRenderer.setSmoothing(false);
            textRenderer.setColor(Color.WHITE);
        }

        textRenderer.beginRendering(vp.getWidth(), vp.getHeight(), true);
        Rectangle2D rect = textRenderer.getBounds(name);
        textRenderer.draw(name, (vp.getWidth() - 5) - (int) rect.getWidth(), (vp.getHeight() - 5) - (int) rect.getHeight());
        textRenderer.endRendering();
    }

    @Override
    public void remove(GL2 gl) {
        dispose(gl);
        worker.cancel(true);
    }

    @Override
    public Component getOptionsPanel() {
        return null;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public boolean isVisible() {
        return true;
    }

    @Override
    public void setVisible(boolean b) {
    }

    @Override
    public String getTimeString() {
        return null;
    }

    @Override
    public boolean isDeletable() {
        return false;
    }

    @Override
    public void init(GL2 gl) {
    }

    @Override
    public void dispose(GL2 gl) {
        if (textRenderer != null) {
            textRenderer.dispose();
            textRenderer = null;
        }
    }

    @Override
    public void renderMiniview(GL2 gl, GL3DViewport vp) {
    }

}

@@ -1603,16 +1603,22 @@
 aw(name,
+ (int)
  (vp.get
@@ -1622,35 +1622,24 @@
 getWidth() -
- 5) - (int)
  rect.getWid
@@ -1642,17 +1642,33 @@
 tWidth()
-,
+ - 5 * sx), (int)
  (vp.get
@@ -1681,19 +1681,8 @@
 () -
- 5) - (int)
  rec
@@ -1694,16 +1694,26 @@
 Height()
+ - 5 * sy)
 );%0A     

Reposition text