@Test
  public void shouldCreateJBListWithActionCellRenderer() {
    // when
    JList popupList = popupListFactory.getPopupList();

    // then
    assertThat(popupList).isInstanceOf(JBList.class);
    assertThat(popupList.getCellRenderer()).isInstanceOf(ExpandedItemListCellRendererWrapper.class);
    assertThat(((ExpandedItemListCellRendererWrapper) popupList.getCellRenderer()).getWrappee())
        .isInstanceOf(ActionCellRenderer.class);
    assertThat(((JBList) popupList).getItemsCount()).isEqualTo(1);
  }
  private static boolean doChooseLanguageToInject(Editor editor, final Processor<String> onChosen) {
    final String[] langIds = InjectedLanguage.getAvailableLanguageIDs();
    Arrays.sort(langIds);

    final JList list = new JBList(langIds);
    list.setCellRenderer(
        new ListCellRendererWrapper<String>(list.getCellRenderer()) {
          @Override
          public void customize(
              JList list, String value, int index, boolean selected, boolean hasFocus) {
            final Language language = InjectedLanguage.findLanguageById(value);
            assert language != null;
            final FileType ft = language.getAssociatedFileType();
            setIcon(ft != null ? ft.getIcon() : EmptyIcon.ICON_16);
            setText(
                language.getDisplayName() + (ft != null ? " (" + ft.getDescription() + ")" : ""));
          }
        });
    new PopupChooserBuilder(list)
        .setItemChoosenCallback(
            new Runnable() {
              public void run() {
                final String string = (String) list.getSelectedValue();
                onChosen.process(string);
              }
            })
        .setFilteringEnabled(new Function.Self<Object, String>())
        .createPopup()
        .showInBestPositionFor(editor);
    return true;
  }
Ejemplo n.º 3
0
 @Override
 public int getListElementHeight() {
   if (cellHeight == -1) {
     cellHeight =
         groupsList
             .getCellRenderer()
             .getListCellRendererComponent(groupsList, "Test", 0, false, false)
             .getPreferredSize()
             .height;
   }
   return cellHeight;
 }
Ejemplo n.º 4
0
 private static JButton getButton(JList<String> list, Point pt, int index) {
   Component c =
       list.getCellRenderer().getListCellRendererComponent(list, "", index, false, false);
   Rectangle r = list.getCellBounds(index, index);
   c.setBounds(r);
   // c.doLayout(); //may be needed for mone LayoutManager
   pt.translate(-r.x, -r.y);
   Component b = SwingUtilities.getDeepestComponentAt(c, pt.x, pt.y);
   if (b instanceof JButton) {
     return (JButton) b;
   } else {
     return null;
   }
 }
Ejemplo n.º 5
0
 @Override
 public void mousePressed(MouseEvent e) {
   // JList list = (JList) e.getComponent();
   Point pt = e.getPoint();
   int index = list.locationToIndex(pt);
   if (index >= 0) {
     JButton button = getButton(list, pt, index);
     if (Objects.nonNull(button)) {
       ButtonsRenderer renderer = (ButtonsRenderer) list.getCellRenderer();
       renderer.pressedIndex = index;
       renderer.button = button;
       listRepaint(list, list.getCellBounds(index, index));
     }
   }
 }
  private void updateRenderers(boolean isStructure) {
    if (isStructure) {
      if (mDefaultRenderer == null) mDefaultRenderer = mList.getCellRenderer();

      ChemistryCellRenderer renderer = new ChemistryCellRenderer();
      renderer.setAlternatingRowBackground(DetailTableCellRenderer.TOGGLE_ROW_BACKGROUND);
      mList.setCellRenderer(renderer);
      mList.setFixedCellHeight(80);
    } else {
      if (mDefaultRenderer != null) {
        mList.setCellRenderer(mDefaultRenderer);
        mList.setFixedCellHeight(-1);
      }
    }
  }
