Ejemplo n.º 1
0
  /** Called when something is selected or typed. Goal is to check that everything is valid. */
  private boolean checkValid() {
    if (!this.isShowing()) return true; // prevent to check while init
    if (!compatibleDimensions()) {
      jButtonOK.setEnabled(false);
      for (JComboBox box : image_boxes) {
        box.setForeground(Color.RED);
      }
      jTextAreaInfo.setText(MESSAGES[2]);
      jTextAreaInfo.setCaretPosition(0);
      return false;

    } else {

      String error = getExpressionError();
      if (error.length() != 0) {
        jButtonOK.setEnabled(false);
        expressionField.getEditor().getEditorComponent().setForeground(Color.RED);
        jTextAreaInfo.setText(error);
        jTextAreaInfo.setCaretPosition(0);
        return false;

      } else {

        jButtonOK.setEnabled(true);
        for (JComboBox box : image_boxes) {
          box.setForeground(Color.BLACK);
        }
        expressionField.getEditor().getEditorComponent().setForeground(Color.BLACK);
        jTextAreaInfo.setText(MESSAGES[0]);
        jTextAreaInfo.setCaretPosition(0);
        return true;
      }
    }
  }
  private void initOtherComponents() {
    Calendar now = Calendar.getInstance();
    toDatejSpinner.setValue(now.getTime());
    now.add(Calendar.MONTH, -6);
    fromDatejSpinner.setValue(now.getTime());

    exchangeJComboBox.setModel(
        new DefaultComboBoxModel(mainJFrame.mappingExchangeID_Assets.keySet().toArray()));
    exchangeComboKeyHandler = new ComboKeyHandler(exchangeJComboBox);
    JTextField fieldExchange = (JTextField) exchangeJComboBox.getEditor().getEditorComponent();
    fieldExchange.addKeyListener(exchangeComboKeyHandler);

    assetJComboBox.setModel(
        new DefaultComboBoxModel(
            mainJFrame.mappingExchangeID_Assets.get(
                (ExchangeEntity) exchangeJComboBox.getSelectedItem())));
    assetComboKeyHandler = new ComboKeyHandler(assetJComboBox);
    JTextField fieldSymbol = (JTextField) assetJComboBox.getEditor().getEditorComponent();
    fieldSymbol.addKeyListener(assetComboKeyHandler);

    asset = (AssetEntity) assetJComboBox.getSelectedItem();
    toDate = (Date) toDatejSpinner.getValue();
    fromDate = (Date) fromDatejSpinner.getValue();

    newAddDecAlgJDialog();
    newAddCriteriaJDialog();
    newImportPortfolioJDialog();
  }
Ejemplo n.º 3
0
    private void handleEditor(PropertyChangeEvent evt) {
      if (evt.getNewValue() instanceof AutoCompleteComboBoxEditor) {
        return;
      }

      AutoCompleteComboBoxEditor acEditor = (AutoCompleteComboBoxEditor) evt.getOldValue();
      boolean strictMatching = false;

      if (acEditor.getEditorComponent() != null) {
        JTextComponent textComponent = (JTextComponent) acEditor.getEditorComponent();
        strictMatching = ((AutoCompleteDocument) textComponent.getDocument()).strictMatching;

        undecorate(textComponent);

        for (KeyListener l : textComponent.getKeyListeners()) {
          if (l instanceof KeyAdapter) {
            textComponent.removeKeyListener(l);
            break;
          }
        }
      }

      JTextComponent editorComponent = (JTextComponent) comboBox.getEditor().getEditorComponent();
      AbstractAutoCompleteAdaptor adaptor = new ComboBoxAdaptor(comboBox);
      AutoCompleteDocument document =
          createAutoCompleteDocument(
              adaptor, strictMatching, acEditor.stringConverter, editorComponent.getDocument());
      decorate(editorComponent, document, adaptor);

      editorComponent.addKeyListener(new AutoComplete.KeyAdapter(comboBox));

      // set before adding the listener for the editor
      comboBox.setEditor(
          new AutoCompleteComboBoxEditor(comboBox.getEditor(), document.stringConverter));
    }
