コード例 #1
0
  /**
   * sets up the keystroke mappings for "Ctrl-F" firing the find/replace panel Escape making it
   * disappear, and enter key firing a search
   */
  private void setupKeyStrokeMappings() {
    // table.getActionMap().clear();

    // override the "Ctrl-F" function for launching the find dialog shipped with JXTable
    table
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(
                KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
            UIRegistry.getResourceString(FIND));
    table
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK),
            UIRegistry.getResourceString(FIND));

    // create action that will display the find/replace dialog
    launchFindAction = new LaunchFindAction();
    table.getActionMap().put(FIND, launchFindAction);

    // Allow ESC buttun to call DisablePanelAction
    String CANCEL_KEY = "CANCELKEY"; // i18n
    // Allow ENTER button to SearchAction
    String ENTER_KEY = "ENTERKEY"; // i18n
    String REPLACE_KEY = "REPLACEKEY"; // i18n

    KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);

    InputMap textFieldInputMap =
        findField.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    textFieldInputMap.put(enterKey, ENTER_KEY);
    textFieldInputMap.put(escapeKey, CANCEL_KEY);

    ActionMap textFieldActionMap = findField.getActionMap();
    textFieldActionMap.put(ENTER_KEY, searchAction);
    textFieldActionMap.put(CANCEL_KEY, hideFindPanelAction);

    if (!table.isReadOnly()) {
      InputMap replaceFieldInputMap =
          replaceField.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
      replaceFieldInputMap.put(enterKey, REPLACE_KEY);
      replaceFieldInputMap.put(escapeKey, CANCEL_KEY);

      ActionMap replaceFieldActionMap = replaceField.getActionMap();
      replaceFieldActionMap.put(REPLACE_KEY, replaceAction);
      replaceFieldActionMap.put(CANCEL_KEY, hideFindPanelAction);
    }
  }
コード例 #2
0
  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;
  }
コード例 #3
0
  private static void fixKeyStroke(JTextField textField, String name, int vk, int mask) {
    Action action = null;

    ActionMap actionMap = textField.getActionMap();
    for (Object k : actionMap.allKeys()) {
      if (k.equals(name)) {
        action = actionMap.get(k);
      }
    }

    if (action != null) {
      InputMap[] inputMaps =
          new InputMap[] {
            textField.getInputMap(JComponent.WHEN_FOCUSED),
            textField.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT),
            textField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
          };

      for (InputMap i : inputMaps) {
        i.put(
            KeyStroke.getKeyStroke(vk, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | mask),
            action);
      }
    }
  }
コード例 #4
0
    Panel() {
      dialogPanel = new JPanel(new BorderLayout());
      dialogPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

      entryPanel = new JPanel(new BorderLayout(4, 0));
      entryPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
      entry = new JTextField(20);

      buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
      ok = new JButton("OK");
      cancel = new JButton("Cancel");

      entryPanel.add(entry, BorderLayout.CENTER);

      buttonPanel.add(ok);
      buttonPanel.add(cancel);

      dialogPanel.add(entryPanel, BorderLayout.CENTER);
      dialogPanel.add(buttonPanel, BorderLayout.SOUTH);

      ok.addActionListener(this);
      cancel.addActionListener(this);

      entry.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
      entry.getActionMap().put("enter", new EnterAction());
    }
コード例 #5
0
  public TextFieldDocListener(JTextField txtField) {
    this.txtField = txtField;

    InputMap im = txtField.getInputMap();
    ActionMap am = txtField.getActionMap();
    im.put(KeyStroke.getKeyStroke("TAB"), COMMIT_ACTION);
    am.put(COMMIT_ACTION, new CommitAction());

    PropertiesParser prop = PropertiesLoader.getPropertyInstance();
    String[] hints = prop.getPropertyGroups("sim.gui.ioinput.textcompletion");
    commands = new ArrayList<String>(hints.length);
    for (String hint : hints) {
      commands.add(prop.getStringProperty("sim.gui.ioinput.textcompletion." + hint + ".hints"));
    }
    Collections.sort(commands);
    logger.debug("text completion hints loaded: " + commands.toString());
  }
