import jalview.api.ViewStyleI;
import java.awt.Color;
+import java.lang.reflect.Method;
+import java.util.HashMap;
/**
* A container for holding alignment view properties. View properties are
*/
boolean upperCasebold = false;
+ public ViewStyle(ViewStyleI viewStyle)
+ {
+ configureFrom(viewStyle);
+ }
+
+ public ViewStyle()
+ {
+ }
+
+ private void configureFrom(ViewStyleI viewStyle)
+ {
+ 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())
+ {
+ if (m.getDeclaringClass() == ViewStyleI.class)
+ {
+ 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);
+ }
+ }
+ }
+ // try and do the set thing
+ for (String prop : setters.keySet())
+ {
+ Method getter = getters.get(prop);
+ Method setter = setters.get(prop);
+ if (getter == null)
+ {
+ getter = isErs.get(prop);
+ }
+ if (getter != null && setter != null)
+ {
+ try
+ {
+ setter.invoke(this, getter.invoke(viewStyle));
+ } catch (Exception q)
+ {
+ System.err.println("Unexpected exception setting view property "
+ + prop + " by reflection");
+ q.printStackTrace();
+ }
+
+ }
+ }
+ }
+
/**
* @return the upperCasebold
*/
--- /dev/null
+package jalview.viewmodel.styles;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestviewStyle
+{
+
+ @Test
+ public void testSetterGetter()
+ {
+ ViewStyle orig = new ViewStyle();
+ orig.setCharHeight(23);
+ orig.setWrappedWidth(253);
+ orig.setWrapAlignment(true);
+ ViewStyle copy = new ViewStyle(orig);
+ orig.setWrapAlignment(false);
+ Assert.assertEquals(copy.getCharHeight(), orig.getCharHeight());
+ Assert.assertEquals(copy.getWrappedWidth(), orig.getWrappedWidth());
+ Assert.assertEquals(copy.getWrapAlignment(), !orig.getWrapAlignment());
+ }
+
+}