Example #1
0
  /** Constructor. */
  public TilePatternsView() {
    super();

    tilePatternIcons = new ArrayList<TilePatternIcon>();

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    // tileset properties
    // the tile pattern list
    // view of the current tile pattern

    // tileset properties
    tilesetPropertiesView = new TilesetPropertiesView();
    tilesetPropertiesView.setMaximumSize(new Dimension(Integer.MAX_VALUE, 120));
    tilesetPropertiesView.setAlignmentX(Component.LEFT_ALIGNMENT);

    // list
    tilePatternsListModel = new TilePatternsListModel();
    tilePatternsList = new JList(tilePatternsListModel);
    tilePatternsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tilePatternsList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    tilePatternsList.setVisibleRowCount(-1); // make the rows as wide as possible
    tilePatternsList
        .getSelectionModel()
        .addListSelectionListener(new TilePatternListSelectionListener());
    tilePatternsList.setCellRenderer(new TilePatternListRenderer());

    tilePatternsList.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_DELETE) {
              if (tileset != null && tileset.getSelectedTilePattern() != null) {
                tileset.removeTilePattern();
              }
            }
          }
        });

    JScrollPane listScroller = new JScrollPane(tilePatternsList);
    listScroller.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    listScroller.setAlignmentX(Component.LEFT_ALIGNMENT);

    // tile view
    tilePatternView = new TilePatternView();
    tilePatternView.setMaximumSize(new Dimension(Integer.MAX_VALUE, 300));
    tilePatternView.setAlignmentX(Component.LEFT_ALIGNMENT);

    add(tilesetPropertiesView);
    add(Box.createRigidArea(new Dimension(0, 5)));
    add(listScroller);
    add(Box.createRigidArea(new Dimension(0, 5)));
    add(tilePatternView);
  }
Example #2
0
  /**
   * Sets the tileset observed.
   *
   * @param tileset the current tileset, or null if there is no tileset
   */
  public void setTileset(Tileset tileset) {

    if (tileset != this.tileset) {

      if (this.tileset != null) {
        this.tileset.deleteObserver(tilePatternsListModel);
      }

      this.tileset = tileset;
      tilesetPropertiesView.setTileset(tileset);
      tilePatternView.setTileset(tileset);

      if (tileset != null) {
        tileset.addObserver(tilePatternsListModel);

        loadIcons();
        tilePatternsListModel.update(tileset, null);
      } else {
        repaint();
      }
    }
  }