Skip to content

Commit 2a4b43b

Browse files
committed
Use CommState for comm link renderer states
1 parent ffecbe7 commit 2a4b43b

File tree

6 files changed

+45
-49
lines changed

6 files changed

+45
-49
lines changed

src/us/mn/state/dot/tms/client/comm/CommCellRenderer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* IRIS -- Intelligent Roadway Information System
3-
* Copyright (C) 2008-2014 Minnesota Department of Transportation
3+
* Copyright (C) 2008-2026 Minnesota Department of Transportation
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -14,6 +14,7 @@
1414
*/
1515
package us.mn.state.dot.tms.client.comm;
1616

17+
import java.awt.Color;
1718
import java.awt.Component;
1819
import javax.swing.JLabel;
1920
import javax.swing.JTable;
@@ -32,13 +33,12 @@ public Component getTableCellRendererComponent(JTable table,
3233
Object value, boolean isSelected, boolean hasFocus,
3334
int row, int col)
3435
{
35-
JLabel lbl = (JLabel)super.getTableCellRendererComponent(table,
36-
"", isSelected, hasFocus, row, col);
37-
if (value instanceof CommState) {
38-
CommState cs = (CommState)value;
39-
lbl.setIcon(cs.icon);
40-
} else
41-
lbl.setIcon(null);
36+
JLabel lbl = (JLabel) super.getTableCellRendererComponent(
37+
table, "", isSelected, hasFocus, row, col);
38+
Color c = Color.BLACK;
39+
if (value instanceof CommState)
40+
c = ((CommState) value).color;
41+
lbl.setIcon(new ControllerIcon(c));
4242
return lbl;
4343
}
4444
}

src/us/mn/state/dot/tms/client/comm/CommLinkModel.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ static private Object getCommConfigLabel(Object value) {
7878
return value;
7979
}
8080