Ejemplo n.º 4
0
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();

    if (src == add) {
      // Selection has been made, or add button pressed:
      if ((sel != null) && (sel.getSelectedItem() != null)) {
        String s = sel.getSelectedItem().toString();
        addField(s);
      } else if ((input != null) && !input.getText().equals("")) {
        addField(input.getText());
      }
    } else if (src == input) {
      addField(input.getText());
    } else if (src == remove) {
      // Remove button pressed:
      removeSelected();
    } else if (src == sel) {
      if (e.getActionCommand().equals("comboBoxChanged") && (e.getModifiers() == 0))
        // These conditions signify arrow key navigation in the dropdown list, so we should
        // not react to it. I'm not sure if this is well defined enough to be guaranteed to work
        // everywhere.
        return;
      String s = sel.getSelectedItem().toString();
      addField(s);
      sel.getEditor().selectAll();
    } else if (src == up) {
      move(-1);
    } else if (src == down) {
      move(1);
    }
  }
 @Override
 public Component getTableCellEditorComponent(
     JTable table, Object value, boolean isSelected, int row, int column) {
   input.setSelectedItem(value);
   WbSwingUtilities.requestFocus((JComponent) input.getEditor().getEditorComponent());
   return input;
 }
Ejemplo n.º 6
0
    @Override
    public void keyPressed(KeyEvent evt) {
      if (evt.isConsumed()) return;
      Component comp = getFocusOwner();
      if (evt.getKeyCode() == KeyEvent.VK_ENTER && enterEnabled) {
        while (comp != null) {
          if (comp instanceof JComboBox) {
            JComboBox<?> combo = (JComboBox<?>) comp;
            if (combo.isEditable()) {
              Object selected = combo.getEditor().getItem();
              if (selected != null) combo.setSelectedItem(selected);
            }

            if (combo.isPopupVisible()) {
              evt.consume();
              combo.setPopupVisible(false);
            }
            return;
          }
          // TODO: add other classes that need custom key handling here.
          comp = comp.getParent();
        }
        evt.consume();
        ok();
      } else if (evt.getKeyCode() == KeyEvent.VK_ESCAPE || isCloseBufferShortcut(evt)) {
        evt.consume();
        if (comp instanceof JComboBox) {
          JComboBox<?> combo = (JComboBox<?>) comp;
          if (combo.isPopupVisible()) combo.setPopupVisible(false);
          else cancel();
        } else cancel();
      }
    }
Ejemplo n.º 7
0
  /**
   * Enables auto-completion for specified combobox
   *
   * @param comboBox Combo to be featured
   * @param strict Whether strict matching (check 'startWith' or 'contains') should be used
   * @param allowsUserValues Whether non-present items are allowed
   */
  public static void enable(JComboBox comboBox, boolean strict, boolean allowsUserValues) {
    comboBox.setEditable(true);
    KeyListener[] listeners =
        comboBox.getEditor().getEditorComponent().getListeners(KeyListener.class);
    comboBox.setEditor(new CustomTypeComboBoxEditor(comboBox, allowsUserValues));
    for (KeyListener listener : listeners) {
      comboBox.getEditor().getEditorComponent().addKeyListener(listener);
    }

    AutoCompletion ac = new AutoCompletion(comboBox, strict, allowsUserValues);
    comboBox.addFocusListener(ac);
    ac.textEditor.addKeyListener(ac);

    // original keys would not work properly
    SwingUtilities.replaceUIActionMap(comboBox, null);
  }
 /**
  * Fügt einer {@link JComboBox} an allen nötigen Stellen einen {@link EditorChangeListener} hinzu.
  *
  * @param comboBox
  * @param editorChangeListener
  */
 private void addChangeListenerToComboBox(
     JComboBox comboBox, final EditorChangeListener editorChangeListener) {
   BasicComboBoxEditor editor = (BasicComboBoxEditor) comboBox.getEditor();
   JTextField textField = (JTextField) editor.getEditorComponent();
   textField.getDocument().addDocumentListener(editorChangeListener);
   comboBox.addItemListener(editorChangeListener);
 }
  private void resetFromFile(@NotNull VirtualFile file, @NotNull Project project) {
    final Module moduleForFile = ModuleUtilCore.findModuleForFile(file, project);
    if (moduleForFile == null) {
      return;
    }

    final VirtualFile parent = file.getParent();
    if (parent == null) {
      return;
    }

    if (myModule == null) {
      final Object prev = myModuleCombo.getSelectedItem();
      myModuleCombo.setSelectedItem(moduleForFile);

      if (!moduleForFile.equals(myModuleCombo.getSelectedItem())) {
        myModuleCombo.setSelectedItem(prev);
        return;
      }
    } else if (!myModule.equals(moduleForFile)) {
      return;
    }

    final JCheckBox checkBox = myCheckBoxes.get(parent.getName());
    if (checkBox == null) {
      return;
    }

    for (JCheckBox checkBox1 : myCheckBoxes.values()) {
      checkBox1.setSelected(false);
    }
    checkBox.setSelected(true);
    myFileNameCombo.getEditor().setItem(file.getName());
  }
