package ui;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import main.settings.ServerList;
import main.settings.Settings;
import ui.misc.MessageBox;
import ui.status.StatusBar;
import ui.status.StatusManagerInterface;
import ui.tabs.*;
import ui.tray.TrayManager;
public class GuiManager
{
private MainFrame mainFrame;
private StatusBar statusBar;
private int numberOfFixedTabs;
private TransfersTab transfersTab;
private SearchTab searchTab;
private ChatTab chatTab;
private TrayManager trayManager;
public GuiManager()
{
mainFrame = new MainFrame();
setupTabs();
setupStatusBar();
mainFrame.addWindowListener(new Disposer());
trayManager = new TrayManager(mainFrame);
if (Settings.application.start_to_tray)
{
trayManager.startToTray();
}
else
{
mainFrame.setVisible(true);
}
MessageBox.setParent(mainFrame);
}
private void setupTabs()
{
transfersTab = new TransfersTab();
searchTab = new SearchTab();
chatTab = new ChatTab();
mainFrame.addTab(new ServersTab(), "Servers");
mainFrame.addTab(transfersTab, "Transfers");
mainFrame.addTab(searchTab, "Search");
mainFrame.addTab(new ShareTab(), "Files");
mainFrame.addTab(new BandwidthTab(), "Bandwidth");
mainFrame.addTab(chatTab, "Chat");
mainFrame.addTab(new SettingsTab(), "Settings");
numberOfFixedTabs = mainFrame.getNumberOfTabs();
mainFrame.initializeTabActivation(new TabActivator());
}
private void setupStatusBar()
{
statusBar = new StatusBar();
mainFrame.add(statusBar, BorderLayout.SOUTH);
}
public final class TabActivator implements ChangeListener
{
private int lastIndex;
public TabActivator()
{
this.lastIndex = Settings.application.last_open_tab;
}
public int getLastActiveIndex()
{
return lastIndex;
}
public void stateChanged(ChangeEvent event)
{
lastIndex = mainFrame.updateActiveTab(lastIndex);
if (lastIndex < numberOfFixedTabs)
{
Settings.application.last_open_tab = lastIndex;
}
}
}
private final class Disposer extends WindowAdapter
{
public void windowClosed(WindowEvent event)
{
Settings.writeToFile();
ServerList.writeToDataFile();
System.exit(0);
}
}
public MainFrame getMainFrame()
{
return mainFrame;
}
public StatusManagerInterface getStatusManager()
{
return statusBar;
}
public TrayManager getTrayManager()
{
return trayManager;
}
public void flashTransfersTab()
{
transfersTab.flash();
}
public SearchTab getSearchTab()
{
return searchTab;
}
public ChatTab getChatTab()
{
return chatTab;
}
}