From 00ec8073218a0788e62cc2aa22de9a1a14d81952 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 29 Jun 2018 09:54:39 +0100 Subject: [PATCH 1/1] JAL-3049 working tooltip on colours column --- src/jalview/gui/FeatureSettings.java | 177 +++++++++++++++++++--------------- 1 file changed, 100 insertions(+), 77 deletions(-) diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 78c1cac..01a7310 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -24,6 +24,7 @@ import jalview.api.FeatureColourI; import jalview.api.FeatureSettingsControllerI; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; +import jalview.datamodel.features.FeatureMatcher; import jalview.datamodel.features.FeatureMatcherI; import jalview.datamodel.features.FeatureMatcherSet; import jalview.datamodel.features.FeatureMatcherSetI; @@ -92,6 +93,7 @@ import javax.swing.JSlider; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.SwingConstants; +import javax.swing.border.Border; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.table.AbstractTableModel; @@ -122,6 +124,8 @@ public class FeatureSettings extends JPanel private static final int MIN_HEIGHT = 400; + private final static String BASE_TOOLTIP = "Click to edit, right-click for menu"; + final FeatureRenderer fr; public final AlignFrame af; @@ -197,19 +201,27 @@ public class FeatureSettings extends JPanel table = new JTable() { + static final String tt = "Click to edit, right-click for menu"; // todo i18n + @Override public String getToolTipText(MouseEvent e) { String tip = null; int column = table.columnAtPoint(e.getPoint()); + int row = table.rowAtPoint(e.getPoint()); + switch (column) { case TYPE_COLUMN: tip = JvSwingUtils.wrapTooltip(true, MessageManager .getString("label.feature_settings_click_drag")); break; + case COLOUR_COLUMN: + FeatureColourI colour = (FeatureColourI) table.getValueAt(row, + column); + tip = getColorTooltip(colour); + break; case FILTER_COLUMN: - int row = table.rowAtPoint(e.getPoint()); FeatureMatcherSet o = (FeatureMatcherSet) table.getValueAt(row, column); tip = o.isEmpty() @@ -1321,6 +1333,91 @@ public class FeatureSettings extends JPanel this.add(settingsPane); } + /** + * Answers a suitable tooltip to show on the colour cell of the table + * + * @param gcol + * @return + */ + public String getColorTooltip(FeatureColourI gcol) + { + if (gcol.isSimpleColour()) + { + return BASE_TOOLTIP; + } + StringBuilder tt = new StringBuilder(); + if (gcol.isAboveThreshold()) + { + tt.append("Thresholded (Above ").append(gcol.getThreshold()) + .append(")"); + } + else if (gcol.isBelowThreshold()) + { + tt.append("Thresholded (Below ").append(gcol.getThreshold()) + .append(")"); + } + else if (gcol.isColourByLabel()) + { + tt.insert(0, "Coloured by label text "); + } + tt.append("; ").append(BASE_TOOLTIP); + return tt.toString(); + } + + public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol, + int w, int h) + { + boolean thr = false; + StringBuilder tx = new StringBuilder(); + + if (gcol.isColourByAttribute()) + { + tx.append(FeatureMatcher + .toAttributeDisplayName(gcol.getAttributeName())); + } + else if (!gcol.isColourByLabel()) + { + tx.append(MessageManager.getString("label.score")); + } + tx.append(" "); + if (gcol.isAboveThreshold()) + { + thr = true; + tx.append(">"); + } + if (gcol.isBelowThreshold()) + { + thr = true; + tx.append("<"); + } + if (gcol.isColourByLabel()) + { + if (thr) + { + tx.append(" "); + } + if (!gcol.isColourByAttribute()) + { + tx.append("Label"); + } + comp.setIcon(null); + } + else + { + Color newColor = gcol.getMaxColour(); + comp.setBackground(newColor); + // System.err.println("Width is " + w / 2); + Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr); + comp.setIcon(ficon); + // tt+="RGB value: Max (" + newColor.getRed() + ", " + // + newColor.getGreen() + ", " + newColor.getBlue() + // + ")\nMin (" + minCol.getRed() + ", " + minCol.getGreen() + // + ", " + minCol.getBlue() + ")"); + } + comp.setHorizontalAlignment(SwingConstants.CENTER); + comp.setText(tx.toString()); + } + // /////////////////////////////////////////////////////////////////////// // http://java.sun.com/docs/books/tutorial/uiswing/components/table.html // /////////////////////////////////////////////////////////////////////// @@ -1406,11 +1503,9 @@ public class FeatureSettings extends JPanel class ColorRenderer extends JLabel implements TableCellRenderer { - javax.swing.border.Border unselectedBorder = null; + Border unselectedBorder = null; - javax.swing.border.Border selectedBorder = null; - - final String baseTT = "Click to edit, right/apple click for menu."; + Border selectedBorder = null; public ColorRenderer() { @@ -1425,7 +1520,6 @@ public class FeatureSettings extends JPanel { FeatureColourI cellColour = (FeatureColourI) color; setOpaque(true); - setToolTipText(baseTT); setBackground(tbl.getBackground()); if (!cellColour.isSimpleColour()) { @@ -1532,77 +1626,6 @@ public class FeatureSettings extends JPanel renderGraduatedColor(comp, gcol, w, h); } - public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol, - int w, int h) - { - boolean thr = false; - StringBuilder tt = new StringBuilder(); - StringBuilder tx = new StringBuilder(); - - if (gcol.isColourByAttribute()) - { - tx.append(String.join(":", gcol.getAttributeName())); - } - else if (!gcol.isColourByLabel()) - { - tx.append(MessageManager.getString("label.score")); - } - tx.append(" "); - if (gcol.isAboveThreshold()) - { - thr = true; - tx.append(">"); - tt.append("Thresholded (Above ").append(gcol.getThreshold()) - .append(") "); - } - if (gcol.isBelowThreshold()) - { - thr = true; - tx.append("<"); - tt.append("Thresholded (Below ").append(gcol.getThreshold()) - .append(") "); - } - if (gcol.isColourByLabel()) - { - tt.append("Coloured by label text. ").append(tt); - if (thr) - { - tx.append(" "); - } - if (!gcol.isColourByAttribute()) - { - tx.append("Label"); - } - comp.setIcon(null); - } - else - { - Color newColor = gcol.getMaxColour(); - comp.setBackground(newColor); - // System.err.println("Width is " + w / 2); - Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr); - comp.setIcon(ficon); - // tt+="RGB value: Max (" + newColor.getRed() + ", " - // + newColor.getGreen() + ", " + newColor.getBlue() - // + ")\nMin (" + minCol.getRed() + ", " + minCol.getGreen() - // + ", " + minCol.getBlue() + ")"); - } - comp.setHorizontalAlignment(SwingConstants.CENTER); - comp.setText(tx.toString()); - if (tt.length() > 0) - { - if (comp.getToolTipText() == null) - { - comp.setToolTipText(tt.toString()); - } - else - { - comp.setToolTipText( - tt.append(" ").append(comp.getToolTipText()).toString()); - } - } - } - class ColorEditor extends AbstractCellEditor implements TableCellEditor, ActionListener { -- 1.7.10.2