/*
* ATMClient.java
*
* Created on February 25, 2008, 1:58 PM
*/
package gui;
import framework.IATMCModel;
import framework.IATMClient;
import framework.IChatTab;
import framework.IConnectTab;
import framework.IPlaneUpdateObject;
import gui.tabs.ChatTab;
import gui.tabs.ConnectTab;
import gui.tabs.RadarTab;
import gui.tabs.StatusTab;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.ATMCModel;
import pluginreceiver.gui.*;
import gui.windows.NavaidAirportEditor;
import gui.windows.SettingsWindow;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
*
* @author swift
*/
public class ATMClient extends javax.swing.JFrame implements IATMClient {
private IChatTab chatTab;
private IConnectTab connectTab;
private PluginReceiverPanel pluginTab;
private RadarTab radarTab;
private StatusTab statusTab;
private SettingsWindow settingsWindow;
private IATMCModel atmcModel;
/** Creates new form ATMClient */
public ATMClient() {
try {
atmcModel = new ATMCModel(this);
initComponents();
connectTab = new ConnectTab(this);
statusTab = new StatusTab();
settingsWindow = new SettingsWindow(this);
tabPane.add("Connection", (ConnectTab) connectTab);
tabPane.add("Status", statusTab);
this.validate();
} catch (Exception ex) {
Logger.getLogger(ATMClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
tabPane = new javax.swing.JTabbedPane();
statusLabel = new javax.swing.JLabel();
statusMessage = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("ATMClient");
tabPane.setDoubleBuffered(true);
statusLabel.setText("Not Logged In");
statusMessage.setBackground(new java.awt.Color(255, 255, 255));
statusMessage.setText("Started up");
jMenu1.setText("File");
jMenuItem1.setText("Airport/Navaid Editor");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
menuBar.add(jMenu1);
jMenu2.setText("Edit");
jMenuItem2.setText("Settings");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
menuBar.add(jMenu2);
setJMenuBar(menuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(statusMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 416, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addComponent(tabPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 820, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(statusMessage)
.addComponent(statusLabel))
.addGap(4, 4, 4)
.addComponent(tabPane, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
new NavaidAirportEditor().showDialog();
}//GEN-LAST:event_jMenuItem1ActionPerformed
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
settingsWindow.setVisible(true);
}//GEN-LAST:event_jMenuItem2ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ATMClient().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuBar menuBar;
private javax.swing.JLabel statusLabel;
private javax.swing.JLabel statusMessage;
private javax.swing.JTabbedPane tabPane;
// End of variables declaration//GEN-END:variables
public IATMCModel getModel() {
return atmcModel;
}
public void setFunctions(String[] funcs) {
connectTab.setFuncs(funcs);
}
public RadarTab getRadarTab(){
return radarTab;
}
public void setTabs(final boolean tabs) {
final ATMClient tmp = this;
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
if (tabs) {
if (radarTab == null) {
tabPane.add("Radar", radarTab = new RadarTab(tmp));
}
if (chatTab == null) {
tabPane.add("Chat", (ChatTab) (chatTab = new ChatTab(tmp)));
}
} else {
if (radarTab != null) {
tabPane.remove(radarTab);
radarTab = null;
}
if (chatTab != null) {
tabPane.remove((ChatTab) chatTab);
chatTab = null;
}
}
tmp.validate();
}
});
}
public void setFunctionChooser(boolean func) {
connectTab.setFunctionChooser(func);
}
public void setStatus(final String message) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
statusLabel.setText(message);
}
});
}
public void addChatMessage(String message) {
String[] test = message.split(":");
System.out.println(test.length);
if (test.length == 2) {
chatTab.addText(message.split(":")[0], message.split(":")[1]);
} else {
chatTab.addText(message.split(":")[0], "");
}
}
public void addStatusMessage(String message) {
DateFormat tmp = new SimpleDateFormat();
String test = tmp.format(new Date());
statusTab.addMessage("("+test+") "+message);
statusMessage.setText(message);
}
public void setUserList(final String[] userList) {
atmcModel.updateRadarPlaneList(userList);
final ATMClient tmp = this;
java.awt.EventQueue.invokeLater(new Thread() {
public void run() {
if (radarTab == null) {
tabPane.add("Radar", radarTab = new RadarTab(tmp));
}
if (chatTab == null) {
tabPane.add("Chat", (ChatTab) (chatTab = new ChatTab(tmp)));
}
chatTab.addNicks(userList);
}
});
}
public void startXPlaneClient() {
try {
if (pluginTab == null) {
pluginTab = new PluginReceiverPanel(this);
tabPane.add("Plugin receiver", pluginTab);
} else {
tabPane.add("Plugin receiver", pluginTab);
}
} catch (Exception ex) {
Logger.getLogger(ATMClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void stopXPlaneClient() {
tabPane.remove(pluginTab);
}
public void setPilotData(IPlaneUpdateObject puo) {
if (pluginTab != null) {
pluginTab.setValues(puo);
}
}
}