Пример #1
0
 @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);
   }
 }
Пример #2
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));
  }
Пример #3
0
  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);
  }