1 package jalview.viewmodel.styles;
3 import jalview.api.ViewStyleI;
6 import java.lang.reflect.Method;
7 import java.util.HashMap;
10 * A container for holding alignment view properties. View properties are
11 * data-independent, which means they can be safely copied between views
12 * involving different alignment data without causing exceptions in the
18 public class ViewStyle implements ViewStyleI
21 private boolean abovePIDThreshold = false;
28 * gui state - changes to colour scheme propagated to all groups
30 private boolean colourAppliesToAllGroups;
33 * colour according to the reference sequence defined on the alignment
35 private boolean colourByReferenceSeq = false;
37 boolean conservationColourSelected = false;
40 * show the reference sequence in the alignment view
42 private boolean displayReferenceSeq = false;
44 private int increment;
47 * display gap characters
49 boolean renderGaps = true;
51 private boolean rightAlignIds = false;
53 boolean scaleAboveWrapped = false;
55 boolean scaleLeftWrapped = true;
57 boolean scaleRightWrapped = true;
59 boolean seqNameItalics;
62 * show annotation tracks on the alignment
64 private boolean showAnnotation = true;
67 * render each residue in a coloured box
69 boolean showBoxes = true;
72 * Colour sequence text
74 boolean showColourText = false;
79 boolean showHiddenMarkers = true;
82 * show /start-end in ID panel
84 boolean showJVSuffix = true;
87 * scale features height according to score
89 boolean showSeqFeaturesHeight;
92 * display setting for showing/hiding sequence features on alignment view
94 boolean showSequenceFeatures = false;
97 * display sequence symbols
99 boolean showText = true;
102 * show non-conserved residues only
104 protected boolean showUnconserved = false;
106 Color textColour = Color.black;
108 Color textColour2 = Color.white;
111 * PID or consensus threshold
116 * threshold for switching between textColour & textColour2
118 int thresholdTextColour = 0;
121 * upper case characters in sequence are shown in bold
123 boolean upperCasebold = false;
125 public ViewStyle(ViewStyleI viewStyle)
127 ViewStyle.configureFrom(this, viewStyle);
134 private static HashMap<String, Method> getters, isErs, setters;
137 getters = new HashMap<String, Method>();
138 isErs = new HashMap<String, Method>();
139 setters = new HashMap<String, Method>();
140 // Match Getters and Setters
141 for (Method m : ViewStyleI.class.getMethods())
143 if (m.getDeclaringClass() == ViewStyleI.class)
145 if (m.getName().startsWith("get"))
147 getters.put(m.getName().substring(3), m);
149 if (m.getName().startsWith("is"))
151 isErs.put(m.getName().substring(2), m);
153 if (m.getName().startsWith("set"))
155 setters.put(m.getName().substring(3), m);
161 private static void configureFrom(ViewStyle us, ViewStyleI viewStyle)
163 // try and do the set thing
164 for (String prop : setters.keySet())
166 Method getter = getters.get(prop);
167 Method setter = setters.get(prop);
170 getter = isErs.get(prop);
172 if (getter != null && setter != null)
176 setter.invoke(us, getter.invoke(viewStyle));
177 } catch (Exception q)
179 System.err.println("Unexpected exception setting view property "
180 + prop + " by reflection");
188 private static boolean equivalent(ViewStyle us, ViewStyleI them)
190 // look for properties we can set
191 for (String prop : setters.keySet())
193 Method getter = getters.get(prop);
196 getter = isErs.get(prop);
202 if (!getter.invoke(them).equals(getter.invoke(us)))
206 } catch (Exception q)
208 System.err.println("Unexpected exception testing equivalence of property "
209 + prop + " by reflection");
218 public boolean equals(ViewStyleI other)
220 return other == null ? false : equivalent(this, other);
224 * @return the upperCasebold
227 public boolean isUpperCasebold()
229 return upperCasebold;
233 * @param upperCasebold
234 * the upperCasebold to set
237 public void setUpperCasebold(boolean upperCasebold)
239 this.upperCasebold = upperCasebold;
245 boolean wrapAlignment = false;
248 * number columns in wrapped alignment
255 * @return true if percent identity threshold is applied to shading
258 public boolean getAbovePIDThreshold()
260 return abovePIDThreshold;
266 * @return DOCUMENT ME!
269 public int getCharHeight()
277 * @return DOCUMENT ME!
280 public int getCharWidth()
288 * @return flag indicating if colourchanges propagated to all groups
291 public boolean getColourAppliesToAllGroups()
293 return colourAppliesToAllGroups;
299 * @return DOCUMENT ME!
302 public boolean getColourText()
304 return showColourText;
310 * @return true if conservation based shading is enabled
313 public boolean getConservationSelected()
315 return conservationColourSelected;
321 * @return get scalar for bleaching colourschemes by conservation
324 public int getIncrement()
332 * @return DOCUMENT ME!
335 public boolean getScaleAboveWrapped()
337 return scaleAboveWrapped;
343 * @return DOCUMENT ME!
346 public boolean getScaleLeftWrapped()
348 return scaleLeftWrapped;
354 * @return DOCUMENT ME!
357 public boolean getScaleRightWrapped()
359 return scaleRightWrapped;
365 * @return DOCUMENT ME!
368 public boolean getShowBoxes()
374 public boolean getShowHiddenMarkers()
376 return showHiddenMarkers;
382 * @return DOCUMENT ME!
385 public boolean getShowJVSuffix()
393 * @return DOCUMENT ME!
396 public boolean getShowText()
402 public boolean getShowUnconserved()
404 return showUnconserved;
408 * @return the textColour
411 public Color getTextColour()
417 * @return the textColour2
420 public Color getTextColour2()
428 * @return DOCUMENT ME!
431 public int getThreshold()
437 * @return the thresholdTextColour
440 public int getThresholdTextColour()
442 return thresholdTextColour;
448 * @return DOCUMENT ME!
451 public boolean getWrapAlignment()
453 return wrapAlignment;
459 * @return DOCUMENT ME!
462 public int getWrappedWidth()
468 public boolean isColourByReferenceSeq()
470 return colourByReferenceSeq;
474 * @return the conservationColourSelected
477 public boolean isConservationColourSelected()
479 return conservationColourSelected;
483 public boolean isDisplayReferenceSeq()
485 return displayReferenceSeq;
489 * @return the renderGaps
492 public boolean isRenderGaps()
498 public boolean isRightAlignIds()
500 return rightAlignIds;
504 * @return the seqNameItalics
507 public boolean isSeqNameItalics()
509 return seqNameItalics;
513 public boolean isShowAnnotation()
515 return showAnnotation;
519 * @return the showColourText
522 public boolean isShowColourText()
524 return showColourText;
528 * @return the showSeqFeaturesHeight
531 public boolean isShowSeqFeaturesHeight()
533 return showSeqFeaturesHeight;
537 public boolean isShowSequenceFeatures()
539 return showSequenceFeatures;
543 public boolean isShowSequenceFeaturesHeight()
546 return showSeqFeaturesHeight;
554 * indicate if percent identity threshold is applied to shading
557 public void setAbovePIDThreshold(boolean b)
559 abovePIDThreshold = b;
569 public void setCharHeight(int h)
581 public void setCharWidth(int w)
589 * indicating if subsequent colourscheme changes will be propagated
593 public void setColourAppliesToAllGroups(boolean b)
595 colourAppliesToAllGroups = b;
599 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
601 this.colourByReferenceSeq = colourByReferenceSeq;
611 public void setColourText(boolean state)
613 showColourText = state;
617 * @param conservationColourSelected
618 * the conservationColourSelected to set
621 public void setConservationColourSelected(
622 boolean conservationColourSelected)
624 this.conservationColourSelected = conservationColourSelected;
631 * enable conservation based shading
634 public void setConservationSelected(boolean b)
636 conservationColourSelected = b;
640 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
642 this.displayReferenceSeq = displayReferenceSeq;
648 * set the scalar for bleaching colourschemes according to degree of
652 public void setIncrement(int inc)
664 public void setRenderGaps(boolean state)
670 public void setRightAlignIds(boolean rightAlignIds)
672 this.rightAlignIds = rightAlignIds;
682 public void setScaleAboveWrapped(boolean b)
684 scaleAboveWrapped = b;
694 public void setScaleLeftWrapped(boolean b)
696 scaleLeftWrapped = b;
702 * @param scaleRightWrapped
707 public void setScaleRightWrapped(boolean b)
709 scaleRightWrapped = b;
713 public void setSeqNameItalics(boolean italics)
715 seqNameItalics = italics;
719 public void setShowAnnotation(boolean b)
731 public void setShowBoxes(boolean state)
737 * @param showColourText
738 * the showColourText to set
741 public void setShowColourText(boolean showColourText)
743 this.showColourText = showColourText;
747 public void setShowHiddenMarkers(boolean show)
749 showHiddenMarkers = show;
759 public void setShowJVSuffix(boolean b)
765 public void setShowSeqFeaturesHeight(boolean selected)
767 showSeqFeaturesHeight = selected;
775 * features are displayed if true
778 public void setShowSequenceFeatures(boolean b)
780 showSequenceFeatures = b;
790 public void setShowText(boolean state)
796 public void setShowUnconserved(boolean showunconserved)
798 showUnconserved = showunconserved;
803 * the textColour to set
806 public void setTextColour(Color textColour)
808 this.textColour = textColour;
813 * the textColour2 to set
816 public void setTextColour2(Color textColour2)
818 this.textColour2 = textColour2;
828 public void setThreshold(int thresh)
834 * @param thresholdTextColour
835 * the thresholdTextColour to set
838 public void setThresholdTextColour(int thresholdTextColour)
840 this.thresholdTextColour = thresholdTextColour;
850 public void setWrapAlignment(boolean state)
852 wrapAlignment = state;
862 public void setWrappedWidth(int w)
864 this.wrappedWidth = w;
868 public boolean sameStyle(ViewStyleI them)
870 return equivalent(this, them);