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 net
.sourceforge
.aprog
.i18n
.Messages
.setMessagesBase
;
28 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.APPLICATION_COPYRIGHT
;
29 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.APPLICATION_NAME
;
30 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.APPLICATION_VERSION
;
31 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.DOM
;
32 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.FILE
;
33 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.FILE_MODIFIED
;
34 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.QUASI_XPATH_ERROR
;
35 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.QUASI_XPATH_EXPRESSION
;
36 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.SELECTED_NODE
;
37 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.XPATH_ERROR
;
38 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.XPATH_EXPRESSION
;
39 import static net
.sourceforge
.aprog
.markups
.MarkupsConstants
.Variables
.XPATH_RESULT
;
40 import static net
.sourceforge
.aprog
.markups
.MarkupsTools
.addListener
;
41 import static net
.sourceforge
.aprog
.swing
.SwingTools
.canInvokeLaterThisMethodInAWT
;
42 import static net
.sourceforge
.aprog
.swing
.SwingTools
.useSystemLookAndFeel
;
43 import static net
.sourceforge
.aprog
.tools
.Tools
.getThisPackagePath
;
44 import net
.sourceforge
.aprog
.af
.MacOSXTools
;
45 import net
.sourceforge
.aprog
.context
.Context
;
46 import net
.sourceforge
.aprog
.events
.Variable
;
47 import net
.sourceforge
.aprog
.events
.Variable
.ValueChangedEvent
;
48 import net
.sourceforge
.aprog
.tools
.IllegalInstantiationException
;
49 import net
.sourceforge
.aprog
.xml
.XMLTools
;
51 import org
.w3c
.dom
.Node
;
52 import org
.w3c
.dom
.events
.Event
;
53 import org
.w3c
.dom
.events
.EventListener
;
57 * @author codistmonk (creation 2010-07-03)
59 public final class Markups
{
62 * @throws IllegalInstantiationException To prevent instantiation
65 throw new IllegalInstantiationException();
69 MacOSXTools
.setApplicationName(MarkupsConstants
.APPLICATION_NAME
);
70 useSystemLookAndFeel();
71 setMessagesBase(getThisPackagePath() + "Messages");
75 * @param arguments the command line arguments
77 public static final void main(final String
[] arguments
) {
78 if (canInvokeLaterThisMethodInAWT(null, (Object
) arguments
)) {
79 MarkupsComponents
.newMainFrame(newContext()).setVisible(true);
89 public static final Context
newContext() {
90 final Context result
= new Context();
92 result
.set(APPLICATION_NAME
, MarkupsConstants
.APPLICATION_NAME
);
93 result
.set(APPLICATION_VERSION
, MarkupsConstants
.APPLICATION_VERSION
);
94 result
.set(APPLICATION_COPYRIGHT
, MarkupsConstants
.APPLICATION_COPYRIGHT
);
95 result
.set(FILE
, null);
96 result
.set(FILE_MODIFIED
, false);
97 result
.set(DOM
, XMLTools
.newDocument());
98 result
.set(SELECTED_NODE
, null);
99 result
.set(XPATH_EXPRESSION
, null);
100 result
.set(XPATH_RESULT
, null);
101 result
.set(XPATH_ERROR
, null);
102 result
.set(QUASI_XPATH_EXPRESSION
, null);
103 result
.set(QUASI_XPATH_ERROR
, null);
105 final Variable
<String
> xPathExpressionVariable
= result
.getVariable(XPATH_EXPRESSION
);
107 xPathExpressionVariable
.addListener(new Variable
.Listener
<String
>() {
110 public final void valueChanged(final ValueChangedEvent
<String
, ?
> event
) {
111 MarkupsActions
.evaluateXPathExpression(result
);
116 final EventListener domListener
= new EventListener() {
119 public final void handleEvent(final Event event
) {
120 result
.set(FILE_MODIFIED
, true);
121 MarkupsActions
.evaluateXPathExpression(result
);
126 addListener(result
, DOM
, new AbstractDOMListenerReattacher(domListener
) {
129 protected final void afterReattachment(final ValueChangedEvent
<Node
, ?
> event
) {
130 MarkupsActions
.evaluateXPathExpression(result
);
135 addListener(result
, SELECTED_NODE
, new Variable
.Listener
<Node
>() {
138 public final void valueChanged(final ValueChangedEvent
<Node
, ?
> event
) {
139 MarkupsActions
.evaluateXPathExpression(result
);