4 * Copyright 2010 Codist Monk.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 package net
.sourceforge
.aprog
.markups
;
27 import static javax
.swing
.KeyStroke
.getKeyStroke
;
29 import static net
.sourceforge
.aprog
.i18n
.Messages
.*;
30 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.*;
31 import static net
.sourceforge
.aprog
.markups
.MarkupsXMLTools
.*;
32 import static net
.sourceforge
.aprog
.subtitlesadjuster
.SubtitlesAdjusterTools
.*;
33 import static net
.sourceforge
.aprog
.subtitlesadjuster
.SubtitlesAdjusterTools
.menu
;
34 import static net
.sourceforge
.aprog
.swing
.SwingTools
.checkAWT
;
35 import static net
.sourceforge
.aprog
.swing
.SwingTools
.menuBar
;
36 import static net
.sourceforge
.aprog
.swing
.SwingTools
.packAndCenter
;
37 import static net
.sourceforge
.aprog
.swing
.SwingTools
.scrollable
;
38 import static net
.sourceforge
.aprog
.tools
.Tools
.*;
39 import static net
.sourceforge
.aprog
.xml
.XMLTools
.*;
41 import java
.awt
.BorderLayout
;
42 import java
.awt
.Color
;
43 import java
.awt
.Component
;
44 import java
.awt
.dnd
.DropTarget
;
45 import java
.awt
.dnd
.DropTargetAdapter
;
46 import java
.awt
.dnd
.DropTargetDragEvent
;
47 import java
.awt
.dnd
.DropTargetDropEvent
;
48 import java
.awt
.dnd
.DropTargetEvent
;
49 import java
.awt
.event
.ActionEvent
;
50 import java
.awt
.event
.ActionListener
;
51 import java
.awt
.event
.WindowListener
;
52 import java
.io
.ByteArrayOutputStream
;
54 import java
.util
.List
;
56 import javax
.swing
.BorderFactory
;
57 import javax
.swing
.DefaultListModel
;
58 import javax
.swing
.JButton
;
59 import javax
.swing
.JFrame
;
60 import javax
.swing
.JList
;
61 import javax
.swing
.JMenuBar
;
62 import javax
.swing
.JMenuItem
;
63 import javax
.swing
.JPanel
;
64 import javax
.swing
.JSplitPane
;
65 import javax
.swing
.JTabbedPane
;
66 import javax
.swing
.JTextArea
;
67 import javax
.swing
.JTextField
;
68 import javax
.swing
.JTree
;
69 import javax
.swing
.SwingUtilities
;
70 import javax
.swing
.border
.TitledBorder
;
71 import javax
.swing
.event
.DocumentEvent
;
72 import javax
.swing
.event
.DocumentListener
;
73 import javax
.swing
.event
.TreeSelectionEvent
;
74 import javax
.swing
.event
.TreeSelectionListener
;
75 import javax
.swing
.tree
.DefaultMutableTreeNode
;
76 import javax
.swing
.tree
.DefaultTreeModel
;
78 import net
.sourceforge
.aprog
.context
.Context
;
79 import net
.sourceforge
.aprog
.events
.Variable
;
80 import net
.sourceforge
.aprog
.events
.Variable
.ValueChangedEvent
;
81 import net
.sourceforge
.aprog
.i18n
.Translator
;
82 import net
.sourceforge
.aprog
.subtitlesadjuster
.SubtitlesAdjusterActions
;
83 import net
.sourceforge
.aprog
.subtitlesadjuster
.SubtitlesAdjusterComponents
;
84 import net
.sourceforge
.aprog
.swing
.SwingTools
;
85 import net
.sourceforge
.aprog
.tools
.IllegalInstantiationException
;
86 import net
.sourceforge
.aprog
.xml
.XMLTools
;
87 import net
.sourceforge
.jmacadapter
.MacAdapterTools
;
89 import org
.w3c
.dom
.NamedNodeMap
;
90 import org
.w3c
.dom
.Node
;
91 import org
.w3c
.dom
.events
.Event
;
92 import org
.w3c
.dom
.events
.EventListener
;
96 * @author codistmonk (creation 2010-07-03)
98 public final class MarkupsComponents
{
101 * @throws IllegalInstantiationException To prevent instantiation
103 private MarkupsComponents() {
104 throw new IllegalInstantiationException();
116 public static final JFrame
newMainFrame(final Context context
) {
117 final JFrame result
= new JFrame();
119 context
.set(MAIN_FRAME
, result
);
121 result
.setJMenuBar(newMenuBar(context
));
122 result
.add(newMainPanel(context
));
124 result
.addWindowListener(newListener(WindowListener
.class, "windowClosing",
125 MarkupsActions
.class, "quit", context
));
127 invokeOnVariableChanged(context
, FILE
,
128 SubtitlesAdjusterActions
.class, "updateMainFrameTitle", context
);
129 invokeOnVariableChanged(context
, FILE_MODIFIED
,
130 SubtitlesAdjusterActions
.class, "updateMainFrameTitle", context
);
132 Translator
.getDefaultTranslator().addListener(newListener(Translator
.Listener
.class, "localeChanged",
133 SwingTools
.class, "packAndUpdateMinimumSize", result
));
135 return packAndCenter(result
);
147 public static final JMenuBar
newMenuBar(final Context context
) {
150 if (MacAdapterTools
.isMacOSX()) {
151 MacAdapterTools
.setUseScreenMenuBar(true);
156 newAboutMenuItem(context
),
158 newPreferencesMenuItem(context
),
160 newQuitMenuItem(context
)
163 newNewMenuItem(context
),
165 newOpenMenuItem(context
),
167 newSaveMenuItem(context
),
168 newSaveAsMenuItem(context
)
171 newUndoMenuItem(context
),
172 newRedoMenuItem(context
),
174 newCopyMenuItem(context
),
175 newCutMenuItem(context
),
176 newPasteMenuItem(context
)
179 newAppendNewNodeMenuItem(context
),
181 newMoveUpMenuItem(context
),
182 newMoveDownMenuItem(context
)
185 newManualMenuItem(context
)
198 public static final JMenuItem
newAboutMenuItem(final Context context
) {
201 return SubtitlesAdjusterComponents
.newAboutMenuItem(context
);
213 public static final JMenuItem
newPreferencesMenuItem(final Context context
) {
216 return SubtitlesAdjusterComponents
.newPreferencesMenuItem(context
);
228 public static final JMenuItem
newQuitMenuItem(final Context context
) {
231 if (MacAdapterTools
.isMacOSX() && MacAdapterTools
.getUseScreenMenuBar()) {
232 if (registerMacOSXApplicationListener("handleQuit",
233 MarkupsActions
.class, "quit", context
)) {
238 return item("Quit", getKeyStroke(META
+ " Q"),
239 MarkupsActions
.class, "quit", context
);
251 public static final JMenuItem
newNewMenuItem(final Context context
) {
252 return item("New", getKeyStroke(META
+ " N"),
253 MarkupsActions
.class, "newFile", context
);
265 public static final JMenuItem
newOpenMenuItem(final Context context
) {
266 return item("Open...", getKeyStroke(META
+ " O"),
267 MarkupsActions
.class, "open", context
);
279 public static final JMenuItem
newSaveMenuItem(final Context context
) {
280 final JMenuItem result
= item("Save", getKeyStroke(META
+ " S"),
281 MarkupsActions
.class, "save", context
);
282 final Variable
<Boolean
> fileModifiedVariable
= context
.getVariable(FILE_MODIFIED
);
284 fileModifiedVariable
.addListener(new Variable
.Listener
<Boolean
>() {
287 public final void valueChanged(final ValueChangedEvent
<Boolean
, ?
> event
) {
288 result
.setEnabled(event
.getNewValue());
305 public static final JMenuItem
newSaveAsMenuItem(final Context context
) {
306 final JMenuItem result
= item("Save As...", getKeyStroke(META
+ " shift S"),
307 MarkupsActions
.class, "saveAs", context
);
321 public static final JMenuItem
newUndoMenuItem(final Context context
) {
322 final JMenuItem result
= item("Undo", getKeyStroke(META
+ " Z"),
323 MarkupsActions
.class, "undo", context
);
337 public static final JMenuItem
newRedoMenuItem(final Context context
) {
338 final JMenuItem result
= item("Redo", getKeyStroke(META
+ " Y"),
339 MarkupsActions
.class, "redo", context
);
353 public static final JMenuItem
newCopyMenuItem(final Context context
) {
354 final JMenuItem result
= item("Copy", getKeyStroke(META
+ " C"),
355 MarkupsActions
.class, "copy", context
);
369 public static final JMenuItem
newCutMenuItem(final Context context
) {
370 final JMenuItem result
= item("Cut", getKeyStroke(META
+ " X"),
371 MarkupsActions
.class, "cut", context
);
385 public static final JMenuItem
newPasteMenuItem(final Context context
) {
386 final JMenuItem result
= item("Paste", getKeyStroke(META
+ " V"),
387 MarkupsActions
.class, "paste", context
);
401 public static final JMenuItem
newAppendNewNodeMenuItem(final Context context
) {
402 final JMenuItem result
= item("Append New Node",
403 MarkupsActions
.class, "appendNewNode", context
);
417 public static final JMenuItem
newMoveUpMenuItem(final Context context
) {
418 final JMenuItem result
= item("Move Up",
419 MarkupsActions
.class, "moveUp", context
);
433 public static final JMenuItem
newMoveDownMenuItem(final Context context
) {
434 final JMenuItem result
= item("Move Down",
435 MarkupsActions
.class, "moveDown", context
);
449 public static final JMenuItem
newManualMenuItem(final Context context
) {
451 "Manual", getKeyStroke("F1"),
452 SubtitlesAdjusterActions
.class, "showManual", context
);
463 public static final JPanel
newMainPanel(final Context context
) {
464 final JPanel result
= new JPanel(new BorderLayout());
466 result
.add(newMainSplitPane(context
));
468 new DropTarget(result
, new DropTargetAdapter() {
471 public final void dragEnter(final DropTargetDragEvent event
) {
472 result
.setBorder(BorderFactory
.createLineBorder(Color
.GREEN
, 2));
476 public final void dragExit(final DropTargetEvent event
) {
477 result
.setBorder(null);
481 public final void drop(final DropTargetDropEvent event
) {
482 result
.setBorder(null);
484 final List
<File
> files
= SwingTools
.getFiles(event
);
486 if (!files
.isEmpty() && MarkupsActions
.confirm(context
)) {
487 MarkupsActions
.open(context
, files
.get(0));
493 final Variable
<Node
> selectedNodeVariable
= context
.getVariable(DOM
);
495 selectedNodeVariable
.addListener(new Variable
.Listener
<Node
>() {
498 public final void valueChanged(final ValueChangedEvent
<Node
, ?
> event
) {
499 final Node node
= event
.getNewValue();
503 addDOMEventListener(node
, new EventListener() {
506 public final void handleEvent(final Event event
) {
526 public static final JSplitPane
newMainSplitPane(final Context context
) {
527 return new JSplitPane(JSplitPane
.HORIZONTAL_SPLIT
,
528 scrollable(newDOMTreeView(context
)),
529 newContextualSplitPane(context
));
540 public static final JSplitPane
newContextualSplitPane(final Context context
) {
541 return new JSplitPane(JSplitPane
.VERTICAL_SPLIT
,
542 newNodePanel(context
),
543 newXPathPanel(context
));
554 public static final JPanel
newNodePanel(final Context context
) {
555 final JPanel result
= new JPanel(new BorderLayout());
557 result
.add(newNodeNamePanel(context
), BorderLayout
.NORTH
);
558 result
.add(newNodeValuePanel(context
), BorderLayout
.CENTER
);
571 public static final JPanel
newNodeNamePanel(final Context context
) {
572 return newTitledPanel("Name", newNodeNameTextField(context
));
583 public static final JTextField
newNodeNameTextField(final Context context
) {
584 final JTextField result
= new JTextField();
585 final Variable
<Node
> selectedNodeVariable
= context
.getVariable(SELECTED_NODE
);
586 final EventListener nodeListener
= new EventListener() {
589 public final void handleEvent(final Event event
) {
590 final Node node
= selectedNodeVariable
.getValue();
594 result
.setText(node
== null ?
"" : node
.getNodeName());
599 selectedNodeVariable
.addListener(new Variable
.Listener
<Node
>() {
602 public final void valueChanged(final ValueChangedEvent
<Node
, ?
> event
) {
603 if (event
.getOldValue() != null) {
604 removeDOMEventListener(event
.getOldValue(), nodeListener
);
607 final Node node
= event
.getNewValue();
612 addDOMEventListener(node
, nodeListener
);
615 result
.setEditable(node
!= null && set(Node
.ATTRIBUTE_NODE
,
616 Node
.ELEMENT_NODE
).contains(node
.getNodeType()));
618 result
.setText(node
== null ?
"" : node
.getNodeName());
623 result
.getDocument().addDocumentListener(new AbstractDocumentHandler() {
626 protected final void eventReceived(final DocumentEvent event
) {
627 SwingUtilities
.invokeLater(new Runnable() {
630 public final void run() {
631 final Node node
= selectedNodeVariable
.getValue();
632 final String text
= result
.getText();
634 debugPrint(node
, text
);
636 if (node
== null || node
.getNodeName().equals(text
)) {
643 node
.getNamespaceURI(),
644 node
.getNamespaceURI() == null ? text
: node
.getPrefix() + ":" + text
);
645 } catch (final Exception exception
) {
646 exception
.printStackTrace();
647 result
.setText(node
.getNodeName());
667 public static final JPanel
newNodeValuePanel(final Context context
) {
668 return newTitledPanel("Value", scrollable(newNodeValueTextArea(context
)));
679 public static final JTextArea
newNodeValueTextArea(final Context context
) {
680 final Variable
<Node
> selectedNodeVariable
= context
.getVariable(SELECTED_NODE
);
681 final JTextArea result
= new JTextArea();
683 final EventListener nodeListener
= new EventListener() {
686 public final void handleEvent(final Event event
) {
687 final Node node
= selectedNodeVariable
.getValue();
689 if (event
.getTarget() == node
) {
690 result
.setText(node
== null ?
"" : node
.getNodeValue());
696 selectedNodeVariable
.addListener(new Variable
.Listener
<Node
>() {
699 public final void valueChanged(final ValueChangedEvent
<Node
, ?
> event
) {
700 if (event
.getOldValue() != null) {
701 removeDOMEventListener(event
.getOldValue(), nodeListener
);
704 final Node node
= event
.getNewValue();
707 addDOMEventListener(node
, nodeListener
);
710 result
.setEditable(node
!= null && set(Node
.ATTRIBUTE_NODE
, Node
.CDATA_SECTION_NODE
, Node
.COMMENT_NODE
,
711 Node
.PROCESSING_INSTRUCTION_NODE
, Node
.TEXT_NODE
).contains(node
.getNodeType()));
713 result
.setText(node
== null ?
"" : node
.getNodeValue());
718 result
.getDocument().addDocumentListener(new AbstractDocumentHandler() {
721 protected final void eventReceived(final DocumentEvent event
) {
722 SwingUtilities
.invokeLater(new Runnable() {
725 public final void run() {
726 final Node node
= selectedNodeVariable
.getValue();
727 final String text
= result
.getText();
729 debugPrint(node
, text
);
731 if (node
.getNodeValue().equals(text
)) {
736 node
.setNodeValue(text
);
737 } catch (final Exception exception
) {
738 exception
.printStackTrace();
739 result
.setText(node
.getNodeName());
759 public static final JPanel
newXPathPanel(final Context context
) {
760 final JPanel result
= new JPanel(new BorderLayout());
762 result
.setBorder(BorderFactory
.createTitledBorder(
763 BorderFactory
.createEtchedBorder(),
768 result
.add(newTitledPanel("Context", newContextTextField(context
)), BorderLayout
.NORTH
);
769 result
.add(newXPathTabbedPane(context
), BorderLayout
.CENTER
);
782 public static final JTextField
newContextTextField(final Context context
) {
783 final Variable
<Node
> selectedNodeVariable
= context
.getVariable(SELECTED_NODE
);
784 final JTextField result
= new JTextField();
786 final EventListener nodeListener
= new EventListener() {
789 public final void handleEvent(final Event event
) {
790 final Node node
= selectedNodeVariable
.getValue();
792 if (event
.getTarget() == node
) {
793 result
.setText(node
== null ?
"" : getIdentifyingXPath(node
));
799 selectedNodeVariable
.addListener(new Variable
.Listener
<Node
>() {
802 public final void valueChanged(final ValueChangedEvent
<Node
, ?
> event
) {
803 if (event
.getOldValue() != null) {
804 removeDOMEventListener(event
.getOldValue(), nodeListener
);
807 final Node node
= event
.getNewValue();
810 addDOMEventListener(node
, nodeListener
);
813 result
.setText(node
== null ?
"" : getIdentifyingXPath(node
));
818 result
.setEditable(false);
831 public static final JTabbedPane
newXPathTabbedPane(final Context context
) {
832 final JTabbedPane result
= new JTabbedPane();
834 result
.add("List", newXPathListSplitPane(context
));
835 result
.add("Create", newQuasiXPathPanel(context
));
848 public static final JSplitPane
newXPathListSplitPane(final Context context
) {
849 return new JSplitPane(JSplitPane
.VERTICAL_SPLIT
,
850 newTitledPanel("XPath Expression", scrollable(newXPathExpressionTextArea(context
))),
851 newTitledPanel("Matches", scrollable(newXPathList(context
))));
862 public static final JTextArea
newXPathExpressionTextArea(final Context context
) {
863 final JTextArea result
= new JTextArea();
865 result
.getDocument().addDocumentListener(new AbstractDocumentHandler() {
868 protected final void eventReceived(final DocumentEvent event
) {
869 context
.set(XPATH_EXPRESSION
, result
.getText());
874 final Variable
<Exception
> xPathErrorVariable
= context
.getVariable(XPATH_ERROR
);
876 xPathErrorVariable
.addListener(new Variable
.Listener
<Exception
>() {
878 private Color defaultBackground
;
881 public final void valueChanged(final ValueChangedEvent
<Exception
, ?
> event
) {
882 if (this.defaultBackground
== null) {
883 this.defaultBackground
= result
.getBackground();
886 result
.setBackground(event
.getNewValue() == null ?
this.defaultBackground
: Color
.RED
);
902 public static final JList
newXPathList(final Context context
) {
903 final DefaultListModel model
= new DefaultListModel();
904 final JList result
= new JList(model
);
906 final Variable
<String
> xpathExpressionVariable
= context
.getVariable(XPATH_EXPRESSION
);
908 xpathExpressionVariable
.addListener(new Variable
.Listener
<String
>() {
911 public final void valueChanged(final ValueChangedEvent
<String
, ?
> event
) {
914 final Node contextNode
= context
.get(SELECTED_NODE
);
917 for (final Node node
: toList(getNodes(contextNode
, event
.getNewValue()))) {
918 model
.addElement(node
);
921 context
.set(XPATH_ERROR
, null);
922 } catch (final Exception exception
) {
923 context
.set(XPATH_ERROR
, exception
);
940 public static final JPanel
newQuasiXPathPanel(final Context context
) {
941 final JPanel result
= new JPanel(new BorderLayout());
943 result
.add(newTitledPanel("Quasi-XPath Expression", newQuasiXPathExpressionTextArea(context
)), BorderLayout
.CENTER
);
944 result
.add(newQuasiXPathCreateButton(context
), BorderLayout
.SOUTH
);
957 public static final JTextArea
newQuasiXPathExpressionTextArea(final Context context
) {
958 final JTextArea result
= new JTextArea();
960 result
.getDocument().addDocumentListener(new AbstractDocumentHandler() {
963 protected final void eventReceived(final DocumentEvent event
) {
964 context
.set(QUASI_XPATH_EXPRESSION
, result
.getText());
969 final Variable
<Exception
> quasiXPathErrorVariable
= context
.getVariable(QUASI_XPATH_ERROR
);
971 quasiXPathErrorVariable
.addListener(new Variable
.Listener
<Exception
>() {
973 private Color defaultBackground
;
976 public final void valueChanged(final ValueChangedEvent
<Exception
, ?
> event
) {
977 if (this.defaultBackground
== null) {
978 this.defaultBackground
= result
.getBackground();
981 result
.setBackground(event
.getNewValue() == null ?
this.defaultBackground
: Color
.RED
);
997 public static final JButton
newQuasiXPathCreateButton(final Context context
) {
998 final JButton result
= translate(new JButton("Create Node"));
1000 result
.addActionListener(new ActionListener() {
1002 private Color defaultBackground
;
1005 public final void actionPerformed(final ActionEvent event
) {
1006 if (this.defaultBackground
== null) {
1007 this.defaultBackground
= result
.getParent().getBackground();
1011 getOrCreateNode((Node
) context
.get(SELECTED_NODE
), (String
) context
.get(QUASI_XPATH_EXPRESSION
));
1013 context
.set(QUASI_XPATH_ERROR
, null);
1014 } catch (final Exception exception
) {
1015 context
.set(QUASI_XPATH_ERROR
, exception
);
1026 * @param translationKey
1035 public static final JPanel
newTitledPanel(final String translationKey
, final Component component
) {
1036 final JPanel result
= new JPanel(new BorderLayout());
1038 result
.setBorder(translate(BorderFactory
.createTitledBorder(translationKey
)));
1040 result
.add(component
);
1053 public static final String
toXMLString(final Node node
) {
1054 final ByteArrayOutputStream buffer
= new ByteArrayOutputStream();
1056 XMLTools
.write(node
, buffer
, 0);
1058 return buffer
.toString();
1069 public static final JTree
newDOMTreeView(final Context context
) {
1070 final Variable
<Node
> domVariable
= context
.getVariable(DOM
);
1071 final JTree result
= new JTree(new DOMTreeModel(domVariable
.getValue()));
1073 domVariable
.addListener(new Variable
.Listener
<Node
>() {
1076 public final void valueChanged(final ValueChangedEvent
<Node
, ?
> event
) {
1077 final DOMTreeModel treeModel
= new DOMTreeModel(event
.getNewValue());
1079 result
.setModel(treeModel
);
1081 context
.set(TREE_MODEL
, treeModel
);
1086 result
.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
1089 public final void valueChanged(final TreeSelectionEvent event
) {
1090 if (event
.getNewLeadSelectionPath() == null) {
1091 context
.set(SELECTED_NODE
, null);
1096 final DefaultMutableTreeNode selectedTreeNode
= (DefaultMutableTreeNode
) event
.getNewLeadSelectionPath().getLastPathComponent();
1098 if (selectedTreeNode
!= null) {
1099 context
.set(SELECTED_NODE
, (Node
) selectedTreeNode
.getUserObject());
1110 * @author codistmonk (creation 2010-07-04)
1112 public static final class DOMTreeModel
extends DefaultTreeModel
{
1120 public DOMTreeModel(final Node domNode
) {
1121 super(newTreeNode(domNode
));
1130 public final Node
getDOMNode() {
1131 return (Node
) ((DefaultMutableTreeNode
) this.getRoot()).getUserObject();
1134 private static final long serialVersionUID
= 4264388285566053331L;
1145 public static final DefaultMutableTreeNode
newTreeNode(final Node domNode
) {
1146 final DefaultMutableTreeNode result
= new DefaultMutableTreeNode(domNode
) {
1149 public final String
toString() {
1150 switch (domNode
.getNodeType()) {
1151 case Node
.ATTRIBUTE_NODE
:
1152 return domNode
.getNodeName() +
1153 (domNode
.getNodeValue() == null ?
"" : "=\"" + domNode
.getNodeValue() + "\"");
1155 return domNode
.getNodeName() +
1156 (domNode
.getNodeValue() == null ?
"" : "[" + domNode
.getNodeValue() + "]");
1160 private static final long serialVersionUID
= 8090552131823122052L;
1163 final NamedNodeMap attributes
= domNode
.getAttributes();
1165 if (attributes
!= null) {
1166 for (int i
= 0; i
< attributes
.getLength(); ++i
) {
1167 result
.add(newTreeNode(attributes
.item(i
)));
1171 if (domNode
.getNodeType() != Node
.ATTRIBUTE_NODE
) {
1172 for (final Node domChild
: XMLTools
.toList(domNode
.getChildNodes())) {
1173 result
.add(newTreeNode(domChild
));
1185 * @author codistmonk (ceration 2010-07-07)
1187 public static abstract class AbstractDocumentHandler
implements DocumentListener
{
1190 public final void insertUpdate(final DocumentEvent event
) {
1191 this.doInsertUpdate(event
);
1195 public final void removeUpdate(final DocumentEvent event
) {
1196 this.doRemoveUpdate(event
);
1200 public final void changedUpdate(final DocumentEvent event
) {
1201 this.doChangedUpdate(event
);
1209 protected void doInsertUpdate(final DocumentEvent event
) {
1210 this.eventReceived(event
);
1218 protected void doRemoveUpdate(final DocumentEvent event
) {
1219 this.eventReceived(event
);
1227 protected void doChangedUpdate(final DocumentEvent event
) {
1228 this.eventReceived(event
);
1236 protected abstract void eventReceived(DocumentEvent event
);