public AbstractTokenVisualization getTokenVisualization(Token t) {
   if (tokenRegistry.containsKey(t.getID())) {
     return tokenRegistry.get(t.getID());
   } else {
     return null;
   }
 }
Пример #2
0
  @Override
  public boolean applies(Token t) {
    retVal = false;
    if (this.param.equals(t.getWOCR()) & !t.isCorrected()) {
      retVal = true;
    } else {
      retVal = false;
    }

    return retVal;
  }
Пример #3
0
  public void processEdit(ComboBoxEntry cbe) {
    if (cbe.getType() == ComboBoxEntryType.NORMAL) {
      endTokenEditing(box.getEditor().getItem().toString());
    } else if (cbe.getType() == ComboBoxEntryType.MERGE) {
      abortTokenEditing();
      MainController.findInstance().mergeRightward(tokenID);
      MainController.findInstance()
          .addToLog(
              MainController.findInstance().getLastFocusedTCName()
                  + " # merge # "
                  + " # "
                  + temptoken.getWOCR()
                  + " # "
                  + temptoken.getWOCR());
    } else if (cbe.getType() == ComboBoxEntryType.SETCORRECTED) {
      abortTokenEditing();
      if (!temptoken.isCorrected()) {
        MainController.findInstance().setCorrected(tokenID, true);
      }
      instance.revalidate();
      MainController.findInstance()
          .addToLog(
              MainController.findInstance().getLastFocusedTCName()
                  + " # set as corrected # "
                  + temptoken.getWOCR());

      // if delete, check if prev and next token are spaces, if the case delete one of them to not
      // produce sequent spaces
    } else if (cbe.getType() == ComboBoxEntryType.DELETE) {

      abortTokenEditing();
      MainController.findInstance().deleteToken(tokenID);

    } else if (cbe.getType() == ComboBoxEntryType.FOCUS_IN_MAIN) {
      abortTokenEditing();
      MessageCenter.getInstance()
          .fireTokenNavigationEvent(
              new TokenNavigationEvent(this, tokenID, TokenNavigationType.FOCUS_IN_MAIN));
    }
  }
Пример #4
0
  public void startTokenEditing() {

    this.isEditing = true;

    LinkedHashSet<ComboBoxEntry> cands = new LinkedHashSet<>();

    temptoken = MainController.findInstance().getDocument().getTokenByID(tokenID);

    cands.add(new ComboBoxEntry(this.getTokenTextLabelText(), ComboBoxEntryType.NORMAL));

    Iterator<Candidate> iterator =
        MainController.findInstance().getDocument().candidateIterator(tokenID);
    int maxcands = 5;
    while (iterator.hasNext() && maxcands > 1) {
      maxcands--;
      cands.add(new ComboBoxEntry(iterator.next().getSuggestion(), ComboBoxEntryType.NORMAL));
    }

    cands.add(new ComboBoxEntry(setcorrect, ComboBoxEntryType.SETCORRECTED));
    cands.add(new ComboBoxEntry(delete, ComboBoxEntryType.DELETE));
    cands.add(new ComboBoxEntry(merger, ComboBoxEntryType.MERGE));

    if (tvm.getClass().getSimpleName().equals("TokenVisualizationConcordanceMode")) {
      cands.add(new ComboBoxEntry(focusInMain, ComboBoxEntryType.FOCUS_IN_MAIN));
    }

    JButton submitButton = new JButton("↵");
    submitButton.setFocusable(false);
    submitButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent ae) {
            endTokenEditing(box.getEditor().getItem().toString());
          }
        });

    box =
        new MyEditCustomComboBox(
            cands,
            tokenTextLabel.getFont(),
            new Dimension(
                tokenTextLabel.getPreferredSize().width, tokenTextLabel.getPreferredSize().height),
            temptoken.getNumberOfCandidates(),
            submitButton);
    box.setWide(true);
    ((JPanel) box.getEditor().getEditorComponent()).getComponent(0).addKeyListener(keyListener);
    //        box.getEditor().getEditorComponent().addKeyListener(keyListener);

    fl =
        new FocusListener() {

          @Override
          public void focusGained(FocusEvent e) {
            if (e.getComponent()
                .getParent()
                .getParent()
                .getClass()
                .getName()
                .equals("jav.gui.token.edit.MyEditCustomComboBox")) {
              JComboBox b = (JComboBox) e.getComponent().getParent().getParent();
              if (!b.isPopupVisible()) {
                b.showPopup();
                b.setPopupVisible(true);
                b.getEditor().selectAll();
              }
            }
          }

          @Override
          public void focusLost(FocusEvent e) {
            abortTokenEditing();
          }
        };
    ((JPanel) box.getEditor().getEditorComponent()).getComponent(0).addFocusListener(fl);

    //        box.getEditor().getEditorComponent().addFocusListener(fl);

    //        BoundsPopupMenuListener lis = new BoundsPopupMenuListener( false , true ) {
    //            @Override
    //            public void popupMenuCanceled(PopupMenuEvent e) {
    //                abortTokenEditing();
    //            }
    //        };
    //        box.addPopupMenuListener( lis );

    //        box.addPopupMenuListener(new PopupMenuListener() {
    //
    //            @Override
    //            public void popupMenuWillBecomeVisible(PopupMenuEvent pme) {
    //                JComboBox comboBox = (JComboBox) pme.getSource();
    //		if (comboBox.getItemCount() == 0) return;
    //		Object child = comboBox.getAccessibleContext().getAccessibleChild(0);
    //            }
    //
    //            @Override
    //            public void popupMenuWillBecomeInvisible(PopupMenuEvent pme) {
    //            }
    //
    //            @Override
    //            public void popupMenuCanceled(PopupMenuEvent pme) {
    ////                abortTokenEditing();
    //            }
    //        });
    this.remove(tokenTextLabel);
    this.add(box);
    this.calculateSizeEditMode();
    this.repaint();
    this.revalidate();
    ((JTextField) ((JPanel) box.getEditor().getEditorComponent()).getComponent(0)).grabFocus();
  }
 public void removefromRegistry(Token t) {
   if (tokenRegistry.containsKey(t.getID())) {
     tokenRegistry.remove(t.getID());
   }
 }
 public void addtoRegistry(Token t, AbstractTokenVisualization tv) {
   tokenRegistry.put(t.getID(), tv);
 }