Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/alicebot/server/core/targeting/gui/TargetingGUI.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.server.core.targeting.gui;
6   
7   import java.awt.*;
8   import java.awt.event.ActionEvent;
9   import java.awt.event.ActionListener;
10  import java.io.File;
11  import java.io.IOException;
12  import javax.swing.*;
13  import org.alicebot.server.core.targeting.TargetingTool;
14  import org.alicebot.server.core.util.Trace;
15  
16  // Referenced classes of package org.alicebot.server.core.targeting.gui:
17  //            TargetPanel, InputPanel, CategoryPanel
18  
19  public class TargetingGUI extends JPanel
20  {
21  
22      public void start()
23      {
24          frame = new JFrame();
25          updateTitle();
26          frame.getContentPane().add(this);
27          frame.setDefaultCloseOperation(3);
28          frame.setJMenuBar(menuBar);
29          frame.pack();
30          frame.setLocation(50, 50);
31          frame.setIconImage(aliceIcon.getImage());
32          frame.setVisible(true);
33          targetPanel.nextTarget();
34      }
35  
36      public TargetingGUI(TargetingTool targetingtool)
37      {
38          targetingTool = targetingtool;
39          targetPanel = new TargetPanel(this);
40          targetPanel.setMinimumSize(minDimension);
41          targetPanel.setPreferredSize(prefDimension);
42          targetPanel.setAlignmentX(0.0F);
43          inputPanel = new InputPanel(this);
44          inputPanel.setMinimumSize(minDimension);
45          inputPanel.setPreferredSize(prefDimension);
46          inputPanel.setAlignmentX(0.0F);
47          categoryPanel = new CategoryPanel(this);
48          categoryPanel.setMinimumSize(minDimension);
49          categoryPanel.setPreferredSize(prefDimension);
50          categoryPanel.setAlignmentX(0.0F);
51          statusBar = new JLabel();
52          statusBar.setAlignmentX(1.0F);
53          statusBar.setHorizontalAlignment(4);
54          statusBar.setFont(new Font("Fixedsys", 0, 12));
55          statusBar.setForeground(Color.black);
56          statusBar.setMinimumSize(new Dimension(600, 14));
57          statusBar.setPreferredSize(new Dimension(700, 14));
58          statusBar.setMaximumSize(new Dimension(32767, 14));
59          tabbedPane = new JTabbedPane();
60          tabbedPane.setAlignmentX(1.0F);
61          tabbedPane.setMinimumSize(new Dimension(600, 500));
62          tabbedPane.setPreferredSize(new Dimension(700, 500));
63          tabbedPane.setMaximumSize(new Dimension(32767, 32767));
64          tabbedPane.setFont(new Font("Fixedsys", 0, 12));
65          tabbedPane.setTabPlacement(3);
66          tabbedPane.add("Targets", targetPanel);
67          tabbedPane.add("Inputs", inputPanel);
68          tabbedPane.add("Categories", categoryPanel);
69          setLayout(new BoxLayout(this, 1));
70          add(tabbedPane);
71          add(statusBar);
72          menuBar = new JMenuBar();
73          JMenu jmenu = new JMenu("File");
74          jmenu.setFont(new Font("Fixedsys", 0, 12));
75          jmenu.setMnemonic(70);
76          JMenuItem jmenuitem = new JMenuItem("Load targets data from URL...");
77          jmenuitem.setFont(new Font("Fixedsys", 0, 12));
78          jmenuitem.setMnemonic(85);
79          jmenuitem.addActionListener(new ActionListener() {
80  
81              public void actionPerformed(ActionEvent actionevent)
82              {
83                  loadDataURLBox();
84              }
85  
86          });
87          JMenuItem jmenuitem1 = new JMenuItem("Load targets data from file path...");
88          jmenuitem1.setFont(new Font("Fixedsys", 0, 12));
89          jmenuitem1.setMnemonic(80);
90          jmenuitem1.addActionListener(new ActionListener() {
91  
92              public void actionPerformed(ActionEvent actionevent)
93              {
94                  loadDataFilePathChooser();
95              }
96  
97          });
98          JMenuItem jmenuitem2 = new JMenuItem("Reload target data");
99          jmenuitem2.setFont(new Font("Fixedsys", 0, 12));
100         jmenuitem2.setMnemonic(82);
101         jmenuitem2.addActionListener(new ActionListener() {
102 
103             public void actionPerformed(ActionEvent actionevent)
104             {
105                 reloadTargets();
106             }
107 
108         });
109         JMenuItem jmenuitem3 = new JMenuItem("Exit");
110         jmenuitem3.setFont(new Font("Fixedsys", 0, 12));
111         jmenuitem3.setMnemonic(88);
112         jmenuitem3.addActionListener(new ActionListener() {
113 
114             public void actionPerformed(ActionEvent actionevent)
115             {
116                 shutdown();
117             }
118 
119         });
120         jmenu.add(jmenuitem);
121         jmenu.add(jmenuitem1);
122         jmenu.addSeparator();
123         jmenu.add(jmenuitem2);
124         jmenu.addSeparator();
125         jmenu.add(jmenuitem3);
126         JMenu jmenu1 = new JMenu("Edit");
127         jmenu1.setFont(new Font("Fixedsys", 0, 12));
128         jmenu1.setMnemonic(69);
129         JMenu jmenu2 = new JMenu("View");
130         jmenu2.setFont(new Font("Fixedsys", 0, 12));
131         jmenu2.setMnemonic(86);
132         JMenuItem jmenuitem4 = new JMenuItem("Targets");
133         jmenuitem4.setFont(new Font("Fixedsys", 0, 12));
134         jmenuitem4.setMnemonic(84);
135         jmenuitem4.addActionListener(new ActionListener() {
136 
137             public void actionPerformed(ActionEvent actionevent)
138             {
139                 viewTargets();
140             }
141 
142         });
143         JMenuItem jmenuitem5 = new JMenuItem("Inputs");
144         jmenuitem5.setFont(new Font("Fixedsys", 0, 12));
145         jmenuitem5.setMnemonic(73);
146         jmenuitem5.addActionListener(new ActionListener() {
147 
148             public void actionPerformed(ActionEvent actionevent)
149             {
150                 viewInputs();
151             }
152 
153         });
154         JMenuItem jmenuitem6 = new JMenuItem("Inputs");
155         jmenuitem6.setFont(new Font("Fixedsys", 0, 12));
156         jmenuitem6.setMnemonic(67);
157         jmenuitem6.addActionListener(new ActionListener() {
158 
159             public void actionPerformed(ActionEvent actionevent)
160             {
161                 viewCategories();
162             }
163 
164         });
165         jmenu2.add(jmenuitem4);
166         jmenu2.add(jmenuitem5);
167         jmenu2.add(jmenuitem6);
168         JMenu jmenu3 = new JMenu("Options");
169         jmenu3.setFont(new Font("Fixedsys", 0, 12));
170         jmenu3.setMnemonic(79);
171         JCheckBoxMenuItem jcheckboxmenuitem = new JCheckBoxMenuItem("Include incomplete <that>s", targetingtool.includeIncompleteThats());
172         jcheckboxmenuitem.setFont(new Font("Fixedsys", 0, 12));
173         jcheckboxmenuitem.setMnemonic(73);
174         jcheckboxmenuitem.setAccelerator(KeyStroke.getKeyStroke(84, 2));
175         jcheckboxmenuitem.addActionListener(new ActionListener() {
176 
177             public void actionPerformed(ActionEvent actionevent)
178             {
179                 includeIncompleteThats(((JCheckBoxMenuItem)actionevent.getSource()).getState());
180             }
181 
182         });
183         JCheckBoxMenuItem jcheckboxmenuitem1 = new JCheckBoxMenuItem("Include incomplete <topic>s", targetingtool.includeIncompleteTopics());
184         jcheckboxmenuitem1.setFont(new Font("Fixedsys", 0, 12));
185         jcheckboxmenuitem1.setMnemonic(78);
186         jcheckboxmenuitem1.setAccelerator(KeyStroke.getKeyStroke(80, 2));
187         jcheckboxmenuitem1.addActionListener(new ActionListener() {
188 
189             public void actionPerformed(ActionEvent actionevent)
190             {
191                 includeIncompleteTopics(((JCheckBoxMenuItem)actionevent.getSource()).getState());
192             }
193 
194         });
195         JMenuItem jmenuitem7 = new JMenuItem("Change reload frequency...");
196         jmenuitem7.setFont(new Font("Fixedsys", 0, 12));
197         jmenuitem7.setMnemonic(82);
198         jmenuitem7.addActionListener(new ActionListener() {
199 
200             public void actionPerformed(ActionEvent actionevent)
201             {
202                 showSetReloadFrequencyBox();
203             }
204 
205         });
206         jmenu3.add(jcheckboxmenuitem);
207         jmenu3.add(jcheckboxmenuitem1);
208         jmenu3.addSeparator();
209         jmenu3.add(jmenuitem7);
210         JMenu jmenu4 = new JMenu("Actions");
211         jmenu4.setFont(new Font("Fixedsys", 0, 12));
212         jmenu4.setMnemonic(65);
213         JMenuItem jmenuitem8 = new JMenuItem("Discard target");
214         jmenuitem8.setFont(new Font("Fixedsys", 0, 12));
215 //        jmenuitem8.addActionListener(new TargetPanel.DiscardTarget(targetPanel));
216         JMenuItem jmenuitem9 = new JMenuItem("Discard all targets");
217         jmenuitem9.setFont(new Font("Fixedsys", 0, 12));
218 //        jmenuitem9.addActionListener(new TargetPanel.DiscardAllTargets(targetPanel));
219         JMenuItem jmenuitem10 = new JMenuItem("Save new category from target");
220         jmenuitem10.setFont(new Font("Fixedsys", 0, 12));
221         jmenuitem10.setMnemonic(83);
222         jmenuitem10.setAccelerator(KeyStroke.getKeyStroke(83, 2));
223 //        jmenuitem10.addActionListener(new TargetPanel.SaveTarget(targetPanel));
224         JMenuItem jmenuitem11 = new JMenuItem("Get next target");
225         jmenuitem11.setFont(new Font("Fixedsys", 0, 12));
226         jmenuitem11.setMnemonic(78);
227         jmenuitem11.setAccelerator(KeyStroke.getKeyStroke(78, 2));
228 //        jmenuitem11.addActionListener(new TargetPanel.NextTarget(targetPanel));
229         jmenu4.add(jmenuitem10);
230         jmenu4.add(jmenuitem11);
231         jmenu4.add(jmenuitem8);
232         jmenu4.add(jmenuitem9);
233         JMenu jmenu5 = new JMenu("Help");
234         jmenu5.setFont(new Font("Fixedsys", 0, 12));
235         jmenu5.setMnemonic(72);
236         JMenuItem jmenuitem12 = new JMenuItem("About...");
237         jmenuitem12.setFont(new Font("Fixedsys", 0, 12));
238         jmenuitem12.setMnemonic(65);
239         jmenuitem12.addActionListener(new ActionListener() {
240 
241             public void actionPerformed(ActionEvent actionevent)
242             {
243                 showAboutBox();
244             }
245 
246         });
247         jmenu5.add(jmenuitem12);
248         menuBar.add(jmenu);
249         menuBar.add(jmenu1);
250         menuBar.add(jmenu2);
251         menuBar.add(jmenu3);
252         menuBar.add(jmenu4);
253         menuBar.add(jmenu5);
254     }
255 
256     public void shutdown()
257     {
258         TargetingTool.shutdown();
259     }
260 
261     public void reloadTargets()
262     {
263         try
264         {
265             targetingTool.reload();
266         }
267         catch(Exception exception)
268         {
269             showError(exception.getMessage());
270         }
271     }
272 
273     private void includeIncompleteThats(boolean flag)
274     {
275         targetingTool.includeIncompleteThats(flag);
276         if(!targetPanel.hasTarget())
277             targetPanel.nextTarget();
278     }
279 
280     private void includeIncompleteTopics(boolean flag)
281     {
282         targetingTool.includeIncompleteTopics(flag);
283         if(!targetPanel.hasTarget())
284             targetPanel.nextTarget();
285     }
286 
287     private void showAboutBox()
288     {
289         JOptionPane.showMessageDialog(null, ((Object) (HELP_MESSAGE)), "About", 1, aliceLogo);
290     }
291 
292     private void showSetReloadFrequencyBox()
293     {
294         int i = targetingTool.getReloadFrequency();
295         Object obj = JOptionPane.showInputDialog(null, "Please input a value in seconds.", "Set Reload Frequency", -1, null, null, new Integer(i));
296         if(obj == null)
297             return;
298         int j;
299         try
300         {
301             j = Integer.parseInt((String)obj);
302         }
303         catch(NumberFormatException numberformatexception)
304         {
305             JOptionPane.showMessageDialog(null, "Invalid entry. Reload frequency unchanged from " + i + ".", "Invalid entry.", 2);
306             return;
307         }
308         targetingTool.restartTimer(j);
309         JOptionPane.showMessageDialog(null, "Reload frequency changed to " + j + ".", "Frequency changed.", -1);
310     }
311 
312     private void loadDataURLBox()
313     {
314         String s = targetingTool.getTargetsDataPath();
315         Object obj = JOptionPane.showInputDialog(null, "Enter the targets data URL from which to load.", "Change data URL", -1, null, null, s);
316         if(obj == null)
317         {
318             return;
319         } else
320         {
321             JOptionPane.showMessageDialog(null, "Targets data URL changed to " + (String)obj + ".", "Data path changed.", -1);
322             setStatus("Loading targets data....");
323             targetingTool.changeTargetsDataPath((String)obj);
324             targetPanel.nextTarget();
325             setStatus("");
326             updateTitle();
327             return;
328         }
329     }
330 
331     private void loadDataFilePathChooser()
332     {
333         String s = targetingTool.getTargetsDataPath();
334         JFileChooser jfilechooser = new JFileChooser(s);
335         jfilechooser.setDialogTitle("Choose Targets Data File");
336         int i = jfilechooser.showDialog(this, "Choose");
337         if(i == 0)
338         {
339             File file = jfilechooser.getSelectedFile();
340             String s1 = null;
341             try
342             {
343                 s1 = file.getCanonicalPath();
344             }
345             catch(IOException ioexception)
346             {
347                 showError("I/O error trying to access \"" + s1 + "\".");
348                 Trace.userinfo("I/O error trying to access \"" + s1 + "\".");
349                 return;
350             }
351             JOptionPane.showMessageDialog(null, "Targets data file path changed to " + s1 + ".", "Data path changed.", -1);
352             setStatus("Loading targets data....");
353             targetingTool.changeTargetsDataPath(s1);
354             targetPanel.nextTarget();
355             setStatus("");
356             updateTitle();
357         }
358     }
359 
360     public void showError(String s)
361     {
362         JOptionPane.showMessageDialog(null, s, "Error", 0);
363     }
364 
365     public void setStatus(String s)
366     {
367         statusBar.setText(s);
368         Trace.devinfo(s);
369     }
370 
371     private void updateTitle()
372     {
373         frame.setTitle("AIML Targeting Tool, Charliebot version " + "4.1.8" + " - " + targetingTool.getTargetsDataPath());
374     }
375 
376     public void viewTargets()
377     {
378         tabbedPane.setSelectedIndex(0);
379     }
380 
381     public void viewInputs()
382     {
383         tabbedPane.setSelectedIndex(1);
384     }
385 
386     public void viewCategories()
387     {
388         tabbedPane.setSelectedIndex(2);
389     }
390 
391     static final int MIN_WIDTH = 600;
392     static final int MIN_HEIGHT = 400;
393     static final int PREF_WIDTH = 700;
394     static final int PREF_HEIGHT = 500;
395     static final Dimension minDimension = new Dimension(600, 400);
396     static final Dimension prefDimension = new Dimension(700, 500);
397     private static TargetingTool targetingTool;
398     private JFrame frame;
399     private JTabbedPane tabbedPane;
400     public TargetPanel targetPanel;
401     public InputPanel inputPanel;
402     public CategoryPanel categoryPanel;
403     private static JMenuBar menuBar;
404     public JLabel statusBar;
405     private static final Object HELP_MESSAGE[] = {
406         "AIML Targeting Tool", "Charliebot version " + "4.1.8", "(c) A.L.I.C.E. AI Foundation (http://alicebot.org)"
407     };
408     private static final ImageIcon aliceLogo = new ImageIcon(ClassLoader.getSystemResource("org/alicebot/icons/aliceLogo.jpg"));
409     private static final ImageIcon aliceIcon = new ImageIcon(ClassLoader.getSystemResource("org/alicebot/icons/aliceIcon.jpg"));
410 
411 
412 
413 
414 
415 
416 
417 }