GM設定と、プラグインビューのダイアログ表示機能を実装
@@ -519,6 +519,7 @@ | ||
519 | 519 | if (sceneButton == null) { |
520 | 520 | sceneButton = new JButton(); |
521 | 521 | sceneButton.setText("次のシーン"); |
522 | + sceneButton.setEnabled(false); | |
522 | 523 | sceneButton.addActionListener(new java.awt.event.ActionListener() { |
523 | 524 | public void actionPerformed(java.awt.event.ActionEvent e) { |
524 | 525 | actionMap.get("nextScene").actionPerformed(e); |
@@ -600,6 +601,7 @@ | ||
600 | 601 | if (initButton == null) { |
601 | 602 | initButton = new JButton(); |
602 | 603 | initButton.setText("初期化"); |
604 | + initButton.setEnabled(false); | |
603 | 605 | initButton.addActionListener(new java.awt.event.ActionListener() { |
604 | 606 | public void actionPerformed(java.awt.event.ActionEvent e) { |
605 | 607 | actionMap.get("initServer").actionPerformed(e); |
@@ -17,6 +17,8 @@ | ||
17 | 17 | /** ユーザが生きているかどうか */ |
18 | 18 | private boolean active = true; |
19 | 19 | |
20 | + private String sessionId; | |
21 | + | |
20 | 22 | public UserStatus(){ |
21 | 23 | |
22 | 24 | } |
@@ -27,11 +29,12 @@ | ||
27 | 29 | * @param writing |
28 | 30 | * @param status |
29 | 31 | */ |
30 | - public UserStatus(String name, boolean writing, String status) { | |
32 | + public UserStatus(String name, boolean writing, String status, String sessionId) { | |
31 | 33 | super(); |
32 | 34 | this.name = name; |
33 | 35 | this.writing = writing; |
34 | 36 | this.status.add(status); |
37 | + this.sessionId = sessionId; | |
35 | 38 | } |
36 | 39 | |
37 | 40 | /** |
@@ -92,4 +95,12 @@ | ||
92 | 95 | public void setActive(boolean active) { |
93 | 96 | this.active = active; |
94 | 97 | } |
98 | + | |
99 | + public String getSessionId() { | |
100 | + return sessionId; | |
101 | + } | |
102 | + | |
103 | + public void setSessionId(String sessionId) { | |
104 | + this.sessionId = sessionId; | |
105 | + } | |
95 | 106 | } |
@@ -190,15 +190,16 @@ | ||
190 | 190 | */ |
191 | 191 | public void sendStatus(ClientProxy proxy) { |
192 | 192 | User[] users = userManager.getAllUsers(); |
193 | - String[] message = new String[users.length * 3 + 1]; | |
193 | + String[] message = new String[users.length * 4 + 1]; | |
194 | 194 | message[0] = "status"; |
195 | 195 | for (int i = 0; i < users.length; i++) { |
196 | - message[i * 3 + 1] = users[i].getDisplayName(); | |
197 | - message[i * 3 + 2] = users[i].isWriting() ? "y" : "n"; | |
196 | + message[i * 4 + 1] = users[i].getDisplayName(); | |
197 | + message[i * 4 + 2] = users[i].isWriting() ? "y" : "n"; | |
198 | + message[i * 4 + 3] = users[i].getSessionId(); | |
198 | 199 | if(primaryPlugin != null){ |
199 | - message[i * 3 + 3] = primaryPlugin.getUserStatus(users[i]); | |
200 | - if(message[i * 3 + 3] == null || message[i * 3 + 3].length() == 0){ | |
201 | - message[i * 3 + 3] = " "; | |
200 | + message[i * 4 + 4] = primaryPlugin.getUserStatus(users[i]); | |
201 | + if(message[i * 4 + 4] == null || message[i * 3 + 3].length() == 0){ | |
202 | + message[i * 4 + 4] = " "; | |
202 | 203 | } |
203 | 204 | } |
204 | 205 | } |
@@ -22,19 +22,18 @@ | ||
22 | 22 | throws IOException { |
23 | 23 | if(isOwner(proxy.getSessionId()) |
24 | 24 | && getUserManager().getUser(request[1]) != null){ |
25 | - if(getUserManager().getMasterId().equals(proxy.getSessionId())){ | |
26 | - if(!proxy.getSessionId().equals(request[1])){ | |
27 | - getUserManager().setMasterId(request[1]); | |
28 | - ClientProxy currentUserProxy = getServer().getProxy(request[1]); | |
29 | - currentUserProxy.sendMessage(new String[]{request[0], "gm"}); | |
30 | - } | |
31 | - } else { | |
32 | - ClientProxy prevUserProxy = getServer().getProxy(getUserManager().getMasterId()); | |
33 | - prevUserProxy.sendMessage(new String[]{request[0], "nogm"}); | |
34 | - getUserManager().setMasterId(request[1]); | |
35 | - ClientProxy currentUserProxy = getServer().getProxy(request[1]); | |
36 | - currentUserProxy.sendMessage(new String[]{request[0], "gm"}); | |
37 | - } | |
25 | + String prevId = getUserManager().getMasterId(); | |
26 | + if(!prevId.equals(getServer().getOwner())){ | |
27 | + ClientProxy prevUserProxy = getServer().getProxy(request[1]); | |
28 | + if(prevUserProxy != null){ | |
29 | + prevUserProxy.sendMessage(new String[]{request[0], "nogm"}); | |
30 | + } | |
31 | + } | |
32 | + getUserManager().setMasterId(request[1]); | |
33 | + ClientProxy nextUserProxy = getServer().getProxy(request[1]); | |
34 | + if(nextUserProxy != null){ | |
35 | + nextUserProxy.sendMessage(new String[]{request[0], "gm"}); | |
36 | + } | |
38 | 37 | } |
39 | 38 | return ActionResult.OK_NEXT; |
40 | 39 | } |
@@ -86,8 +86,6 @@ | ||
86 | 86 | |
87 | 87 | private JMenuItem exitItem = null; |
88 | 88 | |
89 | - private JButton saveButton = null; | |
90 | - | |
91 | 89 | private JScrollPane textScrollPane = null; |
92 | 90 | |
93 | 91 | private JPanel chatPanel = null; |
@@ -180,6 +178,12 @@ | ||
180 | 178 | |
181 | 179 | private JMenuItem saveLogItem = null; |
182 | 180 | |
181 | + private JPopupMenu userPopupMenu = null; // @jve:decl-index=0:visual-constraint="911,405" | |
182 | + | |
183 | + private JMenuItem setGmItem = null; | |
184 | + | |
185 | + private HashMap<String, PluginDialog> dialogMap = new HashMap<String, PluginDialog>(); | |
186 | + | |
183 | 187 | /** |
184 | 188 | * This is the default constructor |
185 | 189 | */ |
@@ -300,7 +304,6 @@ | ||
300 | 304 | toolBar.add(getDisconnectButton()); |
301 | 305 | toolBar.add(getServerButton()); |
302 | 306 | toolBar.addSeparator(); |
303 | - toolBar.add(getSaveButton()); | |
304 | 307 | } |
305 | 308 | return toolBar; |
306 | 309 | } |
@@ -392,18 +395,6 @@ | ||
392 | 395 | } |
393 | 396 | |
394 | 397 | /** |
395 | - * This method initializes saveButton | |
396 | - * | |
397 | - * @return javax.swing.JButton | |
398 | - */ | |
399 | - private JButton getSaveButton() { | |
400 | - if (saveButton == null) { | |
401 | - saveButton = new JButton(); | |
402 | - } | |
403 | - return saveButton; | |
404 | - } | |
405 | - | |
406 | - /** | |
407 | 398 | * This method initializes textScrollPane |
408 | 399 | * |
409 | 400 | * @return javax.swing.JScrollPane |
@@ -666,11 +657,19 @@ | ||
666 | 657 | * |
667 | 658 | * @return javax.swing.JTable |
668 | 659 | */ |
669 | - private JTable getUserTable() { | |
660 | + public JTable getUserTable() { | |
670 | 661 | if (userTable == null) { |
671 | 662 | userTable = new JTable(); |
672 | 663 | userTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); |
673 | 664 | userTable.setModel(getUserTableModel()); |
665 | + userTable.addMouseListener(new java.awt.event.MouseAdapter() { | |
666 | + public void mouseClicked(java.awt.event.MouseEvent e) { | |
667 | + int rowIndex = getUserTable().getSelectedRow(); | |
668 | + if(rowIndex >= 0 && SwingUtilities.isRightMouseButton(e)){ | |
669 | + getUserPopupMenu().show(userTable, e.getX(), e.getY()); | |
670 | + } | |
671 | + } | |
672 | + }); | |
674 | 673 | TableColumnModel tcm = userTable.getColumnModel(); |
675 | 674 | TableColumn column0 = tcm.getColumn(0); |
676 | 675 | column0.setPreferredWidth(100); |
@@ -705,7 +704,7 @@ | ||
705 | 704 | * |
706 | 705 | * @return jp.sf.chaplet.core.ui.UserTableModel |
707 | 706 | */ |
708 | - private UserTableModel getUserTableModel() { | |
707 | + public UserTableModel getUserTableModel() { | |
709 | 708 | if (userTableModel == null) { |
710 | 709 | userTableModel = new UserTableModel(); |
711 | 710 | } |
@@ -737,15 +736,22 @@ | ||
737 | 736 | |
738 | 737 | public void propertyChange(PropertyChangeEvent evt) { |
739 | 738 | if(evt.getPropertyName().equals("displayMode")){ |
739 | + ClientPlugin plugin = (ClientPlugin) evt.getSource(); | |
740 | + // 新しいビューの追加 | |
741 | + if(evt.getNewValue() == DisplayMode.TAB){ | |
742 | + showAsTabItem(plugin); | |
743 | + } else if(evt.getNewValue() == DisplayMode.WINDOW){ | |
744 | + showAsWindow(plugin); | |
745 | + } | |
740 | 746 | // 古いビューの削除 |
741 | 747 | if(evt.getOldValue() == DisplayMode.TAB){ |
742 | - removeTabItem((ClientPlugin) evt.getSource()); | |
748 | + removeTabItem(plugin); | |
749 | + } else if(evt.getOldValue() == DisplayMode.WINDOW){ | |
750 | + PluginDialog dialog = dialogMap.get(plugin.getPluginId()); | |
751 | + if(dialog != null){ | |
752 | + dialog.dispose(); | |
753 | + } | |
743 | 754 | } |
744 | - | |
745 | - // 新しいビューの追加 | |
746 | - if(evt.getNewValue() == DisplayMode.TAB){ | |
747 | - showAsTabItem((ClientPlugin) evt.getSource()); | |
748 | - } | |
749 | 755 | } |
750 | 756 | } |
751 | 757 |
@@ -867,9 +873,22 @@ | ||
867 | 873 | getTabbedPane().remove(plugin.getSwingComponent()); |
868 | 874 | } |
869 | 875 | |
870 | - public void showAsWindow(ClientPlugin plugin) { | |
871 | - // TODO 自動生成されたメソッド・スタブ | |
872 | - | |
876 | + public void showAsWindow(final ClientPlugin plugin) { | |
877 | + final PluginDialog dialog = new PluginDialog(this); | |
878 | + dialog.add(plugin.getSwingComponent(), BorderLayout.CENTER); | |
879 | + dialog.setTitle(plugin.getName()); | |
880 | + dialog.addWindowListener(new WindowAdapter(){ | |
881 | + public void windowClosing(WindowEvent e) { | |
882 | + plugin.setDisplayMode(DisplayMode.NONE); | |
883 | + getPluginPanel().getPluginTableModel().fireTableDataChanged(); | |
884 | + } | |
885 | + }); | |
886 | + dialogMap.put(plugin.getPluginId(), dialog); | |
887 | + SwingUtilities.invokeLater(new Runnable() { | |
888 | + public void run() { | |
889 | + dialog.setVisible(true); | |
890 | + } | |
891 | + }); | |
873 | 892 | } |
874 | 893 | |
875 | 894 | public void showStatus(UserStatus[] status) { |
@@ -1061,7 +1080,7 @@ | ||
1061 | 1080 | initAllItem.setText("すべて初期化"); |
1062 | 1081 | initAllItem.addActionListener(new java.awt.event.ActionListener() { |
1063 | 1082 | public void actionPerformed(java.awt.event.ActionEvent e) { |
1064 | - System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() | |
1083 | + actionMap.get("reload").actionPerformed(e); | |
1065 | 1084 | } |
1066 | 1085 | }); |
1067 | 1086 | } |
@@ -1323,4 +1342,35 @@ | ||
1323 | 1342 | } |
1324 | 1343 | return saveLogItem; |
1325 | 1344 | } |
1345 | + | |
1346 | + /** | |
1347 | + * This method initializes userPopupMenu | |
1348 | + * | |
1349 | + * @return javax.swing.JPopupMenu | |
1350 | + */ | |
1351 | + private JPopupMenu getUserPopupMenu() { | |
1352 | + if (userPopupMenu == null) { | |
1353 | + userPopupMenu = new JPopupMenu(); | |
1354 | + userPopupMenu.add(getSetGmItem()); | |
1355 | + } | |
1356 | + return userPopupMenu; | |
1357 | + } | |
1358 | + | |
1359 | + /** | |
1360 | + * This method initializes setGmItem | |
1361 | + * | |
1362 | + * @return javax.swing.JMenuItem | |
1363 | + */ | |
1364 | + private JMenuItem getSetGmItem() { | |
1365 | + if (setGmItem == null) { | |
1366 | + setGmItem = new JMenuItem(); | |
1367 | + setGmItem.setText("GMに選ぶ"); | |
1368 | + setGmItem.addActionListener(new java.awt.event.ActionListener() { | |
1369 | + public void actionPerformed(java.awt.event.ActionEvent e) { | |
1370 | + actionMap.get("callSetGM").actionPerformed(e); | |
1371 | + } | |
1372 | + }); | |
1373 | + } | |
1374 | + return setGmItem; | |
1375 | + } | |
1326 | 1376 | } // @jve:decl-index=0:visual-constraint="10,10" |
@@ -104,7 +104,7 @@ | ||
104 | 104 | * |
105 | 105 | * @return jp.sf.chaplet.core.ui.PluginTableModel |
106 | 106 | */ |
107 | - private PluginTableModel getPluginTableModel() { | |
107 | + public PluginTableModel getPluginTableModel() { | |
108 | 108 | if (pluginTableModel == null) { |
109 | 109 | pluginTableModel = new PluginTableModel(); |
110 | 110 | } |
@@ -0,0 +1,55 @@ | ||
1 | +/** | |
2 | + * | |
3 | + */ | |
4 | +package jp.sf.chaplet.core.ui; | |
5 | + | |
6 | +import java.awt.BorderLayout; | |
7 | +import java.awt.Frame; | |
8 | + | |
9 | +import javax.swing.JDialog; | |
10 | +import javax.swing.JPanel; | |
11 | +import javax.swing.WindowConstants; | |
12 | + | |
13 | +/** | |
14 | + * PluginDialog<br> | |
15 | + * @version $Id$ | |
16 | + */ | |
17 | +public class PluginDialog extends JDialog { | |
18 | + | |
19 | + private static final long serialVersionUID = 1L; | |
20 | + | |
21 | + private JPanel jContentPane = null; | |
22 | + | |
23 | + /** | |
24 | + * @param owner | |
25 | + */ | |
26 | + public PluginDialog(Frame owner) { | |
27 | + super(owner); | |
28 | + initialize(); | |
29 | + } | |
30 | + | |
31 | + /** | |
32 | + * This method initializes this | |
33 | + * | |
34 | + * @return void | |
35 | + */ | |
36 | + private void initialize() { | |
37 | + this.setSize(428, 426); | |
38 | + this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); | |
39 | + this.setContentPane(getJContentPane()); | |
40 | + } | |
41 | + | |
42 | + /** | |
43 | + * This method initializes jContentPane | |
44 | + * | |
45 | + * @return javax.swing.JPanel | |
46 | + */ | |
47 | + private JPanel getJContentPane() { | |
48 | + if (jContentPane == null) { | |
49 | + jContentPane = new JPanel(); | |
50 | + jContentPane.setLayout(new BorderLayout()); | |
51 | + } | |
52 | + return jContentPane; | |
53 | + } | |
54 | + | |
55 | +} // @jve:decl-index=0:visual-constraint="10,10" |
@@ -430,8 +430,13 @@ | ||
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
433 | - public void callSetGM(String name) { | |
434 | - getConnection().sendMessage(new String[] { "setgm", name }); | |
433 | + @Action | |
434 | + public void callSetGM() { | |
435 | + int rowIndex = view.getUserTable().getSelectedRow(); | |
436 | + if(rowIndex >= 0){ | |
437 | + UserStatus user = view.getUserTableModel().getRow(rowIndex); | |
438 | + getConnection().sendMessage(new String[] { "setgm", user.getSessionId() }); | |
439 | + } | |
435 | 440 | } |
436 | 441 | |
437 | 442 | /** |
@@ -18,12 +18,13 @@ | ||
18 | 18 | * @see jp.sf.chaplet.core.client.ClientAction#messageRecieved(java.lang.String[]) |
19 | 19 | */ |
20 | 20 | public ActionResult messageRecieved(String[] message) { |
21 | - UserStatus[] status = new UserStatus[(message.length - 1)/ 3]; | |
21 | + UserStatus[] status = new UserStatus[(message.length - 1)/ 4]; | |
22 | 22 | for(int i = 0; i < status.length; i++){ |
23 | 23 | status[i] = new UserStatus(); |
24 | - status[i].setName(message[i * 3 + 1]); | |
25 | - status[i].setWriting(message[i * 3 + 2].equals("y")); | |
26 | - String[] extStatus = message[i * 3 + 3].split(","); | |
24 | + status[i].setName(message[i * 4 + 1]); | |
25 | + status[i].setWriting(message[i * 4 + 2].equals("y")); | |
26 | + status[i].setSessionId(message[i * 4 + 3]); | |
27 | + String[] extStatus = message[i * 4 + 4].split(","); | |
27 | 28 | for (int j = 0; j < extStatus.length; j++) { |
28 | 29 | status[i].setStatusOf(j, extStatus[j]); |
29 | 30 | } |