-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathBlockNoteLabel.java
More file actions
93 lines (82 loc) · 2.49 KB
/
Copy pathBlockNoteLabel.java
File metadata and controls
93 lines (82 loc) · 2.49 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
85
86
87
88
89
90
91
92
93
// -*- 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 java.awt.event.MouseEvent;
import openblocks.workspace.Workspace;
import openblocks.workspace.WorkspaceEvent;
/**
* The BlockNoteLabel class controls the visibility of a BlockNote on a
* RenderableBlock
*
*/
public class BlockNoteLabel extends BlockControlLabel {
private static final long serialVersionUID = 1L;
public static final int BLOCK_NOTE_LABEL_SIZE = 14; // pixels, unzoomed
private final BlockNote balloon;
public BlockNoteLabel(long blockID, BlockNote balloon, String labelText) {
super(blockID);
setText(labelText);
this.balloon = balloon;
setBackground(Color.darkGray);
setOpaque(true);
}
@Override
public void setActive(boolean active) {
super.setActive(active);
balloon.setVisible(active);
}
/**
* setup current visual state of button
*/
@Override
public void update() {
RenderableBlock rb = RenderableBlock.getRenderableBlock(getBlockID());
if (rb != null) {
Point location = rb.getUnscaledBlockNoteLabelLocation(this);
setLocation(rb.rescale(location.x), rb.rescale(location.y));
setSize(rb.rescale(BLOCK_NOTE_LABEL_SIZE), rb.rescale(BLOCK_NOTE_LABEL_SIZE));
setForeground(isActive() ? Color.WHITE : Color.LIGHT_GRAY);
}
}
/**
* Implement MouseListener interface
* toggle collapse state of block if button pressed
*/
@Override
public void mouseClicked(MouseEvent e) {
toggle();
RenderableBlock rb = RenderableBlock.getRenderableBlock(getBlockID());
balloon.setVisible(isActive());
Workspace.getInstance().notifyListeners(new WorkspaceEvent(balloon.getRenderableBlock().
getParentWidget(), WorkspaceEvent.BLOCK_NOTE_VISIBILITY_CHANGE));
update();
rb.revalidate();
rb.repaint();
Workspace.getInstance().getMiniMap().repaint();
}
/**
* highlight button state
* Flash balloon
*/
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
balloon.setVisible(true);
balloon.showOnTop();
}
/**
* de-highlight button state
* Hide inactive balloon
*/
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
if (!isActive()) {
balloon.setVisible(false);
}
}
}