예제 #1
0
 public void setMode(TokenVisualizationMode n, Token t) {
   this.tvm = n;
   this.tokenTextLabel.setForeground(tvm.getUnselectedColor());
   this.addMouseListener(tvm.getMouseListener());
   this.addKeyListener(tvm.getKeyListener());
   tvm.setTokenVisualizationStyle(this, t);
   this.calculateSizeNormMode();
   this.revalidate();
 }
예제 #2
0
 public void activate() {
   if (tvm != null) {
     this.addMouseListener(tvm.getMouseListener());
     this.addKeyListener(keyListener);
     this.setBackground(Color.white);
   }
 }
예제 #3
0
 public void deactivate() {
   if (tvm != null) {
     this.removeMouseListener(tvm.getMouseListener());
     this.removeKeyListener(keyListener);
     this.setBackground(Color.lightGray);
   }
 }
예제 #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();
  }
예제 #5
0
 public void setCorrected(boolean b) {
   tvm.setCorrected(instance, b);
 }
예제 #6
0
 public void update(String newtext) {
   tokenTextLabel.setText(newtext);
   tvm.setTokenVisualizationStyle(instance);
   this.calculateSizeNormMode();
   this.revalidate();
 }
예제 #7
0
 public void setMultiSelected(boolean b) {
   this.isMultiSelected = b;
   if (!this.isSpace()) {
     tvm.setTokenVisualizationStyle(this);
   }
 }
예제 #8
0
 public void setSelected(boolean b) {
   this.isSelected = b;
   this.grabFocus();
   tvm.setTokenVisualizationStyle(this);
 }