X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=5aa9499c209c59089820124a63ad09bb02811498;hb=09020de409b5dce834dc59fc1b94e24c653eac0f;hp=390427a35aaef48545719ee883057e1b314d81c2;hpb=ed1529065c002bb837ea2572b00d1dfdceaa6050;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 390427a..5aa9499 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -20,8 +20,10 @@ */ package jalview.gui; +import jalview.api.AlignViewportI; import jalview.api.FeatureColourI; import jalview.api.FeatureSettingsControllerI; +import jalview.api.ViewStyleI; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.datamodel.features.FeatureMatcher; @@ -29,12 +31,14 @@ import jalview.datamodel.features.FeatureMatcherI; import jalview.datamodel.features.FeatureMatcherSet; import jalview.datamodel.features.FeatureMatcherSetI; import jalview.gui.Help.HelpId; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.schemes.FeatureColour; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean; +import jalview.viewmodel.styles.ViewStyle; import jalview.xml.binding.jalview.JalviewUserColours; import jalview.xml.binding.jalview.JalviewUserColours.Colour; import jalview.xml.binding.jalview.JalviewUserColours.Filter; @@ -44,6 +48,7 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.Font; import java.awt.Graphics; import java.awt.GridLayout; @@ -80,8 +85,7 @@ import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JColorChooser; -import javax.swing.JDialog; +import javax.swing.JCheckBoxMenuItem; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JLayeredPane; @@ -93,6 +97,7 @@ import javax.swing.JSlider; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.SwingConstants; +import javax.swing.ToolTipManager; import javax.swing.border.Border; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -130,7 +135,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"; + private final static String BASE_TOOLTIP = MessageManager + .getString("label.click_to_edit"); final FeatureRenderer fr; @@ -141,7 +147,9 @@ public class FeatureSettings extends JPanel */ Object[][] originalData; - private float originalTransparency; + float originalTransparency; + + private ViewStyleI originalViewStyle; private Map originalFilters; @@ -167,7 +175,7 @@ public class FeatureSettings extends JPanel /* * true when Feature Settings are updating from feature renderer */ - private boolean handlingUpdate = false; + boolean handlingUpdate = false; /* * holds {featureCount, totalExtent} for each feature type @@ -190,6 +198,7 @@ public class FeatureSettings extends JPanel transparency.setMaximum(100 - originalTransparencyAsPercent); originalFilters = new HashMap<>(fr.getFeatureFilters()); // shallow copy + originalViewStyle = new ViewStyle(af.viewport.getViewStyle()); try { @@ -201,8 +210,6 @@ 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) { @@ -232,6 +239,7 @@ public class FeatureSettings extends JPanel default: break; } + return tip; } @@ -254,22 +262,19 @@ public class FeatureSettings extends JPanel 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)); + ToolTipManager.sharedInstance().registerComponent(table); + table.setDefaultEditor(FeatureColour.class, new ColorEditor()); table.setDefaultRenderer(FeatureColour.class, new ColorRenderer()); - table.setDefaultEditor(FeatureMatcherSet.class, new FilterEditor(this)); + table.setDefaultEditor(FeatureMatcherSet.class, new FilterEditor()); table.setDefaultRenderer(FeatureMatcherSet.class, new FilterRenderer()); TableColumn colourColumn = new TableColumn(COLOUR_COLUMN, 75, - new ColorRenderer(), new ColorEditor(this)); + new ColorRenderer(), new ColorEditor()); table.addColumn(colourColumn); TableColumn filterColumn = new TableColumn(FILTER_COLUMN, 75, - new FilterRenderer(), new FilterEditor(this)); + new FilterRenderer(), new FilterEditor()); table.addColumn(filterColumn); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); @@ -279,21 +284,23 @@ public class FeatureSettings extends JPanel @Override public void mousePressed(MouseEvent evt) { - selectedRow = table.rowAtPoint(evt.getPoint()); + Point pt = evt.getPoint(); + selectedRow = table.rowAtPoint(pt); String type = (String) table.getValueAt(selectedRow, TYPE_COLUMN); if (evt.isPopupTrigger()) { Object colour = table.getValueAt(selectedRow, COLOUR_COLUMN); - popupSort(selectedRow, type, colour, fr.getMinMax(), evt.getX(), - evt.getY()); + showPopupMenu(selectedRow, type, colour, evt.getPoint()); } - else if (evt.getClickCount() == 2) + else if (evt.getClickCount() == 2 + && table.columnAtPoint(pt) == TYPE_COLUMN) { boolean invertSelection = evt.isAltDown(); boolean toggleSelection = Platform.isControlDown(evt); boolean extendSelection = evt.isShiftDown(); fr.ap.alignFrame.avc.markColumnsContainingFeatures( invertSelection, extendSelection, toggleSelection, type); + fr.ap.av.sendSelection(); } } @@ -306,8 +313,7 @@ public class FeatureSettings extends JPanel { String type = (String) table.getValueAt(selectedRow, TYPE_COLUMN); Object colour = table.getValueAt(selectedRow, COLOUR_COLUMN); - popupSort(selectedRow, type, colour, fr.getMinMax(), evt.getX(), - evt.getY()); + showPopupMenu(selectedRow, type, colour, evt.getPoint()); } } }); @@ -370,18 +376,9 @@ public class FeatureSettings extends JPanel frame = new JInternalFrame(); frame.setContentPane(this); - if (Platform.isAMac()) - { - Desktop.addInternalFrame(frame, - MessageManager.getString("label.sequence_feature_settings"), - 600, 480); - } - else - { - Desktop.addInternalFrame(frame, - MessageManager.getString("label.sequence_feature_settings"), - 600, 450); - } + Desktop.addInternalFrame(frame, + MessageManager.getString("label.sequence_feature_settings"), + 600, Platform.isAMacAndNotJS() ? 480 : 450); frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); frame.addInternalFrameListener( @@ -392,36 +389,116 @@ public class FeatureSettings extends JPanel javax.swing.event.InternalFrameEvent evt) { fr.removePropertyChangeListener(change); - }; + } }); frame.setLayer(JLayeredPane.PALETTE_LAYER); inConstruction = false; } - protected void popupSort(final int rowSelected, final String type, - final Object typeCol, final Map minmax, int x, - int y) + /** + * Constructs and shows a popup menu of possible actions on the selected row + * and feature type + * + * @param rowSelected + * @param type + * @param typeCol + * @param pt + */ + protected void showPopupMenu(final int rowSelected, final String type, + final Object typeCol, final Point pt) { - final FeatureColourI featureColour = (FeatureColourI) typeCol; - JPopupMenu men = new JPopupMenu(MessageManager .formatMessage("label.settings_for_param", new String[] { type })); + final FeatureColourI featureColour = (FeatureColourI) typeCol; + + /* + * menu option to select (or deselect) variable colour + */ + final JCheckBoxMenuItem variableColourCB = new JCheckBoxMenuItem( + MessageManager.getString("label.variable_colour")); + variableColourCB.setSelected(!featureColour.isSimpleColour()); + men.add(variableColourCB); + + /* + * checkbox action listener doubles up as listener to OK + * from the variable colour / filters dialog + */ + variableColourCB.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + if (e.getSource() == variableColourCB) + { + men.setVisible(true); // BH 2018 for JavaScript because this is a + // checkbox + men.setVisible(false); // BH 2018 for JavaScript because this is a + // checkbox + if (featureColour.isSimpleColour()) + { + /* + * toggle simple colour to variable colour - show dialog + */ + FeatureTypeSettings fc = new FeatureTypeSettings(fr, type); + fc.addActionListener(this); + } + else + { + /* + * toggle variable to simple colour - show colour chooser + */ + String title = MessageManager + .formatMessage("label.select_colour_for", type); + ColourChooserListener listener = new ColourChooserListener() + { + @Override + public void colourSelected(Color c) + { + table.setValueAt(new FeatureColour(c), rowSelected, + COLOUR_COLUMN); + table.validate(); + updateFeatureRenderer( + ((FeatureTableModel) table.getModel()).getData(), + false); + } + }; + JalviewColourChooser.showColourChooser(FeatureSettings.this, + title, featureColour.getMaxColour(), listener); + } + } + else + { + if (e.getSource() instanceof FeatureTypeSettings) + { + /* + * update after OK in feature colour dialog; the updated + * colour will have already been set in the FeatureRenderer + */ + FeatureColourI fci = fr.getFeatureColours().get(type); + table.setValueAt(fci, rowSelected, COLOUR_COLUMN); + // BH 2018 setting a table value does not invalidate it. + // System.out.println("FeatureSettings is valied" + + // table.validate(); + } + } + } + }); + + men.addSeparator(); + JMenuItem scr = new JMenuItem( MessageManager.getString("label.sort_by_score")); men.add(scr); - final FeatureSettings me = this; scr.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - me.af.avc - .sortAlignmentByFeatureScore(Arrays.asList(new String[] + af.avc.sortAlignmentByFeatureScore(Arrays.asList(new String[] { type })); } - }); JMenuItem dens = new JMenuItem( MessageManager.getString("label.sort_by_density")); @@ -431,11 +508,9 @@ public class FeatureSettings extends JPanel @Override public void actionPerformed(ActionEvent e) { - me.af.avc - .sortAlignmentByFeatureDensity(Arrays.asList(new String[] + af.avc.sortAlignmentByFeatureDensity(Arrays.asList(new String[] { type })); } - }); men.add(dens); @@ -448,6 +523,7 @@ public class FeatureSettings extends JPanel { fr.ap.alignFrame.avc.markColumnsContainingFeatures(false, false, false, type); + fr.ap.av.sendSelection(); } }); JMenuItem clearCols = new JMenuItem(MessageManager @@ -459,6 +535,7 @@ public class FeatureSettings extends JPanel { fr.ap.alignFrame.avc.markColumnsContainingFeatures(true, false, false, type); + fr.ap.av.sendSelection(); } }); JMenuItem hideCols = new JMenuItem( @@ -469,6 +546,7 @@ public class FeatureSettings extends JPanel public void actionPerformed(ActionEvent arg0) { fr.ap.alignFrame.hideFeatureColumns(type, true); + fr.ap.av.sendSelection(); } }); JMenuItem hideOtherCols = new JMenuItem( @@ -479,13 +557,14 @@ public class FeatureSettings extends JPanel public void actionPerformed(ActionEvent arg0) { fr.ap.alignFrame.hideFeatureColumns(type, false); + fr.ap.av.sendSelection(); } }); men.add(selCols); men.add(clearCols); men.add(hideCols); men.add(hideOtherCols); - men.show(table, x, y); + men.show(table, pt.x, pt.y); } @Override @@ -542,7 +621,7 @@ public class FeatureSettings extends JPanel { fr.setGroupVisibility(check.getText(), check.isSelected()); resetTable(new String[] { grp }); - af.alignPanel.paintAlignment(true, true); + refreshDisplay(); } }); groupPanel.add(check); @@ -640,7 +719,7 @@ public class FeatureSettings extends JPanel data[dataIndex][FILTER_COLUMN] = featureFilter == null ? new FeatureMatcherSet() : featureFilter; - data[dataIndex][SHOW_COLUMN] = new Boolean( + data[dataIndex][SHOW_COLUMN] = Boolean.valueOf( af.getViewport().getFeaturesDisplayed().isVisible(type)); dataIndex++; displayableTypes.remove(type); @@ -667,7 +746,7 @@ public class FeatureSettings extends JPanel data[dataIndex][FILTER_COLUMN] = featureFilter == null ? new FeatureMatcherSet() : featureFilter; - data[dataIndex][SHOW_COLUMN] = new Boolean(true); + data[dataIndex][SHOW_COLUMN] = Boolean.valueOf(true); dataIndex++; displayableTypes.remove(type); } @@ -698,8 +777,8 @@ public class FeatureSettings extends JPanel } /** - * Updates 'originalData' (used for restore on Cancel) if we detect that changes - * have been made outwith this dialog + * Updates 'originalData' (used for restore on Cancel) if we detect that + * changes have been made outwith this dialog *