home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / table / TableColumn.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  4.9 KB  |  229 lines

  1. package com.sun.java.swing.table;
  2.  
  3. import com.sun.java.swing.BorderFactory;
  4. import com.sun.java.swing.JComponent;
  5. import com.sun.java.swing.JLabel;
  6. import com.sun.java.swing.JTable;
  7. import java.awt.Component;
  8. import java.beans.PropertyChangeListener;
  9. import java.beans.PropertyChangeSupport;
  10. import java.io.Serializable;
  11.  
  12. public class TableColumn implements Serializable {
  13.    public static final String COLUMN_WIDTH_PROPERTY = "columWidth";
  14.    public static final String HEADER_VALUE_PROPERTY = "headerValue";
  15.    public static final String HEADER_RENDERER_PROPERTY = "headerRenderer";
  16.    public static final String CELL_RENDERER_PROPERTY = "cellRenderer";
  17.    protected int modelIndex;
  18.    protected Object identifier;
  19.    protected int width;
  20.    protected int minWidth;
  21.    protected int maxWidth;
  22.    protected TableCellRenderer headerRenderer;
  23.    protected Object headerValue;
  24.    protected TableCellRenderer cellRenderer;
  25.    protected TableCellEditor cellEditor;
  26.    protected boolean isResizable;
  27.    protected transient int resizedPostingDisableCount;
  28.    private PropertyChangeSupport changeSupport;
  29.  
  30.    public TableColumn() {
  31.       this(0);
  32.    }
  33.  
  34.    public TableColumn(int var1) {
  35.       this(var1, 75, (TableCellRenderer)null, (TableCellEditor)null);
  36.    }
  37.  
  38.    public TableColumn(int var1, int var2) {
  39.       this(var1, var2, (TableCellRenderer)null, (TableCellEditor)null);
  40.    }
  41.  
  42.    public TableColumn(int var1, int var2, TableCellRenderer var3, TableCellEditor var4) {
  43.       this.modelIndex = var1;
  44.       this.width = var2;
  45.       this.cellRenderer = var3;
  46.       this.cellEditor = var4;
  47.       this.minWidth = 15;
  48.       this.maxWidth = Integer.MAX_VALUE;
  49.       this.isResizable = true;
  50.       this.resizedPostingDisableCount = 0;
  51.       this.setHeaderRenderer(this.createDefaultHeaderRenderer());
  52.       this.headerValue = null;
  53.    }
  54.  
  55.    public void setModelIndex(int var1) {
  56.       this.modelIndex = var1;
  57.    }
  58.  
  59.    public int getModelIndex() {
  60.       return this.modelIndex;
  61.    }
  62.  
  63.    public void setIdentifier(Object var1) {
  64.       this.identifier = var1;
  65.    }
  66.  
  67.    public Object getIdentifier() {
  68.       return this.identifier != null ? this.identifier : this.getHeaderValue();
  69.    }
  70.  
  71.    public void setHeaderRenderer(TableCellRenderer var1) {
  72.       TableCellRenderer var2 = this.headerRenderer;
  73.       if (var1 == null) {
  74.          throw new IllegalArgumentException("Object is null");
  75.       } else {
  76.          this.headerRenderer = var1;
  77.          if (this.changeSupport != null) {
  78.             this.changeSupport.firePropertyChange("headerRenderer", var2, this.headerRenderer);
  79.          }
  80.  
  81.       }
  82.    }
  83.  
  84.    public TableCellRenderer getHeaderRenderer() {
  85.       return this.headerRenderer;
  86.    }
  87.  
  88.    public void setHeaderValue(Object var1) {
  89.       Object var2 = this.headerValue;
  90.       this.headerValue = var1;
  91.       if (this.changeSupport != null) {
  92.          this.changeSupport.firePropertyChange("headerValue", var2, this.headerValue);
  93.       }
  94.  
  95.    }
  96.  
  97.    public Object getHeaderValue() {
  98.       return this.headerValue;
  99.    }
  100.  
  101.    public void setCellRenderer(TableCellRenderer var1) {
  102.       TableCellRenderer var2 = this.cellRenderer;
  103.       this.cellRenderer = var1;
  104.       if (this.changeSupport != null) {
  105.          this.changeSupport.firePropertyChange("cellRenderer", var2, this.cellRenderer);
  106.       }
  107.  
  108.    }
  109.  
  110.    public TableCellRenderer getCellRenderer() {
  111.       return this.cellRenderer;
  112.    }
  113.  
  114.    public void setCellEditor(TableCellEditor var1) {
  115.       this.cellEditor = var1;
  116.    }
  117.  
  118.    public TableCellEditor getCellEditor() {
  119.       return this.cellEditor;
  120.    }
  121.  
  122.    public void setWidth(int var1) {
  123.       int var2 = this.width;
  124.       if (this.width != var1) {
  125.          this.width = var1;
  126.          if (this.width < this.minWidth) {
  127.             this.width = this.minWidth;
  128.          } else if (this.width > this.maxWidth) {
  129.             this.width = this.maxWidth;
  130.          }
  131.  
  132.          if (this.changeSupport != null) {
  133.             this.changeSupport.firePropertyChange("columWidth", new Integer(var2), new Integer(this.width));
  134.          }
  135.  
  136.       }
  137.    }
  138.  
  139.    public int getWidth() {
  140.       return this.width;
  141.    }
  142.  
  143.    public void setMinWidth(int var1) {
  144.       this.minWidth = var1;
  145.       if (this.minWidth < 0) {
  146.          this.minWidth = 0;
  147.       }
  148.  
  149.       if (this.width < this.minWidth) {
  150.          this.setWidth(this.minWidth);
  151.       }
  152.  
  153.    }
  154.  
  155.    public int getMinWidth() {
  156.       return this.minWidth;
  157.    }
  158.  
  159.    public void setMaxWidth(int var1) {
  160.       this.maxWidth = var1;
  161.       if (this.maxWidth < 0) {
  162.          this.maxWidth = 0;
  163.       } else if (this.maxWidth < this.minWidth) {
  164.          this.maxWidth = this.minWidth;
  165.       }
  166.  
  167.       if (this.width > this.maxWidth) {
  168.          this.setWidth(this.maxWidth);
  169.       }
  170.  
  171.    }
  172.  
  173.    public int getMaxWidth() {
  174.       return this.maxWidth;
  175.    }
  176.  
  177.    public void setResizable(boolean var1) {
  178.       this.isResizable = var1;
  179.    }
  180.  
  181.    public boolean getResizable() {
  182.       return this.isResizable;
  183.    }
  184.  
  185.    public void sizeWidthToFit() {
  186.       Component var1 = this.getHeaderRenderer().getTableCellRendererComponent((JTable)null, this.getHeaderValue(), false, false, 0, 0);
  187.       int var2 = var1.getPreferredSize().width;
  188.       if (var2 > this.getMaxWidth()) {
  189.          this.setMaxWidth(var2);
  190.       }
  191.  
  192.       if (var2 < this.getMinWidth()) {
  193.          this.setMinWidth(var2);
  194.       }
  195.  
  196.       this.setWidth(var2);
  197.    }
  198.  
  199.    public void disableResizedPosting() {
  200.       ++this.resizedPostingDisableCount;
  201.    }
  202.  
  203.    public void enableResizedPosting() {
  204.       --this.resizedPostingDisableCount;
  205.    }
  206.  
  207.    public synchronized void addPropertyChangeListener(PropertyChangeListener var1) {
  208.       if (this.changeSupport == null) {
  209.          this.changeSupport = new PropertyChangeSupport(this);
  210.       }
  211.  
  212.       this.changeSupport.addPropertyChangeListener(var1);
  213.    }
  214.  
  215.    public synchronized void removePropertyChangeListener(PropertyChangeListener var1) {
  216.       if (this.changeSupport != null) {
  217.          this.changeSupport.removePropertyChangeListener(var1);
  218.       }
  219.  
  220.    }
  221.  
  222.    protected TableCellRenderer createDefaultHeaderRenderer() {
  223.       1 var1 = new 1();
  224.       ((JLabel)var1).setHorizontalAlignment(0);
  225.       ((JComponent)var1).setBorder(BorderFactory.createRaisedBevelBorder());
  226.       return var1;
  227.    }
  228. }
  229.