package art.servers.gui;
|
|
import art.library.gui.FlatGUI;
|
import art.library.gui.flat.FlatButton;
|
import art.library.gui.flat.FlatDialog;
|
import art.library.gui.flat.FlatMenu;
|
import art.library.gui.flat.FlatMenuBar;
|
import art.library.gui.flat.FlatMenuItem;
|
import art.library.gui.flat.FlatToggleButton;
|
import art.library.gui.flat.FlatWindow;
|
import art.library.model.transactions.traces.Trace;
|
import art.library.utils.resources.Resources;
|
import art.servers.Shared;
|
import art.servers.gui.components.PanelClock;
|
import java.awt.Dimension;
|
import java.awt.Font;
|
import java.awt.GraphicsDevice;
|
import java.awt.GraphicsEnvironment;
|
import java.awt.Image;
|
import java.awt.MenuItem;
|
import java.awt.MouseInfo;
|
import java.awt.PointerInfo;
|
import java.awt.PopupMenu;
|
import java.awt.SystemTray;
|
import java.awt.TrayIcon;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowEvent;
|
import javax.swing.JFrame;
|
import javax.swing.JOptionPane;
|
import javax.swing.JToolBar;
|
import javax.swing.SwingUtilities;
|
|
public class ArticWindow extends FlatWindow
|
{
|
protected ArticWindow window;
|
protected MenuListener menuListener;
|
protected MyActionListener myActionListener;
|
protected javax.swing.Timer secondTimer = null;
|
private FlatButton buttonExit = null;
|
private FlatButton buttonHide = null;
|
private FlatMenuItem menuExit = null;
|
private FlatMenuItem menuHide = null;
|
private PanelClock panelReloj;
|
private ArticPanel articPanel;
|
|
|
|
public ArticWindow()
|
{
|
super();
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.window = this;
|
myActionListener = new MyActionListener();
|
this.setIcon(Resources.getResourceURL(Shared.configuration.general.windowIcon));
|
this.setTitle(Shared.configuration.general.windowTitle);
|
this.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
|
|
secondTimer = new javax.swing.Timer(1000, new ActionListener()
|
{
|
public void actionPerformed(ActionEvent e)
|
{
|
timer();
|
}
|
});
|
|
menuWindow();
|
menuBar();
|
menuButtons();
|
content();
|
footer();
|
reload();
|
secondTimer.start();
|
systemTry();
|
|
addWindowListener(new WindowAdapter()
|
{
|
@Override
|
public void windowClosing(WindowEvent evt)
|
{
|
int answer = FlatDialog.showDialog(ArticWindow.this, Shared.getMessage("Closing"), Shared.getMessage("Do you really want to close?"), true, FlatDialog.DIALOG_QUESTION);
|
|
if (answer == JOptionPane.YES_OPTION)
|
{
|
Shared.exit();
|
}
|
}
|
});
|
}
|
|
|
|
|
public void addTrace(Object object)
|
{
|
if (object instanceof Trace)
|
{
|
articPanel.panelTraces.addTrace(object);
|
}
|
|
articPanel.panelLogger.addTrace(object);
|
}
|
|
|
|
|
public ArticPanel getArticPanel()
|
{
|
return articPanel;
|
}
|
|
|
private void menuWindow()
|
{
|
}
|
|
|
private void menuBar()
|
{
|
FlatMenuBar menuBar = new FlatMenuBar();
|
|
FlatMenu menu = new FlatMenu();
|
menu.setText(Shared.getMessage("&File"));
|
|
menuExit = new FlatMenuItem();
|
menuExit.setText(Shared.getMessage("E&xit"));
|
menuExit.addActionListener(new java.awt.event.ActionListener()
|
{
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
{
|
salir(true);
|
}
|
});
|
|
menuHide = new FlatMenuItem();
|
menuHide.setText(Shared.getMessage("&Hide"));
|
menuHide.addActionListener(new java.awt.event.ActionListener()
|
{
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
{
|
setVisible(false);
|
}
|
});
|
|
menu.add(menuHide);
|
menu.addSeparator();
|
menu.add(menuExit);
|
menuBar.add(menu);
|
this.setMenuBar(menuBar);
|
|
}
|
|
|
|
|
private void menuButtons()
|
{
|
JToolBar toolbar = new JToolBar();
|
this.setMenuButtons(toolbar);
|
|
buttonExit = new FlatButton(Shared.getMessage("E&xit"));
|
buttonExit.setIcon(Resources.getResourceURL("data/art.library.server/icons/24x24/exit10.png"));
|
buttonExit.setPreferredSize(new Dimension(buttonExit.getStringWidth(), 0));
|
buttonExit.addActionListener(new java.awt.event.ActionListener()
|
{
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
{
|
salir(true);
|
}
|
});
|
|
buttonHide = new FlatButton(Shared.getMessage("&Hide"));
|
buttonHide.setIcon(Resources.getResourceURL("data/art.library.server/icons/24x24/hide.png"));
|
buttonHide.setPreferredSize(new Dimension(buttonHide.getStringWidth(), 0));
|
buttonHide.addActionListener(new java.awt.event.ActionListener()
|
{
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
{
|
setVisible(false);
|
}
|
});
|
|
|
this.addButtonMenu(buttonExit);
|
this.addButtonMenu(buttonHide);
|
this.addButtonSeparator();
|
|
}
|
|
|
|
private void footer()
|
{
|
panelReloj = new PanelClock();
|
setFooter(panelReloj, new Dimension(24, 24));
|
}
|
|
|
public void messageFooter(String text)
|
{
|
panelReloj.message(text);
|
}
|
|
private void content()
|
{
|
articPanel = new ArticPanel(this);
|
this.setContent(articPanel);
|
articPanel.selection();
|
}
|
|
|
|
private void salir(boolean ask)
|
{
|
if (ask == true)
|
{
|
int answer = FlatDialog.showDialog(ArticWindow.this, Shared.getMessage("Closing"), Shared.getMessage("Do you really want to close?"), true, FlatDialog.DIALOG_QUESTION);
|
if (answer != JOptionPane.YES_OPTION) return;
|
}
|
|
Shared.traceInformation(Shared.getMessage("Graphic interface"), "Finishing");
|
Shared.exit();
|
}
|
|
|
|
public void reload()
|
{
|
articPanel.reload();
|
panelReloj.reload();
|
};
|
|
|
|
|
public void grants() {};
|
public void help() {};
|
|
|
public void timer()
|
{
|
if (this.isShowing() == true)
|
{
|
panelReloj.timer();
|
articPanel.timer();
|
}
|
}
|
|
public void edit(boolean value) {};
|
|
public void setMenuListener(MenuListener menuListener)
|
{
|
this.menuListener = menuListener;
|
}
|
|
public MenuListener getMenuListener()
|
{
|
return menuListener;
|
}
|
|
public void startGUI()
|
{
|
Runnable runnable = new Runnable()
|
{
|
public void run()
|
{
|
showGUI(true);
|
}
|
};
|
|
SwingUtilities.invokeLater(runnable);
|
}
|
|
|
public void showGUI(int x, int y, int w, int h, boolean resizable, boolean automaticSystemLocation)
|
{
|
setLocation(x, y);
|
if (automaticSystemLocation == true)
|
{
|
setLocationByPlatform(true);
|
}
|
setPreferredSize(new Dimension(w, h));
|
setResizable(resizable);
|
setVisible(true);
|
pack();
|
}
|
|
|
public void showGUI(boolean automaticSystemLocation)
|
{
|
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
|
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
int x = (int) pointerInfo.getLocation().getX();
|
int y = (int) pointerInfo.getLocation().getY();
|
int screenWidth = gd.getDisplayMode().getWidth();
|
int screenHeight = gd.getDisplayMode().getHeight();
|
int w = screenWidth - (x % screenWidth);
|
int h = screenHeight - (y % screenHeight);
|
setLocation(x, y);
|
if (automaticSystemLocation == true)
|
{
|
setLocationByPlatform(true);
|
}
|
setPreferredSize(new Dimension(w, h));
|
setResizable(true);
|
setVisible(true);
|
pack();
|
|
}
|
|
|
|
private class MyActionListener implements ActionListener
|
{
|
|
public void actionPerformed(ActionEvent e)
|
{
|
String action = null;
|
|
if (e.getSource() instanceof FlatMenuItem)
|
{
|
FlatMenuItem menuItem = (FlatMenuItem) e.getSource();
|
action = menuItem.getName();
|
}
|
else if (e.getSource() instanceof FlatButton)
|
{
|
FlatButton button = (FlatButton) e.getSource();
|
action = button.getName();
|
}
|
else if (e.getSource() instanceof FlatToggleButton)
|
{
|
FlatToggleButton button = (FlatToggleButton) e.getSource();
|
action = button.getName();
|
}
|
|
MenuListener listener = window.getMenuListener();
|
|
if ((action != null) && (listener != null))
|
{
|
if (listener != null)
|
{
|
listener.menuSelection(action);
|
}
|
}
|
|
}
|
|
}
|
|
|
|
private SystemTray tray = null;
|
private TrayIcon trayIcon = null;
|
private Image icon_STATUS = Resources.getResourceImage("data/" + Shared.getApplicationName() + "/icons/16x16/status-white.png");
|
|
|
private void systemTry()
|
{
|
try
|
{
|
if (!SystemTray.isSupported())
|
{
|
return;
|
}
|
|
PopupMenu popup = new PopupMenu();
|
trayIcon = new TrayIcon(icon_STATUS, Shared.configuration.general.windowTitle);
|
trayIcon.setPopupMenu(popup);
|
tray = SystemTray.getSystemTray();
|
|
MenuItem aboutItem = new MenuItem(Shared.configuration.general.windowTitle);
|
aboutItem.setFont(getFont().deriveFont(Font.BOLD));
|
MenuItem lookItem = new MenuItem(Shared.getMessage("Look"));
|
MenuItem showItem = new MenuItem(Shared.getMessage("Show"));
|
MenuItem hideItem = new MenuItem(Shared.getMessage("Hide"));
|
MenuItem exitItem = new MenuItem(Shared.getMessage("Exit"));
|
|
//Add components to pop-up menu
|
|
popup.add(aboutItem);
|
popup.addSeparator();
|
popup.add(lookItem);
|
popup.addSeparator();
|
popup.add(showItem);
|
popup.add(hideItem);
|
popup.addSeparator();
|
popup.add(exitItem);
|
|
|
lookItem.addActionListener(new java.awt.event.ActionListener()
|
{
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
{
|
FlatGUI.initialise();
|
repaint();
|
}
|
});
|
|
showItem.addActionListener(new java.awt.event.ActionListener()
|
{
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
{
|
setExtendedState(JFrame.NORMAL);
|
setVisible(true);
|
}
|
});
|
|
hideItem.addActionListener(new java.awt.event.ActionListener()
|
{
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
{
|
setVisible(false);
|
}
|
});
|
|
exitItem.addActionListener(new java.awt.event.ActionListener()
|
{
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
{
|
salir(false);
|
}
|
});
|
|
tray.add(trayIcon);
|
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
|
public abstract class MenuListener
|
{
|
public abstract void menuSelection(String option);
|
}
|
|
}
|