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 RemoveGroupFrame extends JDialog {
023    
024      DaemonCommunication daemonCommunication;
025      UserInterface userInterface;
026      LocalPluginManager localPluginManager;
027    
028      JPanel contentPane;
029      JButton jButtonOk = new JButton();
030      JButton jButtonCancel = new JButton();
031      JLabel jLabelRemoveGroup = new JLabel();
032      JScrollPane jScrollPane1 = new JScrollPane();
033    
034      JList jList1;
035      String str = null;
036    
037      // Construct the frame
038      public RemoveGroupFrame() {
039        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
040        try {
041          jbInit();
042        }
043        catch (Exception e) {
044          e.printStackTrace();
045        }
046      }
047    
048      // Component initialization
049      private void jbInit() throws Exception {
050        contentPane = (JPanel)this.getContentPane();
051        jButtonOk.setBounds(new Rectangle(92, 195, 56, 25));
052        jButtonOk.setText("Ok");
053        jButtonOk.addActionListener(new RemoveGroupFrame_jButtonOk_actionAdapter(this));
054        jButtonCancel.setBounds(new Rectangle(166, 195, 74, 25));
055        jButtonCancel.setText("Cancel");
056        jButtonCancel.addActionListener(new
057            RemoveGroupFrame_jButtonCancel_actionAdapter(this));
058        contentPane.setLayout(null);
059        this.setTitle("Sharpster");
060        this.setSize(new Dimension(257, 268));
061    
062        jLabelRemoveGroup.setText("Remove Group:");
063        jLabelRemoveGroup.setBounds(new Rectangle(12, 19, 94, 15));
064        jScrollPane1.setBounds(new Rectangle(105, 17, 134, 165));
065        contentPane.add(jScrollPane1, null);
066        contentPane.add(jButtonOk, null);
067        contentPane.add(jButtonCancel, null);
068        contentPane.add(jLabelRemoveGroup, null);
069        jScrollPane1.getViewport().add(jList1, null);
070    
071        ListSelectionModel selectionModel = new SingleSelectionModel() {
072          public void updateSingleSelection(int oldIndex, int newIndex) {
073            str = (String) jList1.getModel().getElementAt(newIndex);
074            System.out.println(str);
075          }
076        };
077    
078    
079    
080        daemonCommunication = new DaemonCommunication();
081        localPluginManager = new LocalPluginManager();
082        userInterface = new UserInterface(daemonCommunication,
083                                          localPluginManager);
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    
098        jList1.setSelectionModel(selectionModel);
099        jScrollPane1.getViewport().add(jList1, null);
100    
101      }
102    
103      void jButtonOk_actionPerformed(ActionEvent e) {
104        GroupCommand gc = new GroupCommand();
105    
106        gc.command = SubCommand.REMOVE_GROUP;
107        gc.group = str;
108    
109        daemonCommunication.groupCommand(gc);
110    
111        this.dispose();
112      }
113    
114      void jButtonCancel_actionPerformed(ActionEvent e) {
115        this.dispose();
116      }
117    
118    }
119    
120    class RemoveGroupFrame_jButtonOk_actionAdapter
121        implements java.awt.event.ActionListener {
122      RemoveGroupFrame adaptee;
123    
124      RemoveGroupFrame_jButtonOk_actionAdapter(RemoveGroupFrame adaptee) {
125        this.adaptee = adaptee;
126      }
127    
128      public void actionPerformed(ActionEvent e) {
129        adaptee.jButtonOk_actionPerformed(e);
130      }
131    }
132    
133    class RemoveGroupFrame_jButtonCancel_actionAdapter
134        implements java.awt.event.ActionListener {
135      RemoveGroupFrame adaptee;
136    
137      RemoveGroupFrame_jButtonCancel_actionAdapter(RemoveGroupFrame adaptee) {
138        this.adaptee = adaptee;
139      }
140    
141      public void actionPerformed(ActionEvent e) {
142        adaptee.jButtonCancel_actionPerformed(e);
143      }
144    }