Skip to content

Commit

Permalink
change display name of ConfidenceScore from COSMIC to Confidence (fix).
Browse files Browse the repository at this point in the history
  • Loading branch information
mfleisch committed Jul 1, 2023
1 parent af6280b commit 84b9e8e
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,135 +32,137 @@
import java.text.DecimalFormat;
import java.util.stream.Stream;

public class CompoundCellRenderer extends JLabel implements ListCellRenderer<InstanceBean>{

private InstanceBean ec;

private Color backColor, foreColor;

private Font valueFont, compoundFont, propertyFont, statusFont;

private Color selectedBackground, evenBackground, unevenBackground, selectedForeground;
private Color activatedForeground, deactivatedForeground, disableBackground;

private DecimalFormat numberFormat;
private ImageIcon loadingGif;

public CompoundCellRenderer(){
this.setPreferredSize(new Dimension(210,86));
initColorsAndFonts();
this.numberFormat = new DecimalFormat("#0.00");
}

public void initColorsAndFonts() {
compoundFont = Fonts.FONT_BOLD.deriveFont(13f);
propertyFont = Fonts.FONT_BOLD.deriveFont(12f);
statusFont = Fonts.FONT_BOLD.deriveFont(24f);
valueFont = Fonts.FONT.deriveFont(12f);

selectedBackground = UIManager.getColor("ComboBox:\"ComboBox.listRenderer\"[Selected].background");
selectedForeground = UIManager.getColor("ComboBox:\"ComboBox.listRenderer\"[Selected].textForeground");
evenBackground = UIManager.getColor("ComboBox:\"ComboBox.listRenderer\".background");
disableBackground = UIManager.getColor("ComboBox.background");
unevenBackground = new Color(213, 227, 238);
activatedForeground = UIManager.getColor("List.foreground");
deactivatedForeground = Color.GRAY;
}

@Override
public Component getListCellRendererComponent(
JList<? extends InstanceBean> list, InstanceBean value,
int index, boolean isSelected, boolean cellHasFocus) {
this.ec = value;
if(isSelected){
this.backColor = this.selectedBackground;
this.foreColor = this.selectedForeground;
}else{
if(index%2==0) this.backColor = this.evenBackground;
else this.backColor = this.unevenBackground;
this.foreColor = this.activatedForeground;
}

this.setToolTipText(ec.getGUIName());

return this;
}



@Override
public void paint(Graphics g){

Graphics2D g2 = (Graphics2D) g;

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

g2.setColor(this.backColor);

g2.fillRect(0, 0, (int) this.getSize().getWidth(), (int) this.getSize().getWidth());

FontMetrics compoundFm = g2.getFontMetrics(this.compoundFont);
FontMetrics propertyFm = g2.getFontMetrics(this.propertyFont);
FontMetrics valueFm = g2.getFontMetrics(this.valueFont);

g2.setColor(this.foreColor);

final int maxWidth = getWidth() - 2;
int compoundLength = compoundFm.stringWidth(ec.getGUIName()) + 4;

boolean trigger = compoundLength + 2 > maxWidth;

Paint p = g2.getPaint();

if (trigger) {
g2.setPaint(new GradientPaint(maxWidth - 18, 0, foreColor, maxWidth - 1, 0, backColor));
}

g2.drawLine(2, 17, Math.min(maxWidth - 3, 2 + compoundLength), 17);

g2.setFont(compoundFont);
g2.drawString(ec.getGUIName(), 4, 13);

if (trigger) g2.setPaint(p);
public class CompoundCellRenderer extends JLabel implements ListCellRenderer<InstanceBean> {

// int ms1No = ec.getMs1Spectra().size();
// int ms2No = ec.getMs2Spectra().size();
private InstanceBean ec;

private Color backColor, foreColor;

private Font valueFont, compoundFont, propertyFont, statusFont;

private Color selectedBackground, evenBackground, unevenBackground, selectedForeground;
private Color activatedForeground, deactivatedForeground, disableBackground;

private DecimalFormat numberFormat;
private ImageIcon loadingGif;

public CompoundCellRenderer() {
this.setPreferredSize(new Dimension(210, 86));
initColorsAndFonts();
this.numberFormat = new DecimalFormat("#0.00");
}

public void initColorsAndFonts() {
compoundFont = Fonts.FONT_BOLD.deriveFont(13f);
propertyFont = Fonts.FONT_BOLD.deriveFont(12f);
statusFont = Fonts.FONT_BOLD.deriveFont(24f);
valueFont = Fonts.FONT.deriveFont(12f);

selectedBackground = UIManager.getColor("ComboBox:\"ComboBox.listRenderer\"[Selected].background");
selectedForeground = UIManager.getColor("ComboBox:\"ComboBox.listRenderer\"[Selected].textForeground");
evenBackground = UIManager.getColor("ComboBox:\"ComboBox.listRenderer\".background");
disableBackground = UIManager.getColor("ComboBox.background");
unevenBackground = new Color(213, 227, 238);
activatedForeground = UIManager.getColor("List.foreground");
deactivatedForeground = Color.GRAY;
}

@Override
public Component getListCellRendererComponent(
JList<? extends InstanceBean> list, InstanceBean value,
int index, boolean isSelected, boolean cellHasFocus) {
this.ec = value;
if (isSelected) {
this.backColor = this.selectedBackground;
this.foreColor = this.selectedForeground;
} else {
if (index % 2 == 0) this.backColor = this.evenBackground;
else this.backColor = this.unevenBackground;
this.foreColor = this.activatedForeground;
}

this.setToolTipText(ec.getGUIName());

String ionizationProp = "Ionization";
String focMassProp = "Precursor";
String rtProp = "RT";
String confProp = "COSMIC";
return this;
}

g2.setFont(propertyFont);
g2.drawString(ionizationProp, 4, 32);
g2.drawString(focMassProp, 4, 48);
g2.drawString(rtProp, 4, 64);
g2.drawString(confProp, 4, 80);

int xPos = Stream.of(propertyFm.stringWidth(ionizationProp), propertyFm.stringWidth(focMassProp), propertyFm.stringWidth(rtProp))
.max(Integer::compareTo).get() + 15;
@Override
public void paint(Graphics g) {

String ionValue = ec.getIonization().toString();
double focD = ec.getIonMass();
String focMass = focD > 0 ? numberFormat.format(focD) + " Da" : "unknown";
String rtValue = ec.getID().getRt().map(RetentionTime::getRetentionTimeInSeconds).map(s -> s / 60)
.map(numberFormat::format).map(i -> i + " min").orElse("N/A");
Graphics2D g2 = (Graphics2D) g;

g2.setFont(valueFont);
g2.drawString(ionValue, xPos, 32);
g2.drawString(focMass, xPos, 48);
g2.drawString(rtValue, xPos, 64);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

ec.getID().getConfidenceScore().ifPresent(confScore -> {
g2.setFont(propertyFont);
String conf = confScore<0|| Double.isNaN(confScore) ? ConfidenceScore.NA() : BigDecimal.valueOf(confScore).setScale(3, RoundingMode.HALF_UP).toString();
g2.drawString(conf, xPos, 80);
});
g2.setColor(this.backColor);

g2.fillRect(0, 0, (int) this.getSize().getWidth(), (int) this.getSize().getWidth());

FontMetrics compoundFm = g2.getFontMetrics(this.compoundFont);
FontMetrics propertyFm = g2.getFontMetrics(this.propertyFont);
FontMetrics valueFm = g2.getFontMetrics(this.valueFont);

g2.setColor(this.foreColor);

final int maxWidth = getWidth() - 2;
int compoundLength = compoundFm.stringWidth(ec.getGUIName()) + 4;

boolean trigger = compoundLength + 2 > maxWidth;

Paint p = g2.getPaint();

if (trigger) {
g2.setPaint(new GradientPaint(maxWidth - 18, 0, foreColor, maxWidth - 1, 0, backColor));
}

g2.drawLine(2, 17, Math.min(maxWidth - 3, 2 + compoundLength), 17);

g2.setFont(compoundFont);
g2.drawString(ec.getGUIName(), 4, 13);

if (trigger) g2.setPaint(p);

// int ms1No = ec.getMs1Spectra().size();
// int ms2No = ec.getMs2Spectra().size();

g2.setFont(statusFont);
GuiUtils.drawListStatusElement(ec.isComputing(), g2, this);
}
String ionizationProp = "Ionization";
String focMassProp = "Precursor";
String rtProp = "RT";
String confProp = ConfidenceScore.NA(ConfidenceScore.class).shortName();

g2.setFont(propertyFont);
g2.drawString(ionizationProp, 4, 32);
g2.drawString(focMassProp, 4, 48);
g2.drawString(rtProp, 4, 64);
g2.drawString(confProp, 4, 80);

int xPos = Stream.of(
propertyFm.stringWidth(ionizationProp),
propertyFm.stringWidth(focMassProp),
propertyFm.stringWidth(rtProp),
propertyFm.stringWidth(confProp)
).max(Integer::compareTo).get() + 15;

String ionValue = ec.getIonization().toString();
double focD = ec.getIonMass();
String focMass = focD > 0 ? numberFormat.format(focD) + " Da" : "unknown";
String rtValue = ec.getID().getRt().map(RetentionTime::getRetentionTimeInSeconds).map(s -> s / 60)
.map(numberFormat::format).map(i -> i + " min").orElse("N/A");

g2.setFont(valueFont);
g2.drawString(ionValue, xPos, 32);
g2.drawString(focMass, xPos, 48);
g2.drawString(rtValue, xPos, 64);

ec.getID().getConfidenceScore().ifPresent(confScore -> {
g2.setFont(propertyFont);
String conf = confScore < 0 || Double.isNaN(confScore) ? ConfidenceScore.NA() : BigDecimal.valueOf(confScore).setScale(3, RoundingMode.HALF_UP).toString();
g2.drawString(conf, xPos, 80);
});


g2.setFont(statusFont);
GuiUtils.drawListStatusElement(ec.isComputing(), g2, this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public String getName() {
}

public String getGUIName() {
return getName() + " (" + getID().getCompoundIndex() + ")";
return getName() + " (" + getID().getFeatureId().orElse(String.valueOf(getID().getCompoundIndex())) + ")";
}

public List<SimpleSpectrum> getMs1Spectra() {
Expand Down

0 comments on commit 84b9e8e

Please sign in to comment.