Skip to content

Commit

Permalink
Weighted frequency tables
Browse files Browse the repository at this point in the history
Ability to toggle "Difference view" when CKM is used
  • Loading branch information
ppdewolf committed Jul 9, 2018
1 parent 479c86f commit d9f3b30
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 22 deletions.
24 changes: 18 additions & 6 deletions src/tauargus/gui/PanelTable.form
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</Group>
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="scrollPane" pref="484" max="32767" attributes="0"/>
<Component id="scrollPane" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="panelBottomButtons" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
Expand Down Expand Up @@ -805,16 +805,19 @@
<Component id="comboBoxNrOfVertLevels" min="-2" pref="31" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="0" pref="10" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="labelDecimals" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="comboBoxDecimals" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="checkBoxOutputView" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="checkBoxThousandSeparator" min="-2" max="-2" attributes="0"/>
<Component id="checkBoxThousandSeparator" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="checkBoxCKMView" min="-2" max="-2" attributes="0"/>
<Component id="checkBoxOutputView" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
</Group>
Expand All @@ -838,6 +841,7 @@
<Component id="LabelNrOfVertLevels" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="comboBoxNrOfVertLevels" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="checkBoxThousandSeparator" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="checkBoxCKMView" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
Expand Down Expand Up @@ -970,6 +974,14 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="checkBoxThousandSeparatorActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="checkBoxCKMView">
<Properties>
<Property name="text" type="java.lang.String" value="Difference view"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="checkBoxCKMViewActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
Expand Down
82 changes: 66 additions & 16 deletions src/tauargus/gui/PanelTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,38 @@ private Color getBackgroundColor(Cell cell, Code code) {
if ((cell.response == cell.realizedLower) && (cell.response == cell.realizedUpper)) {return Color.orange;} //exact
if ( (cell.response + cell.upper) > cell.realizedUpper){return Color.getHSBColor(255,100,100);}
if ( (cell.response + cell.lower) < cell.realizedLower){return Color.getHSBColor(255,100,100);}
return getBackgroundColor(code);
return getBackgroundColor(code); // gray background depending on level in hierarchy
} else {
return getBackgroundColor(code);}
return getBackgroundColor(code); // gray background depending on level in hierarchy
}
// if (cell.status.isUnsafe() && cell.auditOk) {
// if (cell.status.isPrimaryUnsafe()) {
// return Color.red;
// } else {
// return Color.orange;
// }
} else if (tableSet.ckmProtect){
}
else {
return getBackgroundColor(code); // gray background depending on level in hierarchy
}
// else if (tableSet.ckmProtect){
// float maxColor = (float) Math.max(Math.abs(tableSet.minDiff), Math.abs(tableSet.maxDiff));
// float diff = (float) Math.abs(cell.CKMValue - cell.response);
// if (diff >= maxColor) diff = maxColor;
// int R, G, B = 255; // darkest: (85,85,255) brightest: (235,235,255)
// R = (int) (235 - (235-85)*(diff-1)/(maxColor-1));
// G = R;
// if (diff > 0){
// return(new Color(R,G,B));
// }
// return getBackgroundColor(code); // gray background depending on level in hierarchy
// } else {
// return getBackgroundColor(code); // gray background depending on level in hierarchy
// }
}

private Color getCKMBackgroundColor(Cell cell, Code code){
if (tableSet.ckmProtect){
float maxColor = (float) Math.max(Math.abs(tableSet.minDiff), Math.abs(tableSet.maxDiff));
float diff = (float) Math.abs(cell.CKMValue - cell.response);
if (diff >= maxColor) diff = maxColor;
Expand All @@ -166,12 +188,12 @@ private Color getBackgroundColor(Cell cell, Code code) {
if (diff > 0){
return(new Color(R,G,B));
}
return getBackgroundColor(code);
return getBackgroundColor(code); // gray background depending on level in hierarchy
} else {
return getBackgroundColor(code);
return getBackgroundColor(code); // gray background depending on level in hierarchy
}
}

private class ColumnHeaderRenderer extends DefaultTableCellRenderer {
final TableCellRenderer renderer;

Expand Down Expand Up @@ -252,7 +274,12 @@ public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table
}

setForeground(cell.status.getForegroundColor());
setBackground(getBackgroundColor(cell, getRowCode(rowIndex)));
if (!(checkBoxCKMView.isEnabled() && checkBoxCKMView.isSelected())){
setBackground(getBackgroundColor(cell, getRowCode(rowIndex)));
}
else{
setBackground(getCKMBackgroundColor(cell, getRowCode(rowIndex)));
}

setHorizontalAlignment(SwingConstants.RIGHT);
return this;
Expand Down Expand Up @@ -599,7 +626,9 @@ private void updateFormatters() {
}

public void updateSuppressButtons() {
int s = tableSet.suppressed; int radioSelect = 0; String hs = "";
int s = tableSet.suppressed;
int radioSelect = 0;
String hs = "";
try {
hs = SystemUtils.getApplicationDirectory(PanelTable.class).getCanonicalPath();
} catch (Exception ex) {}
Expand Down Expand Up @@ -634,7 +663,12 @@ public void updateSuppressButtons() {
}
}
}
boolean b = (s == TableSet.SUP_ROUNDING) || (s == TableSet.SUP_CTA);

