X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2Fstyles%2FViewStyle.java;h=649d07ecce6571cf37367f5b117c4b799ffb02c7;hb=4d7f98a6dd54d9863ba449ec79dcd95d25ed863d;hp=1e97af4a4feb870eca068b048dfde187979f04bc;hpb=be32c14cd8e48fe0a207cd7030cb9cd46f894678;p=jalview.git diff --git a/src/jalview/viewmodel/styles/ViewStyle.java b/src/jalview/viewmodel/styles/ViewStyle.java index 1e97af4..649d07e 100644 --- a/src/jalview/viewmodel/styles/ViewStyle.java +++ b/src/jalview/viewmodel/styles/ViewStyle.java @@ -3,8 +3,6 @@ package jalview.viewmodel.styles; 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 @@ -17,7 +15,6 @@ import java.util.HashMap; */ public class ViewStyle implements ViewStyleI { - private boolean abovePIDThreshold = false; int charHeight; @@ -139,107 +136,177 @@ public class ViewStyle implements ViewStyleI * name of base font for view */ private String fontName; + /** * size for base font */ private int fontSize; - - public ViewStyle(ViewStyleI viewStyle) - { - ViewStyle.configureFrom(this, viewStyle); + + /* + * If true, scale protein residues to 3 times width of cDNA bases (in + * SplitFrame views only) + */ + private boolean scaleProteinAsCdna = true; + + /** + * 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 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(); - isErs = new HashMap(); - setters = new HashMap(); - // Match Getters and Setters - for (Method m : ViewStyleI.class.getMethods()) + if (other == null || !(other instanceof ViewStyle)) { - 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); - } - } + return false; } - } - - 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()) - { - 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); + 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); + } + + /** + * Overridden to ensure that whenever vs1.equals(vs2) then vs1.hashCode() == + * vs2.hashCode() + */ + @Override + public int hashCode() + { + /* + * No need to include all properties, just a selection... + */ + int hash = 0; + int m = 1; + // Boolean.hashCode returns 1231 or 1237 + hash += m++ * Boolean.valueOf(this.abovePIDThreshold).hashCode(); + hash += m++ * Boolean.valueOf(this.centreColumnLabels).hashCode(); + hash += m++ * Boolean.valueOf(this.colourAppliesToAllGroups).hashCode(); + hash += m++ * Boolean.valueOf(this.displayReferenceSeq).hashCode(); + hash += m++ * Boolean.valueOf(this.renderGaps).hashCode(); + hash += m++ * Boolean.valueOf(this.rightAlignIds).hashCode(); + hash += m++ * Boolean.valueOf(this.scaleProteinAsCdna).hashCode(); + hash += m++ * Boolean.valueOf(this.scaleRightWrapped).hashCode(); + hash += m++ * Boolean.valueOf(this.seqNameItalics).hashCode(); + hash += m++ * Boolean.valueOf(this.showAnnotation).hashCode(); + hash += m++ * Boolean.valueOf(this.showBoxes).hashCode(); + hash += m++ * Boolean.valueOf(this.showdbrefs).hashCode(); + hash += m++ * Boolean.valueOf(this.showJVSuffix).hashCode(); + hash += m++ * Boolean.valueOf(this.showSequenceFeatures).hashCode(); + hash += m++ * Boolean.valueOf(this.showUnconserved).hashCode(); + hash += m++ * Boolean.valueOf(this.wrapAlignment).hashCode(); + hash += m++ * this.charHeight; + hash += m++ * this.charWidth; + hash += m++ * fontSize; + hash += m++ * fontStyle; + hash += m++ * idWidth; + hash += String.valueOf(this.fontName).hashCode(); + return hash; } /** @@ -552,7 +619,7 @@ public class ViewStyle implements ViewStyleI * @return the showSeqFeaturesHeight */ @Override - public boolean isShowSeqFeaturesHeight() + public boolean isShowSequenceFeaturesHeight() { return showSeqFeaturesHeight; } @@ -563,13 +630,6 @@ public class ViewStyle implements ViewStyleI return showSequenceFeatures; } - @Override - public boolean isShowSequenceFeaturesHeight() - { - - return showSeqFeaturesHeight; - } - /** * GUI state * @@ -583,7 +643,6 @@ public class ViewStyle implements ViewStyleI abovePIDThreshold = b; } - /** * DOCUMENT ME! * @@ -608,7 +667,6 @@ public class ViewStyle implements ViewStyleI this.charWidth = w; } - /** * @param value * indicating if subsequent colourscheme changes will be propagated @@ -787,7 +845,7 @@ public class ViewStyle implements ViewStyleI } @Override - public void setShowSeqFeaturesHeight(boolean selected) + public void setShowSequenceFeaturesHeight(boolean selected) { showSeqFeaturesHeight = selected; @@ -890,9 +948,9 @@ public class ViewStyle implements ViewStyleI } @Override - public boolean sameStyle(ViewStyleI them) + public boolean sameStyle(ViewStyleI that) { - return equivalent(this, them); + return this.equals(that); } @Override @@ -1004,4 +1062,16 @@ public class ViewStyle implements ViewStyleI { this.shownpfeats = shownpfeats; } + + @Override + public boolean isScaleProteinAsCdna() + { + return this.scaleProteinAsCdna; + } + + @Override + public void setScaleProteinAsCdna(boolean b) + { + this.scaleProteinAsCdna = b; + } }