Пример #1
0
  private JPanel getClickableTagsPanel() {
    JPanel pnl = new JPanel();

    pnl.setLayout(new GridLayout(0, 3));

    ArrayList<Commontags> listTags = new ArrayList<>(mapAllTags.values());
    Collections.sort(listTags);

    for (final Commontags ctag : listTags) {
      JCheckBox cb = new JCheckBox(ctag.getText());

      cb.setForeground(GUITools.getColor(ctag.getColor()));
      cb.setFont(ctag.getType() == 0 ? SYSConst.ARIAL12 : SYSConst.ARIAL12BOLD);

      cb.setSelected(listSelectedTags.contains(ctag));

      cb.addItemListener(
          e -> {
            if (e.getStateChange() == ItemEvent.SELECTED) {
              listSelectedTags.add(ctag);
              add(createButton(ctag));
            } else {
              listSelectedTags.remove(ctag);
              mapButtons.remove(ctag);
            }
            notifyListeners(ctag);
          });

      pnl.add(cb);
    }
    return pnl;
  }
Пример #2
0
  private JButton createButton(final Commontags commontag) {

    if (mapButtons.containsKey(commontag)) {
      OPDE.debug("shortcut");
      return mapButtons.get(commontag);
    }

    final JButton jButton =
        new JButton(
            commontag.getText(),
            editmode ? SYSConst.icon16tagPurpleDelete2 : SYSConst.icon16tagPurple);
    jButton.setFont(SYSConst.ARIAL12);
    jButton.setBorder(new RoundedBorder(10));
    jButton.setHorizontalTextPosition(SwingConstants.LEADING);
    jButton.setForeground(SYSConst.purple1[SYSConst.dark3]);

    if (editmode) {

      jButton.addActionListener(
          e -> {
            listSelectedTags.remove(commontag);
            mapButtons.remove(commontag);
            SwingUtilities.invokeLater(
                () -> {
                  removeAll();

                  add(txtTags);
                  if (btnPickTags != null) {
                    add(btnPickTags);
                  }
                  int tagnum = 1;

                  for (JButton btn : mapButtons.values()) {
                    if (tagnum % MAXLINE == 0) {
                      add(btn, RiverLayout.LINE_BREAK);
                    } else {
                      add(btn, RiverLayout.LEFT);
                    }
                    tagnum++;
                  }

                  remove(jButton);
                  revalidate();
                  repaint();
                  notifyListeners(commontag);
                });
          });
    }
    mapButtons.put(commontag, jButton);

    return jButton;
  }
Пример #3
0
  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);
    }
  }