Ejemplo n.º 7
0
  // PENDING JW: this isn't aware of sorting/filtering - fix!
  private static boolean pointIsInActualBounds(JList list, int index, Point point) {
    ListCellRenderer renderer = list.getCellRenderer();
    ListModel model = list.getModel();
    Object element = model.getElementAt(index);
    Component comp = renderer.getListCellRendererComponent(list, element, index, false, false);

    Dimension prefSize = comp.getPreferredSize();
    Rectangle cellBounds = list.getCellBounds(index, index);
    if (!(comp.getComponentOrientation().isLeftToRight())) {
      cellBounds.x += cellBounds.width - prefSize.width;
    }
    cellBounds.width = prefSize.width;

    return cellBounds.contains(point);
  }
  public static void selectContentDescriptor(
      final @NotNull Editor editor,
      @NotNull Collection<RunContentDescriptor> consoles,
      String selectDialogTitle,
      final Consumer<RunContentDescriptor> descriptorConsumer) {
    if (consoles.size() == 1) {
      RunContentDescriptor descriptor = consoles.iterator().next();
      descriptorConsumer.consume(descriptor);
      descriptorToFront(editor, descriptor);
    } else if (consoles.size() > 1) {
      final JList list = new JBList(consoles);
      final Icon icon = DefaultRunExecutor.getRunExecutorInstance().getIcon();
      list.setCellRenderer(
          new ListCellRendererWrapper<RunContentDescriptor>(list.getCellRenderer()) {
            @Override
            public void customize(
                final JList list,
                final RunContentDescriptor value,
                final int index,
                final boolean selected,
                final boolean hasFocus) {
              setText(value.getDisplayName());
              setIcon(icon);
            }
          });

      final PopupChooserBuilder builder = new PopupChooserBuilder(list);
      builder.setTitle(selectDialogTitle);

      builder
          .setItemChoosenCallback(
              new Runnable() {
                @Override
                public void run() {
                  final Object selectedValue = list.getSelectedValue();
                  if (selectedValue instanceof RunContentDescriptor) {
                    RunContentDescriptor descriptor = (RunContentDescriptor) selectedValue;
                    descriptorConsumer.consume(descriptor);
                    descriptorToFront(editor, descriptor);
                  }
                }
              })
          .createPopup()
          .showInBestPositionFor(editor);
    }
  }
Ejemplo n.º 9
0
  @Override
  public void mouseReleased(MouseEvent e) {
    e.consume();

    // handle marble click
    int releasedRow = table.rowAtPoint(e.getPoint());
    if (releasedRow == mousePressedRow) {
      int totalHeight = 0;
      for (int i = 0; i < releasedRow; i++) totalHeight += table.getRowHeight(i);

      int marbleTop =
          ((JPanel)
                  rowHeader
                      .getCellRenderer()
                      .getListCellRendererComponent(
                          rowHeader, (releasedRow + 1) + "", releasedRow, false, false))
              .getComponent(1)
              .getY();
      if (e.getY() > marbleTop + totalHeight - 4 && e.getY() < marbleTop + totalHeight + 16) {

        GeoCasCell clickedCell = table.getGeoCasCell(table.rowAtPoint(e.getPoint()));
        if (table.isEditing()) {
          table.stopEditing();
        }
        clickedCell.toggleTwinGeoEuclidianVisible();
      }
    }

    mousePressedRow = -1;
    // handle right click

    if (rightClick) {
      if (!rowHeader.isSelectedIndex(releasedRow)) {
        rowHeader.setSelectedIndex(releasedRow);
      }
      if (rowHeader.getSelectedIndices().length > 0) {
        RowHeaderPopupMenu popupMenu = new RowHeaderPopupMenu(rowHeader, table);
        popupMenu.show(e.getComponent(), e.getX(), e.getY());
      }
    }
  }
