Exemplo n.º 1
0
 void lookup(String s, boolean append) {
   if (s.length() > 25) {
     return;
   }
   history[pos++ % history.length] = s;
   f.toFront();
   // ta.requestFocus();
   String dbID = "*";
   int dbIndex = db.getSelectedIndex();
   if (dbIndex < engine.getDatabases().length) {
     dbID = engine.getDatabases()[dbIndex].getID();
   }
   IAnswer[] a = engine.defineMatch(dbID, s, null, true, IDatabase.STRATEGY_NONE);
   StringWriter w = new StringWriter();
   PrintWriter out = new PrintWriter(w);
   IRequest req = new SimpleRequest("", "word=" + s);
   try {
     org.dict.kernel.answer.printer.PlainPrinter.printAnswers(engine, req, a, false, out);
     out.flush();
   } catch (Exception e) {
     e.printStackTrace(out);
   }
   if (append) {
     ta.append(w.toString());
   } else {
     ta.setText(w.toString());
   }
 }
Exemplo n.º 2
0
 /** ClipboardTest constructor comment. */
 public DictAWTView(String cfg) {
   super();
   IDictEngine e = org.dict.server.DatabaseFactory.getEngine(cfg);
   this.engine = e;
   f = new Frame("Dictionary lookup");
   f.setSize(600, 400);
   f.setLayout(new BorderLayout());
   ta = new TextArea();
   ta.setBackground(Color.white);
   ta.setForeground(Color.black);
   ta.addMouseListener(new ML());
   ta.addFocusListener(new FL());
   Button prev = new Button("History");
   prev.addActionListener(new History());
   mode = new Checkbox("Automatic", false);
   db = new Choice();
   for (int i = 0; i < e.getDatabases().length; i++) {
     db.add(e.getDatabases()[i].getName());
   }
   db.add("Any database");
   fontChoice = new Choice();
   fontChoice.add("serif");
   fontChoice.add("monospaced");
   fontChoice.add("dialog");
   fontChoice.addItemListener(new IL());
   sizeChoice = new Choice();
   sizeChoice.add("10");
   sizeChoice.add("12");
   sizeChoice.add("15");
   sizeChoice.addItemListener(new IL());
   Panel north = new Panel();
   north.setBackground(Color.lightGray);
   north.add(mode);
   north.add(db);
   north.add(fontChoice);
   north.add(sizeChoice);
   north.add(prev);
   f.add(north, "North");
   f.add(ta, "Center");
   f.addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       });
   f.setVisible(true);
 }