private JPanel createContentPane() {
    JPanel panel = new JPanel();

    combo1 = new JComboBox<>(numData);
    panel.add(combo1);
    combo2 = new JComboBox<>(dayData);
    combo2.setEditable(true);
    panel.add(combo2);
    panel.setSize(300, 200);

    popupMenu = new JPopupMenu();
    JMenuItem item;
    for (int i = 0; i < dayData.length; i++) {
      item = popupMenu.add(new JMenuItem(dayData[i], mnDayData[i]));
      item.addActionListener(this);
    }
    panel.addMouseListener(new PopupListener(popupMenu));

    JTextField field = new JTextField("CTRL+down for Popup");
    // CTRL-down will show the popup.
    field
        .getInputMap()
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_MASK), "OPEN_POPUP");
    field.getActionMap().put("OPEN_POPUP", new PopupHandler());

    panel.add(field);

    return panel;
  }
  @SuppressWarnings("HardCodedStringLiteral")
  private void processListSelection(final KeyEvent e) {
    if (togglePopup(e)) return;

    if (!isPopupShowing()) return;

    final InputMap map = myPathTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (map != null) {
      final Object object = map.get(KeyStroke.getKeyStrokeForEvent(e));
      if (object instanceof Action) {
        final Action action = (Action) object;
        if (action.isEnabled()) {
          action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "action"));
          e.consume();
          return;
        }
      }
    }

    final Object action = getAction(e, myList);

    if ("selectNextRow".equals(action)) {
      if (ensureSelectionExists()) {
        ListScrollingUtil.moveDown(myList, e.getModifiersEx());
      }
    } else if ("selectPreviousRow".equals(action)) {
      ListScrollingUtil.moveUp(myList, e.getModifiersEx());
    } else if ("scrollDown".equals(action)) {
      ListScrollingUtil.movePageDown(myList);
    } else if ("scrollUp".equals(action)) {
      ListScrollingUtil.movePageUp(myList);
    } else if (getSelectedFileFromCompletionPopup() != null
        && (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB)
        && e.getModifiers() == 0) {
      hideCurrentPopup();
      e.consume();
      processChosenFromCompletion(e.getKeyCode() == KeyEvent.VK_TAB);
    }
  }
  /** Creates panel with function logo and some utilities */
  private Container createTopPanel() {
    JPanel topContainer = new JPanel(new BorderLayout());

    Box logoContainer = Box.createHorizontalBox();
    logoContainer.add(new JLabel(logo));

    topContainer.add(logoContainer, BorderLayout.WEST);

    Box toolBox = Box.createHorizontalBox();

    toolBox.add(new JLabel(toolboxIcon));

    final JLabel highlightGroups = new JLabel(highlightOffIcon);
    highlightGroups.addMouseListener(
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            highlightGroups.setIcon(isHighlighted ? highlightOnOver : highlightOffOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            highlightGroups.setIcon(isHighlighted ? highlightOnIcon : highlightOffIcon);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            if (isHighlighted) {

              transposedSpreadsheetSubform.changeTableRenderer(
                  transposedSpreadsheetSubform.getLockedTable(), null);
              transposedSpreadsheetSubform.changeTableRenderer(
                  transposedSpreadsheetSubform.getScrollTable(), null);
            } else {

              transposedSpreadsheetSubform.changeTableRenderer(
                  transposedSpreadsheetSubform.getLockedTable(),
                  new CustomRowRenderer(
                      transposedSpreadsheetModel.getRowToColour(), UIHelper.VER_11_BOLD));

              transposedSpreadsheetSubform.changeTableRenderer(
                  transposedSpreadsheetSubform.getScrollTable(),
                  new CustomRowRenderer(
                      transposedSpreadsheetModel.getRowToColour(), UIHelper.VER_11_PLAIN));
            }

            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    transposedSpreadsheetSubform.validate();
                    transposedSpreadsheetSubform.repaint();
                    highlightGroups.setIcon(isHighlighted ? highlightOnIcon : highlightOffIcon);
                  }
                });
            isHighlighted = !isHighlighted;
          }
        });

    toolBox.add(highlightGroups);

    final JLabel goToRecordButton = new JLabel(goToRecord);
    goToRecordButton.addMouseListener(
        new MouseAdapter() {
          public void mouseEntered(MouseEvent mouseEvent) {
            goToRecordButton.setIcon(goToRecordOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            goToRecordButton.setIcon(goToRecord);
          }
        });

    toolBox.add(goToRecordButton);

    Box goToRecordEntryField = Box.createVerticalBox();

    final JTextField field = new JTextField("row #");
    UIHelper.renderComponent(field, UIHelper.VER_10_PLAIN, UIHelper.LIGHT_GREY_COLOR, false);

    Dimension fieldSize = new Dimension(60, 16);
    field.setPreferredSize(fieldSize);
    field.setSize(fieldSize);

    goToRecordEntryField.add(Box.createVerticalStrut(5));
    goToRecordEntryField.add(field);
    goToRecordEntryField.add(Box.createVerticalStrut(5));

    final JLabel goButton = new JLabel(go);
    goButton.addMouseListener(
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            goButton.setIcon(goOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            goButton.setIcon(go);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            goToColumn(field);
          }
        });

    Action locateColumn =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            goToColumn(field);
          }
        };

    field.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "LOCATE_COLUMN");
    field.getActionMap().put("LOCATE_COLUMN", locateColumn);

    toolBox.add(goToRecordEntryField);
    toolBox.add(goButton);
    goToRecordEntryField.add(Box.createVerticalStrut(5));

    topContainer.add(toolBox, BorderLayout.EAST);

    information = UIHelper.createLabel("", UIHelper.VER_11_PLAIN, UIHelper.LIGHT_GREY_COLOR);
    information.setHorizontalAlignment(SwingConstants.RIGHT);

    topContainer.add(UIHelper.wrapComponentInPanel(information), BorderLayout.SOUTH);

    return topContainer;
  }
  public FileTextFieldImpl(
      final JTextField field,
      Finder finder,
      LookupFilter filter,
      Map<String, String> macroMap,
      final Disposable parent) {
    myPathTextField = field;
    myMacroMap = new TreeMap<String, String>();
    myMacroMap.putAll(macroMap);

    final InputMap listMap = (InputMap) UIManager.getDefaults().get("List.focusInputMap");
    final KeyStroke[] listKeys = listMap.keys();
    myDisabledTextActions = new HashSet<Action>();
    for (KeyStroke eachListStroke : listKeys) {
      final String listActionID = (String) listMap.get(eachListStroke);
      if ("selectNextRow".equals(listActionID) || "selectPreviousRow".equals(listActionID)) {
        final Object textActionID = field.getInputMap().get(eachListStroke);
        if (textActionID != null) {
          final Action textAction = field.getActionMap().get(textActionID);
          if (textAction != null) {
            myDisabledTextActions.add(textAction);
          }
        }
      }
    }

    final FileTextFieldImpl assigned = (FileTextFieldImpl) myPathTextField.getClientProperty(KEY);
    if (assigned != null) {
      assigned.myFinder = finder;
      assigned.myFilter = filter;
      return;
    }

    myPathTextField.putClientProperty(KEY, this);
    final boolean headless = ApplicationManager.getApplication().isUnitTestMode();

    myUiUpdater = new MergingUpdateQueue("FileTextField.UiUpdater", 200, false, myPathTextField);
    if (!headless) {
      new UiNotifyConnector(myPathTextField, myUiUpdater);
    }

    myFinder = finder;
    myFilter = filter;

    myFileSpitRegExp = myFinder.getSeparator().replaceAll("\\\\", "\\\\\\\\");

    myPathTextField
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              public void insertUpdate(final DocumentEvent e) {
                processTextChanged();
              }

              public void removeUpdate(final DocumentEvent e) {
                processTextChanged();
              }

              public void changedUpdate(final DocumentEvent e) {
                processTextChanged();
              }
            });

    myPathTextField.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(final KeyEvent e) {
            processListSelection(e);
          }
        });

    myPathTextField.addFocusListener(
        new FocusAdapter() {
          public void focusLost(final FocusEvent e) {
            closePopup();
          }
        });

    myCancelAction = new CancelAction();

    new LazyUiDisposable<FileTextFieldImpl>(parent, field, this) {
      protected void initialize(
          @NotNull Disposable parent, @NotNull FileTextFieldImpl child, @Nullable Project project) {
        Disposer.register(child, myUiUpdater);
      }
    };
  }
  void createGUI() {
    // create username field info
    Box fields = Box.createVerticalBox();
    fields.add(Box.createVerticalStrut(10));
    fields.setOpaque(false);

    JPanel userNameCont = new JPanel(new GridLayout(1, 2));
    JLabel usernameLabel = new JLabel("username ");
    usernameLabel.setFont(UIHelper.VER_12_BOLD);
    usernameLabel.setForeground(UIHelper.DARK_GREEN_COLOR);
    userNameCont.add(usernameLabel);

    username = new RoundedJTextField(10, UIHelper.TRANSPARENT_LIGHT_GREEN_COLOR);
    username.setOpaque(false);

    UIHelper.renderComponent(username, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);

    userNameCont.add(username);
    userNameCont.setOpaque(false);

    JPanel passwordCont = new JPanel(new GridLayout(1, 2));
    JLabel passwordLabel = new JLabel("password ");
    passwordLabel.setFont(UIHelper.VER_12_BOLD);
    passwordLabel.setForeground(UIHelper.DARK_GREEN_COLOR);
    passwordCont.add(passwordLabel);
    password = new RoundedJPasswordField(10, UIHelper.TRANSPARENT_LIGHT_GREEN_COLOR);
    UIHelper.renderComponent(password, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);

    passwordCont.add(password);
    passwordCont.setOpaque(false);

    fields.add(userNameCont);
    fields.add(Box.createVerticalStrut(10));
    fields.add(passwordCont);

    JPanel northPanel = new JPanel();
    northPanel.add(new JLabel(pleaseLogin, JLabel.RIGHT), BorderLayout.NORTH);
    northPanel.add(fields, BorderLayout.CENTER);

    JPanel southPanel = new JPanel(new GridLayout(4, 1));
    southPanel.setOpaque(false);

    JPanel buttonContainer = new JPanel(new GridLayout(1, 2));
    buttonContainer.setOpaque(false);

    createProfile = new JLabel(createProfileButton, JLabel.LEFT);
    createProfile.addMouseListener(
        new MouseAdapter() {

          public void mousePressed(MouseEvent event) {
            createProfile.setIcon(createProfileButton);

            clearFields();

            confirmExitPanel.setVisible(false);

            menu.changeView(menu.getCreateProfileGUI());
          }

          public void mouseEntered(MouseEvent event) {
            createProfile.setIcon(createProfileButtonOver);
          }

          public void mouseExited(MouseEvent event) {
            createProfile.setIcon(createProfileButton);
          }
        });

    buttonContainer.add(createProfile);

    login = new JLabel(loginButton, JLabel.RIGHT);
    login.addMouseListener(
        new MouseAdapter() {

          public void mousePressed(MouseEvent event) {
            login.setIcon(Authentication.this.loginButton);
            confirmExitPanel.setVisible(false);
            login();
          }

          public void mouseEntered(MouseEvent event) {
            login.setIcon(loginButtonOver);
          }

          public void mouseExited(MouseEvent event) {
            login.setIcon(Authentication.this.loginButton);
          }
        });

    Action loginAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            login();
          }
        };

    password.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "LOGIN");
    password.getActionMap().put("LOGIN", loginAction);
    username.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "LOGIN");
    username.getActionMap().put("LOGIN", loginAction);

    buttonContainer.add(login);

    southPanel.add(status);
    southPanel.add(buttonContainer);

    exit = new JLabel(exitButtonSml, JLabel.CENTER);
    exit.addMouseListener(
        new MouseAdapter() {

          public void mousePressed(MouseEvent event) {
            exit.setIcon(exitButtonSml);
            confirmExitPanel.setVisible(true);
            confirmExitPanel.getParent().validate();
          }

          public void mouseEntered(MouseEvent event) {
            exit.setIcon(exitButtonSmlOver);
          }

          public void mouseExited(MouseEvent event) {
            exit.setIcon(exitButtonSml);
          }
        });

    JPanel exitCont = new JPanel(new GridLayout(1, 1));
    exitCont.setOpaque(false);

    exitCont.add(exit);

    southPanel.add(exitCont);

    southPanel.add(confirmExitPanel);

    northPanel.add(southPanel, BorderLayout.SOUTH);
    northPanel.setOpaque(false);

    add(northPanel, BorderLayout.CENTER);
  }
