X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=3be597cf13fd4be1c0ea0c71c3a38c3ff88a72ed;hb=9feb54a4d32293b760afcdc29672fb6a880c6cbb;hp=0928ec1be0cebb24575cf652a5f4157bebfa9323;hpb=9bde0814fff97f50e3ac6165a9fb83787c37d39a;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 0928ec1..3be597c 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -84,6 +84,7 @@ import java.util.Vector; import javax.help.HelpSetException; import javax.swing.AbstractCellEditor; import javax.swing.BorderFactory; +import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.Icon; import javax.swing.JButton; @@ -122,6 +123,8 @@ public class FeatureSettings extends JPanel private static final int MIN_HEIGHT = 400; + private static final int MAX_TOOLTIP_LENGTH = 50; + DasSourceBrowser dassourceBrowser; DasSequenceFeatureFetcher dasFeatureFetcher; @@ -414,84 +417,63 @@ public class FeatureSettings extends JPanel }); men.add(dens); - if (minmax != null) + + /* + * variable colour options include colour by label, by score, + * by selected attribute text, or attribute value + */ + final JCheckBoxMenuItem mxcol = new JCheckBoxMenuItem( + MessageManager.getString("label.variable_colour")); + mxcol.setSelected(!featureColour.isSimpleColour()); + men.add(mxcol); + mxcol.addActionListener(new ActionListener() { - final float[][] typeMinMax = minmax.get(type); - /* - * final JCheckBoxMenuItem chb = new JCheckBoxMenuItem("Vary Height"); // - * this is broken at the moment and isn't that useful anyway! - * chb.setSelected(minmax.get(type) != null); chb.addActionListener(new - * ActionListener() { - * - * public void actionPerformed(ActionEvent e) { - * chb.setState(chb.getState()); if (chb.getState()) { minmax.put(type, - * null); } else { minmax.put(type, typeMinMax); } } - * - * }); - * - * men.add(chb); - */ - if (typeMinMax != null && typeMinMax[0] != null) - { - // if (table.getValueAt(row, column)); - // graduated colourschemes for those where minmax exists for the - // positional features - final JCheckBoxMenuItem mxcol = new JCheckBoxMenuItem( - "Graduated Colour"); - mxcol.setSelected(!featureColour.isSimpleColour()); - men.add(mxcol); - mxcol.addActionListener(new ActionListener() - { - JColorChooser colorChooser; + JColorChooser colorChooser; - @Override - public void actionPerformed(ActionEvent e) + @Override + public void actionPerformed(ActionEvent e) + { + if (e.getSource() == mxcol) + { + if (featureColour.isSimpleColour()) { - if (e.getSource() == mxcol) - { - if (featureColour.isSimpleColour()) - { - FeatureColourChooser fc = new FeatureColourChooser(me.fr, - type); - fc.addActionListener(this); - } - else - { - // bring up simple color chooser - colorChooser = new JColorChooser(); - JDialog dialog = JColorChooser.createDialog(me, - "Select new Colour", true, // modal - colorChooser, this, // OK button handler - null); // no CANCEL button handler - colorChooser.setColor(featureColour.getMaxColour()); - dialog.setVisible(true); - } - } - else - { - if (e.getSource() instanceof FeatureColourChooser) - { - FeatureColourChooser fc = (FeatureColourChooser) e - .getSource(); - table.setValueAt(fc.getLastColour(), selectedRow, 1); - table.validate(); - } - else - { - // probably the color chooser! - table.setValueAt(new FeatureColour(colorChooser.getColor()), - selectedRow, 1); - table.validate(); - me.updateFeatureRenderer( - ((FeatureTableModel) table.getModel()).getData(), - false); - } - } + FeatureColourChooser fc = new FeatureColourChooser(me.fr, type); + fc.addActionListener(this); } - - }); + else + { + // bring up simple color chooser + colorChooser = new JColorChooser(); + JDialog dialog = JColorChooser.createDialog(me, + "Select new Colour", true, // modal + colorChooser, this, // OK button handler + null); // no CANCEL button handler + colorChooser.setColor(featureColour.getMaxColour()); + dialog.setVisible(true); + } + } + else + { + if (e.getSource() instanceof FeatureColourChooser) + { + FeatureColourChooser fc = (FeatureColourChooser) e.getSource(); + table.setValueAt(fc.getLastColour(), selectedRow, 1); + table.validate(); + } + else + { + // probably the color chooser! + table.setValueAt(new FeatureColour(colorChooser.getColor()), + selectedRow, 1); + table.validate(); + me.updateFeatureRenderer( + ((FeatureTableModel) table.getModel()).getData(), false); + } + } } - } + + }); + JMenuItem selCols = new JMenuItem( MessageManager.getString("label.select_columns_containing")); selCols.addActionListener(new ActionListener() @@ -1379,7 +1361,8 @@ public class FeatureSettings extends JPanel /* * the panel with the filters for the selected feature type */ - JPanel filtersPanel = new JPanel(new GridLayout(0, 1)); + JPanel filtersPanel = new JPanel(); + filtersPanel.setLayout(new BoxLayout(filtersPanel, BoxLayout.Y_AXIS)); filtersPanel.setBackground(Color.white); filtersPanel.setBorder(BorderFactory .createTitledBorder(MessageManager.getString("label.filters"))); @@ -1414,7 +1397,9 @@ public class FeatureSettings extends JPanel /* * panel with filters - populated by refreshFiltersDisplay */ - chooseFiltersPanel = new JPanel(new GridLayout(0, 1)); + chooseFiltersPanel = new JPanel(); + chooseFiltersPanel.setLayout(new BoxLayout(chooseFiltersPanel, + BoxLayout.Y_AXIS)); filtersPanel.add(chooseFiltersPanel); /* @@ -1471,7 +1456,7 @@ public class FeatureSettings extends JPanel } if (!found) { - filteredFeatureChoice + filteredFeatureChoice // todo i18n .addItem("No filterable feature attributes known"); } @@ -1491,14 +1476,12 @@ public class FeatureSettings extends JPanel * clear the panel and list of filter conditions */ chooseFiltersPanel.removeAll(); - - String selectedType = (String) filteredFeatureChoice.getSelectedItem(); - filters.clear(); /* * look up attributes known for feature type */ + String selectedType = (String) filteredFeatureChoice.getSelectedItem(); List attNames = FeatureAttributes.getInstance().getAttributes( selectedType); @@ -1514,11 +1497,7 @@ public class FeatureSettings extends JPanel { orFilters.setSelected(true); } - Iterator matchers = featureFilters.getMatchers(); - while (matchers.hasNext()) - { - filters.add(matchers.next()); - } + featureFilters.getMatchers().forEach(matcher -> filters.add(matcher)); } /* @@ -1530,16 +1509,16 @@ public class FeatureSettings extends JPanel /* * render the conditions in rows, each in its own JPanel */ - int i = 0; + int filterIndex = 0; for (KeyedMatcherI filter : filters) { String key = filter.getKey(); Condition condition = filter.getMatcher() .getCondition(); String pattern = filter.getMatcher().getPattern(); - JPanel row = addFilter(key, attNames, condition, pattern, i); + JPanel row = addFilter(key, attNames, condition, pattern, filterIndex); chooseFiltersPanel.add(row); - i++; + filterIndex++; } filtersPane.validate(); @@ -1574,7 +1553,13 @@ public class FeatureSettings extends JPanel /* * inputs for attribute, condition, pattern */ - final JComboBox attCombo = new JComboBox<>(); + /* + * drop-down choice of attribute, with description as a tooltip + * if we can obtain it + */ + String featureType = (String) filteredFeatureChoice.getSelectedItem(); + final JComboBox attCombo = populateAttributesDropdown( + featureType, attNames); JComboBox condCombo = new JComboBox<>(); JTextField patternField = new JTextField(8); @@ -1605,12 +1590,6 @@ public class FeatureSettings extends JPanel } }; - /* - * drop-down choice of attribute, with description as a tooltip - * if we can obtain it - */ - String featureType = (String) filteredFeatureChoice.getSelectedItem(); - populateAttributesDropdown(attCombo, featureType, attNames); if ("".equals(attribute)) { attCombo.setSelectedItem(null); @@ -1681,57 +1660,32 @@ public class FeatureSettings extends JPanel * Where metadata is available with a description for an attribute, that is * added as a tooltip. * - * @param attCombo * @param featureType * @param attNames */ - protected void populateAttributesDropdown( - final JComboBox attCombo, String featureType, - List attNames) + protected JComboBox populateAttributesDropdown( + String featureType, List attNames) { - final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer(); - attCombo.setRenderer(renderer); - List tips = new ArrayList(); - if (attNames.isEmpty()) - { - attCombo.addItem("---"); - attCombo.setToolTipText(MessageManager - .getString("label.no_attributes_known")); - } - else + List tooltips = new ArrayList<>(); + FeatureAttributes fa = FeatureAttributes.getInstance(); + for (String attName : attNames) { - attCombo.setToolTipText(""); - FeatureAttributes fs = FeatureAttributes.getInstance(); - for (String attName : attNames) + String desc = fa.getDescription(featureType, attName); + if (desc != null && desc.length() > MAX_TOOLTIP_LENGTH) { - attCombo.addItem(attName); - String desc = fs.getDescription(featureType, attName); - tips.add(desc == null ? "" : desc); + desc = desc.substring(0, MAX_TOOLTIP_LENGTH) + "..."; } + tooltips.add(desc == null ? "" : desc); } - renderer.setTooltips(tips); - final MouseAdapter mouseListener = new MouseAdapter() - { - @Override - public void mouseEntered(MouseEvent e) - { - int j = attCombo.getSelectedIndex(); - if (j > -1) - { - attCombo.setToolTipText(tips.get(j)); - } - } - @Override - public void mouseExited(MouseEvent e) - { - attCombo.setToolTipText(null); - } - }; - for (Component c : attCombo.getComponents()) + JComboBox attCombo = JvSwingUtils.buildComboWithTooltips( + attNames, tooltips); + if (attNames.isEmpty()) { - c.addMouseListener(mouseListener); + attCombo.setToolTipText(MessageManager + .getString("label.no_attributes")); } + return attCombo; } /** @@ -2108,12 +2062,7 @@ public class FeatureSettings extends JPanel boolean isSelected, boolean hasFocus, int row, int column) { FeatureColourI cellColour = (FeatureColourI) color; - // JLabel comp = new JLabel(); - // comp. setOpaque(true); - // comp. - // setBounds(getBounds()); - Color newColor; setToolTipText(baseTT); setBackground(tbl.getBackground()); if (!cellColour.isSimpleColour()) @@ -2121,14 +2070,12 @@ public class FeatureSettings extends JPanel Rectangle cr = tbl.getCellRect(row, column, false); FeatureSettings.renderGraduatedColor(this, cellColour, (int) cr.getWidth(), (int) cr.getHeight()); - } else { this.setText(""); this.setIcon(null); - newColor = cellColour.getColour(); - setBackground(newColor); + setBackground(cellColour.getColour()); } if (isSelected) { @@ -2179,28 +2126,43 @@ public class FeatureSettings extends JPanel int w, int h) { boolean thr = false; - String tt = ""; - String tx = ""; + StringBuilder tt = new StringBuilder(); + StringBuilder tx = new StringBuilder(); + + if (gcol.isColourByAttribute()) + { + tx.append(gcol.getAttributeName()); + } + else if (!gcol.isColourByLabel()) + { + tx.append(MessageManager.getString("label.score")); + } + tx.append(" "); if (gcol.isAboveThreshold()) { thr = true; - tx += ">"; - tt += "Thresholded (Above " + gcol.getThreshold() + ") "; + tx.append(">"); + tt.append("Thresholded (Above ").append(gcol.getThreshold()) + .append(") "); } if (gcol.isBelowThreshold()) { thr = true; - tx += "<"; - tt += "Thresholded (Below " + gcol.getThreshold() + ") "; + tx.append("<"); + tt.append("Thresholded (Below ").append(gcol.getThreshold()) + .append(") "); } if (gcol.isColourByLabel()) { - tt = "Coloured by label text. " + tt; + tt.append("Coloured by label text. ").append(tt); if (thr) { - tx += " "; + tx.append(" "); + } + if (!gcol.isColourByAttribute()) + { + tx.append("Label"); } - tx += "Label"; comp.setIcon(null); } else @@ -2216,16 +2178,17 @@ public class FeatureSettings extends JPanel // + ", " + minCol.getBlue() + ")"); } comp.setHorizontalAlignment(SwingConstants.CENTER); - comp.setText(tx); + comp.setText(tx.toString()); if (tt.length() > 0) { if (comp.getToolTipText() == null) { - comp.setToolTipText(tt); + comp.setToolTipText(tt.toString()); } else { - comp.setToolTipText(tt + " " + comp.getToolTipText()); + comp.setToolTipText(tt.append(" ").append(comp.getToolTipText()) + .toString()); } } } @@ -2347,7 +2310,8 @@ class ColorEditor extends AbstractCellEditor button.setBorderPainted(false); // Set up the dialog that the button brings up. colorChooser = new JColorChooser(); - dialog = JColorChooser.createDialog(button, "Select new Colour", true, // modal + dialog = JColorChooser.createDialog(button, + MessageManager.getString("label.select_new_colour"), true, // modal colorChooser, this, // OK button handler null); // no CANCEL button handler }