-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathCollapseLabel.java
More file actions
84 lines (68 loc) · 2.61 KB
/
Copy pathCollapseLabel.java
File metadata and controls
84 lines (68 loc) · 2.61 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
81
82
83
84
// -*- 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.event.MouseEvent;
import javax.swing.SwingConstants;
/**
* CollapseLabel is a label that can be added to a renderable block that
* will cause all blocks after this block to be hidden from view when
* the isCollapsed parameter is true.
*
*
*/
class CollapseLabel extends BlockControlLabel {
private static final long serialVersionUID = 1L;
// we use small up/down triangles as collapse/expand
// the offsets are hand-tweaked to match
private static final String COLLAPSE_SYMBOL = "\u25B4";
private static final String EXPAND_SYMBOL = "\u25BE";
// offset of the hotspot -- the pointer is at center of hotspot
private static final int LABEL_X_OFFSET = 0;
private static final int LABEL_Y_OFFSET = 0;
// size of the hotspot
private static final int LABEL_WIDTH = 20;
private static final int LABEL_HEIGHT = 40;
CollapseLabel(long blockID) {
super(blockID);
}
/**
* setup current visual state of button
*/
@Override
public void update() {
RenderableBlock rb = RenderableBlock.getRenderableBlock(getBlockID());
if (rb != null) {
int x = 0;
int y = 0;
// The hotspot (label) is at the upper left of the block, as
// specified by these offsets.
y += LABEL_Y_OFFSET;
x += LABEL_X_OFFSET;
// Note: If we want to position the label at the bottom of the block, we
// we could do it like this:
// y += rb.getBlockHeight()/rb.getZoom() - 22 +
// (isActive() ? BlockConnectorShape.CONTROL_PLUG_HEIGHT : 0);
x=rb.rescale(x);
y=rb.rescale(y);
setLocation(x, y);
setSize(rb.rescale(LABEL_WIDTH), rb.rescale(LABEL_HEIGHT));
setVerticalAlignment(SwingConstants.CENTER);
setHorizontalAlignment(SwingConstants.CENTER);
if (isActive()) {
setText(EXPAND_SYMBOL);
} else {
setText(COLLAPSE_SYMBOL);
}
}
}
/**
* Implement MouseListener interface
* toggle collapse state of block if button pressed
*/
@Override
public void mouseClicked(MouseEvent e) {
RenderableBlock.getRenderableBlock(getBlockID()).setCollapsed(!isActive());
}
}