Пример #1
0
 public java.awt.Component getListCellRendererComponent(
     javax.swing.JList list, Object color, int index, boolean isSelected, boolean cellHasFocus) {
   return getComponent(
       color,
       isSelected,
       list.getBackground(),
       list.getSelectionBackground(),
       list.getFixedCellHeight(),
       list.getFont());
 }
Пример #2
0
  public void onKeyPressed(KeyEvent e) {
    int selectedIndex = list.getSelectedIndex();
    int newIndex = selectedIndex;

    int rowsOnScreen = scroll.getHeight() / list.getFixedCellHeight();

    switch (e.getKeyCode()) {
      case KeyEvent.VK_UP:
      case KeyEvent.VK_KP_UP:
        if (!e.isAltDown()) {
          newIndex--;
        }
        break;
      case KeyEvent.VK_DOWN:
      case KeyEvent.VK_KP_DOWN:
        if (!e.isAltDown()) {
          newIndex++;
        }
        break;
      case KeyEvent.VK_PAGE_UP:
        newIndex -= rowsOnScreen;
        break;
      case KeyEvent.VK_PAGE_DOWN:
        newIndex += rowsOnScreen;
        break;
      case KeyEvent.VK_ENTER:
        if ((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) > 0) {
          model.suggest(field.getText().trim());
        } else if ((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) > 0) {
          model.popOut(field.getText().trim());
        } else {
          translateSelected();
        }
        break;
    }

    // check, whether index was changed
    if (newIndex == selectedIndex) {
      return;
    }

    int size = list.getModel().getSize();

    if (newIndex < 0) {
      newIndex = 0;
    }
    if (newIndex >= size) {
      newIndex = size - 1;
    }

    setSelectedIndex(newIndex);
    setSearchTextWithoutNavigating(getSelectedIndexText());
  }
Пример #3
0
 private static int getListBaseline(JList list, int height) {
   int rowHeight = list.getFixedCellHeight();
   if (LIST_LABEL == null) {
     LIST_LABEL = new JLabel("X");
     LIST_LABEL.setBorder(new EmptyBorder(1, 1, 1, 1));
   }
   JLabel label = LIST_LABEL;
   label.setFont(list.getFont());
   // JList actually has much more complex behavior here.
   // If rowHeight != -1 the rowHeight is either the max of all cell
   // heights (layout orientation != VERTICAL), or is variable depending
   // upon the cell.  We assume a default size.
   // We could theoretically query the real renderer, but that would
   // not work for an empty model and the results may vary with
   // the content.
   if (rowHeight == -1) {
     rowHeight = label.getPreferredSize().height;
   }
   return getLabelBaseline(label, rowHeight) + list.getInsets().top;
 }
Пример #4
0
  public EditCircuitPaths(String title, CircuitBuilder parent, OBlock block) {
    _block = block;
    setTitle(java.text.MessageFormat.format(title, _block.getDisplayName()));
    _parent = parent;

    addWindowListener(
        new java.awt.event.WindowAdapter() {
          @Override
          public void windowClosing(java.awt.event.WindowEvent e) {
            closingEvent();
          }
        });
    addHelpMenu("package.jmri.jmrit.display.CircuitBuilder", true);

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));

    contentPane.add(Box.createVerticalStrut(STRUT_SIZE));
    contentPane.add(makeContentPanel());
    contentPane.add(Box.createVerticalStrut(STRUT_SIZE));

    JPanel border = new JPanel();
    border.setLayout(new java.awt.BorderLayout(10, 10));
    border.add(contentPane);
    setContentPane(border);
    _pathList.setPreferredSize(
        new java.awt.Dimension(_pathList.getFixedCellWidth(), _pathList.getFixedCellHeight() * 4));
    pack();
    if (_firstInstance) {
      setLocationRelativeTo(_parent._editor);
      _firstInstance = false;
    } else {
      setLocation(_loc);
      setSize(_dim);
    }
    setVisible(true);
  }