-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathNameLabel.java
More file actions
55 lines (49 loc) · 1.62 KB
/
Copy pathNameLabel.java
File metadata and controls
55 lines (49 loc) · 1.62 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
// -*- 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.renderable;
import java.awt.Color;
import java.awt.Point;
import openblocks.codeblocks.BlockConnectorShape;
import openblocks.codeblocks.BlockShape;
/**
* NameLabel displays the name of a RenderableBlock
*/
class NameLabel extends BlockLabel{
private long blockID;
public NameLabel(String initLabelText, BlockLabel.Type labelType, boolean isEditable,
long blockID) {
super(initLabelText, labelType, isEditable, blockID, true, Color.WHITE);
this.blockID = blockID;
}
Point getUnscaledNameLabelLocation() {
int x = 0;
int y = 0;
RenderableBlock rb = RenderableBlock.getRenderableBlock(blockID);
if (rb != null) {
Point labelLoc = rb.getUnscaledBlockLabelLocation();
x = labelLoc.x;
y = labelLoc.y;
if (rb.getBlockWidget() == null && rb.getAbstractBlockArea() != null) {
y += rb.getAbstractBlockArea().getBounds().height / 2;
} else {
y += 12;
}
if (rb.getBlock().isCommandBlock()) {
y -= 2;
}
if(rb.getBlock().hasPageLabel() && rb.getBlock().hasAfterConnector()) {
y -= BlockConnectorShape.CONTROL_PLUG_HEIGHT;
}
if(!rb.getBlock().hasPageLabel()) {
y -= getAbstractHeight() / 2;
}
}
return new Point(x, y);
}
void update() {
Point usp = getUnscaledNameLabelLocation();
setPixelLocation(rescale(usp.x), rescale(usp.y));
}
}