public void attachLinkSimulationListener() {
    theList.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    theList.addMouseListener(
        new MouseAdapter() {
          public void mouseEntered(MouseEvent e) {
            isOnRow = true;
          }

          public void mouseExited(MouseEvent e) {
            isOnRow = false;
            currentLinkRow = -1;
            theList.repaint();
          }
        });

    theList.addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseMoved(MouseEvent e) {
            isOnRow = true;
            currentLinkRow = theList.locationToIndex(e.getPoint());
            theList.repaint();
          }
        });
  }
Beispiel #2
0
  /**
   * Create a new {@link HoverCellRenderer} instance.
   *
   * @param list The list this renderer works for.
   */
  public HoverCellRenderer(final JList list) {

    panel = new HoverPanel(new BorderLayout());

    myList = list;
    list.addMouseListener(this);
    list.addMouseMotionListener(this);
  }
 @Override
 public void updateUI() {
   if (Objects.nonNull(cbml)) {
     JList<?> list = getList();
     if (Objects.nonNull(list)) {
       list.removeMouseListener(cbml);
       list.removeMouseMotionListener(cbml);
     }
   }
   super.updateUI();
   setRenderer(new ButtonsRenderer<E>(this));
   JList<?> list = getList();
   if (Objects.nonNull(list)) {
     cbml = new CellButtonsMouseListener();
     list.addMouseListener(cbml);
     list.addMouseMotionListener(cbml);
   }
 }
Beispiel #4
0
  private MainPanel() {
    super(new BorderLayout());

    DefaultListModel<String> model = new DefaultListModel<>();
    model.addElement("11\n1");
    model.addElement("222222222222222\n222222222222222");
    model.addElement("3333333333333333333\n33333333333333333333\n33333333333333333");
    model.addElement("444");

    JList<String> list = new JList<>(model);
    list.setFixedCellHeight(-1);
    CellButtonsMouseListener cbml = new CellButtonsMouseListener(list);
    list.addMouseListener(cbml);
    list.addMouseMotionListener(cbml);
    list.setCellRenderer(new ButtonsRenderer<String>(model));

    add(new JScrollPane(list));
    setPreferredSize(new Dimension(320, 240));
  }
Beispiel #5
0
 @Override
 public synchronized void addMouseMotionListener(MouseMotionListener l) {
   if (list != null) {
     list.addMouseMotionListener(l);
   }
 }
  private JList getInfoRouteJList() {
    if (infoRouteJList == null) {

      DefaultListModel defaultListModel = new DefaultListModel();
      if (this.infoRoutesStretchBeansCollection != null
          && !this.infoRoutesStretchBeansCollection.isEmpty()) {
        Iterator<InfoRouteStretchBean> it = this.infoRoutesStretchBeansCollection.iterator();
        while (it.hasNext()) {
          defaultListModel.addElement(it.next());
        }
      }

      infoRouteJList = new JList(defaultListModel);
      infoRouteJList.setCellRenderer(new InfoRouteListRenderer());
      infoRouteJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      infoRouteJList.addMouseMotionListener(
          new MouseMotionListener() {
            @Override
            public void mouseDragged(MouseEvent e) {}

            @Override
            public void mouseMoved(MouseEvent e) {
              // Like Mouse Over
              onInfoRouteListMosueOver(e.getPoint());
            }
          });

      infoRouteJList.addMouseListener(
          new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
              // On Mouse Click
              onInfoRouteListeMouseClicked();
            }

            @Override
            public void mouseEntered(MouseEvent e) {}

            @Override
            public void mouseExited(MouseEvent e) {}

            @Override
            public void mousePressed(MouseEvent e) {}

            @Override
            public void mouseReleased(MouseEvent e) {}
          });

      infoRouteJList.addKeyListener(
          new KeyListener() {

            @Override
            public void keyTyped(KeyEvent e) {}

            @Override
            public void keyReleased(KeyEvent e) {}

            @Override
            public void keyPressed(KeyEvent e) {
              if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                onInfoRouteListEnterKeyPressedDo();
              }
            }
          });
    }
    return infoRouteJList;
  }
  private Component createArrowSettingsPanel() {
    final ArrowStyle[] styles = DiagramSchema.getCurrentSchema().getArrowStyles();
    final JList<ArrowStyle> listView = new JList<>(styles);
    listView.setCellRenderer(
        new ListCellRenderer<ArrowStyle>() {
          public Component getListCellRendererComponent(
              final JList list,
              final ArrowStyle style,
              final int index,
              final boolean isSelected,
              final boolean cellHasFocus) {
            JPanel retVal =
                new JPanel() {
                  @Override
                  protected void paintComponent(final Graphics g) {
                    super.paintComponent(g);
                    Graphics2D g2d = (Graphics2D) g;
                    AffineTransform oldTransform = g2d.getTransform();
                    Paint oldPaint = g2d.getPaint();
                    Stroke oldStroke = g2d.getStroke();

                    Shape arrow = TransitionArrow.getArrowShape(style, getWidth() * 0.9);
                    g2d.setPaint(style.getColor());
                    g2d.translate(getWidth() * 0.95, getHeight() / 2);
                    g2d.fill(arrow);
                    if (style.getBorderWidth() != 0) {
                      g2d.setStroke(new BasicStroke(style.getBorderWidth()));
                      g2d.setPaint(Color.BLACK);
                      g2d.draw(arrow);
                    }

                    g2d.setPaint(oldPaint);
                    g2d.setStroke(oldStroke);
                    g2d.setTransform(oldTransform);
                  }
                };
            Dimension size = new Dimension(150, 30);
            retVal.setMinimumSize(size);
            retVal.setPreferredSize(size);

            if (sequenceValues.size() > index) {
              retVal.setToolTipText(sequenceValues.get(index).getDisplayString());
            } else {
              retVal.setToolTipText("n/a");
            }
            return retVal;
          }
        });
    listView.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() != 2) {
              return;
            }
            int index = listView.getSelectedIndex();
            ListModel listModel = listView.getModel();
            ArrowStyle style = (ArrowStyle) listModel.getElementAt(index);
            ArrowStyle newStyle = ArrowStyleChooser.showDialog(listView, "Edit arrow style", style);
            if (newStyle != null) {
              style.copyValues(newStyle);
              DiagramSchema.getCurrentSchema().store();
              diagramView.repaint();
            }
          }
        });
    MouseInputAdapter dragHandler =
        new MouseInputAdapter() {
          private boolean isDragging = false;
          private int dragStartIndex;

          @Override
          public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e)) {
              dragStartIndex = listView.getSelectedIndex();
            }
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            isDragging = false;
          }

          @Override
          public void mouseDragged(MouseEvent e) {
            if (isDragging) {
              int currentIndex = listView.locationToIndex(e.getPoint());
              if (currentIndex != dragStartIndex) {
                int dragTargetIndex = listView.getSelectedIndex();
                ArrowStyle sourceStyle = styles[dragStartIndex];
                styles[dragStartIndex] = styles[dragTargetIndex];
                styles[dragTargetIndex] = sourceStyle;
                dragStartIndex = currentIndex;
              }
            }
            isDragging = true;
          }
        };
    listView.addMouseListener(dragHandler);
    listView.addMouseMotionListener(dragHandler);
    return new JScrollPane(listView);
  }
