use of com.codename1.xml.Element in project CodenameOne by codenameone.
the class Tree method collapsePath.
/**
* Collapses the last element in the path
* @param path the path to the element that should be collapsed
*/
public void collapsePath(Object... path) {
Container c = this;
int plen = path.length;
for (int iter = 0; iter < plen - 1; iter++) {
c = expandPathNode(isInitialized(), c, path[iter]);
}
collapsePathNode(c, path[plen - 1]);
}
use of com.codename1.xml.Element in project CodenameOne by codenameone.
the class ResourceEditorView method genericRemoveElement.
public void genericRemoveElement(String element) {
Object value = loadedResources.getResourceObject(element);
if (value instanceof com.codename1.ui.Image || value instanceof EditableResources.MultiImage) {
removeImageOrAnimation(element);
return;
}
if (value instanceof com.codename1.ui.Font) {
removeFont(element);
return;
}
if (Arrays.asList(loadedResources.getUIResourceNames()).contains(element)) {
String usedBy = getUiResourceInUse(element);
if (usedBy != null) {
JOptionPane.showMessageDialog(mainPanel, element + " is used by " + usedBy, "Resource In Use", JOptionPane.ERROR_MESSAGE);
return;
}
}
removeSelection(element);
themeList.refresh();
dataList.refresh();
l10nList.refresh();
uiList.refresh();
}
use of com.codename1.xml.Element in project CodenameOne by codenameone.
the class ResourceEditorView method isUiResourceInUse.
private boolean isUiResourceInUse(final String element, String resource) {
final boolean[] flag = new boolean[1];
UIBuilder uib = new UIBuilder() {
public com.codename1.ui.Container createContainer(Resources res, String resourceName) {
flag[0] = flag[0] || element.equals(resourceName);
return super.createContainer(res, resourceName);
}
};
uib.createContainer(loadedResources, resource);
return flag[0];
}
use of com.codename1.xml.Element in project CodenameOne by codenameone.
the class RSSService method readResponse.
/**
* {@inheritDoc}
*/
protected void readResponse(InputStream input) throws IOException {
results = new Vector();
class FinishParsing extends RuntimeException {
}
XMLParser p = new XMLParser() {
private String lastTag;
private Hashtable current;
private String url;
protected boolean startTag(String tag) {
if ("item".equalsIgnoreCase(tag) || "entry".equalsIgnoreCase(tag)) {
if (startOffset > 0) {
return true;
}
current = new Hashtable();
if (iconPlaceholder != null) {
current.put("icon", iconPlaceholder);
}
}
lastTag = tag;
return true;
}
protected void attribute(String tag, String attributeName, String value) {
if (current != null) {
if ("media:thumbnail".equalsIgnoreCase(tag) && "url".equalsIgnoreCase(attributeName)) {
current.put("thumb", value);
} else {
if ("media:player".equalsIgnoreCase(tag) && "url".equalsIgnoreCase(attributeName)) {
current.put("player", value);
}
}
}
}
protected void textElement(String text) {
if (lastTag != null && current != null) {
// make "ATOM" seem like RSS
if ("summary".equals(lastTag)) {
current.put("details", text);
} else {
if ("content".equals(lastTag)) {
current.put("description", text);
} else {
current.put(lastTag, text);
}
}
}
}
protected void endTag(String tag) {
if ("item".equalsIgnoreCase(tag) || "entry".equalsIgnoreCase(tag)) {
if (startOffset > 0) {
startOffset--;
return;
}
results.addElement(current);
current = null;
if (limit > -1 && results.size() >= limit) {
throw new FinishParsing();
}
}
if (tag.equals(lastTag)) {
lastTag = null;
}
}
};
p.setParserCallback(this);
input.mark(10);
// Skip the bom marking UTF-8 in some streams
while (input.read() != '<') {
// input.mark(4);
}
int question = input.read();
String cType = "UTF-8";
if (question == '?') {
// we are in an XML header, check if the encoding section exists
StringBuilder cs = new StringBuilder();
question = input.read();
while (question != '>') {
cs.append((char) question);
question = input.read();
}
String str = cs.toString();
int index = str.indexOf("encoding=\"") + 10;
if (index > -1) {
cType = str.substring(index, Math.max(str.indexOf("\"", index), str.indexOf("'", index)));
}
} else {
// oops, continue as usual
input.reset();
}
String resultType = getResponseContentType();
if (resultType != null && resultType.indexOf("charset=") > -1) {
cType = resultType.substring(resultType.indexOf("charset=") + 8);
}
try {
int pos2 = cType.indexOf(';');
if (pos2 > 0) {
cType = cType.substring(0, pos2);
}
p.eventParser(new InputStreamReader(input, cType));
} catch (FinishParsing ignor) {
hasMore = true;
}
if (isCreatePlainTextDetails()) {
int elementCount = results.size();
for (int iter = 0; iter < elementCount; iter++) {
Hashtable h = (Hashtable) results.elementAt(iter);
String s = (String) h.get("description");
if (s != null && !h.containsKey("details")) {
XMLParser x = new XMLParser();
Element e = x.parse(new CharArrayReader(("<xml>" + s + "</xml>").toCharArray()));
Vector results = e.getTextDescendants(null, false);
StringBuilder endResult = new StringBuilder();
for (int i = 0; i < results.size(); i++) {
endResult.append(((Element) results.elementAt(i)).getText());
}
h.put("details", endResult.toString());
}
}
}
fireResponseListener(new NetworkEvent(this, results));
}
use of com.codename1.xml.Element in project CodenameOne by codenameone.
the class Container method calculateFirstPaintableOffset.
/**
* Efficiently finds the first child component that is visible in the specified
* bounds.
* <p>This is only really helpful if the child components are sorted
* in some way so that we can quickly (with a binary search) find the first
* visible component. E.g. In BoxLayout.Y_AXIS, the components are arranged
* vertically in order of their index so we can use a binary search to find
* the first visible element. For most other layout managers we can't as easily
* do a sort like this.</p>
*
* <p>If the layout manager doesn't allow for a binary search, then this will
* just return 0 (meaning that you need to scan the children from the beginning
* to find visible children).</p>
*
* <p>After you obtain this value, use the {@link #calculateLastPaintableOffset(int, int, int, int, int) } method
* to get the end of the visible region.</p>
*
* <p>The motivation for this is to try to improve performance in places where the container
* has many (say 2500) children, and most of them aren't actually visible.</p>
*
* @param clipX1 Left bounds of region to check. (0,0) is the top left corner of this component.
* @param clipY1 Top bounds of region to check. (0,0) is top left corner of this component.
* @param clipX2 Right bounds of region to check. (0,0) is top left corner of this component.
* @param clipY2 Bottom bounds of region to check. (0,0) is top left corner of this component.
* @return The index within the "components" array where the first child that intersects the provided
* clip occurs, or -1 if there is no "fast" way to find it. If there was a fast way to do it, but no visible
* components were found, then this will return components.size().
*
* @see #calculateLastPaintableOffset(int, int, int, int, int)
*/
private int calculateFirstPaintableOffset(int clipX1, int clipY1, int clipX2, int clipY2) {
int len = components.size();
Layout l = getLayout();
if (l.getClass() == BoxLayout.class) {
if (((BoxLayout) l).getAxis() == BoxLayout.Y_AXIS) {
// Use a binary search to find the first visible
int startPos = binarySearchFirstIntersectionY(clipY1, clipY2, 0, len);
if (startPos >= 0) {
return startPos;
} else {
return len;
}
}
}
return -1;
}
Aggregations