-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathCustomBlockShapeSet.java
More file actions
80 lines (56 loc) · 2.27 KB
/
Copy pathCustomBlockShapeSet.java
File metadata and controls
80 lines (56 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the MIT License https://raw.github.com/mit-cml/app-inventor/master/mitlicense.txt
package openblocks.codeblocks;
import java.awt.geom.Point2D;
import java.util.ArrayList;
public abstract class CustomBlockShapeSet {
/**
* Contains all of the custom block shapes that are being used in a project.
*/
public ArrayList<CustomBlockShape> customBlockShapes = new ArrayList<CustomBlockShape>();
/**
* Add CustomBlockShape to the array of customBlockShapes.
*/
protected void addCustomBlockShape(CustomBlockShape customBlockShape) {
customBlockShapes.add(customBlockShape);
}
/**
* Internal CustomBlockShape class.
*
*/
public class CustomBlockShape {
protected String genusName;
protected Point2D topLeftCorner;
protected Point2D topRightCorner;
protected Point2D botLeftCorner;
protected Point2D botRightCorner;
}
/**
* Checks if the given block is a "special shape" that has custom dimensions.
* CornerPoints is an array with array order Point2D topLeftCorner, Point2D topRightCorner,
* Point2D botLeftCorner, Point2D botRightCorner.
*
* @return if a matching customBlockShape was found that corresponds to the given block.
* @modifies the array of cornerPoints if method returns true
*/
public boolean checkCustomShapes(Block b, Point2D[] cornerPoints, int labelsWidth, int totalSocketHeight) {
//for every customBlockShape
for(CustomBlockShape cbs : customBlockShapes) {
//check genus for a match
if(b.getGenusName().equals(cbs.genusName)) {
//set corner points, making room for the labelWidth
cornerPoints[0] = (Point2D) cbs.topLeftCorner.clone();
cornerPoints[1] = new Point2D.Double(cbs.topRightCorner.getX() + labelsWidth,
cbs.topRightCorner.getY());
cornerPoints[2] = new Point2D.Double(cbs.botLeftCorner.getX(), cbs.botLeftCorner.getY() +totalSocketHeight);
cornerPoints[3] = new Point2D.Double(cbs.botRightCorner.getX() + labelsWidth,
cbs.botRightCorner.getY() + totalSocketHeight);
return true;
}
}
//else no match was found
return false;
}
}