10 Commits

Author SHA1 Message Date
Vulpovile
655aa74f12 Use new jlayer 2025-04-26 21:16:09 -07:00
Vulpovile
1653dd9ce6 Merge branch 'master' of ssh://git.devel.flaremicro.com:4242/FlarePublic/VisualForecast-1000 into feature/current_conditions 2025-04-26 20:51:14 -07:00
2b3f1b8c93 Add licence 2025-04-26 18:23:38 +00:00
Vulpovile
4786cb7bd7 Update gitignore 2025-04-09 21:55:29 -07:00
Vulpovile
0648a0178c A lot 2025-04-09 21:52:18 -07:00
Flare Microsystems
8da8621d9b Merge branch 'feature/hourlyforecast' into 'master'
Feature/hourlyforecast

See merge request FlareMicrosystems/visualforecast-1000!4
2024-03-16 06:48:10 +00:00
Flare Microsystems
0b4ca18c69 Added hourly forecast and message forecast 2024-03-15 23:45:35 -07:00
Flare Microsystems
fee43c3ee2 Optimized 2024-03-09 23:50:47 -08:00
Flare Microsystems
28e19dd91c Completed graphing 2024-03-09 23:35:03 -08:00
Flare Microsystems
5628a5b76e Added hourly forecast 2024-03-08 21:31:49 -08:00
39 changed files with 2250 additions and 191 deletions

View File

@@ -3,5 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="jlayer-1.0.4.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

3
.gitignore vendored
View File

@@ -24,3 +24,6 @@ bin/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*.dat
#Can contain copyrighted music!
Music/

View File

@@ -1,5 +1,6 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
@@ -7,5 +8,8 @@ org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.6

BIN
Announcements/7-day-dis.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,13 @@
#VisualForecast 1000 Properties file. Functional provider must be set for successful boot!
#Thu Mar 07 16:27:03 PST 2024
#Sat Nov 23 19:50:15 PST 2024
displays-enabled.town.prince_rupert.bc=7-day,hourly
displays-enabled.town.victora.bc=36-hour,7-day,hourly
displays-enabled.town.nanaimo.bc=7-day,hourly
displays-enabled.town.prince\ rupert.bc=
displays-enabled.town.kelowna.bc=7-day,hourly
displays-enabled.town.prince_george.bc=36-hour,7-day,hourly
displays-enabled.town.prince\ george.bc=
towns-by-name-and-province=Vancouver,BC;Victora,BC;Kelowna,BC;Nanaimo,BC;Squamish,BC;Prince George,BC;Prince Rupert,BC
displays-enabled.town.squamish.bc=7-day,hourly
towns-by-code=
towns-by-name-and-province=Vancouver,BC;Kamloops,BC;Kelowna,BC
displays-enabled.town.vancouver.bc=

339
LICENCE Normal file
View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

Binary file not shown.

BIN
jlayer-1.0.4.jar Normal file

Binary file not shown.

View File

