Class NodePickerPanel

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, ActionMap

    public class NodePickerPanel
    extends javax.swing.JPanel
    implements ActionMap
    Used to preview and edit nodes.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int ADD_NEW_ELEMENT
      Creates new element while in this mode.
      private javax.swing.JButton addButton
      The Add button.
      private javax.swing.JButton applyButton
      The Apply button.
      private javax.swing.JScrollPane attributePane
      The Attributes table ScrollPane.
      private javax.swing.JLabel attributesLabel
      The Attributes table label.
      private javax.swing.JPanel attributesPanel
      The Attributes table and buttons Panel.
      private javax.swing.JTable attributesTable
      The attributes table - the table that consists of attribute name and attribute value columns.
      private static java.util.ResourceBundle bundle
      The resource bundle.
      private ButtonFactory buttonFactory
      The Button factory.
      private javax.swing.JPanel choosePanel
      The OK and Cancel button Panel.
      private org.w3c.dom.Element clonedElement
      The copy of the original (preview) element.
      private NodePickerController controller
      The controller for this panel.
      private static int EDIT_MODE
      Edit mode.
      private javax.swing.event.EventListenerList eventListeners
      Listeners list.
      private boolean isDirty
      If the element being edited is actually changed.
      private javax.swing.JLabel isWellFormedLabel
      The isWellFormed label.
      private java.util.Map listeners
      The map that contains the listeners
      private int mode
      The panel mode.
      private org.w3c.dom.Node parentElement
      The parent Element for the element to be added.
      private org.w3c.dom.Element previewElement
      The element that is being previewed or edited it's content (xml representation).
      private javax.swing.JButton removeButton
      The Remove button.
      private javax.swing.JButton resetButton
      The Reset button.
      private static ResourceManager resources
      The resource manager.
      private static java.lang.String RESOURCES
      The resource file name.
      private boolean shouldProcessUpdate
      If the attribute table listener should process the update event and update node picker after an update on the table had triggered.
      private NodePickerPanel.SVGInputPanel svgInputPanel
      The svg input panel.
      private javax.swing.JLabel svgInputPanelNameLabel
      The svgInputPanel name label.
      private javax.swing.event.TableModelListener tableModelListener
      The Attribute table model listener.
      private static int VIEW_MODE
      View only.
      • Fields inherited from class javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addButtonActions()
      Adds button actions.
      void addListener​(NodePickerPanel.NodePickerListener listener)
      Adds the listener to the listener list.
      void enterAddNewElementMode​(org.w3c.dom.Element newElement, org.w3c.dom.Node parent)
      Enters the add new element mode.
      void enterEditMode()
      Enters the edit mode.
      void enterViewMode()
      Enters the view mode.
      void fireAddNewElement​(NodePickerPanel.NodePickerEvent event)
      Fires the AddNewElement event.
      void fireUpdateElement​(NodePickerPanel.NodePickerEvent event)
      Fires the updateElement event.
      javax.swing.Action getAction​(java.lang.String key)
      Returns the action associated with the given string or null on error
      private javax.swing.JButton getAddButton()
      Gets the Add button.
      private javax.swing.JButton getApplyButton()
      Gets the Apply button.
      private javax.swing.JPanel getAttributesPanel()
      Gets the attributesPanel.
      private ButtonFactory getButtonFactory()
      Gets buttonFactory.
      private javax.swing.JPanel getChoosePanel()
      Gets the choosePanel.
      private int getMode()
      Gets the current working mode.
      private java.lang.String getNamespaceURI​(java.lang.String prefix)
      Looks up for the namespaceURI based on the given prefix.
      private org.w3c.dom.Element getPreviewElement()
      Getter for the preivewElement.
      private javax.swing.JButton getRemoveButton()
      Gets the Remove button.
      private javax.swing.JButton getResetButton()
      Gets the Reset sbutton.
      java.lang.String getResults()
      Gets the results of this node picker panel - gets the contents of the xml text area.
      private NodePickerPanel.SVGInputPanel getSvgInputPanel()
      Gets the svgInputPanel.
      private void initialize()
      Initalizes this panel.
      private boolean isANodePickerComponent​(java.awt.Component component)
      Checks whether the given component is a part component of the this node picker.
      private boolean isElementModified()
      Whether the element being edit is changed.
      (package private) boolean panelHiding()
      Invoked by the DOMViewer to inform the NodePickerPanel that it is being hidden.
      private org.w3c.dom.Element parseXml​(java.lang.String xmlString)
      Parses the given xml and return parsed document's root element.
      boolean promptForChanges()
      Shows a dialog to save changes.
      private void removeAttributes​(org.w3c.dom.Element element)
      Removes all the attributes from an element.
      void setEditable​(boolean editable)
      Sets the node picker components to be editable / uneditable.
      void setPreviewElement​(org.w3c.dom.Element elem)
      Sets the preview element.
      private boolean shouldUpdate​(java.lang.String mutationEventType, org.w3c.dom.Node affectedNode, org.w3c.dom.Node currentNode)
      If the panel should update its components after dom mutation event.
      private void updateAttributesTable​(org.w3c.dom.Element elem)
      Fills the attributesTable with the given element attribute name - value pairs.
      private void updateElementAttributes​(org.w3c.dom.Element element, NodePickerPanel.AttributesTableModel tableModel)
      Replaces all of the atributes of a given element with the values from the given table model.
      private void updateElementAttributes​(org.w3c.dom.Element elem, org.w3c.dom.Element referentElement)
      Replaces all of the attributes of the given element with the referent element's attributes.
      private void updateNodeXmlArea​(org.w3c.dom.Node node)
      Shows node's String representation in svgInputPanel
      void updateOnDocumentChange​(java.lang.String mutationEventType, org.w3c.dom.Node targetNode)
      Updates the panel when DOM Mutation event occures.
      private void updateViewAfterSvgInput​(org.w3c.dom.Element referentElement, org.w3c.dom.Element elementToUpdate)
      Update the components and the element after text is being inputted in the xml text area.
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • VIEW_MODE

        private static final int VIEW_MODE
        View only. Inspects the associated node.
        See Also:
        Constant Field Values
      • EDIT_MODE

        private static final int EDIT_MODE
        Edit mode. Used for editing the associated node.
        See Also:
        Constant Field Values
      • ADD_NEW_ELEMENT

        private static final int ADD_NEW_ELEMENT
        Creates new element while in this mode.
        See Also:
        Constant Field Values
      • RESOURCES

        private static final java.lang.String RESOURCES
        The resource file name.
        See Also:
        Constant Field Values
      • bundle

        private static java.util.ResourceBundle bundle
        The resource bundle.
      • resources

        private static ResourceManager resources
        The resource manager.
      • attributesTable

        private javax.swing.JTable attributesTable
        The attributes table - the table that consists of attribute name and attribute value columns. Shows the element's attributes.
      • tableModelListener

        private javax.swing.event.TableModelListener tableModelListener
        The Attribute table model listener.
      • attributePane

        private javax.swing.JScrollPane attributePane
        The Attributes table ScrollPane.
      • attributesPanel

        private javax.swing.JPanel attributesPanel
        The Attributes table and buttons Panel.
      • buttonFactory

        private ButtonFactory buttonFactory
        The Button factory.
      • addButton

        private javax.swing.JButton addButton
        The Add button.
      • removeButton

        private javax.swing.JButton removeButton
        The Remove button.
      • attributesLabel

        private javax.swing.JLabel attributesLabel
        The Attributes table label.
      • applyButton

        private javax.swing.JButton applyButton
        The Apply button.
      • resetButton

        private javax.swing.JButton resetButton
        The Reset button.
      • choosePanel

        private javax.swing.JPanel choosePanel
        The OK and Cancel button Panel.
      • isWellFormedLabel

        private javax.swing.JLabel isWellFormedLabel
        The isWellFormed label.
      • svgInputPanelNameLabel

        private javax.swing.JLabel svgInputPanelNameLabel
        The svgInputPanel name label.
      • shouldProcessUpdate

        private boolean shouldProcessUpdate
        If the attribute table listener should process the update event and update node picker after an update on the table had triggered. Used instead of removing and adding the table listener.
      • previewElement

        private org.w3c.dom.Element previewElement
        The element that is being previewed or edited it's content (xml representation).
      • clonedElement

        private org.w3c.dom.Element clonedElement
        The copy of the original (preview) element. Used to synchronize svginput area and the attributes table, since the original elements attributes shouldn't be changed while previewing or editing it.
      • parentElement

        private org.w3c.dom.Node parentElement
        The parent Element for the element to be added. It is used when adding the new element, to get the information on where to be appended.
      • mode

        private int mode
        The panel mode.
      • isDirty

        private boolean isDirty
        If the element being edited is actually changed.
      • eventListeners

        private javax.swing.event.EventListenerList eventListeners
        Listeners list.
      • listeners

        private java.util.Map listeners
        The map that contains the listeners
    • Constructor Detail

      • NodePickerPanel

        public NodePickerPanel​(NodePickerController controller)
        Constructor.
        Parameters:
        controller - The node picker panel controller
    • Method Detail

      • initialize

        private void initialize()
        Initalizes this panel.
      • getButtonFactory

        private ButtonFactory getButtonFactory()
        Gets buttonFactory.
      • addButtonActions

        private void addButtonActions()
        Adds button actions.
      • getAddButton

        private javax.swing.JButton getAddButton()
        Gets the Add button.
      • getRemoveButton

        private javax.swing.JButton getRemoveButton()
        Gets the Remove button.
      • getApplyButton

        private javax.swing.JButton getApplyButton()
        Gets the Apply button.
      • getResetButton

        private javax.swing.JButton getResetButton()
        Gets the Reset sbutton.
      • getAttributesPanel

        private javax.swing.JPanel getAttributesPanel()
        Gets the attributesPanel.
      • getChoosePanel

        private javax.swing.JPanel getChoosePanel()
        Gets the choosePanel.
      • getResults

        public java.lang.String getResults()
        Gets the results of this node picker panel - gets the contents of the xml text area.
      • updateViewAfterSvgInput

        private void updateViewAfterSvgInput​(org.w3c.dom.Element referentElement,
                                             org.w3c.dom.Element elementToUpdate)
        Update the components and the element after text is being inputted in the xml text area.
        Parameters:
        referentElement - The updated element, referent element
        elementToUpdate - The element to update.
      • updateElementAttributes

        private void updateElementAttributes​(org.w3c.dom.Element elem,
                                             org.w3c.dom.Element referentElement)
        Replaces all of the attributes of the given element with the referent element's attributes.
        Parameters:
        elem - The element whose attributes should be replaced
        referentElement - The referentElement to copy the attributes from
      • updateElementAttributes

        private void updateElementAttributes​(org.w3c.dom.Element element,
                                             NodePickerPanel.AttributesTableModel tableModel)
        Replaces all of the atributes of a given element with the values from the given table model.
        Parameters:
        element - The node whose attributes should update
        tableModel - The tableModel from which to get attributes
      • removeAttributes

        private void removeAttributes​(org.w3c.dom.Element element)
        Removes all the attributes from an element.
        Parameters:
        element - The given element
      • getNamespaceURI

        private java.lang.String getNamespaceURI​(java.lang.String prefix)
        Looks up for the namespaceURI based on the given prefix. Uses the Node.lookupNamespaceURI method, starting from the parent element of the element being edited / created.
        Parameters:
        prefix - The given prefix
        Returns:
        namespaceURI or null
      • updateAttributesTable

        private void updateAttributesTable​(org.w3c.dom.Element elem)
        Fills the attributesTable with the given element attribute name - value pairs.
        Parameters:
        elem - The given element
      • updateNodeXmlArea

        private void updateNodeXmlArea​(org.w3c.dom.Node node)
        Shows node's String representation in svgInputPanel
        Parameters:
        node - The given node
      • getPreviewElement

        private org.w3c.dom.Element getPreviewElement()
        Getter for the preivewElement.
        Returns:
        the preivewElement
      • setPreviewElement

        public void setPreviewElement​(org.w3c.dom.Element elem)
        Sets the preview element. Enters the view mode and updates the associated components.
        Parameters:
        elem - the element to set
      • panelHiding

        boolean panelHiding()
        Invoked by the DOMViewer to inform the NodePickerPanel that it is being hidden.
      • getMode

        private int getMode()
        Gets the current working mode.
        Returns:
        the mode
      • enterViewMode

        public void enterViewMode()
        Enters the view mode.
      • enterEditMode

        public void enterEditMode()
        Enters the edit mode.
      • enterAddNewElementMode

        public void enterAddNewElementMode​(org.w3c.dom.Element newElement,
                                           org.w3c.dom.Node parent)
        Enters the add new element mode.
        Parameters:
        newElement - The element to be added
        parent - The parent node of the element to be added
      • updateOnDocumentChange

        public void updateOnDocumentChange​(java.lang.String mutationEventType,
                                           org.w3c.dom.Node targetNode)
        Updates the panel when DOM Mutation event occures.
      • shouldUpdate

        private boolean shouldUpdate​(java.lang.String mutationEventType,
                                     org.w3c.dom.Node affectedNode,
                                     org.w3c.dom.Node currentNode)
        If the panel should update its components after dom mutation event. Checks whether any node that is the child node of the node currently being previewed has changed. If true, updates the xml text area of this NodePicker. In case of DOMAttrModiefied mutation event, the additional condition is added - to check whether the attributes of an element that is being previewed are changed. If true, the xml text area is refreshed.
        Returns:
        True if should update
      • parseXml

        private org.w3c.dom.Element parseXml​(java.lang.String xmlString)
        Parses the given xml and return parsed document's root element. Used to check whether the given xml is well formed.
        Parameters:
        xmlString - Xml as a String
        Returns:
        Element
      • setEditable

        public void setEditable​(boolean editable)
        Sets the node picker components to be editable / uneditable.
        Parameters:
        editable - Whether to enable or disable edit
      • isANodePickerComponent

        private boolean isANodePickerComponent​(java.awt.Component component)
        Checks whether the given component is a part component of the this node picker.
        Parameters:
        component - The given component
        Returns:
        True if the given component is a part of the this NodePicker
      • promptForChanges

        public boolean promptForChanges()
        Shows a dialog to save changes.
      • isElementModified

        private boolean isElementModified()
        Whether the element being edit is changed.
        Returns:
        True if the element being edit is changed
      • getAction

        public javax.swing.Action getAction​(java.lang.String key)
                                     throws MissingListenerException
        Returns the action associated with the given string or null on error
        Specified by:
        getAction in interface ActionMap
        Parameters:
        key - the key mapped with the action to get
        Throws:
        MissingListenerException - if the action is not found
      • fireUpdateElement

        public void fireUpdateElement​(NodePickerPanel.NodePickerEvent event)
        Fires the updateElement event.
        Parameters:
        event - The associated NodePickerEvent event
      • fireAddNewElement

        public void fireAddNewElement​(NodePickerPanel.NodePickerEvent event)
        Fires the AddNewElement event.
        Parameters:
        event - The associated NodePickerEvent event
      • addListener

        public void addListener​(NodePickerPanel.NodePickerListener listener)
        Adds the listener to the listener list.
        Parameters:
        listener - The listener to add