199 lines
4.6 KiB
Java
199 lines
4.6 KiB
Java
package com.flaremicro.visualforecast;
|
|
|
|
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;
|
|
|
|
public class VisualForecastFrame extends JFrame implements WindowListener, KeyListener {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
private RenderPanel renderPane;
|
|
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
|
|
{
|
|
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);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public void end() {
|
|
if (executor != null)
|
|
executor.end();
|
|
if (timer != null)
|
|
{
|
|
timer.stop();
|
|
}
|
|
renderPane.end();
|
|
if (forecastProviderManager != null)
|
|
forecastProviderManager.end();
|
|
propertyManager.store();
|
|
}
|
|
|
|
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);
|
|
String forecastProvider = propertyManager.getString("forecast-provider-jar", "");
|
|
propertyManager.store();
|
|
ForecastProvider provider = forecastProviderManager.loadProvider(new File(forecastProvider));
|
|
renderPane.setForecastProvider(provider);
|
|
|
|
}
|
|
}.start();
|
|
|
|
}
|
|
|
|
/**
|
|
* Create the frame.
|
|
*/
|
|
public VisualForecastFrame() {
|
|
propertyManager.load();
|
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
setBounds(100, 100, 640, 480);
|
|
renderPane = new RenderPanel(propertyManager);
|
|
//renderPane.setBorder(null);
|
|
//renderPane.setLayout(new BorderLayout(0, 0));
|
|
add(renderPane);
|
|
setUndecorated(true);
|
|
addWindowListener(this);
|
|
addKeyListener(this);
|
|
}
|
|
|
|
public void windowOpened(WindowEvent e) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
public void windowClosing(WindowEvent e) {
|
|
|
|
end();
|
|
}
|
|
|
|
public void windowClosed(WindowEvent e) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
public void windowIconified(WindowEvent e) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
public void windowDeiconified(WindowEvent e) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
public void windowActivated(WindowEvent e) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
public void windowDeactivated(WindowEvent e) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
public void keyTyped(KeyEvent e) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
public void keyPressed(KeyEvent e) {
|
|
if (e.getKeyCode() == KeyEvent.VK_F11)
|
|
{
|
|
if (isFullscreen)
|
|
{
|
|
isFullscreen = false;
|
|
this.getGraphicsConfiguration().getDevice().setFullScreenWindow(null);
|
|
setBounds(100, 100, 640 * 2, 480 * 2);
|
|
|
|
}
|
|
else
|
|
{
|
|
isFullscreen = true;
|
|
this.getGraphicsConfiguration().getDevice().setFullScreenWindow(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void keyReleased(KeyEvent e) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
}
|