@@ -0,0 +1,286 @@
package com.flaremicro.audio;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Random;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.SourceDataLine;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;
import com.flaremicro.util.Util;
public class AgnosticAudioSystem implements GameAudioSystem {
private Collection<AudioFinishedListener> listeners = new ArrayList<AudioFinishedListener>();
private HashMap<String, AudioSystemThread> threads = new HashMap<String, AudioSystemThread>();
private Random random = new Random();
public void init() {
}
public void destroy() {
}
public void addAudioFinishedListener(AudioFinishedListener listener) {
this.listeners.add(listener);
}
public void removeAudioFinishedListener(AudioFinishedListener listener) {
this.listeners.remove(listener);
}
public void removeAudioFinishedListeners() {
this.listeners.clear();
}
public String play(URL res) {
if (res.getPath().contains("."))
{
String key = String.valueOf(random.nextLong());
String ext = res.getPath().substring(res.getPath().lastIndexOf(".") + 1).toLowerCase();
AudioSystemThread audioSystemThread = null;
if (ext.equalsIgnoreCase("mp3"))
audioSystemThread = new AgnosticMp3AudioSystemThread(res, key, this, false);
if (ext.equalsIgnoreCase("wav"))
audioSystemThread = new AgnosticWavAudioSystemThread(res, key, this, false);
if (audioSystemThread != null)
{
synchronized (threads)
{
threads.put(key, audioSystemThread);
}
new Thread(audioSystemThread).start();
return key;
}
}
return null;
}
public void playbg(URL res) {
stopbg();
if (res.getPath().contains("."))
{
String ext = res.getPath().substring(res.getPath().lastIndexOf(".") + 1).toLowerCase();
AudioSystemThread audioSystemThread = null;
if (ext.equalsIgnoreCase("mp3"))
audioSystemThread = new AgnosticMp3AudioSystemThread(res, "bg", this, true);
if (ext.equalsIgnoreCase("wav"))
audioSystemThread = new AgnosticWavAudioSystemThread(res, "bg", this, true);
if (audioSystemThread != null)
{
synchronized (threads)
{
threads.put("bg", audioSystemThread);
}
new Thread(audioSystemThread).start();
}
}
}
public void stopbg() {
if (threads.containsKey("bg"))
threads.get("bg").stopMusic();
stopped("bg", threads.get("bg"));
}
public void stopped(String threadName, AudioSystemThread audioSystemThread) {
synchronized (threads)
{
if (audioSystemThread != null && audioSystemThread == threads.get(threadName))
{
threads.remove(threadName);
}
}
for (AudioFinishedListener listener : listeners)
{
listener.audioFinished(threadName, audioSystemThread.resource);
}
}
public void setVolume(float percent, String key) {
AudioSystemThread ast = threads.get(key);
if (ast != null)
{
ast.setVolume(percent);
}
}
public void stop(String currentKey) {
AudioSystemThread ast = threads.get(currentKey);
if (ast != null)
{
ast.stopMusic();
}
}
}
abstract class AudioSystemThread implements Runnable {
protected final boolean looping;
protected final AgnosticAudioSystem system;
protected final URL resource;
protected final String threadName;
public AudioSystemThread(URL resource, String threadName, AgnosticAudioSystem system, boolean looping) {
this.resource = resource;
this.looping = looping;
this.threadName = threadName;
this.system = system;
}
public abstract void setVolume(float percent);
public abstract void stopMusic();
public final void onStop() {
this.system.stopped(threadName, this);
}
}
class AgnosticMp3AudioSystemThread extends AudioSystemThread {
private boolean running = true;
private Player player = null;
private static final int FRAME_BUFFER = 2;
private float volume = 1F;
public AgnosticMp3AudioSystemThread(URL resource, String threadName, AgnosticAudioSystem system, boolean looping) {
super(resource, threadName, system, looping);
}
public void run() {
do
{
try
{
player = new Player(new BufferedInputStream(resource.openStream()));
player.setVolume(volume);
while (running && player.play(FRAME_BUFFER));
}
catch (JavaLayerException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
while (running && looping);
super.onStop();
}
public void stopMusic() {
this.running = false;
if (player != null)
player.close();
}
@Override
public void setVolume(float percent) {
volume = percent;
if (player != null)
{
player.setVolume(volume);
}
}
}
class AgnosticWavAudioSystemThread extends AudioSystemThread {
private boolean running = true;
private SourceDataLine sourceLine = null;
private float volume = 1.0F;
public AgnosticWavAudioSystemThread(URL resource, String threadName, AgnosticAudioSystem system, boolean looping) {
super(resource, threadName, system, looping);
}
public void run() {
AudioInputStream audioStream = null;
do
{
try
{
audioStream = AudioSystem.getAudioInputStream(resource);
AudioFormat audioFormat = audioStream.getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
sourceLine = (SourceDataLine) AudioSystem.getLine(info);
sourceLine.open();
sourceLine.start();
FloatControl volume = (FloatControl) sourceLine.getControl(FloatControl.Type.MASTER_GAIN);
volume.setValue(this.volume);
int nBytesRead = 0;
byte[] abData = new byte[4096];
while (nBytesRead != -1 && running)
{
try
{
nBytesRead = audioStream.read(abData, 0, abData.length);
}
catch (IOException e)
{
e.printStackTrace();
}
if (nBytesRead >= 0)
{
@SuppressWarnings("unused")
int nBytesWritten = sourceLine.write(abData, 0, nBytesRead);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
Util.cleanClose(audioStream);
if (sourceLine != null)
{
sourceLine.drain();
sourceLine.close();
}
}
}
while (running && looping);
onStop();
}
public void stopMusic() {
this.running = false;
if (sourceLine != null)
{
sourceLine.drain();
sourceLine.close();
}
}
@Override
public void setVolume(float percent) {
if (sourceLine != null)
{
this.volume = percent;
FloatControl volume = (FloatControl) sourceLine.getControl(FloatControl.Type.MASTER_GAIN);
volume.setValue(percent);
}
}
}

View File

@@ -0,0 +1,7 @@
package com.flaremicro.audio;
import java.net.URL;
public interface AudioFinishedListener {
public void audioFinished(String key, URL resource);
}

View File

@@ -0,0 +1,83 @@
package com.flaremicro.audio;
import java.net.URL;
import java.util.Random;
public class AudioPlaylist implements AudioFinishedListener{
private final AgnosticAudioSystem aas;
public AudioPlaylist(AgnosticAudioSystem aas)
{
this.aas = aas;
}
String currentKey = null;
int currentPlaylistIndex = 0;
URL[] playlist = null;
float currVol = 1F;
private boolean stopped = true;
public void setPlaylist(URL[] url)
{
this.playlist = url;
this.currentPlaylistIndex = 0;
}
public void shuffle(){
Random rand = new Random();
for (int i = 0; i < playlist.length; i++) {
int randomIndexToSwap = rand.nextInt(playlist.length);
URL temp = playlist[randomIndexToSwap];
playlist[randomIndexToSwap] = playlist[i];
playlist[i] = temp;
}
}
public void start()
{
stopped = false;
currentPlaylistIndex = 0;
aas.addAudioFinishedListener(this);
if(currentKey == null && playlist != null && playlist.length > 0)
{
currentKey = aas.play(playlist[0]);
aas.setVolume(currVol, currentKey);
}
}
public void next()
{
if(playlist != null && playlist.length > 0)
{
currentPlaylistIndex = (currentPlaylistIndex + 1 ) % playlist.length;
currentKey = aas.play(playlist[currentPlaylistIndex]);
aas.setVolume(currVol, currentKey);
}
}
public void audioFinished(String key, URL resource) {
if(!stopped && key == currentKey)
{
next();
}
}
public void setVolume(float volume) {
currVol = volume;
aas.setVolume(currVol, currentKey);
}
public void stop() {
stopped = true;
aas.stop(currentKey);
}
public float getVolume() {
return currVol;
}
}

View File

@@ -0,0 +1,16 @@
package com.flaremicro.audio;
import java.net.URL;
public interface GameAudioSystem {
public void init();
public void destroy();
public void playbg(URL res);
public String play(URL res);
public void stopbg();
}

View File

@@ -0,0 +1,127 @@
package com.flaremicro.visualforecast;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import com.flaremicro.audio.AgnosticAudioSystem;
import com.flaremicro.audio.AudioFinishedListener;
import com.flaremicro.audio.AudioPlaylist;
public class AudioManager implements AudioFinishedListener {
private PropertyManager propertyManager;
private AgnosticAudioSystem aas;
private AudioPlaylist audioPlaylist;
private File playlistDirectory = new File("./Music");
HashSet<String> playingKeys = new HashSet<String>();
public AudioManager(PropertyManager propertyManager) {
this.propertyManager = propertyManager;
this.aas = new AgnosticAudioSystem();
this.aas.addAudioFinishedListener(this);
this.audioPlaylist = new AudioPlaylist(aas);
updatePlaylist();
}
private void updatePlaylist() {
playlistDirectory = propertyManager.getFile("music-dir", playlistDirectory);
if (playlistDirectory == null || !playlistDirectory.isDirectory())
return;
File[] files = playlistDirectory.listFiles();
URL[] urls = new URL[files.length];
for (int i = 0; i < files.length; i++)
{
try
{
urls[i] = files[i].toURI().toURL();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
}
audioPlaylist.setPlaylist(urls);
audioPlaylist.shuffle();
}
public void audioFinished(String key, URL resource) {
playingKeys.remove(key);
if (playingKeys.size() == 0)
rampVolume(1F);
}
public void startPlaylist() {
if (playlistDirectory == null || !playlistDirectory.isDirectory())
return;
audioPlaylist.start();
}
public void stopPlaylist() {
audioPlaylist.stop();
}
public void end() {
audioPlaylist.stop();
aas.destroy();
}
public void playAnnouncement(File file) {
try
{
URL url = file.toURI().toURL();
rampVolume(-10F);
playingKeys.add(aas.play(url));
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Thread currThread = null;
private float volume = 1F;
//***horrible***
private void rampVolume(float newVolume) {
this.volume = newVolume;
if (currThread != null)
return;
currThread = new Thread(new Runnable() {
public void run() {
try
{
if (volume < audioPlaylist.getVolume())
{
while (audioPlaylist.getVolume() > volume)
{
audioPlaylist.setVolume(audioPlaylist.getVolume() - 0.1F);
Thread.sleep(10L);
}
}
else if (volume > audioPlaylist.getVolume())
{
while (audioPlaylist.getVolume() < volume)
{
audioPlaylist.setVolume(audioPlaylist.getVolume() + 0.1F);
Thread.sleep(10L);
}
}
}
catch (InterruptedException ex)
{
}
audioPlaylist.setVolume(volume);
currThread = null;
}
});
currThread.start();
}
}

View File

@@ -1,11 +1,11 @@
package com.flaremicro.visualforecast;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import com.flaremicro.util.Util;
@@ -16,57 +16,96 @@ public class PropertyManager {
public PropertyManager() {
}
public PropertyManager(String filename) {
propFile = new File("./"+filename+".properties");
propFile = new File("./" + filename + ".properties");
}
public boolean load() {
Reader reader = null;
try
{
if (propFile.exists())
synchronized(prop){
InputStream reader = null;
try
{
reader = new FileReader(propFile);
prop.load(reader);
return true;
if (propFile.exists())
{
reader = new FileInputStream(propFile);
prop.load(reader);
return true;
}
return false;
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
Util.cleanClose(reader);
}
return false;
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
Util.cleanClose(reader);
}
return false;
}
public boolean store() {
Writer writer = null;
try
{
writer = new FileWriter(propFile);
prop.store(writer, "VisualForecast 1000 Properties file. Functional provider must be set for successful boot!");
return true;
synchronized(prop){
OutputStream writer = null;
try
{
writer = new FileOutputStream(propFile);
prop.store(writer, "VisualForecast 1000 Properties file. Functional provider must be set for successful boot!");
return true;
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
Util.cleanClose(writer);
}
return false;
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
Util.cleanClose(writer);
}
return false;
}
public String getString(String key, String fallback) {
String result = prop.getProperty(key, fallback);
System.out.println(result);
prop.setProperty(key, result);
return result;
}
public String getStringNoSet(String key, String fallback) {
String result = prop.getProperty(key, fallback);
return result;
}
public int getInteger(String key, int fallback) {
String resultString = getString(key, String.valueOf(fallback));
int resultInt = fallback;
try
{
resultInt = Integer.parseInt(resultString);
}
catch (NumberFormatException ex)
{
}
prop.setProperty(key, String.valueOf(resultInt));
return resultInt;
}
public void setString(String key, String value) {
if (value == null)
prop.remove(key);
else prop.setProperty(key, value);
}
public void setInteger(String key, int value) {
prop.setProperty(key, String.valueOf(value));
}
public File getFile(String key, File fallback) {
String resultString = getString(key, fallback.toString());
if (resultString == null)
return fallback;
else return new File(resultString);
}
}

View File

@@ -14,7 +14,6 @@ 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;
@@ -26,9 +25,9 @@ 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;
import com.flaremicro.visualforecast.displays.Display;
import com.flaremicro.visualforecast.displays.DisplayFactory;
import com.flaremicro.visualforecast.displays.impl.BootupDisplay;
import com.flaremicro.visualforecast.forecast.ForecastDetails;
import com.flaremicro.visualforecast.graphics.DrawingUtil;
import com.flaremicro.visualforecast.graphics.FontManager;
@@ -54,6 +53,8 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
private Rectangle exclusiveRedrawBound = null;
private Rectangle crawlBound = null;
private Rectangle currentBound = new Rectangle(0, 0, 0, 0);
private String currentTown = "";
private String currentForecast = "";
@@ -67,6 +68,10 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
private int stringIndex = -1;
private int currentCrawlStringWidth = 0;
DisplayFactory displayFactory;
AudioManager audioManager;
public RenderPanel(PropertyManager propManager) {
loadCrawlStrings();
this.addComponentListener(this);
@@ -74,6 +79,8 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
this.propManager = propManager;
font = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000.ttf"));
currentFlavour.initDisplay(this, null, ticks, iconAnimationTicks);
displayFactory = new DisplayFactory(propManager);
audioManager = new AudioManager(propManager);
//new Thread(new TickThread(this, 30)).start();
}
@@ -109,30 +116,8 @@ 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()))
@@ -152,7 +137,7 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
g2d.setColor(BG_PURPLE);
g2d.fillRect(0, 0, W, TOPBAR_HEIGHT);
g2d.setPaint(new GradientPaint(0, HEADERBAR_Y, BG_OORANGE, 0, HEADERBAR_Y + (HEADERBAR_HEIGHT + 10), BG_PURPLE));
g2d.setPaint(new GradientPaint(0, HEADERBAR_Y, BG_ORANGE, 0, HEADERBAR_Y + (HEADERBAR_HEIGHT + 10), BG_PURPLE));
g2d.shear(HEADERBAR_SHEAR, 0);
g2d.fillRect(-HEADERBAR_OFFSET, HEADERBAR_Y, HEADERBAR_WIDTH, HEADERBAR_HEIGHT);
@@ -160,7 +145,7 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
g2d.fillRect(W - TIMEBAR_WIDTH + TIMEBAR_OFFSET, TIMEBAR_Y, TIMEBAR_WIDTH, TIMEBAR_HEIGHT);
g2d.shear(-HEADERBAR_SHEAR, 0);
g2d.setPaint(new GradientPaint(0, TOPBAR_HEIGHT, BG_PURPLE, 0, MAINBAR_HEIGHT, BG_OORANGE));
g2d.setPaint(new GradientPaint(0, TOPBAR_HEIGHT, BG_PURPLE, 0, MAINBAR_HEIGHT, BG_ORANGE));
g2d.fillRect(0, TOPBAR_HEIGHT, W, MAINBAR_HEIGHT);
g2d.fillRect(0, TOPBAR_HEIGHT, W, MAINBAR_HEIGHT);
@@ -177,7 +162,7 @@ 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);
@@ -202,7 +187,7 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
//Clock and icon animations, should use repaint regions later
if (getWidth() > 0 && getHeight() > 0)
{
repaint(this.redrawBound);
requestRepaint(this.redrawBound);
}
}
if (this.currentFlavour != null)
@@ -218,10 +203,36 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
this.currentCrawlStringWidth = g.getFontMetrics(font.deriveFont(26F)).stringWidth(currentCrawlString);
g.dispose();
}
else if (this.currentCrawlString != null)
}
public void requestFullRepaint() {
currentBound = this.getBounds();
}
public void requestRepaint(Rectangle bound) {
if (currentBound.width == 0)
currentBound = new Rectangle(bound);
else currentBound.add(bound);
}
public void requestBoundedRepaint() {
requestRepaint(this.redrawBound);
}
public void requestExclusiveBoundedRepaint() {
requestRepaint(exclusiveRedrawBound);
}
public void performPaintIfNeeded() {
if (this.currentCrawlString != null)
{
this.crawlPosition-=2;
repaint(0, this.crawlBound.x, this.crawlBound.y, this.crawlBound.width, this.crawlBound.height);
this.crawlPosition -= 2;
requestRepaint(crawlBound);
}
if (this.currentBound.width != 0)
{
repaint(currentBound);
currentBound.width = 0;
}
}
@@ -245,7 +256,6 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
addRedrawBound(x, y, w, h, true);
}
@Override
public void componentResized(ComponentEvent e) {
loseRedrawRegion();
}
@@ -261,19 +271,16 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
this.currentFlavour.redrawRegionlost(this);
}
@Override
public void componentMoved(ComponentEvent e) {
// TODO Auto-generated method stub
}
@Override
public void componentShown(ComponentEvent e) {
// TODO Auto-generated method stub
}
@Override
public void componentHidden(ComponentEvent e) {
// TODO Auto-generated method stub
@@ -293,8 +300,25 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
}
public void nextDisplay() {
this.currentFlavour = new DayForecastDisplay();
if (this.currentFlavour instanceof BootupDisplay)
{
audioManager.startPlaylist();
}
this.currentFlavour = displayFactory.nextDisplay();
this.currentFlavour.initDisplay(this, forecastProvider, ticks, iconAnimationTicks);
File announcementDirectory = this.propManager.getFile("announcement-dir", new File("Announcements"));
if (announcementDirectory != null && announcementDirectory.isDirectory())
{
File file = new File(announcementDirectory, currentFlavour.getDisplayName() + ".wav");
if(file.exists())
{
this.audioManager.playAnnouncement(file);
}
}
this.loseRedrawRegion();
this.requestFullRepaint();
}
@@ -307,18 +331,6 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
this.currentForecast = currentForecast;
}
public void requestFullRepaint() {
repaint();
}
public void requestBoundedRepaint() {
repaint(redrawBound);
}
public void requestExclusiveBoundedRepaint() {
repaint(exclusiveRedrawBound);
}
private void loadCrawlStrings() {
File crawl = new File("./crawl.txt");
ArrayList<String> strings = new ArrayList<String>();
@@ -346,6 +358,10 @@ public class RenderPanel extends JPanel implements Tickable, ComponentListener {
this.crawlStrings = strings.toArray(new String[strings.size()]);
}
public void end() {
this.audioManager.end();
}
/*@Override
public void run() {
while (true)

View File

@@ -1,15 +1,22 @@
package com.flaremicro.visualforecast;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.util.Map;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import com.flaremicro.util.Util;
import com.flaremicro.visualforecast.api.ForecastProvider;
import com.flaremicro.visualforecast.api.ForecastProviderManager;
@@ -23,12 +30,15 @@ public class VisualForecastFrame extends JFrame implements WindowListener, KeyLi
private ForecastProviderManager forecastProviderManager;
private Executor executor;
private PropertyManager propertyManager = new PropertyManager();
private Timer timer;
//private Timer timer2;
private boolean isFullscreen = false;
/**
* Launch the application.
*/
public static void main(String[] args) {
final Map<String, String> arguments = Util.parseArgs(args, true);
EventQueue.invokeLater(new Runnable() {
public void run() {
try
@@ -36,8 +46,31 @@ public class VisualForecastFrame extends JFrame implements WindowListener, KeyLi
VisualForecastFrame frame = new VisualForecastFrame();
frame.setVisible(true);
frame.init();
if (arguments.containsKey("fullscreen"))
{
try
{
int index = Integer.parseInt(arguments.get("fullscreen"));
GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
if(index < 0 || devices.length < index)
{
JOptionPane.showMessageDialog(frame, arguments.get("fullscreen") + " does not exist as a screen index");
}
else
{
devices[index].setFullScreenWindow(frame);
}
}
catch (NumberFormatException ex)
{
JOptionPane.showMessageDialog(frame, arguments.get("fullscreen") + " is not a valid screen index");
}
}
//GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[1].setFullScreenWindow(frame);
frame.createBufferStrategy(2);
//frame.createBufferStrategy(2);
}
catch (Exception e)
{
@@ -50,6 +83,11 @@ public class VisualForecastFrame extends JFrame implements WindowListener, KeyLi
public void end() {
if (executor != null)
executor.end();
if (timer != null)
{
timer.stop();
}
renderPane.end();
if (forecastProviderManager != null)
forecastProviderManager.end();
propertyManager.store();
@@ -58,15 +96,21 @@ public class VisualForecastFrame extends JFrame implements WindowListener, KeyLi
public void init() {
executor = new Executor(this.renderPane, 30);
executor.begin();
timer = new Timer(33, new ActionListener() {
public void actionPerformed(ActionEvent e) {
renderPane.performPaintIfNeeded();
}
});
timer.start();
new Thread() {
public void run() {
forecastProviderManager = new ForecastProviderManager(renderPane);
propertyManager.load();
String forecastProvider = propertyManager.getString("forecast-provider-jar", "");
propertyManager.store();
ForecastProvider provider = forecastProviderManager.loadProvider(new File(forecastProvider));
renderPane.setForecastProvider(provider);
}
}.start();
@@ -76,66 +120,58 @@ public class VisualForecastFrame extends JFrame implements WindowListener, KeyLi
* Create the frame.
*/
public VisualForecastFrame() {
propertyManager.load();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 640 * 2, 480 * 2);
setBounds(100, 100, 640, 480);
renderPane = new RenderPanel(propertyManager);
renderPane.setBorder(null);
renderPane.setLayout(new BorderLayout(0, 0));
setContentPane(renderPane);
//renderPane.setBorder(null);
//renderPane.setLayout(new BorderLayout(0, 0));
add(renderPane);
setUndecorated(true);
addWindowListener(this);
addKeyListener(this);
}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent e) {
end();
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_F11)
{
@@ -154,7 +190,6 @@ public class VisualForecastFrame extends JFrame implements WindowListener, KeyLi
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub

View File

@@ -13,4 +13,6 @@ public interface Display {
public void drawBoundLimitedDisplay(RenderPanel renderer, Graphics2D g, Rectangle bounds, long ticks, int iconTicks);
public void redrawRegionlost(RenderPanel renderer);
public void notifyForecastProviderUpdate(RenderPanel renderPanel, ForecastProvider forecastProvider);
public String getDisplayName();
}

View File

@@ -0,0 +1,72 @@
package com.flaremicro.visualforecast.displays;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.flaremicro.visualforecast.PropertyManager;
import com.flaremicro.visualforecast.displays.impl.SevenDayForecastDisplay;
import com.flaremicro.visualforecast.displays.impl.HourlyForecastDisplay;
import com.flaremicro.visualforecast.displays.impl.MessageForecastDisplay;
import com.flaremicro.visualforecast.displays.impl.ThirtySixHourForecastDisplay;
public class DisplayFactory {
private static final int CURRENT_SELECTION = 1;
int currentIndex = -1;
String indexValue = "";
PropertyManager propertyManager;
private List<String> nameOrder = new ArrayList<String>();
private Map<String, Display> displays = new HashMap<String, Display>();
public DisplayFactory(PropertyManager propertyManager) {
this.propertyManager = propertyManager;
nameOrder.add(register(new MessageForecastDisplay()));
//nameOrder.add(register(new CurrentForecastDisplay()));
nameOrder.add(register(new ThirtySixHourForecastDisplay()));
nameOrder.add(register(new SevenDayForecastDisplay()));
nameOrder.add(register(new HourlyForecastDisplay()));
int selection = propertyManager.getInteger("current-display-version", -1);
String nameOrderString = getCurrentNameOrder();
if ((selection >= 0 && selection != CURRENT_SELECTION))
{
propertyManager.setInteger("current-display-version", CURRENT_SELECTION);
propertyManager.setString("display-selection", nameOrderString);
propertyManager.store();
}
else
{
System.out.println("got good order: " + propertyManager.getString("display-selection", "oh no"));
nameOrder.clear();
String[] s = propertyManager.getString("display-selection", nameOrderString).split(",");
nameOrder.addAll(Arrays.asList(s));
}
}
private String getCurrentNameOrder() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < nameOrder.size(); i++)
{
if (i != 0)
{
sb.append(",");
}
sb.append(nameOrder.get(i));
}
return sb.toString();
}
private String register(Display display) {
displays.put(display.getDisplayName(), display);
return display.getDisplayName();
}
public Display nextDisplay() {
currentIndex = (currentIndex + 1) % nameOrder.size();
return displays.get(nameOrder.get(currentIndex));
}
}

View File

@@ -1,55 +0,0 @@
package com.flaremicro.visualforecast.displays;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import com.flaremicro.visualforecast.RenderPanel;
import com.flaremicro.visualforecast.api.ForecastProvider;
import com.flaremicro.visualforecast.graphics.DrawingUtil;
import static com.flaremicro.visualforecast.graphics.RenderConstants.*;
public class TextDisplay implements Display {
public TextDisplay(String title, String scrollText) {
/*
int w2 = g2d.getFontMetrics().stringWidth("EXTREME WEATHER ADVISORY");
drawOutlinedString(g2d, (W >> 1) - (w2 >> 1), TOPBAR_HEIGHT + 48, "EXTREME WEATHER ADVISORY", Color.RED, Color.BLACK, 2);
g2d.setFont(font.deriveFont(30F));
for (int i = 0; i < testString.length; i++)
{
drawOutlinedString(g2d, 90, TOPBAR_HEIGHT + 78 + 25 * i, testString[i], Color.WHITE, Color.BLACK, 1);
}
*/
}
@Override
public void tick(RenderPanel renderer, long ticks, int iconTicks) {
}
@Override
public void initDisplay(RenderPanel renderer, ForecastProvider forecastProvider, long ticks, int iconTicks) {
}
@Override
public void drawDisplay(RenderPanel renderer, Graphics2D g2d, long ticks, int iconTicks) {
DrawingUtil.drawGradientRect(g2d, 60, TOPBAR_HEIGHT, W - 120, MAINBAR_HEIGHT, 20, BG_BLUE.brighter(), BG_BLUE.darker());
g2d.setColor(BG_BLUE.brighter());
g2d.drawRect(60 + STROKE_OFFSET, TOPBAR_HEIGHT + STROKE_OFFSET, W - 120 - STROKE_WIDTH, MAINBAR_HEIGHT - STROKE_WIDTH);
}
@Override
public void drawBoundLimitedDisplay(RenderPanel renderer, Graphics2D g2d, Rectangle bounds, long ticks, int iconTicks) {
}
@Override
public void redrawRegionlost(RenderPanel renderer) {
}
@Override
public void notifyForecastProviderUpdate(RenderPanel renderer, ForecastProvider forecastProvider) {
}
}

View File

@@ -1,4 +1,4 @@
package com.flaremicro.visualforecast.displays;
package com.flaremicro.visualforecast.displays.impl;
import java.awt.Color;
import java.awt.Font;
@@ -7,6 +7,7 @@ import java.awt.Rectangle;
import com.flaremicro.visualforecast.RenderPanel;
import com.flaremicro.visualforecast.api.ForecastProvider;
import com.flaremicro.visualforecast.displays.Display;
import com.flaremicro.visualforecast.graphics.DrawingUtil;
import com.flaremicro.visualforecast.graphics.FontManager;
import com.flaremicro.visualforecast.graphics.RenderConstants;
@@ -64,7 +65,7 @@ public class BootupDisplay implements Display {
IconProvider.drawIcon(g2d, IconProvider.INDEXED_ICONS[i], x, y, 80, iconTicks);
}
g2d.setFont(font.deriveFont(40F));
DrawingUtil.drawOutlinedString(g2d, RenderConstants.W / 2 - g2d.getFontMetrics().stringWidth("VisualForecast 1000") / 2, RenderConstants.H / 2, "VisualForecast 1000", Color.WHITE, Color.BLACK, 2);
//DrawingUtil.drawOutlinedString(g2d, RenderConstants.W / 2 - g2d.getFontMetrics().stringWidth("VisualForecast 1000") / 2, RenderConstants.H / 2, "VisualForecast 1000", Color.WHITE, Color.BLACK, 2);
}
else if (this.ticks > 90)
{
@@ -102,4 +103,9 @@ public class BootupDisplay implements Display {
this.forecastReady = provider.isForecastReady();
}
}
@Override
public String getDisplayName() {
return "bootup";
}
}

View File

@@ -0,0 +1,180 @@
package com.flaremicro.visualforecast.displays.impl;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import com.flaremicro.visualforecast.RenderPanel;
import com.flaremicro.visualforecast.api.ForecastProvider;
import com.flaremicro.visualforecast.displays.Display;
import com.flaremicro.visualforecast.graphics.DrawingUtil;
import com.flaremicro.visualforecast.graphics.FontManager;
import static com.flaremicro.visualforecast.graphics.RenderConstants.*;
public class CurrentForecastDisplay implements Display {
private String[] lines = new String[0];
private Font font;
private int stringOffset = 0;
private int ticksBeforeChange = 0;
public CurrentForecastDisplay() {
font = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000.ttf")).deriveFont(30F);
/*
int w2 = g2d.getFontMetrics().stringWidth("EXTREME WEATHER ADVISORY");
drawOutlinedString(g2d, (W >> 1) - (w2 >> 1), TOPBAR_HEIGHT + 48, "EXTREME WEATHER ADVISORY", Color.RED, Color.BLACK, 2);
g2d.setFont(font.deriveFont(30F));
for (int i = 0; i < testString.length; i++)
{
drawOutlinedString(g2d, 90, TOPBAR_HEIGHT + 78 + 25 * i, testString[i], Color.WHITE, Color.BLACK, 1);
}
*/
}
@Override
public void tick(RenderPanel renderer, long ticks, int iconTicks) {
ticksBeforeChange--;
if (ticksBeforeChange <= 0)
{
stringOffset += 9;
if (stringOffset < lines.length)
{
ticksBeforeChange = 200;
renderer.requestExclusiveBoundedRepaint();
}
else
{
renderer.nextDisplay();
}
}
}
@Override
public void initDisplay(RenderPanel renderer, ForecastProvider forecastProvider, long ticks, int iconTicks) {
ticksBeforeChange = 200;
stringOffset = 0;
String test = "*IMPORTANT NOTICE*\n*THIS BETA IS UNFINISHED*\n\nThis is a Beta version of the VisualForeast 1000! Many things are not finished, and only the hourly and 7 day forecasts are ready. There will be a lot more to come!\nPlease note that there are some issues with data collection from Environment Canada resulting in missing or potentially incorrect information around midnight hours. This will be fixed as the project continues and the disclaimer will be removed.";
ArrayList<String> linesList = new ArrayList<String>();
renderer.setCurrentForecast("Current Conditions");
renderer.setCurrentTown("TOWN NAME HERE");
BufferedImage disposableImage = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g = disposableImage.createGraphics();
FontMetrics f = g.getFontMetrics(font);
String[] lines = test.split("\n");
for (int i = 0; i < lines.length; i++)
{
splitText(lines[i], W - 150 - STROKE_WIDTH, f, linesList);
//if(words[i])
}
g.dispose();
disposableImage.flush();
redrawRegionlost(renderer);
this.lines = linesList.toArray(new String[0]);
}
private void splitText(String text, int maxWidth, FontMetrics fontMetrics, ArrayList<String> lineList) {
text = text.trim();
//this.text.add(text);
if (fontMetrics.stringWidth(text) <= maxWidth)
lineList.add(text);
else
{
while (text.length() > 0)
{
int idx = binSearch(text, fontMetrics, maxWidth, 1, text.length());
if (idx <= 0)
break;
String texPart = text.substring(0, idx).trim();
if (fontMetrics.stringWidth(text.substring(0, Math.min(text.length(), idx + 1))) > maxWidth && texPart.contains(" "))
{
idx = texPart.lastIndexOf(" ");
texPart = texPart.substring(0, idx);
}
lineList.add(texPart);
text = text.substring(idx).trim();
}
}
}
private static int binSearch(String string, FontMetrics fontMetrics, int key, int low, int high) {
int index = 0;
while (low <= high)
{
int mid = low + ((high - low) / 2);
int midmetric = fontMetrics.stringWidth(string.substring(0, mid));
if (midmetric < key)
{
low = mid + 1;
index = mid;
}
else if (midmetric > key)
{
high = mid - 1;
}
else if (midmetric == key)
{
index = mid;
break;
}
}
return index;
}
@Override
public void drawDisplay(RenderPanel renderer, Graphics2D g2d, long ticks, int iconTicks) {
}
@Override
public void drawBoundLimitedDisplay(RenderPanel renderer, Graphics2D g2d, Rectangle bounds, long ticks, int iconTicks) {
DrawingUtil.drawGradientRect(g2d, 60, TOPBAR_HEIGHT, W - 120, MAINBAR_HEIGHT, 20, BG_BLUE.darker(), BG_BLUE.brighter());
g2d.setFont(font);
FontMetrics fontMetrics = g2d.getFontMetrics();
g2d.setColor(BG_BLUE.darker());
g2d.drawRect(60 + STROKE_OFFSET, TOPBAR_HEIGHT + STROKE_OFFSET, W - 120 - STROKE_WIDTH, MAINBAR_HEIGHT - STROKE_WIDTH);
for (int i = 0; i < Math.min(9, lines.length - this.stringOffset); i++)
{
if (lines[i + stringOffset].startsWith("*") && lines[i].endsWith("*"))
{
String line = lines[i + stringOffset].substring(1, lines[i + stringOffset].length() - 1);
DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, "*", Color.WHITE, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET + (W - 150 - STROKE_WIDTH) / 2 - fontMetrics.stringWidth(line) / 2, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, line, Color.WHITE, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, W - 95 - STROKE_WIDTH, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, "*", Color.WHITE, Color.BLACK, 2);
}
else if (lines[i + stringOffset].startsWith("[") && lines[i].endsWith("]"))
{
String line = lines[i + stringOffset].substring(1, lines[i + stringOffset].length() - 1);
DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET + (W - 150 - STROKE_WIDTH) / 2 - fontMetrics.stringWidth(line) / 2, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, line, Color.WHITE, Color.BLACK, 2);
}
else DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, lines[i + stringOffset], Color.WHITE, Color.BLACK, 2);
}
}
@Override
public void redrawRegionlost(RenderPanel renderer) {
renderer.addRedrawBound(TOPBAR_HEIGHT, W - 120, MAINBAR_HEIGHT, 20);
}
@Override
public void notifyForecastProviderUpdate(RenderPanel renderer, ForecastProvider forecastProvider) {
}
@Override
public String getDisplayName() {
return "current";
}
}

