use of org.loboevolution.html.node.Node in project LoboEvolution by LoboEvolution.
the class ElementPropertiesPanel method tableModel.
private TableModel tableModel(Node node) {
if (node.getNodeType() != NodeType.ELEMENT_NODE) {
Toolkit.getDefaultToolkit().beep();
return _defaultTableModel;
}
HTMLElementImpl elm = (HTMLElementImpl) node;
Map<String, String> cssProperties = new HashMap<>();
final String classNames = elm.getClassName();
final String elementName = elm.getTagName();
final String[] classNameArray = Strings.isNotBlank(classNames) ? Strings.split(classNames) : null;
final List<CSSStyleSheetImpl.SelectorEntry> matchingRules = elm.findStyleDeclarations(elementName, classNameArray, false);
for (CSSStyleSheetImpl.SelectorEntry entry : matchingRules) {
final CSSStyleDeclarationImpl styleDeclaration = entry.getRule().getStyle();
styleDeclaration.getProperties().forEach(prop -> {
final String propertyName = prop.getName();
final String propertyValue = styleDeclaration.getPropertyValue(propertyName);
cssProperties.put(propertyName.toLowerCase(), propertyValue);
});
}
List<CSSStyleDeclarationImpl> styleDeclaration = elm.getStyle().getStyleDeclarations();
if (styleDeclaration != null) {
styleDeclaration.forEach(decl -> decl.getProperties().forEach(prop -> {
final String propertyName = prop.getName();
final String propertyValue = decl.getPropertyValue(propertyName);
cssProperties.put(propertyName.toLowerCase(), propertyValue);
}));
}
return new PropertiesTableModel(cssProperties);
}
use of org.loboevolution.html.node.Node in project LoboEvolution by LoboEvolution.
the class HTMLOptionsCollectionImpl method addElements.
private void addElements(HTMLOptionElement element, HTMLElement before) {
List<Node> nodeList = getList();
if (nodeList.size() == 0) {
nodeList.add(0, element);
} else {
boolean found = false;
HTMLOptionElement bef = (HTMLOptionElement) before;
for (int i = 0; i < nodeList.size(); i++) {
HTMLOptionElement elem = (HTMLOptionElement) nodeList.get(i);
if (elem.getText().equals(bef.getText())) {
nodeList.add(i, element);
found = true;
break;
}
}
if (!found)
throw new DOMException(DOMException.NOT_FOUND_ERR, "Record not found");
}
}
use of org.loboevolution.html.node.Node in project LoboEvolution by LoboEvolution.
the class SVGClipPathElementImpl method getClippingShape.
/**
* <p>getClippingShape.</p>
*
* @param clippedElement a {@link org.loboevolution.html.dom.svg.SVGElement} object.
* @return a {@link java.awt.Shape} object.
*/
protected Shape getClippingShape(SVGElement clippedElement) {
Area clipArea = null;
AffineTransform clipTransform = new AffineTransform();
if (hasChildNodes()) {
NodeListImpl children = (NodeListImpl) getChildNodes();
for (Node child : children) {
if (child instanceof SVGUseElementImpl) {
String href = ((SVGUseElementImpl) child).getHref().getAnimVal();
if (href.length() > 0) {
int index = href.indexOf('#');
if (index != -1) {
String id = href.substring(index + 1).trim();
Element ref = (Element) child(id);
if (ref != null) {
Shape childShape = ((Drawable) ref).createShape(clipTransform);
if (childShape != null) {
AffineTransform childAffineTransform = clipTransform;
if (ref instanceof SVGTransformable) {
SVGTransformListImpl childTransform = (SVGTransformListImpl) ((SVGTransformable) ref).getTransform().getAnimVal();
if (childTransform != null) {
childAffineTransform.concatenate(childTransform.getAffineTransform());
}
}
GeneralPath path = new GeneralPath(childShape);
path.transform(childAffineTransform);
String clipRule = ((SVGStylableImpl) child).getClipRule();
SVGClipPathElementImpl clipPath = ((SVGStylableImpl) child).getClippingPath();
if (clipRule.equals("evenodd")) {
path.setWindingRule(Path2D.WIND_EVEN_ODD);
} else {
path.setWindingRule(Path2D.WIND_NON_ZERO);
}
Area childClipArea = new Area(path);
if (clipPath != null) {
Shape clipShape = clipPath.getClippingShape(clippedElement);
if (clipShape != null) {
childClipArea.intersect(new Area(clipShape));
}
}
if (clipArea == null) {
clipArea = childClipArea;
} else {
clipArea.add(childClipArea);
}
}
}
}
}
} else if (child instanceof Drawable) {
Shape childShape = ((Drawable) child).createShape(clipTransform);
if (childShape != null) {
if (child instanceof SVGTransformable) {
SVGAnimatedTransformListImpl childTransform = (SVGAnimatedTransformListImpl) ((SVGTransformable) child).getTransform();
if (childTransform != null) {
clipTransform.concatenate(((SVGTransformListImpl) childTransform.getAnimVal()).getAffineTransform());
}
}
GeneralPath path = new GeneralPath(childShape);
path.transform(clipTransform);
String clipRule = ((SVGStylableImpl) child).getClipRule();
SVGClipPathElementImpl clipPath = ((SVGStylableImpl) child).getClippingPath();
if (clipRule.equals("evenodd")) {
path.setWindingRule(Path2D.WIND_EVEN_ODD);
} else {
path.setWindingRule(Path2D.WIND_NON_ZERO);
}
Area childClipArea = new Area(path);
// see if child has a clipPath property
if (clipPath != null) {
Shape clipShape = clipPath.getClippingShape(clippedElement);
if (clipShape != null) {
childClipArea.intersect(new Area(clipShape));
}
}
if (clipArea == null) {
clipArea = childClipArea;
} else {
clipArea.add(childClipArea);
}
}
}
}
}
SVGClipPathElementImpl clipPath = getClippingPath();
getClipRule();
if (clipPath != null) {
Shape clipShape = clipPath.getClippingShape(clippedElement);
if (clipShape != null) {
if (clipArea == null) {
clipArea = new Area(clipShape);
} else {
clipArea.intersect(new Area(clipShape));
}
}
}
if (clipArea != null) {
Shape clipShape = clipArea;
if (getClipPathUnits().getAnimVal() == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
SVGRectImpl bbox = null;
if (clippedElement instanceof SVGTransformable) {
bbox = (SVGRectImpl) ((SVGTransformable) clippedElement).getBBox();
} else if (clippedElement instanceof SVGSVGElementImpl) {
bbox = (SVGRectImpl) ((SVGSVGElementImpl) clippedElement).getBBox();
}
if (bbox != null) {
AffineTransform clipTrans = AffineTransform.getTranslateInstance(bbox.getX(), bbox.getY());
clipTrans.scale(bbox.getWidth(), bbox.getHeight());
clipShape = clipTrans.createTransformedShape(clipShape);
return clipShape;
}
}
}
return clipArea;
}
use of org.loboevolution.html.node.Node in project LoboEvolution by LoboEvolution.
the class XPathNSResolverImpl method lookupNamespaceURI.
/**
* {@inheritDoc}
*/
@Override
public String lookupNamespaceURI(String prefix) {
String namespace = null;
if (prefix.equals("xml")) {
namespace = Constants.S_XMLNAMESPACEURI;
} else {
int type;
while ((null != parent) && (null == namespace) && (((type = parent.getNodeType()) == NodeType.ELEMENT_NODE) || ((type = parent.getNodeType()) == NodeType.DOCUMENT_NODE) || (type == NodeType.ENTITY_REFERENCE_NODE))) {
if (type == NodeType.DOCUMENT_NODE) {
Document document = (Document) parent;
Element docelm = document.getDocumentElement();
if (docelm != null && docelm.getNodeName().indexOf(prefix.toUpperCase() + ":") == 0) {
return docelm.getNamespaceURI();
}
}
if (type == NodeType.ELEMENT_NODE) {
if (parent.getNodeName().indexOf(prefix.toUpperCase() + ":") == 0) {
return parent.getNamespaceURI();
}
NamedNodeMap nnm = ((Element) parent).getAttributes();
for (int i = 0; i < nnm.getLength(); i++) {
Node attr = nnm.item(i);
String aname = attr.getNodeName();
boolean isPrefix = aname.startsWith("xmlns:");
if (isPrefix || aname.equals("xmlns")) {
int index = aname.indexOf(':');
String p = isPrefix ? aname.substring(index + 1) : "";
if (p.equals(prefix)) {
namespace = attr.getNodeValue();
break;
}
}
}
}
parent = parent.getParentNode();
}
}
return namespace;
}
use of org.loboevolution.html.node.Node in project LoboEvolution by LoboEvolution.
the class XPathResultImpl method getSingleNodeValue.
/**
* {@inheritDoc}
*/
@Override
public Node getSingleNodeValue() throws XPathException {
if (m_resultType != ANY_UNORDERED_NODE_TYPE && m_resultType != FIRST_ORDERED_NODE_TYPE) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] { m_xpath.getPatternString(), getTypeString(m_resultType) });
throw new XPathException(XPathException.TYPE_ERR, fmsg);
// "The XPathResult of XPath expression {0} has an XPathResultType
// of {1} which cannot be converted to a single node.
// This method applies only to types ANY_UNORDERED_NODE_TYPE and
// FIRST_ORDERED_NODE_TYPE."
}
NodeIterator result = null;
if (null == result) {
return null;
}
Node node = result.nextNode();
if (isNamespaceNode(node)) {
return new XPathNamespaceImpl(node);
} else {
return node;
}
}
Aggregations