Ejemplo n.º 10
0
  public void setPerson(Person person) {
    personName.setText(person.fullName());
    lAge.setText("Age: " + person.ageYears());
    lBirth.setText("Born: " + Utils.formatDate(person.birthDate));
    if (person.isAlive()) lDeath.setText("Died: N/A");
    else lDeath.setText("Died: " + Utils.formatDate(person.deathDate));
    lEyeColor.setText("Eye Color: " + person.eyeColor);
    lHairColor.setText("Hair Color: " + person.hairColor);
    lHeight.setText("Height: " + person.height);
    lInt.setText("Intelligence: " + person.intelligence.geneString());
    lFriends.setText("Friends: " + person.friendships.size());

    // father.setText("");
    // mother.setText("");
    father.setListData(new Person[] {});
    mother.setListData(new Person[] {});
    Vector<Person> listValues = new Vector<Person>();
    for (Relationship rel : Relationship.values()) {
      List<Person> rels = person.relations.get(rel);
      for (Person p : rels) {
        // listValues.add(rel.name(p.gender) + ": " + p.fullName());
        if (rel == Relationship.Parent && p.gender == 'M') father.setListData(new Person[] {p});
        else if (rel == Relationship.Parent && p.gender == 'F')
          mother.setListData(new Person[] {p});

        listValues.add(p);
      }
    }

    relations.setListData(listValues);
    ((PersonRelationListRenderer) (relations.getCellRenderer())).setRelative(person);

    events = town.getEventManager().getEventsByPerson(person);
    String[] data = new String[events.length];

    for (int i = 0; i < events.length; i++) {
      data[i] = Utils.formatDate(events[i].getDate()) + ": " + events[i].getNote();
    }

    eventList.setListData(data);
  }
Ejemplo n.º 11
0
 @Override
 public void mouseMoved(MouseEvent e) {
   JList list = (JList) e.getComponent();
   Point pt = e.getPoint();
   int index = list.locationToIndex(pt);
   if (!list.getCellBounds(index, index).contains(pt)) {
     if (prevIndex >= 0) {
       Rectangle r = list.getCellBounds(prevIndex, prevIndex);
       listRepaint(list, r);
     }
     index = -1;
     prevButton = null;
     return;
   }
   if (index >= 0) {
     JButton button = getButton(list, pt, index);
     ButtonsRenderer renderer = (ButtonsRenderer) list.getCellRenderer();
     if (Objects.nonNull(button)) {
       renderer.rolloverIndex = index;
       if (!button.equals(prevButton)) {
         Rectangle r = list.getCellBounds(prevIndex, index);
         listRepaint(list, r);
       }
     } else {
       renderer.rolloverIndex = -1;
       Rectangle r = null;
       if (prevIndex == index) {
         if (prevIndex >= 0 && Objects.nonNull(prevButton)) {
           r = list.getCellBounds(prevIndex, prevIndex);
         }
       } else {
         r = list.getCellBounds(index, index);
       }
       listRepaint(list, r);
       prevIndex = -1;
     }
     prevButton = button;
   }
   prevIndex = index;
 }
Ejemplo n.º 12
0
 public ListCellRenderer getDestinationCellRenderer() {
   return destList.getCellRenderer();
 }
Ejemplo n.º 13
0
 public ListCellRenderer getSourceCellRenderer() {
   return sourceList.getCellRenderer();
 }
