This commit is contained in:
Flare Microsystems
2024-03-07 16:27:21 -08:00
parent e0ef9e61f8
commit 107f83084e
7 changed files with 114 additions and 25 deletions

View File

@@ -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,15 +52,23 @@ 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 = "";
private ForecastProvider forecastProvider = null;
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;
@@ -94,8 +109,30 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
public void paintComponent(Graphics g) {
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);
@@ -150,9 +177,20 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
DrawingUtil.drawOutlinedString(g2d, W - sw - 60, TIMEBAR_Y + 36, timeString, Color.WHITE, Color.BLACK, 2);
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.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);
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);
}
}
@@ -168,7 +206,23 @@ 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() {
@@ -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);
}
@@ -225,9 +283,8 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
this.forecastProvider = forecastProvider;
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)

View File

@@ -217,13 +217,21 @@ public class DayForecastDisplay implements Display {
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + (131 * i) + (127 / 2) - (metrics.stringWidth(statLine1) / 2), RenderConstants.TOPBAR_HEIGHT + 170, statLine1, Color.WHITE, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + (131 * i) + (127 / 2) - (metrics.stringWidth(statLine2) / 2), RenderConstants.TOPBAR_HEIGHT + 200, statLine2, Color.WHITE, Color.BLACK, 2);
if (!ValueCheck.valueNoData(forecast.hiTemp) && !ValueCheck.valueNoData(forecast.loTemp))
if (!ValueCheck.valueNoData(forecast.hiTemp))
{
g2d.setFont(font.deriveFont(26F));
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + (131 * i) + 30 - (metrics.stringWidth(String.valueOf(forecast.hiTemp)) >> 1), RenderConstants.TOPBAR_HEIGHT + 295, String.valueOf(forecast.hiTemp), Color.WHITE, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + (131 * i) + 92 - (metrics.stringWidth(String.valueOf(forecast.loTemp)) >> 1), RenderConstants.TOPBAR_HEIGHT + 295, String.valueOf(forecast.loTemp), Color.WHITE, Color.BLACK, 2);
g2d.setFont(smallFont.deriveFont(24F));
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + (131 * i) + 20, RenderConstants.TOPBAR_HEIGHT + 270, "Hi", Color.RED, Color.BLACK, 2);
}
if (!ValueCheck.valueNoData(forecast.loTemp))
{
g2d.setFont(font.deriveFont(26F));
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + (131 * i) + 92 - (metrics.stringWidth(String.valueOf(forecast.loTemp)) >> 1), RenderConstants.TOPBAR_HEIGHT + 295, String.valueOf(forecast.loTemp), Color.WHITE, Color.BLACK, 2);
g2d.setFont(smallFont.deriveFont(24F));
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + (131 * i) + 82, RenderConstants.TOPBAR_HEIGHT + 270, "Lo", Color.CYAN, Color.BLACK, 2);
}