Methods Summary |
---|
protected void | calculatePercentages()
double runningTotal = 0.0;
for (int i = model.getRowCount() - 1; i >= 0; i--) {
percentages[i] = 0.0;
for (int j = model.getColumnCount() - 1; j >=0; j--) {
// First try the cell as a Number object.
Object val = model.getValueAt(i,j);
if (val instanceof Number) {
percentages[i] += ((Number)val).doubleValue();
}
else if (val instanceof String) {
// oops, it wasn't numeric...
// Ok, so try it as a string
try {
percentages[i]+=Double.valueOf(val.toString()).doubleValue();
}
catch(Exception e) {
// not a numeric string...give up.
}
}
}
runningTotal += percentages[i];
}
// Make each entry a percentage of the total.
for (int i = model.getRowCount() - 1; i >= 0; i--) {
percentages[i] /= runningTotal;
}
|
protected void | createLabelsAndTips()
for (int i = model.getRowCount() - 1; i >= 0; i--) {
labels[i] = (String)model.getValueAt(i, 0);
tips[i] = formatter.format(percentages[i]);
}
|
public java.awt.Color[] | getColor() return cp.getColor();
|
public java.awt.Color | getColor(int index) return cp.getColor(index);
|
public javax.swing.table.TableModel | getModel() return model;
|
public java.awt.Color | getTextColor() return cp.getTextColor();
|
public java.awt.Font | getTextFont() return cp.getTextFont();
|
public java.lang.String | getToolTipText(java.awt.event.MouseEvent me)
if (tips != null) {
int whichTip = cp.indexOfEntryAt(me);
if (whichTip != -1) {
return tips[whichTip];
}
}
return null;
|
public void | setColor(java.awt.Color[] clist) cp.setColor(clist);
|
public void | setColor(int index, java.awt.Color c) cp.setColor(index, c);
|
public void | setModel(javax.swing.table.TableModel tm)
// get listener code correct.
if (tm != model) {
if (model != null) {
model.removeTableModelListener(this);
}
model = tm;
model.addTableModelListener(this);
updateLocalValues(true);
}
|
public void | setTextColor(java.awt.Color c) cp.setTextColor(c);
|
public void | setTextFont(java.awt.Font f) cp.setTextFont(f);
|
public void | tableChanged(javax.swing.event.TableModelEvent tme)
// Rebuild the arrays only if the structure changed.
updateLocalValues(tme.getType() != TableModelEvent.UPDATE);
|
protected void | updateLocalValues(boolean freshStart)
if (freshStart) {
int count = model.getRowCount();
if ((tips == null) || (count != tips.length)) {
percentages = new double[count];
labels = new String[count];
tips = new String[count];
}
}
calculatePercentages();
createLabelsAndTips();
// Now that everything's up-to-date, reset the chart painter with the new
// values.
cp.setValues(percentages);
cp.setLabels(labels);
// Finally, repaint the chart.
repaint();
|