adds documentation for appearance builder

This commit is contained in:
Vicilu 2016-10-14 11:50:58 -03:00 committed by GitHub
parent 466619d296
commit 7c5de3f4da

View File

@ -18,25 +18,38 @@ import net.sf.openrocket.util.Coordinate;
*/ */
public class AppearanceBuilder extends AbstractChangeSource { public class AppearanceBuilder extends AbstractChangeSource {
private Color paint; private Color paint; //current cached color
private double shine; private double shine; //current cached shine
private double offsetU, offsetV; private double offsetU, offsetV;//current offset to be used
private double centerU, centerV; private double centerU, centerV;//current values for the center of the appearance
private double scaleU, scaleV; private double scaleU, scaleV; //current values for scaling
private double rotation; private double rotation; //
private DecalImage image; private DecalImage image;
private Decal.EdgeMode edgeMode; private Decal.EdgeMode edgeMode;
private boolean batch; private boolean batch;
/**
* Default constructor
* Set the builder to make appearance of null values
*
*/
public AppearanceBuilder() { public AppearanceBuilder() {
resetToDefaults(); resetToDefaults();
} }
/**
* Constructor that initializes already with a
*
* @param a the appearance to be copied
*/
public AppearanceBuilder(Appearance a) { public AppearanceBuilder(Appearance a) {
setAppearance(a); setAppearance(a);
} }
/**
* Clears the builder cache and set to build blank appearances
*/
private void resetToDefaults() { private void resetToDefaults() {
paint = new Color(0, 0, 0); paint = new Color(0, 0, 0);
shine = 0; shine = 0;
@ -46,8 +59,15 @@ public class AppearanceBuilder extends AbstractChangeSource {
rotation = 0; rotation = 0;
image = null; image = null;
edgeMode = EdgeMode.REPEAT; edgeMode = EdgeMode.REPEAT;
fireChangeEvent();//shouldn't this fire change event?
} }
/**
* Sets the builder to create appearance equals to an existing appearance
* Fires change only once, hence the call to batch
*
* @param a the appearance to be used as the new template
*/
public void setAppearance(final Appearance a) { public void setAppearance(final Appearance a) {
batch(new Runnable() { batch(new Runnable() {
@Override @Override
@ -56,20 +76,33 @@ public class AppearanceBuilder extends AbstractChangeSource {
if (a != null) { if (a != null) {
setPaint(a.getPaint()); setPaint(a.getPaint());
setShine(a.getShine()); setShine(a.getShine());
Decal d = a.getTexture(); setDecal(a.getTexture());
if (d != null) {
setOffset(d.getOffset().x, d.getOffset().y);
setCenter(d.getCenter().x, d.getCenter().y);
setScaleUV(d.getScale().x, d.getScale().y);
setRotation(d.getRotation());
setEdgeMode(d.getEdgeMode());
setImage(d.getImage());
}
} }
} }
}); });
} }
/**
* makes a full copy of a decal, including information of offsets, center and scale
*
* @param d The decal
*/
public void setDecal(Decal d){
if (d != null) {
setOffset(d.getOffset().x, d.getOffset().y);
setCenter(d.getCenter().x, d.getCenter().y);
setScaleUV(d.getScale().x, d.getScale().y);
setRotation(d.getRotation());
setEdgeMode(d.getEdgeMode());
setImage(d.getImage());
}
fireChangeEvent();
}
/**
* Method creates another object of Appearance
* @return the created appearance
*/
public Appearance getAppearance() { public Appearance getAppearance() {
Decal t = null; Decal t = null;
@ -88,143 +121,316 @@ public class AppearanceBuilder extends AbstractChangeSource {
} }
/**
* get current paint in template
*
* return the color used in the current paint
*/
public Color getPaint() { public Color getPaint() {
return paint; return paint;
} }
/**
* sets a new paint color to be used
* fires change event
*
* @param paint the new color
*/
public void setPaint(Color paint) { public void setPaint(Color paint) {
this.paint = paint; this.paint = paint;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current shine
*
* @return current shine in template
*/
public double getShine() { public double getShine() {
return shine; return shine;
} }
/**
* Sets a new shine for template
* fires change event
*
* @param shine the new shine for template
*/
public void setShine(double shine) { public void setShine(double shine) {
this.shine = shine; this.shine = shine;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current offset axis U used
*
* @return offset in axis U
*/
public double getOffsetU() { public double getOffsetU() {
return offsetU; return offsetU;
} }
/**
* sets a new offset in axis U for template
* fires change event
*
* @param offsetU the new offset to be used
*/
public void setOffsetU(double offsetU) { public void setOffsetU(double offsetU) {
this.offsetU = offsetU; this.offsetU = offsetU;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current offset axis V used
*
* @return offset in axis V
*/
public double getOffsetV() { public double getOffsetV() {
return offsetV; return offsetV;
} }
/**
* sets a new offset in axis V for template
* fires change event
*
* @param offsetV the new offset to be used
*/
public void setOffsetV(double offsetV) { public void setOffsetV(double offsetV) {
this.offsetV = offsetV; this.offsetV = offsetV;
fireChangeEvent(); fireChangeEvent();
} }
/**
* sets a new offset to be used for template
* fires change event
*
* @param u offset in axis u
* @param v offset in axis v
*/
public void setOffset(double u, double v) { public void setOffset(double u, double v) {
setOffsetU(u); setOffsetU(u);
setOffsetV(v); setOffsetV(v);
} }
/**
* gets the current center in axis U used in template
*
* @return the current value of U of cente in template
*/
public double getCenterU() { public double getCenterU() {
return centerU; return centerU;
} }
/**
* set a new value for axis U for center in template
* fires change event
*
* @param centerU value of axis U for center
*/
public void setCenterU(double centerU) { public void setCenterU(double centerU) {
this.centerU = centerU; this.centerU = centerU;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current center in axis V used in template
*
* @return the current value of V of cente in template
*/
public double getCenterV() { public double getCenterV() {
return centerV; return centerV;
} }
/**
* set a new value for axis V for center in template
* fires change event
*
* @param centerU value of axis V for center
*/
public void setCenterV(double centerV) { public void setCenterV(double centerV) {
this.centerV = centerV; this.centerV = centerV;
fireChangeEvent(); fireChangeEvent();
} }
/**
* sets a new center for template
* fires chenge event
*
* @param u new value for axis u of the center
* @param v new value for axis v of the center
*/
public void setCenter(double u, double v) { public void setCenter(double u, double v) {
setCenterU(u); setCenterU(u);
setCenterV(v); setCenterV(v);
} }
/**
* gets the current scale value of axis u in template
*
* @return current value for axis u of scale
*/
public double getScaleU() { public double getScaleU() {
return scaleU; return scaleU;
} }
/**
* sets a new value of axis U for scaling in the template
* fires change event
*
* @param scaleU new value of scalling in axis U
*/
public void setScaleU(double scaleU) { public void setScaleU(double scaleU) {
this.scaleU = scaleU; this.scaleU = scaleU;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current scale value of axis V in template
*
* @return current value for axis V of scale
*/
public double getScaleV() { public double getScaleV() {
return scaleV; return scaleV;
} }
/**
* sets a new value of axis V for scaling in the template
* fires change event
*
* @param scaleV new value of scalling in axis V
*/
public void setScaleV(double scaleV) { public void setScaleV(double scaleV) {
this.scaleV = scaleV; this.scaleV = scaleV;
fireChangeEvent(); fireChangeEvent();
} }
/**
* sets a new value of both axis for scaling in the template
* fires change event
*
* @param u new value of scalling in axis U
* @param v new value of scalling in axis v
*/
public void setScaleUV(double u, double v) { public void setScaleUV(double u, double v) {
setScaleU(u); setScaleU(u);
setScaleV(v); setScaleV(v);
} }
/**
* gets the current value of X axis for scalling in the template
*
* @return value of scalling in axis x
*/
public double getScaleX() { public double getScaleX() {
return 1.0 / getScaleU(); return 1.0 / getScaleU();
} }
public void setScaleX(double scaleU) { /**
setScaleU(1.0 / scaleU); * sets a new value of axis X for scalling in template
* fires change event
*
* @param scaleX the new value for axis X
*/
public void setScaleX(double scaleX) {
setScaleU(1.0 / scaleX);
} }
/**
* gets the current value of Y axis for scalling in the template
*
* @return value of scalling in axis Y
*/
public double getScaleY() { public double getScaleY() {
return 1.0 / getScaleV(); return 1.0 / getScaleV();
} }
public void setScaleY(double scaleV) { /**
setScaleV(1.0 / scaleV); * sets a new value of axis Y for scalling in template
* fires change event
*
* @param scaleX the new value for axis Y
*/
public void setScaleY(double scaleY) {
setScaleV(1.0 / scaleY);
} }
/**
* gets the current value of rotation in template
*
* @return the current rotation in template
*/
public double getRotation() { public double getRotation() {
return rotation; return rotation;
} }
/**
* sets a new value of rotation in template
* fires chenge event
*
* @param rotation the new value for rotation in template
*/
public void setRotation(double rotation) { public void setRotation(double rotation) {
this.rotation = rotation; this.rotation = rotation;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current image in template
*
* @param the current image in template
*/
public DecalImage getImage() { public DecalImage getImage() {
return image; return image;
} }
/**
* sets a new image in template
* fires change event
*
* @param image the new image to be used as template
*/
public void setImage(DecalImage image) { public void setImage(DecalImage image) {
this.image = image; this.image = image;
fireChangeEvent(); fireChangeEvent();
} }
/**
* gets the current Edge mode in use
*
* @return the current edge mode in template
*/
public Decal.EdgeMode getEdgeMode() { public Decal.EdgeMode getEdgeMode() {
return edgeMode; return edgeMode;
} }
/**
* sets a new edge mode to be used in template
* fires change event
*
* @param edgeMode the new edgeMode to be used
*/
public void setEdgeMode(Decal.EdgeMode edgeMode) { public void setEdgeMode(Decal.EdgeMode edgeMode) {
this.edgeMode = edgeMode; this.edgeMode = edgeMode;
fireChangeEvent(); fireChangeEvent();
} }
/**
* only applies change if there is no more changes comming
*/
@Override @Override
protected void fireChangeEvent() { protected void fireChangeEvent() {
if (!batch) if (!batch)
super.fireChangeEvent(); super.fireChangeEvent();
} }
/**
* function that garantees that chenges event only occurs after all changes are made
*
* param r the functor to be executed
*/
public void batch(Runnable r) { public void batch(Runnable r) {
batch = true; batch = true;
r.run(); r.run();