X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=22101487a711fb87e6d202a02bde3503cf92fac0;hb=9d139ca8d1af8f0f2d78193d418ae9e9168a3e8a;hp=9f73873b8662a0fccd3310f140f6c495fde370f5;hpb=865a855a4ca87eadb3e5ff284ed32ed307d9c34b;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java old mode 100755 new mode 100644 index 9f73873..2210148 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -1,45 +1,96 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1) + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) * Copyright (C) 2014 The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.gui; -import java.io.*; -import java.util.*; -import java.util.List; - -import java.awt.*; -import java.awt.event.*; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -import javax.swing.*; -import javax.swing.event.*; -import javax.swing.table.*; - import jalview.analysis.AlignmentSorter; import jalview.bin.Cache; import jalview.commands.OrderCommand; -import jalview.datamodel.*; -import jalview.io.*; +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.util.MessageManager; import jalview.ws.dbsources.das.api.jalviewSourceI; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.GridLayout; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import javax.help.HelpSetException; +import javax.swing.AbstractCellEditor; +import javax.swing.BorderFactory; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JColorChooser; +import javax.swing.JDialog; +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; +import javax.swing.JSlider; +import javax.swing.JTabbedPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; + public class FeatureSettings extends JPanel { DasSourceBrowser dassourceBrowser; @@ -83,7 +134,19 @@ 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) { + /* + * Tooltip for feature name only + */ + return JvSwingUtils.wrapTooltip(true, + MessageManager.getString("label.feature_settings_click_drag")); + } + return null; + } + }; table.getTableHeader().setFont(new Font("Verdana", Font.PLAIN, 12)); table.setFont(new Font("Verdana", Font.PLAIN, 12)); table.setDefaultRenderer(Color.class, new ColorRenderer()); @@ -99,7 +162,27 @@ public class FeatureSettings extends JPanel public void mousePressed(MouseEvent evt) { selectedRow = table.rowAtPoint(evt.getPoint()); - if (javax.swing.SwingUtilities.isRightMouseButton(evt)) + if (SwingUtilities.isRightMouseButton(evt)) + { + popupSort(selectedRow, (String) table.getValueAt(selectedRow, 0), + table.getValueAt(selectedRow, 1), fr.minmax, evt.getX(), + evt.getY()); + } + else if (evt.getClickCount() == 2) + { + fr.ap.alignFrame.avc.markColumnsContainingFeatures( + evt.isAltDown(), evt.isShiftDown() || evt.isMetaDown(), + evt.isMetaDown(), + (String) table.getValueAt(selectedRow, 0)); + } + } + + // isPopupTrigger fires on mouseReleased on Mac + @Override + public void mouseReleased(MouseEvent evt) + { + selectedRow = table.rowAtPoint(evt.getPoint()); + if (evt.isPopupTrigger()) { popupSort(selectedRow, (String) table.getValueAt(selectedRow, 0), table.getValueAt(selectedRow, 1), fr.minmax, evt.getX(), @@ -132,7 +215,8 @@ public class FeatureSettings extends JPanel } } }); - +// table.setToolTipText(JvSwingUtils.wrapTooltip(true, +// MessageManager.getString("label.feature_settings_click_drag"))); scrollPane.setViewportView(table); dassourceBrowser = new DasSourceBrowser(this); @@ -166,11 +250,15 @@ public class FeatureSettings extends JPanel frame.setContentPane(this); if (new jalview.util.Platform().isAMac()) { - Desktop.addInternalFrame(frame, "Sequence Feature Settings", 475, 480); + Desktop.addInternalFrame(frame, + MessageManager.getString("label.sequence_feature_settings"), + 475, 480); } else { - Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 450); + Desktop.addInternalFrame(frame, + MessageManager.getString("label.sequence_feature_settings"), + 400, 450); } frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() @@ -188,8 +276,11 @@ public class FeatureSettings extends JPanel protected void popupSort(final int selectedRow, final String type, final Object typeCol, final Hashtable minmax, int x, int y) { - JPopupMenu men = new JPopupMenu("Settings for " + type); - JMenuItem scr = new JMenuItem("Sort by Score"); + 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() @@ -202,7 +293,8 @@ public class FeatureSettings extends JPanel } }); - JMenuItem dens = new JMenuItem("Sort by Density"); + JMenuItem dens = new JMenuItem( + MessageManager.getString("label.sort_by_density")); dens.addActionListener(new ActionListener() { @@ -291,6 +383,32 @@ public class FeatureSettings extends JPanel }); } } + JMenuItem selCols = new JMenuItem( + MessageManager.getString("label.select_columns_containing")); + selCols.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent arg0) + { + fr.ap.alignFrame.avc.markColumnsContainingFeatures(false, false, + false, type); + } + }); + JMenuItem clearCols = new JMenuItem( + MessageManager.getString("label.select_columns_not_containing")); + clearCols.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent arg0) + { + fr.ap.alignFrame.avc.markColumnsContainingFeatures(true, false, + false, type); + } + }); + men.add(selCols); + men.add(clearCols); men.show(table, x, y); } @@ -468,7 +586,9 @@ public class FeatureSettings extends JPanel || ((Boolean) fr.featureGroups.get(group)).booleanValue()) { if (group != null) + { checkGroupState(group); + } type = tmpfeatures[index].getType(); if (!visibleChecks.contains(type)) { @@ -506,7 +626,9 @@ public class FeatureSettings extends JPanel if (fr.renderOrder != null) { if (!handlingUpdate) + { fr.findAllFeatures(groupChanged != null); // prod to update + } // colourschemes. but don't // affect display // First add the checks in the previous render order, @@ -587,12 +709,18 @@ public class FeatureSettings extends JPanel { order[i] = fr.getOrder(data[i][0].toString()); if (order[i] < 0) + { order[i] = fr.setOrder(data[i][0].toString(), i / order.length); + } if (i > 1) + { sort = sort || order[i - 1] > order[i]; + } } if (sort) + { jalview.util.QuickSort.sort(order, data); + } } void load() @@ -602,8 +730,8 @@ public class FeatureSettings extends JPanel { "fc" }, new String[] { "Sequence Feature Colours" }, "Sequence Feature Colours"); chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle("Load Feature Colours"); - chooser.setToolTipText("Load"); + chooser.setDialogTitle(MessageManager.getString("label.load_feature_colours")); + chooser.setToolTipText(MessageManager.getString("action.load")); int value = chooser.showOpenDialog(this); @@ -617,7 +745,7 @@ public class FeatureSettings extends JPanel file), "UTF-8"); jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours(); - jucs = (jalview.schemabinding.version2.JalviewUserColours) jucs + jucs = jucs .unmarshal(in); for (int i = jucs.getColourCount() - 1; i >= 0; i--) @@ -700,8 +828,8 @@ public class FeatureSettings extends JPanel { "fc" }, new String[] { "Sequence Feature Colours" }, "Sequence Feature Colours"); chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle("Save Feature Colour Scheme"); - chooser.setToolTipText("Save"); + chooser.setDialogTitle(MessageManager.getString("label.save_feature_colours")); + chooser.setToolTipText(MessageManager.getString("action.save")); int value = chooser.showSaveDialog(this); @@ -783,7 +911,9 @@ public class FeatureSettings extends JPanel public void orderByAvWidth() { if (table == null || table.getModel() == null) + { return; + } Object[][] data = ((FeatureTableModel) table.getModel()).getData(); float[] width = new float[data.length]; float[] awidth; @@ -805,7 +935,9 @@ public class FeatureSettings extends JPanel width[i] = 0; } if (max < width[i]) + { max = width[i]; + } } boolean sort = false; for (int i = 0; i < width.length; i++) @@ -825,11 +957,15 @@ public class FeatureSettings extends JPanel fr.setOrder(data[i][0].toString(), width[i]); // store for later } if (i > 0) + { sort = sort || width[i - 1] > width[i]; + } } if (sort) + { jalview.util.QuickSort.sort(width, data); // update global priority order + } updateFeatureRenderer(data, false); table.repaint(); @@ -897,7 +1033,9 @@ public class FeatureSettings extends JPanel JButton sortByDens = new JButton(); - JPanel transbuttons = new JPanel(new GridLayout(4, 1)); + JButton help = new JButton(); + + JPanel transbuttons = new JPanel(new GridLayout(5, 1)); private void jbInit() throws Exception { @@ -906,7 +1044,7 @@ public class FeatureSettings extends JPanel dasSettingsPane.setLayout(borderLayout3); bigPanel.setLayout(borderLayout4); invert.setFont(JvSwingUtils.getLabelFont()); - invert.setText("Invert Selection"); + invert.setText(MessageManager.getString("label.invert_selection")); invert.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -915,7 +1053,7 @@ public class FeatureSettings extends JPanel } }); optimizeOrder.setFont(JvSwingUtils.getLabelFont()); - optimizeOrder.setText("Optimise Order"); + optimizeOrder.setText(MessageManager.getString("label.optimise_order")); optimizeOrder.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -924,7 +1062,8 @@ public class FeatureSettings extends JPanel } }); sortByScore.setFont(JvSwingUtils.getLabelFont()); - sortByScore.setText("Seq sort by Score"); + sortByScore + .setText(MessageManager.getString("label.seq_sort_by_score")); sortByScore.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -933,7 +1072,8 @@ public class FeatureSettings extends JPanel } }); sortByDens.setFont(JvSwingUtils.getLabelFont()); - sortByDens.setText("Seq Sort by density"); + sortByDens.setText(MessageManager + .getString("label.sequence_sort_by_density")); sortByDens.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -941,8 +1081,23 @@ public class FeatureSettings extends JPanel sortByDens(null); } }); + help.setFont(JvSwingUtils.getLabelFont()); + help.setText(MessageManager.getString("action.help")); + help.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + try + { + Help.showHelpWindow(HelpId.SequenceFeatureSettings); + } catch (HelpSetException e1) + { + e1.printStackTrace(); + } + } + }); cancel.setFont(JvSwingUtils.getLabelFont()); - cancel.setText("Cancel"); + cancel.setText(MessageManager.getString("action.cancel")); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -952,7 +1107,7 @@ public class FeatureSettings extends JPanel } }); ok.setFont(JvSwingUtils.getLabelFont()); - ok.setText("OK"); + ok.setText(MessageManager.getString("action.ok")); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -961,7 +1116,7 @@ public class FeatureSettings extends JPanel } }); loadColours.setFont(JvSwingUtils.getLabelFont()); - loadColours.setText("Load Colours"); + loadColours.setText(MessageManager.getString("label.load_colours")); loadColours.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -970,7 +1125,7 @@ public class FeatureSettings extends JPanel } }); saveColours.setFont(JvSwingUtils.getLabelFont()); - saveColours.setText("Save Colours"); + saveColours.setText(MessageManager.getString("label.save_colours")); saveColours.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -982,13 +1137,15 @@ public class FeatureSettings extends JPanel { public void stateChanged(ChangeEvent evt) { - fr.setTransparency((float) (100 - transparency.getValue()) / 100f); + fr.setTransparency((100 - transparency.getValue()) / 100f); af.alignPanel.paintAlignment(true); } }); transparency.setMaximum(70); - fetchDAS.setText("Fetch DAS Features"); + transparency.setToolTipText(MessageManager + .getString("label.transparency_tip")); + fetchDAS.setText(MessageManager.getString("label.fetch_das_features")); fetchDAS.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -996,7 +1153,7 @@ public class FeatureSettings extends JPanel fetchDAS_actionPerformed(e); } }); - saveDAS.setText("Save as default"); + saveDAS.setText(MessageManager.getString("action.save_as_default")); saveDAS.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -1007,7 +1164,7 @@ public class FeatureSettings extends JPanel dasButtonPanel.setBorder(BorderFactory.createEtchedBorder()); dasSettingsPane.setBorder(null); cancelDAS.setEnabled(false); - cancelDAS.setText("Cancel Fetch"); + cancelDAS.setText(MessageManager.getString("action.cancel_fetch")); cancelDAS.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) @@ -1016,13 +1173,16 @@ public class FeatureSettings extends JPanel } }); this.add(tabbedPane, java.awt.BorderLayout.CENTER); - tabbedPane.addTab("Feature Settings", settingsPane); - tabbedPane.addTab("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); transbuttons.add(sortByScore); transbuttons.add(sortByDens); + transbuttons.add(help); + JPanel sliderPanel = new JPanel(); + sliderPanel.add(transparency); transPanel.add(transparency); transPanel.add(transbuttons); buttonPanel.add(ok); @@ -1130,13 +1290,13 @@ public class FeatureSettings extends JPanel private String[] getDisplayedFeatureGroups() { String[] gps = null; + ArrayList _gps = new ArrayList(); if (fr != null) { if (fr.featureGroups != null) { Iterator en = fr.featureGroups.keySet().iterator(); - gps = new String[fr.featureColours.size()]; int g = 0; boolean valid = false; while (en.hasNext()) @@ -1146,17 +1306,18 @@ public class FeatureSettings extends JPanel if (on != null && on.booleanValue()) { valid = true; - gps[g++] = gp; + _gps.add(gp); } } - while (g < gps.length) - { - gps[g++] = null; - } if (!valid) { return null; } + else + { + gps = new String[_gps.size()]; + _gps.toArray(gps); + } } } return gps; @@ -1311,11 +1472,15 @@ public class FeatureSettings extends JPanel public void noDasSourceActive() { complete(); - JOptionPane.showInternalConfirmDialog(Desktop.desktop, - "No das sources were selected.\n" - + "Please select some sources and\n" + " try again.", - "No Sources Selected", JOptionPane.DEFAULT_OPTION, - JOptionPane.INFORMATION_MESSAGE); + 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); } // /////////////////////////////////////////////////////////////////////// @@ -1329,7 +1494,7 @@ public class FeatureSettings extends JPanel } private String[] columnNames = - { "Feature Type", "Colour", "Display" }; + { MessageManager.getString("label.feature_type"), MessageManager.getString("action.colour"), MessageManager.getString("label.display") }; private Object[][] data; @@ -1594,7 +1759,7 @@ class FeatureIcon implements Icon // width/g.getFontMetrics().stringWidth("Label"), // height/g.getFontMetrics().getHeight()))); - g.drawString("Label", 0, 0); + g.drawString(MessageManager.getString("label.label"), 0, 0); } else