⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tilesettablemodel.java

📁 tiled地图编辑器是2d的,很不错的国外软件,使用起来很方便的
💻 JAVA
字号:
/* *  Tiled Map Editor, (c) 2004-2006 * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  Adam Turk <aturk@biggeruniverse.com> *  Bjorn Lindeijer <b.lindeijer@xs4all.nl> */package tiled.mapeditor.util;import java.util.Iterator;import java.util.Vector;import javax.swing.table.AbstractTableModel;import tiled.core.*;/** * @version $Id: TilesetTableModel.java 683 2006-06-25 14:17:37Z bjorn $ */public class TilesetTableModel extends AbstractTableModel{    private Map map;    //private String[] columnNames = { "Tileset name", "Usage count" };    private String[] columnNames = { "Tileset name" };    public TilesetTableModel(Map map) {        this.map = map;    }    public void setMap(Map map) {        this.map = map;        fireTableDataChanged();    }    public String getColumnName(int col) {        return columnNames[col];    }    public int getRowCount() {        if (map != null) {            return map.getTilesets().size();        } else {            return 0;        }    }    public int getColumnCount() {        return columnNames.length;    }    public Object getValueAt(int row, int col) {        Vector tilesets = map.getTilesets();        if (row >= 0 && row < tilesets.size()) {            TileSet tileset = (TileSet)tilesets.get(row);            if (col == 0) {                return tileset.getName();            } else {                return String.valueOf(checkSetUsage(tileset));            }        } else {            return null;        }    }    public boolean isCellEditable(int row, int col) {        return col == 0;    }    public void setValueAt(Object value, int row, int col) {        Vector tilesets = map.getTilesets();        if (row >= 0 && row < tilesets.size()) {            TileSet tileset = (TileSet)tilesets.get(row);            if (col == 0) {                tileset.setName(value.toString());            }            fireTableCellUpdated(row, col);        }    }    private int checkSetUsage(TileSet s) {        int used = 0;        Iterator tileIterator = s.iterator();        while (tileIterator.hasNext()) {            Tile tile = (Tile)tileIterator.next();            Iterator itr = map.getLayers();            while (itr.hasNext()) {                MapLayer ml = (MapLayer)itr.next();                if (ml instanceof TileLayer) {                    if (ml.isUsed(tile)) {                        used++;                        break;                    }                }            }        }        return used;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -