1 package jp.sourceforge.gokigen.memoma.holders;
3 import java.util.Enumeration;
4 import java.util.Hashtable;
5 import android.content.Context;
6 import android.graphics.Color;
7 import android.graphics.Paint;
8 import android.graphics.RectF;
9 import android.util.Log;
10 import android.widget.Toast;
12 import jp.sourceforge.gokigen.memoma.Main;
13 import jp.sourceforge.gokigen.memoma.R;
21 public class MeMoMaObjectHolder
23 public static final int ID_NOTSPECIFY = -1;
25 public static final int DRAWSTYLE_RECTANGLE = 0;
26 public static final int DRAWSTYLE_ROUNDRECT = 1;
27 public static final int DRAWSTYLE_OVAL = 2;
28 public static final int DRAWSTYLE_DIAMOND = 3;
29 public static final int DRAWSTYLE_HEXAGONAL = 4;
30 public static final int DRAWSTYLE_PARALLELOGRAM = 5;
31 public static final int DRAWSTYLE_KEYBOARD = 6;
32 public static final int DRAWSTYLE_PAPER = 7;
33 public static final int DRAWSTYLE_DRUM = 8;
34 public static final int DRAWSTYLE_CIRCLE = 9;
35 public static final int DRAWSTYLE_NO_REGION = 10;
37 public static final int DRAWSTYLE_LOOP_START = 11;
38 public static final int DRAWSTYLE_LOOP_END = 12;
39 public static final int DRAWSTYLE_LEFT_ARROW = 13;
40 public static final int DRAWSTYLE_DOWN_ARROW = 14;
41 public static final int DRAWSTYLE_UP_ARROW = 15;
42 public static final int DRAWSTYLE_RIGHT_ARROW = 16;
44 public static final float ROUNDRECT_CORNER_RX = 8;
45 public static final float ROUNDRECT_CORNER_RY = 8;
47 public static final float STOROKE_BOLD_WIDTH = 3.5f;
48 public static final float STOROKE_NORMAL_WIDTH = 0.0f;
50 public static final float DUPLICATEPOSITION_MARGIN = 15.0f;
52 public static final float OBJECTSIZE_DEFAULT_X = 144.0f;
53 public static final float OBJECTSIZE_DEFAULT_Y = (OBJECTSIZE_DEFAULT_X / 16.0f * 9.0f);
55 public static final float OBJECTSIZE_MINIMUM_X = 48.0f;
56 public static final float OBJECTSIZE_MINIMUM_Y = (OBJECTSIZE_MINIMUM_X / 16.0f * 9.0f);
58 public static final float OBJECTSIZE_MAXIMUM_X = 14400.0f;
59 public static final float OBJECTSIZE_MAXIMUM_Y = (OBJECTSIZE_MAXIMUM_X / 16.0f * 9.0f);
61 public static final float OBJECTSIZE_STEP_X = OBJECTSIZE_MINIMUM_X * 1.0f;
62 public static final float OBJECTSIZE_STEP_Y = OBJECTSIZE_MINIMUM_Y * 1.0f;
64 public static final float FONTSIZE_DEFAULT = 12.0f;
66 private MeMoMaConnectLineHolder connectLineHolder = null;
68 private Hashtable<Integer, PositionObject> objectPoints = null;
69 private Integer serialNumber = 1;
70 private String dataTitle = "";
71 private String background = "";
72 private Context parent;
73 private final IOperationHistoryHolder historyHolder;
75 public MeMoMaObjectHolder(Context context, MeMoMaConnectLineHolder lineHolder, IOperationHistoryHolder historyHolder)
77 objectPoints = new Hashtable<>();
78 connectLineHolder = lineHolder;
80 this.historyHolder = historyHolder;
84 * データの有無を見る (true の場合、データはない。)
88 public boolean isEmpty()
90 return (((connectLineHolder == null)||(objectPoints == null))||(objectPoints.isEmpty()));
93 public MeMoMaConnectLineHolder getConnectLineHolder()
95 return (connectLineHolder);
98 public void setDataTitle(String title)
103 public String getDataTitle()
108 public void setBackground(String data)
113 public String getBackground()
118 public int getCount()
120 return (objectPoints.size());
123 public Enumeration<Integer> getObjectKeys()
125 return (objectPoints.keys());
128 public PositionObject getPosition(Integer key)
130 return (objectPoints.get(key));
133 public boolean removePosition(Integer key)
135 PositionObject removeTarget = objectPoints.remove(key);
136 if (removeTarget != null)
138 historyHolder.addHistory(key, IOperationHistoryHolder.ChangeKind.DELETE_OBJECT, removeTarget);
140 Log.v(Main.APP_IDENTIFIER, "REMOVE : " + key);
144 public void removeAllPositions()
146 objectPoints.clear();
150 public void setSerialNumber(int id)
152 serialNumber = (id == ID_NOTSPECIFY) ? ++serialNumber : id;
155 public int getSerialNumber()
157 return (serialNumber);
160 public void dumpPositionObject(PositionObject position)
162 if (position == null)
166 RectF posRect = position.getRect();
167 Log.v(Main.APP_IDENTIFIER, "[" + posRect.left + "," + posRect.top + "][" + posRect.right + "," + posRect.bottom + "] " + "label : " + position.getLabel() + " detail : " + position.getDetail());
177 public PositionObject duplicatePosition(int key)
179 PositionObject orgPosition = objectPoints.get(key);
180 if (orgPosition == null)
182 // 元のオブジェクトが見つからなかったので、何もせずに戻る
185 RectF orgRect = orgPosition.getRect();
186 PositionObject position = new PositionObject(serialNumber,
187 new RectF(orgRect.left + DUPLICATEPOSITION_MARGIN, orgRect.top + DUPLICATEPOSITION_MARGIN, orgRect.right + DUPLICATEPOSITION_MARGIN, orgRect.bottom + DUPLICATEPOSITION_MARGIN),
188 orgPosition.getDrawStyle(),
189 orgPosition.getIcon(),
190 orgPosition.getLabel(),
191 orgPosition.getDetail(),
192 orgPosition.getUserChecked(),
193 orgPosition.getLabelColor(),
194 orgPosition.getObjectColor(),
195 orgPosition.getPaintStyle(),
196 orgPosition.getstrokeWidth(),
197 orgPosition.getFontSize(),
199 objectPoints.put(serialNumber, position);
204 public PositionObject createPosition(int id)
206 PositionObject position = new PositionObject(id,
207 new RectF(0, 0, OBJECTSIZE_DEFAULT_X, OBJECTSIZE_DEFAULT_Y),
208 MeMoMaObjectHolder.DRAWSTYLE_RECTANGLE,
215 Paint.Style.STROKE.toString(),
216 STOROKE_NORMAL_WIDTH,
219 objectPoints.put(id, position);
223 public PositionObject createPosition(float x, float y, int drawStyle)
225 PositionObject position = createPosition(serialNumber);
226 RectF posRect = position.getRect();
227 position.setRectLeft(posRect.left + x);
228 position.setRectRight(posRect.right + x);
229 position.setRectTop(posRect.top + y);
230 position.setRectBottom(posRect.bottom + y);
231 position.setDrawStyle(drawStyle);
240 public void expandObjectSize(Integer key)
242 PositionObject position = objectPoints.get(key);
243 if (position == null)
245 // 元のオブジェクトが見つからなかったので、何もせずに戻る
248 RectF posRect = position.getRect();
249 float width = posRect.right - posRect.left;
250 float height = posRect.bottom - posRect.top;
251 if (((width + (OBJECTSIZE_STEP_X * 2.0f)) > OBJECTSIZE_MAXIMUM_X)||((height + (OBJECTSIZE_STEP_Y * 2.0f)) > OBJECTSIZE_MAXIMUM_Y))
254 String outputMessage = parent.getString(R.string.object_bigger_limit) + " ";
255 Toast.makeText(parent, outputMessage, Toast.LENGTH_SHORT).show();
258 position.setRectLeft(posRect.left - OBJECTSIZE_STEP_X);
259 position.setRectRight(posRect.right + OBJECTSIZE_STEP_X);
260 position.setRectTop(posRect.top - OBJECTSIZE_STEP_Y);
261 position.setRectBottom(posRect.bottom + OBJECTSIZE_STEP_Y);
269 public void shrinkObjectSize(Integer key)
271 PositionObject position = objectPoints.get(key);
272 if (position == null)
274 // 元のオブジェクトが見つからなかったので、何もせずに戻る
277 RectF posRect = position.getRect();
278 float width = posRect.right - posRect.left;
279 float height = posRect.bottom - posRect.top;
280 if (((width - (OBJECTSIZE_STEP_X * 2.0f)) < OBJECTSIZE_MINIMUM_X)||((height - (OBJECTSIZE_STEP_Y * 2.0f)) < OBJECTSIZE_MINIMUM_Y))
283 String outputMessage = parent.getString(R.string.object_small_limit) + " ";
284 Toast.makeText(parent, outputMessage, Toast.LENGTH_SHORT).show();
287 position.setRectLeft(posRect.left + OBJECTSIZE_STEP_X);
288 position.setRectRight(posRect.right - OBJECTSIZE_STEP_X);
289 position.setRectTop(posRect.top + OBJECTSIZE_STEP_Y);
290 position.setRectBottom(posRect.bottom - OBJECTSIZE_STEP_Y);
293 public MeMoMaConnectLineHolder getLineHolder()
295 return (connectLineHolder);
298 static public int getObjectDrawStyleIcon(int drawStyle)
301 if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_RECTANGLE)
303 icon = R.drawable.btn_rectangle;
305 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_ROUNDRECT)
307 icon = R.drawable.btn_roundrect;
309 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_OVAL)
311 icon = R.drawable.btn_oval;
313 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_DIAMOND)
315 icon = R.drawable.btn_diamond;
317 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_HEXAGONAL)
319 icon = R.drawable.btn_hexagonal;
321 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_PARALLELOGRAM)
323 icon = R.drawable.btn_parallelogram;
325 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_KEYBOARD)
327 icon = R.drawable.btn_keyboard;
329 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_PAPER)
331 icon = R.drawable.btn_paper;
333 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_DRUM)
335 icon = R.drawable.btn_drum;
337 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_CIRCLE)
339 icon = R.drawable.btn_circle;
341 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_NO_REGION)
343 icon = R.drawable.btn_noregion;
345 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_LOOP_START)
347 icon = R.drawable.btn_trapezoidy_up;
349 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_LOOP_END)
351 icon = R.drawable.btn_trapezoidy_down;
353 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_LEFT_ARROW)
355 icon = R.drawable.btn_arrow_left;
357 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_DOWN_ARROW)
359 icon = R.drawable.btn_arrow_down;
361 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_UP_ARROW)
363 icon = R.drawable.btn_arrow_up;
365 else if (drawStyle == MeMoMaObjectHolder.DRAWSTYLE_RIGHT_ARROW)
367 icon = R.drawable.btn_arrow_right;