1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * ident "%Z%%M% %I% %E% SMI"
24 *
25 * Copyright (c) 1998-1999 by Sun Microsystems, Inc.
26 * All rights reserved.
27 */
28 package com.sun.dhcpmgr.ui;
29
30 import javax.swing.table.DefaultTableCellRenderer;
31 import java.util.Date;
32 import java.text.DateFormat;
33 import java.net.InetAddress;
34 import com.sun.dhcpmgr.data.IPAddress;
35
36 // Renderer for cells containing Dates, InetAddresses or IPAddresses
37 public class ExtendedCellRenderer extends DefaultTableCellRenderer {
38 private DateFormat dateFormat = DateFormat.getInstance();
39
40 protected void setValue(Object value) {
41 if (value != null) {
42 if (value instanceof Date) {
43 long t = ((Date)value).getTime();
44 if (t == 0) {
45 super.setValue(null);
46 } else if (t < 0) {
47 super.setValue(ResourceStrings.getString("never"));
48 } else {
49 super.setValue(dateFormat.format(value));
50 }
51 } else if (value instanceof InetAddress) {
52 super.setValue(((InetAddress)value).getHostAddress());
53 } else if (value instanceof IPAddress) {
54 super.setValue(((IPAddress)value).getHostAddress());
55 } else {
56 super.setValue(value);
57 }
58 } else {
59 super.setValue(value);
60 }
61 }
62 }