AddMappingDlg.java
Go to the documentation of this file.
00001 package instruction.gui.dialog;
00002 
00003 import instruction.semanticObjects.Word;
00004 import instruction.wordnet.WordNetRDF2;
00005 
00006 import java.awt.Dimension;
00007 import java.awt.Frame;
00008 import java.awt.event.ActionEvent;
00009 import java.awt.event.ActionListener;
00010 import java.util.ArrayList;
00011 
00012 import javax.swing.DefaultListModel;
00013 import javax.swing.JButton;
00014 import javax.swing.JDialog;
00015 import javax.swing.JLabel;
00016 import javax.swing.JList;
00017 import javax.swing.JPanel;
00018 import javax.swing.JScrollPane;
00019 import javax.swing.JTextField;
00020 import javax.swing.ListSelectionModel;
00021 import javax.swing.ScrollPaneConstants;
00022 import javax.swing.SpringLayout;
00023 
00024 public class AddMappingDlg extends JDialog {
00025 
00029         private static final long serialVersionUID = 1L;
00030         JButton jButton = null;
00031         JPanel jContentPane = null;
00032         JTextField text = null;
00033         JList sensesList = null;
00034         
00035         Word w = null;
00036         private String synset = null;
00037         private String concept = null;
00038         
00039         DefaultListModel listModel = new DefaultListModel();
00040 
00041         public AddMappingDlg(Frame owner, Word w) {
00042                 super(owner);
00043                 this.w = w;
00044                 initialize();
00045         }
00046 
00052         private void initialize() {
00053                 this.setContentPane(getJContentPane());
00054                 this.setTitle("Add Cyc-Mapping for Word Sense");
00055                 setSize(400, 465);
00056         }
00057 
00063         private JPanel getJContentPane() {
00064                 if (jContentPane == null) {
00065                         jContentPane = new JPanel();
00066 
00067                         SpringLayout layout = new SpringLayout();
00068                         jContentPane.setLayout(layout);
00069 
00070                         JLabel label1 = new JLabel();
00071                         label1
00072                                         .setText("<html><p>Choose the appropriate word sense from the WordNet ontology.<br><br>The word under consideration is<br><br><p align=\"center\">"
00073                                                         + w.getLabel() + " (word stem is: " + WordNetRDF2.getWordStem(w.getLabel(), WordNetRDF2.convertPOS(w.getType())) + ")"
00074                                                         + "</p><br>These are possible senses offered by WordNet:</p></html>");
00075 
00076                         jContentPane.add(label1);
00077 
00078                         ArrayList<String> synsets = WordNetRDF2.getSynsets(w.getLabel(),  WordNetRDF2.convertPOS(w.getType()));
00079 
00080                         GlossaryEntry[] entries = new GlossaryEntry[synsets.size()];
00081                         for (int i = 0; i < entries.length; i++) {
00082                                 entries[i] = new GlossaryEntry(synsets.get(i), WordNetRDF2.getGlossaryForSynset(synsets.get(i)));
00083                         }
00084 
00085                         sensesList = new JList(entries);
00086                         sensesList.setVisibleRowCount(4);
00087                         sensesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
00088                         sensesList.setLayoutOrientation(JList.VERTICAL);
00089                 
00090                         JScrollPane scroller = new JScrollPane(sensesList);
00091                         scroller
00092                                         .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
00093                         scroller
00094                                         .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
00095                         scroller.setPreferredSize(new Dimension(-1,120));
00096                         
00097 
00098                         JButton ok = new JButton();
00099                         ok.setText("OK");
00100                         ok.addActionListener(new ActionListener() {
00101 
00102                                 public void actionPerformed(ActionEvent arg0) {
00103                                         AddMappingDlg.this.concept = AddMappingDlg.this.text.getText();
00104                                         AddMappingDlg.this.synset = ((AddMappingDlg.GlossaryEntry)sensesList.getSelectedValue()).getSynset();
00105                                         AddMappingDlg.this.setVisible(false);
00106                                 }
00107 
00108                         });
00109                         JLabel label2 = new JLabel();
00110                         label2
00111                                         .setText("<html><p>Now type the appropriate Cyc Concept the sense "
00112                                                         + "<br>shall be mapped to:</p></html>");
00113 
00114                         JLabel label3 = new JLabel();
00115                         label3
00116                                         .setText("<html><p>The Mapping will be added to the Cyc ontology persistently. "
00117                                                         + "If you press cancel, the whole instruction will be discarded.</p></html>");
00118 
00119                         text = new JTextField();
00120                         text.setText("Thing");
00121 
00122                         JButton cancel = new JButton();
00123                         cancel.setText("Cancel");
00124                         cancel.addActionListener(new ActionListener() {
00125                                 
00126                                 @Override
00127                                 public void actionPerformed(ActionEvent e) {
00128                                         AddMappingDlg.this.setVisible(false);
00129                                         
00130                                 }
00131                         });
00132 
00133                         layout.putConstraint(SpringLayout.NORTH, label1, 10,
00134                                         SpringLayout.NORTH, jContentPane);
00135                         layout.putConstraint(SpringLayout.NORTH, scroller, 10,
00136                                         SpringLayout.SOUTH, label1);
00137                         layout.putConstraint(SpringLayout.EAST, label1, -10,
00138                                         SpringLayout.EAST, jContentPane);
00139                         layout.putConstraint(SpringLayout.WEST, label1, 10,
00140                                         SpringLayout.WEST, jContentPane);
00141 
00142                         layout.putConstraint(SpringLayout.EAST, scroller, -10,
00143                                         SpringLayout.EAST, jContentPane);
00144                         layout.putConstraint(SpringLayout.WEST, scroller, 10,
00145                                         SpringLayout.WEST, jContentPane);
00146 
00147                         layout.putConstraint(SpringLayout.SOUTH, ok, -10,
00148                                         SpringLayout.SOUTH, jContentPane);
00149                         layout.putConstraint(SpringLayout.WEST, ok, 10, SpringLayout.WEST,
00150                                         jContentPane);
00151 
00152                         layout.putConstraint(SpringLayout.NORTH, label2, 10,
00153                                         SpringLayout.SOUTH, scroller);
00154                         layout.putConstraint(SpringLayout.WEST, label2, 10,
00155                                         SpringLayout.WEST, jContentPane);
00156                         layout.putConstraint(SpringLayout.EAST, label1, -10,
00157                                         SpringLayout.EAST, jContentPane);
00158 
00159                         layout.putConstraint(SpringLayout.NORTH, text, 20,
00160                                         SpringLayout.SOUTH, label2);
00161                         layout.putConstraint(SpringLayout.WEST, text, 10,
00162                                         SpringLayout.WEST, jContentPane);
00163                         layout.putConstraint(SpringLayout.EAST, text, -10,
00164                                         SpringLayout.EAST, jContentPane);
00165                         layout.putConstraint(SpringLayout.SOUTH, text, -20,
00166                                         SpringLayout.NORTH, label3);
00167                         layout.putConstraint(SpringLayout.WEST, label3, 10,
00168                                         SpringLayout.NORTH, jContentPane);
00169                         layout.putConstraint(SpringLayout.EAST, label3, 10,
00170                                         SpringLayout.EAST, jContentPane);
00171                         layout.putConstraint(SpringLayout.SOUTH, label3, -10,
00172                                         SpringLayout.NORTH, ok);
00173 
00174                         layout.putConstraint(SpringLayout.SOUTH, cancel, -10,
00175                                         SpringLayout.SOUTH, jContentPane);
00176                         layout.putConstraint(SpringLayout.WEST, cancel, 10,
00177                                         SpringLayout.EAST, ok);
00178 
00179                         jContentPane.add(cancel);
00180                         jContentPane.add(label3);
00181                         jContentPane.add(label2);
00182                         jContentPane.add(scroller);
00183                         jContentPane.add(ok);
00184                         jContentPane.add(text);
00185                         
00186                         
00187                 }
00188 
00189                 return jContentPane;
00190         }
00191 
00192         public String getConcept() {
00193                 return concept;
00194         }
00195         
00196         public String getSynset() {
00197                 return synset;
00198         }
00199         
00200         private class GlossaryEntry {
00201 
00202                 private String entry;
00203                 private String synset;
00204 
00205                 public GlossaryEntry(String synset, String entry) {
00206                         this.entry = entry;
00207                         this.synset = synset;
00208                 }
00209                 
00210                 
00211 
00212                 public String getSynset() {
00213                         return synset;
00214                 }
00215 
00216                 @Override
00217                 public String toString() {
00218                         return entry;
00219                 }
00220 
00221         }
00222 
00223         public static void main(String[] args) {
00224 
00225                 AddMappingDlg dlg = new AddMappingDlg(null, new Word(Word.TYPE_PAST_PARTICIPLE, "had"));
00226                 dlg.setModal(true);
00227                 dlg.setPreferredSize(null);
00228                 dlg.pack();
00229                 dlg.setVisible(true);
00230         }
00231 }
 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