2011-07-12 18:56:49 +00:00
|
|
|
package net.i2p.itoopie.gui;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
|
2022-01-11 13:08:48 -05:00
|
|
|
import net.i2p.itoopie.configuration.ConfigurationManager;
|
|
|
|
|
2011-07-12 18:56:49 +00:00
|
|
|
public class WindowHandler {
|
2022-01-11 11:05:00 -05:00
|
|
|
private final HashSet<JFrame> _frames = new HashSet<JFrame>();
|
|
|
|
private JFrame mainFrame;
|
|
|
|
private boolean areFramesShown;
|
2022-01-11 13:08:48 -05:00
|
|
|
private final ConfigurationManager _conf;
|
|
|
|
|
|
|
|
public WindowHandler(ConfigurationManager conf) {
|
|
|
|
_conf = conf;
|
|
|
|
}
|
2022-01-11 11:05:00 -05:00
|
|
|
|
|
|
|
public void register(JFrame frame){
|
2011-07-12 18:56:49 +00:00
|
|
|
_frames.add(frame);
|
|
|
|
}
|
|
|
|
|
2022-01-11 11:05:00 -05:00
|
|
|
public void registerMain(JFrame frame){
|
2011-07-14 09:08:30 +00:00
|
|
|
mainFrame = frame;
|
|
|
|
}
|
|
|
|
|
2022-01-12 07:25:07 -05:00
|
|
|
public void destroyMain() {
|
|
|
|
if (mainFrame != null) {
|
|
|
|
mainFrame.dispose();
|
|
|
|
_frames.remove(mainFrame);
|
|
|
|
mainFrame = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-11 11:05:00 -05:00
|
|
|
public void deRegister(JFrame frame){
|
2022-01-09 12:06:20 -05:00
|
|
|
// don't remove the main frame when
|
|
|
|
// the user clicks on the X, so we have the updated
|
|
|
|
// graph when the user clicks on the icon again
|
|
|
|
if (frame == mainFrame)
|
|
|
|
hideFrames();
|
|
|
|
else
|
|
|
|
_frames.remove(frame);
|
2011-07-12 18:56:49 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 11:05:00 -05:00
|
|
|
public void hideFrames(){
|
2011-07-12 18:56:49 +00:00
|
|
|
for (JFrame frame : _frames){
|
|
|
|
frame.setVisible(false);
|
|
|
|
}
|
2011-07-14 09:08:30 +00:00
|
|
|
if (mainFrame != null){
|
|
|
|
mainFrame.setVisible(false);
|
|
|
|
}
|
2011-07-12 18:56:49 +00:00
|
|
|
areFramesShown = false;
|
|
|
|
}
|
|
|
|
|
2022-01-11 11:05:00 -05:00
|
|
|
public void showFrames(){
|
2011-07-12 18:56:49 +00:00
|
|
|
for (JFrame frame : _frames){
|
|
|
|
frame.setVisible(true);
|
|
|
|
}
|
2011-07-14 09:08:30 +00:00
|
|
|
if (mainFrame != null){
|
|
|
|
mainFrame.setVisible(true);
|
|
|
|
}
|
2011-07-12 18:56:49 +00:00
|
|
|
areFramesShown = true;
|
|
|
|
}
|
|
|
|
|
2022-01-11 11:05:00 -05:00
|
|
|
public void toggleFrames(){
|
2011-07-12 18:56:49 +00:00
|
|
|
if (_frames.isEmpty()){
|
2022-01-11 13:08:48 -05:00
|
|
|
new Main(this, _conf);
|
2011-07-12 18:56:49 +00:00
|
|
|
} else {
|
|
|
|
if (areFramesShown){
|
|
|
|
hideFrames();
|
|
|
|
} else {
|
|
|
|
showFrames();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|