X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=63f1b137853a8af84f0f6133616d324222623264;hb=ad79fcf0705b71f2504b1ed4092d54a8c45ef09f;hp=8f841d1ea85222dc76e0dcf2e3c062461e90c1b2;hpb=341e759bcdf94d50e58217f55a87f25a44eeef54;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 8f841d1..63f1b13 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,23 +20,27 @@ */ package jalview.gui; -import jalview.analysis.AlignmentSorter; +import jalview.api.FeatureColourI; +import jalview.api.FeatureSettingsControllerI; import jalview.bin.Cache; -import jalview.commands.OrderCommand; import jalview.datamodel.AlignmentI; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.Help.HelpId; import jalview.io.JalviewFileChooser; -import jalview.schemes.AnnotationColourGradient; -import jalview.schemes.GraduatedColor; +import jalview.io.JalviewFileView; +import jalview.schemabinding.version2.JalviewUserColours; +import jalview.schemes.FeatureColour; +import jalview.util.Format; import jalview.util.MessageManager; +import jalview.util.Platform; +import jalview.util.QuickSort; +import jalview.viewmodel.AlignmentViewport; import jalview.ws.dbsources.das.api.jalviewSourceI; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; +import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.GridLayout; @@ -56,10 +60,13 @@ import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; -import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.Vector; import javax.help.HelpSetException; @@ -75,7 +82,6 @@ import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JLayeredPane; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; @@ -92,6 +98,7 @@ import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; public class FeatureSettings extends JPanel + implements FeatureSettingsControllerI { DasSourceBrowser dassourceBrowser; @@ -107,6 +114,8 @@ public class FeatureSettings extends JPanel Object[][] originalData; + private float originalTransparency; + final JInternalFrame frame; JScrollPane scrollPane = new JScrollPane(); @@ -119,12 +128,27 @@ public class FeatureSettings extends JPanel JPanel transPanel = new JPanel(new GridLayout(1, 2)); + private static final int MIN_WIDTH = 400; + + private static final int MIN_HEIGHT = 400; + + /** + * when true, constructor is still executing - so ignore UI events + */ + protected volatile boolean inConstruction = true; + + /** + * Constructor + * + * @param af + */ public FeatureSettings(AlignFrame af) { this.af = af; fr = af.getFeatureRenderer(); - - transparency.setMaximum(100 - (int) (fr.transparency * 100)); + // allow transparency to be recovered + transparency.setMaximum(100 + - (int) ((originalTransparency = fr.getTransparency()) * 100)); try { @@ -134,15 +158,18 @@ public class FeatureSettings extends JPanel ex.printStackTrace(); } - table = new JTable() { + table = new JTable() + { @Override - public String getToolTipText(MouseEvent e) { - if (table.columnAtPoint(e.getPoint()) == 0) { + public String getToolTipText(MouseEvent e) + { + if (table.columnAtPoint(e.getPoint()) == 0) + { /* * Tooltip for feature name only */ - return JvSwingUtils.wrapTooltip(true, - MessageManager.getString("label.feature_settings_click_drag")); + return JvSwingUtils.wrapTooltip(true, MessageManager + .getString("label.feature_settings_click_drag")); } return null; } @@ -153,31 +180,34 @@ public class FeatureSettings extends JPanel table.setDefaultEditor(Color.class, new ColorEditor(this)); - table.setDefaultEditor(GraduatedColor.class, new ColorEditor(this)); - table.setDefaultRenderer(GraduatedColor.class, new ColorRenderer()); + table.setDefaultEditor(FeatureColour.class, new ColorEditor(this)); + table.setDefaultRenderer(FeatureColour.class, new ColorRenderer()); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(MouseEvent evt) { selectedRow = table.rowAtPoint(evt.getPoint()); - if (SwingUtilities.isRightMouseButton(evt)) + if (evt.isPopupTrigger()) { popupSort(selectedRow, (String) table.getValueAt(selectedRow, 0), - table.getValueAt(selectedRow, 1), fr.minmax, evt.getX(), - evt.getY()); + table.getValueAt(selectedRow, 1), fr.getMinMax(), + evt.getX(), evt.getY()); } else if (evt.getClickCount() == 2) { + boolean invertSelection = evt.isAltDown(); + boolean toggleSelection = Platform.isControlDown(evt); + boolean extendSelection = evt.isShiftDown(); fr.ap.alignFrame.avc.markColumnsContainingFeatures( - evt.isAltDown(), evt.isShiftDown() || evt.isMetaDown(), - evt.isMetaDown(), + invertSelection, extendSelection, toggleSelection, (String) table.getValueAt(selectedRow, 0)); } } - // isPopupTrigger fires on mouseReleased on Mac + // isPopupTrigger fires on mouseReleased on Windows @Override public void mouseReleased(MouseEvent evt) { @@ -185,54 +215,58 @@ public class FeatureSettings extends JPanel if (evt.isPopupTrigger()) { popupSort(selectedRow, (String) table.getValueAt(selectedRow, 0), - table.getValueAt(selectedRow, 1), fr.minmax, evt.getX(), - evt.getY()); + table.getValueAt(selectedRow, 1), fr.getMinMax(), + evt.getX(), evt.getY()); } } }); table.addMouseMotionListener(new MouseMotionAdapter() { + @Override public void mouseDragged(MouseEvent evt) { int newRow = table.rowAtPoint(evt.getPoint()); if (newRow != selectedRow && selectedRow != -1 && newRow != -1) { - Object[] temp = new Object[3]; - temp[0] = table.getValueAt(selectedRow, 0); - temp[1] = table.getValueAt(selectedRow, 1); - temp[2] = table.getValueAt(selectedRow, 2); - - table.setValueAt(table.getValueAt(newRow, 0), selectedRow, 0); - table.setValueAt(table.getValueAt(newRow, 1), selectedRow, 1); - table.setValueAt(table.getValueAt(newRow, 2), selectedRow, 2); - - table.setValueAt(temp[0], newRow, 0); - table.setValueAt(temp[1], newRow, 1); - table.setValueAt(temp[2], newRow, 2); - + /* + * reposition 'selectedRow' to 'newRow' (the dragged to location) + * this could be more than one row away for a very fast drag action + * so just swap it with adjacent rows until we get it there + */ + Object[][] data = ((FeatureTableModel) table.getModel()) + .getData(); + int direction = newRow < selectedRow ? -1 : 1; + for (int i = selectedRow; i != newRow; i += direction) + { + Object[] temp = data[i]; + data[i] = data[i + direction]; + data[i + direction] = temp; + } + updateFeatureRenderer(data); + table.repaint(); selectedRow = newRow; } } }); -// table.setToolTipText(JvSwingUtils.wrapTooltip(true, -// MessageManager.getString("label.feature_settings_click_drag"))); + // table.setToolTipText(JvSwingUtils.wrapTooltip(true, + // MessageManager.getString("label.feature_settings_click_drag"))); scrollPane.setViewportView(table); dassourceBrowser = new DasSourceBrowser(this); dasSettingsPane.add(dassourceBrowser, BorderLayout.CENTER); - if (af.getViewport().getFeaturesDisplayed() == null - || fr.renderOrder == null) + if (af.getViewport().isShowSequenceFeatures() || !fr.hasRenderOrder()) { fr.findAllFeatures(true); // display everything! } - setTableData(); + discoverAllFeatureData(); final PropertyChangeListener change; final FeatureSettings fs = this; fr.addPropertyChangeListener(change = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { if (!fs.resettingTable && !fs.handlingUpdate) @@ -248,7 +282,7 @@ public class FeatureSettings extends JPanel frame = new JInternalFrame(); frame.setContentPane(this); - if (new jalview.util.Platform().isAMac()) + if (Platform.isAMac()) { Desktop.addInternalFrame(frame, MessageManager.getString("label.sequence_feature_settings"), @@ -260,24 +294,31 @@ public class FeatureSettings extends JPanel MessageManager.getString("label.sequence_feature_settings"), 400, 450); } + frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); - frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() - { - public void internalFrameClosed( - javax.swing.event.InternalFrameEvent evt) - { - fr.removePropertyChangeListener(change); - dassourceBrowser.fs = null; - }; - }); + frame.addInternalFrameListener( + new javax.swing.event.InternalFrameAdapter() + { + @Override + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + fr.removePropertyChangeListener(change); + dassourceBrowser.fs = null; + }; + }); frame.setLayer(JLayeredPane.PALETTE_LAYER); + inConstruction = false; } protected void popupSort(final int selectedRow, final String type, - final Object typeCol, final Hashtable minmax, int x, int y) + final Object typeCol, final Map minmax, int x, + int y) { - JPopupMenu men = new JPopupMenu(MessageManager.formatMessage( - "label.settings_for_param", new String[] + 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")); @@ -286,10 +327,12 @@ public class FeatureSettings extends JPanel scr.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - me.sortByScore(new String[] - { type }); + me.af.avc + .sortAlignmentByFeatureScore(Arrays.asList(new String[] + { type })); } }); @@ -298,17 +341,19 @@ public class FeatureSettings extends JPanel dens.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - me.sortByDens(new String[] - { type }); + me.af.avc + .sortAlignmentByFeatureDensity(Arrays.asList(new String[] + { type })); } }); men.add(dens); if (minmax != null) { - final Object typeMinMax = minmax.get(type); + 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! @@ -323,24 +368,25 @@ public class FeatureSettings extends JPanel * * men.add(chb); */ - if (typeMinMax != null && ((float[][]) typeMinMax)[0] != null) + 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(!(typeCol instanceof Color)); + mxcol.setSelected(!featureColour.isSimpleColour()); men.add(mxcol); mxcol.addActionListener(new ActionListener() { JColorChooser colorChooser; + @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == mxcol) { - if (typeCol instanceof Color) + if (featureColour.isSimpleColour()) { FeatureColourChooser fc = new FeatureColourChooser(me.fr, type); @@ -354,8 +400,7 @@ public class FeatureSettings extends JPanel "Select new Colour", true, // modal colorChooser, this, // OK button handler null); // no CANCEL button handler - colorChooser.setColor(((GraduatedColor) typeCol) - .getMaxColor()); + colorChooser.setColor(featureColour.getMaxColour()); dialog.setVisible(true); } } @@ -371,7 +416,8 @@ public class FeatureSettings extends JPanel else { // probably the color chooser! - table.setValueAt(colorChooser.getColor(), selectedRow, 1); + table.setValueAt(new FeatureColour(colorChooser.getColor()), + selectedRow, 1); table.validate(); me.updateFeatureRenderer( ((FeatureTableModel) table.getModel()).getData(), @@ -387,7 +433,6 @@ public class FeatureSettings extends JPanel MessageManager.getString("label.select_columns_containing")); selCols.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent arg0) { @@ -395,11 +440,10 @@ public class FeatureSettings extends JPanel false, type); } }); - JMenuItem clearCols = new JMenuItem( - MessageManager.getString("label.select_columns_not_containing")); + JMenuItem clearCols = new JMenuItem(MessageManager + .getString("label.select_columns_not_containing")); clearCols.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent arg0) { @@ -407,8 +451,30 @@ public class FeatureSettings extends JPanel false, type); } }); + JMenuItem hideCols = new JMenuItem( + MessageManager.getString("label.hide_columns_containing")); + hideCols.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent arg0) + { + fr.ap.alignFrame.hideFeatureColumns(type, true); + } + }); + JMenuItem hideOtherCols = new JMenuItem( + MessageManager.getString("label.hide_columns_not_containing")); + hideOtherCols.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent arg0) + { + fr.ap.alignFrame.hideFeatureColumns(type, false); + } + }); men.add(selCols); men.add(clearCols); + men.add(hideCols); + men.add(hideOtherCols); men.show(table, x, y); } @@ -418,58 +484,26 @@ public class FeatureSettings extends JPanel private boolean handlingUpdate = false; /** - * contains a float[3] for each feature type string. created by setTableData + * holds {featureCount, totalExtent} for each feature type */ - Hashtable typeWidth = null; + Map typeWidth = null; - synchronized public void setTableData() + @Override + synchronized public void discoverAllFeatureData() { - if (fr.featureGroups == null) - { - fr.featureGroups = new Hashtable(); - } - Vector allFeatures = new Vector(); - Vector allGroups = new Vector(); - SequenceFeature[] tmpfeatures; - String group; - for (int i = 0; i < af.getViewport().getAlignment().getHeight(); i++) - { - if (af.getViewport().getAlignment().getSequenceAt(i) - .getDatasetSequence().getSequenceFeatures() == null) - { - continue; - } - - tmpfeatures = af.getViewport().getAlignment().getSequenceAt(i) - .getDatasetSequence().getSequenceFeatures(); + Set allGroups = new HashSet<>(); + AlignmentI alignment = af.getViewport().getAlignment(); - int index = 0; - while (index < tmpfeatures.length) + for (int i = 0; i < alignment.getHeight(); i++) + { + SequenceI seq = alignment.getSequenceAt(i); + for (String group : seq.getFeatures().getFeatureGroups(true)) { - if (tmpfeatures[index].begin == 0 && tmpfeatures[index].end == 0) - { - index++; - continue; - } - - if (tmpfeatures[index].getFeatureGroup() != null) - { - group = tmpfeatures[index].featureGroup; - if (!allGroups.contains(group)) - { - allGroups.addElement(group); - if (group != null) - { - checkGroupState(group); - } - } - } - - if (!allFeatures.contains(tmpfeatures[index].getType())) + if (group != null && !allGroups.contains(group)) { - allFeatures.addElement(tmpfeatures[index].getType()); + allGroups.add(group); + checkGroupState(group); } - index++; } } @@ -479,165 +513,130 @@ public class FeatureSettings extends JPanel } /** + * Synchronise gui group list and check visibility of group * * @param group - * @return true if group has been seen before and is already added to set. + * @return true if group is visible */ private boolean checkGroupState(String group) { - boolean visible; - if (fr.featureGroups.containsKey(group)) - { - visible = ((Boolean) fr.featureGroups.get(group)).booleanValue(); - } - else - { - visible = true; // new group is always made visible - } - - if (groupPanel == null) - { - groupPanel = new JPanel(); - } + boolean visible = fr.checkGroupVisibility(group, true); - boolean alreadyAdded = false; for (int g = 0; g < groupPanel.getComponentCount(); g++) { if (((JCheckBox) groupPanel.getComponent(g)).getText().equals(group)) { - alreadyAdded = true; ((JCheckBox) groupPanel.getComponent(g)).setSelected(visible); - break; + return visible; } } - if (alreadyAdded) - { - - return true; - } - - fr.featureGroups.put(group, new Boolean(visible)); final String grp = group; final JCheckBox check = new JCheckBox(group, visible); check.setFont(new Font("Serif", Font.BOLD, 12)); + check.setToolTipText(group); check.addItemListener(new ItemListener() { + @Override public void itemStateChanged(ItemEvent evt) { - fr.featureGroups.put(check.getText(), - new Boolean(check.isSelected())); - af.alignPanel.seqPanel.seqCanvas.repaint(); + fr.setGroupVisibility(check.getText(), check.isSelected()); + af.alignPanel.getSeqPanel().seqCanvas.repaint(); if (af.alignPanel.overviewPanel != null) { af.alignPanel.overviewPanel.updateOverviewImage(); } - resetTable(new String[] - { grp }); + resetTable(new String[] { grp }); } }); groupPanel.add(check); - return false; + return visible; } boolean resettingTable = false; synchronized void resetTable(String[] groupChanged) { - if (resettingTable == true) + if (resettingTable) { return; } resettingTable = true; - typeWidth = new Hashtable(); + typeWidth = new Hashtable<>(); // TODO: change avWidth calculation to 'per-sequence' average and use long // rather than float - float[] avWidth = null; - SequenceFeature[] tmpfeatures; - String group = null, type; - Vector visibleChecks = new Vector(); - - // Find out which features should be visible depending on which groups - // are selected / deselected - // and recompute average width ordering + + Set displayableTypes = new HashSet<>(); + Set foundGroups = new HashSet<>(); + + /* + * determine which feature types may be visible depending on + * which groups are selected, and recompute average width data + */ for (int i = 0; i < af.getViewport().getAlignment().getHeight(); i++) { - tmpfeatures = af.getViewport().getAlignment().getSequenceAt(i) - .getDatasetSequence().getSequenceFeatures(); - if (tmpfeatures == null) - { - continue; - } + SequenceI seq = af.getViewport().getAlignment().getSequenceAt(i); - int index = 0; - while (index < tmpfeatures.length) + /* + * get the sequence's groups for positional features + * and keep track of which groups are visible + */ + Set groups = seq.getFeatures().getFeatureGroups(true); + Set visibleGroups = new HashSet<>(); + for (String group : groups) { - group = tmpfeatures[index].featureGroup; - - if (tmpfeatures[index].begin == 0 && tmpfeatures[index].end == 0) + if (group == null || checkGroupState(group)) { - index++; - continue; + visibleGroups.add(group); } + } + foundGroups.addAll(groups); - if (group == null || fr.featureGroups.get(group) == null - || ((Boolean) fr.featureGroups.get(group)).booleanValue()) - { - if (group != null) - { - checkGroupState(group); - } - type = tmpfeatures[index].getType(); - if (!visibleChecks.contains(type)) - { - visibleChecks.addElement(type); - } - } - if (!typeWidth.containsKey(tmpfeatures[index].getType())) - { - typeWidth.put(tmpfeatures[index].getType(), - avWidth = new float[3]); - } - else - { - avWidth = (float[]) typeWidth.get(tmpfeatures[index].getType()); - } - avWidth[0]++; - if (tmpfeatures[index].getBegin() > tmpfeatures[index].getEnd()) - { - avWidth[1] += 1 + tmpfeatures[index].getBegin() - - tmpfeatures[index].getEnd(); - } - else + /* + * get distinct feature types for visible groups + * record distinct visible types, and their count and total length + */ + Set types = seq.getFeatures().getFeatureTypesForGroups(true, + visibleGroups.toArray(new String[visibleGroups.size()])); + for (String type : types) + { + displayableTypes.add(type); + float[] avWidth = typeWidth.get(type); + if (avWidth == null) { - avWidth[1] += 1 + tmpfeatures[index].getEnd() - - tmpfeatures[index].getBegin(); + avWidth = new float[2]; + typeWidth.put(type, avWidth); } - index++; + // todo this could include features with a non-visible group + // - do we greatly care? + // todo should we include non-displayable features here, and only + // update when features are added? + avWidth[0] += seq.getFeatures().getFeatureCount(true, type); + avWidth[1] += seq.getFeatures().getTotalFeatureLength(type); } } - int fSize = visibleChecks.size(); - Object[][] data = new Object[fSize][3]; + Object[][] data = new Object[displayableTypes.size()][3]; int dataIndex = 0; - if (fr.renderOrder != null) + if (fr.hasRenderOrder()) { if (!handlingUpdate) - { + { fr.findAllFeatures(groupChanged != null); // prod to update + // colourschemes. but don't + // affect display + // First add the checks in the previous render order, + // in case the window has been closed and reopened } - // colourschemes. but don't - // affect display - // First add the checks in the previous render order, - // in case the window has been closed and reopened - for (int ro = fr.renderOrder.length - 1; ro > -1; ro--) + List frl = fr.getRenderOrder(); + for (int ro = frl.size() - 1; ro > -1; ro--) { - type = fr.renderOrder[ro]; + String type = frl.get(ro); - if (!visibleChecks.contains(type)) + if (!displayableTypes.contains(type)) { continue; } @@ -645,30 +644,32 @@ public class FeatureSettings extends JPanel data[dataIndex][0] = type; data[dataIndex][1] = fr.getFeatureStyle(type); data[dataIndex][2] = new Boolean( - af.getViewport().getFeaturesDisplayed().containsKey(type)); + af.getViewport().getFeaturesDisplayed().isVisible(type)); dataIndex++; - visibleChecks.removeElement(type); + displayableTypes.remove(type); } } - fSize = visibleChecks.size(); - for (int i = 0; i < fSize; i++) + /* + * process any extra features belonging only to + * a group which was just selected + */ + while (!displayableTypes.isEmpty()) { - // These must be extra features belonging to the group - // which was just selected - type = visibleChecks.elementAt(i).toString(); + String type = displayableTypes.iterator().next(); data[dataIndex][0] = type; data[dataIndex][1] = fr.getFeatureStyle(type); if (data[dataIndex][1] == null) { // "Colour has been updated in another view!!" - fr.renderOrder = null; + fr.clearRenderOrder(); return; } data[dataIndex][2] = new Boolean(true); dataIndex++; + displayableTypes.remove(type); } if (originalData == null) @@ -679,24 +680,105 @@ public class FeatureSettings extends JPanel System.arraycopy(data[i], 0, originalData[i], 0, 3); } } + else + { + updateOriginalData(data); + } table.setModel(new FeatureTableModel(data)); table.getColumnModel().getColumn(0).setPreferredWidth(200); - if (groupPanel != null) - { - groupPanel.setLayout(new GridLayout(fr.featureGroups.size() / 4 + 1, - 4)); - - groupPanel.validate(); - bigPanel.add(groupPanel, BorderLayout.NORTH); - } + groupPanel.setLayout( + new GridLayout(fr.getFeatureGroupsSize() / 4 + 1, 4)); + pruneGroups(foundGroups); + groupPanel.validate(); updateFeatureRenderer(data, groupChanged != null); resettingTable = false; } /** + * Updates 'originalData' (used for restore on Cancel) if we detect that + * changes have been made outwith this dialog + *
    + *
  • a new feature type added (and made visible)
  • + *
  • a feature colour changed (in the Amend Features dialog)
  • + *
+ * + * @param foundData + */ + protected void updateOriginalData(Object[][] foundData) + { + // todo LinkedHashMap instead of Object[][] would be nice + + Object[][] currentData = ((FeatureTableModel) table.getModel()) + .getData(); + for (Object[] row : foundData) + { + String type = (String) row[0]; + boolean found = false; + for (Object[] current : currentData) + { + if (type.equals(current[0])) + { + found = true; + /* + * currently dependent on object equality here; + * really need an equals method on FeatureColour + */ + if (!row[1].equals(current[1])) + { + /* + * feature colour has changed externally - update originalData + */ + for (Object[] original : originalData) + { + if (type.equals(original[0])) + { + original[1] = row[1]; + break; + } + } + } + break; + } + } + if (!found) + { + /* + * new feature detected - add to original data (on top) + */ + Object[][] newData = new Object[originalData.length + 1][3]; + for (int i = 0; i < originalData.length; i++) + { + System.arraycopy(originalData[i], 0, newData[i + 1], 0, 3); + } + newData[0] = row; + originalData = newData; + } + } + } + + /** + * Remove from the groups panel any checkboxes for groups that are not in the + * foundGroups set. This enables removing a group from the display when the + * last feature in that group is deleted. + * + * @param foundGroups + */ + protected void pruneGroups(Set foundGroups) + { + for (int g = 0; g < groupPanel.getComponentCount(); g++) + { + JCheckBox checkbox = (JCheckBox) groupPanel.getComponent(g); + if (!foundGroups.contains(checkbox.getText())) + { + groupPanel.remove(checkbox); + } + } + } + + /** * reorder data based on the featureRenderers global priority list. * * @param data @@ -725,12 +807,11 @@ public class FeatureSettings extends JPanel void load() { - JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "fc" }, new String[] - { "Sequence Feature Colours" }, "Sequence Feature Colours"); - chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle(MessageManager.getString("label.load_feature_colours")); + JalviewFileChooser chooser = new JalviewFileChooser("fc", + "Sequence Feature Colours"); + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle( + MessageManager.getString("label.load_feature_colours")); chooser.setToolTipText(MessageManager.getString("action.load")); int value = chooser.showOpenDialog(this); @@ -741,12 +822,10 @@ public class FeatureSettings extends JPanel try { - InputStreamReader in = new InputStreamReader(new FileInputStream( - file), "UTF-8"); + InputStreamReader in = new InputStreamReader( + new FileInputStream(file), "UTF-8"); - jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours(); - jucs = jucs - .unmarshal(in); + JalviewUserColours jucs = JalviewUserColours.unmarshal(in); for (int i = jucs.getColourCount() - 1; i >= 0; i--) { @@ -765,7 +844,7 @@ public class FeatureSettings extends JPanel Cache.log.warn("Couldn't parse out graduated feature color.", e); } - GraduatedColor gcol = new GraduatedColor(mincol, maxcol, + FeatureColourI gcol = new FeatureColour(mincol, maxcol, newcol.getMin(), newcol.getMax()); if (newcol.hasAutoScale()) { @@ -777,31 +856,28 @@ public class FeatureSettings extends JPanel } if (newcol.hasThreshold()) { - gcol.setThresh(newcol.getThreshold()); - gcol.setThreshType(AnnotationColourGradient.NO_THRESHOLD); // default + gcol.setThreshold(newcol.getThreshold()); } if (newcol.getThreshType().length() > 0) { String ttyp = newcol.getThreshType(); - if (ttyp.equalsIgnoreCase("NONE")) - { - gcol.setThreshType(AnnotationColourGradient.NO_THRESHOLD); - } if (ttyp.equalsIgnoreCase("ABOVE")) { - gcol.setThreshType(AnnotationColourGradient.ABOVE_THRESHOLD); + gcol.setAboveThreshold(true); } if (ttyp.equalsIgnoreCase("BELOW")) { - gcol.setThreshType(AnnotationColourGradient.BELOW_THRESHOLD); + gcol.setBelowThreshold(true); } } fr.setColour(name = newcol.getName(), gcol); } else { - fr.setColour(name = jucs.getColour(i).getName(), new Color( - Integer.parseInt(jucs.getColour(i).getRGB(), 16))); + Color color = new Color( + Integer.parseInt(jucs.getColour(i).getRGB(), 16)); + fr.setColour(name = jucs.getColour(i).getName(), + new FeatureColour(color)); } fr.setOrder(name, (i == 0) ? 0 : i / jucs.getColourCount()); } @@ -823,12 +899,11 @@ public class FeatureSettings extends JPanel void save() { - JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "fc" }, new String[] - { "Sequence Feature Colours" }, "Sequence Feature Colours"); - chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle(MessageManager.getString("label.save_feature_colours")); + JalviewFileChooser chooser = new JalviewFileChooser("fc", + "Sequence Feature Colours"); + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle( + MessageManager.getString("label.save_feature_colours")); chooser.setToolTipText(MessageManager.getString("action.save")); int value = chooser.showSaveDialog(this); @@ -843,49 +918,40 @@ public class FeatureSettings extends JPanel PrintWriter out = new PrintWriter(new OutputStreamWriter( new FileOutputStream(choice), "UTF-8")); - Iterator e = fr.featureColours.keySet().iterator(); - float[] sortOrder = new float[fr.featureColours.size()]; - String[] sortTypes = new String[fr.featureColours.size()]; + Set fr_colours = fr.getAllFeatureColours(); + Iterator e = fr_colours.iterator(); + float[] sortOrder = new float[fr_colours.size()]; + String[] sortTypes = new String[fr_colours.size()]; int i = 0; while (e.hasNext()) { - sortTypes[i] = e.next().toString(); + sortTypes[i] = e.next(); sortOrder[i] = fr.getOrder(sortTypes[i]); i++; } - jalview.util.QuickSort.sort(sortOrder, sortTypes); + QuickSort.sort(sortOrder, sortTypes); sortOrder = null; - Object fcol; - GraduatedColor gcol; for (i = 0; i < sortTypes.length; i++) { jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour(); col.setName(sortTypes[i]); - col.setRGB(jalview.util.Format.getHexString(fr.getColour(col - .getName()))); - fcol = fr.getFeatureStyle(sortTypes[i]); - if (fcol instanceof GraduatedColor) + FeatureColourI fcol = fr.getFeatureStyle(sortTypes[i]); + if (fcol.isSimpleColour()) { - gcol = (GraduatedColor) fcol; - col.setMin(gcol.getMin()); - col.setMax(gcol.getMax()); - col.setMinRGB(jalview.util.Format.getHexString(gcol - .getMinColor())); - col.setAutoScale(gcol.isAutoScale()); - col.setThreshold(gcol.getThresh()); - col.setColourByLabel(gcol.isColourByLabel()); - switch (gcol.getThreshType()) - { - case AnnotationColourGradient.NO_THRESHOLD: - col.setThreshType("NONE"); - break; - case AnnotationColourGradient.ABOVE_THRESHOLD: - col.setThreshType("ABOVE"); - break; - case AnnotationColourGradient.BELOW_THRESHOLD: - col.setThreshType("BELOW"); - break; - } + col.setRGB(Format.getHexString(fcol.getColour())); + } + else + { + col.setRGB(Format.getHexString(fcol.getMaxColour())); + col.setMin(fcol.getMin()); + col.setMax(fcol.getMax()); + col.setMinRGB( + jalview.util.Format.getHexString(fcol.getMinColour())); + col.setAutoScale(fcol.isAutoScaled()); + col.setThreshold(fcol.getThreshold()); + col.setColourByLabel(fcol.isColourByLabel()); + col.setThreshType(fcol.isAboveThreshold() ? "ABOVE" + : (fcol.isBelowThreshold() ? "BELOW" : "NONE")); } ucs.addColour(col); } @@ -921,7 +987,7 @@ public class FeatureSettings extends JPanel int num = 0; for (int i = 0; i < data.length; i++) { - awidth = (float[]) typeWidth.get(data[i][0]); + awidth = typeWidth.get(data[i][0]); if (awidth[0] > 0) { width[i] = awidth[1] / awidth[0];// *awidth[0]*awidth[2]; - better @@ -962,9 +1028,9 @@ public class FeatureSettings extends JPanel } } if (sort) - { + { jalview.util.QuickSort.sort(width, data); - // update global priority order + // update global priority order } updateFeatureRenderer(data, false); @@ -987,10 +1053,19 @@ public class FeatureSettings extends JPanel updateFeatureRenderer(data, true); } + /** + * Update the priority order of features; only repaint if this changed the + * order of visible features + * + * @param data + * @param visibleNew + */ private void updateFeatureRenderer(Object[][] data, boolean visibleNew) { - fr.setFeaturePriority(data, visibleNew); - af.alignPanel.paintAlignment(true); + if (fr.setFeaturePriority(data, visibleNew)) + { + af.alignPanel.paintAlignment(true); + } } int selectedRow = -1; @@ -1043,10 +1118,15 @@ public class FeatureSettings extends JPanel settingsPane.setLayout(borderLayout2); dasSettingsPane.setLayout(borderLayout3); bigPanel.setLayout(borderLayout4); + + groupPanel = new JPanel(); + bigPanel.add(groupPanel, BorderLayout.NORTH); + invert.setFont(JvSwingUtils.getLabelFont()); invert.setText(MessageManager.getString("label.invert_selection")); invert.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { invertSelection(); @@ -1056,6 +1136,7 @@ public class FeatureSettings extends JPanel optimizeOrder.setText(MessageManager.getString("label.optimise_order")); optimizeOrder.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { orderByAvWidth(); @@ -1066,25 +1147,44 @@ public class FeatureSettings extends JPanel .setText(MessageManager.getString("label.seq_sort_by_score")); sortByScore.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - sortByScore(null); + af.avc.sortAlignmentByFeatureScore(null); } }); sortByDens.setFont(JvSwingUtils.getLabelFont()); - sortByDens.setText(MessageManager - .getString("label.sequence_sort_by_density")); + sortByDens.setText( + MessageManager.getString("label.sequence_sort_by_density")); sortByDens.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) + { + af.avc.sortAlignmentByFeatureDensity(null); + } + }); + help.setFont(JvSwingUtils.getLabelFont()); + help.setText(MessageManager.getString("action.help")); + help.addActionListener(new ActionListener() + { + @Override public void actionPerformed(ActionEvent e) { - sortByDens(null); + try + { + Help.showHelpWindow(HelpId.SequenceFeatureSettings); + } catch (HelpSetException e1) + { + e1.printStackTrace(); + } } }); help.setFont(JvSwingUtils.getLabelFont()); help.setText(MessageManager.getString("action.help")); help.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { try @@ -1100,8 +1200,10 @@ public class FeatureSettings extends JPanel cancel.setText(MessageManager.getString("action.cancel")); cancel.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { + fr.setTransparency(originalTransparency); updateFeatureRenderer(originalData); close(); } @@ -1110,6 +1212,7 @@ public class FeatureSettings extends JPanel ok.setText(MessageManager.getString("action.ok")); ok.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { close(); @@ -1119,6 +1222,7 @@ public class FeatureSettings extends JPanel loadColours.setText(MessageManager.getString("label.load_colours")); loadColours.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { load(); @@ -1128,6 +1232,7 @@ public class FeatureSettings extends JPanel saveColours.setText(MessageManager.getString("label.save_colours")); saveColours.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { save(); @@ -1135,19 +1240,24 @@ public class FeatureSettings extends JPanel }); transparency.addChangeListener(new ChangeListener() { + @Override public void stateChanged(ChangeEvent evt) { - fr.setTransparency((100 - transparency.getValue()) / 100f); - af.alignPanel.paintAlignment(true); + if (!inConstruction) + { + fr.setTransparency((100 - transparency.getValue()) / 100f); + af.alignPanel.paintAlignment(true); + } } }); transparency.setMaximum(70); - transparency.setToolTipText(MessageManager - .getString("label.transparency_tip")); + transparency.setToolTipText( + MessageManager.getString("label.transparency_tip")); fetchDAS.setText(MessageManager.getString("label.fetch_das_features")); fetchDAS.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { fetchDAS_actionPerformed(e); @@ -1156,6 +1266,7 @@ public class FeatureSettings extends JPanel saveDAS.setText(MessageManager.getString("action.save_as_default")); saveDAS.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { saveDAS_actionPerformed(e); @@ -1167,14 +1278,17 @@ public class FeatureSettings extends JPanel cancelDAS.setText(MessageManager.getString("action.cancel_fetch")); cancelDAS.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { cancelDAS_actionPerformed(e); } }); this.add(tabbedPane, java.awt.BorderLayout.CENTER); - tabbedPane.addTab(MessageManager.getString("label.feature_settings"), settingsPane); - tabbedPane.addTab(MessageManager.getString("label.das_settings"), dasSettingsPane); + tabbedPane.addTab(MessageManager.getString("label.feature_settings"), + settingsPane); + tabbedPane.addTab(MessageManager.getString("label.das_settings"), + dasSettingsPane); bigPanel.add(transPanel, java.awt.BorderLayout.SOUTH); transbuttons.add(optimizeOrder); transbuttons.add(invert); @@ -1198,137 +1312,13 @@ public class FeatureSettings extends JPanel settingsPane.add(buttonPanel, java.awt.BorderLayout.SOUTH); } - protected void sortByDens(String[] typ) - { - sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY); - } - - protected void sortBy(String[] typ, String methodText, final String method) - { - if (typ == null) - { - typ = getDisplayedFeatureTypes(); - } - String gps[] = null; - gps = getDisplayedFeatureGroups(); - if (typ != null) - { - ArrayList types = new ArrayList(); - for (int i = 0; i < typ.length; i++) - { - if (typ[i] != null) - { - types.add(typ[i]); - } - typ = new String[types.size()]; - types.toArray(typ); - } - } - if (gps != null) - { - ArrayList grps = new ArrayList(); - - for (int i = 0; i < gps.length; i++) - { - if (gps[i] != null) - { - grps.add(gps[i]); - } - } - gps = new String[grps.size()]; - grps.toArray(gps); - } - AlignmentPanel alignPanel = af.alignPanel; - AlignmentI al = alignPanel.av.getAlignment(); - - int start, stop; - SequenceGroup sg = alignPanel.av.getSelectionGroup(); - if (sg != null) - { - start = sg.getStartRes(); - stop = sg.getEndRes(); - } - else - { - start = 0; - stop = al.getWidth(); - } - SequenceI[] oldOrder = al.getSequencesArray(); - AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method); - af.addHistoryItem(new OrderCommand(methodText, oldOrder, alignPanel.av - .getAlignment())); - alignPanel.paintAlignment(true); - - } - - protected void sortByScore(String[] typ) - { - sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE); - } - - private String[] getDisplayedFeatureTypes() - { - String[] typ = null; - if (fr != null) - { - synchronized (fr.renderOrder) - { - typ = new String[fr.renderOrder.length]; - System.arraycopy(fr.renderOrder, 0, typ, 0, typ.length); - for (int i = 0; i < typ.length; i++) - { - if (af.viewport.getFeaturesDisplayed().get(typ[i]) == null) - { - typ[i] = null; - } - } - } - } - return typ; - } - - private String[] getDisplayedFeatureGroups() - { - String[] gps = null; - ArrayList _gps = new ArrayList(); - if (fr != null) - { - - if (fr.featureGroups != null) - { - Iterator en = fr.featureGroups.keySet().iterator(); - int g = 0; - boolean valid = false; - while (en.hasNext()) - { - String gp = (String) en.next(); - Boolean on = (Boolean) fr.featureGroups.get(gp); - if (on != null && on.booleanValue()) - { - valid = true; - _gps.add(gp); - } - } - if (!valid) - { - return null; - } - else - { - gps = new String[_gps.size()]; - _gps.toArray(gps); - } - } - } - return gps; - } - public void fetchDAS_actionPerformed(ActionEvent e) { fetchDAS.setEnabled(false); cancelDAS.setEnabled(true); dassourceBrowser.setGuiEnabled(false); - Vector selectedSources = dassourceBrowser.getSelectedSources(); + Vector selectedSources = dassourceBrowser + .getSelectedSources(); doDasFeatureFetch(selectedSources, true, true); } @@ -1344,7 +1334,7 @@ public class FeatureSettings extends JPanel { SequenceI[] dataset, seqs; int iSize; - AlignViewport vp = af.getViewport(); + AlignmentViewport vp = af.getViewport(); if (vp.getSelectionGroup() != null && vp.getSelectionGroup().getSize() > 0) { @@ -1387,7 +1377,7 @@ public class FeatureSettings extends JPanel * Vector of Strings to resolve to DAS source nicknames. * @return sources that are present in source list. */ - public List resolveSourceNicknames(Vector sources) + public List resolveSourceNicknames(Vector sources) { return dassourceBrowser.sourceRegistry.resolveSourceNicknames(sources); } @@ -1398,7 +1388,7 @@ public class FeatureSettings extends JPanel * * @return vector of selected das source nicknames */ - public Vector getSelectedSources() + public Vector getSelectedSources() { return dassourceBrowser.getSelectedSources(); } @@ -1412,7 +1402,7 @@ public class FeatureSettings extends JPanel * if true then runs in same thread, otherwise passes to the Swing * executor */ - public void fetchDasFeatures(Vector sources, boolean block) + public void fetchDasFeatures(Vector sources, boolean block) { initDasSources(); List resolved = dassourceBrowser.sourceRegistry @@ -1429,6 +1419,7 @@ public class FeatureSettings extends JPanel Runnable fetcher = new Runnable() { + @Override public void run() { doDasFeatureFetch(dassources, true, false); @@ -1472,15 +1463,10 @@ public class FeatureSettings extends JPanel public void noDasSourceActive() { complete(); - JOptionPane - .showInternalConfirmDialog( - Desktop.desktop, - MessageManager - .getString("label.no_das_sources_selected_warn"), - MessageManager - .getString("label.no_das_sources_selected_title"), - JOptionPane.DEFAULT_OPTION, - JOptionPane.INFORMATION_MESSAGE); + JvOptionPane.showInternalConfirmDialog(Desktop.desktop, + MessageManager.getString("label.no_das_sources_selected_warn"), + MessageManager.getString("label.no_das_sources_selected_title"), + JvOptionPane.DEFAULT_OPTION, JvOptionPane.INFORMATION_MESSAGE); } // /////////////////////////////////////////////////////////////////////// @@ -1493,8 +1479,10 @@ public class FeatureSettings extends JPanel this.data = data; } - private String[] columnNames = - { MessageManager.getString("label.feature_type"), MessageManager.getString("action.colour"), MessageManager.getString("label.display") }; + private String[] columnNames = { + MessageManager.getString("label.feature_type"), + MessageManager.getString("action.colour"), + MessageManager.getString("label.display") }; private Object[][] data; @@ -1508,6 +1496,7 @@ public class FeatureSettings extends JPanel this.data = data; } + @Override public int getColumnCount() { return columnNames.length; @@ -1518,31 +1507,37 @@ public class FeatureSettings extends JPanel return data[row]; } + @Override public int getRowCount() { return data.length; } + @Override public String getColumnName(int col) { return columnNames[col]; } + @Override public Object getValueAt(int row, int col) { return data[row][col]; } + @Override public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); } + @Override public boolean isCellEditable(int row, int col) { return col == 0 ? false : true; } + @Override public void setValueAt(Object value, int row, int col) { data[row][col] = value; @@ -1567,10 +1562,11 @@ public class FeatureSettings extends JPanel setVerticalTextPosition(SwingConstants.CENTER); } - public Component getTableCellRendererComponent(JTable table, - Object color, boolean isSelected, boolean hasFocus, int row, - int column) + @Override + public Component getTableCellRendererComponent(JTable tbl, Object color, + boolean isSelected, boolean hasFocus, int row, int column) { + FeatureColourI cellColour = (FeatureColourI) color; // JLabel comp = new JLabel(); // comp. setOpaque(true); @@ -1578,11 +1574,11 @@ public class FeatureSettings extends JPanel // setBounds(getBounds()); Color newColor; setToolTipText(baseTT); - setBackground(table.getBackground()); - if (color instanceof GraduatedColor) + setBackground(tbl.getBackground()); + if (!cellColour.isSimpleColour()) { - Rectangle cr = table.getCellRect(row, column, false); - FeatureSettings.renderGraduatedColor(this, (GraduatedColor) color, + Rectangle cr = tbl.getCellRect(row, column, false); + FeatureSettings.renderGraduatedColor(this, cellColour, (int) cr.getWidth(), (int) cr.getHeight()); } @@ -1590,20 +1586,16 @@ public class FeatureSettings extends JPanel { this.setText(""); this.setIcon(null); - newColor = (Color) color; - // comp. + newColor = cellColour.getColour(); setBackground(newColor); - // comp.setToolTipText("RGB value: " + newColor.getRed() + ", " - // + newColor.getGreen() + ", " + newColor.getBlue()); } if (isSelected) { if (selectedBorder == null) { selectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5, - table.getSelectionBackground()); + tbl.getSelectionBackground()); } - // comp. setBorder(selectedBorder); } else @@ -1611,9 +1603,8 @@ public class FeatureSettings extends JPanel if (unselectedBorder == null) { unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5, - table.getBackground()); + tbl.getBackground()); } - // comp. setBorder(unselectedBorder); } @@ -1627,7 +1618,7 @@ public class FeatureSettings extends JPanel * @param comp * @param gcol */ - public static void renderGraduatedColor(JLabel comp, GraduatedColor gcol) + public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol) { int w = comp.getWidth(), h = comp.getHeight(); if (w < 20) @@ -1643,23 +1634,23 @@ public class FeatureSettings extends JPanel renderGraduatedColor(comp, gcol, w, h); } - public static void renderGraduatedColor(JLabel comp, GraduatedColor gcol, + public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol, int w, int h) { boolean thr = false; String tt = ""; String tx = ""; - if (gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) + if (gcol.isAboveThreshold()) { thr = true; tx += ">"; - tt += "Thresholded (Above " + gcol.getThresh() + ") "; + tt += "Thresholded (Above " + gcol.getThreshold() + ") "; } - if (gcol.getThreshType() == AnnotationColourGradient.BELOW_THRESHOLD) + if (gcol.isBelowThreshold()) { thr = true; tx += "<"; - tt += "Thresholded (Below " + gcol.getThresh() + ") "; + tt += "Thresholded (Below " + gcol.getThreshold() + ") "; } if (gcol.isColourByLabel()) { @@ -1673,7 +1664,7 @@ public class FeatureSettings extends JPanel } else { - Color newColor = gcol.getMaxColor(); + Color newColor = gcol.getMaxColour(); comp.setBackground(newColor); // System.err.println("Width is " + w / 2); Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr); @@ -1701,7 +1692,7 @@ public class FeatureSettings extends JPanel class FeatureIcon implements Icon { - GraduatedColor gcol; + FeatureColourI gcol; Color backg; @@ -1713,7 +1704,7 @@ class FeatureIcon implements Icon Color mpcolour = Color.white; - FeatureIcon(GraduatedColor gfc, Color bg, int w, int h, boolean mspace) + FeatureIcon(FeatureColourI gfc, Color bg, int w, int h, boolean mspace) { gcol = gfc; backg = bg; @@ -1732,16 +1723,19 @@ class FeatureIcon implements Icon } } + @Override public int getIconWidth() { return width; } + @Override public int getIconHeight() { return height; } + @Override public void paintIcon(Component c, Graphics g, int x, int y) { @@ -1750,7 +1744,7 @@ class FeatureIcon implements Icon g.setColor(backg); g.fillRect(0, 0, width, height); // need an icon here. - g.setColor(gcol.getMaxColor()); + g.setColor(gcol.getMaxColour()); g.setFont(new Font("Verdana", Font.PLAIN, 9)); @@ -1764,7 +1758,7 @@ class FeatureIcon implements Icon } else { - Color minCol = gcol.getMinColor(); + Color minCol = gcol.getMinColour(); g.setColor(minCol); g.fillRect(0, 0, s1, height); if (midspace) @@ -1772,25 +1766,23 @@ class FeatureIcon implements Icon g.setColor(Color.white); g.fillRect(s1, 0, e1 - s1, height); } - g.setColor(gcol.getMaxColor()); + g.setColor(gcol.getMaxColour()); g.fillRect(0, e1, width - e1, height); } } } -class ColorEditor extends AbstractCellEditor implements TableCellEditor, - ActionListener +class ColorEditor extends AbstractCellEditor + implements TableCellEditor, ActionListener { FeatureSettings me; - GraduatedColor currentGColor; + FeatureColourI currentColor; FeatureColourChooser chooser; String type; - Color currentColor; - JButton button; JColorChooser colorChooser; @@ -1822,6 +1814,7 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor, /** * Handles events from the editor button and from the dialog's OK button. */ + @Override public void actionPerformed(ActionEvent e) { @@ -1829,11 +1822,11 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor, { // The user has clicked the cell, so // bring up the dialog. - if (currentColor != null) + if (currentColor.isSimpleColour()) { // bring up simple color chooser - button.setBackground(currentColor); - colorChooser.setColor(currentColor); + button.setBackground(currentColor.getColour()); + colorChooser.setColor(currentColor.getColour()); dialog.setVisible(true); } else @@ -1850,15 +1843,13 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor, } else { // User pressed dialog's "OK" button. - if (currentColor != null) + if (currentColor.isSimpleColour()) { - currentColor = colorChooser.getColor(); + currentColor = new FeatureColour(colorChooser.getColor()); } else { - // class cast exceptions may be raised if the chooser created on a - // non-graduated color - currentGColor = (GraduatedColor) chooser.getLastColour(); + currentColor = chooser.getLastColour(); } me.table.setValueAt(getCellEditorValue(), selectedRow, 1); fireEditingStopped(); @@ -1867,31 +1858,27 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor, } // Implement the one CellEditor method that AbstractCellEditor doesn't. + @Override public Object getCellEditorValue() { - if (currentColor == null) - { - return currentGColor; - } return currentColor; } // Implement the one method defined by TableCellEditor. + @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - currentGColor = null; - currentColor = null; + currentColor = (FeatureColourI) value; this.selectedRow = row; type = me.table.getValueAt(row, 0).toString(); button.setOpaque(true); button.setBackground(me.getBackground()); - if (value instanceof GraduatedColor) + if (!currentColor.isSimpleColour()) { - currentGColor = (GraduatedColor) value; JLabel btn = new JLabel(); btn.setSize(button.getSize()); - FeatureSettings.renderGraduatedColor(btn, currentGColor); + FeatureSettings.renderGraduatedColor(btn, currentColor); button.setBackground(btn.getBackground()); button.setIcon(btn.getIcon()); button.setText(btn.getText()); @@ -1900,8 +1887,7 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor, { button.setText(""); button.setIcon(null); - currentColor = (Color) value; - button.setBackground(currentColor); + button.setBackground(currentColor.getColour()); } return button; }