Beispiel #8
0
  protected void initUI() {
    myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    myList.setCellRenderer(new MessagesListCellRenderer());
    myComponent.setLayout(new BorderLayout());

    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(new JPanel(), BorderLayout.CENTER);

    DefaultActionGroup group = new DefaultActionGroup();
    group.add(myWarningsAction);
    group.add(myInfoAction);
    group.add(myAutoscrollToSourceAction);
    group.add(new MessagesLimitAction());

    myToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, false);
    panel.add(myToolbar.getComponent(), BorderLayout.NORTH);

    myComponent.add(panel, BorderLayout.WEST);
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myList);
    myComponent.add(scrollPane, BorderLayout.CENTER);

    myComponent.registerKeyboardAction(
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (mySearchPanel == null) {
              mySearchPanel = new MessageToolSearchPanel(myList, MessageList.this);
              myComponent.add(mySearchPanel, BorderLayout.NORTH);
            }
            mySearchPanel.activate();
          }
        },
        KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    myList.setFixedCellHeight(
        Toolkit.getDefaultToolkit().getFontMetrics(myList.getFont()).getHeight() + 5);

    myList.registerKeyboardAction(
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            openCurrentMessageIfPossible();
          }
        },
        KeyStroke.getKeyStroke("F4"),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    myList.registerKeyboardAction(
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            openCurrentMessageIfPossible();
          }
        },
        KeyStroke.getKeyStroke("ENTER"),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    myList.registerKeyboardAction(
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            showHelpForCurrentMessage();
          }
        },
        KeyStroke.getKeyStroke("F1"),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    myList.registerKeyboardAction(
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            myList.getSelectionModel().setSelectionInterval(0, myList.getModel().getSize());
          }
        },
        KeyStroke.getKeyStroke('A', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    myList.addMouseWheelListener(
        new MouseWheelListener() {
          @Override
          public void mouseWheelMoved(MouseWheelEvent e) {
            myList.setAutoscrolls(false);
            scrollPane.dispatchEvent(e);
          }
        });

    myList.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            boolean oneClickOpen =
                e.getClickCount() == 1
                    && e.getButton() == MouseEvent.BUTTON1
                    && myAutoscrollToSourceAction.isSelected(null);
            boolean twoClickOpen = e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1;
            if (oneClickOpen || twoClickOpen) {
              openCurrentMessageIfPossible();
            }
          }

          @Override
          public void mousePressed(MouseEvent e) {
            // todo select element under mouse
            if (e.isPopupTrigger()) {
              showPopupMenu(e);
            }
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
              showPopupMenu(e);
            }
          }
        });

    myList.addMouseMotionListener(
        new MouseMotionListener() {
          @Override
          public void mouseDragged(MouseEvent e) {}

          @Override
          public void mouseMoved(MouseEvent e) {
            int index = myList.locationToIndex(e.getPoint());

            final IMessage message = index != -1 ? (IMessage) myModel.getElementAt(index) : null;
            if (message == null || !myAutoscrollToSourceAction.isSelected(null)) {
              myList.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
              return;
            }

            boolean canNavigate =
                ModelAccess.instance()
                    .runReadAction(
                        new Computable<Boolean>() {
                          @Override
                          public Boolean compute() {
                            return MessagesListCellRenderer.canNavigate(message) == NavStatus.YES;
                          }
                        });

            myList.setCursor(
                Cursor.getPredefinedCursor(
                    canNavigate ? Cursor.HAND_CURSOR : Cursor.DEFAULT_CURSOR));
          }
        });
  }