-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDashBoard.java
288 lines (259 loc) · 10.6 KB
/
DashBoard.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* Copyright (C) 2010 WeaveBytes, Inc.,
*
* Confidential, all rights reserved. No distribution is permitted.
___ ______ ____ ________
\ \ __ / __| / \ / ___|
\ \ / \ / |_ / /\ \ / |_
\ \/ \/ /| _| / /__\ \/ /| _|
\ /\ / | |__/ ______ / | |___
\__/ \__/ |_______/ \ _/ |______|
___ __
______ | | ________ __ __ | |
/ ___| | | / __ \ | | | | ______| |
| | | | | | | | | | | | / ___ |
| |____| |__ | |__| |__| \____/ | \ \___| |
\_______|______\________/__ \________/__ \________|
*/
//Description : Dashboard.java is the main page for weavecloud
//Creation Date : July 27, 2011
//Authors : Simranpal Singh, Varinder Pal Singh
//Project Manager : Navjot Singh
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.net.*;
import java.io.*;
class DashBoard extends JFrame implements ActionListener {
private JMenuBar mb;
private JMenu cloud, groups, inbox, options, help;
private JMenuItem hwhelp,habout;
private JMenuItem cregister, cexit;
private JMenuItem gcreate,gjoin,ginvite;
private JMenuItem osettings;
private JMenuItem miFileUp;
private JButton inviteButton;
private JPanel mainPane, treePane;
private CloudLogin login;
private JToolBar toolbar;
private JLabel status;
private boolean isConnected = false;
private Socket socket;
static InputStream is = null;
static OutputStream os = null;
private ServerHandler sHandler = null;
private String user = "test"; //dummy user
DashBoard() {
super("Weave Cloud");
setSize(800, 600);
setLocation(200, 200);
setIconImage(Toolkit.getDefaultToolkit().getImage("images/icons/32x32/cloud.png"));
setLayout(new BorderLayout());
addMenus();
setupToolbar();
SplitPane();
/*status label*/
status = new JLabel("");
add(status, BorderLayout.SOUTH);
// setDbFont(16);
// setDbColor("CYAN");
new TreePanel(this);
setVisible(true);
connectServer();
}//constructor
public void setDbColor(String color){
//Color c = color;
if(color=="CYAN"){
mainPane.setBackground(Color.CYAN);
treePane.setBackground(Color.CYAN);
mb.setBackground(Color.CYAN);
toolbar.setBackground(Color.CYAN);
}
}
public void setDbFont(int font) {
Font value = new Font("Courier New",Font.PLAIN,font);
cloud.setFont(value);
groups.setFont(value);
inbox.setFont(value);
options.setFont(value);
help.setFont(value);
status.setFont(value);
cregister.setFont(value);
hwhelp.setFont(value);
habout.setFont(value);
cexit.setFont(value);
gcreate.setFont(value);
gjoin.setFont(value);
ginvite.setFont(value);
osettings.setFont(value);
miFileUp.setFont(value);
}
public void SplitPane() {
//treePane.setLineWrap(true);
//mainPane.setLineWrap(true);
treePane.setMinimumSize(new Dimension(150, 150));
mainPane.setMinimumSize(new Dimension(150, 150));
treePane.setPreferredSize(new Dimension(600, 600));
treePane.setLayout(new BorderLayout());
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treePane, mainPane);
getContentPane().add(sp, BorderLayout.CENTER);
}
public void addMenus() {
mb = new JMenuBar();
setJMenuBar(mb);
cloud = new JMenu("Cloud");
groups = new JMenu("Groups");
inbox = new JMenu("Inbox");
options = new JMenu("Options");
help = new JMenu("Help");
mb.add(cloud);
mb.add(groups);
mb.add(inbox);
mb.add(options);
mb.add(help);
cregister = new JMenuItem("Register", new ImageIcon(getClass().getResource("images/icons/16x16/register.png")));
cexit = new JMenuItem("Exit", new ImageIcon(getClass().getResource("images/icons/16x16/exit.png")));
gcreate = new JMenuItem("Create", new ImageIcon(getClass().getResource("images/icons/16x16/group.png")));
gjoin = new JMenuItem("Join", new ImageIcon(getClass().getResource("images/icons/16x16/user.png")));
ginvite = new JMenuItem("Invite", new ImageIcon(getClass().getResource("images/icons/16x16/invite.png")));
osettings = new JMenuItem("Settings", new ImageIcon(getClass().getResource("images/icons/16x16/setting.png")));
hwhelp = new JMenuItem("Weave Cloud Help", new ImageIcon(getClass().getResource("images/icons/16x16/help.png")));
habout = new JMenuItem("About", new ImageIcon(getClass().getResource("images/icons/16x16/cloud.png")));
miFileUp = new JMenuItem("File Upload", new ImageIcon(getClass().getResource("images/icons/16x16/cloud.png")));
mainPane = new JPanel();
treePane = new JPanel();
cregister.setActionCommand(Config.CMD_REGISTER);
gcreate.setActionCommand(Config.CMD_CREATE_GROUP);
gjoin.setActionCommand(Config.CMD_JOIN_GROUP);
ginvite.setActionCommand(Config.CMD_INVITE);
osettings.setActionCommand(Config.CMD_SETTINGS);
miFileUp.setActionCommand(Config.CMD_FILE_UPLOAD);
hwhelp.setActionCommand(Config.CMD_HELP);
habout.setActionCommand(Config.CMD_ABOUT);
cexit.setActionCommand(Config.CMD_EXIT);
cloud.add(cregister);
cloud.add(cexit);
groups.add(gcreate);
groups.add(gjoin);
groups.add(ginvite);
options.add(miFileUp);
options.add(osettings);
help.add(hwhelp);
help.add(habout);
cregister.addActionListener(this);
miFileUp.addActionListener(this);
cexit.addActionListener(this);
gcreate.addActionListener(this);
gjoin.addActionListener(this);
ginvite.addActionListener(this);
osettings.addActionListener(this);
habout.addActionListener(this);
}
private void setupToolbar() {
toolbar = new JToolBar();
//Create
JButton createButton = new JButton(new ImageIcon(getClass().getResource("images/icons/64x64/group.png")));
createButton.setToolTipText("Create a new group ");
toolbar.add(createButton);
createButton.setActionCommand(Config.CMD_CREATE_GROUP);
createButton.addActionListener(this);
//Join
JButton joinButton = new JButton(new ImageIcon(getClass().getResource("images/icons/64x64/user.png")));
joinButton.setToolTipText("Join an existing group");
toolbar.add(joinButton);
joinButton.addActionListener(this);
joinButton.setActionCommand(Config.CMD_JOIN_GROUP);
//Invite
JButton inviteButton = new JButton(new ImageIcon(getClass().getResource("images/icons/64x64/invite.png")));
inviteButton.setToolTipText("Invite a Friend");
toolbar.add(inviteButton);
inviteButton.addActionListener(this);
inviteButton.setActionCommand(Config.CMD_INVITE);
//Settings
JButton settingButton = new JButton(new ImageIcon(getClass().getResource("images/icons/64x64/setting.png")));
settingButton.setToolTipText("Change settings");
toolbar.add(settingButton);
settingButton.addActionListener(this);
settingButton.setActionCommand(Config.CMD_SETTINGS);
//Help
JButton helpButton = new JButton(new ImageIcon(getClass().getResource("images/icons/64x64/help.png")));
helpButton.setToolTipText("About WeaveCloud");
toolbar.add(helpButton);
helpButton.addActionListener(this);
helpButton.setActionCommand(Config.CMD_HELP);
//Exit
JButton exitButton = new JButton(new ImageIcon(getClass().getResource("images/icons/64x64/exit.png")));
exitButton.setToolTipText("Exit from Weave Cloud..");
toolbar.add(exitButton);
exitButton.addActionListener(this);
exitButton.setActionCommand(Config.CMD_EXIT);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//Add Toolbar to JFrame
add(toolbar, BorderLayout.NORTH);
}
public void actionPerformed(ActionEvent ae) {
if(ae.getActionCommand().equals(Config.CMD_REGISTER)) new Registration(this);
if(ae.getActionCommand().equals(Config.CMD_EXIT)) System.exit(0);
if(ae.getActionCommand().equals(Config.CMD_CREATE_GROUP)) new GroupAdd(this);
if(ae.getActionCommand().equals(Config.CMD_JOIN_GROUP)) new JoinGroup(this);
if(ae.getActionCommand().equals(Config.CMD_INVITE)) new Invitation(this);
if(ae.getActionCommand().equals(Config.CMD_SETTINGS)) new Settings(this);
if(ae.getActionCommand().equals(Config.CMD_ABOUT)) new AboutWeaveCloud(this);
if(ae.getActionCommand().equals(Config.CMD_FILE_UPLOAD)) new Uploader(this);
}
public void setStatus(String msg) {
status.setText(msg);
}
public void doSleep(int msecs) {
try { Thread.sleep(msecs); }
catch (Exception e1){}
}
public void setConnectedStatus(boolean val) {
isConnected = val;
if(isConnected) setStatus("Connected to WeaveCloud Server.");
else setStatus("Disconnected from WeaveCloud Server.");
}
public void connectServer() {
int attempt=0;
while(!isConnected && attempt < Config.SERVER_CONNECT_ATTEMPTS) {
try {
attempt ++;
log.info("attempt = " + attempt);
setStatus("#" + attempt + ") Connecting to server at " + Config.HOST + " ...");
socket = new Socket(Config.HOST, Config.PORT);
setConnectedStatus(true);
byte msg[] = new byte[1024];
is = socket.getInputStream();
os = socket.getOutputStream();
break;
}
catch (Exception e){
doSleep(1000);
setStatus("Failed to connect to server");
doSleep(1000);
}
}
if(!isConnected) {
setStatus("Closing application...");
doSleep(1000);
System.exit(1);
}
sHandler = new ServerHandler(socket, this);
}
public static void sendMessageToServer(String msg) {
if(os == null) return;
try {
os.write(msg.getBytes());
}
catch (Exception e) {
e.printStackTrace();
}
}
public String getUser() { return user; }
// main method
public static void main(String []args) {
//new Splash();
DashBoard d = new DashBoard();
}
}//DashBoard