View File

@@ -0,0 +1,349 @@
package com.flaremicro.visualforecast.displays.impl;
import static com.flaremicro.visualforecast.graphics.RenderConstants.BG_BLUE;
import static com.flaremicro.visualforecast.graphics.RenderConstants.MAINBAR_HEIGHT;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import com.flaremicro.visualforecast.RenderPanel;
import com.flaremicro.visualforecast.api.ForecastProvider;
import com.flaremicro.visualforecast.displays.Display;
import com.flaremicro.visualforecast.forecast.ForecastDetails;
import com.flaremicro.visualforecast.forecast.HourlyForecast;
import com.flaremicro.visualforecast.forecast.TownForecast;
import com.flaremicro.visualforecast.forecast.ValueCheck;
import com.flaremicro.visualforecast.graphics.DrawingUtil;
import com.flaremicro.visualforecast.graphics.FontManager;
import com.flaremicro.visualforecast.graphics.RenderConstants;
import com.flaremicro.visualforecast.icons.IconProvider;
public class HourlyForecastDisplay implements Display {
private Font font;
private Font smallFont;
private ForecastDetails details;
private TownForecast currentTown = null;
private int townIndex;
private int ticksBeforeChange = 200;
// private int animationTicks = -1;
private byte[] windchill = null;
private byte[] tempval = null;
private float[] percipval = null;
DateFormat simpleDateFormat = new SimpleDateFormat("ha");
BufferedImage lastBuffer = null;
public HourlyForecastDisplay() {
font = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000.ttf"));
smallFont = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000 Small.ttf"));
}
@Override
public void tick(RenderPanel renderer, long ticks, int iconTicks) {
ticksBeforeChange--;
if (ticksBeforeChange <= 0)
{
ticksBeforeChange = 200;
do
{
townIndex++;
if (details == null || townIndex >= details.getTownForecast().length)
{
renderer.nextDisplay();
return;
}
this.currentTown = details.getTownForecast()[townIndex];
}
while (this.currentTown == null || !currentTown.isDisplaySupported(this.getDisplayName()) || currentTown.getHourlyForecast() == null || currentTown.getHourlyForecast().length == 0);
renderer.setCurrentTown(currentTown.getTownName());
setGraphValues(currentTown);
renderer.requestFullRepaint();
}
}
public void setGraphValues(TownForecast town) {
if (town != null)
{
HourlyForecast[] forecast = town.getHourlyForecast();
if (forecast != null && forecast.length > 0)
{
int size = Math.min(12, forecast.length);
windchill = new byte[size];
tempval = new byte[size];
percipval = new float[size];
for (int i = 0; i < size; i++)
{
windchill[i] = forecast[i].windChill;
tempval[i] = forecast[i].temp;
percipval[i] = forecast[i].percip;
}
}
}
}
@Override
public void initDisplay(RenderPanel renderer, ForecastProvider forecastProvider, long ticks, int iconTicks) {
this.details = forecastProvider != null ? forecastProvider.getForecast() : null;
renderer.setCurrentForecast("12 Hour Forecast");
if (details == null || details.getTownForecast() == null || details.getTownForecast().length <= 0)
this.details = null;
else
{
townIndex = 0;
currentTown = details.getTownForecast()[townIndex];
renderer.setCurrentTown(currentTown.getTownName());
setGraphValues(currentTown);
}
redrawRegionlost(renderer);
}
@Override
public void drawDisplay(RenderPanel renderer, Graphics2D g2d, long ticks, int iconTicks) {
HourlyForecast[] forecast = currentTown.getHourlyForecast();
if (forecast == null)
return;
g2d.setColor(RenderConstants.BG_BLUE);
//g2d.fillRect(RenderConstants.SIDE_OFFSET, RenderConstants.TOPBAR_HEIGHT + 20, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2, RenderConstants.MAINBAR_HEIGHT - 40);
DrawingUtil.drawGradientRect(g2d, RenderConstants.SIDE_OFFSET, RenderConstants.TOPBAR_HEIGHT + 20, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2, RenderConstants.MAINBAR_HEIGHT - 40, 15, BG_BLUE.darker(), BG_BLUE.brighter());
int min = minTemp(forecast);
int max = maxTemp(forecast);
int range = max - min;
if (range == 0)
{
min -= 1;
max += 1;
range = 2;
}
g2d.setPaint(new GradientPaint(0, RenderConstants.TOPBAR_HEIGHT + 40, RenderConstants.BG_ORANGE, 0, RenderConstants.MAINBAR_HEIGHT, RenderConstants.BG_PURPLE));
g2d.fillRect(RenderConstants.SIDE_OFFSET + 40, RenderConstants.TOPBAR_HEIGHT + 40, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60, RenderConstants.MAINBAR_HEIGHT - 124);
g2d.setColor(Color.BLACK);
g2d.drawRect(RenderConstants.SIDE_OFFSET, RenderConstants.TOPBAR_HEIGHT + 20, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2, RenderConstants.MAINBAR_HEIGHT - 40);
/*float lineHeight = (RenderConstants.MAINBAR_HEIGHT - 104) / 9F;
for(int i = 0; i < 10; i++)
{
g2d.drawLine(RenderConstants.SIDE_OFFSET + 36, (int)(RenderConstants.TOPBAR_HEIGHT + 40 + lineHeight * i), RenderConstants.W - RenderConstants.SIDE_OFFSET - 36, (int) (RenderConstants.TOPBAR_HEIGHT + 40 + lineHeight * i));
}*/
g2d.setFont(smallFont.deriveFont(20F));
FontMetrics fm = g2d.getFontMetrics();
DrawingUtil.drawOutlinedString(g2d, 100, RenderConstants.TOPBAR_HEIGHT + 35, "Temperature\u00B0c", Color.RED, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, 260, RenderConstants.TOPBAR_HEIGHT + 35, "Wind Chill\u00B0c", Color.WHITE, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, 410, RenderConstants.TOPBAR_HEIGHT + 35, "Precipitation%", Color.CYAN, Color.BLACK, 2);
g2d.setFont(font.deriveFont(20F));
String minText = min + "\u00B0";
String maxText = max + "\u00B0";
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 38 - fm.stringWidth(maxText), RenderConstants.TOPBAR_HEIGHT + 53, maxText, Color.YELLOW, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 38 - fm.stringWidth(minText), RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 92, minText, Color.YELLOW, Color.BLACK, 2);
g2d.setFont(font.deriveFont(20F));
g2d.setColor(RenderConstants.BG_ORANGE.darker());
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40, (RenderConstants.TOPBAR_HEIGHT + 50), (RenderConstants.W - RenderConstants.SIDE_OFFSET - 20), (RenderConstants.TOPBAR_HEIGHT + 50));
g2d.setColor(RenderConstants.BG_PURPLE.brighter());
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40, RenderConstants.TOPBAR_HEIGHT + 50 + RenderConstants.MAINBAR_HEIGHT - 144, (RenderConstants.W - RenderConstants.SIDE_OFFSET - 20), RenderConstants.TOPBAR_HEIGHT + 50 + RenderConstants.MAINBAR_HEIGHT - 144);
//BlackLines
g2d.setFont(smallFont.deriveFont(20F));
if (max > 0 && min < 0)
{
int nextTemp = (RenderConstants.TOPBAR_HEIGHT + RenderConstants.MAINBAR_HEIGHT - 94) + (int) (((min) / (float) range) * (RenderConstants.MAINBAR_HEIGHT - 144));
g2d.setColor(Color.LIGHT_GRAY);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40, nextTemp, RenderConstants.W - RenderConstants.SIDE_OFFSET - 20, nextTemp);
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 - fm.stringWidth("0\u00B0"), nextTemp + 4, "0\u00B0", Color.YELLOW, Color.BLACK, 2);
}
int slotWidth = (RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60) / 12;
g2d.setClip(RenderConstants.SIDE_OFFSET + 40, RenderConstants.TOPBAR_HEIGHT + 40, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60, RenderConstants.MAINBAR_HEIGHT - 124);
g2d.translate(RenderConstants.SIDE_OFFSET + 40, RenderConstants.TOPBAR_HEIGHT + RenderConstants.MAINBAR_HEIGHT - 94);
g2d.translate(2, 2);
g2d.setColor(Color.BLACK);
this.graphTemp(g2d, this.windchill, min, slotWidth, range, RenderConstants.MAINBAR_HEIGHT - 144);
g2d.setColor(Color.WHITE);
g2d.translate(-2, -2);
this.graphTemp(g2d, this.windchill, min, slotWidth, range, RenderConstants.MAINBAR_HEIGHT - 144);
g2d.translate(2, 2);
g2d.setColor(Color.BLACK);
this.graphPercent(g2d, this.percipval, slotWidth, 100F, RenderConstants.MAINBAR_HEIGHT - 144);
g2d.setColor(Color.CYAN);
g2d.translate(-2, -2);
this.graphPercent(g2d, this.percipval, slotWidth, 100F, RenderConstants.MAINBAR_HEIGHT - 144);
g2d.translate(2, 2);
g2d.setColor(Color.BLACK);
this.graphTemp(g2d, this.tempval, min, slotWidth, range, RenderConstants.MAINBAR_HEIGHT - 144);
g2d.setColor(Color.RED);
g2d.translate(-2, -2);
this.graphTemp(g2d, this.tempval, min, slotWidth, range, RenderConstants.MAINBAR_HEIGHT - 144);
g2d.translate(-RenderConstants.SIDE_OFFSET - 40, 94 - RenderConstants.TOPBAR_HEIGHT - RenderConstants.MAINBAR_HEIGHT);
g2d.setClip(null);
g2d.setStroke(new BasicStroke(2));
g2d.setColor(Color.BLACK);
g2d.drawRect(RenderConstants.SIDE_OFFSET + 40, RenderConstants.TOPBAR_HEIGHT + 40, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60, RenderConstants.MAINBAR_HEIGHT - 124);
for (int i = 0; i < Math.min(12, forecast.length); i++)
{
String timeString = simpleDateFormat.format(forecast[i].hour);
timeString = timeString.substring(0, timeString.length() - 1);
if ((i % 2) == 0)
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) - fm.stringWidth(timeString) / 2, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 70, timeString, Color.YELLOW, Color.BLACK, 2);
else DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) - fm.stringWidth(timeString) / 2, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 60, timeString, Color.YELLOW, Color.BLACK, 2);
IconProvider.drawIcon(g2d, IconProvider.INDEXED_ICONS[forecast[i].iconId], RenderConstants.SIDE_OFFSET + 45 + i * slotWidth, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 55, slotWidth - 10, iconTicks);
}
lastBuffer = renderer.getSnapshot().getSubimage(RenderConstants.SIDE_OFFSET - 1, RenderConstants.TOPBAR_HEIGHT + 19, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 + 2, RenderConstants.MAINBAR_HEIGHT - 38);
lastBuffer.setAccelerationPriority(1);
}
public int minTemp(HourlyForecast[] forecast) {
int min = Integer.MAX_VALUE;
for (int i = 0; i < forecast.length; i++)
{
int currMin;
if (ValueCheck.valueNoData(forecast[i].windChill) && ValueCheck.valueNoData(forecast[i].temp))
continue;
else if (ValueCheck.valueNoData(forecast[i].windChill))
currMin = forecast[i].temp;
else if (ValueCheck.valueNoData(forecast[i].temp))
currMin = forecast[i].windChill;
else currMin = Math.min(forecast[i].temp, forecast[i].windChill);
if (currMin < min)
min = currMin;
}
return min;
}
public int maxTemp(HourlyForecast[] forecast) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < forecast.length; i++)
{
int currMax;
if (ValueCheck.valueNoData(forecast[i].windChill) && ValueCheck.valueNoData(forecast[i].temp))
continue;
else if (ValueCheck.valueNoData(forecast[i].windChill))
currMax = forecast[i].temp;
else if (ValueCheck.valueNoData(forecast[i].temp))
currMax = forecast[i].windChill;
else currMax = Math.max(forecast[i].temp, forecast[i].windChill);
if (currMax > max)
max = currMax;
}
return max;
}
@Override
public void drawBoundLimitedDisplay(RenderPanel renderer, Graphics2D g2d, Rectangle bounds, long ticks, int iconTicks) {
HourlyForecast[] forecast = currentTown.getHourlyForecast();
if (forecast == null)
return;
if (this.lastBuffer != null)
{
g2d.drawImage(lastBuffer, RenderConstants.SIDE_OFFSET - 1, RenderConstants.TOPBAR_HEIGHT + 19, renderer);
}
int slotWidth = (RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60) / 12;
for (int i = 0; i < Math.min(12, forecast.length); i++)
{
if (IconProvider.INDEXED_ICONS[forecast[i].iconId].isAnimated())
IconProvider.drawIcon(g2d, IconProvider.INDEXED_ICONS[forecast[i].iconId], RenderConstants.SIDE_OFFSET + 45 + i * slotWidth, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 55, slotWidth - 10, iconTicks);
}
}
public void graphTemp(Graphics2D g2d, byte[] tempVal, int min, int slotWidth, float range, float multiplier) {
int lastTemp = ValueCheck.NO_DATA_INT;
for (int i = 0; i < tempVal.length; i++)
{
if (ValueCheck.valueNoData(tempVal[i]))
{
lastTemp = ValueCheck.NO_DATA_INT;
continue;
}
int nextTemp = -(int) (((tempVal[i] - min) / range) * multiplier);
if (i == 0)
{
lastTemp = nextTemp;
}
if (ValueCheck.valueNoData(lastTemp))
{
lastTemp = nextTemp;
continue;
}
g2d.drawLine(slotWidth / 2 + (slotWidth * (i - 1)), lastTemp, slotWidth / 2 + (slotWidth * i), nextTemp);
if (i == Math.min(12, tempVal.length) - 1)
{
g2d.drawLine(slotWidth / 2 + (slotWidth * (i)), nextTemp, slotWidth / 2 + (slotWidth * (i + 1)), nextTemp);
}
lastTemp = nextTemp;
}
}
public void graphPercent(Graphics2D g2d, float[] precVal, int slotWidth, float range, float multiplier) {
int lastTemp = ValueCheck.NO_DATA_INT;
for (int i = 0; i < tempval.length; i++)
{
if (ValueCheck.valueNoData(precVal[i]))
{
lastTemp = ValueCheck.NO_DATA_INT;
continue;
}
int nextTemp = -(int) (((precVal[i]) / range) * multiplier);
if (i == 0)
{
lastTemp = nextTemp;
}
if (ValueCheck.valueNoData(lastTemp))
{
lastTemp = nextTemp;
continue;
}
g2d.drawLine(slotWidth / 2 + (slotWidth * (i - 1)), lastTemp, slotWidth / 2 + (slotWidth * i), nextTemp);
if (i == Math.min(12, precVal.length) - 1)
{
g2d.drawLine(slotWidth / 2 + (slotWidth * (i)), nextTemp, slotWidth / 2 + (slotWidth * (i + 1)), nextTemp);
}
lastTemp = nextTemp;
}
}
@Override
public void redrawRegionlost(RenderPanel renderer) {
int slotWidth = (RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60) / 12;
renderer.addRedrawBound(RenderConstants.SIDE_OFFSET + 45, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 55, slotWidth * 12 - 10, slotWidth - 10);
}
@Override
public void notifyForecastProviderUpdate(RenderPanel renderer, ForecastProvider forecastProvider) {
}
@Override
public String getDisplayName() {
return "hourly";
}
}