コード例 #6
0
    InputPanel() {
      p.setLayout(new BorderLayout());
      p.add(inputJTF, BorderLayout.CENTER);

      InputMap im = inputJTF.getInputMap(JComponent.WHEN_FOCUSED);
      ActionMap am = inputJTF.getActionMap();
      im.put(KeyStroke.getKeyStroke("ESCAPE"), ESCAPE_ACTION);
      am.put(ESCAPE_ACTION, new EscapeAction());

      im.put(KeyStroke.getKeyStroke("ENTER"), ENTER_ACTION);
      am.put(ENTER_ACTION, new RedrawListener());

      im.put(KeyStroke.getKeyStroke("ESCAPE"), ESCAPE_ACTION);
      am.put(ESCAPE_ACTION, new EscapeAction());

      im.put(KeyStroke.getKeyStroke("ENTER"), ENTER_ACTION);
      am.put(ENTER_ACTION, new RedrawListener());
    }
コード例 #7
0
  public TextFieldDemo() {
    initComponents();

    InputStream in = getClass().getResourceAsStream("content.txt");
    try {
      textArea.read(new InputStreamReader(in), null);
    } catch (IOException e) {
      e.printStackTrace();
    }

    hilit = new DefaultHighlighter();
    painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR);
    textArea.setHighlighter(hilit);

    entryBg = entry.getBackground();
    entry.getDocument().addDocumentListener(this);

    InputMap im = entry.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap am = entry.getActionMap();
    im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION);
    am.put(CANCEL_ACTION, new CancelAction());
  }
コード例 #8
0
  public void query(String query) throws IOException {
    EntrySet data;
    try {
      data = DatabaseService.getConnection().query(query);
    } catch (QueryException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
          Main.MAIN_FRAME, e.getMessage(), "Error Querying", JOptionPane.ERROR_MESSAGE);
      return;
    }

    removeAll();
    mainPanel.removeAll();
    toolbarPanel.removeAll();
    jtable = new JTable(new DataTableModel(data));
    jtable.setDefaultRenderer(Object.class, new DataTableRenderer());
    DataTableModel model = (DataTableModel) jtable.getModel();

    for (Entry entry : data.getEntries()) {
      model.addRow(entry.getData());
    }

    jtable.addMouseListener(new RowSelectionPopupListener(jtable, data));
    jtable
        .getModel()
        .addTableModelListener(
            new TableModelListener() {
              @Override
              public void tableChanged(TableModelEvent e) {
                if (!ignoreChanges) {
                  if (e.getType() == TableModelEvent.UPDATE) {
                    ignoreChanges = true;
                    int row = e.getLastRow();

                    if (row < data.size()) {
                      Entry entry = data.getEntries()[row];
                      Change change =
                          new Change(
                              entry.getEntryID(), Change.SET, new ArrayList<>(), new ArrayList<>());
                      Change previous = ChangeService.getService().getChange(entry.getEntryID());
                      if (previous != null) {
                        change.setOriginalData(previous.getOriginalData());
                      } else {
                        change.setOriginalData(new ArrayList<>(Arrays.asList(entry.getData())));
                      }

                      for (int col = 0; col < jtable.getColumnCount(); col++) {
                        change.getData().add((Serializable) jtable.getValueAt(row, col));
                      }

                      model.setRowColor(row, Color.orange);
                      ChangeService.getService().change(change);
                      setCanCommit(true);
                      ignoreChanges = false;
                    } else {
                      JOptionPane.showMessageDialog(
                          Main.MAIN_FRAME,
                          "You must commit this entry before editing it.",
                          "Error Editing",
                          JOptionPane.WARNING_MESSAGE);
                    }
                  }
                }
              }
            });

    JButton queryButton = new JButton("Query");
    queryField.setText(lastQuery);
    AutoCompleteDocument auto = new AutoCompleteDocument(queryField, data);

    queryField.getDocument().addDocumentListener(auto);
    queryField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTROL, 0), "autocomplete");
    queryField.getActionMap().put("autocomplete", auto.getAutocompleteAction());
    mainPanel.add(queryField, 0, 0);
    mainPanel.c.anchor = GridBagConstraints.NORTHEAST;
    mainPanel.add(queryButton, 0, 0);

    queryButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (canCommit) {
              if (JOptionPane.showConfirmDialog(
                      Main.MAIN_FRAME,
                      "Requerying the table will remove your uncommited changes. Continue?",
                      "Discard Uncommited Changes?",
                      JOptionPane.YES_NO_CANCEL_OPTION)
                  != JOptionPane.YES_OPTION) {
                return;
              }
            }
            ChangeService.getService().setChanges(new ArrayList<>());
            setCanCommit(false);

            try {
              lastQuery = queryField.getText();
              DatabaseService.getConnection()
                  .query(queryField.getText() + " IN " + DatabaseService.getCurrentTableName());
              query(lastQuery.toLowerCase().startsWith("get") ? lastQuery : "GET");
            } catch (QueryException e1) {
              JOptionPane.showMessageDialog(
                  Main.MAIN_FRAME, e1.getMessage(), "Error Querying", JOptionPane.ERROR_MESSAGE);
            } catch (IOException e1) {
              e1.printStackTrace();
            }
            return;
          }
        });

    if (commitButton.getActionListeners().length > 0) {
      commitButton.removeActionListener(commitButton.getActionListeners()[0]);
    }
    commitButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            CommitChangesWindow window = new CommitChangesWindow(data);
            window.open();
          }
        });
    JButton addButton = new JButton(new ImageIcon("assets/GreenPlus.png"));
    addButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            AddEntryWindow window = new AddEntryWindow(data);
            window.open();
          }
        });

    canCommit = false;
    commitButton.setEnabled(false);
    toolbarPanel.add(addButton, 0, 0);
    toolbarPanel.add(commitButton, 0, 1);

    addButton.setToolTipText("Add Entry");
    commitButton.setToolTipText("Commit Changes");

    mainPanel.c.anchor = GridBagConstraints.NORTHWEST;
    mainPanel.add(status, 0, 1);
    mainPanel.add(new JScrollPane(jtable), 0, 2);

    add(toolbarPanel);
    add(mainPanel);
    Main.MAIN_FRAME.pack();

    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    Main.MAIN_FRAME.setLocation(
        dim.width / 2 - Main.MAIN_FRAME.getSize().width / 2,
        dim.height / 2 - Main.MAIN_FRAME.getSize().height / 2);
  }
