X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;fp=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=b49593a1697a2842b036a8a55d02a6a02c3cc905;hb=ec8f3cedf60fb1feed6d34de6b49f6bfa78b9dd8;hp=b87e4bf92c10de36e2a0b7cf827a5dd5341871f3;hpb=056dad85a910551cc95e44d451a61f6b8c4dd35d;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index b87e4bf..b49593a 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -20,32 +20,6 @@ */ package jalview.gui; -import jalview.api.AlignViewControllerGuiI; -import jalview.api.AlignViewportI; -import jalview.api.FeatureColourI; -import jalview.api.FeatureSettingsControllerI; -import jalview.api.SplitContainerI; -import jalview.api.ViewStyleI; -import jalview.controller.FeatureSettingsControllerGuiI; -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; -import jalview.gui.Help.HelpId; -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; -import jalview.xml.binding.jalview.ObjectFactory; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -87,8 +61,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; @@ -100,6 +73,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; @@ -114,6 +88,33 @@ import javax.xml.bind.Marshaller; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; +import jalview.api.AlignViewControllerGuiI; +import jalview.api.AlignViewportI; +import jalview.api.FeatureColourI; +import jalview.api.FeatureSettingsControllerI; +import jalview.api.SplitContainerI; +import jalview.api.ViewStyleI; +import jalview.controller.FeatureSettingsControllerGuiI; +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; +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; +import jalview.xml.binding.jalview.ObjectFactory; + public class FeatureSettings extends JPanel implements FeatureSettingsControllerI, FeatureSettingsControllerGuiI { @@ -137,7 +138,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"); + private final static String BASE_TOOLTIP = MessageManager + .getString("label.click_to_edit"); final FeatureRenderer fr; @@ -148,7 +150,7 @@ public class FeatureSettings extends JPanel */ Object[][] originalData; - private float originalTransparency; + float originalTransparency; private ViewStyleI originalViewStyle; @@ -180,7 +182,7 @@ public class FeatureSettings extends JPanel /* * true when Feature Settings are updating from feature renderer */ - private boolean handlingUpdate = false; + boolean handlingUpdate = false; /* * a change listener to ensure the dialog is updated if @@ -264,7 +266,7 @@ public class FeatureSettings extends JPanel default: break; } - + return tip; } @@ -287,19 +289,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.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); @@ -315,8 +317,7 @@ public class FeatureSettings extends JPanel 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 && table.columnAtPoint(pt) == TYPE_COLUMN) @@ -339,8 +340,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()); } } }); @@ -399,6 +399,7 @@ public class FeatureSettings extends JPanel } }); + SplitContainerI splitframe = af.getSplitViewContainer(); if (splitframe != null) { @@ -424,7 +425,7 @@ public class FeatureSettings extends JPanel } if (bounds == null) { - if (Platform.isAMac()) + if (Platform.isAMacAndNotJS()) { Desktop.addInternalFrame(frame, title, 600, 480); } @@ -435,8 +436,8 @@ public class FeatureSettings extends JPanel } else { - Desktop.addInternalFrame(frame, title, - false, bounds.width, bounds.height); + Desktop.addInternalFrame(frame, title, false, bounds.width, + bounds.height); frame.setBounds(bounds); frame.setVisible(true); } @@ -454,8 +455,8 @@ public class FeatureSettings extends JPanel }); frame.setLayer(JLayeredPane.PALETTE_LAYER); } - inConstruction = false; - } + inConstruction = false; + } /** * Sets the state of buttons to show complement features from viewport @@ -481,13 +482,96 @@ public class FeatureSettings extends JPanel change = null; } - 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) { 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) + { + // BH 2018 for JavaScript because this is a checkbox + men.setVisible(true); + men.setVisible(false); + 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); @@ -561,7 +645,7 @@ public class FeatureSettings extends JPanel men.add(clearCols); men.add(hideCols); men.add(hideOtherCols); - men.show(table, x, y); + men.show(table, pt.x, pt.y); } /** @@ -815,8 +899,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 *