Class NodePickerPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, ActionMap

public class NodePickerPanel extends JPanel implements ActionMap
Used to preview and edit nodes.
See Also:
  • Field Details

    • VIEW_MODE

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

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

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

      private static final String RESOURCES
      The resource file name.
      See Also:
    • bundle

      private static ResourceBundle bundle
      The resource bundle.
    • resources

      private static ResourceManager resources
      The resource manager.
    • attributesTable

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

      private TableModelListener tableModelListener
      The Attribute table model listener.
    • attributePane

      private JScrollPane attributePane
      The Attributes table ScrollPane.
    • attributesPanel

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

      private ButtonFactory buttonFactory
      The Button factory.
    • addButton

      private JButton addButton
      The Add button.
    • removeButton

      private JButton removeButton
      The Remove button.
    • attributesLabel

      private JLabel attributesLabel
      The Attributes table label.
    • applyButton

      private JButton applyButton
      The Apply button.
    • resetButton

      private JButton resetButton
      The Reset button.
    • choosePanel

      private JPanel choosePanel
      The OK and Cancel button Panel.
    • svgInputPanel

      private NodePickerPanel.SVGInputPanel svgInputPanel
      The svg input panel.
    • isWellFormedLabel

      private JLabel isWellFormedLabel
      The isWellFormed label.
    • svgInputPanelNameLabel

      private 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 Element previewElement
      The element that is being previewed or edited it's content (xml representation).
    • clonedElement

      private 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 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 EventListenerList eventListeners
      Listeners list.
    • controller

      private NodePickerController controller
      The controller for this panel.
    • listeners

      private Map listeners
      The map that contains the listeners
  • Constructor Details

    • NodePickerPanel

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

    • initialize

      private void initialize()
      Initalizes this panel.
    • getButtonFactory

      private ButtonFactory getButtonFactory()
      Gets buttonFactory.
    • addButtonActions

      private void addButtonActions()
      Adds button actions.
    • getAddButton

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

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

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

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

      private JPanel getAttributesPanel()
      Gets the attributesPanel.
    • getSvgInputPanel

      private NodePickerPanel.SVGInputPanel getSvgInputPanel()
      Gets the svgInputPanel.
    • getChoosePanel

      private JPanel getChoosePanel()
      Gets the choosePanel.
    • getResults

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

      private void updateViewAfterSvgInput(Element referentElement, 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(Element elem, 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(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(Element element)
      Removes all the attributes from an element.
      Parameters:
      element - The given element
    • getNamespaceURI

      private String getNamespaceURI(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(Element elem)
      Fills the attributesTable with the given element attribute name - value pairs.
      Parameters:
      elem - The given element
    • updateNodeXmlArea

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

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

      public void setPreviewElement(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(Element newElement, 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(String mutationEventType, Node targetNode)
      Updates the panel when DOM Mutation event occures.
    • shouldUpdate

      private boolean shouldUpdate(String mutationEventType, Node affectedNode, 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 Element parseXml(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(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 Action getAction(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