-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathSocketLabel.java
More file actions
57 lines (52 loc) · 2.15 KB
/
Copy pathSocketLabel.java
File metadata and controls
57 lines (52 loc) · 2.15 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
// -*- 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.geom.Point2D;
import openblocks.codeblocks.BlockConnector;
import openblocks.codeblocks.BlockConnectorShape;
class SocketLabel extends BlockLabel{
private BlockConnector socket;
SocketLabel(BlockConnector socket, String initLabelText, BlockLabel.Type labelType, boolean isEditable, long blockID){
super(initLabelText, labelType, isEditable, blockID, false, new Color(190, 250, 125));
this.socket = socket;
}
/**
* Returns true if the socket label should not be added to this. Conditions for ignoring socket labels are:
* 1. the specified socket is a bottom socket
* 2. the specified socket has an empty label
* @param socket the BlockConnector to test
* @return true if the specified socket should have a corresponding Blocklabel instance added to this.
*/
static boolean ignoreSocket(BlockConnector socket){
return (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) || socket.getLabel().equals("");
}
void update(Point2D socketPoint){
if(ignoreSocket(socket)) return;
//abstarct location so we need to tranform it
double x;
double y;
if (BlockConnectorShape.isCommandConnector(socket)) {
//command socket
x = -8 - BlockConnectorShape.COMMAND_INPUT_BAR_WIDTH + socketPoint.getX();
y = -4 + socketPoint.getY();
}else{
//data socket
x = -4 - BlockConnectorShape.getConnectorDimensions(socket).width + socketPoint.getX();
y = -10 + socketPoint.getY();
}
x = - this.getAbstractWidth() + x;
this.setPixelLocation(rescale(x), rescale(y));
}
@Override
protected void textChanged(String text) {
// Prevents running this when sockets are null.
// Sockets can be null during loading.
if (socket != null){
socket.setLabel(text);
super.textChanged(text);
}
}
}