Ejemplo n.º 10
0
 private static int getComboBoxBaselineResizeBehavior(JComboBox cb) {
   if (cb.isEditable()) {
     return getBaselineResizeBehavior(cb.getEditor().getEditorComponent());
   }
   ListCellRenderer renderer = cb.getRenderer();
   if (renderer == null) {
     if (brbListCellRenderer == null) {
       brbListCellRenderer = new DefaultListCellRenderer();
     }
     renderer = brbListCellRenderer;
   }
   Object value = null;
   Object prototypeValue = cb.getPrototypeDisplayValue();
   if (prototypeValue != null) {
     value = prototypeValue;
   } else if (cb.getModel().getSize() > 0) {
     value = cb.getModel().getElementAt(0);
   }
   if (value != null) {
     if (brbList == null) {
       brbList = new JList();
     }
     Component component = renderer.getListCellRendererComponent(brbList, value, -1, false, false);
     return getBaselineResizeBehavior(component);
   }
   return BRB_OTHER;
 }
Ejemplo n.º 11
0
  public void refreshSupplier(boolean remove) {

    if (remove) panel.remove(supplierCombo);

    try {
      model =
          new DefaultComboBoxModel(
              Manager.getInstance().getSupplierManager().getSuppliers().toArray());
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    supplierCombo = new JComboBox(model);
    supplierCombo.setUI(ColorArrowUI.createUI(this));
    supplierCombo.setEditable(true);
    supplierComboField = (JTextField) supplierCombo.getEditor().getEditorComponent();
    supplierComboField.setText("");
    supplierComboField.setOpaque(false);
    supplierComboField.setBorder(BorderFactory.createEmptyBorder());
    supplierComboField.addKeyListener(new ComboKeyHandler(supplierCombo));

    supplierCombo.setFont(new Font("Arial Narrow", Font.PLAIN, 14));
    supplierCombo.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
    supplierCombo.setOpaque(false);

    supplierCombo.setSelectedIndex(-1);

    supplierCombo.setVisible(supplierLabel.isVisible());

    supplierCombo.setBounds(85, 56, 220, 20);

    panel.add(supplierCombo);
  }
Ejemplo n.º 12
0
 public PercentEditor(JComboBox comboBox) {
   super(NumberFormat.getPercentInstance());
   addPropertyChangeListener("value", this);
   // We steal the border from the LAF's editor
   // Note: this doesn't work for Nimbus
   JComponent oldEditor = (JComponent) comboBox.getEditor().getEditorComponent();
   setBorder(oldEditor.getBorder());
 }
 public String getText() {
   Object o = input.getSelectedItem();
   if (o == null) {
     o = input.getEditor().getItem();
   }
   if (o instanceof String) {
     return (String) o;
   }
   return null;
 }
Ejemplo n.º 14
0
  /**
   * Folgendes Szenario. Der User gibt einen Wert in eine {@link JComboBox} ein, und bevor er auf
   * eine andere {@link Component} klickt, klickt er in der Toolbar auf "Speichern".<br>
   * Der eingegebene Wert ist in diesem Moment noch nicht als <em>selectedItem</em> in der {@link
   * JComboBox} festgelegt worden.<br>
   * Aus diesem Grund prŸft diese Methode, ob momentan eine {@link JComboBox} den Fokus hat, und
   * speichert ggf. den eingegebenen Wert dieser als <em>selectedItem</em><br>
   * <br>
   * WŸrde dies nicht gemacht, ginge der eingegebene Wert aus dem Szenario oben verloren.
   *
   * @see #editTags(ArrayList)
   */
  private void saveValueFromEditedComboBox() {
    Component currentFocusOwner =
        KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    Component combo = SwingUtilities.getAncestorOfClass(JComboBox.class, currentFocusOwner);

    if (combo != null && combo instanceof JComboBox) {
      JComboBox comboBox = (JComboBox) combo;
      comboBox.setSelectedItem(comboBox.getEditor().getItem());
    }
  }
 public String getPropertyType() {
   javax.swing.text.Document doc =
       ((JTextComponent) jComboBoxPropertyType.getEditor().getEditorComponent()).getDocument();
   try {
     String propType = doc.getText(0, doc.getLength());
     return propType == null ? null : (isArray() ? propType + "[]" : propType); // NOi18N
   } catch (javax.swing.text.BadLocationException ex) {
     return null;
   }
 }
      private void prepareTextComboBox(final Object propertyValue) {
        // _textComboBox wird in der letzten Zeile editierbar gemacht, und es wird
        // der übergebene Wert in diese Zeile eingetragen und selektiert, wenn er nicht
        // einem der anderen Einträge entspricht.

        if (propertyValue != null) {
          String propertyValueAsString = (String) propertyValue;
          final int size = _textComboBox.getModel().getSize();
          boolean propertyValueFound = false;
          for (int i = 0; i < size - 1; i++) {
            if (propertyValueAsString.equals((String) _textComboBox.getItemAt(i))) {
              propertyValueFound = true;
              _textComboBox.setSelectedIndex(i);
              break;
            }
          }
          if (!propertyValueFound) {
            _textComboBox.removeItemAt(size - 1);
            _textComboBox.addItem(propertyValueAsString);
            _textComboBox.setSelectedIndex(size - 1);
          }
        }

        ItemListener textComboBoxItemListener =
            new ItemListener() {
              public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                  if (_textComboBox.getSelectedIndex()
                      == DOTPointPainter.DYNAMIC_TEXT_ITEMS.length - 1) {
                    _textComboBox.setEditable(true);
                  } else {
                    _textComboBox.setEditable(false);
                  }
                }
              }
            };
        _textComboBox.addItemListener(textComboBoxItemListener);

        ActionListener editorActionListener =
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                final int length = DOTPointPainter.DYNAMIC_TEXT_ITEMS.length;
                final int index = length - 1;
                final ComboBoxEditor editor = _textComboBox.getEditor();
                String editedItem = (String) editor.getItem();
                _textComboBox.insertItemAt(editedItem, index);
                final DefaultComboBoxModel model = (DefaultComboBoxModel) _textComboBox.getModel();
                if (model.getSize()
                    > length) { // Sieht komisch aus, aber der direkte Weg ging nicht.
                  model.removeElementAt(length);
                }
              }
            };
        _textComboBox.getEditor().addActionListener(editorActionListener);
      }
