-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathBlockImageIcon.java
More file actions
80 lines (66 loc) · 3.05 KB
/
Copy pathBlockImageIcon.java
File metadata and controls
80 lines (66 loc) · 3.05 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.renderable;
import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
* BlockImageIcon holds information regarding the ImageIcons drawn within a RenderableBlock. This information
* includes the following:
* - ImageIcon instance to draw
* - ImageLocation that represents the exact location of the ImageIcon on the RenderableBlock. (There is only one
* BlockImageIcion per ImageLocation. This is reinforced within the BlockImageMap in the BlockGenus instance.)
*
*/
public class BlockImageIcon extends JLabel{
private static final long serialVersionUID = 328149080423L;
/**
* ImageLocation specifies the relative location of this BlockImageIcon within the visible
* Block instance of this BlockGenus.
*
* Note: there is only one BlockImageIcon per ImageLocation within a Block
*/
public enum ImageLocation {
CENTER, EAST, WEST, NORTH, SOUTH, SOUTHEAST, SOUTHWEST, NORTHEAST, NORTHWEST;
public static ImageLocation getImageLocation(String s) {
for (ImageLocation loc : values()) {
if (loc.toString().equalsIgnoreCase(s)) {
return loc;
}
}
return null;
}
}
private ImageIcon blockImageIcon;
private ImageLocation location;
private boolean isEditable;
private boolean wrapText;
/**
* Constructs a new BlockImageIcon from the specified parameters.
* @param blockImageIcon ImageIcon to draw on a block
* @param location ImageLocation of this ImageIcon
* @param isEditable if true, this instance may be replaced at the specified ImageLocation
* @param wrapText if true, the block labels of the RendearbleBlock will not overlap the ImageIcon drawn on it at
* the specified location
*/
public BlockImageIcon(ImageIcon blockImageIcon, ImageLocation location, boolean isEditable, boolean wrapText){
super(blockImageIcon);
setPreferredSize(new Dimension(blockImageIcon.getIconWidth(), blockImageIcon.getIconHeight()));
setSize(new Dimension(blockImageIcon.getIconWidth(), blockImageIcon.getIconHeight()));
setMinimumSize(new Dimension(blockImageIcon.getIconWidth(), blockImageIcon.getIconHeight()));
this.blockImageIcon = blockImageIcon;
this.location = location;
this.isEditable = isEditable;
this.wrapText = wrapText;
}
public ImageIcon getImageIcon(){ return blockImageIcon; }
public void setImageIcon(ImageIcon icon){
blockImageIcon = icon;
super.setIcon(icon);
}
public ImageLocation getImageLocation() { return location; }
public boolean isEditable() { return isEditable; }
public boolean wrapText(){ return wrapText; }
}