001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.glm.execution.eg;
027:
028: import javax.swing.table.AbstractTableModel;
029: import javax.swing.JLabel;
030:
031: /**
032: * Augment the standard TableModel interface to include column layout info.
033: **/
034: public abstract class EGTableModelBase extends AbstractTableModel {
035: public static int SEND_WIDTH;
036: public static int DATE_WIDTH;
037: public static int STEP_WIDTH;
038: public static int ITEM_WIDTH;
039: public static int CONSUMER_WIDTH;
040: public static int QUANTITY_WIDTH;
041: public static int CLUSTER_WIDTH;
042:
043: static {
044: SEND_WIDTH = getCellWidth("Send");
045: DATE_WIDTH = getCellWidth("12/12/2000 23:59 (MMM)");
046: STEP_WIDTH = getCellWidth("MONTHLY");
047: CONSUMER_WIDTH = getCellWidth("M1A1 120 MM Tank Combat Full TrackXXX");
048: ITEM_WIDTH = getCellWidth("NSN/XXXXXXXXXXXXX");
049: QUANTITY_WIDTH = getNumericCellWidth("10,000,000.000");
050: CLUSTER_WIDTH = getCellWidth("XXXXXXXXXXXXXXX");
051: setWidths();
052: }
053:
054: public static int getCellWidth(String s) {
055: JLabel label = new JLabel(s);
056: label.setFont(ReportManagerGUI.getFirstFont());
057: return label.getPreferredSize().width;
058: }
059:
060: public static int getNumericCellWidth(String s) {
061: JLabel label = new JLabel(s);
062: label.setFont(ReportManagerGUI.getFirstNumberFont());
063: return label.getPreferredSize().width;
064: }
065:
066: public static void setWidths() {
067: }
068:
069: /**
070: * Default implementation of compareRowsByColumn compares class
071: * names if the objects have different classes. Otherwise uses
072: * compareTo if both are Comparable. Otherwise, compares the
073: * toString values of the objects.
074: **/
075: public int compareRowsByColumn(int row1, int row2, int column) {
076: Object o1 = getValueAt(row1, column);
077: Object o2 = getValueAt(row2, column);
078: if (o1 == null) {
079: if (o2 == null)
080: return 0;
081: return -1;
082: } else if (o2 == null) {
083: return 1;
084: }
085: if (o1.getClass() != o2.getClass()) {
086: return o1.getClass().getName().compareTo(
087: o2.getClass().getName());
088: }
089: if (o1 instanceof Comparable) {
090: return ((Comparable) o1).compareTo(o2);
091: }
092: return o1.toString().compareTo(o2.toString());
093: }
094:
095: public String getToolTipText(int row, int col) {
096: return null;
097: }
098:
099: public boolean cellIsMarked(int row, int col) {
100: return false;
101: }
102:
103: public void cellSelectionChanged(int row, int col) {
104: }
105:
106: public boolean cellIsFirst(int row, int col) {
107: if (row == 0)
108: return true;
109: Object this Value = getValueAt(row, col);
110: if (this Value == null)
111: return true;
112: Object prevValue = getValueAt(row - 1, col);
113: if (prevValue == null)
114: return true;
115: return !thisValue.equals(prevValue);
116: }
117: }
|