001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.samples.daytrader.client; 018 019 import java.awt.*; 020 import javax.swing.*; 021 import javax.swing.table.*; 022 import java.text.*; 023 import java.math.BigDecimal; 024 025 public class AuditRenderer extends DefaultTableCellRenderer { 026 private NumberFormat nf = NumberFormat.getCurrencyInstance(); 027 028 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 029 super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 030 if (value instanceof AuditModel) { 031 AuditModel am = (AuditModel)value; 032 // TODO: Terrible abuse of Swing and Models - fix this 033 TradeStreamerQuoteDataBean quote = TradeClient.getTradeClient().getAuditStats().getSymbol(row); 034 switch (am.getType()) { 035 case AuditModel.PRICE: { 036 BigDecimal aPrice = am.getAuditPrice(); 037 setText(nf.format(aPrice)); 038 if (aPrice.compareTo(quote.getPrice()) != 0) { 039 setForeground(Color.red); 040 setFont(table.getFont().deriveFont(Font.BOLD)); 041 } 042 else { 043 setForeground(table.getForeground()); 044 setFont(table.getFont()); 045 } 046 break; 047 } 048 case AuditModel.VOLUME: { 049 double aVolume = am.getAuditVolume(); 050 setText(String.valueOf(aVolume)); 051 if (aVolume != quote.getVolume()) { 052 setForeground(Color.red); 053 setFont(table.getFont().deriveFont(Font.BOLD)); 054 } 055 else { 056 setForeground(table.getForeground()); 057 setFont(table.getFont()); 058 } 059 break; 060 } 061 default: { 062 System.out.println("should not be reached"); 063 } 064 } 065 } 066 return this; 067 } 068 } 069 070