public ViewStyle(ViewStyleI viewStyle)
{
- configureFrom(viewStyle);
+ ViewStyle.configureFrom(this, viewStyle);
}
public ViewStyle()
{
}
- private void configureFrom(ViewStyleI viewStyle)
+ private static HashMap<String, Method> getters, isErs, setters;
+ static
{
- HashMap<String, Method> getters = new HashMap<String, Method>(), isErs = new HashMap<String, Method>();
- HashMap<String, Method> setters = new HashMap<String, Method>();
- // Match Getters and Setters
- for (Method m : ViewStyleI.class.getMethods())
+ getters = new HashMap<String, Method>();
+ isErs = new HashMap<String, Method>();
+ setters = new HashMap<String, Method>();
+ // Match Getters and Setters
+ for (Method m : ViewStyleI.class.getMethods())
+ {
+ if (m.getDeclaringClass() == ViewStyleI.class)
{
- if (m.getDeclaringClass() == ViewStyleI.class)
+ if (m.getName().startsWith("get"))
{
- if (m.getName().startsWith("get"))
- {
- getters.put(m.getName().substring(3), m);
- }
- if (m.getName().startsWith("is"))
- {
- isErs.put(m.getName().substring(2), m);
- }
- if (m.getName().startsWith("set"))
- {
- setters.put(m.getName().substring(3), m);
- }
+ getters.put(m.getName().substring(3), m);
+ }
+ if (m.getName().startsWith("is"))
+ {
+ isErs.put(m.getName().substring(2), m);
+ }
+ if (m.getName().startsWith("set"))
+ {
+ setters.put(m.getName().substring(3), m);
}
}
+ }
+ }
+
+ private static void configureFrom(ViewStyle us, ViewStyleI viewStyle)
+ {
// try and do the set thing
for (String prop : setters.keySet())
{
{
try
{
- setter.invoke(this, getter.invoke(viewStyle));
+ setter.invoke(us, getter.invoke(viewStyle));
} catch (Exception q)
{
System.err.println("Unexpected exception setting view property "
}
}
+ private static boolean equivalent(ViewStyle us, ViewStyleI them)
+ {
+ // look for properties we can set
+ for (String prop : setters.keySet())
+ {
+ Method getter = getters.get(prop);
+ if (getter == null)
+ {
+ getter = isErs.get(prop);
+ }
+ if (getter != null)
+ {
+ try
+ {
+ if (!getter.invoke(them).equals(getter.invoke(us)))
+ {
+ return false;
+ }
+ } catch (Exception q)
+ {
+ System.err.println("Unexpected exception testing equivalence of property "
+ + prop + " by reflection");
+ q.printStackTrace();
+ }
+ }
+ }
+
+ return true;
+ }
+
+ public boolean equals(ViewStyleI other)
+ {
+ return other == null ? false : equivalent(this, other);
+ }
+
/**
* @return the upperCasebold
*/
{
this.wrappedWidth = w;
}
+
+ @Override
+ public boolean sameStyle(ViewStyleI them)
+ {
+ return equivalent(this, them);
+ }
}
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import jalview.api.AlignmentViewPanel;
+import jalview.api.ViewStyleI;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import java.io.File;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
}
}
+
+ @Test
+ public void testCopyViewSettings() throws Exception
+ {
+ AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
+ "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
+ Assert.assertTrue("Didn't read in the example file correctly.", af != null);
+ AlignmentViewPanel sps = null, groups = null;
+ for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
+ {
+ if ("Spinach Feredoxin Structure".equals(ap.getViewName()))
+ {
+ sps = ap;
+ }
+ if (ap.getViewName().contains("MAFFT"))
+ {
+ groups = ap;
+ }
+ }
+ assertTrue("Couldn't find the structure view", sps != null);
+ assertTrue("Couldn't find the MAFFT view", groups != null);
+
+ ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
+ ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
+ Assert.assertFalse(structureStyle.sameStyle(groupStyle));
+
+ groups.getAlignViewport().setViewStyle(structureStyle);
+ Assert.assertFalse(groupStyle.sameStyle(groups.getAlignViewport()
+ .getViewStyle()));
+ Assert.assertTrue(structureStyle.sameStyle(groups.getAlignViewport()
+ .getViewStyle()));
+
+ }
}