Exemple #1
0
 /*
  * abort editing, keep original string
  */
 public void abortTokenEditing() {
   box.getEditor().getEditorComponent().removeFocusListener(fl);
   this.remove(box);
   this.add(tokenTextLabel);
   this.calculateSizeNormMode();
   this.repaint();
   this.revalidate();
   this.grabFocus();
   this.isEditing = false;
 }
Exemple #2
0
 /*
  * correct Token with String in editor Textfield
  */
 public void endTokenEditing(String editString) {
   // TODO check implementation
   //        boolean b = Pattern.matches("([^ ]+ [^ ]+)*", editString);
   //        if (b) {
   if (editString.contains(" ")) {
     MainController.findInstance().splitToken(this.tokenID, editString);
     //
     // MainController.findInstance().addToLog(MainController.findInstance().getLastFocusedTCName()
     // + " # split # " + temptoken.getWOCR() + " # " + retval);
   } else {
     // if (!editString.equals(tokenTextLabel.getText())) {
     MainController.findInstance().correctTokenByString(this.tokenID, editString);
     //
     // MainController.findInstance().addToLog(MainController.findInstance().getLastFocusedTCName()
     // + " # correct # " + temptoken.getWOCR() + " # " + editString);
     //            } else {
     //                abortTokenEditing();
     //            }
   }
   //            if (editString.contains(" ") && !editString.startsWith(" ") &&
   // !editString.endsWith(" ")) {
   ////            if (editString.matches("\\p{Alnum}.*\\W+.*\\p{Alnum}*")) {
   //                int retval = this.token.handleSplit(editString);
   //
   // MainController.findInstance().addToLog(MainController.findInstance().getLastFocusedTCName()+"
   // # split # "+this.token.getWOCR()+" # "+retval);
   //                MessageCenter.getInstance().fireTokenStatusEvent(new
   // TokenStatusEvent(this.token, TokenStatusType.SPLIT, retval));
   //            } else if (editString.contains(" ") && (editString.startsWith(" ") ||
   // editString.endsWith(" "))) {
   //                abortTokenEditing();
   //            } else {
   //                MainController.findInstance().correctTokenByString(token, editorf.getText());
   //
   // MainController.findInstance().addToLog(MainController.findInstance().getLastFocusedTCName()+
   // " # correct # "+token.getWOCR()+" # "+editorf.getText());
   //            }
   //        this.remove(editorf);
   box.getEditor().getEditorComponent().removeFocusListener(fl);
   this.remove(box);
   this.add(tokenTextLabel);
   this.calculateSizeNormMode();
   this.repaint();
   this.revalidate();
   this.grabFocus();
   this.isEditing = false;
 }
Exemple #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));
    }
  }
Exemple #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();
  }