package jalview.viewmodel.styles;
import java.awt.Color;
-import java.lang.reflect.Method;
-import java.util.HashMap;
import jalview.api.ViewStyleI;
*/
public class ViewStyle implements ViewStyleI
{
-
private boolean abovePIDThreshold = false;
int charHeight;
*/
private boolean scaleProteinAsCdna = true;
- public ViewStyle(ViewStyleI viewStyle)
- {
- ViewStyle.configureFrom(this, viewStyle);
+ /**
+ * Copy constructor
+ *
+ * @param vs
+ */
+ public ViewStyle(ViewStyleI vs)
+ {
+ setAbovePIDThreshold(vs.getAbovePIDThreshold());
+ setCentreColumnLabels(vs.isCentreColumnLabels());
+ setCharHeight(vs.getCharHeight());
+ setCharWidth(vs.getCharWidth());
+ setColourAppliesToAllGroups(vs.getColourAppliesToAllGroups());
+ setColourByReferenceSeq(vs.isColourByReferenceSeq());
+ setColourText(vs.getColourText());
+ setConservationColourSelected(vs.isConservationColourSelected());
+ setConservationSelected(vs.getConservationSelected());
+ setDisplayReferenceSeq(vs.isDisplayReferenceSeq());
+ setFontName(vs.getFontName());
+ setFontSize(vs.getFontSize());
+ setFontStyle(vs.getFontStyle());
+ setIdWidth(vs.getIdWidth());
+ setIncrement(vs.getIncrement());
+ setRenderGaps(vs.isRenderGaps());
+ setRightAlignIds(vs.isRightAlignIds());
+ setScaleAboveWrapped(vs.getScaleAboveWrapped());
+ setScaleLeftWrapped(vs.getScaleLeftWrapped());
+ setScaleProteinAsCdna(vs.isScaleProteinAsCdna());
+ setScaleRightWrapped(vs.getScaleRightWrapped());
+ setSeqNameItalics(vs.isSeqNameItalics());
+ setShowAnnotation(vs.isShowAnnotation());
+ setShowBoxes(vs.getShowBoxes());
+ setShowColourText(vs.isShowColourText());
+ setShowDBRefs(vs.isShowDBRefs());
+ setShowHiddenMarkers(vs.getShowHiddenMarkers());
+ setShowJVSuffix(vs.getShowJVSuffix());
+ setShowNPFeats(vs.isShowNPFeats());
+ setShowSequenceFeaturesHeight(vs.isShowSequenceFeaturesHeight());
+ setShowSequenceFeatures(vs.isShowSequenceFeatures());
+ setShowText(vs.getShowText());
+ setShowUnconserved(vs.getShowUnconserved());
+ setTextColour(vs.getTextColour());
+ setTextColour2(vs.getTextColour2());
+ setThreshold(vs.getThreshold());
+ setThresholdTextColour(vs.getThresholdTextColour());
+ setUpperCasebold(vs.isUpperCasebold());
+ setWrapAlignment(vs.getWrapAlignment());
+ setWrappedWidth(vs.getWrappedWidth());
+ // ViewStyle.configureFrom(this, viewStyle);
}
public ViewStyle()
{
}
- private static HashMap<String, Method> getters, isErs, setters;
- static
+ /**
+ * Returns true if all attributes of the ViewStyles have the same value
+ */
+ @Override
+ public boolean equals(Object other)
{
- 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.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);
- }
- }
- }
- }
-
- private static void configureFrom(ViewStyle us, ViewStyleI viewStyle)
- {
- // 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(us, getter.invoke(viewStyle));
- } catch (Exception q)
- {
- System.err.println("Unexpected exception setting view property "
- + prop + " by reflection");
- q.printStackTrace();
- }
-
- }
- }
- }
-
- private static boolean equivalent(ViewStyle us, ViewStyleI them)
- {
- // look for properties we can set
- for (String prop : setters.keySet())
+ if (other == null || !(other instanceof ViewStyle))
{
- 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 false;
}
-
- return true;
+ ViewStyle vs = (ViewStyle) other;
+
+ boolean match = (getAbovePIDThreshold() == vs.getAbovePIDThreshold()
+ && isCentreColumnLabels() == vs.isCentreColumnLabels()
+ && getCharHeight() == vs.getCharHeight()
+ && getCharWidth() == vs.getCharWidth()
+ && getColourAppliesToAllGroups() == vs
+ .getColourAppliesToAllGroups()
+ && isColourByReferenceSeq() == vs.isColourByReferenceSeq()
+ && getColourText() == vs.getColourText()
+ && isConservationColourSelected() == vs
+ .isConservationColourSelected()
+ && getConservationSelected() == vs.getConservationSelected()
+ && isDisplayReferenceSeq() == vs.isDisplayReferenceSeq()
+ && getFontSize() == vs.getFontSize()
+ && getFontStyle() == vs.getFontStyle()
+ && getIdWidth() == vs.getIdWidth()
+ && getIncrement() == vs.getIncrement()
+ && isRenderGaps() == vs.isRenderGaps()
+ && isRightAlignIds() == vs.isRightAlignIds()
+ && getScaleAboveWrapped() == vs.getScaleAboveWrapped()
+ && getScaleLeftWrapped() == vs.getScaleLeftWrapped()
+ && isScaleProteinAsCdna() == vs.isScaleProteinAsCdna()
+ && getScaleRightWrapped() == vs.getScaleRightWrapped()
+ && isSeqNameItalics() == vs.isSeqNameItalics()
+ && isShowAnnotation() == vs.isShowAnnotation()
+ && getShowBoxes() == vs.getShowBoxes()
+ && isShowColourText() == vs.isShowColourText()
+ && isShowDBRefs() == vs.isShowDBRefs()
+ && getShowHiddenMarkers() == vs.getShowHiddenMarkers()
+ && getShowJVSuffix() == vs.getShowJVSuffix()
+ && isShowNPFeats() == vs.isShowNPFeats()
+ && isShowSequenceFeaturesHeight() == vs
+ .isShowSequenceFeaturesHeight()
+ && isShowSequenceFeatures() == vs.isShowSequenceFeatures()
+ && getShowText() == vs.getShowText()
+ && getShowUnconserved() == vs.getShowUnconserved()
+ && getThreshold() == vs.getThreshold()
+ && getThresholdTextColour() == vs.getThresholdTextColour()
+ && isUpperCasebold() == vs.isUpperCasebold()
+ && getWrapAlignment() == vs.getWrapAlignment() && getWrappedWidth() == vs
+ .getWrappedWidth());
+ /*
+ * and compare non-primitive types; syntax below will match null with null values
+ */
+ match = match
+ && String.valueOf(getFontName()).equals(
+ String.valueOf(vs.getFontName()));
+ match = match
+ && String.valueOf(getTextColour()).equals(
+ String.valueOf(vs.getTextColour()));
+ match = match
+ && String.valueOf(getTextColour2()).equals(
+ String.valueOf(vs.getTextColour2()));
+ return match;
+ // return equivalent(this, (ViewStyle) other);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return 0; // TODO
}
-
- public boolean equals(ViewStyleI other)
- {
- return other == null ? false : equivalent(this, other);
- }
-
/**
* @return the upperCasebold
*/
* @return the showSeqFeaturesHeight
*/
@Override
- public boolean isShowSeqFeaturesHeight()
+ public boolean isShowSequenceFeaturesHeight()
{
return showSeqFeaturesHeight;
}
return showSequenceFeatures;
}
- @Override
- public boolean isShowSequenceFeaturesHeight()
- {
-
- return showSeqFeaturesHeight;
- }
-
/**
* GUI state
*
}
@Override
- public void setShowSeqFeaturesHeight(boolean selected)
+ public void setShowSequenceFeaturesHeight(boolean selected)
{
showSeqFeaturesHeight = selected;
}
@Override
- public boolean sameStyle(ViewStyleI them)
+ public boolean sameStyle(ViewStyleI that)
{
- return equivalent(this, them);
+ return this.equals(that);
}
@Override