private void cmbTagsActionPerformed(ActionEvent e) { if (!editmode) return; if (txtTags.getText().isEmpty()) return; if (txtTags.getText().length() > 100) return; final String enteredText = SYSTools.tidy(txtTags.getText()).toLowerCase(); if (!addNewTags && !mapAllTags.containsKey(enteredText)) return; if (!mapAllTags.containsKey(enteredText)) { Commontags myNewCommontag = new Commontags(SYSTools.tidy(enteredText)); mapAllTags.put(enteredText, myNewCommontag); ac.uninstallListeners(); ac = new AutoCompletion(txtTags, mapAllTags.keySet().toArray(new String[] {})); ac.setStrict(false); ac.setStrictCompletion(false); } if (!listSelectedTags.contains(mapAllTags.get(enteredText))) { listSelectedTags.add(mapAllTags.get(enteredText)); SwingUtilities.invokeLater( () -> { if (listSelectedTags.size() % MAXLINE == 0) { add(createButton(mapAllTags.get(enteredText)), RiverLayout.LINE_BREAK); } else { add(createButton(mapAllTags.get(enteredText)), RiverLayout.LEFT); } txtTags.setText(""); revalidate(); repaint(); notifyListeners(mapAllTags.get(enteredText)); }); } }
private void initPanel() { mapButtons = new HashMap<>(); for (Commontags commontags : CommontagsTools.getAll()) { mapAllTags.put(commontags.getText(), commontags); } int tagnum = 1; for (Commontags selectedTags : listSelectedTags) { if (tagnum % MAXLINE == 0) { add(createButton(selectedTags), RiverLayout.LINE_BREAK); } else { add(createButton(selectedTags), RiverLayout.LEFT); } tagnum++; } if (editmode) { txtTags = new JTextField(10); SelectAllUtils.install(txtTags); ac = new AutoCompletion(txtTags, mapAllTags.keySet().toArray(new String[] {})); ac.setStrict(false); ac.setStrictCompletion(false); txtTags.addActionListener(e -> cmbTagsActionPerformed(e)); txtTags.addFocusListener( new FocusAdapter() { @Override public void focusLost(FocusEvent e) { cmbTagsActionPerformed(null); } }); txtTags.addKeyListener( new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (Character.isAlphabetic(c) || Character.isDigit(c)) { super.keyTyped(e); } else { e.consume(); } } }); add(txtTags); btnPickTags = GUITools.getTinyButton("opde.tags.pnlcommontags.allTags", SYSConst.icon22checkbox); btnPickTags.setPressedIcon(SYSConst.icon22Pressed); btnPickTags.addActionListener( e -> { final JidePopup popup = new JidePopup(); JPanel pnl = new JPanel(new BorderLayout()); pnl.add(new JScrollPane(getClickableTagsPanel()), BorderLayout.CENTER); // JButton btnApply = new JButton(SYSConst.icon22apply); // pnl.add(btnApply, BorderLayout.SOUTH); // // btnApply.addActionListener(new ActionListener() { // @Override // public void actionPerformed(ActionEvent ae) { // popup.hidePopup(); // } // }); popup.setMovable(false); popup .getContentPane() .setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnPickTags); popup.removeExcludedComponent(btnPickTags); pnl.setPreferredSize(new Dimension(400, 200)); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); popup.addPopupMenuListener( new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { OPDE.debug("popupMenuWillBecomeVisible"); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { SwingUtilities.invokeLater( () -> { removeAll(); add(txtTags); if (btnPickTags != null) { add(btnPickTags); } int tagnum1 = 1; for (JButton btn : mapButtons.values()) { if (tagnum1 % MAXLINE == 0) { add(btn, RiverLayout.LINE_BREAK); } else { add(btn, RiverLayout.LEFT); } tagnum1++; } revalidate(); repaint(); }); } @Override public void popupMenuCanceled(PopupMenuEvent e) { OPDE.debug("popupMenuCanceled"); } }); GUITools.showPopup(popup, SwingConstants.WEST); }); add(btnPickTags); } }