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

📄 basictableui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* BasicTableUI.java --   Copyright (C) 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.plaf.basic;import java.awt.Color;import java.awt.Component;import java.awt.ComponentOrientation;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import javax.swing.AbstractAction;import javax.swing.ActionMap;import javax.swing.CellRendererPane;import javax.swing.DefaultListSelectionModel;import javax.swing.InputMap;import javax.swing.JComponent;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.KeyStroke;import javax.swing.ListSelectionModel;import javax.swing.LookAndFeel;import javax.swing.UIManager;import javax.swing.border.Border;import javax.swing.event.ChangeEvent;import javax.swing.event.MouseInputListener;import javax.swing.plaf.ActionMapUIResource;import javax.swing.plaf.ComponentUI;import javax.swing.plaf.InputMapUIResource;import javax.swing.plaf.TableUI;import javax.swing.table.TableCellRenderer;import javax.swing.table.TableColumn;import javax.swing.table.TableColumnModel;import javax.swing.table.TableModel;public class BasicTableUI extends TableUI{  public static ComponentUI createUI(JComponent comp)   {    return new BasicTableUI();  }  protected FocusListener focusListener;    protected KeyListener keyListener;     protected MouseInputListener	mouseInputListener;     protected CellRendererPane rendererPane;     protected JTable table;  /** The normal cell border. */  Border cellBorder;  /** The action bound to KeyStrokes. */  TableAction action;  /**   * Listens for changes to the tables properties.   */  private PropertyChangeListener propertyChangeListener;  /**   * Handles key events for the JTable. Key events should be handled through   * the InputMap/ActionMap mechanism since JDK1.3. This class is only there   * for backwards compatibility.   *    * @author Roman Kennke (kennke@aicas.com)   */  public class KeyHandler implements KeyListener  {    /**     * Receives notification that a key has been pressed and released.     *     * @param event the key event     */    public void keyTyped(KeyEvent event)    {      // Key events should be handled through the InputMap/ActionMap mechanism      // since JDK1.3. This class is only there for backwards compatibility.    }    /**     * Receives notification that a key has been pressed.     *     * @param event the key event     */    public void keyPressed(KeyEvent event)    {      // Key events should be handled through the InputMap/ActionMap mechanism      // since JDK1.3. This class is only there for backwards compatibility.    }    /**     * Receives notification that a key has been released.     *     * @param event the key event     */    public void keyReleased(KeyEvent event)    {      // Key events should be handled through the InputMap/ActionMap mechanism      // since JDK1.3. This class is only there for backwards compatibility.    }  }  public class FocusHandler implements FocusListener  {    public void focusGained(FocusEvent e)     {      // TODO: Implement this properly.    }    public void focusLost(FocusEvent e)     {      // TODO: Implement this properly.    }  }  public class MouseInputHandler implements MouseInputListener  {    Point begin, curr;    private void updateSelection(boolean controlPressed)    {      // Update the rows      int lo_row = table.rowAtPoint(begin);      int hi_row  = table.rowAtPoint(curr);      ListSelectionModel rowModel = table.getSelectionModel();      if (lo_row != -1 && hi_row != -1)        {          if (controlPressed && rowModel.getSelectionMode()               != ListSelectionModel.SINGLE_SELECTION)            rowModel.addSelectionInterval(lo_row, hi_row);          else            rowModel.setSelectionInterval(lo_row, hi_row);        }            // Update the columns      int lo_col = table.columnAtPoint(begin);      int hi_col = table.columnAtPoint(curr);      ListSelectionModel colModel = table.getColumnModel().        getSelectionModel();      if (lo_col != -1 && hi_col != -1)        {          if (controlPressed && colModel.getSelectionMode() !=               ListSelectionModel.SINGLE_SELECTION)            colModel.addSelectionInterval(lo_col, hi_col);          else            colModel.setSelectionInterval(lo_col, hi_col);        }    }    public void mouseClicked(MouseEvent e)     {      // TODO: What should be done here, if anything?    }    public void mouseDragged(MouseEvent e)     {      if (table.isEnabled())        {          curr = new Point(e.getX(), e.getY());          updateSelection(e.isControlDown());        }    }    public void mouseEntered(MouseEvent e)     {      // TODO: What should be done here, if anything?    }    public void mouseExited(MouseEvent e)     {      // TODO: What should be done here, if anything?    }    public void mouseMoved(MouseEvent e)     {      // TODO: What should be done here, if anything?    }    public void mousePressed(MouseEvent e)     {      if (table.isEnabled())        {          ListSelectionModel rowModel = table.getSelectionModel();          ListSelectionModel colModel = table.getColumnModel().getSelectionModel();          int rowLead = rowModel.getLeadSelectionIndex();          int colLead = colModel.getLeadSelectionIndex();          begin = new Point(e.getX(), e.getY());          curr = new Point(e.getX(), e.getY());          //if control is pressed and the cell is already selected, deselect it          if (e.isControlDown() && table.              isCellSelected(table.rowAtPoint(begin),table.columnAtPoint(begin)))            {                                                     table.getSelectionModel().              removeSelectionInterval(table.rowAtPoint(begin),                                       table.rowAtPoint(begin));              table.getColumnModel().getSelectionModel().              removeSelectionInterval(table.columnAtPoint(begin),                                       table.columnAtPoint(begin));            }          else            updateSelection(e.isControlDown());          // If we were editing, but the moved to another cell, stop editing          if (rowLead != rowModel.getLeadSelectionIndex() ||              colLead != colModel.getLeadSelectionIndex())            if (table.isEditing())              table.editingStopped(new ChangeEvent(e));        }    }    public void mouseReleased(MouseEvent e)     {      if (table.isEnabled())        {          begin = null;          curr = null;        }    }  }  /**   * Listens for changes to the model property of the JTable and adjusts some   * settings.   *   * @author Roman Kennke (kennke@aicas.com)   */  private class PropertyChangeHandler implements PropertyChangeListener  {    /**     * Receives notification if one of the JTable's properties changes.     *     * @param ev the property change event     */    public void propertyChange(PropertyChangeEvent ev)    {      String propName = ev.getPropertyName();      if (propName.equals("model"))        {          ListSelectionModel rowSel = table.getSelectionModel();          rowSel.clearSelection();          ListSelectionModel colSel = table.getColumnModel().getSelectionModel();          colSel.clearSelection();          TableModel model = table.getModel();          // Adjust lead and anchor selection indices of the row and column          // selection models.          if (model.getRowCount() > 0)            {              rowSel.setAnchorSelectionIndex(0);              rowSel.setLeadSelectionIndex(0);            }          else            {              rowSel.setAnchorSelectionIndex(-1);              rowSel.setLeadSelectionIndex(-1);            }          if (model.getColumnCount() > 0)            {              colSel.setAnchorSelectionIndex(0);              colSel.setLeadSelectionIndex(0);            }          else            {              colSel.setAnchorSelectionIndex(-1);              colSel.setLeadSelectionIndex(-1);            }        }    }  }  protected FocusListener createFocusListener()   {    return new FocusHandler();  }  protected MouseInputListener createMouseInputListener()   {    return new MouseInputHandler();  }

⌨️ 快捷键说明

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