Changed GUI to do some of the heavy lifting in seperate threads.

Fixed LogoPanel not loading a logo on first paint(), by issuing JPanel.validate() after logo has been loaded.
This commit is contained in:
dev
2011-07-14 09:08:30 +00:00
parent 865f762858
commit 3872802ed3
5 changed files with 71 additions and 47 deletions

View File

@ -14,6 +14,7 @@ import java.awt.event.MouseListener;
import java.net.URL;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import net.i2p.itoopie.gui.WindowHandler;
@ -49,39 +50,43 @@ public class TrayManager {
* Add the tray icon to the system tray and start everything up.
*/
protected void startManager() {
if(SystemTray.isSupported()) {
tray = SystemTray.getSystemTray();
trayIcon = new TrayIcon(IconLoader.getTrayImage(), "itoopie", getMainMenu());
trayIcon.setImageAutoSize(true); //Resize image to fit the system tray
trayIcon.addMouseListener(new MouseListener(){
@Override
public void mouseClicked(MouseEvent arg0) {
WindowHandler.toggleFrames();
}
@Override
public void mouseEntered(MouseEvent arg0) {
}
@Override
public void mouseExited(MouseEvent arg0) {
}
@Override
public void mousePressed(MouseEvent arg0) {
}
@Override
public void mouseReleased(MouseEvent arg0) {
}
});
try {
tray.add(trayIcon);
} catch (AWTException e) {
}
}
SwingUtilities.invokeLater(new Runnable(){
public void run(){
if(SystemTray.isSupported()) {
tray = SystemTray.getSystemTray();
trayIcon = new TrayIcon(IconLoader.getTrayImage(), "itoopie", getMainMenu());
trayIcon.setImageAutoSize(true); //Resize image to fit the system tray
trayIcon.addMouseListener(new MouseListener(){
@Override
public void mouseClicked(MouseEvent arg0) {
WindowHandler.toggleFrames();
}
@Override
public void mouseEntered(MouseEvent arg0) {
}
@Override
public void mouseExited(MouseEvent arg0) {
}
@Override
public void mousePressed(MouseEvent arg0) {
}
@Override
public void mouseReleased(MouseEvent arg0) {
}
});
try {
tray.add(trayIcon);
} catch (AWTException e) {
}
}
}
});
}
protected void languageChanged() {

View File

@ -72,6 +72,7 @@ public class Main {
frame = new RegisteredFrame();
frame.setBounds(100, 100, 550, 400);
frame.setResizable(false);
WindowHandler.registerMain(frame);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
@ -82,14 +83,13 @@ public class Main {
Chart2D bwChart = BandwidthChart.getChart();
Chart2D partTunnelChart = ParticipatingTunnelsChart.getChart();
//bwChart.setPreferredSize(new Dimension(30,100));
ChartPanel pt = new ChartPanel(partTunnelChart);
pt.setSize(300, 135);
pt.setLocation(15, 15);;
pt.setLocation(15, 10);
pt.setBorder(BorderFactory.createLineBorder(Color.GRAY));
ChartPanel cp = new ChartPanel(bwChart);
cp.setSize(300,135);
cp.setLocation(15, 165);
cp.setLocation(15, 155);
cp.setBorder(BorderFactory.createLineBorder(Color.GRAY));
overviewPanel.add(pt);
@ -102,11 +102,9 @@ public class Main {
JPanel configArea = new JPanel();
configArea.setOpaque(false);
//configArea.setLayout(new Grid());
configPanel.add(configArea, BorderLayout.CENTER);
JPanel buttonArea = new JPanel();
buttonArea.setOpaque(false);
buttonArea.setLayout(new BorderLayout(0, 0));
@ -164,6 +162,7 @@ public class Main {
});
frame.setVisible(true);
frame.repaint(); // Force repaint to make sure that Logo is loaded.
//frame.repaint(); // Force repaint to make sure that Logo is loaded.
}
}

View File

@ -7,12 +7,17 @@ import javax.swing.JFrame;
public class WindowHandler {
private static final HashSet<JFrame> _frames = new HashSet<JFrame>();
private static JFrame mainFrame;
private static boolean areFramesShown = false;
public static void register(JFrame frame){
_frames.add(frame);
}
public static void registerMain(JFrame frame){
mainFrame = frame;
}
public static void deRegister(JFrame frame){
_frames.remove(frame);
}
@ -21,6 +26,9 @@ public class WindowHandler {
for (JFrame frame : _frames){
frame.setVisible(false);
}
if (mainFrame != null){
mainFrame.setVisible(false);
}
areFramesShown = false;
}
@ -28,6 +36,9 @@ public class WindowHandler {
for (JFrame frame : _frames){
frame.setVisible(true);
}
if (mainFrame != null){
mainFrame.setVisible(true);
}
areFramesShown = true;
}

View File

@ -4,25 +4,34 @@ import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import net.i2p.itoopie.util.IconLoader;
public class LogoPanel extends JPanel {
private final static int IMAGE_SIZE = 128;
private Image bg;
/**
* An ordinary panel, but with a logotype added.
*/
private static final long serialVersionUID = 5619646652656877782L;
public LogoPanel(String imageName){
public LogoPanel(final String imageName) {
super();
bg = IconLoader.getIcon(imageName, 128);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
bg = IconLoader.getIcon(imageName, 128);
LogoPanel.this.repaint();
LogoPanel.this.updateUI();
LogoPanel.this.validate();
}
});
}
@Override
public void paintComponent(Graphics g){
g.drawImage(bg, Math.abs(this.getWidth()-IMAGE_SIZE),Math.abs(this.getHeight()-IMAGE_SIZE),null);
public void paintComponent(Graphics g) {
g.drawImage(bg, Math.abs(this.getWidth() - IMAGE_SIZE),
Math.abs(this.getHeight() - IMAGE_SIZE), null);
}
}

View File

@ -24,12 +24,12 @@
package net.i2p.itoopie.gui.component.chart;
import info.monitorenter.gui.chart.ITrace2D;
import info.monitorenter.reflection.ObjectRecorder;
import info.monitorenter.util.TimeStampedValue;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import net.i2p.itoopie.util.TimeStampedValue;
/**
* A simple adapter that allows displaying of timestamped values from an
* inspection of the