View File

@@ -0,0 +1,180 @@
package com.flaremicro.visualforecast.displays.impl;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import com.flaremicro.visualforecast.RenderPanel;
import com.flaremicro.visualforecast.api.ForecastProvider;
import com.flaremicro.visualforecast.displays.Display;
import com.flaremicro.visualforecast.graphics.DrawingUtil;
import com.flaremicro.visualforecast.graphics.FontManager;
import static com.flaremicro.visualforecast.graphics.RenderConstants.*;
public class MessageForecastDisplay implements Display {
private String[] lines = new String[0];
private Font font;
private int stringOffset = 0;
private int ticksBeforeChange = 0;
public MessageForecastDisplay() {
font = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000.ttf")).deriveFont(30F);
/*
int w2 = g2d.getFontMetrics().stringWidth("EXTREME WEATHER ADVISORY");
drawOutlinedString(g2d, (W >> 1) - (w2 >> 1), TOPBAR_HEIGHT + 48, "EXTREME WEATHER ADVISORY", Color.RED, Color.BLACK, 2);
g2d.setFont(font.deriveFont(30F));
for (int i = 0; i < testString.length; i++)
{
drawOutlinedString(g2d, 90, TOPBAR_HEIGHT + 78 + 25 * i, testString[i], Color.WHITE, Color.BLACK, 1);
}
*/
}
@Override
public void tick(RenderPanel renderer, long ticks, int iconTicks) {
ticksBeforeChange--;
if (ticksBeforeChange <= 0)
{
stringOffset += 9;
if (stringOffset < lines.length)
{
ticksBeforeChange = 200;
renderer.requestExclusiveBoundedRepaint();
}
else
{
renderer.nextDisplay();
}
}
}
@Override
public void initDisplay(RenderPanel renderer, ForecastProvider forecastProvider, long ticks, int iconTicks) {
ticksBeforeChange = 200;
stringOffset = 0;
String test = "*IMPORTANT NOTICE*\n*THIS BETA IS UNFINISHED*\n\nThis is a Beta version of the VisualForeast 1000! Many things are not finished, and only the hourly and 7 day forecasts are ready. There will be a lot more to come!\nPlease note that there are some issues with data collection from Environment Canada resulting in missing or potentially incorrect information around midnight hours. This will be fixed as the project continues and the disclaimer will be removed.";
ArrayList<String> linesList = new ArrayList<String>();
renderer.setCurrentForecast("Welcome to the");
renderer.setCurrentTown("VisualForecast 1000");
BufferedImage disposableImage = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g = disposableImage.createGraphics();
FontMetrics f = g.getFontMetrics(font);
String[] lines = test.split("\n");
for (int i = 0; i < lines.length; i++)
{
splitText(lines[i], W - 150 - STROKE_WIDTH, f, linesList);
//if(words[i])
}
g.dispose();
disposableImage.flush();
redrawRegionlost(renderer);
this.lines = linesList.toArray(new String[0]);
}
private void splitText(String text, int maxWidth, FontMetrics fontMetrics, ArrayList<String> lineList) {
text = text.trim();
//this.text.add(text);
if (fontMetrics.stringWidth(text) <= maxWidth)
lineList.add(text);
else
{
while (text.length() > 0)
{
int idx = binSearch(text, fontMetrics, maxWidth, 1, text.length());
if (idx <= 0)
break;
String texPart = text.substring(0, idx).trim();
if (fontMetrics.stringWidth(text.substring(0, Math.min(text.length(), idx + 1))) > maxWidth && texPart.contains(" "))
{
idx = texPart.lastIndexOf(" ");
texPart = texPart.substring(0, idx);
}
lineList.add(texPart);
text = text.substring(idx).trim();
}
}
}
private static int binSearch(String string, FontMetrics fontMetrics, int key, int low, int high) {
int index = 0;
while (low <= high)
{
int mid = low + ((high - low) / 2);
int midmetric = fontMetrics.stringWidth(string.substring(0, mid));
if (midmetric < key)
{
low = mid + 1;
index = mid;
}
else if (midmetric > key)
{
high = mid - 1;
}
else if (midmetric == key)
{
index = mid;
break;
}
}
return index;
}
@Override
public void drawDisplay(RenderPanel renderer, Graphics2D g2d, long ticks, int iconTicks) {
}
@Override
public void drawBoundLimitedDisplay(RenderPanel renderer, Graphics2D g2d, Rectangle bounds, long ticks, int iconTicks) {
DrawingUtil.drawGradientRect(g2d, 60, TOPBAR_HEIGHT, W - 120, MAINBAR_HEIGHT, 20, BG_BLUE.darker(), BG_BLUE.brighter());
g2d.setFont(font);
FontMetrics fontMetrics = g2d.getFontMetrics();
g2d.setColor(BG_BLUE.darker());
g2d.drawRect(60 + STROKE_OFFSET, TOPBAR_HEIGHT + STROKE_OFFSET, W - 120 - STROKE_WIDTH, MAINBAR_HEIGHT - STROKE_WIDTH);
for (int i = 0; i < Math.min(9, lines.length - this.stringOffset); i++)
{
if (lines[i + stringOffset].startsWith("*") && lines[i].endsWith("*"))
{
String line = lines[i + stringOffset].substring(1, lines[i + stringOffset].length() - 1);
DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, "*", Color.WHITE, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET + (W - 150 - STROKE_WIDTH) / 2 - fontMetrics.stringWidth(line) / 2, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, line, Color.WHITE, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, W - 95 - STROKE_WIDTH, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, "*", Color.WHITE, Color.BLACK, 2);
}
else if (lines[i + stringOffset].startsWith("[") && lines[i].endsWith("]"))
{
String line = lines[i + stringOffset].substring(1, lines[i + stringOffset].length() - 1);
DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET + (W - 150 - STROKE_WIDTH) / 2 - fontMetrics.stringWidth(line) / 2, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, line, Color.WHITE, Color.BLACK, 2);
}
else DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, lines[i + stringOffset], Color.WHITE, Color.BLACK, 2);
}
}
@Override
public void redrawRegionlost(RenderPanel renderer) {
renderer.addRedrawBound(TOPBAR_HEIGHT, W - 120, MAINBAR_HEIGHT, 20);
}
@Override
public void notifyForecastProviderUpdate(RenderPanel renderer, ForecastProvider forecastProvider) {
}
@Override
public String getDisplayName() {
return "message";
}
}

