|
|
|
|
@@ -12,12 +12,19 @@ import java.awt.event.ComponentEvent;
|
|
|
|
|
import java.awt.event.ComponentListener;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.awt.image.VolatileImage;
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.FileReader;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
|
|
|
|
import static com.flaremicro.visualforecast.graphics.RenderConstants.*;
|
|
|
|
|
|
|
|
|
|
import com.flaremicro.util.Util;
|
|
|
|
|
import com.flaremicro.visualforecast.api.ForecastProvider;
|
|
|
|
|
import com.flaremicro.visualforecast.displays.BootupDisplay;
|
|
|
|
|
import com.flaremicro.visualforecast.displays.DayForecastDisplay;
|
|
|
|
|
@@ -45,6 +52,7 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
|
|
|
|
|
|
|
|
|
|
private Rectangle redrawBound = new Rectangle(0, 0, 1, 1);
|
|
|
|
|
private Rectangle exclusiveRedrawBound = null;
|
|
|
|
|
private Rectangle crawlBound = null;
|
|
|
|
|
|
|
|
|
|
private String currentTown = "";
|
|
|
|
|
private String currentForecast = "";
|
|
|
|
|
@@ -53,7 +61,14 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
|
|
|
|
|
|
|
|
|
|
private PropertyManager propManager;
|
|
|
|
|
|
|
|
|
|
private String[] crawlStrings = new String[0];
|
|
|
|
|
String currentCrawlString = null;
|
|
|
|
|
private int crawlPosition = 0;
|
|
|
|
|
private int stringIndex = -1;
|
|
|
|
|
private int currentCrawlStringWidth = 0;
|
|
|
|
|
|
|
|
|
|
public RenderPanel(PropertyManager propManager) {
|
|
|
|
|
loadCrawlStrings();
|
|
|
|
|
this.addComponentListener(this);
|
|
|
|
|
this.setDoubleBuffered(true);
|
|
|
|
|
this.propManager = propManager;
|
|
|
|
|
@@ -95,7 +110,29 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
|
|
|
|
|
super.paintComponent(g);
|
|
|
|
|
Graphics2D g2d = prepareFrameBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(g.getClipBounds().equals(this.crawlBound))
|
|
|
|
|
{
|
|
|
|
|
g2d.setColor(BG_BLUE);
|
|
|
|
|
g2d.fillRect(0, H - INFOBAR_HEIGHT, W, INFOBAR_HEIGHT);
|
|
|
|
|
|
|
|
|
|
g2d.setColor(Color.DARK_GRAY);
|
|
|
|
|
g2d.drawLine(0, H - INFOBAR_HEIGHT + STROKE_OFFSET, W, H - INFOBAR_HEIGHT + STROKE_OFFSET);
|
|
|
|
|
|
|
|
|
|
g2d.setColor(Color.WHITE);
|
|
|
|
|
g2d.drawLine(0, H - INFOBAR_HEIGHT + STROKE_WIDTH + STROKE_OFFSET, W, H - INFOBAR_HEIGHT + STROKE_WIDTH + STROKE_OFFSET);
|
|
|
|
|
if (this.currentCrawlString != null)
|
|
|
|
|
{
|
|
|
|
|
g2d.setFont(font.deriveFont(26F));
|
|
|
|
|
DrawingUtil.drawOutlinedString(g2d, this.crawlPosition, H - INFOBAR_HEIGHT + 30, this.currentCrawlString, Color.WHITE, Color.BLACK, 2);
|
|
|
|
|
}
|
|
|
|
|
g2d.dispose();
|
|
|
|
|
g.drawImage(frameBuffer, 0, 0, getWidth(), getHeight(), this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawMainRegion(g2d);
|
|
|
|
|
|
|
|
|
|
if (currentFlavour != null)
|
|
|
|
|
{
|
|
|
|
|
if (this.getBounds().equals(g.getClipBounds()))
|
|
|
|
|
@@ -127,16 +164,6 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
|
|
|
|
|
g2d.fillRect(0, TOPBAR_HEIGHT, W, MAINBAR_HEIGHT);
|
|
|
|
|
|
|
|
|
|
g2d.fillRect(0, TOPBAR_HEIGHT, W, MAINBAR_HEIGHT);
|
|
|
|
|
|
|
|
|
|
g2d.setColor(BG_BLUE);
|
|
|
|
|
g2d.fillRect(0, H - INFOBAR_HEIGHT, W, INFOBAR_HEIGHT);
|
|
|
|
|
|
|
|
|
|
g2d.setColor(Color.DARK_GRAY);
|
|
|
|
|
g2d.drawLine(0, H - INFOBAR_HEIGHT + STROKE_OFFSET, W, H - INFOBAR_HEIGHT + STROKE_OFFSET);
|
|
|
|
|
|
|
|
|
|
g2d.setColor(Color.WHITE);
|
|
|
|
|
g2d.drawLine(0, H - INFOBAR_HEIGHT + STROKE_WIDTH + STROKE_OFFSET, W, H - INFOBAR_HEIGHT + STROKE_WIDTH + STROKE_OFFSET);
|
|
|
|
|
|
|
|
|
|
// g2d.setColor(Color.GRAY);
|
|
|
|
|
// g2d.drawRect(60, TOPBAR_HEIGHT+2, W-120, MAINBAR_HEIGHT-4);
|
|
|
|
|
|
|
|
|
|
@@ -151,8 +178,19 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
|
|
|
|
|
g2d.setFont(font.deriveFont(36F));
|
|
|
|
|
DrawingUtil.drawOutlinedString(g2d, 60, HEADERBAR_Y + 52, currentTown, Color.YELLOW, Color.BLACK, 2);
|
|
|
|
|
|
|
|
|
|
g2d.setColor(BG_BLUE);
|
|
|
|
|
g2d.fillRect(0, H - INFOBAR_HEIGHT, W, INFOBAR_HEIGHT);
|
|
|
|
|
|
|
|
|
|
g2d.setColor(Color.DARK_GRAY);
|
|
|
|
|
g2d.drawLine(0, H - INFOBAR_HEIGHT + STROKE_OFFSET, W, H - INFOBAR_HEIGHT + STROKE_OFFSET);
|
|
|
|
|
|
|
|
|
|
g2d.setColor(Color.WHITE);
|
|
|
|
|
g2d.drawLine(0, H - INFOBAR_HEIGHT + STROKE_WIDTH + STROKE_OFFSET, W, H - INFOBAR_HEIGHT + STROKE_WIDTH + STROKE_OFFSET);
|
|
|
|
|
if (this.currentCrawlString != null)
|
|
|
|
|
{
|
|
|
|
|
g2d.setFont(font.deriveFont(26F));
|
|
|
|
|
DrawingUtil.drawOutlinedString(g2d, -20, H - INFOBAR_HEIGHT + 30, "Welcome to WeatherBC! Stay tuned for your long range forcast", Color.WHITE, Color.BLACK, 2);
|
|
|
|
|
DrawingUtil.drawOutlinedString(g2d, this.crawlPosition, H - INFOBAR_HEIGHT + 30, this.currentCrawlString, Color.WHITE, Color.BLACK, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -168,8 +206,24 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (this.currentFlavour != null)
|
|
|
|
|
{
|
|
|
|
|
this.currentFlavour.tick(this, ticks, iconAnimationTicks);
|
|
|
|
|
}
|
|
|
|
|
if (this.crawlStrings != null && this.crawlStrings.length > 0 && this.crawlPosition + this.currentCrawlStringWidth <= 0)
|
|
|
|
|
{
|
|
|
|
|
stringIndex = ((stringIndex + 1) % this.crawlStrings.length);
|
|
|
|
|
this.currentCrawlString = this.crawlStrings[stringIndex];
|
|
|
|
|
this.crawlPosition = W;
|
|
|
|
|
Graphics g = this.getGraphics();
|
|
|
|
|
this.currentCrawlStringWidth = g.getFontMetrics(font.deriveFont(26F)).stringWidth(currentCrawlString);
|
|
|
|
|
g.dispose();
|
|
|
|
|
}
|
|
|
|
|
else if (this.currentCrawlString != null)
|
|
|
|
|
{
|
|
|
|
|
this.crawlPosition-=2;
|
|
|
|
|
repaint(0, this.crawlBound.x, this.crawlBound.y, this.crawlBound.width, this.crawlBound.height);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BufferedImage getSnapshot() {
|
|
|
|
|
return frameBuffer.getSnapshot();
|
|
|
|
|
@@ -199,6 +253,10 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
|
|
|
|
|
public void loseRedrawRegion() {
|
|
|
|
|
this.redrawBound = null;
|
|
|
|
|
addRedrawBound(W - TIMEBAR_WIDTH + TIMEBAR_OFFSET, TIMEBAR_Y, TIMEBAR_WIDTH, TIMEBAR_HEIGHT, false);
|
|
|
|
|
float wScale = getWidth() / (float) W;
|
|
|
|
|
float hScale = getHeight() / (float) H;
|
|
|
|
|
this.crawlBound = new Rectangle((int) 0, (int) ((H - INFOBAR_HEIGHT + 8) * hScale), (int) (W * wScale), (int) (30 * hScale));
|
|
|
|
|
|
|
|
|
|
if (this.currentFlavour != null)
|
|
|
|
|
this.currentFlavour.redrawRegionlost(this);
|
|
|
|
|
}
|
|
|
|
|
@@ -226,8 +284,7 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
|
|
|
|
|
this.currentFlavour.notifyForecastProviderUpdate(this, forecastProvider);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void notifyForecastProviderUpdate()
|
|
|
|
|
{
|
|
|
|
|
public void notifyForecastProviderUpdate() {
|
|
|
|
|
this.currentFlavour.notifyForecastProviderUpdate(this, forecastProvider);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -262,6 +319,33 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
|
|
|
|
|
repaint(exclusiveRedrawBound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadCrawlStrings() {
|
|
|
|
|
File crawl = new File("./crawl.txt");
|
|
|
|
|
ArrayList<String> strings = new ArrayList<String>();
|
|
|
|
|
if (crawl != null)
|
|
|
|
|
{
|
|
|
|
|
BufferedReader br = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
br = new BufferedReader(new FileReader(crawl));
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = br.readLine()) != null)
|
|
|
|
|
{
|
|
|
|
|
strings.add(line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (IOException e)
|
|
|
|
|
{
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Util.cleanClose(br);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.crawlStrings = strings.toArray(new String[strings.size()]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
while (true)
|
|
|
|
|
|