📄 mainscreengui.java
字号:
/*
* RIC 2 by Harry Otten (c) Copyright 2003 hotten@dds.nl
* Check out http://www.hotten.dds.nl/ric/
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Calendar;
import java.util.Vector;
public class MainScreenGUI extends JFrame implements ActionListener, WindowListener, MouseListener {
private NetworkCommunicator networkCommunicator;
private JButton connect, disconnect, stateButton, settings, extra, exit;
private JTextArea textArea;
private JScrollPane scrollPaneUserList, scrollPaneTextArea;
private JScrollBar scrollBarVer;
private JScrollBar scrollBarHor;
private Thread listens;
private Calendar deTijd;
private int state;
private boolean personalState;
private JList userList;
public MainScreenGUI(NetworkCommunicator networkCommunicator) {
this.networkCommunicator = networkCommunicator;
}
public void setStoplicht(boolean stand) {
if (stand) {
connect.setEnabled(false);
disconnect.setEnabled(true);
personalState=true;
} else {
disconnect.setEnabled(false);
connect.setEnabled(true);
personalState=false;
}
}
public void setup() {
getContentPane().setLayout(null);
setTitle(RIC.VERSIONTITLE + RIC.VERSION);
setResizable(false);
setIconImage(new ImageIcon("../graphics/network.gif").getImage());
connect = new JButton("online");
connect.addActionListener(this);
disconnect = new JButton("offline");
disconnect.addActionListener(this);
stateButton = new JButton("refresh");
stateButton.addActionListener(this);
settings = new JButton("settings");
settings.addActionListener(this);
textArea = new JTextArea();
textArea.setEditable(false);
extra = new JButton("detail");
extra.addActionListener(this);
exit = new JButton("exit");
exit.addActionListener(this);
userList = new JList();
userList.addMouseListener(this);
// setting the color the same as the main screen.
userList.setBackground(this.getBackground());
// disable multi select
userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// manier voor de iconen
userList.setCellRenderer(new MyCellRenderer());
scrollPaneUserList = new JScrollPane(userList,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPaneTextArea = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
connect.setBounds(5,5,80,22);
disconnect.setBounds(90,5,80,22);
getContentPane().add(connect);
getContentPane().add(disconnect);
stateButton.setBounds(5,115,80,22);
getContentPane().add(stateButton);
settings.setBounds(90,115,80,22);
getContentPane().add(settings);
extra.setBounds(175,115,80,22);
getContentPane().add(extra);
exit.setBounds(175,5,80,22);
getContentPane().add(exit);
scrollPaneTextArea.setBounds(5,150,250,90);
getContentPane().add(scrollPaneTextArea);
scrollPaneUserList.setBounds(5,35,250,70);
getContentPane().add(scrollPaneUserList);
setSize(265, 175);
//buttons should be disabled and after connected to the server.
//the will be set.
disconnect.setEnabled(false);
connect.setEnabled(false);
addWindowListener(this);
show();
}
public void addText(String text) {
deTijd = Calendar.getInstance(); //getting the real time
String tijd = Integer.toString(deTijd.get(Calendar.HOUR_OF_DAY))+":";
if ((Integer.toString(deTijd.get(Calendar.MINUTE))).length()==1)
tijd = tijd + "0" + (Integer.toString(deTijd.get(Calendar.MINUTE)));
else tijd = tijd + (Integer.toString(deTijd.get(Calendar.MINUTE)));
textArea.insert(tijd + " " + text,0); //putting it on the screen
textArea.setCaretPosition(0);
/* DEBUG */
//System.out.println(tijd + " " + text);
}
public void setScreenState(int state) {
this.state=state;
if (state==0) {
stateButton.setText("refresh");
stateButton.setEnabled(true);
connect.setEnabled(true);
getContentPane().repaint();
}
else if (state==1) {
connect.setEnabled(false);
stateButton.setText("connect");
stateButton.setEnabled(true);
getContentPane().repaint();
} else if (state==2) {
stateButton.setEnabled(false);
getContentPane().repaint();
}
}
public void updateUserList(Vector list) {
userList.setListData(list);
};
public boolean getPersonalState() {
return personalState;
};
public void popUp(boolean detail) {
if (detail) {
setSize(getWidth(),275);
show();
}
setVisible(true);
super.setState(Frame.NORMAL);
toFront();
};
public void mouseClicked(MouseEvent e) {
// System.out.println( ((RicUser) userList.getSelectedValue() ) .name);
};
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void windowActivated(WindowEvent event)
{};
public void windowClosed(WindowEvent event) {
};
public void windowClosing(WindowEvent event) {
dispose();
if (state==0) { // if no connection don't tell networkCommunicator to disconnect.
System.out.println("Nicely disconnecting");
networkCommunicator.disconnect();
}
System.exit(0);
};
public void windowDeactivated(WindowEvent event) {
};
public void windowDeiconified(WindowEvent event)
{};
public void windowIconified(WindowEvent event)
{
if (Config.getHideFromTaskbar())
setVisible(false);
};
public void windowOpened(WindowEvent event)
{};
public void actionPerformed(ActionEvent event) {
if (event.getSource() == connect)
networkCommunicator.sendConnect();
else if (event.getSource() == disconnect)
networkCommunicator.sendDisconnect();
else if (event.getSource() == stateButton)
{
if (state==0) {
networkCommunicator.sendStatusCheck();
if (getHeight()<275) {
setSize(getWidth(),275);
show();
}
} else if (state==1)
{
//this will connect to the RIC server
listens = new Thread(networkCommunicator);
listens.start();
}
}
else if (event.getSource() == settings)
networkCommunicator.settingsGUI();
else if (event.getSource() == extra) {
if (getHeight()>175) {
setSize(getWidth(),175);
} else {
setSize(getWidth(),275);
show();
}
} else if (event.getSource() == exit) {
windowClosing(null);
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -