import jalview.datamodel.SequenceI;
import jalview.gui.Help.HelpId;
import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
import jalview.schemabinding.version2.JalviewUserColours;
import jalview.schemes.FeatureColour;
import jalview.util.Format;
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;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
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;
JPanel transPanel = new JPanel(new GridLayout(1, 2));
+ private static final int MIN_WIDTH = 400;
+
+ private static final int MIN_HEIGHT = 400;
+
+ /**
+ * Constructor
+ *
+ * @param af
+ */
public FeatureSettings(AlignFrame af)
{
this.af = af;
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.getMinMax(),
else if (evt.getClickCount() == 2)
{
boolean invertSelection = evt.isAltDown();
- boolean ctrlDown = Platform.isControlDown(evt);
- boolean toggleSelection = ctrlDown;
- boolean extendSelection = evt.isShiftDown() || ctrlDown;
+ boolean toggleSelection = Platform.isControlDown(evt);
+ boolean extendSelection = evt.isShiftDown();
fr.ap.alignFrame.avc.markColumnsContainingFeatures(
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)
{
MessageManager.getString("label.sequence_feature_settings"),
400, 450);
}
+ frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
{
{
boolean visible = fr.checkGroupVisibility(group, true);
- if (groupPanel == null)
- {
- groupPanel = new JPanel();
- }
-
- 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 visible;
- }
final String grp = group;
final JCheckBox check = new JCheckBox(group, visible);
check.setFont(new Font("Serif", Font.BOLD, 12));
SequenceFeature[] tmpfeatures;
String group = null, type;
Vector<String> visibleChecks = new Vector<String>();
+ Set<String> foundGroups = new HashSet<String>();
// Find out which features should be visible depending on which groups
// are selected / deselected
while (index < tmpfeatures.length)
{
group = tmpfeatures[index].featureGroup;
+ foundGroups.add(group);
if (tmpfeatures[index].begin == 0 && tmpfeatures[index].end == 0)
{
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.getFeatureGroupsSize() / 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
+ * <ul>
+ * <li>a new feature type added (and made visible)</li>
+ * <li>a feature colour changed (in the Amend Features dialog)</li>
+ * </ul>
+ *
+ * @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<String> 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
void load()
{
- JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
- new String[] { "fc" },
- new String[] { "Sequence Feature Colours" },
+ JalviewFileChooser chooser = new JalviewFileChooser("fc",
"Sequence Feature Colours");
- chooser.setFileView(new jalview.io.JalviewFileView());
+ chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager
.getString("label.load_feature_colours"));
chooser.setToolTipText(MessageManager.getString("action.load"));
void save()
{
- JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"),
- new String[] { "fc" },
- new String[] { "Sequence Feature Colours" },
+ JalviewFileChooser chooser = new JalviewFileChooser("fc",
"Sequence Feature Colours");
- chooser.setFileView(new jalview.io.JalviewFileView());
+ chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager
.getString("label.save_feature_colours"));
chooser.setToolTipText(MessageManager.getString("action.save"));
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()
public void noDasSourceActive()
{
complete();
- JOptionPane
+ JvOptionPane
.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.DEFAULT_OPTION,
+ JvOptionPane.INFORMATION_MESSAGE);
}
// ///////////////////////////////////////////////////////////////////////