Ejemplo n.º 17
0
  protected AutoCompletion(final JComboBox comboBox, boolean strict, boolean allowsUserValues) {
    this.comboBox = comboBox;
    textEditor = ((JTextComponent) comboBox.getEditor().getEditorComponent());

    this.allowsUserValues = allowsUserValues;

    suggestionList = new SuggestionList(comboBox, strict);

    /** Marking combobox as auto-completing */
    comboBox.putClientProperty(AUTOCOMPLETION_PROPERTY, Boolean.TRUE);
  }
 private JTextField getComboText() {
   JComponent component = myEditor.getChildComponent();
   if (component instanceof JTextField) {
     return (JTextField) component;
   }
   if (component instanceof JComboBox) {
     JComboBox combo = (JComboBox) component;
     return (JTextField) combo.getEditor().getEditorComponent();
   }
   return null;
 }
Ejemplo n.º 19
0
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == okButton) {
      result = (String) comboBox.getEditor().getItem();
      setVisible(false);
      dispose();
    } else if (e.getSource() == cancelButton) {
      setVisible(false);
      dispose();
    }
  }
Ejemplo n.º 20
0
    private void handleEnabled(PropertyChangeEvent evt) {
      if (Boolean.TRUE.equals(evt.getNewValue())) {
        comboBox.setEditable(true);
      } else {
        JTextComponent textComponent = (JTextComponent) comboBox.getEditor().getEditorComponent();
        boolean strictMatching =
            ((AutoCompleteDocument) textComponent.getDocument()).strictMatching;

        comboBox.setEditable(!strictMatching);
      }
    }
Ejemplo n.º 21
0
 /**
  * Constructor for the LiveSearchBox. First create a pointer to the controller. Then create a
  * JComboBox, set the preferred size, set the setEditable to true, and set the background. The
  * component is retrieved from adress and sets a size. Finally a listener is added to component.
  */
 public LiveSearchBox() {
   controller = Controller.getInstance();
   adress = new JComboBox();
   Dimension d = adress.getPreferredSize();
   adress.setPreferredSize(new Dimension(170, (int) d.getHeight()));
   adress.setEditable(true);
   adress.setBackground(Color.lightGray);
   component = (JTextField) adress.getEditor().getEditorComponent();
   component.setSize(50, 10);
   doc = component.getDocument();
   listener = createListener();
   doc.addDocumentListener(listener);
 }
