Example usage for org.jdom2 Element setAttribute

List of usage examples for org.jdom2 Element setAttribute

Introduction

In this page you can find the example usage for org.jdom2 Element setAttribute.

Prototype

public Element setAttribute(final String name, final String value) 

Source Link

Document

This sets an attribute value for this element.

Usage

From source file:de.danielluedecke.zettelkasten.database.AcceleratorKeys.java

License:Open Source License

/**
 * This methos inits the accelerator table of the new entry window's menus. We separate
 * the initialisation of the accelerator tables for each window to keep an better
 * overiew.//from  w w  w. j  av a2 s  . com
 */
private void initNewEntryKeys() {
    // this is our element variable which will be used below to set all the child elements
    Element acckey;

    // now we have to go through an endless list of accelerator keys. it is important
    // that the attribute values have exactly the same spelling like the actions' names
    // which can be found in the properties-files (resources). This ensures we can easily
    // assign accelerator keys to actions:
    //
    // javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(zettelkasten.ZettelkastenApp.class).getContext().getActionMap(ZettelkastenView.class, this);
    // AbstractAction ac = (AbstractAction) actionMap.get(CAcceleratorKey.getActionName());
    // KeyStroke ks = KeyStroke.getKeyStroke(CAcceleratorKey.getAccelerator());
    // ac.putValue(AbstractAction.ACCELERATOR_KEY, ks);        

    //
    // The actions of the new entry window's file menu
    //

    // the accelerator for the "closeWindow" action
    if (!findElement(NEWENTRYKEYS, "closeWindow")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "closeWindow");
        acckey.setText(mask + " W");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }
    // the accelerator for the "applyChanges" action
    if (!findElement(NEWENTRYKEYS, "applyChanges")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "applyChanges");
        acckey.setText(mask + " shift S");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }
    // the accelerator for the "retrieveKeywordsFromDisplayedEntry" action
    if (!findElement(NEWENTRYKEYS, "retrieveKeywordsFromDisplayedEntry")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "retrieveKeywordsFromDisplayedEntry");
        acckey.setText(mask + " alt G");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    //
    // The actions of the new entry window's edit menu
    //

    // the accelerator for the "selecteAllText" action
    if (!findElement(NEWENTRYKEYS, "selecteAllText")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "selecteAllText");
        acckey.setText(mask + " A");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addSegmentFromQuickList" action
    if (!findElement(NEWENTRYKEYS, "addSegmentFromQuickList")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addSegmentFromQuickList");
        acckey.setText(mask + " shift G");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addKeywordFromSelection" action
    if (!findElement(NEWENTRYKEYS, "addKeywordFromSelection")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addKeywordFromSelection");
        acckey.setText(mask + " shift K");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addTitleFromSelection" action
    if (!findElement(NEWENTRYKEYS, "addTitleFromSelection")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addTitleFromSelection");
        acckey.setText(mask + " alt U");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addTitleFromFirstLine" action
    if (!findElement(NEWENTRYKEYS, "addTitleFromFirstLine")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addTitleFromFirstLine");
        acckey.setText(mask + " shift U");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "undoAction" action
    if (!findElement(NEWENTRYKEYS, "undoAction")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "undoAction");
        acckey.setText(mask + " Z");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "redoAction" action
    if (!findElement(NEWENTRYKEYS, "redoAction")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "redoAction");
        acckey.setText(mask + " shift Z");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "replace" action
    if (!findElement(NEWENTRYKEYS, "replace")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "replace");
        acckey.setText(mask + " H");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    //
    // The actions of the new entry window's insert menu
    //

    // the accelerator for the "addAuthorFromMenu" action
    if (!findElement(NEWENTRYKEYS, "addAuthorFromMenu")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addAuthorFromMenu");
        acckey.setText(mask + " shift L");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "insertFootnote" action
    if (!findElement(NEWENTRYKEYS, "insertFootnote")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "insertFootnote");
        acckey.setText(mask + " shift N");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "insertImage" action
    if (!findElement(NEWENTRYKEYS, "insertImage")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "insertImage");
        acckey.setText(mask + " shift I");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "insertTable" action
    if (!findElement(NEWENTRYKEYS, "insertTable")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "insertTable");
        acckey.setText(mask + " shift T");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "insertHyperlink" action
    if (!findElement(NEWENTRYKEYS, "insertHyperlink")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "insertHyperlink");
        acckey.setText(mask + " K");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "insertManualLink" action
    if (!findElement(NEWENTRYKEYS, "insertManualLink")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "insertManualLink");
        acckey.setText(mask + " shift M");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "insertAttachment" action
    if (!findElement(NEWENTRYKEYS, "insertAttachment")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "insertAttachment");
        acckey.setText(mask + " shift A");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "insertSymbol" action
    if (!findElement(NEWENTRYKEYS, "insertSymbol")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "insertSymbol");
        acckey.setText(mask + " alt S");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "insertForm" action
    if (!findElement(NEWENTRYKEYS, "insertForm")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "insertForm");
        acckey.setText(mask + " shift F");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "insertManualTimestamp" action
    if (!findElement(NEWENTRYKEYS, "insertManualTimestamp")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "insertManualTimestamp");
        acckey.setText(mask + " F7");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    //
    // The actions of the new entry window's format menu
    //

    // the accelerator for the "formatBold" action
    if (!findElement(NEWENTRYKEYS, "formatBold")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatBold");
        acckey.setText(mask + " B");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatItalic" action
    if (!findElement(NEWENTRYKEYS, "formatItalic")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatItalic");
        acckey.setText(mask + " I");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatUnderline" action
    if (!findElement(NEWENTRYKEYS, "formatUnderline")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatUnderline");
        acckey.setText(mask + " U");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatStrikeThrough" action
    if (!findElement(NEWENTRYKEYS, "formatStrikeThrough")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatStrikeThrough");
        acckey.setText(mask + " D");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatSup" action
    if (!findElement(NEWENTRYKEYS, "formatSup")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatSup");
        acckey.setText(mask + " " + pluskey);
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatSub" action
    if (!findElement(NEWENTRYKEYS, "formatSub")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatSub");
        acckey.setText(ctrlkey + " " + numbersign);
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatHeading1" action
    if (!findElement(NEWENTRYKEYS, "formatHeading1")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatHeading1");
        acckey.setText(mask + " shift H");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatHeading2" action
    if (!findElement(NEWENTRYKEYS, "formatHeading2")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatHeading2");
        acckey.setText(mask + " alt H");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatCite" action
    if (!findElement(NEWENTRYKEYS, "formatCite")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatCite");
        acckey.setText(mask + " shift C");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatCode" action
    if (!findElement(NEWENTRYKEYS, "formatCode")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatCode");
        acckey.setText(mask + " alt C");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatFont" action
    if (!findElement(NEWENTRYKEYS, "formatFont")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatFont");
        acckey.setText(mask + " alt F");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatQuote" action
    if (!findElement(NEWENTRYKEYS, "formatQuote")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatQuote");
        acckey.setText(mask + " shift 2");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "alignCenter" action
    if (!findElement(NEWENTRYKEYS, "alignCenter")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "alignCenter");
        acckey.setText(mask + " E");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "alignLeft" action
    if (!findElement(NEWENTRYKEYS, "alignLeft")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "alignLeft");
        acckey.setText(mask + " L");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "alignRight" action
    if (!findElement(NEWENTRYKEYS, "alignRight")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "alignRight");
        acckey.setText(mask + " R");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "alignMargin" action
    if (!findElement(NEWENTRYKEYS, "alignMargin")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "alignMargin");
        acckey.setText(mask + " shift R");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatHighlight" action
    if (!findElement(NEWENTRYKEYS, "formatHighlight")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatHighlight");
        acckey.setText(mask + " M");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatList" action
    if (!findElement(NEWENTRYKEYS, "formatList")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatList");
        acckey.setText(mask + " alt L");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatList" action
    if (!findElement(NEWENTRYKEYS, "formatOrderedList")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatOrderedList");
        acckey.setText(mask + " alt N");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    // the accelerator for the "formatColor" action
    if (!findElement(NEWENTRYKEYS, "formatColor")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "formatColor");
        acckey.setText(mask + " T");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }

    //
    // The actions of the new entry window's window menu
    //

    // the accelerator for the "setFocusToEditPane" action
    if (!findElement(NEWENTRYKEYS, "setFocusToEditPane")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "setFocusToEditPane");
        acckey.setText(mask + " F2");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }
    // the accelerator for the "setFocusToKeywordList" action
    if (!findElement(NEWENTRYKEYS, "setFocusToKeywordList")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "setFocusToKeywordList");
        acckey.setText(mask + " F3");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }
    // the accelerator for the "setFocusToAuthorList" action
    if (!findElement(NEWENTRYKEYS, "setFocusToAuthorList")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "setFocusToAuthorList");
        acckey.setText(mask + " F4");
        acceleratorKeysNewEntry.getRootElement().addContent(acckey);
    }
}

From source file:de.danielluedecke.zettelkasten.database.AcceleratorKeys.java

License:Open Source License

/**
 * This methos inits the accelerator table of the desktop window's menus. We separate
 * the initialisation of the accelerator tables for each window to keep an better
 * overiew./*from  w  w w  .  j a  va  2  s.  com*/
 */
private void initDesktopKeys() {
    // this is our element variable which will be used below to set all the child elements
    Element acckey;

    // now we have to go through an endless list of accelerator keys. it is important
    // that the attribute values have exactly the same spelling like the actions' names
    // which can be found in the properties-files (resources). This ensures we can easily
    // assign accelerator keys to actions:
    //
    // javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(zettelkasten.ZettelkastenApp.class).getContext().getActionMap(ZettelkastenView.class, this);
    // AbstractAction ac = (AbstractAction) actionMap.get(CAcceleratorKey.getActionName());
    // KeyStroke ks = KeyStroke.getKeyStroke(CAcceleratorKey.getAccelerator());
    // ac.putValue(AbstractAction.ACCELERATOR_KEY, ks);        

    //
    // The actions of the desktop window's file menu
    //

    // the accelerator for the "newDesktop" action
    if (!findElement(DESKTOPKEYS, "newDesktop")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "newDesktop");
        acckey.setText(mask + " shift N");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addBullet" action
    if (!findElement(DESKTOPKEYS, "addBullet")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addBullet");
        acckey.setText(mask + " B");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addEntry" action
    if (!findElement(DESKTOPKEYS, "addEntry")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addEntry");
        acckey.setText(mask + " alt N");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addLuhmann" action
    if (!findElement(DESKTOPKEYS, "addLuhmann")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addLuhmann");
        acckey.setText(mask + " alt I");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "insertEntry" action
    if (!findElement(DESKTOPKEYS, "insertEntry")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "insertEntry");
        acckey.setText(mask + " N");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "exportDesktop" action
    if (!findElement(DESKTOPKEYS, "exportDesktop")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "exportDesktop");
        acckey.setText(mask + " shift E");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "exportMultipleDesktop" action
    if (!findElement(DESKTOPKEYS, "exportMultipleDesktop")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "exportMultipleDesktop");
        acckey.setText(mask + " shift X");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "printContent" action
    if (!findElement(DESKTOPKEYS, "printContent")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "printContent");
        acckey.setText(mask + " P");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "closeWindow" action
    if (!findElement(DESKTOPKEYS, "closeWindow")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "closeWindow");
        acckey.setText(mask + " W");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    //
    // The actions of the desktop window's edit menu
    //

    // the accelerator for the "cutNode" action
    if (!findElement(DESKTOPKEYS, "cutNode")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "cutNode");
        acckey.setText(mask + " X");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "copyNode" action
    if (!findElement(DESKTOPKEYS, "copyNode")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "copyNode");
        acckey.setText(mask + " C");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "pasteNode" action
    if (!findElement(DESKTOPKEYS, "pasteNode")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "pasteNode");
        acckey.setText(mask + " V");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "editEntry" action
    if (!findElement(DESKTOPKEYS, "editEntry")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "editEntry");
        acckey.setText(mask + " alt E");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "modifiyEntry" action
    if (!findElement(DESKTOPKEYS, "modifiyEntry")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "modifiyEntry");
        acckey.setText(mask + " E");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "applyModificationsToOriginalEntry" action
    if (!findElement(DESKTOPKEYS, "applyModificationsToOriginalEntry")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "applyModificationsToOriginalEntry");
        acckey.setText(mask + " shift P");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "applyAllModificationsToOriginalEntries" action
    if (!findElement(DESKTOPKEYS, "applyAllModificationsToOriginalEntries")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "applyAllModificationsToOriginalEntries");
        acckey.setText(mask + " alt P");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "moveNodeUp" action
    if (!findElement(DESKTOPKEYS, "moveNodeUp")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "moveNodeUp");
        acckey.setText(mask + " UP");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "moveNodeDown" action
    if (!findElement(DESKTOPKEYS, "moveNodeDown")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "moveNodeDown");
        acckey.setText(mask + " DOWN");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "renameBullet" action
    if (!findElement(DESKTOPKEYS, "renameBullet")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "renameBullet");
        acckey.setText(renamekey);
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "commentNode" action
    if (!findElement(DESKTOPKEYS, "commentNode")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "commentNode");
        acckey.setText(mask + " K");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "deleteNode" action
    if (!findElement(DESKTOPKEYS, "deleteNode")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "deleteNode");
        acckey.setText(delkey);
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    //
    // The actions of the desktop window's find menu
    //

    // the accelerator for the "findLive" action
    if (!findElement(DESKTOPKEYS, "findLive")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "findLive");
        acckey.setText(mask + " shift F");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "findLiveNext" action
    if (!findElement(DESKTOPKEYS, "findLiveNext")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "findLiveNext");
        acckey.setText(mask + " G");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    // the accelerator for the "findLivePrev" action
    if (!findElement(DESKTOPKEYS, "findLivePrev")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "findLivePrev");
        acckey.setText(mask + " shift G");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }

    //
    // The actions of the desktop window's view menu
    //

    // the accelerator for the "updateView" action
    if (!findElement(DESKTOPKEYS, "updateView")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "updateView");
        acckey.setText("F5");
        acceleratorKeysDesktop.getRootElement().addContent(acckey);
    }
}

From source file:de.danielluedecke.zettelkasten.database.AcceleratorKeys.java

License:Open Source License

/**
 * This methos inits the accelerator table of the desktop window's menus. We separate
 * the initialisation of the accelerator tables for each window to keep an better
 * overiew.//from  w ww. j a  v  a 2 s . c o  m
 */
private void initSearchResultsKeys() {
    // this is our element variable which will be used below to set all the child elements
    Element acckey;

    // now we have to go through an endless list of accelerator keys. it is important
    // that the attribute values have exactly the same spelling like the actions' names
    // which can be found in the properties-files (resources). This ensures we can easily
    // assign accelerator keys to actions:
    //
    // javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(zettelkasten.ZettelkastenApp.class).getContext().getActionMap(ZettelkastenView.class, this);
    // AbstractAction ac = (AbstractAction) actionMap.get(CAcceleratorKey.getActionName());
    // KeyStroke ks = KeyStroke.getKeyStroke(CAcceleratorKey.getAccelerator());
    // ac.putValue(AbstractAction.ACCELERATOR_KEY, ks);        

    //
    // The actions of the search results window's edit menu
    //

    // the accelerator for the "removeSearchResult" action
    if (!findElement(SEARCHRESULTSKEYS, "removeSearchResult")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "removeSearchResult");
        acckey.setText(mask + " shift " + delkey);
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "removeAllSearchResults" action
    if (!findElement(SEARCHRESULTSKEYS, "removeAllSearchResults")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "removeAllSearchResults");
        acckey.setText(mask + " alt shift " + delkey);
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "exportEntries" action
    if (!findElement(SEARCHRESULTSKEYS, "exportEntries")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "exportEntries");
        acckey.setText(mask + " shift E");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "closeWindow" action
    if (!findElement(SEARCHRESULTSKEYS, "closeWindow")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "closeWindow");
        acckey.setText(mask + " W");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    //
    // The actions of the search results window's edit menu
    //

    // the accelerator for the "selectAll" action
    if (!findElement(SEARCHRESULTSKEYS, "selectAll")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "selectAll");
        acckey.setText(mask + " A");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "editEntry" action
    if (!findElement(SEARCHRESULTSKEYS, "editEntry")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "editEntry");
        acckey.setText(mask + " E");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "findAndReplace" action
    if (!findElement(SEARCHRESULTSKEYS, "findAndReplace")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "findAndReplace");
        acckey.setText(mask + " R");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "removeEntry" action
    if (!findElement(SEARCHRESULTSKEYS, "removeEntry")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "removeEntry");
        acckey.setText(delkey);
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addToManLinks" action
    if (!findElement(SEARCHRESULTSKEYS, "addToManLinks")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addToManLinks");
        acckey.setText(mask + " alt L");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addToLuhmann" action
    if (!findElement(SEARCHRESULTSKEYS, "addToLuhmann")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addToLuhmann");
        acckey.setText(mask + " alt I");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addToBookmarks" action
    if (!findElement(SEARCHRESULTSKEYS, "addToBookmarks")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addToBookmarks");
        acckey.setText(mask + " B");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "addToDesktop" action
    if (!findElement(SEARCHRESULTSKEYS, "addToDesktop")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "addToDesktop");
        acckey.setText("F9");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "showEntryInDesktop" action
    if (!findElement(SEARCHRESULTSKEYS, "showEntryInDesktop")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "showEntryInDesktop");
        acckey.setText(mask + " F9");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "toggleHighlightResults" action
    if (!findElement(SEARCHRESULTSKEYS, "toggleHighlightResults")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "toggleHighlightResults");
        acckey.setText("F7");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }

    // the accelerator for the "switchLayout" action
    if (!findElement(SEARCHRESULTSKEYS, "switchLayout")) {
        acckey = new Element("key");
        acckey.setAttribute("action", "switchLayout");
        acckey.setText(mask + " F7");
        acceleratorKeysSearchResults.getRootElement().addContent(acckey);
    }
}

From source file:de.danielluedecke.zettelkasten.database.AutoKorrektur.java

License:Open Source License

/**
 * Adds a new pair of false/correct words to the document
 * //from  www .  ja  v a 2  s .c  o  m
 * @param falsch the wrong or mispelled word
 * @param richtig the correct writing
 * @return {@code true} if element was successfully addes, {@code false} if "falsch" already existed or
 * one of the parameters were invalid
 */
public boolean addElement(String falsch, String richtig) {
    // check for minimum length
    if (null == falsch || falsch.length() < 2 || null == richtig || richtig.length() < 2) {
        return false;
    }
    // check for existence
    if (exists(falsch)) {
        return false;
    }
    // if it doesn't already exist, create new element
    Element e = new Element(Daten.ELEMENT_ENTRY);
    try {
        // set id-attribute
        e.setAttribute("id", falsch);
        // set content
        e.setText(richtig);
        // and add it to the document
        autokorrektur.getRootElement().addContent(e);
    } catch (IllegalAddException ex) {
        Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
        return false;
    } catch (IllegalDataException ex) {
        Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
        return false;
    }
    // return success
    return true;
}

From source file:de.danielluedecke.zettelkasten.database.Bookmarks.java

License:Open Source License

/**
 * This method deletes a category from the data file. The category that should be deleted
 * is indicated by the category's index-number, passed as parameter "nr". If the index-number
 * is not known, use {@link #deleteCategory(java.lang.String) deleteCategory(String cat)} to delete that 
 * category or {@link #getCategoryPosition getCategoryPosition(int nr)} to retrieve that number.
 * <br><br>/*from   ww  w  . jav a 2  s  . com*/
 * <b>Attention!</b> All related bookmarks that are assigned to this category are deleted as well!
 * 
 * @param nr the index-number of the to be deleted category.
 */
public void deleteCategory(int nr) {
    // get cat-element
    Element category = bookmarks.getRootElement().getChild("category");
    // delete category from the xml-file
    if (category != null && category.removeContent(nr) != null) {
        // if we have successfully deleted a category, delete all bookmarks from
        // that category as well
        for (int cnt = getCount() - 1; cnt >= 0; cnt--) {
            // get each bookmark
            Element bm = retrieveBookmarkElement(cnt);
            try {
                // get category-atribute
                String cat = bm.getAttributeValue("cat");
                // check whether attribute exists
                if (cat != null) {
                    // get cat id
                    int catid = Integer.parseInt(cat);
                    // if catid equals the deleted category, delete bookmark
                    if (catid == nr) {
                        // get bookmark-element
                        Element child = bookmarks.getRootElement().getChild("bookmark");
                        // if it exists, remove it
                        if (child != null) {
                            child.removeContent(cnt);
                        }
                    }
                    // in case the category-id was greater than the deleted category index-number,
                    // we have to update the category-index-number of the non-deleted bookmark
                    else if (catid > nr) {
                        bm.setAttribute("cat", String.valueOf(catid - 1));
                    }
                }
            } catch (NumberFormatException e) {
                Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage());
            } catch (IllegalNameException e) {
                Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage());
            } catch (IllegalDataException e) {
                Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage());
            }
            // change modified state
            setModified(true);
        }
    }
}

From source file:de.danielluedecke.zettelkasten.database.Bookmarks.java

License:Open Source License

/**
 * Adds a new bookmark to the bookmark-file. First, we have to check whether
 * the bookmark already exists. If not, add it. Then we have to check for the
 * category. If it already exists, retrieve the category's index-number. Else
 * add a new category./*from  w  w w .j a va 2s . c  om*/
 * <br><br>
 * Use "getCompleteBookmark" for retrieving a bookmark's entry-number, category
 * and comment.
 * 
 * @param index the index-number of the bookmark, i.e. the entry's number
 * @param cat the category, under which the bookmark should appear.
 * @param comment an optional comment for the bookmark
 */
public void addBookmark(int index, String cat, String comment) {
    // first check whether this index-number was already bookmarked...
    // if not, a -1 is return, else the index-number
    // if the bookmark already exists, do nothing
    if (-1 == getBookmarkPosition(index)) {
        try {
            // retrieve the position of the category
            int catpos = getCategoryPosition(cat);
            // check whether the category exists
            if (-1 == catpos) {
                // if the category doesn't already exist, add it
                catpos = addCategory(cat);
            }
            // create new bookmark-element
            Element bm = new Element(Daten.ELEMENT_ENTRY);
            // set the id, i.e. the number of the entry which is bookmarked
            bm.setAttribute("id", String.valueOf(index));
            // set the category-index for this bookmark
            bm.setAttribute("cat", String.valueOf(catpos));
            // and add the comment
            if (null == comment) {
                comment = "";
            }
            bm.setText(comment);
            // retrieve the bookmark-"root"-element
            Element bookbase = bookmarks.getRootElement().getChild("bookmark");
            // and add the bookmark-element
            bookbase.addContent(bm);
            // change modified-state
            setModified(true);
        } catch (IllegalAddException ex) {
            Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
        } catch (IllegalNameException ex) {
            Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
        } catch (IllegalDataException ex) {
            Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
        }
    }
}

From source file:de.danielluedecke.zettelkasten.database.Bookmarks.java

License:Open Source License

/**
 * Changes an existing bookmark in the bookmark-file. First, we have to check whether
 * the bookmark already exists. If not, leave method. Then we have to check for the
 * category. If it already exists, retrieve the category's index-number. Else
 * add a new category.//from w w  w  . j  a va  2 s  .  c o  m
 * 
 * @param index the index-number of the bookmark, i.e. the entry's number
 * @param cat the category, under which the bookmark should appear.
 * @param comment an optional comment for the bookmark
 */
public void changeBookmark(int index, String cat, String comment) {
    // get the bookmark position
    int pos = getBookmarkPosition(index);
    // check whether it exists and go on...
    if (pos != -1) {
        // retrieve the position of the category
        int catpos = getCategoryPosition(cat);
        // check whether the category exists
        if (-1 == catpos) {
            // if the category doesn't already exist, add it
            catpos = addCategory(cat);
        }
        try {
            // get bookmark-element
            Element bm = retrieveBookmarkElement(pos);
            // set the id, i.e. the number of the entry which is bookmarked
            bm.setAttribute("id", String.valueOf(index));
            // set the category-index for this bookmark
            bm.setAttribute("cat", String.valueOf(catpos));
            // and add the comment
            bm.setText(comment);
            // change modified-state
            setModified(true);
        } catch (IllegalNameException ex) {
            Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
        } catch (IllegalDataException ex) {
            Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
        }
    }
}

From source file:de.danielluedecke.zettelkasten.database.Bookmarks.java

License:Open Source License

/**
 * This method changes the category-id (category-number) of a given bookmark {@code nr}.
 * //  w w w. j  av  a 2  s .c o m
 * @param nr the bookmark-index-number as it appears in the database (<b>not</b> the entry-number of the bookmark)
 * @param newindex the new index-number of the bookmark's category-id
 */
public void setBookmarkCategory(int nr, int newindex) {
    // check for valid value
    if (nr >= 1 && nr < getCount()) {
        // retrieve the bookmark-element
        Element bm = retrieveBookmarkElement(nr);
        // if we have a valid element, change the category-attribute
        if (bm != null) {
            bm.setAttribute("cat", String.valueOf(newindex));
            setModified(true);
        }
    }
}

From source file:de.danielluedecke.zettelkasten.database.Daten.java

License:Open Source License

/**
 * Initiates the global variables and creates empty JDom objects
 * <br><br>/*www  . j  ava 2  s.co m*/
 * <b>Warning!</b> This method does <i>not</i> clear the filePath-variable, so
 * be sure you have set the filePath to null manually, if necessary.
 */
public final void initZettelkasten() {
    // reset all global variables
    modified = false;
    zknframe.resetBackupNecessary();
    zknFile = null;
    authorFile = null;
    keywordFile = null;
    metainfFile = null;
    zknFileExport = null;
    // init the history array
    history = new int[HISTORY_MAX];
    // current position in the history array refers to the first element
    historyPosition = 0;
    // indicates that we have one (initial) element
    historyCount = 1;
    // the one and only element is the first entry
    history[0] = 1;
    // no update to the tabbed panes in the main window when nothing is loaded
    keywordlistUpToDate = true;
    authorlistUpToDate = true;
    titlelistUpToDate = true;
    clusterlistUpToDate = true;
    attachmentlistUpToDate = true;
    // create "empty" XML JDom objects
    zknFile = new Document(new Element(DOCUMENT_ZETTELKASTEN));
    authorFile = new Document(new Element(DOCUMENT_AUTHORS));
    keywordFile = new Document(new Element(DOCUMENT_KEYWORDS));
    // prepare the metainformation-file
    metainfFile = new Document(new Element("metainformation"));
    // first create an attribute for the fileversion-number
    Element fileversion = new Element(ELEMENT_VERSION_INFO);
    fileversion.setAttribute("id", currentVersion);
    // and add it to the document
    metainfFile.getRootElement().addContent(fileversion);
    // than create an empty description and add it
    Element desc = new Element(ELEMEMT_DESCRIPTION);
    metainfFile.getRootElement().addContent(desc);
    // than create an empty atachment-path and add it
    Element attpath = new Element(ELEMENT_ATTACHMENT_PATH);
    metainfFile.getRootElement().addContent(attpath);
    // than create an empty atachment-path and add it
    Element imgpath = new Element(ELEMENT_IMAGE_PATH);
    metainfFile.getRootElement().addContent(imgpath);
    // init zettel-position-index
    zettelPos = 1;
    // reset references to first and last entry
    setFirstZettel(-1);
    setLastZettel(-1);
    // here we add all files which are stored in the zipped data-file in a list-array
    filesToLoad.clear();
    filesToLoad.add(Constants.metainfFileName);
    filesToLoad.add(Constants.zknFileName);
    filesToLoad.add(Constants.authorFileName);
    filesToLoad.add(Constants.keywordFileName);
    filesToLoad.add(Constants.bookmarksFileName);
    filesToLoad.add(Constants.searchrequestsFileName);
    filesToLoad.add(Constants.desktopFileName);
    filesToLoad.add(Constants.desktopModifiedEntriesFileName);
    filesToLoad.add(Constants.desktopNotesFileName);
    filesToLoad.add(Constants.synonymsFileName);
    filesToLoad.add(Constants.bibTexFileName);
    // reset list
    allLuhmannNumbers.clear();
}

From source file:de.danielluedecke.zettelkasten.database.Daten.java

License:Open Source License

/**
 * This method changes the frequencies of an entry's authors and keywords by the given value {@code addvalue}.
 * @param nr the entrynumber, which author- and keywords-frequencies should be changed
 * @param addvalue the amount of increase or decrease of each author/keyword-frequency
 *///ww w  .jav  a  2 s  . c  o  m
private void changeFrequencies(int nr, int addvalue) {
    // first of all, we duplicate all authors and keywords frequencies from the existing entry.
    // therefore, we first retrieve all author-index-numbers from that entry
    int[] aus = getAuthorIndexNumbers(nr);
    // check whether we have any values at all
    if (aus != null && aus.length > 0) {
        // iterate the array
        for (int a : aus) {
            // check for valid value
            if (a != -1) {
                try {
                    // retrieve existing author
                    Element au = retrieveElement(authorFile, a);
                    // chek for valid value
                    if (au != null) {
                        // get the count-value, which indicates the frequency of occurences of this
                        // author in the whole data file
                        String freq = au.getAttributeValue(ATTRIBUTE_FREQUENCIES);
                        if (freq != null) {
                            int f = Integer.parseInt(freq);
                            // increase frequency by 1
                            au.setAttribute(ATTRIBUTE_FREQUENCIES, String.valueOf(f + addvalue));
                        }
                    }
                } catch (NumberFormatException ex) {
                    Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
                } catch (IllegalNameException ex) {
                    Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
                } catch (IllegalDataException ex) {
                    Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
                }
            }
        }
    }
    // now do this for the keywords. retrieve all keyword -index-numbers from that entry
    int[] kws = getKeywordIndexNumbers(nr);
    // check whether we have any values at all
    if (kws != null && kws.length > 0) {
        // iterate the array
        for (int k : kws) {
            // check for valid value
            if (k != -1) {
                try {
                    // retrieve existing author
                    Element kw = retrieveElement(keywordFile, k);
                    // chek for valid value
                    if (kw != null) {
                        // get the count-value, which indicates the frequency of occurences of this
                        // keyword in the whole data file
                        String freq = kw.getAttributeValue(ATTRIBUTE_FREQUENCIES);
                        if (freq != null) {
                            int f = Integer.parseInt(freq);
                            // increase frequency by 1
                            kw.setAttribute(ATTRIBUTE_FREQUENCIES, String.valueOf(f + addvalue));
                        }
                    }
                } catch (NumberFormatException ex) {
                    Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
                } catch (IllegalNameException ex) {
                    Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
                } catch (IllegalDataException ex) {
                    Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
                }
            }
        }
    }
}