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

📄 propertiestablemodel.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.Properties;import javax.swing.table.AbstractTableModel;import tiled.mapeditor.Resources;/** * @version $Id: PropertiesTableModel.java 683 2006-06-25 14:17:37Z bjorn $ */public class PropertiesTableModel extends AbstractTableModel{    private Properties properties;        private static final String[] columnNames = { Resources.getString("dialog.properties.column.name"),     												Resources.getString("dialog.properties.column.value") };    public PropertiesTableModel() {        properties = new Properties();    }    public int getRowCount() {        return properties.size() + 1;    }    public String getColumnName(int col) {        return columnNames[col];    }    public int getColumnCount() {        return columnNames.length;    }    /**     * Returns wether the given position in the table is editable. Values can     * only be edited when they have a name.     */    public boolean isCellEditable(int row, int col) {        return col == 0 || col == 1 && getValueAt(row, 0) != null;    }    public Object getValueAt(int rowIndex, int columnIndex) {        Object[] array = properties.keySet().toArray();        if (rowIndex >= 0 && rowIndex < properties.size()) {            if (columnIndex == 0) {                return array[rowIndex];            } else if (columnIndex == 1) {                return properties.get(array[rowIndex]);            }        }        return null;    }    public void setValueAt(Object value, int row, int col) {        if (row >= 0) {            if (row >= properties.size() && col == 0) {                if (((String)value).length() > 0) {                    properties.setProperty((String)value, "");                    fireTableDataChanged();                }            } else {                if (col == 1) {                    properties.setProperty(                            (String)getValueAt(row, 0), (String)value);                    fireTableCellUpdated(row, col);                } else if (col == 0) {                    String val = (String)getValueAt(row, 1);                    if (getValueAt(row, col) != null) {                        properties.remove(getValueAt(row, col));                    }                    if (((String)value).length() > 0) {                        properties.setProperty((String)value, val);                    }                    fireTableDataChanged();                }            }        }    }    public void remove(Object key) {        properties.remove(key);        fireTableDataChanged();    }    public void update(Properties props) {        properties = props;        fireTableDataChanged();    }    public Properties getProperties() {        return properties;    }}

⌨️ 快捷键说明

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