From 84b9e8e53e1df2cc1051036a02aca2b3f8773468 Mon Sep 17 00:00:00 2001 From: fleisch Date: Sat, 1 Jul 2023 18:00:13 +0200 Subject: [PATCH] change display name of ConfidenceScore from COSMIC to Confidence (fix). --- .../instance_panel/CompoundCellRenderer.java | 242 +++++++++--------- .../bioinf/projectspace/InstanceBean.java | 2 +- 2 files changed, 123 insertions(+), 121 deletions(-) diff --git a/sirius_gui/src/main/java/de/unijena/bioinf/ms/gui/mainframe/instance_panel/CompoundCellRenderer.java b/sirius_gui/src/main/java/de/unijena/bioinf/ms/gui/mainframe/instance_panel/CompoundCellRenderer.java index 261d7851f0..9c8359e20a 100644 --- a/sirius_gui/src/main/java/de/unijena/bioinf/ms/gui/mainframe/instance_panel/CompoundCellRenderer.java +++ b/sirius_gui/src/main/java/de/unijena/bioinf/ms/gui/mainframe/instance_panel/CompoundCellRenderer.java @@ -32,135 +32,137 @@ import java.text.DecimalFormat; import java.util.stream.Stream; -public class CompoundCellRenderer extends JLabel implements ListCellRenderer{ - - 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 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 { -// 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 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); + } } \ No newline at end of file diff --git a/sirius_gui/src/main/java/de/unijena/bioinf/projectspace/InstanceBean.java b/sirius_gui/src/main/java/de/unijena/bioinf/projectspace/InstanceBean.java index 3cf332d3df..1d4fe23ecd 100644 --- a/sirius_gui/src/main/java/de/unijena/bioinf/projectspace/InstanceBean.java +++ b/sirius_gui/src/main/java/de/unijena/bioinf/projectspace/InstanceBean.java @@ -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 getMs1Spectra() {