Beispiel #6
0
  public SearchManager2(JabRefFrame frame, SidePaneManager manager) {
    super(manager, GUIGlobals.getIconUrl("search"), Globals.lang("Search"));

    this.frame = frame;
    incSearcher = new IncrementalSearcher(Globals.prefs);

    // setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.magenta));

    searchReq =
        new JCheckBoxMenuItem(
            Globals.lang("Search required fields"),
            Globals.prefs.getBoolean(JabRefPreferences.SEARCH_REQ));
    searchOpt =
        new JCheckBoxMenuItem(
            Globals.lang("Search optional fields"),
            Globals.prefs.getBoolean(JabRefPreferences.SEARCH_OPT));
    searchGen =
        new JCheckBoxMenuItem(
            Globals.lang("Search general fields"),
            Globals.prefs.getBoolean(JabRefPreferences.SEARCH_GEN));
    searchAll =
        new JCheckBoxMenuItem(
            Globals.lang("Search all fields"),
            Globals.prefs.getBoolean(JabRefPreferences.SEARCH_ALL));
    regExpSearch =
        new JCheckBoxMenuItem(
            Globals.lang("Use regular expressions"),
            Globals.prefs.getBoolean(JabRefPreferences.REG_EXP_SEARCH));

    increment = new JRadioButton(Globals.lang("Incremental"), false);
    floatSearch = new JRadioButton(Globals.lang("Float"), true);
    hideSearch = new JRadioButton(Globals.lang("Filter"), true);
    showResultsInDialog = new JRadioButton(Globals.lang("Show results in dialog"), true);
    searchAllBases =
        new JRadioButton(
            Globals.lang("Global search"),
            Globals.prefs.getBoolean(JabRefPreferences.SEARCH_ALL_BASES));
    ButtonGroup types = new ButtonGroup();
    types.add(increment);
    types.add(floatSearch);
    types.add(hideSearch);
    types.add(showResultsInDialog);
    types.add(searchAllBases);

    select = new JCheckBoxMenuItem(Globals.lang("Select matches"), false);
    increment.setToolTipText(Globals.lang("Incremental search"));
    floatSearch.setToolTipText(Globals.lang("Gray out non-matching entries"));
    hideSearch.setToolTipText(Globals.lang("Hide non-matching entries"));
    showResultsInDialog.setToolTipText(Globals.lang("Show search results in a window"));

    // Add an item listener that makes sure we only listen for key events
    // when incremental search is turned on.
    increment.addItemListener(this);
    floatSearch.addItemListener(this);
    hideSearch.addItemListener(this);
    showResultsInDialog.addItemListener(this);
    // Add the global focus listener, so a menu item can see if this field was focused when
    // an action was called.
    searchField.addFocusListener(Globals.focusListener);

    if (searchAll.isSelected()) {
      searchReq.setEnabled(false);
      searchOpt.setEnabled(false);
      searchGen.setEnabled(false);
    }
    searchAll.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent event) {
            boolean state = !searchAll.isSelected();
            searchReq.setEnabled(state);
            searchOpt.setEnabled(state);
            searchGen.setEnabled(state);
          }
        });

    caseSensitive =
        new JCheckBoxMenuItem(
            Globals.lang("Case sensitive"),
            Globals.prefs.getBoolean(JabRefPreferences.CASE_SENSITIVE_SEARCH));

    highLightWords =
        new JCheckBoxMenuItem(
            Globals.lang("Highlight Words"),
            Globals.prefs.getBoolean(JabRefPreferences.HIGH_LIGHT_WORDS));

    searchAutoComplete =
        new JCheckBoxMenuItem(
            Globals.lang("Autocomplete names"),
            Globals.prefs.getBoolean(JabRefPreferences.SEARCH_AUTO_COMPLETE));
    settings.add(select);

    // 2005.03.29, trying to remove field category searches, to simplify
    // search usability.
    // settings.addSeparator();
    // settings.add(searchReq);
    // settings.add(searchOpt);
    // settings.add(searchGen);
    // settings.addSeparator();
    // settings.add(searchAll);
    // ---------------------------------------------------------------
    settings.addSeparator();
    settings.add(caseSensitive);
    settings.add(regExpSearch);
    settings.addSeparator();
    settings.add(highLightWords);
    settings.addSeparator();
    settings.add(searchAutoComplete);

    searchField.addActionListener(this);
    searchField.addCaretListener(this);
    search.addActionListener(this);
    searchField.addFocusListener(
        new FocusAdapter() {

          @Override
          public void focusGained(FocusEvent e) {
            if (increment.isSelected()) {
              searchField.setText("");
            }
          }

          @Override
          public void focusLost(FocusEvent e) {
            incSearch = false;
            incSearchPos = -1; // Reset incremental
            // search. This makes the
            // incremental search reset
            // once the user moves focus to
            // somewhere else.
            if (increment.isSelected()) {
              // searchField.setText("");
              // System.out.println("focuslistener");
            }
          }
        });
    escape.addActionListener(this);
    escape.setEnabled(false); // enabled after searching

    openset.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (settings.isVisible()) {
              // System.out.println("oee");
              // settings.setVisible(false);
            } else {
              JButton src = (JButton) e.getSource();
              settings.show(src, 0, openset.getHeight());
            }
          }
        });

    searchAutoComplete.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            Globals.prefs.putBoolean(
                JabRefPreferences.SEARCH_AUTO_COMPLETE, searchAutoComplete.isSelected());
            if (SearchManager2.this.frame.basePanel() != null) {
              SearchManager2.this.frame.basePanel().updateSearchManager();
            }
          }
        });
    Insets margin = new Insets(0, 2, 0, 2);
    // search.setMargin(margin);
    escape.setMargin(margin);
    openset.setMargin(margin);
    JButton help = new JButton(GUIGlobals.getImage("help"));
    int butSize = help.getIcon().getIconHeight() + 5;
    Dimension butDim = new Dimension(butSize, butSize);
    help.setPreferredSize(butDim);
    help.setMinimumSize(butDim);
    help.setMargin(margin);
    help.addActionListener(new HelpAction(Globals.helpDiag, GUIGlobals.searchHelp, "Help"));

    // Select the last used mode of search:
    if (Globals.prefs.getBoolean(JabRefPreferences.INCREMENT_S)) {
      increment.setSelected(true);
    } else if (Globals.prefs.getBoolean(JabRefPreferences.FLOAT_SEARCH)) {
      floatSearch.setSelected(true);
    } else if (Globals.prefs.getBoolean(JabRefPreferences.SHOW_SEARCH_IN_DIALOG)) {
      showResultsInDialog.setSelected(true);
    } else if (Globals.prefs.getBoolean(JabRefPreferences.SEARCH_ALL_BASES)) {
      searchAllBases.setSelected(true);
    } else {
      hideSearch.setSelected(true);
    }

    JPanel main = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    main.setLayout(gbl);
    GridBagConstraints con = new GridBagConstraints();
    con.gridwidth = GridBagConstraints.REMAINDER;
    con.fill = GridBagConstraints.BOTH;
    con.weightx = 1;

    gbl.setConstraints(searchField, con);
    main.add(searchField);
    // con.gridwidth = 1;
    gbl.setConstraints(search, con);
    main.add(search);
    con.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(escape, con);
    main.add(escape);
    con.insets = new Insets(0, 2, 0, 0);
    gbl.setConstraints(increment, con);
    main.add(increment);
    gbl.setConstraints(floatSearch, con);
    main.add(floatSearch);
    gbl.setConstraints(hideSearch, con);
    main.add(hideSearch);
    gbl.setConstraints(showResultsInDialog, con);
    main.add(showResultsInDialog);
    gbl.setConstraints(searchAllBases, con);
    main.add(searchAllBases);
    con.insets = new Insets(0, 0, 0, 0);
    JPanel pan = new JPanel();
    GridBagLayout gb = new GridBagLayout();
    gbl.setConstraints(pan, con);
    pan.setLayout(gb);
    con.weightx = 1;
    con.gridwidth = 1;
    gb.setConstraints(openset, con);
    pan.add(openset);
    con.weightx = 0;
    gb.setConstraints(help, con);
    pan.add(help);
    main.add(pan);
    main.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

    setContentContainer(main);

    searchField.getInputMap().put(Globals.prefs.getKey("Repeat incremental search"), "repeat");

    searchField
        .getActionMap()
        .put(
            "repeat",
            new AbstractAction() {

              @Override
              public void actionPerformed(ActionEvent e) {
                if (increment.isSelected()) {
                  repeatIncremental();
                }
              }
            });
    searchField.getInputMap().put(Globals.prefs.getKey("Clear search"), "escape");
    searchField
        .getActionMap()
        .put(
            "escape",
            new AbstractAction() {

              @Override
              public void actionPerformed(ActionEvent e) {
                hideAway();
                // SearchManager2.this.actionPerformed(new ActionEvent(escape, 0, ""));
              }
            });
    setSearchButtonSizes();
    updateSearchButtonText();
  }