-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathComplaint.java
More file actions
109 lines (94 loc) · 3.55 KB
/
Copy pathComplaint.java
File metadata and controls
109 lines (94 loc) · 3.55 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// -*- 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 openblocks.yacodeblocks.Escapers;
import openblocks.codeblocks.ComplaintDepartment;
import openblocks.codeblockutil.CGraphite;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.awt.Dimension;
import javax.swing.JTextArea;
/**
*
* Complaint stores and displays errors and warnings.
*
*/
public class Complaint extends BlockNote {
private static final long serialVersionUID = 328149080425L;
private static int INITIAL_WIDTH = 280;
private static int INITIAL_HEIGHT = 60;
private static int MAX_WIDTH = 400;
/**
* Constructs a Complaint
* @param source block that the comment is linked to.
*/
public Complaint(RenderableBlock source){
this(new JTextArea(), source);
}
private Complaint(JTextArea label, RenderableBlock source) {
super(label, source, "!", CGraphite.complaint_background, true,
MAX_WIDTH, INITIAL_HEIGHT);
textContent = label;
textContent.setEditable(false);
textContent.setLineWrap(true);
textContent.setWrapStyleWord(true);
fontMetrics = getFontMetrics(label.getFont());
int textPadding = fontMetrics.stringWidth("M") * TEXT_PADDING_EMS;
setBlockNoteSize(new Dimension(INITIAL_WIDTH, INITIAL_HEIGHT));
source.chooseLocationForBalloon(this, INITIAL_WIDTH, INITIAL_HEIGHT);
}
/**
* @return The complaint's text
*/
public String getText() {
return textContent.getText();
}
/**
* String representation of this
*/
@Override
public String toString() {
return "Complaint ID: " + " at " + getLocation() + " with text: \""
+ getText() + "\"";
}
@Override
public String getSaveString() {
StringBuffer saveString = new StringBuffer();
saveString.append("<Complaint>\n");
saveString.append("<Text>");
String textValue = getText().replaceAll("`", "'");
// Encode complaints to preserve international characters.
textValue = Escapers.encodeInternationalCharacters(textValue);
saveString.append(Escapers.escapeForXml(textValue));
saveString.append("</Text>");
saveString.append(super.getSaveString());
saveString.append("</Complaint>\n");
return saveString.toString();
}
/**
* Loads the BlockNote from a NodeList of parts
* @param complaintChildren
* @param rb
* @return the BlockNote from a NodeList of Complaint/BlockNote parts
*/
public static Complaint loadComplaint(NodeList complaintChildren, RenderableBlock rb) {
Complaint complaint = new Complaint(rb);
for (int j = 0; j < complaintChildren.getLength(); j++) {
Node complaintChild = complaintChildren.item(j);
if (complaintChild.getNodeName().equals("Text")) {
String textValue = complaintChild.getTextContent();
// Decode complaints to preserve international characters.
textValue = Escapers.decodeInternationalCharacters(textValue);
complaint.setText(textValue);
break;
}
}
loadBlockNote(complaintChildren, rb, complaint);
complaint.getBlockNoteLabel().setBackground(
complaint.getText().contains("Error") ? ComplaintDepartment.ERROR_COLOR
: ComplaintDepartment.WARNING_COLOR);
return complaint;
}
}