001 package sharpster.client.gui; 002 003 /** 004 * <p>Title: </p> 005 * <p>Description: </p> 006 * <p>Copyright: Copyright (c) 2003</p> 007 * <p>Company: Kafka</p> 008 * @author Tommy Eriksson 009 * @version 1.0 010 */ 011 012 import java.awt.*; 013 import java.awt.event.*; 014 import javax.swing.*; 015 016 import sharpster.common.*; 017 import sharpster.client.daemoncommunication.DaemonCommunication; 018 import sharpster.client.localplugin.LocalPluginManager; 019 import sharpster.client.userinterface.UserInterface; 020 021 022 public class ListGroupsFrame extends JDialog { 023 024 DaemonCommunication daemonCommunication; 025 UserInterface userInterface; 026 LocalPluginManager localPluginManager; 027 028 029 JPanel contentPane; 030 JButton jButtonOk = new JButton(); 031 JLabel jLabelGroups = new JLabel(); 032 JScrollPane jScrollPane1 = new JScrollPane(); 033 String[] lista = {"tommy", "maria", "fiffi", "inja", "bajs", "kiss"}; 034 JList jList1;// = new JList(lista); 035 String str = null; 036 037 038 // Construct the frame 039 public ListGroupsFrame() { 040 enableEvents(AWTEvent.WINDOW_EVENT_MASK); 041 try { 042 jbInit(); 043 } 044 catch (Exception e) { 045 e.printStackTrace(); 046 } 047 } 048 049 // Component initialization 050 private void jbInit() throws Exception { 051 contentPane = (JPanel) this.getContentPane(); 052 jButtonOk.setBounds(new Rectangle(74, 144, 57, 25)); 053 jButtonOk.setText("Ok"); 054 jButtonOk.addActionListener(new ListGroupsFrame_jButtonOk_actionAdapter(this)); 055 contentPane.setLayout(null); 056 this.setTitle("Sharpster"); 057 this.setSize(new Dimension(212, 214)); 058 059 jLabelGroups.setText("Groups:"); 060 jLabelGroups.setBounds(new Rectangle(17, 16, 50, 15)); 061 jScrollPane1.setBounds(new Rectangle(69, 14, 125, 116)); 062 contentPane.add(jButtonOk, null); 063 contentPane.add(jScrollPane1, null); 064 contentPane.add(jLabelGroups, null); 065 066 /** 067 ListSelectionModel selectionModel = new SingleSelectionModel() { 068 public void updateSingleSelection(int oldIndex, int newIndex) { 069 str = (String)jList1.getModel().getElementAt(newIndex); 070 System.out.println(str); 071 } 072 }; 073 */ 074 075 // jList1.setSelectionModel(selectionModel); 076 077 078 //Create all objects 079 daemonCommunication = new DaemonCommunication(); 080 localPluginManager = new LocalPluginManager(); 081 userInterface = new UserInterface(daemonCommunication, 082 localPluginManager); 083 084 085 ResponseCollection resp; 086 String[] str; 087 088 GroupCommand gc = new GroupCommand(); 089 090 gc.command = SubCommand.LIST_GROUPS; 091 092 resp = daemonCommunication.groupCommand(gc); 093 GroupResponse gr = (GroupResponse)resp.getResponse(0); 094 095 str = (String[])gr.getGroups().toArray(new String[0]); 096 jList1 = new JList(str); 097 jScrollPane1.getViewport().add(jList1, null); 098 099 100 } 101 102 void jButtonOk_actionPerformed(ActionEvent e) { 103 this.dispose(); 104 } 105 106 } 107 108 109 class ListGroupsFrame_jButtonOk_actionAdapter implements java.awt.event.ActionListener { 110 ListGroupsFrame adaptee; 111 112 ListGroupsFrame_jButtonOk_actionAdapter(ListGroupsFrame adaptee) { 113 this.adaptee = adaptee; 114 } 115 public void actionPerformed(ActionEvent e) { 116 adaptee.jButtonOk_actionPerformed(e); 117 } 118 }