• R/O
  • SSH
  • HTTPS

chaplet: 提交


Commit MetaInfo

修訂36 (tree)
時間2007-07-11 22:06:19
作者koe

Log Message

接続先のサーバのIPアドレスが異なっても同じマシンであれば、前回のセッションを引き継いで再開できるように修正

Change Summary

差異

--- chaplet/trunk/src/core/jp/sf/chaplet/StorageUtils.java (revision 35)
+++ chaplet/trunk/src/core/jp/sf/chaplet/StorageUtils.java (revision 36)
@@ -22,6 +22,7 @@
2222 public static final String PLUGIN = "plugin.xml";
2323 public static final String FONT = "font.xml";
2424 public static final String SERVER = "serverstat.xml";
25+ public static final String SESSION = "session.xml";
2526
2627 private static String prefix = null;
2728
--- chaplet/trunk/src/core/jp/sf/chaplet/core/ui/ConnectDialog.java (revision 35)
+++ chaplet/trunk/src/core/jp/sf/chaplet/core/ui/ConnectDialog.java (revision 36)
@@ -3,6 +3,7 @@
33 */
44 package jp.sf.chaplet.core.ui;
55
6+import java.awt.Cursor;
67 import java.awt.Frame;
78 import java.awt.GridBagConstraints;
89 import java.awt.GridBagLayout;
@@ -27,6 +28,7 @@
2728
2829 import jp.sf.chaplet.StorageUtils;
2930 import jp.sf.chaplet.core.client.ServerAddress;
31+import jp.sf.chaplet.core.client.Session;
3032
3133 /**
3234 * 接続設定ダイアログ。<br>
@@ -54,18 +56,28 @@
5456
5557 private JList historyList = null;
5658
57- private DefaultListModel historyListModel = null; // @jve:decl-index=0:visual-constraint="389,12"
59+ private DefaultListModel historyListModel = null; // @jve:decl-index=0:visual-constraint="461,10"
5860
5961 private JButton cancelButton = null;
6062
6163 private Action connectAction; // @jve:decl-index=0:
6264
63- private DefaultFormatter portFormatter = null; // @jve:decl-index=0:visual-constraint="386,63"
65+ private DefaultFormatter portFormatter = null; // @jve:decl-index=0:visual-constraint="474,58"
6466
65- private DefaultFormatterFactory formatterFactory = null; // @jve:decl-index=0:visual-constraint="381,110"
67+ private DefaultFormatterFactory formatterFactory = null; // @jve:decl-index=0:visual-constraint="472,103"
6668
6769 private List<ServerAddress> addressList; // @jve:decl-index=0:
70+
71+ private List<Session> sessionList;
6872
73+ private JScrollPane scroll2Pane = null;
74+
75+ private JList sessionIdList = null;
76+
77+ private JLabel jLabel2 = null;
78+
79+ private DefaultListModel sessionIdListModel = null; // @jve:decl-index=0:visual-constraint="459,155"
80+
6981 /**
7082 * @param owner
7183 */
@@ -85,7 +97,7 @@
8597 */
8698 @SuppressWarnings("unchecked")
8799 private void initialize() {
88- this.setSize(335, 200);
100+ this.setSize(363, 200);
89101 this.setTitle("接続設定");
90102 this.setContentPane(getJContentPane());
91103 addressList = (List<ServerAddress>) StorageUtils.load("server.xml", ArrayList.class);
@@ -102,6 +114,13 @@
102114 getPortText().setText(String.valueOf(address.getPort()));
103115 getPortText().setValue(address.getPort());
104116 }
117+ getSessionIdListModel().addElement(new Session());
118+ sessionList = (List<Session>) StorageUtils.load(StorageUtils.SESSION, ArrayList.class);
119+ for (Session session : sessionList) {
120+ if(!session.isNew()){
121+ getSessionIdListModel().addElement(session);
122+ }
123+ }
105124 }
106125
107126 /**
@@ -111,6 +130,19 @@
111130 */
112131 private JPanel getJContentPane() {
113132 if (jContentPane == null) {
133+ GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
134+ gridBagConstraints21.gridx = 2;
135+ gridBagConstraints21.gridy = 0;
136+ jLabel2 = new JLabel();
137+ jLabel2.setText("過去のセッション");
138+ GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
139+ gridBagConstraints11.fill = GridBagConstraints.BOTH;
140+ gridBagConstraints11.gridy = 1;
141+ gridBagConstraints11.weightx = 60.0;
142+ gridBagConstraints11.weighty = 1.0;
143+ gridBagConstraints11.gridheight = 2;
144+ gridBagConstraints11.insets = new Insets(5, 5, 5, 5);
145+ gridBagConstraints11.gridx = 2;
114146 GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
115147 gridBagConstraints5.fill = GridBagConstraints.BOTH;
116148 gridBagConstraints5.gridy = 2;
@@ -120,12 +152,13 @@
120152 gridBagConstraints5.insets = new Insets(5, 5, 5, 5);
121153 gridBagConstraints5.gridx = 0;
122154 GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
123- gridBagConstraints4.gridx = 2;
155+ gridBagConstraints4.gridx = 0;
124156 gridBagConstraints4.weightx = 0.0;
125157 gridBagConstraints4.fill = GridBagConstraints.HORIZONTAL;
126158 gridBagConstraints4.gridheight = 2;
127159 gridBagConstraints4.anchor = GridBagConstraints.NORTH;
128- gridBagConstraints4.gridy = 1;
160+ gridBagConstraints4.gridwidth = 3;
161+ gridBagConstraints4.gridy = 3;
129162 GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
130163 gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL;
131164 gridBagConstraints3.gridy = 1;
@@ -135,7 +168,7 @@
135168 GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
136169 gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL;
137170 gridBagConstraints2.gridy = 1;
138- gridBagConstraints2.weightx = 50.0;
171+ gridBagConstraints2.weightx = 40.0;
139172 gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
140173 gridBagConstraints2.gridx = 0;
141174 GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
@@ -156,6 +189,8 @@
156189 jContentPane.add(getPortText(), gridBagConstraints3);
157190 jContentPane.add(getButtonPanel(), gridBagConstraints4);
158191 jContentPane.add(getScrollPane(), gridBagConstraints5);
192+ jContentPane.add(getScroll2Pane(), gridBagConstraints11);
193+ jContentPane.add(jLabel2, gridBagConstraints21);
159194 }
160195 return jContentPane;
161196 }
@@ -196,11 +231,12 @@
196231 gridBagConstraints7.fill = GridBagConstraints.HORIZONTAL;
197232 gridBagConstraints7.insets = new Insets(5, 5, 5, 5);
198233 GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
199- gridBagConstraints6.gridx = 0;
234+ gridBagConstraints6.gridx = 1;
200235 gridBagConstraints6.insets = new Insets(5, 5, 5, 5);
201- gridBagConstraints6.gridy = 1;
236+ gridBagConstraints6.gridy = 0;
202237 buttonPanel = new JPanel();
203238 buttonPanel.setLayout(new GridBagLayout());
239+ buttonPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
204240 buttonPanel.add(getOkButton(), gridBagConstraints7);
205241 buttonPanel.add(getCancelButton(), gridBagConstraints6);
206242 }
@@ -215,7 +251,7 @@
215251 private JButton getOkButton() {
216252 if (okButton == null) {
217253 okButton = new JButton();
218- okButton.setText("接続");
254+ okButton.setText(" 接続 ");
219255 okButton.addActionListener(new java.awt.event.ActionListener() {
220256 public void actionPerformed(java.awt.event.ActionEvent e) {
221257 ServerAddress address = new ServerAddress();
@@ -224,7 +260,6 @@
224260 for (Iterator<ServerAddress> iter = addressList.iterator(); iter.hasNext();) {
225261 ServerAddress addr = iter.next();
226262 if(addr.equals(address)){
227- address.setSessionId(addr.getSessionId());
228263 iter.remove();
229264 }
230265 }
@@ -233,6 +268,19 @@
233268 addressList.remove(7);
234269 }
235270 StorageUtils.save(addressList, "server.xml");
271+ Session session = (Session) sessionIdList.getSelectedValue();
272+ if(session == null){
273+ session = new Session();
274+ }
275+ for (Iterator<Session> iterator = sessionList.iterator(); iterator.hasNext();) {
276+ Session s = (Session) iterator.next();
277+ if(session.equals(s)){
278+ iterator.remove();
279+ break;
280+ }
281+ }
282+ sessionList.add(0, session);
283+ StorageUtils.save(sessionList, StorageUtils.SESSION);
236284 connectAction.actionPerformed(e);
237285 dispose();
238286 }
@@ -337,4 +385,38 @@
337385 return formatterFactory;
338386 }
339387
388+ /**
389+ * This method initializes scroll2Pane
390+ *
391+ * @return javax.swing.JScrollPane
392+ */
393+ private JScrollPane getScroll2Pane() {
394+ if (scroll2Pane == null) {
395+ scroll2Pane = new JScrollPane();
396+ scroll2Pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
397+ scroll2Pane.setViewportView(getSessionIdList());
398+ }
399+ return scroll2Pane;
400+ }
401+
402+ /**
403+ * This method initializes sessionIdList
404+ *
405+ * @return javax.swing.JList
406+ */
407+ private JList getSessionIdList() {
408+ if (sessionIdList == null) {
409+ sessionIdList = new JList();
410+ sessionIdList.setModel(getSessionIdListModel());
411+ }
412+ return sessionIdList;
413+ }
414+
415+ public DefaultListModel getSessionIdListModel() {
416+ if(sessionIdListModel == null){
417+ sessionIdListModel = new DefaultListModel();
418+ }
419+ return sessionIdListModel;
420+ }
421+
340422 } // @jve:decl-index=0:visual-constraint="10,10"
--- chaplet/trunk/src/core/jp/sf/chaplet/core/client/LoginAction.java (revision 35)
+++ chaplet/trunk/src/core/jp/sf/chaplet/core/client/LoginAction.java (revision 36)
@@ -25,13 +25,16 @@
2525 ConfigLoader.getInstance().load().setGM(response.length > 3);
2626 Handle handle = (Handle) StorageUtils.load(StorageUtils.HANDLE, Handle.class);
2727 appendSystemLog(handle.getName() + " さんがログインしました。");
28- ArrayList<ServerAddress> serverList =
29- (ArrayList<ServerAddress>) StorageUtils.load("server.xml", ArrayList.class);
30- if(serverList.size() > 0){
31- ServerAddress address = serverList.get(0);
32- address.setSessionId(response[1]);
33- StorageUtils.save(serverList, "server.xml");
28+ ArrayList<Session> sessionList =
29+ (ArrayList<Session>) StorageUtils.load(StorageUtils.SESSION, ArrayList.class);
30+ Session session = null;
31+ if(sessionList.size() == 0){
32+ session = new Session();
33+ } else {
34+ session = sessionList.get(0);
3435 }
36+ session.setSessionId(response[1]);
37+ StorageUtils.save(sessionList, StorageUtils.SESSION);
3538
3639 getMainView().setLoginOK(true);
3740 return ActionResult.OK_NEXT;
--- chaplet/trunk/src/core/jp/sf/chaplet/core/client/ServerAddress.java (revision 35)
+++ chaplet/trunk/src/core/jp/sf/chaplet/core/client/ServerAddress.java (revision 36)
@@ -3,6 +3,7 @@
33 */
44 package jp.sf.chaplet.core.client;
55
6+
67 /**
78 * サーバのアドレス。<br>
89 * ホスト名とポート番号の組。
@@ -22,7 +23,6 @@
2223 this.port = port;
2324 }
2425
25- private String sessionId;
2626 /**
2727 * @return host
2828 */
@@ -72,16 +72,4 @@
7272 }
7373 return host.equals(address.host) && port == address.port;
7474 }
75- /**
76- * @return sessionId
77- */
78- public String getSessionId() {
79- return sessionId;
80- }
81- /**
82- * @param sessionId 設定する sessionId
83- */
84- public void setSessionId(String sessionId) {
85- this.sessionId = sessionId;
86- }
8775 }
--- chaplet/trunk/src/core/jp/sf/chaplet/core/client/ChatClient.java (revision 35)
+++ chaplet/trunk/src/core/jp/sf/chaplet/core/client/ChatClient.java (revision 36)
@@ -481,10 +481,23 @@
481481 view.setMessage("接続失敗です。先にあなたの名前を指定してください。");
482482 return;
483483 }
484+ Handle handle = (Handle) StorageUtils.load(StorageUtils.HANDLE, Handle.class);
485+ handle.setName(name);
486+ StorageUtils.save(handle, StorageUtils.HANDLE);
487+
484488 ServerAddress address = serverList.get(0);
489+
490+ String sessionId = "";
491+ ArrayList<Session> sessionList = (ArrayList<Session>) StorageUtils.load(StorageUtils.SESSION, ArrayList.class);
492+ if(sessionList.size() > 0){
493+ Session session = sessionList.get(0);
494+ if(!session.isNew()){
495+ sessionId = session.getSessionId();
496+ }
497+ }
498+
485499 try {
486- connection.connect(address.getHost(), address.getPort(), address
487- .getSessionId(), name);
500+ connection.connect(address.getHost(), address.getPort(), sessionId, name);
488501 return;
489502 } catch (Exception e) {
490503 view.setMessage("サーバ [" + address + "] への接続に失敗しました。");
@@ -493,10 +506,18 @@
493506 }
494507 }
495508
509+ @SuppressWarnings("unchecked")
496510 private void disconnect() {
497511 connection.close();
498512 view.appendSystemLog(view.getHandleText().getText() + " さんがログアウトしました。");
499513 view.setLoginOK(false);
514+ ArrayList<Session> sessionList =
515+ (ArrayList<Session>) StorageUtils.load(StorageUtils.SESSION, ArrayList.class);
516+ if(sessionList.size() > 0){
517+ Session session = sessionList.get(0);
518+ session.setDate(new Date());
519+ StorageUtils.save(sessionList, StorageUtils.SESSION);
520+ }
500521 }
501522
502523 /**
@@ -599,7 +620,6 @@
599620 address = new ServerAddress();
600621 address.setHost("127.0.0.1");
601622 address.setPort(10001);
602- address.setSessionId(UUID.randomUUID().toString());
603623 serverList.add(0, address);
604624 } else {
605625 address = serverList.get(0);
@@ -607,19 +627,37 @@
607627 address = new ServerAddress();
608628 address.setHost("127.0.0.1");
609629 address.setPort(10001);
610- address.setSessionId(UUID.randomUUID().toString());
611630 serverList.add(0, address);
612631 }
613632 }
614633 StorageUtils.save(serverList, "server.xml");
615634
635+ ArrayList<Session> sessionList = (ArrayList<Session>) StorageUtils.load(StorageUtils.SESSION, ArrayList.class);
636+ Session session = null;
637+ if(sessionList.size() == 0){
638+ session = new Session();
639+ session.setSessionId(UUID.randomUUID().toString());
640+ sessionList.add(session);
641+ } else {
642+ session = sessionList.get(0);
643+ if(session.isNew()){
644+ session = new Session();
645+ session.setSessionId(UUID.randomUUID().toString());
646+ sessionList.add(0, session);
647+ }
648+ }
649+ StorageUtils.save(sessionList, StorageUtils.SESSION);
650+
616651 String name = view.getHandleText().getText();
617652 if (name == null || name.length() == 0) {
618653 view.setMessage("接続失敗です。先にあなたの名前を指定してください。");
619654 return;
620655 }
656+ Handle handle = (Handle) StorageUtils.load(StorageUtils.HANDLE, Handle.class);
657+ handle.setName(name);
658+ StorageUtils.save(handle, StorageUtils.HANDLE);
621659
622- final String sessionId = address.getSessionId();
660+ final String sessionId = session.getSessionId();
623661
624662 Thread thread = new Thread(new Runnable() {
625663 public void run() {
--- chaplet/trunk/src/core/jp/sf/chaplet/core/client/Session.java (nonexistent)
+++ chaplet/trunk/src/core/jp/sf/chaplet/core/client/Session.java (revision 36)
@@ -0,0 +1,57 @@
1+/**
2+ *
3+ */
4+package jp.sf.chaplet.core.client;
5+
6+import java.text.DateFormat;
7+import java.text.SimpleDateFormat;
8+import java.util.Date;
9+
10+/**
11+ * Session<br>
12+ * @version $Id$
13+ */
14+public class Session {
15+ private String sessionId = "";
16+ private Date date;
17+ private DateFormat format = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
18+ public String getSessionId() {
19+ return sessionId;
20+ }
21+ public void setSessionId(String sessionId) {
22+ this.sessionId = sessionId;
23+ }
24+ public Date getDate() {
25+ return date;
26+ }
27+ public void setDate(Date date) {
28+ this.date = date;
29+ }
30+
31+ /**
32+ * @see java.lang.Object#equals(java.lang.Object)
33+ */
34+ @Override
35+ public boolean equals(Object obj) {
36+ if(obj instanceof Session){
37+ return false;
38+ }
39+ return sessionId.equals(((Session) obj).sessionId);
40+ }
41+
42+ /**
43+ * @see java.lang.Object#toString()
44+ */
45+ @Override
46+ public String toString() {
47+ if(date == null){
48+ return "(新規)";
49+ } else {
50+ return format.format(date);
51+ }
52+ }
53+
54+ public boolean isNew(){
55+ return date == null;
56+ }
57+}
Added: svn:keywords
## -0,0 +1 ##
+" Date Revision Author HeadURL Id "
\ No newline at end of property
Show on old repository browser