import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.io.Reader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.gui.Help.HelpId;
import jalview.gui.JalviewColourChooser.ColourChooserListener;
+import jalview.io.DataSourceType;
+import jalview.io.FileParse;
import jalview.io.JalviewFileChooser;
import jalview.io.JalviewFileView;
import jalview.schemes.FeatureColour;
chooser.showOpenDialog(this);
}
+ public static boolean loadFeatureSettingsFile(FeatureRenderer fr,
+ File file) throws Exception
+ {
+ InputStreamReader in = new InputStreamReader(new FileInputStream(file),
+ "UTF-8");
+ return loadFeatureSettingsFile(fr, in);
+ }
+
+ public static void loadFeatureSettingsFile(
+ FeatureRenderer featureRenderer, Object fileObject,
+ DataSourceType sourceType) throws Exception
+ {
+ FileParse fp = new FileParse(fileObject, sourceType);
+ loadFeatureSettingsFile(featureRenderer, fp.getReader());
+ }
+
+ private static boolean loadFeatureSettingsFile(FeatureRenderer fr,
+ Reader in) throws Exception
+ {
+ JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.jalview");
+ javax.xml.bind.Unmarshaller um = jc.createUnmarshaller();
+ XMLStreamReader streamReader = XMLInputFactory.newInstance()
+ .createXMLStreamReader(in);
+ JAXBElement<JalviewUserColours> jbe = um.unmarshal(streamReader,
+ JalviewUserColours.class);
+ JalviewUserColours jucs = jbe.getValue();
+
+ // JalviewUserColours jucs = JalviewUserColours.unmarshal(in);
+
+ /*
+ * load feature colours
+ */
+ for (int i = jucs.getColour().size() - 1; i >= 0; i--)
+ {
+ Colour newcol = jucs.getColour().get(i);
+ FeatureColourI colour = jalview.project.Jalview2XML
+ .parseColour(newcol);
+ fr.setColour(newcol.getName(), colour);
+ fr.setOrder(newcol.getName(), i / (float) jucs.getColour().size());
+ }
+
+ /*
+ * load feature filters; loaded filters will replace any that are
+ * currently defined, other defined filters are left unchanged
+ */
+ for (int i = 0; i < jucs.getFilter().size(); i++)
+ {
+ Filter filterModel = jucs.getFilter().get(i);
+ String featureType = filterModel.getFeatureType();
+ FeatureMatcherSetI filter = jalview.project.Jalview2XML
+ .parseFilter(featureType, filterModel.getMatcherSet());
+ if (!filter.isEmpty())
+ {
+ fr.setFeatureFilter(featureType, filter);
+ }
+ }
+ return true;
+ }
+
/**
* Loads feature colours and filters from XML stored in the given file
*
*/
void load(File file)
{
+ load(file, DataSourceType.FILE);
+ }
+
+ /**
+ * Loads feature colours and filters from XML at a specified source
+ *
+ * @param file
+ * - string or file or other object that allows FileParse to be
+ * created
+ */
+ void load(Object file, DataSourceType sourceType)
+ {
try
{
- InputStreamReader in = new InputStreamReader(
- new FileInputStream(file), "UTF-8");
-
- JAXBContext jc = JAXBContext
- .newInstance("jalview.xml.binding.jalview");
- javax.xml.bind.Unmarshaller um = jc.createUnmarshaller();
- XMLStreamReader streamReader = XMLInputFactory.newInstance()
- .createXMLStreamReader(in);
- JAXBElement<JalviewUserColours> jbe = um.unmarshal(streamReader,
- JalviewUserColours.class);
- JalviewUserColours jucs = jbe.getValue();
-
- // JalviewUserColours jucs = JalviewUserColours.unmarshal(in);
-
- /*
- * load feature colours
- */
- for (int i = jucs.getColour().size() - 1; i >= 0; i--)
- {
- Colour newcol = jucs.getColour().get(i);
- FeatureColourI colour = jalview.project.Jalview2XML
- .parseColour(newcol);
- fr.setColour(newcol.getName(), colour);
- fr.setOrder(newcol.getName(), i / (float) jucs.getColour().size());
- }
-
- /*
- * load feature filters; loaded filters will replace any that are
- * currently defined, other defined filters are left unchanged
- */
- for (int i = 0; i < jucs.getFilter().size(); i++)
- {
- Filter filterModel = jucs.getFilter().get(i);
- String featureType = filterModel.getFeatureType();
- FeatureMatcherSetI filter = jalview.project.Jalview2XML
- .parseFilter(featureType, filterModel.getMatcherSet());
- if (!filter.isEmpty())
- {
- fr.setFeatureFilter(featureType, filter);
- }
- }
-
+ loadFeatureSettingsFile(fr, file, sourceType);
/*
* update feature settings table
*/
}
} catch (Exception ex)
{
- jalview.bin.Console.outPrintln("Error loading User Colour File\n" + ex);
+ jalview.bin.Console
+ .outPrintln("Error loading User Colour File\n" + ex);
}
}
refreshDisplay();
}
}
-
class FeatureIcon implements Icon
{
FeatureColourI gcol;