コード例 #9
0
    SettingsPanel() {
      // Construct a GridLayout with 1 columns and an unspecified number of rows.
      // p.setLayout(new GridLayout(0,1));
      p.setLayout(new BorderLayout());

      JPanel topPanel = new JPanel();
      topPanel.setBorder(BorderFactory.createTitledBorder("settings"));
      topPanel.setLayout(new GridLayout(0, 1));
      p.add(topPanel, BorderLayout.NORTH);

      final JCheckBox jcb = new JCheckBox("Show contours with colours", true);
      jcb.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              useColors = jcb.isSelected();
              redraw();
            }
          });
      topPanel.add(jcb);

      decompList.setSelectedIndex(decompStrings.length - 1);
      decompList.addActionListener(new RedrawListener());
      topPanel.add(decompList);

      recompList.setSelectedIndex(recompStrings.length - 1);
      recompList.addActionListener(new RedrawListener());
      topPanel.add(recompList);

      JPanel examplePanel = new JPanel();
      examplePanel.setBorder(BorderFactory.createTitledBorder("examples"));
      examplePanel.setLayout(new GridLayout(0, 1));
      p.add(examplePanel, BorderLayout.CENTER);

      JButton v3 = new JButton("draw Venn 3");
      v3.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              draw("a b c ab ac bc abc");
            }
          });
      examplePanel.add(v3);

      final JLabel testLabel = new JLabel("draw test index:");
      examplePanel.add(testLabel);
      InputMap im = testJTF.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
      ActionMap am = testJTF.getActionMap();
      im.put(KeyStroke.getKeyStroke("ENTER"), ENTER_ACTION);
      am.put(ENTER_ACTION, new TestListener());
      examplePanel.add(testJTF);

      JButton next = new JButton("draw next test case");
      next.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              if (testJTF.getText().length() == 0) {
                test_num = 0;
              } else {
                test_num += 1;
                if (test_num > TestData.test_data.length - 1) {
                  test_num = 0;
                }
              }
              testJTF.setText("" + (test_num + 1));
              drawTest(test_num + 1);
            }
          });
      examplePanel.add(next);
      JButton prev = new JButton("draw previous test case");
      prev.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              if (testJTF.getText().length() == 0) {
                test_num = 0;
              } else {
                test_num -= 1;
                if (test_num < 0) {
                  test_num = TestData.test_data.length - 1;
                }
              }
              testJTF.setText("" + (test_num + 1));
              drawTest(test_num + 1);
            }
          });
      examplePanel.add(prev);
    }
コード例 #10
0
  /** 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;
  }
コード例 #11
0
  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);
      }
    };
  }
コード例 #12
0
  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);
  }
コード例 #13
0
ファイル: SearchManager2.java プロジェクト: steog88/jabref
  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();
  }