new plotter

This commit is contained in:
Sergey Solovyev 2013-01-14 18:05:23 +04:00
parent f08e03761b
commit c9770cef4b
2 changed files with 21 additions and 8 deletions

View File

@ -97,7 +97,8 @@ public class CalculatorPlotFunctionSettingsActivity extends SherlockFragmentActi
final PlotLineColor newPlotLineColor = PlotLineColor.values()[position]; final PlotLineColor newPlotLineColor = PlotLineColor.values()[position];
int newLineColor = newPlotLineColor.getColor(); int newLineColor = newPlotLineColor.getColor();
if ( newLineColor != plotFunction.getPlotLineDef().getLineColor() ) { if ( newLineColor != plotFunction.getPlotLineDef().getLineColor() ) {
final PlotFunction newPlotFunction = new PlotFunction(plotFunction.getXyFunction(), PlotLineDef.changeLineColor(plotFunction.getPlotLineDef(), newLineColor)); final PlotLineDef newPlotLineDef = PlotLineDef.changeLineColor(plotFunction.getPlotLineDef(), newLineColor);
final PlotFunction newPlotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
if(plotter.updateFunction(newPlotFunction)) { if(plotter.updateFunction(newPlotFunction)) {
plotFunction = newPlotFunction; plotFunction = newPlotFunction;
} }
@ -115,7 +116,8 @@ public class CalculatorPlotFunctionSettingsActivity extends SherlockFragmentActi
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final PlotLineColorType newPlotLineColorType = PlotLineColorType.values()[position]; final PlotLineColorType newPlotLineColorType = PlotLineColorType.values()[position];
if ( newPlotLineColorType != plotFunction.getPlotLineDef().getLineColorType() ) { if ( newPlotLineColorType != plotFunction.getPlotLineDef().getLineColorType() ) {
final PlotFunction newPlotFunction = new PlotFunction(plotFunction.getXyFunction(), PlotLineDef.changeLineColorType(plotFunction.getPlotLineDef(), newPlotLineColorType)); final PlotLineDef newPlotLineDef = PlotLineDef.changeLineColorType(plotFunction.getPlotLineDef(), newPlotLineColorType);
final PlotFunction newPlotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
if(plotter.updateFunction(newPlotFunction)) { if(plotter.updateFunction(newPlotFunction)) {
plotFunction = newPlotFunction; plotFunction = newPlotFunction;
} }
@ -133,7 +135,10 @@ public class CalculatorPlotFunctionSettingsActivity extends SherlockFragmentActi
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final PlotLineStyle newPlotLineStyle = PlotLineStyle.values()[position]; final PlotLineStyle newPlotLineStyle = PlotLineStyle.values()[position];
if ( newPlotLineStyle != plotFunction.getPlotLineDef().getLineStyle() ) { if ( newPlotLineStyle != plotFunction.getPlotLineDef().getLineStyle() ) {
final PlotFunction newPlotFunction = new PlotFunction(plotFunction.getXyFunction(), PlotLineDef.changeLineStyle(plotFunction.getPlotLineDef(), newPlotLineStyle));
final PlotLineDef newPlotLineDef = PlotLineDef.changeLineStyle(plotFunction.getPlotLineDef(), newPlotLineStyle);
final PlotFunction newPlotFunction = PlotFunction.changePlotLineDef(plotFunction, newPlotLineDef);
if(plotter.updateFunction(newPlotFunction)) { if(plotter.updateFunction(newPlotFunction)) {
plotFunction = newPlotFunction; plotFunction = newPlotFunction;
} }

View File

@ -13,7 +13,7 @@ public class PlotFunction {
private XyFunction xyFunction; private XyFunction xyFunction;
@NotNull @NotNull
private PlotLineDef mPlotLineDef; private PlotLineDef plotLineDef;
private boolean pinned = false; private boolean pinned = false;
@ -21,26 +21,34 @@ public class PlotFunction {
public PlotFunction(@NotNull XyFunction xyFunction) { public PlotFunction(@NotNull XyFunction xyFunction) {
this.xyFunction = xyFunction; this.xyFunction = xyFunction;
this.mPlotLineDef = PlotLineDef.newDefaultInstance(); this.plotLineDef = PlotLineDef.newDefaultInstance();
} }
public PlotFunction(@NotNull XyFunction xyFunction, public PlotFunction(@NotNull XyFunction xyFunction,
@NotNull PlotLineDef plotLineDef) { @NotNull PlotLineDef plotLineDef) {
this.xyFunction = xyFunction; this.xyFunction = xyFunction;
this.mPlotLineDef = plotLineDef; this.plotLineDef = plotLineDef;
} }
@NotNull @NotNull
private PlotFunction copy() { private PlotFunction copy() {
final PlotFunction copy = new PlotFunction(this.xyFunction); final PlotFunction copy = new PlotFunction(this.xyFunction);
copy.mPlotLineDef = this.mPlotLineDef; copy.plotLineDef = this.plotLineDef;
copy.pinned = this.pinned; copy.pinned = this.pinned;
copy.visible = this.visible; copy.visible = this.visible;
return copy; return copy;
} }
@NotNull
public static PlotFunction changePlotLineDef(@NotNull PlotFunction that, @NotNull PlotLineDef newPlotLineDef) {
final PlotFunction copy = that.copy();
copy.plotLineDef = newPlotLineDef;
return copy;
}
@NotNull
public static PlotFunction pin(@NotNull PlotFunction that) { public static PlotFunction pin(@NotNull PlotFunction that) {
return togglePinned(that, true); return togglePinned(that, true);
} }
@ -81,7 +89,7 @@ public class PlotFunction {
@NotNull @NotNull
public PlotLineDef getPlotLineDef() { public PlotLineDef getPlotLineDef() {
return mPlotLineDef; return plotLineDef;
} }
public boolean isPinned() { public boolean isPinned() {