81+
/** Get a comm link state */
82+
static private CommState getCommState(CommLink cl) {
83+
if (cl == null || !cl.getPollEnabled())
84+
return CommState.INACTIVE;
85+
CommConfig cc = cl.getCommConfig();
86+
if (cc == null)
87+
return CommState.INACTIVE;
88+
if (cc.getPollinator())
89+
return CommState.POLLINATOR;
90+
if (cl.getConnected())
91+
return CommState.OK;
92+
else
93+
return CommState.OFFLINE;
94+
}
95+
8196
/** Create a proxy descriptor */
8297
static public ProxyDescriptor<CommLink> descriptor(Session s) {
8398
return new ProxyDescriptor<CommLink>(
@@ -132,13 +147,11 @@ public void setValueAt(CommLink cl, Object value) {
132147
cl.setPollEnabled((Boolean) value);
133148
}
134149
});
135-
cols.add(new ProxyColumn<CommLink>("comm.link.connected", 50) {
150+
cols.add(new ProxyColumn<CommLink>("comm.link.connected", 50,
151+
CommState.class)
152+
{
136153
public Object getValueAt(CommLink cl) {
137-
CommConfig cc = cl.getCommConfig();
138-
if (cc != null && cc.getPollinator())
139-
return null;
140-
else
141-
return cl.getConnected();
154+
return getCommState(cl);
142155
}
143156
protected TableCellRenderer createCellRenderer() {
144157
return new ConnectedCellRenderer();

src/us/mn/state/dot/tms/client/comm/CommListRenderer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* IRIS -- Intelligent Roadway Information System
3-
* Copyright (C) 2014-2020 Minnesota Department of Transportation
3+
* Copyright (C) 2014-2026 Minnesota Department of Transportation
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -14,6 +14,7 @@
1414
*/
1515
package us.mn.state.dot.tms.client.comm;
1616

17+
import java.awt.Color;
1718
import java.awt.Component;
1819
import javax.swing.DefaultListCellRenderer;
1920
import javax.swing.JLabel;
@@ -39,13 +40,12 @@ static private String valueText(Object value) {
3940
public Component getListCellRendererComponent(JList list, Object value,
4041
int index, boolean isSelected, boolean hasFocus)
4142
{
42-
JLabel lbl = (JLabel)super.getListCellRendererComponent(list,
43+
JLabel lbl = (JLabel) super.getListCellRendererComponent(list,
4344
valueText(value), index, isSelected, hasFocus);
44-
if (value instanceof CommState) {
45-
CommState cs = (CommState)value;
46-
lbl.setIcon(cs.icon);
47-
} else
48-
lbl.setIcon(null);
45+
Color c = Color.BLACK;
46+
if (value instanceof CommState)
47+
c = ((CommState) value).color;
48+
lbl.setIcon(new ControllerIcon(c));
4949
return lbl;
5050
}
5151
}

src/us/mn/state/dot/tms/client/comm/CommState.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* IRIS -- Intelligent Roadway Information System
3-
* Copyright (C) 2014-2025 Minnesota Department of Transportation
3+
* Copyright (C) 2014-2026 Minnesota Department of Transportation
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -28,12 +28,12 @@ public enum CommState {
2828
OFFLINE (ProxyTheme.COLOR_OFFLINE),
2929
POLLINATOR (ProxyTheme.COLOR_POLLINATOR);
3030

31-
/** Icon for the comm state */
32-
public final ControllerIcon icon;
31+
/** Color for the comm state */
32+
public final Color color;
3333

3434
/** Create a comm state */
3535
private CommState(Color c) {
36-
icon = new ControllerIcon(c);
36+
color = c;
3737
}
3838

3939
/** Get values with null as first */

src/us/mn/state/dot/tms/client/comm/ConnectedCellRenderer.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,32 @@
1414
*/
1515
package us.mn.state.dot.tms.client.comm;
1616

17+
import java.awt.Color;
1718
import java.awt.Component;
1819
import javax.swing.Icon;
1920
import javax.swing.JLabel;
2021
import javax.swing.JTable;
2122
import javax.swing.table.DefaultTableCellRenderer;
22-
import us.mn.state.dot.tms.client.proxy.ProxyTheme;
2323

2424
/**
2525
* Renderer for connected status in a table cell.
2626
*
27-
* NOTE: Null indicates the comm link is handled by `pollinator`.
28-
*
2927
* @author Douglas Lau
3028
*/
3129
public class ConnectedCellRenderer extends DefaultTableCellRenderer {
3230

33-
/** Icon for OK status */
34-
static private final Icon OK = new CommLinkIcon(
35-
ProxyTheme.COLOR_AVAILABLE);
36-
37-
/** Icon for FAIL status */
38-
static private final Icon FAIL = new CommLinkIcon(
39-
ProxyTheme.COLOR_OFFLINE);
40-
41-
/** Icon for POLLINATOR status */
42-
static private final Icon POLLINATOR = new CommLinkIcon(
43-
ProxyTheme.COLOR_POLLINATOR);
44-
4531
/** Get the renderer component */
4632
@Override
4733
public Component getTableCellRendererComponent(JTable table,
4834
Object value, boolean isSelected, boolean hasFocus,
4935
int row, int column)
5036
{
51-
JLabel label = (JLabel) super.getTableCellRendererComponent(
37+
JLabel lbl = (JLabel) super.getTableCellRendererComponent(
5238
table, "", isSelected, hasFocus, row, column);
53-
if (value == null)
54-
label.setIcon(POLLINATOR);
55-
else if (Boolean.TRUE.equals(value))
56-
label.setIcon(OK);
57-
else
58-
label.setIcon(FAIL);
59-
return label;
39+
Color c = Color.BLACK;
40+
if (value instanceof CommState)
41+
c = ((CommState) value).color;
42+
lbl.setIcon(new CommLinkIcon(c));
43+
return lbl;
6044
}
6145
}

src/us/mn/state/dot/tms/client/comm/ControllerTableModel.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
package us.mn.state.dot.tms.client.comm;
1616

17-
import java.awt.Color;
1817
import java.awt.Component;
1918
import java.util.ArrayList;
2019
import java.util.Comparator;

0 commit comments

Comments
 (0)