Ejemplo n.º 22
0
 private static void setupSelectionOnPreferredComponent(final JComponent component) {
   if (component instanceof JTextField) {
     JTextField field = (JTextField) component;
     String text = field.getText();
     if (text != null && field.getClientProperty(HAVE_INITIAL_SELECTION) == null) {
       field.setSelectionStart(0);
       field.setSelectionEnd(text.length());
     }
   } else if (component instanceof JComboBox) {
     JComboBox combobox = (JComboBox) component;
     combobox.getEditor().selectAll();
   }
 }
Ejemplo n.º 23
0
    protected CompileCppDialog(
        Project _project, CompileHandler compilerHandler, CompileCppOptions options) {
      super(_project, false);

      project = _project;
      setModal(true);

      doRun.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              final boolean b = doRun.isSelected();
              executableFileName.setEnabled(b);
              executableFileName.setEditable(b);
            }
          });

      executableFileName.getEditor().setItem(options != null ? options.getOutputFileName() : "");
      doRun.setSelected(lastRunStatus);

      final CppSupportLoader loader = CppSupportLoader.getInstance(project);
      final String compileParameters = loader.getAdditionalCompileParameters();

      compileProperties.setText(
          (compileParameters != null && compileParameters.length() > 0
                  ? compileParameters + " "
                  : "")
              + CompileHandler.MARKER);

      setTitle(CppBundle.message("compile.cpp.file.dialog.title"));

      compilerSelector.setModel(
          new DefaultComboBoxModel(CppSupportSettings.CompilerSelectOptions.values()));
      compilerSelector.setSelectedItem(getCurrentCompilerOption(project));

      setSelectedProjectCompile();

      includeProjectCompileParametersCheckBox.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              setSelectedProjectCompile();
            }
          });

      includeProjectCompileParametersCheckBox.setSelected(loader.isIncludeProjectSettings());
      final String compileParametersText = compilerHandler.buildProjectCompileOptions(project);
      projectCompileParameters.setText(compileParametersText != null ? compileParametersText : "");

      init();
    }
Ejemplo n.º 24
0
    /** {@inheritDoc} */
    @Override
    public void actionPerformed(ActionEvent e) {
      JComboBox comboBox = (JComboBox) e.getSource();
      JTextComponent textComponent = (JTextComponent) comboBox.getEditor().getEditorComponent();
      AutoCompleteDocument doc = (AutoCompleteDocument) textComponent.getDocument();

      // doing this prevents the updating of the selected item to "" during the remove prior
      // to the insert in JTextComponent.setText
      doc.strictMatching = true;
      try {
        delegate.actionPerformed(e);
      } finally {
        doc.strictMatching = false;
      }
    }
Ejemplo n.º 25
0
  public void show() {
    if (dialog == null) {
      buildDialog();
    }

    target.getEditComponent().requestFocusInWindow();

    replaceCombo.setEnabled(target.isEditable());
    replaceAllButton.setEnabled(target.isEditable());
    replaceButton.setEnabled(target.isEditable());

    UISupport.showDialog(dialog);
    findCombo.getEditor().selectAll();
    findCombo.requestFocus();
  }
Ejemplo n.º 26
0
  private JComboBox getCmbPkgFilter() {
    if (cmbPkgFilter == null) {
      cmbPkgFilterModel = new DefaultComboBoxModel();
      cmbPkgFilter = new JComboBox();
      cmbPkgFilter.setModel(cmbPkgFilterModel);
      cmbPkgFilter.setBounds(118, 6, 140, 21);
      cmbPkgFilter.setEditable(true);
      ((JTextField) (cmbPkgFilter.getEditor().getEditorComponent()))
          .addActionListener(
              new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                  String regex =
                      ((JTextField) (cmbPkgFilter.getEditor().getEditorComponent()))
                          .getText()
                          .toString()
                          .trim();
                  TXLogger.logger.debug("Filter regex:" + cmbPkgFilterModel.getSize());
                  // System.out.println("Filter regex:"
                  // + cmbPkgFilterModel.getSize());
                  pkgTblModel.reload_rs_packages(cmbOrderBy.getSelectedItem().toString(), regex);
                  if (cmbPkgFilterModel.getSize() == 0) {
                    cmbPkgFilterModel.addElement(regex);
                  }
                  if (!regex.equals("")) {
                    boolean hasKey = false;
                    for (int i = 0; i < cmbPkgFilterModel.getSize(); i++) {
                      if ((cmbPkgFilterModel.getElementAt(i).toString().equals(regex))) {
                        hasKey = true;
                        i = cmbPkgFilterModel.getSize();
                      }
                    }
                    if (!hasKey) {
                      cmbPkgFilterModel.insertElementAt(regex, 0);
                    }
                    cmbPkgFilter.setSelectedIndex(0);
                    //								btnNew.setEnabled(false);
                    //								copyItem.setEnabled(false);

                  } else {
                    //								btnNew.setEnabled(true);
                    //								copyItem.setEnabled(true);
                  }
                }
              });
    }
    return cmbPkgFilter;
  }
 private static int getIntValue(JComboBox combo, int defaultValue) {
   String temp = (String) combo.getEditor().getItem();
   int value = -1;
   if (temp != null && temp.trim().length() > 0) {
     try {
       value = Integer.parseInt(temp);
     } catch (NumberFormatException ignore) {
     }
     if (value <= 0) {
       value = defaultValue;
     }
   } else {
     value = defaultValue;
   }
   return value;
 }
