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

📄 jxtable.java

📁 java实现浏览器等本地桌面的功能
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * $Id: JXTable.java,v 1.79 2005/10/12 13:57:01 kleopatra Exp $ * * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, * Santa Clara, California 95054, U.S.A. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */package org.jdesktop.swingx;import java.awt.Component;import java.awt.ComponentOrientation;import java.awt.Container;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.print.PrinterException;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.lang.reflect.Field;import java.text.DateFormat;import java.text.NumberFormat;import java.util.Collections;import java.util.Date;import java.util.Enumeration;import java.util.HashMap;import java.util.Hashtable;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Vector;import java.util.regex.Matcher;import java.util.regex.Pattern;import javax.swing.AbstractButton;import javax.swing.Action;import javax.swing.ActionMap;import javax.swing.DefaultCellEditor;import javax.swing.Icon;import javax.swing.ImageIcon;import javax.swing.JCheckBox;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JViewport;import javax.swing.KeyStroke;import javax.swing.ListCellRenderer;import javax.swing.ListSelectionModel;import javax.swing.ScrollPaneConstants;import javax.swing.SizeSequence;import javax.swing.UIDefaults;import javax.swing.UIManager;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.event.ListSelectionEvent;import javax.swing.event.TableColumnModelEvent;import javax.swing.event.TableModelEvent;import javax.swing.table.DefaultTableCellRenderer;import javax.swing.table.JTableHeader;import javax.swing.table.TableCellEditor;import javax.swing.table.TableCellRenderer;import javax.swing.table.TableColumn;import javax.swing.table.TableColumnModel;import javax.swing.table.TableModel;import org.jdesktop.swingx.action.BoundAction;import org.jdesktop.swingx.decorator.ComponentAdapter;import org.jdesktop.swingx.decorator.FilterPipeline;import org.jdesktop.swingx.decorator.Highlighter;import org.jdesktop.swingx.decorator.HighlighterPipeline;import org.jdesktop.swingx.decorator.PatternHighlighter;import org.jdesktop.swingx.decorator.PipelineEvent;import org.jdesktop.swingx.decorator.PipelineListener;import org.jdesktop.swingx.decorator.RowSizing;import org.jdesktop.swingx.decorator.SearchHighlighter;import org.jdesktop.swingx.decorator.Selection;import org.jdesktop.swingx.decorator.Sorter;import org.jdesktop.swingx.icon.ColumnControlIcon;import org.jdesktop.swingx.plaf.LookAndFeelAddons;import org.jdesktop.swingx.table.ColumnControlButton;import org.jdesktop.swingx.table.ColumnFactory;import org.jdesktop.swingx.table.DefaultTableColumnModelExt;import org.jdesktop.swingx.table.TableColumnExt;import org.jdesktop.swingx.table.TableColumnModelExt;/** * <p> * A JXTable is a JTable with built-in support for row sorting, filtering, and * highlighting, column visibility and a special popup control on the column * header for quick access to table configuration. You can instantiate a JXTable * just as you would a JTable, using a TableModel. However, a JXTable * automatically wraps TableColumns inside a TableColumnExt instance. * TableColumnExt supports visibility, sortability, and prototype values for * column sizing, none of which are available in TableColumn. You can retrieve * the TableColumnExt instance for a column using {@link #getColumnExt(Object)} * or {@link #getColumnExt(int colnumber)}. *  * <p> * A JXTable is, by default, sortable by clicking on column headers; each * subsequent click on a header reverses the order of the sort, and a sort arrow * icon is automatically drawn on the header. Sorting can be disabled using * {@link #setSortable(boolean)}. Sorting on columns is handled by a Sorter * instance which contains a Comparator used to compare values in two rows of a * column. You can replace the Comparator for a given column by using * <code>getColumnExt("column").getSorter().setComparator(customComparator)</code> *  * <p> * Columns can be hidden or shown by setting the visible property on the * TableColumnExt using {@link TableColumnExt#setVisible(boolean)}. Columns can * also be shown or hidden from the column control popup. *  * <p> * The column control popup is triggered by an icon drawn to the far right of * the column headers, above the table's scrollbar (when installed in a * JScrollPane). The popup allows the user to select which columns should be * shown or hidden, as well as to pack columns and turn on horizontal scrolling. * To show or hide the column control, use the * {@link #setColumnControlVisible(boolean show)}method. *  * <p> * Rows can be filtered from a JXTable using a Filter class and a * FilterPipeline. One assigns a FilterPipeline to the table using * {@link #setFilters(FilterPipeline)}. Filtering hides, but does not delete or * permanently remove rows from a JXTable. Filters are used to provide sorting * to the table--rows are not removed, but the table is made to believe rows in * the model are in a sorted order. *  * <p> * One can automatically highlight certain rows in a JXTable by attaching * Highlighters in the {@link #setHighlighters(HighlighterPipeline)}method. An * example would be a Highlighter that colors alternate rows in the table for * readability; AlternateRowHighlighter does this. Again, like Filters, * Highlighters can be chained together in a HighlighterPipeline to achieve more * interesting effects. *  * <p> * You can resize all columns, selected columns, or a single column using the * methods like {@link #packAll()}. Packing combines several other aspects of a * JXTable. If horizontal scrolling is enabled using * {@link #setHorizontalScrollEnabled(boolean)}, then the scrollpane will allow * the table to scroll right-left, and columns will be sized to their preferred * size. To control the preferred sizing of a column, you can provide a * prototype value for the column in the TableColumnExt using * {@link TableColumnExt#setPrototypeValue(Object)}. The prototype is used as * an indicator of the preferred size of the column. This can be useful if some * data in a given column is very long, but where the resize algorithm would * normally not pick this up. *  * <p> * Last, you can also provide searches on a JXTable using the Searchable property. *  * <p> * Keys/Actions registered with this component: *  * <ul> * <li> "find" - open an appropriate search widget for searching cell content. The *   default action registeres itself with the SearchFactory as search target. * <li> "print" - print the table * <li> {@link JXTable#HORIZONTAL_ACTION_COMMAND} - toggle the horizontal scrollbar * <li> {@link JXTable#PACKSELECTED_ACTION_COMMAND} - resize the selected column to fit the widest *  cell content  * <li> {@link JXTable#PACKALL_ACTION_COMMAND} - resize all columns to fit the widest *  cell content in each column *  * </ul> *  * <p> * Key bindings. *  * <ul> * <li> "control F" - bound to actionKey "find". * </ul> *  * <p> * Client Properties. *  * <ul> * <li> {@link JXTable#MATCH_HIGHLIGHTER} - set to Boolean.TRUE to  *  use a SearchHighlighter to mark a cell as matching. * </ul> *  * @author Ramesh Gupta * @author Amy Fowler * @author Mark Davidson * @author Jeanette Winzenburg */public class JXTable extends JTable {     /**     * Constant string for horizontal scroll actions, used in JXTable's Action     * Map.     */    public static final String HORIZONTALSCROLL_ACTION_COMMAND =         ColumnControlButton.COLUMN_CONTROL_MARKER + "horizontalScroll";    /** Constant string for packing all columns, used in JXTable's Action Map. */    public static final String PACKALL_ACTION_COMMAND =         ColumnControlButton.COLUMN_CONTROL_MARKER + "packAll";    /**     * Constant string for packing selected columns, used in JXTable's Action     * Map.     */    public static final String PACKSELECTED_ACTION_COMMAND =         ColumnControlButton.COLUMN_CONTROL_MARKER + "packSelected";    /** The prefix marker to find component related properties in the resourcebundle. */    public static final String UIPREFIX = "JXTable.";    /** key for client property to use SearchHighlighter as match marker. */    public static final String MATCH_HIGHLIGHTER = AbstractSearchable.MATCH_HIGHLIGHTER;    static {        // Hack: make sure the resource bundle is loaded        LookAndFeelAddons.getAddon();    }    /** The FilterPipeline for the table. */    protected FilterPipeline filters;    /** The HighlighterPipeline for the table. */    protected HighlighterPipeline highlighters;    /** The ComponentAdapter for model data access. */    protected ComponentAdapter dataAdapter;    /** The handler for mapping view/model coordinates of row selection. */    private Selection selection;    /** flag to indicate if table is interactively sortable. */    private boolean sortable;    /** future - enable/disable autosort on cell updates not used *///    private boolean automaticSortDisabled;    /** Listens for changes from the filters. */    private PipelineListener pipelineListener;    /** Listens for changes from the highlighters. */    private ChangeListener highlighterChangeListener;    /** the factory to use for column creation and configuration. */    private ColumnFactory columnFactory;    /** The default number of visible rows (in a ScrollPane). */    private int visibleRowCount = 18;    private RowSizing rowSizing;    private Field rowModelField;    private boolean rowHeightEnabled;    /**     * flag to indicate if the column control is visible.     */    private boolean columnControlVisible;    /**     * ScrollPane's original vertical scroll policy. If the columnControl is     * visible the policy is set to ALWAYS.     */    private int verticalScrollPolicy;    /**     * A button that allows the user to select which columns to display, and     * which to hide     */    private JComponent columnControlButton;    /**     * Mouse/Motion/Listener keeping track of mouse moved in cell coordinates.     */    private RolloverProducer rolloverProducer;    /**     * RolloverController: listens to cell over events and repaints     * entered/exited rows.     */    private LinkController linkController;    /** field to store the autoResizeMode while interactively setting      *  horizontal scrollbar to visible.     */    private int oldAutoResizeMode;    /** temporary hack: rowheight will be internally adjusted to font size      *  on instantiation and in updateUI if      *  the height has not been set explicitly by the application.     */    protected boolean isXTableRowHeightSet;    protected Searchable searchable;    /** Instantiates a JXTable with a default table model, no data. */    public JXTable() {        init();    }    /**     * Instantiates a JXTable with a specific table model.     *      * @param dm     *            The model to use.     */    public JXTable(TableModel dm) {        super(dm);        init();    }    /**     * Instantiates a JXTable with a specific table model.     *      * @param dm     *            The model to use.     */    public JXTable(TableModel dm, TableColumnModel cm) {        super(dm, cm);        init();    }    /**     * Instantiates a JXTable with a specific table model, column model, and     * selection model.     *      * @param dm     *            The table model to use.     * @param cm     *            The colomn model to use.     * @param sm     *            The list selection model to use.     */    public JXTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {        super(dm, cm, sm);        init();    }    /**     * Instantiates a JXTable for a given number of columns and rows.     *      * @param numRows     *            Count of rows to accomodate.     * @param numColumns     *            Count of columns to accomodate.     */    public JXTable(int numRows, int numColumns) {        super(numRows, numColumns);        init();    }    /**     * Instantiates a JXTable with data in a vector or rows and column names.     *      * @param rowData     *            Row data, as a Vector of Objects.     * @param columnNames     *            Column names, as a Vector of Strings.     */    public JXTable(Vector rowData, Vector columnNames) {        super(rowData, columnNames);        init();    }

⌨️ 快捷键说明

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