boolean b = (s == TableSet.SUP_CKM || s == TableSet.SUP_NO);
checkBoxCKMView.setEnabled(b);
if (!b) checkBoxCKMView.setSelected(false);

b = (s == TableSet.SUP_ROUNDING) || (s == TableSet.SUP_CTA) || (s == TableSet.SUP_CKM);
checkBoxOutputView.setEnabled(!b);
if (b) {
checkBoxOutputView.setSelected(false);
Expand Down Expand Up @@ -860,6 +894,7 @@ private void initComponents() {
comboBoxDecimals = new javax.swing.JComboBox();
checkBoxOutputView = new javax.swing.JCheckBox();
checkBoxThousandSeparator = new javax.swing.JCheckBox();
checkBoxCKMView = new javax.swing.JCheckBox();

table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
Expand Down Expand Up @@ -1134,7 +1169,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
});

buttonUndoSuppress.setText("Undo");
buttonUndoSuppress.setActionCommand("Undo");
buttonUndoSuppress.setNextFocusableComponent(table);
buttonUndoSuppress.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Expand Down Expand Up @@ -1296,6 +1330,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

checkBoxCKMView.setText("Difference view");
checkBoxCKMView.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
checkBoxCKMViewActionPerformed(evt);
}
});

javax.swing.GroupLayout panelBottomButtonsLayout = new javax.swing.GroupLayout(panelBottomButtons);
panelBottomButtons.setLayout(panelBottomButtonsLayout);
panelBottomButtonsLayout.setHorizontalGroup(
Expand All @@ -1316,15 +1357,17 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(LabelNrOfVertLevels)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(comboBoxNrOfVertLevels, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 10, Short.MAX_VALUE)
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(panelBottomButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelBottomButtonsLayout.createSequentialGroup()
.addComponent(labelDecimals)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboBoxDecimals, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(checkBoxOutputView))
.addComponent(comboBoxDecimals, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(checkBoxThousandSeparator))
.addGap(18, 18, 18)
.addGroup(panelBottomButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(checkBoxCKMView)
.addComponent(checkBoxOutputView))
.addGap(3, 3, 3))
);
panelBottomButtonsLayout.setVerticalGroup(
Expand All @@ -1343,7 +1386,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(buttonTableSummary)
.addComponent(LabelNrOfVertLevels)
.addComponent(comboBoxNrOfVertLevels, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(checkBoxThousandSeparator))
.addComponent(checkBoxThousandSeparator)
.addComponent(checkBoxCKMView))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

Expand Down Expand Up @@ -1389,7 +1433,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
.addComponent(scrollPane)
.addGroup(layout.createSequentialGroup()
.addComponent(panelBottomButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
Expand Down Expand Up @@ -2099,6 +2143,11 @@ private void radioButtonCellKeyActionPerformed(java.awt.event.ActionEvent evt) {
updateSuppressButtons();
}//GEN-LAST:event_radioButtonCellKeyActionPerformed

private void checkBoxCKMViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBoxCKMViewActionPerformed
((AbstractTableModel)table.getModel()).fireTableDataChanged();
adjustColumnWidths();
}//GEN-LAST:event_checkBoxCKMViewActionPerformed

private void organiseSafetyButtons(CellStatus status) {
if (status.isEmpty()) {
buttonSafe.setEnabled(false);
Expand Down Expand Up @@ -2169,6 +2218,7 @@ private void organiseSafetyButtons(CellStatus status) {
private javax.swing.JButton buttonTableSummary;
private javax.swing.JButton buttonUndoSuppress;
private javax.swing.JButton buttonUnsafe;
private javax.swing.JCheckBox checkBoxCKMView;
private javax.swing.JCheckBox checkBoxInverseWeight;
private javax.swing.JCheckBox checkBoxOutputView;
private javax.swing.JCheckBox checkBoxThousandSeparator;
Expand Down

0 comments on commit d9f3b30

Please sign in to comment.