X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fprint%2FPrintableContext.java;h=4a5ddcacbfec91bc17938358082eb0b42973877a;hb=36a7942e7433b8493e4142a5f3dd85a956bb498b;hp=6645b6960b010ac19b14d99fed749d98ee6811cf;hpb=50f171ab51eae5c91117ebdc9b7a0d43d764ddb5;p=debian%2Fopenrocket diff --git a/src/net/sf/openrocket/gui/print/PrintableContext.java b/src/net/sf/openrocket/gui/print/PrintableContext.java index 6645b696..4a5ddcac 100644 --- a/src/net/sf/openrocket/gui/print/PrintableContext.java +++ b/src/net/sf/openrocket/gui/print/PrintableContext.java @@ -14,97 +14,108 @@ import java.util.TreeSet; * Instances of this class are meant to keep track of what the user has selected to be printed. */ public class PrintableContext implements Comparable, Iterable { - - /** - * The stage number. May be null for printables that have no stage meaning. - */ - private Set stageNumber; - - /** - * The type of thing to be printed. - */ - private OpenRocketPrintable printable; - - private final Map> previous = new TreeMap>(); - - - public PrintableContext () { - } - - /** - * Constructor. - * - * @param theStageNumber the stage number of the printable; may be null if not applicable - * @param thePrintable the type of the thing to be printed - * - * @throws IllegalArgumentException thrown if thePrintable.isStageSpecific - */ - private PrintableContext (final Set theStageNumber, final OpenRocketPrintable thePrintable) - throws IllegalArgumentException { - if (thePrintable.isStageSpecific() && theStageNumber == null) { - throw new IllegalArgumentException("A stage number must be provided when a printable is stage specific."); - } - stageNumber = theStageNumber; - printable = thePrintable; - } - - public void add (final Integer theStageNumber, final OpenRocketPrintable thePrintable) - throws IllegalArgumentException { - Set stages = previous.get(thePrintable); - if (stages == null) { - stages = new TreeSet(); - previous.put(thePrintable, stages); - } - if (theStageNumber != null) { - stages.add(theStageNumber); - } - } - - - public Iterator iterator () { - return new Iterator() { - - Iterator keyIter = previous.keySet().iterator(); - - @Override - public boolean hasNext () { - return keyIter.hasNext(); - } - - @Override - public PrintableContext next () { - final OpenRocketPrintable key = keyIter.next(); - return new PrintableContext(previous.get(key), key); - } - - @Override - public void remove () { - } - }; - - } - - /** - * Get the stage number, if it's applicable to the printable. - * - * @return the stage number - */ - public Set getStageNumber () { - return stageNumber; - } - - /** - * Get the printable. - * - * @return the printable - */ - public OpenRocketPrintable getPrintable () { - return printable; - } - - @Override - public int compareTo (final PrintableContext other) { - return this.printable.getPrintOrder() - other.printable.getPrintOrder(); - } - + + /** + * The stage number. May be null for printables that have no stage meaning. + */ + private Set stageNumber; + + /** + * The type of thing to be printed. + */ + private OpenRocketPrintable printable; + + /** + * Sort of a reverse map that tracks each type of printable item and the stages for which that item is to be printed. + */ + private final Map> previous = new TreeMap>(); + + /** + * Constructor. + */ + public PrintableContext() { + } + + /** + * Constructor. + * + * @param theStageNumber the stage number of the printable; may be null if not applicable + * @param thePrintable the type of the thing to be printed + * + * @throws IllegalArgumentException thrown if thePrintable.isStageSpecific + */ + private PrintableContext(final Set theStageNumber, final OpenRocketPrintable thePrintable) + throws IllegalArgumentException { + if (thePrintable.isStageSpecific() && theStageNumber == null) { + throw new IllegalArgumentException("A stage number must be provided when a printable is stage specific."); + } + stageNumber = theStageNumber; + printable = thePrintable; + } + + /** + * Add a type of printable to a stage (number). + * + * @param theStageNumber the stage number + * @param thePrintable the printable to associate with the stage + */ + public void add(final Integer theStageNumber, final OpenRocketPrintable thePrintable) { + Set stages = previous.get(thePrintable); + if (stages == null) { + stages = new TreeSet(); + previous.put(thePrintable, stages); + } + if (theStageNumber != null) { + stages.add(theStageNumber); + } + } + + /** PrintableContext iterator. */ + @Override + public Iterator iterator() { + return new Iterator() { + + Iterator keyIter = previous.keySet().iterator(); + + @Override + public boolean hasNext() { + return keyIter.hasNext(); + } + + @Override + public PrintableContext next() { + final OpenRocketPrintable key = keyIter.next(); + return new PrintableContext(previous.get(key), key); + } + + @Override + public void remove() { + } + }; + + } + + /** + * Get the stage number, if it's applicable to the printable. + * + * @return the stage number + */ + public Set getStageNumber() { + return stageNumber; + } + + /** + * Get the printable. + * + * @return the printable + */ + public OpenRocketPrintable getPrintable() { + return printable; + } + + @Override + public int compareTo(final PrintableContext other) { + return this.printable.getPrintOrder() - other.printable.getPrintOrder(); + } + }