EHowInstructionPanel.java
Go to the documentation of this file.
00001 package instruction.gui;
00002 
00003 import instruction.gui.dialog.InstructionProgressDlg;
00004 import instruction.configuration.ConfigurationManager;
00005 import instruction.gui.internal.DisambiguationOracle;
00006 import instruction.gui.internal.PlanImporterWrapper;
00007 import instruction.gui.tab.BrowserTab;
00008 import instruction.gui.tab.CycViewTab;
00009 import instruction.gui.tab.InternalViewTab;
00010 import instruction.gui.tab.OnlineSearchPanel;
00011 import instruction.gui.tab.RPLViewTab;
00012 import instruction.gui.tab.SearchViewTab;
00013 import instruction.gui.tab.TreeViewTab;
00014 import instruction.opencyc.OpenCyc;
00015 import instruction.wrapper.LocalFileWrapper;
00016 
00017 import java.awt.BorderLayout;
00018 import java.awt.Color;
00019 import java.awt.Dimension;
00020 import java.awt.event.ActionEvent;
00021 import java.awt.event.ActionListener;
00022 import java.io.File;
00023 import java.util.Iterator;
00024 import java.util.List;
00025 import java.util.Map;
00026 import java.util.Set;
00027 
00028 import javax.swing.BorderFactory;
00029 import javax.swing.JButton;
00030 import javax.swing.JComponent;
00031 import javax.swing.JOptionPane;
00032 import javax.swing.JPanel;
00033 import javax.swing.JTabbedPane;
00034 import javax.swing.UIManager;
00035 
00036 
00037 public class EHowInstructionPanel extends JPanel {
00038 
00039         private static final long serialVersionUID = 7862127773357644721L;
00040 
00041         JPanel[] tabs = { new SearchViewTab(), new BrowserTab(), new TreeViewTab(),
00042                         new InternalViewTab(), new CycViewTab(), new RPLViewTab() };
00043 
00044         JPanel me = this;
00045         JComponent bar = null;
00046         JTabbedPane tabComponent = null;
00047 
00048         public void init() {
00049 
00050                 ConfigurationManager.loadSettings();
00051 
00052                 try {
00053                         PlanImporterWrapper.getImporter().initialize();
00054                 } catch (Exception e1) {
00055                         e1.printStackTrace();
00056                 }
00057                 
00058                 tabComponent = new JTabbedPane();
00059                 setLayout(new BorderLayout(0,0));
00060 
00061                 
00062                 for (JPanel tab : tabs) {
00063 
00064                         try {
00065                                 tabComponent.addTab(tab.getClass().getField("TITLE").get(null)
00066                                                 .toString(), null, tab);
00067                         } catch (Exception e) {
00068                                 e.printStackTrace();
00069                         }
00070                 }
00071 
00072                 add(tabComponent, BorderLayout.CENTER);
00073                 
00074                 
00075                 for (int i = 1; i < tabs.length; i++) {
00076                         tabComponent.setEnabledAt(i, false);
00077                 }
00078 
00079                 //tabComponent.setEnabledAt(5, true);
00080 
00081                 // *************************************************************************
00082                 // Initialize the bar at the bottom
00083                 // *************************************************************************
00084                 bar = new JPanel();
00085                 
00086                 JButton next = new JButton("Next >");
00087 
00088                 next.addActionListener(new ActionListener() {
00089 
00090                         public void actionPerformed(ActionEvent arg0) {
00091 
00092                                 int idx = tabComponent.getSelectedIndex();
00093 
00094                                 if (idx == 0) {
00095                                         new Thread() {
00096                                                 public void run() {
00097 
00098                                                 //      PlanImporterWrapper.getImporter().addAddCycMappingListener(addMapping);
00099                                                         try {
00100                                                                 InstructionProgressDlg dlg = new InstructionProgressDlg(
00101                                                                                 null);
00102                                                                 dlg
00103                                                                                 .setLocationRelativeTo(EHowInstructionPanel.this);
00104                                                                 dlg.setModal(false);
00105                                                                 dlg.setVisible(true);
00106 
00107                                                                 PlanImporterWrapper.getImporter()
00108                                                                                 .addProgressListener(dlg);
00109                                                                 PlanImporterWrapper.getImporter().initialize();
00110                                                                 PlanImporterWrapper.getImporter().setAddMappingListener(new AddMappingListener());
00111                                                                 Map<String, List<String>> mappings = ConfigurationManager
00112                                                                                 .getMappings();
00113                                                                 Set<String> synsets = mappings.keySet();
00114                                                                 for (Iterator<String> i = synsets.iterator(); i
00115                                                                                 .hasNext();) {
00116                                                                         String synset = i.next();
00117                                                                         List<String> concepts = mappings
00118                                                                                         .get(synset);
00119                                                                         for (Iterator<String> j = concepts
00120                                                                                         .iterator(); j.hasNext();) {
00121                                                                                 OpenCyc.getInstance().addMapping(
00122                                                                                                 synset, j.next());
00123                                                                         }
00124                                                                 }
00125                                                                 PlanImporterWrapper
00126                                                                                 .getImporter()
00127                                                                                 .getDisambiguator()
00128                                                                                 .load(
00129                                                                                                 ConfigurationManager
00130                                                                                                                 .getPathDisambiguator());
00131                                                                 PlanImporterWrapper
00132                                                                                 .getImporter()
00133                                                                                 .getDisambiguator()
00134                                                                                 .setDisambiguationOracle(
00135                                                                                                 new DisambiguationOracle(
00136                                                                                                                 EHowInstructionPanel.this));
00137                                                                 PlanImporterWrapper
00138                                                                                 .getImporter()
00139                                                                                 .getDisambiguator()
00140                                                                                 .setRunMode(
00141                                                                                                 ConfigurationManager
00142                                                                                                                 .getDisambiguatorMode());
00143                                                                 LocalFileWrapper wrp = new LocalFileWrapper();
00144                                                                 String howto = ((SearchViewTab) tabComponent
00145                                                                                 .getSelectedComponent()).getHowtoPath();
00146                                                                 File dummy = new File(howto);
00147                                                                 if (dummy.exists())
00148                                                                         wrp.load(howto);
00149                                                                 else {
00150                                                                         howto = howto.replaceAll(" ", "_");
00151                                                                         howto = ConfigurationManager
00152                                                                                         .getPathHowtos()
00153                                                                                         + File.separator + howto;
00154                                                                         wrp.load(howto);
00155                                                                 }
00156 
00157                                                                 PlanImporterWrapper.getImporter().setWrapper(
00158                                                                                 wrp);
00159 
00160                                                                 dlg.setVisible(false);
00161                                                                 PlanImporterWrapper.getImporter()
00162                                                                                 .removeProgressListener(dlg);
00163                                                                 tabComponent.setSelectedIndex((tabComponent
00164                                                                                 .getSelectedIndex() + 1)
00165                                                                                 % tabs.length);
00166                                                                 tabComponent.setEnabledAt(1, true);
00167                                                         } catch (Exception e) {
00168                                                                 JOptionPane.showMessageDialog(
00169                                                                                 EHowInstructionPanel.this, e
00170                                                                                                 .getMessage(), "Error",
00171                                                                                 JOptionPane.ERROR_MESSAGE);
00172                                                                 e.printStackTrace();
00173                                                         }
00174                                                 }
00175                                         }.start();
00176                                 }
00177 
00178                                 else if (idx == 1) {
00179                                         new Thread() {
00180                                                 public void run() {
00181 
00182                                                         try {
00183                                                                 InstructionProgressDlg dlg = new InstructionProgressDlg(
00184                                                                                 null);
00185                                                                 dlg
00186                                                                                 .setLocationRelativeTo(EHowInstructionPanel.this);
00187                                                                 dlg.setModal(false);
00188                                                                 dlg.setVisible(true);
00189                                                                 PlanImporterWrapper.getImporter()
00190                                                                                 .addProgressListener(dlg);
00191 
00192                                                                 PlanImporterWrapper.getImporter()
00193                                                                                 .parseInstructions();
00194 
00195                                                                 dlg.setVisible(false);
00196                                                                 PlanImporterWrapper.getImporter()
00197                                                                                 .removeProgressListener(dlg);
00198                                                                 tabComponent.setSelectedIndex((tabComponent
00199                                                                                 .getSelectedIndex() + 1)
00200                                                                                 % tabs.length);
00201                                                                 tabComponent.setEnabledAt(2, true);
00202                                                         } catch (Exception e) {
00203                                                                 JOptionPane.showMessageDialog(
00204                                                                                 EHowInstructionPanel.this, e
00205                                                                                                 .getMessage(), "Error",
00206                                                                                 JOptionPane.ERROR_MESSAGE);
00207                                                                 e.printStackTrace();
00208                                                         }
00209                                                 }
00210                                         }.start();
00211                                 }
00212 
00213                                 else if (idx == 2) {
00214                                         new Thread() {
00215                                                 public void run() {
00216 
00217                                                         try {
00218                                                                 InstructionProgressDlg dlg = new InstructionProgressDlg(
00219                                                                                 null);
00220                                                                 dlg
00221                                                                                 .setLocationRelativeTo(EHowInstructionPanel.this);
00222                                                                 dlg.setModal(false);
00223                                                                 dlg.setVisible(true);
00224                                                                 PlanImporterWrapper.getImporter()
00225                                                                                 .addProgressListener(dlg);
00226 
00227                                                                 PlanImporterWrapper.getImporter()
00228                                                                                 .recognizeAndDisambiguateInstructions();
00229 
00230                                                                 dlg.setVisible(false);
00231                                                                 PlanImporterWrapper.getImporter()
00232                                                                                 .removeProgressListener(dlg);
00233                                                                 tabComponent.setSelectedIndex((tabComponent
00234                                                                                 .getSelectedIndex() + 1)
00235                                                                                 % tabs.length);
00236                                                                 tabComponent.setEnabledAt(3, true);
00237                                                         } catch (Exception e) {
00238                                                                 JOptionPane.showMessageDialog(
00239                                                                                 EHowInstructionPanel.this, e
00240                                                                                                 .getMessage(), "Error",
00241                                                                                 JOptionPane.ERROR_MESSAGE);
00242                                                                 e.printStackTrace();
00243                                                         }
00244                                                 }
00245                                         }.start();
00246                                 }
00247 
00248                                 else if (idx == 3) {
00249                                         new Thread() {
00250                                                 public void run() {
00251 
00252                                                         try {
00253                                                                 InstructionProgressDlg dlg = new InstructionProgressDlg(
00254                                                                                 null);
00255                                                                 dlg
00256                                                                                 .setLocationRelativeTo(EHowInstructionPanel.this);
00257                                                                 dlg.setModal(false);
00258                                                                 dlg.setVisible(true);
00259                                                                 PlanImporterWrapper.getImporter()
00260                                                                                 .addProgressListener(dlg);
00261 
00262                                                                 PlanImporterWrapper.getImporter()
00263                                                                                 .convert2CycAssertions();
00264 
00265                                                                 PlanImporterWrapper.getImporter()
00266                                                                                 .removeProgressListener(dlg);
00267                                                                 dlg.setVisible(false);
00268                                                                 tabComponent.setSelectedIndex((tabComponent
00269                                                                                 .getSelectedIndex() + 1)
00270                                                                                 % tabs.length);
00271                                                                 tabComponent.setEnabledAt(4, true);
00272                                                         } catch (Exception e) {
00273                                                                 JOptionPane.showMessageDialog(
00274                                                                                 EHowInstructionPanel.this, e
00275                                                                                                 .getMessage(), "Error",
00276                                                                                 JOptionPane.ERROR_MESSAGE);
00277                                                                 e.printStackTrace();
00278                                                         }
00279                                                 }
00280                                         }.start();
00281                                 }
00282 
00283                                 else if (idx == 4) {
00284                                         new Thread() {
00285                                                 public void run() {
00286 
00287                                                         try {
00288                                                                 InstructionProgressDlg dlg = new InstructionProgressDlg(
00289                                                                                 null);
00290                                                                 dlg
00291                                                                                 .setLocationRelativeTo(EHowInstructionPanel.this);
00292                                                                 dlg.setModal(false);
00293                                                                 dlg.setVisible(true);
00294                                                                 PlanImporterWrapper.getImporter()
00295                                                                                 .addProgressListener(dlg);
00296 
00297                                                                 PlanImporterWrapper.getImporter()
00298                                                                                 .generateRPLPlan();
00299 
00300                                                                 PlanImporterWrapper.getImporter()
00301                                                                                 .removeProgressListener(dlg);
00302                                                                 dlg.setVisible(false);
00303                                                                 tabComponent.setSelectedIndex((tabComponent
00304                                                                                 .getSelectedIndex() + 1)
00305                                                                                 % tabs.length);
00306                                                                 tabComponent.setEnabledAt(5, true);
00307                                                         } catch (Exception e) {
00308                                                                 JOptionPane.showMessageDialog(
00309                                                                                 EHowInstructionPanel.this, e
00310                                                                                                 .getMessage(), "Error",
00311                                                                                 JOptionPane.ERROR_MESSAGE);
00312                                                                 e.printStackTrace();
00313                                                         }
00314                                                 }
00315                                         }.start();
00316                                 }
00317                         }
00318 
00319                 });
00320 
00321                 bar.add(next);
00322                 add(bar, BorderLayout.SOUTH);
00323                 setMinimumSize(new Dimension(1100, 800));
00324 
00325         }
00326 
00327 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


comp_ehow
Author(s): Moritz Tenorth, Daniel Nyga
autogenerated on Tue Apr 16 2013 00:18:02