X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=33c22f4dad133adc0adf1220810ae3cca8e4e2cf;hb=ae81fc691048b2151003030cb079bee26a0b610c;hp=4f3d7b9574acac427f661294c8da57ee30276998;hpb=b7791df75a2e535cfe438e85b101918eedeb71dc;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 4f3d7b9..33c22f4 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -35,7 +35,6 @@ import jalview.io.JalviewFileView; import jalview.schemes.FeatureColour; import jalview.util.MessageManager; import jalview.util.Platform; -import jalview.util.dialogrunner.RunResponse; import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean; import jalview.xml.binding.jalview.JalviewUserColours; import jalview.xml.binding.jalview.JalviewUserColours.Colour; @@ -99,6 +98,7 @@ import javax.swing.border.Border; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.table.AbstractTableModel; +import javax.swing.table.JTableHeader; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; @@ -163,12 +163,6 @@ public class FeatureSettings extends JPanel int selectedRow = -1; - JButton fetchDAS = new JButton(); - - JButton saveDAS = new JButton(); - - JButton cancelDAS = new JButton(); - boolean resettingTable = false; /* @@ -230,7 +224,8 @@ public class FeatureSettings extends JPanel FeatureMatcherSet o = (FeatureMatcherSet) table.getValueAt(row, column); tip = o.isEmpty() - ? MessageManager.getString("label.filters_tooltip") + ? MessageManager + .getString("label.configure_feature_tooltip") : o.toString(); break; default: @@ -239,6 +234,7 @@ public class FeatureSettings extends JPanel return tip; } + /** * Position the tooltip near the bottom edge of, and half way across, the @@ -255,21 +251,22 @@ public class FeatureSettings extends JPanel return loc; } }; - table.getTableHeader().setFont(new Font("Verdana", Font.PLAIN, 12)); - ToolTipManager.sharedInstance().registerComponent(table); - - table.setDefaultEditor(FeatureColour.class, new ColorEditor(this)); + JTableHeader tableHeader = table.getTableHeader(); + 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()); 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); @@ -284,8 +281,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) { @@ -306,8 +302,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 +365,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( @@ -398,50 +384,25 @@ public class FeatureSettings extends JPanel 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 })); - 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[] - { type })); - } - - }); - JMenuItem dens = new JMenuItem( - MessageManager.getString("label.sort_by_density")); - dens.addActionListener(new ActionListener() - { - - @Override - public void actionPerformed(ActionEvent e) - { - me.af.avc - .sortAlignmentByFeatureDensity(Arrays.asList(new String[] - { type })); - } - - }); - men.add(dens); + final FeatureColourI featureColour = (FeatureColourI) typeCol; /* - * variable colour options include colour by label, by score, - * by selected attribute text, or attribute value + * menu option to select (or deselect) variable colour */ final JCheckBoxMenuItem variableColourCB = new JCheckBoxMenuItem( MessageManager.getString("label.variable_colour")); @@ -459,12 +420,14 @@ public class FeatureSettings extends JPanel { 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(me.fr, type); + FeatureTypeSettings fc = new FeatureTypeSettings(fr, type); fc.addActionListener(this); } else @@ -472,7 +435,7 @@ public class FeatureSettings extends JPanel /* * toggle variable to simple colour - show colour chooser */ - String title = MessageManager.getString("label.select_colour"); + String title = MessageManager.formatMessage("label.select_colour_for", type); ColourChooserListener listener = new ColourChooserListener() { @Override @@ -481,15 +444,17 @@ public class FeatureSettings extends JPanel table.setValueAt(new FeatureColour(c), rowSelected, COLOUR_COLUMN); table.validate(); - me.updateFeatureRenderer( + updateFeatureRenderer( ((FeatureTableModel) table.getModel()).getData(), false); } }; - JalviewColourChooser.showColourChooser(me, title, featureColour.getMaxColour(), listener); + JalviewColourChooser.showColourChooser(FeatureSettings.this, title, + featureColour.getMaxColour(), listener); } } - else { + else + { if (e.getSource() instanceof FeatureTypeSettings) { /* @@ -498,12 +463,42 @@ public class FeatureSettings extends JPanel */ FeatureColourI fci = fr.getFeatureColours().get(type); table.setValueAt(fci, rowSelected, COLOUR_COLUMN); - table.validate(); + // BH 2018 setting a table value does not invalidate it. +// System.out.println("FeatureSettings is valied" + table.isValid()); +// table.validate(); } } } + }); + + men.addSeparator(); + + JMenuItem scr = new JMenuItem( + MessageManager.getString("label.sort_by_score")); + men.add(scr); + scr.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + af.avc.sortAlignmentByFeatureScore(Arrays.asList(new String[] + { type })); + } }); + JMenuItem dens = new JMenuItem( + MessageManager.getString("label.sort_by_density")); + dens.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + af.avc.sortAlignmentByFeatureDensity(Arrays.asList(new String[] + { type })); + } + }); + men.add(dens); JMenuItem selCols = new JMenuItem( MessageManager.getString("label.select_columns_containing")); @@ -551,7 +546,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); } @Override @@ -885,13 +880,15 @@ public class FeatureSettings extends JPanel chooser.setDialogTitle( MessageManager.getString("label.load_feature_colours")); chooser.setToolTipText(MessageManager.getString("action.load")); - chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION){ - - @Override - public void run() { - File file = chooser.getSelectedFile(); - load(file); - }}); + chooser.setResponseHandler(0, new Runnable() + { + @Override + public void run() + { + File file = chooser.getSelectedFile(); + load(file); + } + }); chooser.showOpenDialog(this); } @@ -1263,22 +1260,6 @@ public class FeatureSettings extends JPanel } } }); - help.setFont(JvSwingUtils.getLabelFont()); - help.setText(MessageManager.getString("action.help")); - help.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - try - { - Help.showHelpWindow(HelpId.SequenceFeatureSettings); - } catch (HelpSetException e1) - { - e1.printStackTrace(); - } - } - }); JButton cancel = new JButton(MessageManager.getString("action.cancel")); cancel.setFont(JvSwingUtils.getLabelFont()); @@ -1464,7 +1445,7 @@ public class FeatureSettings extends JPanel private String[] columnNames = { MessageManager.getString("label.feature_type"), MessageManager.getString("action.colour"), - MessageManager.getString("label.filter"), + MessageManager.getString("label.configuration"), MessageManager.getString("label.show") }; private Object[][] data; @@ -1664,11 +1645,10 @@ public class FeatureSettings extends JPanel renderGraduatedColor(comp, gcol, w, h); } - class ColorEditor extends AbstractCellEditor + @SuppressWarnings("serial") +class ColorEditor extends AbstractCellEditor implements TableCellEditor, ActionListener { - FeatureSettings me; - FeatureColourI currentColor; FeatureTypeSettings chooser; @@ -1681,9 +1661,8 @@ public class FeatureSettings extends JPanel int rowSelected = 0; - public ColorEditor(FeatureSettings fs) + public ColorEditor() { - this.me = fs; // Set up the editor (from the table's point of view), // which is a button. // This button brings up the color chooser dialog, @@ -1708,14 +1687,21 @@ public class FeatureSettings extends JPanel /* * simple colour chooser */ - String ttl = MessageManager.getString("label.select_colour"); - ColourChooserListener listener = new ColourChooserListener() { + String ttl = MessageManager.formatMessage("label.select_colour_for", type); + ColourChooserListener listener = new ColourChooserListener() + { @Override public void colourSelected(Color c) { currentColor = new FeatureColour(c); - me.table.setValueAt(currentColor, rowSelected, COLOUR_COLUMN); + table.setValueAt(currentColor, rowSelected, COLOUR_COLUMN); + fireEditingStopped(); } + @Override + public void cancel() + { + fireEditingStopped(); + } }; JalviewColourChooser.showColourChooser(button, ttl, currentColor.getColour(), listener); } @@ -1724,16 +1710,13 @@ public class FeatureSettings extends JPanel /* * variable colour and filters dialog */ - chooser = new FeatureTypeSettings(me.fr, type); - /** - * @j2sNative - */ + chooser = new FeatureTypeSettings(fr, type); + if (!Platform.isJS()) { chooser.setRequestFocusEnabled(true); chooser.requestFocus(); } chooser.addActionListener(this); - // Make the renderer reappear. fireEditingStopped(); } } @@ -1745,7 +1728,7 @@ public class FeatureSettings extends JPanel * update table data without triggering updateFeatureRenderer */ currentColor = fr.getFeatureColours().get(type); - FeatureMatcherSetI currentFilter = me.fr.getFeatureFilter(type); + FeatureMatcherSetI currentFilter = fr.getFeatureFilter(type); if (currentFilter == null) { currentFilter = new FeatureMatcherSet(); @@ -1754,13 +1737,26 @@ public class FeatureSettings extends JPanel .getData()[rowSelected]; data[COLOUR_COLUMN] = currentColor; data[FILTER_COLUMN] = currentFilter; - fireEditingStopped(); - me.table.validate(); + // SwingJS needs an explicit repaint() here, + // rather than relying upon no validation having + // occurred since the stopEditing call was made. + // Its laying out has not been stopped by the modal frame + table.validate(); + table.repaint(); } } - // Implement the one CellEditor method that AbstractCellEditor doesn't. + /** + * Override allows access to this method from anonymous inner classes + */ + @Override + protected void fireEditingStopped() + { + super.fireEditingStopped(); + } + + // Implement the one CellEditor method that AbstractCellEditor doesn't. @Override public Object getCellEditorValue() { @@ -1774,9 +1770,9 @@ public class FeatureSettings extends JPanel { currentColor = (FeatureColourI) value; this.rowSelected = row; - type = me.table.getValueAt(row, TYPE_COLUMN).toString(); + type = table.getValueAt(row, TYPE_COLUMN).toString(); button.setOpaque(true); - button.setBackground(me.getBackground()); + button.setBackground(FeatureSettings.this.getBackground()); if (!currentColor.isSimpleColour()) { JLabel btn = new JLabel(); @@ -1802,10 +1798,10 @@ public class FeatureSettings extends JPanel * as display text). On click in the cell, opens the Feature Display Settings * dialog at the Filters tab. */ - class FilterEditor extends AbstractCellEditor + @SuppressWarnings("serial") +class FilterEditor extends AbstractCellEditor implements TableCellEditor, ActionListener { - FeatureSettings me; FeatureMatcherSetI currentFilter; @@ -1819,9 +1815,8 @@ public class FeatureSettings extends JPanel int rowSelected = 0; - public FilterEditor(FeatureSettings me) + public FilterEditor() { - this.me = me; button = new JButton(); button.setActionCommand(EDIT); button.addActionListener(this); @@ -1836,7 +1831,7 @@ public class FeatureSettings extends JPanel { if (button == e.getSource()) { - FeatureTypeSettings chooser = new FeatureTypeSettings(me.fr, type); + FeatureTypeSettings chooser = new FeatureTypeSettings(fr, type); chooser.addActionListener(this); chooser.setRequestFocusEnabled(true); chooser.requestFocus(); @@ -1858,17 +1853,23 @@ public class FeatureSettings extends JPanel * update table data without triggering updateFeatureRenderer */ FeatureColourI currentColor = fr.getFeatureColours().get(type); - currentFilter = me.fr.getFeatureFilter(type); + currentFilter = fr.getFeatureFilter(type); if (currentFilter == null) { currentFilter = new FeatureMatcherSet(); } + Object[] data = ((FeatureTableModel) table.getModel()) .getData()[rowSelected]; data[COLOUR_COLUMN] = currentColor; data[FILTER_COLUMN] = currentFilter; fireEditingStopped(); - me.table.validate(); + // SwingJS needs an explicit repaint() here, + // rather than relying upon no validation having + // occurred since the stopEditing call was made. + // Its laying out has not been stopped by the modal frame + table.validate(); + table.repaint(); } } @@ -1884,9 +1885,9 @@ public class FeatureSettings extends JPanel { currentFilter = (FeatureMatcherSetI) value; this.rowSelected = row; - type = me.table.getValueAt(row, TYPE_COLUMN).toString(); + type = table.getValueAt(row, TYPE_COLUMN).toString(); button.setOpaque(true); - button.setBackground(me.getBackground()); + button.setBackground(FeatureSettings.this.getBackground()); button.setText(currentFilter.toString()); button.setIcon(null); return button; @@ -1971,7 +1972,8 @@ class FeatureIcon implements Icon g.fillRect(s1, 0, e1 - s1, height); } g.setColor(gcol.getMaxColour()); - g.fillRect(0, e1, width - e1, height); +// g.fillRect(0, e1, width - e1, height); // BH 2018 + g.fillRect(e1, 0, width - e1, height); } } }