당신은 할 수 있습니다 ...하지만 정말 간단하지 않습니다 ... 왜냐하면 JEditorPane은 CSS 절대 위치 지정을 가지고 있지 않기 때문에 어떤 요소가 위치를 가졌는지를 인식해야합니다 : 절대 위치 또는 위치 : 같은 고정 된 속성은 ViewFactory의 확장, 무엇인가 : 당신은이에 (이미지를 배치하는 경우이 경우
public class ExtendedHTMLEditorKit extends HTMLEditorKit{
//.... other code here
public class MyHTMLFactory extends HTMLFactory{
//other code here
@Override
public View create(Element elem) {
if (isLayered(elem)){ //it means, it has position attribute
return new PositionedView(elem);
}
else
return super.create(elem);
}
boolean isLayered(Element elem){
SimpleAttributeSet sas = new SimpleAttributeSet(elem);
StyleSheet styles = (HTMLDocument elem.getDocument).getStyleSheet();
Tag tag = element.getAttributes().getAttribute(AttributeSet.NameAttribute);
sas.addAttributes(styleSheet.getRule(tag, element));
return sas.isDefined("position")
&& !sas.getAttribute("position").toString().equalsIgnorecase("static");
}
}
}
, 우리는 ... 나도 몰라 당신의 요소에 대한 정확한 뷰를 구축 한 후 필요 간단한 것일 수도 있습니다.) 많은 것들을 ... 코드에서 볼 수 있습니다. divs를 사용하고 있습니다 ...
내가하는 일을 더 많이 설명하겠습니다. 구성 요소를 만들었습니다. 새로운 JEditorPane을보고, 원래 요소의 innerCode를 배치 한 다음 부모 에디터의 올바른 위치로 옮긴다.
이것을 동기화하는 것은 정말 어렵다. ... 나는이 당신을 도움이되기를 바랍니다
public class PositionedView extends ComponentView{
private JEditorPane view;
private JEditorPane parent;
@Override
public Component createComponent(){
if (view == null){
view = new JEditorPane();
}
String innerText = dumpInnerText(getElement());
view.setText(innerText);
view.setLocation(getAbsoluteX(), getAbsoluteY());
parent.add(view);
}
@Override
public void setParent(View parent) {
if (parent != null) {
java.awt.Container host = parent.getContainer();
if (host != null && host instanceof JEditorPane) {
parent = (JEditorPane) host;
}
}
super.setParent(parent);
}
protected int getAbsoluteX() {
//search for the attribute left or right and calculate the position over parent
}
protected int getAbsoluteY(){
//search for the attribute top or bottom and calculate the position over parent
}
protected String dumpInnerText(Element element){
//there are several ways to do it, I used my own reader/writer,
//because I've need add special tags support...
}
}
아 : 만 whant 표시를 사용하는 경우 편집하지만,이 같은
확인 .. 뷰가 있어야합니다 ... 더 간단합니다 ! 또 다른 일이 있습니다 : 이렇게하면 뷰가 불투명하지 않게 보호해야합니다. 즉, 모든 뷰 요소, 다른 경우에는 요소에 대해 빈 칸을 갖게됩니다.
또 다른 것은 뷰의 정확한 치수를 확인해야 할 수도 있습니다. width/height 속성을 얻기 위해 getAbsoluteX/getAbsoluteY를 수행해야 할 수도 있습니다.
분명한 답변을 보내 주셔서 감사합니다. – krslynx
p.s. 필자는 FlyingSaucer라는 타사 라이브러리를 사용하여이 문제를 해결했습니다. – krslynx