View File

@@ -1,4 +1,4 @@
package com.flaremicro.visualforecast.displays;
package com.flaremicro.visualforecast.displays.impl;
import static com.flaremicro.visualforecast.graphics.RenderConstants.MAINBAR_HEIGHT;
@@ -16,6 +16,7 @@ import java.util.Locale;
import com.flaremicro.visualforecast.RenderPanel;
import com.flaremicro.visualforecast.api.ForecastProvider;
import com.flaremicro.visualforecast.displays.Display;
import com.flaremicro.visualforecast.forecast.DayForecast;
import com.flaremicro.visualforecast.forecast.ForecastDetails;
import com.flaremicro.visualforecast.forecast.TownForecast;
@@ -25,7 +26,7 @@ import com.flaremicro.visualforecast.graphics.FontManager;
import com.flaremicro.visualforecast.graphics.RenderConstants;
import com.flaremicro.visualforecast.icons.IconProvider;
public class DayForecastDisplay implements Display {
public class SevenDayForecastDisplay implements Display {
private int dayOffset = 0;
private Font font;
private Font smallFont;
@@ -40,14 +41,19 @@ public class DayForecastDisplay implements Display {
private int ticksBeforeChange = 200;
private int animationTicks = -1;
public DayForecastDisplay() {
public SevenDayForecastDisplay() {
font = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000.ttf"));
smallFont = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000 Small.ttf"));
}
//TODO improve
@Override
public void tick(RenderPanel renderer, long ticks, int iconTicks) {
if (animationTicks >= 0)
if(details == null || details.getTownForecast() == null){
renderer.nextDisplay();
return;
}
else if (animationTicks >= 0)
{
animationTicks += 8;
if (animationTicks > RenderConstants.W - 60)
@@ -70,19 +76,23 @@ public class DayForecastDisplay implements Display {
dayOffset = dayOffset + 4;
if (dayOffset >= 8)
{
dayOffset = 0;
townIndex++;
if (townIndex >= details.getTownForecast().length)
do
{
renderer.nextDisplay();
return;
}
else
{
previousTown = currentTown;
currentTown = details.getTownForecast()[townIndex];
renderer.setCurrentTown(currentTown.getTownName());
dayOffset = 0;
townIndex++;
if (townIndex >= details.getTownForecast().length)
{
renderer.nextDisplay();
return;
}
else
{
previousTown = currentTown;
currentTown = details.getTownForecast()[townIndex];
renderer.setCurrentTown(currentTown.getTownName());
}
}
while (this.currentTown != null && !this.currentTown.isDisplaySupported(this.getDisplayName()));
}
animationTicks = 0;
@@ -225,7 +235,7 @@ public class DayForecastDisplay implements Display {
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));
@@ -296,4 +306,9 @@ public class DayForecastDisplay implements Display {
public void notifyForecastProviderUpdate(RenderPanel renderer, ForecastProvider forecastProvider) {
}
@Override
public String getDisplayName() {
return "7-day";
}
}

View File

@@ -1,4 +1,4 @@
package com.flaremicro.visualforecast.displays;
package com.flaremicro.visualforecast.displays.impl;
import static com.flaremicro.visualforecast.graphics.RenderConstants.MAINBAR_HEIGHT;
@@ -16,6 +16,7 @@ import java.util.Locale;
import com.flaremicro.visualforecast.RenderPanel;
import com.flaremicro.visualforecast.api.ForecastProvider;
import com.flaremicro.visualforecast.displays.Display;
import com.flaremicro.visualforecast.forecast.DayForecast;
import com.flaremicro.visualforecast.forecast.ForecastDetails;
import com.flaremicro.visualforecast.forecast.TownForecast;
@@ -25,7 +26,7 @@ import com.flaremicro.visualforecast.graphics.FontManager;
import com.flaremicro.visualforecast.graphics.RenderConstants;
import com.flaremicro.visualforecast.icons.IconProvider;
public class DayForecastDisplayOldAnimation implements Display {
public class SevenDayForecastDisplayOldAnimation implements Display {
private int dayOffset = 0;
private Font font;
private Font smallFont;
@@ -39,7 +40,7 @@ public class DayForecastDisplayOldAnimation implements Display {
private int ticksBeforeChange = 200;
private int animationTicks = -1;
public DayForecastDisplayOldAnimation() {
public SevenDayForecastDisplayOldAnimation() {
font = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000.ttf"));
smallFont = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000 Small.ttf"));
}
@@ -263,4 +264,9 @@ public class DayForecastDisplayOldAnimation implements Display {
@Override
public void notifyForecastProviderUpdate(RenderPanel renderer, ForecastProvider forecastProvider) {
}
@Override
public String getDisplayName() {
return "7-day-old";
}
}

View File

@@ -0,0 +1,232 @@
package com.flaremicro.visualforecast.displays.impl;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import com.flaremicro.visualforecast.RenderPanel;
import com.flaremicro.visualforecast.api.ForecastProvider;
import com.flaremicro.visualforecast.displays.Display;
import com.flaremicro.visualforecast.forecast.ForecastDetails;
import com.flaremicro.visualforecast.forecast.TownForecast;
import com.flaremicro.visualforecast.graphics.DrawingUtil;
import com.flaremicro.visualforecast.graphics.FontManager;
import static com.flaremicro.visualforecast.graphics.RenderConstants.*;
public class ThirtySixHourForecastDisplay implements Display {
private int townIndex = 0;
private TownForecast[] townForecasts;
private String[] lines = new String[0];
private Font font;
private int stringOffset = 0;
private int ticksBeforeChange = 0;
public ThirtySixHourForecastDisplay() {
font = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000.ttf")).deriveFont(30F);
/*
int w2 = g2d.getFontMetrics().stringWidth("EXTREME WEATHER ADVISORY");
drawOutlinedString(g2d, (W >> 1) - (w2 >> 1), TOPBAR_HEIGHT + 48, "EXTREME WEATHER ADVISORY", Color.RED, Color.BLACK, 2);
g2d.setFont(font.deriveFont(30F));
for (int i = 0; i < testString.length; i++)
{
drawOutlinedString(g2d, 90, TOPBAR_HEIGHT + 78 + 25 * i, testString[i], Color.WHITE, Color.BLACK, 1);
}
*/
}
@Override
public void tick(RenderPanel renderer, long ticks, int iconTicks) {
ticksBeforeChange--;
if (ticksBeforeChange <= 0)
{
stringOffset += 9;
if (stringOffset < lines.length)
{
ticksBeforeChange = 200;
renderer.requestExclusiveBoundedRepaint();
}
else
{
if(!setNextTown(renderer))
{
renderer.nextDisplay();
}
else
{
ticksBeforeChange = 200;
renderer.requestExclusiveBoundedRepaint();
}
}
}
}
@Override
public void initDisplay(RenderPanel renderer, ForecastProvider forecastProvider, long ticks, int iconTicks) {
ForecastDetails details = forecastProvider != null ? forecastProvider.getForecast() : null;
renderer.setCurrentForecast("36 Hour Detailed Forecast");
townIndex = -1;
if(details == null || details.getTownForecast() == null || details.getTownForecast().length <= 0)
{
renderer.nextDisplay();
return;
}
else
{
townForecasts = details.getTownForecast();
if(!setNextTown(renderer))
{
renderer.nextDisplay();
return;
}
}
}
public boolean setNextTown(RenderPanel renderer)
{
townIndex++;
if(townIndex >= townForecasts.length)
return false;
TownForecast town = townForecasts[townIndex];
if(!town.isDisplaySupported(getDisplayName()) || town.getDetailedForecast() == null || town.getDetailedForecast().length <= 0)
{
return setNextTown(renderer);
}
ticksBeforeChange = 200;
stringOffset = 0;
StringBuilder forecastBuilder = new StringBuilder();
for(int i = 0; i < town.getDetailedForecast().length; i++)
{
if(i > 0)
forecastBuilder.append("\n\n");
forecastBuilder.append(town.getDetailedForecast()[i].title + ":\n");
forecastBuilder.append(town.getDetailedForecast()[i].status);
}
ArrayList<String> linesList = new ArrayList<String>();
renderer.setCurrentTown(town.getTownName());
BufferedImage disposableImage = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g = disposableImage.createGraphics();
FontMetrics f = g.getFontMetrics(font);
String[] lines = forecastBuilder.toString().split("\n");
for (int i = 0; i < lines.length; i++)
{
splitText(lines[i], W - 150 - STROKE_WIDTH, f, linesList);
//if(words[i])
}
g.dispose();
disposableImage.flush();
redrawRegionlost(renderer);
this.lines = linesList.toArray(new String[0]);
return true;
}
private void splitText(String text, int maxWidth, FontMetrics fontMetrics, ArrayList<String> lineList) {
text = text.trim();
//this.text.add(text);
if (fontMetrics.stringWidth(text) <= maxWidth)
lineList.add(text);
else
{
while (text.length() > 0)
{
int idx = binSearch(text, fontMetrics, maxWidth, 1, text.length());
if (idx <= 0)
break;
String texPart = text.substring(0, idx).trim();
if (fontMetrics.stringWidth(text.substring(0, Math.min(text.length(), idx + 1))) > maxWidth && texPart.contains(" "))
{
idx = texPart.lastIndexOf(" ");
texPart = texPart.substring(0, idx);
}
lineList.add(texPart);
text = text.substring(idx).trim();
}
}
}
private static int binSearch(String string, FontMetrics fontMetrics, int key, int low, int high) {
int index = 0;
while (low <= high)
{
int mid = low + ((high - low) / 2);
int midmetric = fontMetrics.stringWidth(string.substring(0, mid));
if (midmetric < key)
{
low = mid + 1;
index = mid;
}
else if (midmetric > key)
{
high = mid - 1;
}
else if (midmetric == key)
{
index = mid;
break;
}
}
return index;
}
@Override
public void drawDisplay(RenderPanel renderer, Graphics2D g2d, long ticks, int iconTicks) {
}
@Override
public void drawBoundLimitedDisplay(RenderPanel renderer, Graphics2D g2d, Rectangle bounds, long ticks, int iconTicks) {
DrawingUtil.drawGradientRect(g2d, 60, TOPBAR_HEIGHT, W - 120, MAINBAR_HEIGHT, 20, BG_BLUE.darker(), BG_BLUE.brighter());
g2d.setFont(font);
FontMetrics fontMetrics = g2d.getFontMetrics();
g2d.setColor(BG_BLUE.darker());
g2d.drawRect(60 + STROKE_OFFSET, TOPBAR_HEIGHT + STROKE_OFFSET, W - 120 - STROKE_WIDTH, MAINBAR_HEIGHT - STROKE_WIDTH);
for (int i = 0; i < Math.min(9, lines.length - this.stringOffset); i++)
{
if (lines[i + stringOffset].startsWith("*") && lines[i].endsWith("*"))
{
String line = lines[i + stringOffset].substring(1, lines[i + stringOffset].length() - 1);
DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, "*", Color.WHITE, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET + (W - 150 - STROKE_WIDTH) / 2 - fontMetrics.stringWidth(line) / 2, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, line, Color.WHITE, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, W - 95 - STROKE_WIDTH, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, "*", Color.WHITE, Color.BLACK, 2);
}
else if (lines[i + stringOffset].startsWith("[") && lines[i].endsWith("]"))
{
String line = lines[i + stringOffset].substring(1, lines[i + stringOffset].length() - 1);
DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET + (W - 150 - STROKE_WIDTH) / 2 - fontMetrics.stringWidth(line) / 2, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, line, Color.WHITE, Color.BLACK, 2);
}
else DrawingUtil.drawOutlinedString(g2d, 60 + 20 + STROKE_OFFSET, TOPBAR_HEIGHT + STROKE_OFFSET + 40 + i * 30, lines[i + stringOffset], Color.WHITE, Color.BLACK, 2);
}
}
@Override
public void redrawRegionlost(RenderPanel renderer) {
renderer.addRedrawBound(TOPBAR_HEIGHT, W - 120, MAINBAR_HEIGHT, 20);
}
@Override
public void notifyForecastProviderUpdate(RenderPanel renderer, ForecastProvider forecastProvider) {
}
@Override
public String getDisplayName() {
return "36-hour";
}
}

View File

@@ -0,0 +1,20 @@
package com.flaremicro.visualforecast.forecast;
import java.util.Date;
public class CurrentConditions {
String station;
String stationCode;
Date timeObserved;
String condition;
byte icon;
byte temperature;
byte dewPoint;
short pressure;
short visibility;
float relativeHumidity;
short windSpeed;
short windGust;
float windBearing;
String windDirection;
}

View File

@@ -1,5 +1,7 @@
package com.flaremicro.visualforecast.forecast;
import com.flaremicro.visualforecast.icons.IconProvider;
public class DayForecast {
public byte hiTemp;
public byte loTemp;
@@ -11,7 +13,7 @@ public class DayForecast {
public DayForecast(byte hiTemp, byte loTemp, byte iconId, String weatherLine1, String weatherLine2, float percipPercent){
this.hiTemp = hiTemp;
this.loTemp = loTemp;
this.iconId = (byte)(iconId & 63);
this.iconId = (byte)(iconId % IconProvider.INDEXED_ICONS.length);
this.weatherLine1 = weatherLine1;
this.weatherLine2 = weatherLine2;
this.percipPercent = percipPercent;

View File

@@ -0,0 +1,12 @@
package com.flaremicro.visualforecast.forecast;
public class DetailedForecast {
public final String title;
public final String status;
public DetailedForecast(String title, String status)
{
this.title = title;
this.status = status;
}
}

View File

@@ -0,0 +1,24 @@
package com.flaremicro.visualforecast.forecast;
import java.util.Date;
import com.flaremicro.visualforecast.icons.IconProvider;
public class HourlyForecast {
public final Date hour;
public final byte iconId;
public final byte temp;
public final short windSpeed;
public final float percip;
public final byte windChill;
public HourlyForecast(Date hour, byte iconId, byte temp, short windSpeed, float percip, byte windChill)
{
this.hour = hour;
this.iconId = (byte) (iconId % IconProvider.INDEXED_ICONS.length);
this.temp = temp;
this.windSpeed = windSpeed;
this.percip = percip;
this.windChill = windChill;
}
}

View File

@@ -1,19 +1,62 @@
package com.flaremicro.visualforecast.forecast;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
public class TownForecast {
public TownForecast(String townName, DayForecast[] dayForecast){
private String townName;
private DayForecast[] dayForecast;
private Set<String> displays = new HashSet<String>();
private HourlyForecast[] hourlyForecast;
private DetailedForecast[] detailedForecast;
public TownForecast(String townName, DayForecast[] dayForecast) {
this.townName = townName;
this.dayForecast = dayForecast;
}
public void setDayForecast(DayForecast[] dayForecast){
this.dayForecast = dayForecast;
}
private final String townName;
private final DayForecast[] dayForecast;
public boolean isDisplaySupported(String displayName)
{
return displays.size() == 0 || displays.contains(displayName);
}
public void setSupportedDisplays(String ... displays){
setSupportedDisplays(Arrays.asList(displays));
}
public void setSupportedDisplays(Collection<String> displays){
this.displays.clear();
this.displays.addAll(displays);
}
public void setHourlyForecast(HourlyForecast[] forecast) {
this.hourlyForecast = forecast;
}
public HourlyForecast[] getHourlyForecast() {
return this.hourlyForecast;
}
public DayForecast[] getDayForecast() {
return dayForecast;
}
public String getTownName() {
return townName;
}
public DetailedForecast[] getDetailedForecast() {
return detailedForecast;
}
public void setDetailedForecast(DetailedForecast[] detailedForecast) {
this.detailedForecast = detailedForecast;
}
}

View File

@@ -31,6 +31,6 @@ public class RenderConstants {
public static final Color BG_PURPLE = new Color(0x2b29b3);
public static final Color BG_OORANGE = new Color(0xff8c00);
public static final Color BG_ORANGE = new Color(0xff8c00);
public static final Color BG_BLUE = new Color(0x394aa8);
}

View File

@@ -53,7 +53,7 @@ public class IconProvider {
public static final Icon BUTTER_RAIN = registerIcon(new BlizzardIcon(26, CLOUD, BUTTER));
public static final Icon RAIN_STORM = registerIcon(new LightningOverlay(27, SMALL_CLOUD, LIGHTNING_BOLT, RAIN_HEAVY));
//public static final Icon INVALID_RAIN = registerIcon(new LightningOverlay(27, SUN, BUTTER, new BlizzardIcon(-1, LIGHTNING_BOLT, INVALID)));
public static final Icon INVALID_RAIN = registerIcon(new LightningOverlay(28, SUN, BUTTER, new BlizzardIcon(-1, LIGHTNING_BOLT, INVALID)));
private static Icon registerIcon(Icon icon)
{

View File

@@ -21,6 +21,7 @@ public class ButterIcon extends Icon {
};
Color[] iceShineAnimation = new Color[] {
new Color(0xFFFFFF),
new Color(0xFFFFFF),
};
public ButterIcon(int id) {

View File

@@ -19,6 +19,7 @@ public class InvalidIcon extends Icon {
@Override
public void drawIcon(Graphics2D g2d, float scale, int animationStep) {
g2d.getTransform();
g2d.setFont(fnt.deriveFont(0.8F));
g2d.translate(0.2F, 0.8F);
DrawingUtil.drawOutlinedString(g2d, 0, 0, "X", Color.YELLOW, Color.BLACK, 1, 2/scale);

View File

@@ -1,3 +1,7 @@
#VisualForecast 1000 Properties file. Functional provider must be set for successful boot!
#Thu Mar 07 16:27:03 PST 2024
#Sat Nov 23 19:50:15 PST 2024
announcement-dir=Announcements
display-selection=36-hour,7-day,hourly
music-dir=./Music
current-display-version=1
forecast-provider-jar=CanadaDatamartProvider.jar