Ejemplo n.º 14
0
 @Override
 public void mouseExited(MouseEvent e) {
   JList list = (JList) e.getComponent();
   ButtonsRenderer renderer = (ButtonsRenderer) list.getCellRenderer();
   renderer.rolloverIndex = -1;
 }
  public InterfaceScreen() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      e.printStackTrace();
    }
    setLayout(null);
    setSize(Main.WIDTH - (Main.WIDTH - 350), Main.HEIGHT);
    int panelWidth = getWidth();
    // int panelHeight = getHeight();

    // Options
    Border defaultBorder = BorderFactory.createLineBorder(new Color(0, 75, 0), 3, true);

    String[] options = {"Change Size", "Change Tile", "Change Tool"};
    optionsList = new JList<String>(options);
    DefaultListCellRenderer renderer = (DefaultListCellRenderer) optionsList.getCellRenderer();
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
    optionsList.setBorder(defaultBorder);
    optionsList.setBounds(10, 11, panelWidth - 20, 100);
    optionsList.addListSelectionListener(
        new ListSelectionListener() {;
          public void valueChanged(ListSelectionEvent e) {
            if (optionsList.getSelectedIndex() == 0) {
              String w1 = JOptionPane.showInputDialog("Enter the width - ");
              if (w1 != null) {
                String h1 = JOptionPane.showInputDialog("Enter the height - ");
                if (h1 != null) {
                  int width = Integer.parseInt(w1);
                  int height = Integer.parseInt(h1);

                  int w = GameScreen.getLevel().width;
                  int h = GameScreen.getLevel().height;
                  GameScreen.getLevel().width = width * 32;
                  GameScreen.getLevel().height = height * 32;
                  GameScreen.undo.add(
                      new UndoEvent() {
                        public void undo() {
                          GameScreen.getLevel().width = w;
                          GameScreen.getLevel().height = h;
                        }
                      });
                }
              }
            } else if (optionsList.getSelectedIndex() == 1) {
              Object[] tiles = {"Grass", "Player Spawn", "Water", "Desert", "Stone"};
              String s =
                  (String)
                      JOptionPane.showInputDialog(
                          null, "Tiles", "Input", JOptionPane.PLAIN_MESSAGE, null, tiles, "Tile");
              if (s != null && !s.equals("Tile")) {
                switch (s) {
                  case "Grass":
                    GameScreen.getLevel().getBrush().setBrushType(TileConstants.ID_GRASS);
                    break;
                  case "Player Spawn":
                    GameScreen.getLevel().getBrush().setBrushType(TileConstants.ID_PLAYER_SPAWN);
                    break;
                  case "Water":
                    GameScreen.getLevel().getBrush().setBrushType(TileConstants.ID_WATER);
                    break;
                  case "Desert":
                    GameScreen.getLevel().getBrush().setBrushType(TileConstants.ID_DESERT);
                    break;
                  case "Stone":
                    GameScreen.getLevel().getBrush().setBrushType(TileConstants.ID_STONE);
                    break;
                }
              }
            } else if (optionsList.getSelectedIndex() == 2) {
              Object[] tools = {"Pencil", "Rectangle"};
              String tool =
                  (String)
                      JOptionPane.showInputDialog(
                          null, "Tools", "Input", JOptionPane.PLAIN_MESSAGE, null, tools, "Tool");
              if (tool != null) {
                switch (tool) {
                  case "Pencil":
                    GameScreen.getLevel().getBrush().setToolType(BrushConstants.BRUSH_PENCIL);
                    break;
                  case "Rectangle":
                    GameScreen.getLevel().getBrush().setToolType(BrushConstants.BRUSH_FLOOD);
                    break;
                }
              }
            }
            optionsList.clearSelection();
            Main.getGameScreen().requestFocus();
          }
        });

    saveButton = new JButton("Save");
    saveButton.setBounds(10, 115, panelWidth - 20, 30);
    saveButton.setBorder(defaultBorder);
    saveButton.setBackground(Color.WHITE);
    saveButton.setContentAreaFilled(false);
    saveButton.setOpaque(true);
    saveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            GameScreen.getLevel().save();
          }
        });

    loadButton = new JButton("Load");
    loadButton.setBounds(10, 149, panelWidth - 20, 30);
    loadButton.setBorder(defaultBorder);
    loadButton.setBackground(Color.WHITE);
    loadButton.setContentAreaFilled(false);
    loadButton.setOpaque(true);
    loadButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            GameScreen.getLevel().load();
          }
        });

    add(optionsList);
    add(saveButton);
    add(loadButton);
  }
Ejemplo n.º 16
0
 private int getMessageWidth(IMessage message) {
   Component renderer =
       myList.getCellRenderer().getListCellRendererComponent(myList, message, 0, false, false);
   return renderer.getPreferredSize().width;
 }