App
CancelableTool.java
Go to the documentation of this file.
1 package mhr.appcore.tools.cancelable;
2 
3 import android.graphics.Canvas;
4 import mhr.appcore.bitmap.BitmapInfo;
5 import mhr.appcore.bitmap.ChannelCount;
6 import mhr.appcore.bitmap.NBitmap;
7 import mhr.appcore.blending.BlendMode;
8 import mhr.appcore.blending.Blender;
9 import mhr.appcore.image.Image;
10 import mhr.appcore.image.layers.RasterLayer;
11 import mhr.appcore.tools.Tool;
12 import mhr.appcore.tools.actiondata.BrushLikeToolActionData;
13 import mhr.appcore.tools.actiondata.CancelableToolActionData;
14 import mhr.appcore.tools.actiondata.ToolActionData;
15 import mhr.appcore.utils.LinearInt;
16 import mhr.appcore.utils.Rect;
17 
21 public abstract class CancelableTool implements Tool {
22 
23  //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
24  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
25  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
26 
27  //===== FIELDS ==============================================================================================================================//
28  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
29  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
30 
31  //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
32  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
33  @Override
34  protected void finalize() throws Throwable {
35  dispose();
36  super.finalize();
37  }
38 
39  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
40  public CancelableTool () {
41  }
42  @Override
43  public synchronized void dispose() {
44  }
45 
46  //===== METHODS =============================================================================================================================//
47  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
48  protected abstract void onPreview(Image img, CancelableToolActionData data);
49 
50  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
51  @Override
52  public void applyTo(Image img, ToolActionData data) {
53  if (!(data instanceof CancelableToolActionData)) {
54  throw new IllegalArgumentException("Received data for different tool");
55  }
56  CancelableToolActionData d = (CancelableToolActionData) data;
57  switch (d.action) {
58  case UPDATE_PREVIEW:
59  if (img.getCanvasOwner() != this) {
61  } else {
62  img.getCanvas(this);
63  }
64  onPreview(img, d);
65  img.addCanvasChangedArea(img.getRect());
66  break;
67  case CANCEL_PREVIEW:
68  if (img.getCanvasOwner() == this) {
69  img.submitCanvas(this, false);
70  }
71  break;
72  case COMMIT_PREVIEW:
73  if (img.getCanvasOwner() == this) {
74  img.submitCanvas(this, true);
75  }
76  break;
77  }
78  }
79 
80  //===== CALLBACKS ===========================================================================================================================//
81 
82 
83 
84  //----- destruktory -------------------------------------------------------------------------------------------------------------------------//
85 
86  //----- metody ------------------------------------------------------------------------------------------------------------------------------//
87 
88 }