home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 24.0 KB | 736 lines |
- /*
- * Copyright (c) 1997 Krumel & Associates, Inc. All Rights Reserved.
- *
- * www.krumel.com - controls@krumel.com
- *
- * Permission is given to the buyer of this package for one software
- * developer to use this software on one CPU (one workstation) and to make
- * one backup copy. You may uitilize and/or modify this class for use in your
- * projects. You may distribute or sell any executable which results from
- * using this code in yur application, except a utility or class of similar
- * nature to this product. You may distribute this product in compiled
- * form only, but soley to be used with your cmpiled executable product
- * for the puposes of dynamic loading. You may NOT redistribute the source
- * code in any form or make it accessible through a network or other
- * distribution media to others. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * The source code is the confidential and proprietary information
- * of Krumel & Associates, Inc. ("Confidential Information"). You shall
- * not disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Krumel & Associates, Inc..
-
- * KRUMEL & ASSOCIATES MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
- * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. KRUMEL & ASSOCIATES SHALL NOT
- * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
- * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
- package symantec.itools.db.awt;
-
- import java.awt.*;
-
- /**
- * CellHints specify the way a grid cell will be drawn, including things like data
- * alignment within cell, font, colors, line styles, etc.
- * It may apply to one or more grid cells.
- */
- public class CellHints implements java.io.Serializable {
- Rectangle bounds = new Rectangle();
- int align;
- int valign = TableView.TOP;
- boolean editable = true;
- Font font = stdFont;
- Color fg = Color.black;
- Color bg = Color.white;
- Color hfg = Color.white;
- Color hbg = Color.blue;
- boolean highlighted = false;
- int lineTopStyle = TableView.THIN_LINE,
- lineBottomStyle = TableView.THIN_LINE,
- lineLeftStyle = TableView.THIN_LINE,
- lineRightStyle = TableView.THIN_LINE;
- Color lineTopColor = Color.gray,
- lineBottomColor = Color.gray,
- lineLeftColor = Color.gray,
- lineRightColor = Color.gray;
- TableCell defaultCell;
- int bits;
- Component control;
- Object cellStorage;
-
- /** Bit position constant for valid "alignment" value flag.
- */
- public static final int ALIGN_BIT = 0;
- /** Bit position constant for valid "vertical alignment" value flag.
- */
- public static final int VALIGN_BIT = 1;
- /** Bit position constant for valid "editable" value flag.
- */
- public static final int EDITABLE_BIT = 2;
- /** Bit position constant for valid "font" value flag.
- */
- public static final int FONT_BIT = 4;
- /** Bit position constant for valid "foreground color" value flag.
- */
- public static final int FG_BIT = 5;
- /** Bit position constant for valid "background color" value flag.
- */
- public static final int BG_BIT = 6;
- /** Bit position constant for valid "highlighted foreground color" value flag.
- */
- public static final int HFG_BIT = 7;
- /** Bit position constant for valid "highlighted background color" value flag.
- */
- public static final int HBG_BIT = 8;
- /** Bit position constant for valid "component" value flag.
- */
- public static final int CONTROL_BIT = 9;
- /** Bit position constant for valid "storage object" value flag.
- */
- public static final int OBJECT_BIT = 10;
- /** Bit position constant for valid "default table cell" value flag.
- */
- public static final int DEFAULT_BIT = 11;
- /** Bit position constant for valid "top boundry line style" value flag.
- */
- public static final int LINE_TOP_STYLE_BIT = 12;
- /** Bit position constant for valid "left boundry line style" value flag.
- */
- public static final int LINE_LEFT_STYLE_BIT = 13;
- /** Bit position constant for valid "bottom boundry line style" value flag.
- */
- public static final int LINE_BOTTOM_STYLE_BIT = 14;
- /** Bit position constant for valid "right boundry line style" value flag.
- */
- public static final int LINE_RIGHT_STYLE_BIT = 15;
- /** Bit position constant for valid "top boundry line color" value flag.
- */
- public static final int LINE_TOP_COLOR_BIT = 16;
- /** Bit position constant for valid "left boundry line color" value flag.
- */
- public static final int LINE_LEFT_COLOR_BIT = 17;
- /** Bit position constant for valid "bottom boundry line color" value flag.
- */
- public static final int LINE_BOTTOM_COLOR_BIT = 18;
- /** Bit position constant for valid "right boundry line color" value flag.
- */
- public static final int LINE_RIGHT_COLOR_BIT = 19;
-
- /** The standard cell font.
- */
- public static Font stdFont = new Font("Dialog", Font.PLAIN, 12);
- TableView view;
- TableCell cell;
-
- /**
- * Constructs a new CellHints object for cells in the given TableView.
- * @param v the TableView
- */
- public CellHints(TableView v) {
- view = v;
- }
-
- /**
- * Sets the sepecified flag bit.
- * @param bit the zero-relative bit index
- */
- public void set(int bit) {
- bits |= (1<<bit);
- }
-
- /**
- * Clears the sepecified flag bit.
- * @param bit the zero-relative bit index
- */
- public void clear(int bit) {
- bits &= ~(1L << bit);
- }
-
- /**
- * Gets the sepecified flag bit.
- * @param bit the zero-relative bit index
- * @return the value of the bit
- */
- public boolean get(int bit) {
- return ((bits >> bit) & 1) != 0;
- }
-
- /**
- * Sets the given Graphics object's clipping rectangle
- * to the value indicated by this CellHint.
- * @param g the Graphics context
- */
- public void clip(Graphics g) {
- g.clipRect(bounds.x, bounds.y, bounds.width, bounds.height);
- }
-
- /**
- * Sets the given Graphics object's foreground color
- * to the value indicated by this CellHint.
- * @param g the Graphics context
- */
- public void setForeground(Graphics g) {
- if (highlighted) {
- g.setColor(hfg);
- } else {
- g.setColor(fg);
- }
- }
-
- /**
- * Sets the given Graphics object's background color
- * to the value indicated by this CellHint.
- * @param g the Graphics context
- */
- public void setBackground(Graphics g) {
- if (highlighted) {
- g.setColor(hbg);
- } else {
- g.setColor(bg);
- }
- }
-
- /**
- * Initializes this CellHint for the given TableCell.
- * @param c the TableCell this CellHint is for
- */
- public final void setHints(TableCell c) {
- cell = c;
-
- if (cell.type() == TableCell.CORNER_CELL) {
- setCornerCellHints(c);
- return;
- }
-
- bounds = view.getCellBounds(c, bounds);
- align = view.getCellAlignment(c);
- fg = view.getCellFG(c);
- bg = view.getCellBG(c);
- editable = view.getCellEditable(c);
- highlighted = view.getCellHighlighted(c);
- font = view.getCellFont(c);
- cellStorage = view.getCellStorage(c);
- control = view.getCellControl(c);
- view.putLineStyles(cell, this);
- }
-
- void setCornerCellHints(TableCell c) {
- CellHints rowHints = view.rowHeadingHints;
-
- bounds = view.getCellBounds(c, bounds);
- align = rowHints.align;
- fg = rowHints.fg;
- bg = rowHints.bg;
- editable = rowHints.editable;
- highlighted = view.isViewSelected();
- font = rowHints.font;
- }
-
- //-------------------------------------------------------------------------
- // Line styles and line color APIs
- //-------------------------------------------------------------------------
-
- void setTopLineStyle(int style) {
- set(LINE_TOP_STYLE_BIT);
- lineTopStyle = style;
- }
-
- void clearTopLineStyle() { clear(LINE_TOP_STYLE_BIT); }
-
- void setTopLineColor(Color c) {
- set(LINE_TOP_COLOR_BIT);
- lineTopColor = c;
- }
-
- void clearTopLineColor() { clear(LINE_TOP_COLOR_BIT); }
-
- void setLeftLineStyle(int style) {
- set(LINE_LEFT_STYLE_BIT);
- lineLeftStyle = style;
- }
-
- void clearLeftLineStyle() { clear(LINE_LEFT_STYLE_BIT); }
-
- void setLeftLineColor(Color c) {
- set(LINE_LEFT_COLOR_BIT);
- lineLeftColor = c;
- }
-
- void clearLeftLineColor() { clear(LINE_BOTTOM_COLOR_BIT); }
-
- void setBottomLineStyle(int style) {
- set(LINE_BOTTOM_STYLE_BIT);
- lineBottomStyle = style;
- }
-
- void clearBottomLineStyle() { clear(LINE_BOTTOM_STYLE_BIT); }
-
- void setBottomLineColor(Color c) {
- set(LINE_BOTTOM_COLOR_BIT);
- lineBottomColor = c;
- }
-
- void clearBottomLineColor() { clear(LINE_BOTTOM_COLOR_BIT); }
-
- void setRightLineStyle(int style) {
- set(LINE_RIGHT_STYLE_BIT);
- lineRightStyle = style;
- }
-
- void clearRightLineStyle() { clear(LINE_RIGHT_STYLE_BIT); }
-
- void setRightLineColor(Color c) {
- set(LINE_RIGHT_COLOR_BIT);
- lineRightColor = c;
- }
-
- void clearRightLineColor() { clear(LINE_RIGHT_COLOR_BIT); }
-
- final void cascadeLineStyles(CellHints row, CellHints cell, CellHints col) {
- //cascade styles
- lineTopStyle = cascadeInt(LINE_TOP_STYLE_BIT, row, cell,
- row!=null ?row.lineTopStyle :-1,
- cell!=null ?cell.lineTopStyle :-1,
- col.lineTopStyle);
- lineLeftStyle = cascadeInt(LINE_LEFT_STYLE_BIT, row, cell,
- row!=null ?row.lineLeftStyle :-1,
- cell!=null ?cell.lineLeftStyle :-1,
- col.lineLeftStyle);
- lineBottomStyle = cascadeInt(LINE_BOTTOM_STYLE_BIT, row, cell,
- row!=null ?row.lineBottomStyle :-1,
- cell!=null ?cell.lineBottomStyle :-1,
- col.lineBottomStyle);
- lineRightStyle = cascadeInt(LINE_RIGHT_STYLE_BIT, row, cell,
- row!=null ?row.lineRightStyle :-1,
- cell!=null ?cell.lineRightStyle :-1,
- col.lineRightStyle);
-
- //cascade colors
- lineTopColor = cascadeColor(LINE_TOP_COLOR_BIT, row, cell,
- row!=null ?row.lineTopColor :null,
- cell!=null ?cell.lineTopColor :null,
- col.lineTopColor);
- lineLeftColor = cascadeColor(LINE_LEFT_COLOR_BIT, row, cell,
- row!=null ?row.lineLeftColor :null,
- cell!=null ?cell.lineLeftColor :null,
- col.lineLeftColor);
- lineBottomColor = cascadeColor(LINE_BOTTOM_COLOR_BIT, row, cell,
- row!=null ?row.lineBottomColor :null,
- cell!=null ?cell.lineBottomColor :null,
- col.lineBottomColor);
- lineRightColor = cascadeColor(LINE_RIGHT_COLOR_BIT, row, cell,
- row!=null ?row.lineRightColor :null,
- cell!=null ?cell.lineRightColor :null,
- col.lineRightColor);
- }
-
- final int cascadeInt(int bit, CellHints row, CellHints cell, int v1, int v2, int vme) {
- if (cell!=null && cell.get(bit)) {
- return v2;
- } else if (row!=null && row.get(bit)) {
- return v1;
- }
-
- return vme;
- }
-
- final Color cascadeColor(int bit, CellHints row, CellHints cell, Color v1, Color v2, Color vme) {
- if (cell!=null && cell.get(bit)) {
- return v2;
- } else if (row!=null && row.get(bit)) {
- return v1;
- }
-
- return vme;
- }
-
- /**
- * Draws the cell boundy indicated by this CellHint.
- * @param g the Graphics context used for drawing
- */
- public final void drawBoundary(Graphics g) {
- Rectangle r = bounds;
- if (lineTopStyle != TableView.NO_LINE) {
- g.setColor(lineTopColor);
- g.drawLine(r.x, r.y, r.x+r.width-1, r.y);
-
- if (lineTopStyle == TableView.THICK_LINE) {
- g.drawLine(r.x, r.y+1, r.x+r.width-1, r.y+1);
- }
- }
- if (lineBottomStyle != TableView.NO_LINE) {
- g.setColor(lineBottomColor);
- g.drawLine(r.x, r.y+r.height-1, r.x+r.width-1, r.y+r.height-1);
- if (lineBottomStyle == TableView.THICK_LINE) {
- g.drawLine(r.x, r.y+r.height-2, r.x+r.width-1, r.y+r.height-2);
- }
- }
-
- if (lineLeftStyle != TableView.NO_LINE) {
- g.setColor(lineLeftColor);
- g.drawLine(r.x, r.y, r.x, r.y+r.height-1);
- if (lineLeftStyle == TableView.THICK_LINE) {
- g.drawLine(r.x+1, r.y, r.x+1, r.y+r.height-1);
- }
- }
- if (lineRightStyle != TableView.NO_LINE) {
- g.setColor(lineRightColor);
- g.drawLine(r.x+r.width-1, r.y, r.x+r.width-1, r.y+r.height-1);
- if (lineRightStyle == TableView.THICK_LINE) {
- g.drawLine(r.x+r.width-2, r.y, r.x+r.width-2, r.y+r.height-1);
- }
- }
- }
-
- /**
- * Gets the cell bounds indicated by this CellHint.
- * @return the cell's bounding rectangle
- */
- public final Rectangle bounds() { return bounds; }
-
- /**
- * Gets this CellHint's "horizontal alignment" value.
- * @return the cell's alignment, one of TableView.LEFT,
- * TableView.CENTER, or TableView.RIGHT
- */
- public final int alignment() { return align; }
-
- /**
- * Gets a valid horizontal alignment value.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the cell's alignment, one of TableView.LEFT,
- * TableView.CENTER, or TableView.RIGHT
- */
- public final int cascadeAlignment(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(ALIGN_BIT)) {
- return c2.align;
- } else if (c1 != null && c1.get(ALIGN_BIT)) {
- return c1.align;
- }
-
- return align;
- }
-
- /**
- * Gets this CellHint's "editable" value.
- * @return the value
- */
- public final boolean editable() { return editable; }
-
- /**
- * Gets a valid "editable" value.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the value
- */
- public final boolean cascadeEditable(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(EDITABLE_BIT)) {
- return c2.editable;
- } else if (c1 != null && c1.get(EDITABLE_BIT)) {
- return c1.editable;
- }
-
- return editable;
- }
-
- /**
- * Gets this CellHint's "vertical alignment" value.
- * @return the cell's alignment, one of TableView.TOP,
- * TableView.CENTER, or TableView.BOTTOM
- */
- public final int vAlignment() { return valign; }
-
- /**
- * Gets a valid vertical alignment value.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the cell's alignment, one of TableView.TOP,
- * TableView.CENTER, or TableView.BOTTOM
- */
- public final int cascadeVAlignment(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(VALIGN_BIT)) {
- return c2.valign;
- } else if (c1 != null && c1.get(VALIGN_BIT)) {
- return c1.valign;
- }
-
- return valign;
- }
-
- /**
- * Gets this CellHint's "font" value.
- * @return the value
- */
- public final Font font() { return font; }
-
- /**
- * Gets a valid "font" value.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the value
- */
- public final Font cascadeFont(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(FONT_BIT)) {
- return c2.font;
- } else if (c1 != null && c1.get(FONT_BIT)) {
- return c1.font;
- }
-
- return font;
- }
-
- /**
- * Gets this CellHint's "foreground color" value.
- * @return the value
- */
- public final Color foreground() { return fg; }
-
- /**
- * Gets a valid "foreground color" value.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the value
- */
- public final Color cascadeForeground(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(FG_BIT)) {
- return c2.fg;
- } else if (c1 != null && c1.get(FG_BIT)) {
- return c1.fg;
- }
-
- return fg;
- }
-
- /**
- * Gets this CellHint's "background color" value.
- * @return the value
- */
- public final Color background() { return bg; }
-
- /**
- * Gets a valid "background color" value.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the value
- */
- public final Color cascadeBackground(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(BG_BIT)) {
- return c2.bg;
- } else if (c1 != null && c1.get(BG_BIT)) {
- return c1.bg;
- }
-
- return bg;
- }
-
- /**
- * Gets this CellHint's "highlighted" value.
- * @return <code>true</code> if highlited, <code>false</code>otherwise
- */
- public final boolean highlighted() { return highlighted; }
-
- /**
- * Gets this CellHint's "hilighted foreground color" value.
- * @return the value
- */
- public final Color hlForeground() { return hfg; }
-
- /**
- * Gets a valid "hilighted foreground color" value.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the value
- */
- public final Color cascadeHlForeground(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(HFG_BIT)) {
- return c2.hfg;
- } else if (c1 != null && c1.get(HFG_BIT)) {
- return c1.hfg;
- }
-
- return hfg;
- }
-
- /**
- * Gets this CellHint's "hilighted background color" value.
- * @return the value
- */
- public final Color hlBackground() { return hbg; }
-
- /**
- * Gets a valid "hilighted background color" value.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the value
- */
- public final Color cascadeHlBackground(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(HBG_BIT)) {
- return c2.hbg;
- } else if (c1 != null && c1.get(HBG_BIT)) {
- return c1.hbg;
- }
-
- return hbg;
- }
-
- /**
- * Gets this CellHint's "top line of boundy" color value.
- * @return the value
- */
- public final Color lineTopColor() { return lineTopColor; }
-
- /**
- * Gets this CellHint's "bottom line of boundy" color value.
- * @return the value
- */
- public final Color lineBottomColor() { return lineBottomColor; }
-
- /**
- * Gets this CellHint's "left line of boundy" color value.
- * @return the value
- */
- public final Color lineLeftColor() { return lineLeftColor; }
-
- /**
- * Gets this CellHint's "right line of boundy" color value.
- * @return the value
- */
- public final Color lineRightColor() { return lineRightColor; }
-
- /**
- * Gets this CellHint's "top line style of boundy" color value.
- * @return the value,
- * one of TableView.NO_LINE, TableView.THIN_LINE, or TableView.THICK_LINE
- */
- public final int lineTopStyle() { return lineTopStyle; }
-
- /**
- * Gets this CellHint's "bottom line style of boundy" color value.
- * @return the value,
- * one of TableView.NO_LINE, TableView.THIN_LINE, or TableView.THICK_LINE
- */
- public final int lineBottomStyle() { return lineBottomStyle; }
-
- /**
- * Gets this CellHint's "left line style of boundy" color value.
- * @return the value,
- * one of TableView.NO_LINE, TableView.THIN_LINE, or TableView.THICK_LINE
- */
- public final int lineLeftStyle() { return lineLeftStyle; }
-
- /**
- * Gets this CellHint's "right line style of boundy" color value.
- * @return the value,
- * one of TableView.NO_LINE, TableView.THIN_LINE, or TableView.THICK_LINE
- */
- public final int lineRightStyle() { return lineRightStyle; }
-
- /**
- * Gets the component in this cell.
- * @return the component
- * @see #setControl
- */
- public Object control() { return control; }
-
- /**
- * Sets the component in this cell.
- * @param c the component
- * @see #control
- */
- protected final void setControl(Component c) {
- control = c;
- if (cell != null) {
- set(CONTROL_BIT);
- } else {
- clear(CONTROL_BIT);
- }
- }
-
- /**
- * Gets a valid cell component.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the component
- */
- public Component cascadeControl(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(CONTROL_BIT)) {
- return c2.control;
- } else if (c1 != null && c1.get(CONTROL_BIT)) {
- return c1.control;
- }
-
- return control;
- }
-
- /**
- * Sets the object stored in this CellHint.
- * @param o the object
- * @see #cellStorage
- */
- protected void setCellStorage(Object o) {
- cellStorage = o;
- if (cell != null) {
- set(OBJECT_BIT);
- } else {
- clear(OBJECT_BIT);
- }
- }
-
- /**
- * Gets the object stored in this CellHint.
- * @return the object
- * @see #setCellStorage
- */
- public Object cellStorage() { return cellStorage; }
-
- /**
- * Gets a valid CellHint stored object.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the stored object
- */
- public Object cascadeStorage(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(OBJECT_BIT)) {
- return c2.cellStorage;
- } else if (c1 != null && c1.get(OBJECT_BIT)) {
- return c1.cellStorage;
- }
-
- return cellStorage;
- }
-
- /**
- * Sets the default table cell for this CellHint.
- * @param cell the default cell
- * @see #defaultCell
- */
- protected void setDefaultCell(TableCell cell) {
- defaultCell = cell;
- setControl(cell.auxControl());
-
- if (cell != null) {
- set(DEFAULT_BIT);
- } else {
- clear(DEFAULT_BIT);
- }
- }
-
- /**
- * Gets the default table cell for this CellHint.
- * @return the table cell
- * @see #setDefaultCell
- */
- public final TableCell defaultCell() { return defaultCell; }
-
- /**
- * Gets a valid CellHint default table cell.
- * This method first checks c2, then c1, and then this CellHint.
- * @return the default table cell
- */
- public final TableCell cascadeDefaultCell(CellHints c1, CellHints c2) {
- if (c2 != null && c2.get(DEFAULT_BIT)) {
- return c2.defaultCell;
- } else if (c1 != null && c1.get(DEFAULT_BIT)) {
- return c1.defaultCell;
- }
-
- return defaultCell;
- }
-
- }
-