Ejemplo n.º 28
0
  public AutoComboBox(final JComboBox<String> comboBox) {
    this.comboBox = comboBox;
    model = comboBox.getModel();
    editor = (JTextComponent) comboBox.getEditor().getEditorComponent();
    editor.setDocument(this);
    comboBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (!selecting) highlightCompletedText(0);
          }
        });
    editor.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (comboBox.isDisplayable()) comboBox.setPopupVisible(true);
            hitBackspace = false;
            switch (e.getKeyCode()) {
                // determine if the pressed key is backspace (needed by the
                // remove method)
              case KeyEvent.VK_BACK_SPACE:
                // hitBackspace = true;
                // hitBackspaceOnSelection = editor.getSelectionStart() !=
                // editor.getSelectionEnd();
                break;
            }
          }
        });
    // Bug 5100422 on Java 1.5: Editable JComboBox won't hide popup when
    // tabbing out
    hidePopupOnFocusLoss = System.getProperty("java.version").startsWith("1.5");
    // Highlight whole text when gaining focus
    editor.addFocusListener(
        new FocusAdapter() {
          public void focusGained(FocusEvent e) {
            highlightCompletedText(0);
          }

          public void focusLost(FocusEvent e) {
            // Workaround for Bug 5100422 - Hide Popup on focus loss
            if (true) comboBox.setPopupVisible(false);
          }
        });
    // Handle initially selected object
    Object selected = comboBox.getSelectedItem();
    if (selected != null) setText(selected.toString());
    highlightCompletedText(0);
  }
  public EditMavenPropertyDialog(
      @Nullable Pair<String, String> value, Map<String, String> availableProperties) {
    super(false);
    setTitle(value == null ? "Add Maven Property" : "Edit Maven Property");

    myAvailableProperties = availableProperties;

    installFocusListeners();
    installPropertySelectionListener();
    fillAvailableProperties();

    if (value != null) {
      myNameBox.getEditor().setItem(value.getFirst());
      myValueField.setText(value.getSecond());
    }

    init();
  }
Ejemplo n.º 30
0
  public void itemStateChanged(ItemEvent ie) {
    if (ie.getStateChange() == ItemEvent.SELECTED) {
      int idx = pages.getSelectedIndex();
      previous_page.setEnabled(idx != 0);
      next_page.setEnabled(idx < pages.getModel().getSize() - 1);

      if (ie.getSource() == pages) {
        showPage(idx);
      } else {
        // the comboBox editor also triggers an unnecessary ItemEvent(.SELECTED)
        if (zoom.getSelectedItem() instanceof String) return;
        ObjectWrapper tw = (ObjectWrapper) zoom.getSelectedItem();
        Float z = (Float) tw.getType();
        fpp.zoom(z.floatValue());

        if (getParent() != null) {
          invalidate();
          getParent().validate();
        }
      }
    }
    if (ie.getStateChange() == ItemEvent.DESELECTED) {
      int idx = pages.getSelectedIndex();
      previous_page.setEnabled(idx != 0);
      next_page.setEnabled(idx < pages.getModel().getSize() - 1);

      String zoomString = "";
      try {
        zoomString = (String) zoom.getEditor().getItem();
      } catch (ClassCastException e) {
        return;
      }
      if (zoomString.indexOf("%") == zoomString.length() - 1)
        zoomString = zoomString.substring(0, zoomString.length() - 1);
      float z = getValidZoom(zoomString);
      fpp.zoom(z);
      updateEditor(z);

      if (getParent() != null) {
        invalidate();
        getParent().validate();
      }
    }
  }