Source code: org/alicebot/gui/ListDialog.java
1 // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.geocities.com/kpdus/jad.html
3 // Decompiler options: packimports(3)
4
5 package org.alicebot.gui;
6
7 import java.awt.*;
8 import java.awt.event.*;
9 import java.io.PrintStream;
10 import javax.swing.*;
11
12 public class ListDialog extends JDialog
13 {
14
15 public static void initialize(Component component, String as[], String s, String s1)
16 {
17 Frame frame = JOptionPane.getFrameForComponent(component);
18 dialog = new ListDialog(frame, as, s, s1);
19 }
20
21 public static String showDialog(Component component, String s)
22 {
23 if(dialog != null)
24 {
25 dialog.setValue(s);
26 dialog.setLocationRelativeTo(component);
27 dialog.setVisible(true);
28 } else
29 {
30 System.err.println("ListDialog requires you to call initialize before calling showDialog.");
31 }
32 return value;
33 }
34
35 private void setValue(String s)
36 {
37 value = s;
38 list.setSelectedValue(value, true);
39 }
40
41 private ListDialog(Frame frame, Object aobj[], String s, String s1)
42 {
43 super(frame, s, true);
44 JButton jbutton = new JButton("Cancel");
45 final JButton setButton = new JButton("Set");
46 jbutton.addActionListener(new ActionListener() {
47
48 public void actionPerformed(ActionEvent actionevent)
49 {
50 ListDialog.dialog.setVisible(false);
51 }
52
53 });
54 setButton.addActionListener(new ActionListener() {
55
56 public void actionPerformed(ActionEvent actionevent)
57 {
58 ListDialog.value = (String)list.getSelectedValue();
59 ListDialog.dialog.setVisible(false);
60 }
61
62 });
63 getRootPane().setDefaultButton(setButton);
64 list = new JList(aobj);
65 list.setSelectionMode(1);
66 list.addMouseListener(new MouseAdapter() {
67
68 public void mouseClicked(MouseEvent mouseevent)
69 {
70 if(mouseevent.getClickCount() == 2)
71 setButton.doClick();
72 }
73
74 });
75 JScrollPane jscrollpane = new JScrollPane(list);
76 jscrollpane.setPreferredSize(new Dimension(250, 80));
77 jscrollpane.setMinimumSize(new Dimension(250, 80));
78 jscrollpane.setAlignmentX(0.0F);
79 JPanel jpanel = new JPanel();
80 jpanel.setLayout(new BoxLayout(jpanel, 1));
81 JLabel jlabel = new JLabel(s1);
82 jlabel.setLabelFor(list);
83 jpanel.add(jlabel);
84 jpanel.add(Box.createRigidArea(new Dimension(0, 5)));
85 jpanel.add(jscrollpane);
86 jpanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
87 JPanel jpanel1 = new JPanel();
88 jpanel1.setLayout(new BoxLayout(jpanel1, 0));
89 jpanel1.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
90 jpanel1.add(Box.createHorizontalGlue());
91 jpanel1.add(jbutton);
92 jpanel1.add(Box.createRigidArea(new Dimension(10, 0)));
93 jpanel1.add(setButton);
94 Container container = getContentPane();
95 container.add(jpanel, "Center");
96 container.add(jpanel1, "South");
97 pack();
98 }
99
100 private static ListDialog dialog;
101 private static String value = "";
102 private JList list;
103
104
105
106
107 }