JavaDoc可重用参数值 [英] JavaDoc Reusable Parameter Values

查看:121
本文介绍了JavaDoc可重用参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我这里有这个代码,这是我对标准Swing TableModel的替代实现。我认为这是一个绝对的噩梦,我的问题是,我有很多rowIndex和columIndex参数,有没有一种方法可以在它们之间共享描述,以实现更标准化,更少手指工作的方式?谢谢!!

Alright, I have this code here which is my replacement implementation of the standard Swing TableModel. Which I think is an absolute nightmare, my question is, I have many rowIndex and columIndex parameters, is there a way I can share a description between them for a more standardized, and less finger working way? Thank You!!

package atablemodel;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

/**
 * My custom swing TableModel version 1.x will represent a complete table model
 * while version 2.x adds several methods for updating an existing table version
 * 0.x is an incomplete version
 * Completely changed everything to work with arraylist instead of array, which means
 * that ATableModel Object can now simply be updated instead of recreated
 * @author alex
 * @version 2.0
 * @see AbstractTableModel
 * @see TableModel
 */

@SuppressWarnings("serial")
public class ATableModel extends AbstractTableModel {
    private ArrayList<String> cn = new ArrayList<String>();
    private ArrayList<ArrayList<RowDataObject>> rd = new ArrayList<ArrayList<RowDataObject>>();

    /**
     * Creates my custom TableModel
     * 
     * @param columnames The names for the columns
     * @param rowdata The data for the rows
     */
    public ATableModel(String[] columnames, Object[][] rowdata) {
        for (int i = 0; i < columnames.length; i++) {
            cn.add(columnames[i]);
        }
        for (int i = 0; i < rowdata.length; i++) {
            ArrayList<RowDataObject> rdot1 = new ArrayList<RowDataObject>();
            for (int i2 = 0; i2 < rowdata[i].length; i2++) {
                rdot1.add(new RowDataObject(rowdata[i][i2]));
            }
            rd.add(rdot1);
        }

    }

    /**
     * Looks up the column name for the specified column
     * 
     * @param column The number of the column to look up
     * @return The name (string) of the column
     */
    public String getColumnName(int column) {
        return cn.get(column);
    }

    /**
     * This method will simply tell you if a cell is editable
     * This is only here because it is in the Default TableModel
     * @deprecated use {@link #getCellEditable(int, int)} instead
     * @param columnIndex The column
     * @param rowIndex The row
     * @return A boolean indicating if the cell is editable or not
     */
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return getCellEditable(rowIndex, columnIndex);
    }

    /**
     * Sets the value at a certain cell; <b>TAKE NOTE!:</b> this set the cell to
     * editable before changing the value, and returns it to either uneditable,
     * or editable depending on what the cell was before in {@link #rde}
     * 
     * @param aValue The value to set
     * @param rowIndex The row
     * @param columnIndex The column
     */
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        boolean editable = getRDO(rowIndex, columnIndex).getEditable();
        getRDO(rowIndex, columnIndex).setEditable(true);
        getRDO(rowIndex, columnIndex).setData(aValue);
        getRDO(rowIndex, columnIndex).setEditable(editable);
    }

    /**
     * gets the number of columns; returns the length of columnnames, so if your
     * rowdata and columnnames don't match up, it might not give you the info
     * you want
     * 
     * @return Number of columns
     */

    public int getColumnCount() {
        return cn.size();
    }

    /**
     * gets the number of rows
     * 
     * @return number of rows
     */
    public int getRowCount() {
        return rd.size();
    }

    /**
     * gets the value for a specified cell
     * 
     * @param rowIndex The row
     * @param columnIndex The column
     * @return the value (if any) at the specified cell
     */
    public Object getValueAt(int rowIndex, int columnIndex) {
        return getRDO(rowIndex, columnIndex).getData();
        /* getValueAt(0, 3); returns d */
    }

    /**
     * do not use, useless unless absolutely necessary for some reason
     * 
     * @deprecated
     */
    public TableModel returnTableModel() {
        return this;
    }

    /**
     * gets a boolean indicating if the cell is editable or not
     * 
     * @param rowIndex The row
     * @param columnIndex The column
     * @return A boolean indicating whether the cell is editable
     */
    public boolean getCellEditable(int rowIndex, int columnIndex) {
        return getRDO(rowIndex, columnIndex).getEditable();
    }

    /**
     * sets all cells editable
     * 
     * @param rowIndex The row
     * @param columnIndex The column
     * @param editable set all cells to this value
     */
    public void setCellEditable(int rowIndex, int columnIndex, boolean editable) {
        getRDO(rowIndex, columnIndex).setEditable(editable);
    }

    /**
     * Sets all cells in the current rowdata to {@code editable}
     * 
     * @param editable What to set all of the cells editable values to
     */

    public void setAllCellsEditable(boolean editable) {
        int x, y;
        for (x = 0; x < rd.size(); x++) {
            for (y = 0; y < rd.get(x).size(); y++) {
                getRDO(x, y).setEditable(editable);
            }
        }
    }

    /**
     * Set all the cells of a single row to editable or not
     * 
     * @param rowIndex The row to set editable
     * @param editable what to set the cells editable values to
     */
    public void setRowEditable(int rowIndex, boolean editable) {
        for (RowDataObject rdo : getRDORow(rowIndex)) {
            rdo.setEditable(editable);
        }
    }

    /**
     * Set all the cells in one column to editable
     * 
     * @param columnIndex The column to set editable
     * @param editable what to set all the cells editable values to
     */
    public void setColumnEditable(int columnIndex, boolean editable) {
        for (RowDataObject rdo : getRDOCol(columnIndex)) {
            rdo.setEditable(editable);
        }
    }

    public RowDataObject getRDO(int rowIndex, int columnIndex) {
        return rd.get(rowIndex).get(columnIndex);
    }

    public ArrayList<RowDataObject> getRDORow(int rowIndex) {
        //ArrayList<RowDataObject> rdor;
        /*for (int i = 0; i < rd.get(rowIndex).size(); i++) {

        }*/
        return rd.get(rowIndex);
    }

    public ArrayList<RowDataObject> getRDOCol(int columnIndex) {
        ArrayList<RowDataObject> rdoc = new ArrayList<RowDataObject>();
        for (int i = 0; i < rd.size(); i++) {
            rdoc.add(rd.get(i).get(columnIndex));
        }

        return rdoc;        
    }

}

/*
 * rd[2][5] 0 1 2 3 4 0 {a b c d e} 1 {f g h i j}
 * 
 * {a b c d e}, {f g h i j}
 */


推荐答案

不可能没有


  • 修补标准doclet(或替换你自己的doclet)

  • 修补Javadoc核心

  • 在将源代码提供给JavaDoc之前预处理源代码

  • 后处理HTML输出在运行Javadoc之后。

  • patching the standard doclet (or substituting your own one)
  • patching the Javadoc core
  • preprocessing the source code before giving it to JavaDoc
  • postprocessing the HTML output after running Javadoc.

这篇关于JavaDoc可重用参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