X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=a15a60777837c8f91957d8c325375770ad3d1077;hb=cc52d6f3b8199cb3e9eab962feeab735c5bdc310;hp=534a0886bbdd6120a5c47d09a4f680847086433b;hpb=8d0d4cb4f21a2f15d61b90b0eb764041c664c81d;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 534a088..a15a607 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; @@ -128,6 +130,8 @@ public class FeatureSettings extends JPanel private static final int MIN_HEIGHT = 400; + private final static String BASE_TOOLTIP = MessageManager.getString("label.click_to_edit"); + final FeatureRenderer fr; public final AlignFrame af; @@ -202,14 +206,20 @@ public class FeatureSettings extends JPanel { 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, true); + break; case FILTER_COLUMN: - int row = table.rowAtPoint(e.getPoint()); FeatureMatcherSet o = (FeatureMatcherSet) table.getValueAt(row, column); tip = o.isEmpty() @@ -220,17 +230,30 @@ public class FeatureSettings extends JPanel default: break; } + return tip; } + + /** + * Position the tooltip near the bottom edge of, and half way across, the + * current cell + */ + @Override + public Point getToolTipLocation(MouseEvent e) + { + Point point = e.getPoint(); + int column = table.columnAtPoint(point); + int row = table.rowAtPoint(point); + Rectangle r = getCellRect(row, column, false); + Point loc = new Point(r.x + r.width / 2, r.y + r.height - 3); + return loc; + } }; JTableHeader tableHeader = table.getTableHeader(); tableHeader.setFont(new Font("Verdana", Font.PLAIN, 12)); tableHeader.setReorderingAllowed(false); table.setFont(new Font("Verdana", Font.PLAIN, 12)); - // table.setDefaultRenderer(Color.class, new ColorRenderer()); - // table.setDefaultEditor(Color.class, new ColorEditor(this)); - // table.setDefaultEditor(FeatureColour.class, new ColorEditor(this)); table.setDefaultRenderer(FeatureColour.class, new ColorRenderer()); @@ -1280,6 +1303,90 @@ public class FeatureSettings extends JPanel this.add(settingsPane); } + /** + * Answers a suitable tooltip to show on the colour cell of the table + * + * @param fcol + * @param withHint + * if true include 'click to edit' and similar text + * @return + */ + public static String getColorTooltip(FeatureColourI fcol, + boolean withHint) + { + if (fcol == null) + { + return null; + } + if (fcol.isSimpleColour()) + { + return withHint ? BASE_TOOLTIP : null; + } + String description = fcol.getDescription(); + description = description.replaceAll("<", "<"); + description = description.replaceAll(">", ">"); + StringBuilder tt = new StringBuilder(description); + if (withHint) + { + tt.append("
").append(BASE_TOOLTIP).append("
"); + } + return JvSwingUtils.wrapTooltip(true, 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 // /////////////////////////////////////////////////////////////////////// @@ -1365,11 +1472,9 @@ public class FeatureSettings extends JPanel class ColorRenderer extends JLabel implements TableCellRenderer { - javax.swing.border.Border unselectedBorder = null; - - javax.swing.border.Border selectedBorder = null; + Border unselectedBorder = null; - final String baseTT = "Click to edit, right/apple click for menu."; + Border selectedBorder = null; public ColorRenderer() { @@ -1384,7 +1489,6 @@ public class FeatureSettings extends JPanel { FeatureColourI cellColour = (FeatureColourI) color; setOpaque(true); - setToolTipText(baseTT); setBackground(tbl.getBackground()); if (!cellColour.isSimpleColour()) { @@ -1491,77 +1595,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 { @@ -1797,7 +1830,6 @@ public class FeatureSettings extends JPanel button.setOpaque(true); button.setBackground(me.getBackground()); button.setText(currentFilter.toString()); - button.setToolTipText(currentFilter.toString()); button.setIcon(null); return button; }