X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPreferences.java;h=7c0ac95997936e8f6cb588624b095c80b7ba7a70;hb=60230a4056ce0094603ca68c6596129e1048dc85;hp=550f32457d40bd869c46fac59e059c85a3c16406;hpb=44fc22cf950ff114ce3a5a07600e7a7eb5fd1216;p=jalview.git diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 550f324..7c0ac95 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -22,17 +22,26 @@ package jalview.gui; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.bin.Cache; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenMarkovModel; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; import jalview.gui.Help.HelpId; import jalview.gui.StructureViewer.ViewerType; +import jalview.hmmer.HMMBuildThread; +import jalview.io.FileFormatI; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.jbgui.GPreferences; import jalview.jbgui.GSequenceLink; -import jalview.schemes.ColourSchemeProperty; -import jalview.urls.DesktopUrlProviderFactory; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.ColourSchemes; +import jalview.schemes.ResidueColourScheme; import jalview.urls.UrlLinkTableModel; -import jalview.urls.UrlProviderFactoryI; -import jalview.urls.UrlProviderI; +import jalview.urls.api.UrlProviderFactoryI; +import jalview.urls.api.UrlProviderI; +import jalview.urls.desktop.DesktopUrlProviderFactory; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.util.UrlConstants; @@ -49,12 +58,12 @@ import java.awt.event.MouseEvent; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Scanner; import javax.help.HelpSetException; import javax.swing.JColorChooser; import javax.swing.JFileChooser; import javax.swing.JInternalFrame; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.ListSelectionModel; import javax.swing.RowFilter; @@ -100,11 +109,19 @@ public class Preferences extends GPreferences public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY"; public static final String CHIMERA_PATH = "CHIMERA_PATH"; + + public static final String HMMER_PATH = "HMMER_PATH"; + + public static final String HMMSEARCH_DB_PATHS = "HMMSEARCH_DB_PATHS"; + + public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS"; public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS"; public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE"; + public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY"; + private static final int MIN_FONT_SIZE = 1; private static final int MAX_FONT_SIZE = 30; @@ -128,10 +145,21 @@ public class Preferences extends GPreferences public static List groupURLLinks; static { - String string = Cache.getDefault("SEQUENCE_LINKS", - UrlConstants.DEFAULT_STRING); - UrlProviderFactoryI factory = new DesktopUrlProviderFactory( - UrlConstants.DEFAULT_LABEL, string); + // get links selected to be in the menu (SEQUENCE_LINKS) + // and links entered by the user but not selected (STORED_LINKS) + String inMenuString = Cache.getDefault("SEQUENCE_LINKS", ""); + String notInMenuString = Cache.getDefault("STORED_LINKS", ""); + String defaultUrl = Cache.getDefault("DEFAULT_URL", + UrlConstants.DEFAULT_LABEL); + + // if both links lists are empty, add the DEFAULT_URL link + // otherwise we assume the default link is in one of the lists + if (inMenuString.isEmpty() && notInMenuString.isEmpty()) + { + inMenuString = UrlConstants.DEFAULT_STRING; + } + UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl, + inMenuString, notInMenuString); sequenceUrlLinks = factory.createUrlProvider(); dataModel = new UrlLinkTableModel(sequenceUrlLinks); @@ -140,7 +168,7 @@ public class Preferences extends GPreferences * .properties file as '|' separated strings */ - groupURLLinks = new ArrayList(); + groupURLLinks = new ArrayList<>(); } JInternalFrame frame; @@ -184,6 +212,34 @@ public class Preferences extends GPreferences frame.setMinimumSize(new Dimension(width, height)); /* + * Set HMMER tab defaults + */ + trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false)); + isHMMERInstalled + .setSelected(Cache.getDefault("HMMER_INSTALLED", false)); + if (Cache.getDefault("USE_UNIPROT", false)) + { + uniprot.setSelected(true); + } + else + { + alignment.setSelected(true); + } + numberOfSequencesToKeepField + .setText(Cache.getProperty("SEQUENCES_TO_KEEP")); + installationLocation.setEnabled(isHMMERInstalled.isSelected()); + hmmerPath.setEnabled(isHMMERInstalled.isSelected()); + hmmerPath.setText(Cache.getProperty(HMMER_PATH)); + hmmerPath.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + validateHMMERPath(); + } + }); + + /* * Set Visual tab defaults */ seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true)); @@ -197,18 +253,22 @@ public class Preferences extends GPreferences openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false)); showUnconserved .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false)); - showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", - false)); - showGroupConservation.setSelected(Cache.getDefault( - "SHOW_GROUP_CONSERVATION", false)); - showConsensHistogram.setSelected(Cache.getDefault( - "SHOW_CONSENSUS_HISTOGRAM", true)); - showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", - false)); - showNpTooltip.setSelected(Cache - .getDefault("SHOW_NPFEATS_TOOLTIP", true)); - showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", - true)); + showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false)); + showGroupConsensus + .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false)); + showGroupConservation.setSelected( + Cache.getDefault("SHOW_GROUP_CONSERVATION", false)); + showConsensHistogram.setSelected( + Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true)); + showConsensLogo + .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false)); + showInformationHistogram.setSelected( + Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true)); + showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false)); + showNpTooltip + .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true)); + showDbRefTooltip + .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true)); String[] fonts = java.awt.GraphicsEnvironment .getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); @@ -228,12 +288,12 @@ public class Preferences extends GPreferences fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif")); fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10")); - fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN - + "")); + fontStyleCB.setSelectedItem( + Cache.getDefault("FONT_STYLE", Font.PLAIN + "")); smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false)); - scaleProteinToCdna.setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, - false)); + scaleProteinToCdna + .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false)); idItalics.setSelected(Cache.getDefault("ID_ITALICS", true)); @@ -273,20 +333,24 @@ public class Preferences extends GPreferences /* * Set Colours tab defaults */ - for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++) + protColour.addItem(ResidueColourScheme.NONE); + nucColour.addItem(ResidueColourScheme.NONE); + for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes()) { - protColour.addItem(ColourSchemeProperty.getColourName(i)); - nucColour.addItem(ColourSchemeProperty.getColourName(i)); + String name = cs.getSchemeName(); + protColour.addItem(name); + nucColour.addItem(name); } - String oldProp = Cache.getDefault(DEFAULT_COLOUR, "None"); + String oldProp = Cache.getDefault(DEFAULT_COLOUR, + ResidueColourScheme.NONE); String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null); protColour.setSelectedItem(newProp != null ? newProp : oldProp); newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null); nucColour.setSelectedItem(newProp != null ? newProp : oldProp); - minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", - Color.orange)); - maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", - Color.red)); + minColour.setBackground( + Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange)); + maxColour.setBackground( + Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red)); /* * Set Structure tab defaults. @@ -299,8 +363,8 @@ public class Preferences extends GPreferences addSecondaryStructure.setEnabled(structSelected); addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false)); addTempFactor.setEnabled(structSelected); - structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY, - ViewerType.JMOL.name())); + structViewer.setSelectedItem( + Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name())); chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, "")); chimeraPath.addActionListener(new ActionListener() { @@ -334,14 +398,17 @@ public class Preferences extends GPreferences linkUrlTable.setRowSorter(sorter); List sortKeys = new ArrayList<>(); - sortKeys.add(new RowSorter.SortKey(3, + UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel(); + sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(), + SortOrder.DESCENDING)); + sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(), SortOrder.DESCENDING)); - sortKeys.add(new RowSorter.SortKey(2, SortOrder.DESCENDING)); - sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING)); + sortKeys.add( + new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); - + // set up filtering ActionListener onReset; onReset = new ActionListener() @@ -363,8 +430,7 @@ public class Preferences extends GPreferences public boolean include( Entry entry) { - String id = entry.getStringValue(4); - return sequenceUrlLinks.isUserEntry(id); + return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry); } }; @@ -386,36 +452,41 @@ public class Preferences extends GPreferences filterTB.getDocument().addDocumentListener(new DocumentListener() { + String caseInsensitiveFlag = "(?i)"; + @Override public void changedUpdate(DocumentEvent e) { - sorter.setRowFilter(RowFilter.regexFilter("(?i)" - + filterTB.getText())); + sorter.setRowFilter(RowFilter + .regexFilter(caseInsensitiveFlag + filterTB.getText())); } @Override public void removeUpdate(DocumentEvent e) { - sorter.setRowFilter(RowFilter.regexFilter("(?i)" - + filterTB.getText())); + sorter.setRowFilter(RowFilter + .regexFilter(caseInsensitiveFlag + filterTB.getText())); } @Override public void insertUpdate(DocumentEvent e) { - sorter.setRowFilter(RowFilter.regexFilter("(?i)" - + filterTB.getText())); + sorter.setRowFilter(RowFilter + .regexFilter(caseInsensitiveFlag + filterTB.getText())); } }); // set up list selection functionality - linkUrlTable.getSelectionModel().addListSelectionListener( - new UrlListSelectionHandler()); + linkUrlTable.getSelectionModel() + .addListSelectionListener(new UrlListSelectionHandler()); // set up radio buttons - linkUrlTable.getColumn("Default").setCellRenderer( - new RadioButtonRenderer()); - linkUrlTable.getColumn("Default") + int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getPrimaryColumn(); + String onClickName = linkUrlTable.getColumnName(onClickCol); + linkUrlTable.getColumn(onClickName) + .setCellRenderer(new RadioButtonRenderer()); + linkUrlTable.getColumn(onClickName) .setCellEditor(new RadioButtonEditor()); // get boolean columns and resize those to min possible @@ -424,8 +495,8 @@ public class Preferences extends GPreferences if (linkUrlTable.getModel().getColumnClass(column) .equals(Boolean.class)) { - TableColumn tableColumn = linkUrlTable.getColumnModel().getColumn( - column); + TableColumn tableColumn = linkUrlTable.getColumnModel() + .getColumn(column); int preferredWidth = tableColumn.getMinWidth(); TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0, @@ -441,8 +512,6 @@ public class Preferences extends GPreferences useProxy.setSelected(Cache.getDefault("USE_PROXY", false)); useProxy_actionPerformed(); // make sure useProxy is correctly initialised - proxyServerTB.setEnabled(useProxy.isSelected()); - proxyPortTB.setEnabled(useProxy.isSelected()); proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", "")); proxyPortTB.setText(Cache.getDefault("PROXY_PORT", "")); @@ -487,14 +556,14 @@ public class Preferences extends GPreferences pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true)); pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true)); modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false)); - embbedBioJSON.setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", - true)); + embbedBioJSON + .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true)); /* * Set Editing tab defaults */ - autoCalculateConsCheck.setSelected(Cache.getDefault( - "AUTO_CALC_CONSENSUS", true)); + autoCalculateConsCheck + .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true)); padGaps.setSelected(Cache.getDefault("PAD_GAPS", false)); sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false)); @@ -536,20 +605,22 @@ public class Preferences extends GPreferences Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean.toString(identity.isSelected())); - Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB - .getSelectedItem().toString()); + Cache.applicationProperties.setProperty("GAP_SYMBOL", + gapSymbolCB.getSelectedItem().toString()); - Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB - .getSelectedItem().toString()); - Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB - .getSelectedItem().toString()); - Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB - .getSelectedItem().toString()); + Cache.applicationProperties.setProperty("FONT_NAME", + fontNameCB.getSelectedItem().toString()); + Cache.applicationProperties.setProperty("FONT_STYLE", + fontStyleCB.getSelectedItem().toString()); + Cache.applicationProperties.setProperty("FONT_SIZE", + fontSizeCB.getSelectedItem().toString()); Cache.applicationProperties.setProperty("ID_ITALICS", Boolean.toString(idItalics.isSelected())); Cache.applicationProperties.setProperty("SHOW_UNCONSERVED", Boolean.toString(showUnconserved.isSelected())); + Cache.applicationProperties.setProperty(SHOW_OCCUPANCY, + Boolean.toString(showOccupancy.isSelected())); Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS", Boolean.toString(showGroupConsensus.isSelected())); Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION", @@ -558,6 +629,10 @@ public class Preferences extends GPreferences Boolean.toString(showConsensHistogram.isSelected())); Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO", Boolean.toString(showConsensLogo.isSelected())); + Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM", + Boolean.toString(showConsensHistogram.isSelected())); + Cache.applicationProperties.setProperty("SHOW_HMM_LOGO", + Boolean.toString(showHMMLogo.isSelected())); Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected())); Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA, @@ -575,8 +650,8 @@ public class Preferences extends GPreferences Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean.toString(startupCheckbox.isSelected())); - Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby - .getSelectedItem().toString()); + Cache.applicationProperties.setProperty("SORT_ALIGNMENT", + sortby.getSelectedItem().toString()); // convert description of sort order to enum name for save SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder @@ -588,22 +663,60 @@ public class Preferences extends GPreferences } final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0; - Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE, Boolean - .valueOf(showAutocalcFirst).toString()); + Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE, + Boolean.valueOf(showAutocalcFirst).toString()); /* * Save Colours settings */ - Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, protColour - .getSelectedItem().toString()); - Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, nucColour - .getSelectedItem().toString()); + Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, + protColour.getSelectedItem().toString()); + Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, + nucColour.getSelectedItem().toString()); Cache.setColourProperty("ANNOTATIONCOLOUR_MIN", minColour.getBackground()); Cache.setColourProperty("ANNOTATIONCOLOUR_MAX", maxColour.getBackground()); /* + * Save HMMER settings + */ + Cache.applicationProperties.setProperty("TRIM_TERMINI", + Boolean.toString(trimTermini.isSelected())); + Cache.applicationProperties.setProperty("USE_UNIPROT", + Boolean.toString(uniprot.isSelected())); + Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP", + numberOfSequencesToKeepField.getText()); + Cache.applicationProperties.setProperty(HMMER_PATH, + hmmerPath.getText()); + boolean hmmerInstalled = isHMMERInstalled.isSelected(); + Cache.applicationProperties.setProperty("HMMER_INSTALLED", + Boolean.toString(hmmerInstalled)); + boolean hmmerFunctioning = validateHMMERPath(false); + Cache.applicationProperties.setProperty("HMMER_FUNCTIONING", + Boolean.toString(hmmerFunctioning)); + AlignFrame[] frames = Desktop.getAlignFrames(); + boolean hmmerStatus = hmmerFunctioning && hmmerInstalled ? true : false; + for (AlignFrame frame : frames) + { + frame.updateHMMERStatus(hmmerStatus); + } + + + trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false)); + if (Cache.getDefault("USE_UNIPROT", false)) + { + uniprot.setSelected(true); + } + else + { + alignment.setSelected(true); + } + numberOfSequencesToKeepField + .setText(Cache.getProperty("SEQUENCES_TO_KEEP")); + hmmerPath.setText(Cache.getProperty(HMMER_PATH)); + + /* * Save Structure settings */ Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN, @@ -614,8 +727,8 @@ public class Preferences extends GPreferences Boolean.toString(useRnaView.isSelected())); Cache.applicationProperties.setProperty(STRUCT_FROM_PDB, Boolean.toString(structFromPdb.isSelected())); - Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY, structViewer - .getSelectedItem().toString()); + Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY, + structViewer.getSelectedItem().toString()); Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText()); Cache.applicationProperties.setProperty("MAP_WITH_SIFTS", Boolean.toString(siftsMapping.isSelected())); @@ -635,17 +748,31 @@ public class Preferences extends GPreferences jalview.util.BrowserLauncher.resetBrowser(); // save user-defined and selected links - String links = linkUrlTable.getModel().toString(); - if (links.isEmpty()) + String menuLinks = sequenceUrlLinks.writeUrlsAsString(true); + if (menuLinks.isEmpty()) { Cache.applicationProperties.remove("SEQUENCE_LINKS"); } else { Cache.applicationProperties.setProperty("SEQUENCE_LINKS", - links.toString()); + menuLinks.toString()); } + String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false); + if (nonMenuLinks.isEmpty()) + { + Cache.applicationProperties.remove("STORED_LINKS"); + } + else + { + Cache.applicationProperties.setProperty("STORED_LINKS", + nonMenuLinks.toString()); + } + + Cache.applicationProperties.setProperty("DEFAULT_URL", + sequenceUrlLinks.getPrimaryUrlId()); + Cache.applicationProperties.setProperty("USE_PROXY", Boolean.toString(useProxy.isSelected())); @@ -746,6 +873,14 @@ public class Preferences extends GPreferences structureTab.requestFocusInWindow(); return false; } + if (isHMMERInstalled.isSelected()) + { + if (!validateHMMER()) + { + hmmerTab.requestFocusInWindow(); + return false; + } + } return true; } @@ -756,30 +891,38 @@ public class Preferences extends GPreferences } + @Override + protected boolean validateHMMER() + { + return validateHMMERPath(); + + } + /** * DOCUMENT ME! */ @Override public void startupFileTextfield_mouseClicked() { - JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] { - "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", - "jar" }, new String[] { "Fasta", "Clustal", "PFAM", "MSF", - "PIR", "BLC", "Jalview" }, - jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT")); + String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + JalviewFileChooser chooser = JalviewFileChooser + .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat); chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle(MessageManager - .getString("label.select_startup_file")); + chooser.setDialogTitle( + MessageManager.getString("label.select_startup_file")); int value = chooser.showOpenDialog(this); if (value == JalviewFileChooser.APPROVE_OPTION) { - jalview.bin.Cache.applicationProperties.setProperty( - "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat()); - startupFileTextfield.setText(chooser.getSelectedFile() - .getAbsolutePath()); + FileFormatI format = chooser.getSelectedFormat(); + if (format != null) + { + Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT", + format.getName()); + } + startupFileTextfield + .setText(chooser.getSelectedFile().getAbsolutePath()); } } @@ -814,12 +957,15 @@ public class Preferences extends GPreferences conservation.setEnabled(annotations.isSelected()); quality.setEnabled(annotations.isSelected()); identity.setEnabled(annotations.isSelected()); + showOccupancy.setEnabled(annotations.isSelected()); showGroupConsensus.setEnabled(annotations.isSelected()); showGroupConservation.setEnabled(annotations.isSelected()); showConsensHistogram.setEnabled(annotations.isSelected() && (identity.isSelected() || showGroupConsensus.isSelected())); showConsensLogo.setEnabled(annotations.isSelected() && (identity.isSelected() || showGroupConsensus.isSelected())); + showInformationHistogram.setEnabled(annotations.isSelected()); + showHMMLogo.setEnabled(annotations.isSelected()); } @Override @@ -829,15 +975,25 @@ public class Preferences extends GPreferences boolean valid = false; while (!valid) { - if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link, + if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link, MessageManager.getString("label.new_sequence_url_link"), - JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION) + JvOptionPane.OK_CANCEL_OPTION, -1, + null) == JvOptionPane.OK_OPTION) { if (link.checkValid()) { - ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow( - link.getName(), link.getURL()); - valid = true; + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isUniqueName(link.getName())) + { + ((UrlLinkTableModel) linkUrlTable.getModel()) + .insertRow(link.getName(), link.getURL()); + valid = true; + } + else + { + link.notifyDuplicate(); + continue; + } } } else @@ -855,29 +1011,42 @@ public class Preferences extends GPreferences int index = linkUrlTable.getSelectedRow(); if (index == -1) { - // no row was selected - JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.no_link_selected"), - MessageManager.getString("label.no_link_selected"), - JOptionPane.WARNING_MESSAGE); + // button no longer enabled if row is not selected + Cache.log.debug("Edit with no row selected in linkUrlTable"); return; } - link.setName(linkUrlTable.getValueAt(index, 0).toString()); - link.setURL(linkUrlTable.getValueAt(index, 1).toString()); + int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getNameColumn(); + int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getUrlColumn(); + String oldName = linkUrlTable.getValueAt(index, nameCol).toString(); + link.setName(oldName); + link.setURL(linkUrlTable.getValueAt(index, urlCol).toString()); boolean valid = false; while (!valid) { - if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link, - MessageManager.getString("label.new_sequence_url_link"), - JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION) + if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link, + MessageManager.getString("label.edit_sequence_url_link"), + JvOptionPane.OK_CANCEL_OPTION, -1, + null) == JvOptionPane.OK_OPTION) { if (link.checkValid()) { - linkUrlTable.setValueAt(link.getName(), index, 0); - linkUrlTable.setValueAt(link.getURL(), index, 1); - valid = true; + if ((oldName.equals(link.getName())) + || (((UrlLinkTableModel) linkUrlTable.getModel()) + .isUniqueName(link.getName()))) + { + linkUrlTable.setValueAt(link.getName(), index, nameCol); + linkUrlTable.setValueAt(link.getURL(), index, urlCol); + valid = true; + } + else + { + link.notifyDuplicate(); + continue; + } } } else @@ -894,11 +1063,8 @@ public class Preferences extends GPreferences int modelIndex = -1; if (index == -1) { - // no row is selected - JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.no_link_selected"), - MessageManager.getString("label.no_link_selected"), - JOptionPane.WARNING_MESSAGE); + // button no longer enabled if row is not selected + Cache.log.debug("Delete with no row selected in linkUrlTable"); return; } else @@ -910,13 +1076,12 @@ public class Preferences extends GPreferences ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex); } - @Override public void defaultBrowser_mouseClicked(MouseEvent e) { JFileChooser chooser = new JFileChooser("."); - chooser.setDialogTitle(MessageManager - .getString("label.select_default_browser")); + chooser.setDialogTitle( + MessageManager.getString("label.select_default_browser")); int value = chooser.showOpenDialog(this); @@ -989,10 +1154,11 @@ public class Preferences extends GPreferences } } catch (NumberFormatException x) { - JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager - .getString("warn.user_defined_width_requirements"), + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager + .getString("warn.user_defined_width_requirements"), MessageManager.getString("label.invalid_id_column_width"), - JOptionPane.WARNING_MESSAGE); + JvOptionPane.WARNING_MESSAGE); userIdWidth.setText(""); } } @@ -1015,15 +1181,180 @@ public class Preferences extends GPreferences File f = new File(chimeraPath.getText()); if (!f.canExecute()) { - JOptionPane.showInternalMessageDialog(Desktop.desktop, + JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager.getString("label.invalid_chimera_path"), MessageManager.getString("label.invalid_name"), - JOptionPane.ERROR_MESSAGE); + JvOptionPane.ERROR_MESSAGE); return false; } } return true; } + + /** + * Returns true if hmmer path contains the necessary valid executables, else + * show an error dialog (if showing dialog). + */ + private boolean validateHMMERPath(boolean showDialog) + { + int missing = 0; + String message = ""; + String folder = hmmerPath.getText().trim(); + if (folder.length() > 0) + { + File f = new File(folder); + if (!f.exists()) + { + if (showDialog) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString("label.folder_not_exists"), + MessageManager.getString("label.invalid_folder"), + JvOptionPane.ERROR_MESSAGE); + } + return false; + } + AlignmentI alignment = new Alignment( + new SequenceI[] + { new Sequence("test", "WLWL", 0, 3) }); + if (canExecute(folder + "/hmmbuild")) + { + validateHMMBuild(alignment); + } + else + { + message += MessageManager.getString("label.hmmbuild_not_found") + + "\n"; + missing++; + } + + + if (canExecute(folder + "/hmmalign")) + { + + } + else + { + message += MessageManager.getString("label.hmmalign_not_found") + + "\n"; + missing++; + } + + + if (canExecute(folder + "/hmmsearch")) + { + + } + else + { + message += MessageManager.getString("label.hmmsearch_not_found") + + "\n"; + missing++; + } + } + + if (missing > 0) + { + if (missing < 3) + { + if (showDialog) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, message, + MessageManager.getString("label.invalid_folder"), + JvOptionPane.ERROR_MESSAGE); + } + return false; + } + else + { + if (showDialog) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString("label.no_binaries"), + MessageManager.getString("label.invalid_folder"), + JvOptionPane.ERROR_MESSAGE); + } + + return false; + } + } + + return true; + } + + /** + * Checks if a file can be executed + * + * @param path + * the path to the file + * @return + */ + public boolean canExecute(String path) + { + File file = new File(path); + if (!file.canExecute()) + { + file = new File(path + ".exe"); + { + if (!file.canExecute()) + { + return false; + } + } + } + return true; + } + + /** + * Runs hmmbuild to check if it is working. While doing this it parses the + * version of HMMER. + * + * @param frame + * @return + */ + public boolean validateHMMBuild(AlignmentI alignment) + { + HMMBuildThread hmmbuild = new HMMBuildThread(alignment); + hmmbuild.hmmbuildWaitTillComplete(); + SequenceI hmmSeq = alignment.getSequenceAt(0); + HiddenMarkovModel hmm; + if (hmmSeq.isHMMConsensusSequence() && hmmSeq.getHMM() != null) + { + hmm = hmmSeq.getHMM(); + + if (hmm.getNumberOfSymbols() < 1) + { + return false; + } + } + else + { + return false; + } + + String header = hmm.getFileHeader(); + if (header == null) + { + return false; + } + else + { + Scanner scanner = new Scanner(header); + scanner.next(); + String string = scanner.next(); + String version = string.substring(1); + Cache.setProperty("HMMER_VERSION", version); + scanner.close(); + + } + return true; + } + + + private boolean validateHMMERPath() + { + return validateHMMERPath(true); + } /** * If Chimera is selected, check it can be found on default or user-specified @@ -1054,13 +1385,12 @@ public class Preferences extends GPreferences if (!found) { String[] options = { "OK", "Help" }; - int showHelp = JOptionPane.showInternalOptionDialog( - Desktop.desktop, + int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop, JvSwingUtils.wrapTooltip(true, MessageManager.getString("label.chimera_missing")), - "", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, + "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE, null, options, options[0]); - if (showHelp == JOptionPane.NO_OPTION) + if (showHelp == JvOptionPane.NO_OPTION) { try { @@ -1127,7 +1457,7 @@ public class Preferences extends GPreferences return name.hashCode() + code.hashCode(); } } - + private class UrlListSelectionHandler implements ListSelectionListener { @@ -1146,27 +1476,26 @@ public class Preferences extends GPreferences } int modelIndex = linkUrlTable.convertRowIndexToModel(index); - // determine if the new selection is a custom url or not - if (!sequenceUrlLinks.isUserEntry((String) linkUrlTable -.getModel() - .getValueAt(modelIndex, 4))) // KM TODO do this better + // enable/disable edit and delete link buttons + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isRowDeletable(modelIndex)) { - // entry is not a user-defined url and so should not be edited - // disable edit and delete buttons - deleteLink.setEnabled(false); - editLink.setEnabled(false); + deleteLink.setEnabled(true); } else { - deleteLink.setEnabled(true); - editLink.setEnabled(true); + deleteLink.setEnabled(false); } - // BUT it's the default url, don't allow deletion - if ((boolean) linkUrlTable.getValueAt(index, 3)) + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isRowEditable(modelIndex)) { - deleteLink.setEnabled(false); + editLink.setEnabled(true); + } + else + { + editLink.setEnabled(false); } } -} + } }