Example usage for java.lang Thread setDaemon

List of usage examples for java.lang Thread setDaemon

Introduction

In this page you can find the example usage for java.lang Thread setDaemon.

Prototype

public final void setDaemon(boolean on) 

Source Link

Document

Marks this thread as either a #isDaemon daemon thread or a user thread.

Usage

From source file:edu.brown.hstore.HStoreSite.java

/**
 * Start the MapReduceHelper Thread/*  w ww.  j a va2s . c  o m*/
 */
private void startMapReduceHelper() {
    synchronized (this.mr_helper) {
        if (this.mr_helper_started)
            return;
        if (debug.val)
            LOG.debug("Starting " + this.mr_helper.getClass().getSimpleName());

        Thread t = new Thread(this.mr_helper);
        t.setDaemon(true);
        t.setUncaughtExceptionHandler(this.exceptionHandler);
        t.start();
        this.mr_helper_started = true;
    } // SYNCH
}

From source file:API.amazon.mws.feeds.service.MarketplaceWebServiceClient.java

/**
 * Constructs MarketplaceWebServiceClient with AWS Access Key ID, AWS Secret Key
 * and MarketplaceWebServiceConfig. Use MarketplaceWebServiceConfig to pass additional
 * configuration that affects how service is being called.
 *
 * @param awsAccessKeyId/*  w  w  w. j a  va2s.c  o  m*/
 *          AWS Access Key ID
 * @param awsSecretAccessKey
 *          AWS Secret Access Key
 * @param config
 *          Additional configuration options
 */
@SuppressWarnings("serial")
public MarketplaceWebServiceClient(String awsAccessKeyId, String awsSecretAccessKey, String applicationName,
        String applicationVersion, MarketplaceWebServiceConfig config) {
    this.awsAccessKeyId = awsAccessKeyId;
    this.awsSecretAccessKey = awsSecretAccessKey;
    this.config = config;
    this.httpClient = configureHttpClient(applicationName, applicationVersion);
    this.asyncExecutor = new ThreadPoolExecutor(config.getMaxAsyncThreads(), config.getMaxAsyncThreads(), 60L,
            TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(config.getMaxAsyncQueueSize()) {

                @Override
                public boolean offer(Runnable task) {
                    log.debug("Maximum number of concurrent threads reached, queuing task...");
                    return super.offer(task);
                }
            }, new ThreadFactory() {

                private final AtomicInteger threadNumber = new AtomicInteger(1);

                public Thread newThread(Runnable task) {
                    Thread thread = new Thread(task,
                            "MarketplaceWebServiceClient-Thread-" + threadNumber.getAndIncrement());
                    thread.setDaemon(true);
                    if (thread.getPriority() != Thread.NORM_PRIORITY) {
                        thread.setPriority(Thread.NORM_PRIORITY);
                    }
                    log.debug("ThreadFactory created new thread: " + thread.getName());
                    return thread;
                }
            }, new RejectedExecutionHandler() {

                public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) {
                    log.debug("Maximum number of concurrent threads reached, and queue is full. "
                            + "Running task in the calling thread..." + Thread.currentThread().getName());
                    if (!executor.isShutdown()) {
                        task.run();
                    }
                }
            });
}

From source file:edu.brown.hstore.HStoreSite.java

/**
 * Initializes all the pieces that we need to start this HStore site up
 * This should only be called by our run() method
 *//* w  w  w  . j a va2  s  .c  om*/
protected HStoreSite init() {
    if (debug.val)
        LOG.debug("Initializing HStoreSite " + this.getSiteName());
    this.hstore_coordinator = this.initHStoreCoordinator();

    // First we need to tell the HStoreCoordinator to start-up and initialize its connections
    if (debug.val)
        LOG.debug("Starting HStoreCoordinator for " + this.getSiteName());
    this.hstore_coordinator.start();

    ThreadGroup auxGroup = this.threadManager.getThreadGroup(ThreadGroupType.AUXILIARY);

    // Start TransactionQueueManager
    Thread t = new Thread(auxGroup, this.txnQueueManager);
    t.setDaemon(true);
    t.setUncaughtExceptionHandler(this.exceptionHandler);
    t.start();

    // Start VoltNetwork
    t = new Thread(this.voltNetwork);
    t.setName(HStoreThreadManager.getThreadName(this, HStoreConstants.THREAD_NAME_VOLTNETWORK));
    t.setDaemon(true);
    t.setUncaughtExceptionHandler(this.exceptionHandler);
    t.start();

    // Start CommandLogWriter
    t = new Thread(auxGroup, this.commandLogger);
    t.setDaemon(true);
    t.setUncaughtExceptionHandler(this.exceptionHandler);
    t.start();

    // Start AntiCacheManager Queue Processor
    if (this.anticacheManager != null && this.anticacheManager.getEvictableTables().isEmpty() == false) {
        t = new Thread(auxGroup, this.anticacheManager);
        t.setDaemon(true);
        t.setUncaughtExceptionHandler(this.exceptionHandler);
        t.start();
    }

    // TransactionPreProcessors
    if (this.preProcessors != null) {
        for (TransactionPreProcessor tpp : this.preProcessors) {
            t = new Thread(this.threadManager.getThreadGroup(ThreadGroupType.PROCESSING), tpp);
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(this.exceptionHandler);
            t.start();
        } // FOR
    }
    // TransactionPostProcessors
    if (this.postProcessors != null) {
        for (TransactionPostProcessor tpp : this.postProcessors) {
            t = new Thread(this.threadManager.getThreadGroup(ThreadGroupType.PROCESSING), tpp);
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(this.exceptionHandler);
            t.start();
        } // FOR
    }

    // Then we need to start all of the PartitionExecutor in threads
    if (debug.val)
        LOG.debug(String.format("Starting PartitionExecutor threads for %s partitions on %s",
                this.local_partitions.size(), this.getSiteName()));
    for (int partition : this.local_partitions.values()) {
        PartitionExecutor executor = this.getPartitionExecutor(partition);
        // executor.initHStoreSite(this);

        t = new Thread(this.threadManager.getThreadGroup(ThreadGroupType.EXECUTION), executor);
        t.setDaemon(true);
        t.setPriority(Thread.MAX_PRIORITY); // Probably does nothing...
        t.setUncaughtExceptionHandler(this.exceptionHandler);
        this.executor_threads[partition] = t;
        t.start();
    } // FOR

    // Start Transaction Cleaners
    int i = 0;
    for (TransactionCleaner cleaner : this.txnCleaners) {
        String name = String.format("%s-%02d",
                HStoreThreadManager.getThreadName(this, HStoreConstants.THREAD_NAME_TXNCLEANER), i);
        t = new Thread(this.threadManager.getThreadGroup(ThreadGroupType.CLEANER), cleaner);
        t.setName(name);
        t.setDaemon(true);
        t.setUncaughtExceptionHandler(this.exceptionHandler);
        t.start();
        i += 1;
    } // FOR

    this.initPeriodicWorks();

    // Transaction Profile CSV Dumper
    if (hstore_conf.site.txn_profiling && hstore_conf.site.txn_profiling_dump) {
        File csvFile = new File(hstore_conf.global.log_dir + File.separator + this.getSiteName().toLowerCase()
                + "-profiler.csv");
        this.txn_profiler_dumper = new TransactionProfilerDumper(csvFile);
        LOG.info(String.format("Transaction profile data will be written to '%s'", csvFile));
    }

    // Add in our shutdown hook
    // Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook()));

    return (this);
}

From source file:com.frostwire.gui.bittorrent.YouTubeVideoUrlDownload.java

private void start() {
    Thread t = new Thread(new Runnable() {

        @Override/*from w ww  .  j  ava 2 s  .c om*/
        public void run() {
            try {
                LinkCollector collector = LinkCollector.getInstance();
                LinkCrawler crawler = new LinkCrawler();
                crawler.setFilter(LinkFilterController.getInstance());
                crawler.crawl(videoUrl);
                crawler.waitForCrawling();

                if (_state.equals(STATE_STOPPED)) {
                    return;
                }

                _state = STATE_FINISHED;
                progress = 100;

                final List<FilePackage> packages = new ArrayList<FilePackage>();

                for (CrawledLink link : crawler.getCrawledLinks()) {
                    CrawledPackage parent = PackageInfo.createCrawledPackage(link);
                    parent.setControlledBy(collector);
                    link.setParentNode(parent);
                    ArrayList<CrawledLink> links = new ArrayList<CrawledLink>();
                    links.add(link);
                    packages.add(createFilePackage(parent, links));
                }

                /*
                for (CrawledPackage pkg : new ArrayList<CrawledPackage>(collector.getPackages())) {
                for (CrawledLink link : new ArrayList<CrawledLink>(pkg.getChildren())) {
                    ArrayList<CrawledLink> links = new ArrayList<CrawledLink>();
                    links.add(link);
                    packages.addAll(collector.removeAndConvert(links));
                }
                }*/

                GUIMediator.safeInvokeAndWait(new Runnable() {
                    public void run() {
                        try {

                            PartialYouTubePackageDialog dlg = new PartialYouTubePackageDialog(
                                    GUIMediator.getAppFrame(), videoUrl, packages);

                            dlg.setVisible(true);
                            if (dlg.getFilesSelection() != null) {
                                for (FilePackage filePackage : dlg.getFilesSelection()) {
                                    BTDownloadMediator.instance().openYouTubeItem(filePackage);
                                }
                            }
                        } catch (Throwable e) {
                            LOG.error("Error reading youtube package:" + e.getMessage(), e);
                            _state = STATE_ERROR;
                        }
                    }
                });

                GUIMediator.safeInvokeAndWait(new Runnable() {
                    public void run() {
                        BTDownloadMediator.instance().remove(YouTubeVideoUrlDownload.this);
                    }
                });
            } catch (Throwable e) {
                LOG.error("Error crawling youtube: " + videoUrl, e);
                _state = STATE_ERROR;
            }
        }
    });
    t.setDaemon(true);
    t.setName("YouTube Crawl: " + videoUrl);
    t.start();
}

From source file:com.xebialabs.overthere.cifs.telnet.CifsTelnetConnection.java

@Override
public OverthereProcess startProcess(final CmdLine cmd) {
    checkNotNull(cmd, "Cannot execute null command line");
    checkArgument(cmd.getArguments().size() > 0, "Cannot execute empty command line");

    final String obfuscatedCmd = cmd.toCommandLine(os, true);
    logger.info("Starting command [{}] on [{}]", obfuscatedCmd, this);

    try {//from  www  .  j a  v a  2  s .c om
        final TelnetClient tc = new TelnetClient();
        tc.setConnectTimeout(connectionTimeoutMillis);
        tc.addOptionHandler(new WindowSizeOptionHandler(299, 25, true, false, true, false));
        logger.info("Connecting to telnet://{}@{}", username, address);
        tc.connect(address, port);
        final InputStream stdout = tc.getInputStream();
        final OutputStream stdin = tc.getOutputStream();
        final PipedInputStream callersStdout = new PipedInputStream();
        final PipedOutputStream toCallersStdout = new PipedOutputStream(callersStdout);
        final ByteArrayOutputStream outputBuf = new ByteArrayOutputStream();
        final int[] exitValue = new int[1];
        exitValue[0] = -1;

        final Thread outputReaderThread = new Thread("Telnet output reader") {
            @Override
            public void run() {
                try {
                    receive(stdout, outputBuf, toCallersStdout, "ogin:");
                    send(stdin, username);

                    receive(stdout, outputBuf, toCallersStdout, "assword:");
                    send(stdin, password);

                    receive(stdout, outputBuf, toCallersStdout, ">", "ogon failure");
                    send(stdin, "PROMPT " + DETECTABLE_WINDOWS_PROMPT);
                    // We must wait for the prompt twice; the first time is an echo of the PROMPT command,
                    // the second is the actual prompt
                    receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);
                    receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);

                    if (workingDirectory != null) {
                        send(stdin, "CD /D " + workingDirectory.getPath());
                        receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);
                    }

                    send(stdin, cmd.toCommandLine(getHostOperatingSystem(), false));

                    receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);

                    send(stdin, "ECHO \"" + ERRORLEVEL_PREAMBLE + "%errorlevel%" + ERRORLEVEL_POSTAMBLE);
                    receive(stdout, outputBuf, toCallersStdout, ERRORLEVEL_POSTAMBLE);
                    receive(stdout, outputBuf, toCallersStdout, ERRORLEVEL_POSTAMBLE);
                    String outputBufStr = outputBuf.toString();
                    int preamblePos = outputBufStr.indexOf(ERRORLEVEL_PREAMBLE);
                    int postamblePos = outputBufStr.indexOf(ERRORLEVEL_POSTAMBLE);
                    if (preamblePos >= 0 && postamblePos >= 0) {
                        String errorlevelString = outputBufStr
                                .substring(preamblePos + ERRORLEVEL_PREAMBLE.length(), postamblePos);
                        logger.debug("Errorlevel string found: {}", errorlevelString);

                        try {
                            synchronized (exitValue) {
                                exitValue[0] = Integer.parseInt(errorlevelString);
                            }
                        } catch (NumberFormatException exc) {
                            logger.error("Cannot parse errorlevel in Windows output: " + outputBuf);
                        }
                    } else {
                        logger.error("Cannot find errorlevel in Windows output: " + outputBuf);
                    }
                } catch (IOException exc) {
                    throw new RuntimeIOException(format("Cannot start command [%s] on [%s]", obfuscatedCmd,
                            CifsTelnetConnection.this), exc);
                } finally {
                    closeQuietly(toCallersStdout);
                }
            }
        };
        outputReaderThread.setDaemon(true);
        outputReaderThread.start();

        return new OverthereProcess() {
            @Override
            public synchronized OutputStream getStdin() {
                return stdin;
            }

            @Override
            public synchronized InputStream getStdout() {
                return callersStdout;
            }

            @Override
            public synchronized InputStream getStderr() {
                return new ByteArrayInputStream(new byte[0]);
            }

            @Override
            public synchronized int waitFor() {
                if (!tc.isConnected()) {
                    return exitValue[0];
                }

                try {
                    try {
                        outputReaderThread.join();
                    } finally {
                        disconnect();
                    }
                    return exitValue[0];
                } catch (InterruptedException exc) {
                    throw new RuntimeIOException(format("Cannot start command [%s] on [%s]", obfuscatedCmd,
                            CifsTelnetConnection.this), exc);
                }
            }

            @Override
            public synchronized void destroy() {
                if (!tc.isConnected()) {
                    return;
                }

                disconnect();
            }

            private synchronized void disconnect() {
                try {
                    tc.disconnect();
                    logger.info("Disconnected from {}", CifsTelnetConnection.this);

                    closeQuietly(toCallersStdout);
                } catch (IOException exc) {
                    throw new RuntimeIOException(format("Cannot disconnect from %s", CifsTelnetConnection.this),
                            exc);
                }
            }

            @Override
            public synchronized int exitValue() {
                if (tc.isConnected()) {
                    throw new IllegalThreadStateException(
                            format("Process for command [%s] on %s is still running", obfuscatedCmd,
                                    CifsTelnetConnection.this));
                }

                synchronized (exitValue) {
                    return exitValue[0];
                }
            }
        };
    } catch (InvalidTelnetOptionException exc) {
        throw new RuntimeIOException(
                "Cannot execute command " + cmd + " at telnet://" + username + "@" + address, exc);
    } catch (IOException exc) {
        throw new RuntimeIOException(
                "Cannot execute command " + cmd + " at telnet://" + username + "@" + address, exc);
    }
}

From source file:com.xebialabs.overthere.telnet.TelnetConnection.java

@Override
public OverthereProcess startProcess(final CmdLine cmd) {
    checkNotNull(cmd, "Cannot execute null command line");
    checkArgument(cmd.getArguments().size() > 0, "Cannot execute empty command line");

    final String obfuscatedCmd = cmd.toCommandLine(os, true);
    logger.info("Starting command [{}] on [{}]", obfuscatedCmd, this);

    try {//from   www  .  jav  a  2  s . com
        final TelnetClient tc = new TelnetClient();
        tc.setSocketFactory(mapper.socketFactory());
        tc.setConnectTimeout(connectionTimeoutMillis);
        tc.addOptionHandler(new WindowSizeOptionHandler(299, 25, true, false, true, false));
        logger.info("Connecting to telnet://{}@{}", username, address);
        tc.connect(address, port);
        tc.setSoTimeout(socketTimeoutMillis);
        final InputStream stdout = tc.getInputStream();
        final OutputStream stdin = tc.getOutputStream();
        final PipedInputStream callersStdout = new PipedInputStream();
        final PipedOutputStream toCallersStdout = new PipedOutputStream(callersStdout);
        final ByteArrayOutputStream outputBuf = new ByteArrayOutputStream();
        final int[] exitValue = new int[1];
        exitValue[0] = -1;

        final Thread outputReaderThread = new Thread("Telnet output reader") {
            @Override
            public void run() {
                try {
                    receive(stdout, outputBuf, toCallersStdout, "ogin:");
                    send(stdin, username);

                    receive(stdout, outputBuf, toCallersStdout, "assword:");
                    send(stdin, password);

                    receive(stdout, outputBuf, toCallersStdout, ">", "ogon failure");
                    send(stdin, "PROMPT " + DETECTABLE_WINDOWS_PROMPT);
                    // We must wait for the prompt twice; the first time is an echo of the PROMPT command,
                    // the second is the actual prompt
                    receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);
                    receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);

                    if (workingDirectory != null) {
                        send(stdin, "CD /D " + workingDirectory.getPath());
                        receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);
                    }

                    send(stdin, cmd.toCommandLine(os, false));

                    receive(stdout, outputBuf, toCallersStdout, DETECTABLE_WINDOWS_PROMPT);

                    send(stdin, "ECHO \"" + ERRORLEVEL_PREAMBLE + "%errorlevel%" + ERRORLEVEL_POSTAMBLE);
                    receive(stdout, outputBuf, toCallersStdout, ERRORLEVEL_POSTAMBLE);
                    receive(stdout, outputBuf, toCallersStdout, ERRORLEVEL_POSTAMBLE);
                    String outputBufStr = outputBuf.toString();
                    int preamblePos = outputBufStr.indexOf(ERRORLEVEL_PREAMBLE);
                    int postamblePos = outputBufStr.indexOf(ERRORLEVEL_POSTAMBLE);
                    if (preamblePos >= 0 && postamblePos >= 0) {
                        String errorlevelString = outputBufStr
                                .substring(preamblePos + ERRORLEVEL_PREAMBLE.length(), postamblePos);
                        logger.debug("Errorlevel string found: {}", errorlevelString);

                        try {
                            synchronized (exitValue) {
                                exitValue[0] = Integer.parseInt(errorlevelString);
                            }
                        } catch (NumberFormatException exc) {
                            logger.error("Cannot parse errorlevel in Windows output: " + outputBuf);
                        }
                    } else {
                        logger.error("Cannot find errorlevel in Windows output: " + outputBuf);
                    }
                } catch (IOException exc) {
                    throw new RuntimeIOException(
                            format("Cannot start command [%s] on [%s]", obfuscatedCmd, TelnetConnection.this),
                            exc);
                } finally {
                    closeQuietly(toCallersStdout);
                }
            }
        };
        outputReaderThread.setDaemon(true);
        outputReaderThread.start();

        return new OverthereProcess() {
            @Override
            public synchronized OutputStream getStdin() {
                return stdin;
            }

            @Override
            public synchronized InputStream getStdout() {
                return callersStdout;
            }

            @Override
            public synchronized InputStream getStderr() {
                return new ByteArrayInputStream(new byte[0]);
            }

            @Override
            public synchronized int waitFor() {
                if (!tc.isConnected()) {
                    return exitValue[0];
                }

                try {
                    try {
                        outputReaderThread.join();
                    } finally {
                        disconnect();
                    }
                    return exitValue[0];
                } catch (InterruptedException exc) {
                    throw new RuntimeIOException(
                            format("Cannot start command [%s] on [%s]", obfuscatedCmd, TelnetConnection.this),
                            exc);
                }
            }

            @Override
            public synchronized void destroy() {
                if (!tc.isConnected()) {
                    return;
                }

                disconnect();
            }

            private synchronized void disconnect() {
                try {
                    tc.disconnect();
                    logger.info("Disconnected from {}", TelnetConnection.this);

                    closeQuietly(toCallersStdout);
                } catch (IOException exc) {
                    throw new RuntimeIOException(format("Cannot disconnect from %s", TelnetConnection.this),
                            exc);
                }
            }

            @Override
            public synchronized int exitValue() {
                if (tc.isConnected()) {
                    throw new IllegalThreadStateException(
                            format("Process for command [%s] on %s is still running", obfuscatedCmd,
                                    TelnetConnection.this));
                }

                synchronized (exitValue) {
                    return exitValue[0];
                }
            }
        };
    } catch (InvalidTelnetOptionException exc) {
        throw new RuntimeIOException(
                "Cannot execute command " + cmd + " at telnet://" + username + "@" + address, exc);
    } catch (IOException exc) {
        throw new RuntimeIOException(
                "Cannot execute command " + cmd + " at telnet://" + username + "@" + address, exc);
    }
}

From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java

/**
 * Build main menu.// w w  w  . j  ava  2 s.c o m
 * 
 * @param spiders
 */
private void buildMenu(final SpidersGraph spiders) {
    JMenuBar menuBar;
    JMenu menu, submenu;
    JMenuItem menuItem, subMenuItem;
    JRadioButtonMenuItem rbMenuItem;

    // create the menu bar
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    // - main menu -------------------------------------------------------
    menu = new JMenu(MindRaiderConstants.MR_TITLE);
    menu.setMnemonic(KeyEvent.VK_M);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.setActiveNotebookAsHome"));
    menuItem.setMnemonic(KeyEvent.VK_H);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            MindRaider.profile.setHomeNotebook();
        }
    });
    menu.add(menuItem);
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.preferences"));
    menuItem.setMnemonic(KeyEvent.VK_P);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new PreferencesJDialog();
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.exit"), KeyEvent.VK_X);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            exitMindRaider();
        }
    });
    menu.add(menuItem);

    menuBar.add(menu);

    // - Find ----------------------------------------------------------

    menu = new JMenu(Messages.getString("MindRaiderJFrame.search"));
    menu.setMnemonic(KeyEvent.VK_F);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchNotebooks"));
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new OpenOutlineJDialog();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchFulltext"));
    menuItem.setMnemonic(KeyEvent.VK_F);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new FtsJDialog();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchConceptsInNotebook"));
    menuItem.setMnemonic(KeyEvent.VK_C);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (MindRaider.profile.getActiveOutlineUri() != null) {
                new OpenNoteJDialog();
            }
        }
    });
    menu.add(menuItem);

    // search by tag
    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchConceptsByTag"));
    menuItem.setEnabled(true);
    menuItem.setMnemonic(KeyEvent.VK_T);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new OpenConceptByTagJDialog();
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.previousNote"));
    menuItem.setEnabled(true);
    menuItem.setMnemonic(KeyEvent.VK_P);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ActionEvent.ALT_MASK));
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            MindRaider.recentConcepts.moveOneNoteBack();
        }
    });
    menu.add(menuItem);

    // global RDF search
    //        menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchRdql"));
    //        menuItem.setEnabled(false);
    //        menuItem.setMnemonic(KeyEvent.VK_R);
    //        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
    //                ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    //        menuItem.addActionListener(new ActionListener() {
    //
    //            public void actionPerformed(ActionEvent e) {
    //                // TODO rdql to be implemented
    //            }
    //        });
    //        menu.add(menuItem);

    menuBar.add(menu);

    // - view ------------------------------------------------------------
    menu = new JMenu(Messages.getString("MindRaiderJFrame.view"));
    menu.setMnemonic(KeyEvent.VK_V);

    // TODO localize L&F menu
    ButtonGroup lfGroup = new ButtonGroup();
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.lookAndFeel"));
    logger.debug("Look and feel is: " + MindRaider.profile.getLookAndFeel()); // {{debug}}
    submenu.setMnemonic(KeyEvent.VK_L);
    subMenuItem = new JRadioButtonMenuItem(Messages.getString("MindRaiderJFrame.lookAndFeelNative"));
    if (MindRaider.LF_NATIVE.equals(MindRaider.profile.getLookAndFeel())) {
        subMenuItem.setSelected(true);
    }
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            setLookAndFeel(MindRaider.LF_NATIVE);
        }
    });
    submenu.add(subMenuItem);
    lfGroup.add(subMenuItem);
    subMenuItem = new JRadioButtonMenuItem(Messages.getString("MindRaiderJFrame.lookAndFeelJava"));
    if (MindRaider.LF_JAVA_DEFAULT.equals(MindRaider.profile.getLookAndFeel())) {
        subMenuItem.setSelected(true);
    }
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            setLookAndFeel(MindRaider.LF_JAVA_DEFAULT);
        }
    });
    submenu.add(subMenuItem);
    lfGroup.add(subMenuItem);
    menu.add(submenu);

    menu.addSeparator();
    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.leftSideBar"));
    menuItem.setMnemonic(KeyEvent.VK_L);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (leftSidebarSplitPane.getDividerLocation() == 1) {
                leftSidebarSplitPane.resetToPreferredSizes();
            } else {
                closeLeftSidebar();
            }
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.rightSideBar"));
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().toggleRightSidebar();
        }
    });
    menu.add(menuItem);

    // TODO tips to be implemented
    // JCheckBoxMenuItem helpCheckbox=new JCheckBoxMenuItem("Tips",true);
    // menu.add(helpCheckbox);

    // TODO localize
    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.toolbar"));
    menuItem.setMnemonic(KeyEvent.VK_T);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            MindRaider.masterToolBar.toggleVisibility();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.rdfNavigatorDashboard"));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            MindRaider.spidersGraph.getGlPanel().toggleControlPanel();
        }
    });
    menu.add(menuItem);

    JCheckBoxMenuItem checkboxMenuItem;
    ButtonGroup colorSchemeGroup;

    //        if (!MindRaider.OUTLINER_PERSPECTIVE.equals(MindRaider.profile
    //                .getUiPerspective())) {

    menu.addSeparator();

    // Facets
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.facet"));
    submenu.setMnemonic(KeyEvent.VK_F);
    colorSchemeGroup = new ButtonGroup();

    String[] facetLabels = FacetCustodian.getInstance().getFacetLabels();
    if (!ArrayUtils.isEmpty(facetLabels)) {
        for (String facetLabel : facetLabels) {
            rbMenuItem = new JRadioButtonMenuItem(facetLabel);
            rbMenuItem.addActionListener(new FacetActionListener(facetLabel));
            colorSchemeGroup.add(rbMenuItem);
            submenu.add(rbMenuItem);
            if (BriefFacet.LABEL.equals(facetLabel)) {
                rbMenuItem.setSelected(true);
            }
        }

    }
    menu.add(submenu);

    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.graphLabelAsUri"));
    checkboxMenuItem.setMnemonic(KeyEvent.VK_G);
    checkboxMenuItem.setState(MindRaider.spidersGraph.isUriLabels());
    checkboxMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                MindRaider.spidersGraph.setUriLabels(j.getState());
                MindRaider.spidersGraph.renderModel();
                MindRaider.profile.setGraphShowLabelsAsUris(j.getState());
                MindRaider.profile.save();
            }
        }
    });

    menu.add(checkboxMenuItem);

    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.predicateNodes"));
    checkboxMenuItem.setMnemonic(KeyEvent.VK_P);
    checkboxMenuItem.setState(!MindRaider.spidersGraph.getHidePredicates());
    checkboxMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                MindRaider.spidersGraph.hidePredicates(!j.getState());
                MindRaider.spidersGraph.renderModel();
                MindRaider.profile.setGraphHidePredicates(!j.getState());
                MindRaider.profile.save();
            }
        }
    });
    menu.add(checkboxMenuItem);

    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.multilineLabels"));
    checkboxMenuItem.setMnemonic(KeyEvent.VK_M);
    checkboxMenuItem.setState(MindRaider.spidersGraph.isMultilineNodes());
    checkboxMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                MindRaider.spidersGraph.setMultilineNodes(j.getState());
                MindRaider.spidersGraph.renderModel();
                MindRaider.profile.setGraphMultilineLabels(j.getState());
                MindRaider.profile.save();
            }
        }
    });
    menu.add(checkboxMenuItem);
    //        }

    menu.addSeparator();

    // Antialias
    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.antiAliased"), true);
    checkboxMenuItem.setMnemonic(KeyEvent.VK_A);
    checkboxMenuItem.setState(SpidersGraph.antialiased);
    checkboxMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                SpidersGraph.antialiased = j.getState();
                MindRaider.spidersGraph.renderModel();
            }
        }
    });
    menu.add(checkboxMenuItem);

    // Enable hyperbolic
    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.hyperbolic"), true);
    checkboxMenuItem.setMnemonic(KeyEvent.VK_H);
    checkboxMenuItem.setState(SpidersGraph.hyperbolic);
    checkboxMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                SpidersGraph.hyperbolic = j.getState();
                MindRaider.spidersGraph.renderModel();
            }
        }
    });
    menu.add(checkboxMenuItem);

    // Show FPS
    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.fps"), true);
    checkboxMenuItem.setMnemonic(KeyEvent.VK_F);
    checkboxMenuItem.setState(SpidersGraph.fps);
    checkboxMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                SpidersGraph.fps = j.getState();
                MindRaider.spidersGraph.renderModel();
            }
        }
    });
    menu.add(checkboxMenuItem);

    // Graph color scheme
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.colorScheme"));
    submenu.setMnemonic(KeyEvent.VK_C);
    String[] allProfilesUris = MindRaider.spidersColorProfileRegistry.getAllProfilesUris();
    colorSchemeGroup = new ButtonGroup();
    for (int i = 0; i < allProfilesUris.length; i++) {
        rbMenuItem = new UriJRadioButtonMenuItem(
                MindRaider.spidersColorProfileRegistry.getColorProfileByUri(allProfilesUris[i]).getLabel(),
                allProfilesUris[i]);
        rbMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() instanceof UriJRadioButtonMenuItem) {
                    MindRaider.spidersColorProfileRegistry
                            .setCurrentProfile(((UriJRadioButtonMenuItem) e.getSource()).uri);
                    MindRaider.spidersGraph
                            .setRenderingProfile(MindRaider.spidersColorProfileRegistry.getCurrentProfile());
                    MindRaider.spidersGraph.renderModel();
                }
            }
        });
        colorSchemeGroup.add(rbMenuItem);
        submenu.add(rbMenuItem);
    }
    menu.add(submenu);

    // Annotation color scheme
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.colorSchemeAnnotation"));
    submenu.setMnemonic(KeyEvent.VK_A);
    allProfilesUris = MindRaider.annotationColorProfileRegistry.getAllProfilesUris();
    colorSchemeGroup = new ButtonGroup();
    for (int i = 0; i < allProfilesUris.length; i++) {
        rbMenuItem = new UriJRadioButtonMenuItem(
                MindRaider.annotationColorProfileRegistry.getColorProfileByUri(allProfilesUris[i]).getLabel(),
                allProfilesUris[i]);
        rbMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() instanceof UriJRadioButtonMenuItem) {
                    MindRaider.annotationColorProfileRegistry
                            .setCurrentProfile(((UriJRadioButtonMenuItem) e.getSource()).uri);
                    OutlineJPanel.getInstance().conceptJPanel.refresh();
                }
            }
        });
        colorSchemeGroup.add(rbMenuItem);
        submenu.add(rbMenuItem);
    }
    menu.add(submenu);

    menu.addSeparator();

    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.fullScreen"));
    checkboxMenuItem.setMnemonic(KeyEvent.VK_U);
    checkboxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0));
    checkboxMenuItem.setState(false);
    checkboxMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                if (j.getState()) {
                    Gfx.toggleFullScreen(MindRaiderMainWindow.this);
                } else {
                    Gfx.toggleFullScreen(null);
                }
            }
        }
    });
    menu.add(checkboxMenuItem);

    menuBar.add(menu);

    // - outline
    // ----------------------------------------------------------------------
    menu = new JMenu(Messages.getString("MindRaiderJFrame.notebook"));
    menu.setMnemonic(KeyEvent.VK_N);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.newNotebook"));
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // TODO clear should be optional - only if creation finished
            // MindRider.spidersGraph.clear();
            new NewOutlineJDialog();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.open"));
    menuItem.setMnemonic(KeyEvent.VK_O);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new OpenOutlineJDialog();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.close"));
    menuItem.setMnemonic(KeyEvent.VK_C);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            MindRaider.outlineCustodian.close();
            OutlineJPanel.getInstance().refresh();
            MindRaider.spidersGraph.renderModel();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.discard"));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.setEnabled(false); // TODO discard method must be implemented
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int result = JOptionPane.showConfirmDialog(MindRaiderMainWindow.this, Messages.getString(
                    "MindRaiderJFrame.confirmDiscardNotebook", MindRaider.profile.getActiveOutline()));
            if (result == JOptionPane.YES_OPTION) {
                if (MindRaider.profile.getActiveOutlineUri() != null) {
                    try {
                        MindRaider.labelCustodian
                                .discardOutline(MindRaider.profile.getActiveOutlineUri().toString());
                        MindRaider.outlineCustodian.close();
                    } catch (Exception e1) {
                        logger.error(Messages.getString("MindRaiderJFrame.unableToDiscardNotebook"), e1);
                    }
                }
            }
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    // export
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.export"));
    submenu.setMnemonic(KeyEvent.VK_E);
    // Atom
    subMenuItem = new JMenuItem("Atom");
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            exportActiveOutlineToAtom();
        }
    });
    submenu.add(subMenuItem);

    // OPML
    subMenuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.opml"));
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (MindRaider.profile.getActiveOutline() == null) {
                JOptionPane.showMessageDialog(MindRaiderMainWindow.this,
                        Messages.getString("MindRaiderJFrame.exportNotebookWarning"),
                        Messages.getString("MindRaiderJFrame.exportError"),

                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            JFileChooser fc = new JFileChooser();
            fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.export"));
            fc.setControlButtonsAreShown(true);
            fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseExportDirectory"));
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            // prepare directory
            String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "export"
                    + File.separator + "opml";
            Utils.createDirectory(exportDirectory);
            fc.setCurrentDirectory(new File(exportDirectory));
            int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                String dstFileName = fc.getSelectedFile().getAbsolutePath() + File.separator + "OPML-EXPORT-"
                        + MindRaider.outlineCustodian.getActiveNotebookNcName() + ".xml";
                logger.debug(Messages.getString("MindRaiderJFrame.exportingToFile", dstFileName));
                MindRaider.outlineCustodian.exportOutline(OutlineCustodian.FORMAT_OPML, dstFileName);
                Launcher.launchViaStart(dstFileName);
            } else {
                logger.debug(Messages.getString("MindRaiderJFrame.exportCommandCancelledByUser"));
            }
        }
    });
    submenu.add(subMenuItem);
    // TWiki
    subMenuItem = new JMenuItem("TWiki");
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (MindRaider.profile.getActiveOutline() == null) {
                JOptionPane.showMessageDialog(MindRaiderMainWindow.this,
                        Messages.getString("MindRaiderJFrame.exportNotebookWarning"),
                        Messages.getString("MindRaiderJFrame.exportError"), JOptionPane.ERROR_MESSAGE);
                return;
            }

            JFileChooser fc = new JFileChooser();
            fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.export"));
            fc.setControlButtonsAreShown(true);
            fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseExportDirectory"));
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            // prepare directory
            String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "export"
                    + File.separator + "twiki";
            Utils.createDirectory(exportDirectory);
            fc.setCurrentDirectory(new File(exportDirectory));
            int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final String dstFileName = fc.getSelectedFile().getAbsolutePath() + File.separator
                        + "TWIKI-EXPORT-" + MindRaider.outlineCustodian.getActiveNotebookNcName() + ".txt";
                logger.debug(Messages.getString("MindRaiderJFrame.exportingToFile", dstFileName));

                MindRaider.outlineCustodian.exportOutline(OutlineCustodian.FORMAT_TWIKI, dstFileName);
            } else {
                logger.debug(Messages.getString("MindRaiderJFrame.exportCommandCancelledByUser"));
            }
        }
    });
    submenu.add(subMenuItem);

    menu.add(submenu);

    // import
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.import"));
    submenu.setMnemonic(KeyEvent.VK_I);

    subMenuItem = new JMenuItem("Atom");
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            importFromAtom();
        }
    });
    submenu.add(subMenuItem);

    // TWiki
    subMenuItem = new JMenuItem("TWiki");
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // choose file to be transformed
            OutlineJPanel.getInstance().clear();
            MindRaider.profile.setActiveOutlineUri(null);
            JFileChooser fc = new JFileChooser();
            int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final File file = fc.getSelectedFile();
                MindRaider.profile.deleteActiveModel();
                logger.debug(
                        Messages.getString("MindRaiderJFrame.importingTWikiTopic", file.getAbsolutePath()));

                // perform it async
                final SwingWorker worker = new SwingWorker() {

                    public Object construct() {
                        ProgressDialogJFrame progressDialogJFrame = new ProgressDialogJFrame(
                                Messages.getString("MindRaiderJFrame.twikiImport"),
                                Messages.getString("MindRaiderJFrame.processingTopicTWiki"));
                        try {
                            MindRaider.outlineCustodian.importNotebook(OutlineCustodian.FORMAT_TWIKI,
                                    (file != null ? file.getAbsolutePath() : null), progressDialogJFrame);
                        } finally {
                            if (progressDialogJFrame != null) {
                                progressDialogJFrame.dispose();
                            }
                        }
                        return null;
                    }
                };
                worker.start();
            } else {
                logger.debug(Messages.getString("MindRaiderJFrame.openCommandCancelledByUser"));
            }
        }
    });
    submenu.add(subMenuItem);

    menu.add(submenu);

    menuBar.add(menu);

    // - note
    // ----------------------------------------------------------------------
    menu = new JMenu(Messages.getString("MindRaiderJFrame.concept"));
    menu.setMnemonic(KeyEvent.VK_C);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.new"));
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().newConcept();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.open"));
    menuItem.setMnemonic(KeyEvent.VK_O);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (MindRaider.profile.getActiveOutlineUri() != null) {
                new OpenNoteJDialog();
            }
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.discard"));
    // do not accelerate this command with DEL - it's already handled
    // elsewhere
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().conceptDiscard();
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.up"));
    menuItem.setMnemonic(KeyEvent.VK_U);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, ActionEvent.CTRL_MASK));
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().conceptUp();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.promote"));
    menuItem.setMnemonic(KeyEvent.VK_P);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ActionEvent.CTRL_MASK));
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().conceptPromote();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.demote"));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, ActionEvent.CTRL_MASK));
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().conceptDemote();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.down"));
    menuItem.setMnemonic(KeyEvent.VK_O);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, ActionEvent.CTRL_MASK));
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().conceptDown();
        }
    });
    menu.add(menuItem);

    menuBar.add(menu);

    // - Tools -----------------------------------------------------------

    menu = new JMenu(Messages.getString("MindRaiderJFrame.tools"));
    menu.setMnemonic(KeyEvent.VK_T);

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.checkAndFix"));
    menuItem.setMnemonic(KeyEvent.VK_F);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Checker.checkAndFixRepositoryAsync();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.backupRepository"));
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Installer.backupRepositoryAsync();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.rebuildSearchIndex"));
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            SearchCommander.rebuildSearchAndTagIndices();
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.captureScreen"));
    menuItem.setMnemonic(KeyEvent.VK_S);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser();
            fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.screenshot"));
            fc.setControlButtonsAreShown(true);
            fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseScreenshotDirectory"));
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            // prepare directory
            String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "Screenshots";
            Utils.createDirectory(exportDirectory);
            fc.setCurrentDirectory(new File(exportDirectory));
            int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final String filename = fc.getSelectedFile().getAbsolutePath() + File.separator
                        + "screenshot.jpg";

                // do it in async (redraw screen)
                Thread thread = new Thread() {
                    public void run() {
                        OutputStream file = null;
                        try {
                            file = new FileOutputStream(filename);

                            Robot robot = new Robot();
                            robot.delay(1000);

                            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(file);
                            encoder.encode(robot.createScreenCapture(
                                    new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())));
                        } catch (Exception e1) {
                            logger.error("Unable to capture screen!", e1);
                        } finally {
                            if (file != null) {
                                try {
                                    file.close();
                                } catch (IOException e1) {
                                    logger.error("Unable to close stream", e1);
                                }
                            }
                        }
                    }
                };
                thread.setDaemon(true);
                thread.start();

            }
        }
    });
    menu.add(menuItem);

    menuBar.add(menu);

    // - MindForger -----------------------------------------------------------

    menu = new JMenu(Messages.getString("MindRaiderMainWindow.menuMindForger"));
    menu.setMnemonic(KeyEvent.VK_O);
    //menu.setIcon(IconsRegistry.getImageIcon("tasks-internet.png"));

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerVideoTutorial"));
    menuItem.setMnemonic(KeyEvent.VK_G);
    menuItem.setToolTipText("http://mindraider.sourceforge.net/mindforger.html");
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Launcher.launchInBrowser("http://mindraider.sourceforge.net/mindforger.html");
        }
    });
    menuItem.setEnabled(true);
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.signUp"));
    menuItem.setMnemonic(KeyEvent.VK_S);
    menuItem.setToolTipText("http://www.mindforger.com");
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Launcher.launchInBrowser("http://www.mindforger.com");
        }
    });
    menuItem.setEnabled(true);
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerUpload"));
    menuItem.setMnemonic(KeyEvent.VK_U);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // fork in order to enable status updates in the main window
            new MindForgerUploadOutlineJDialog();
        }
    });
    menuItem.setEnabled(true);
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerDownload"));
    menuItem.setMnemonic(KeyEvent.VK_U);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            downloadAnOutlineFromMindForger();
        }
    });
    menuItem.setEnabled(true);
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerMyOutlines"));
    menuItem.setMnemonic(KeyEvent.VK_O);
    menuItem.setEnabled(true);
    menuItem.setToolTipText("http://web.mindforger.com");
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Launcher.launchInBrowser("http://web.mindforger.com");
        }
    });
    menu.add(menuItem);

    menuBar.add(menu);

    // - align Help on right -------------------------------------------------------------

    menuBar.add(Box.createHorizontalGlue());

    // - help -------------------------------------------------------------
    menu = new JMenu(Messages.getString("MindRaiderJFrame.help"));
    menu.setMnemonic(KeyEvent.VK_H);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.documentation"));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                MindRaider.outlineCustodian.loadOutline(new URI(MindRaiderVocabulary
                        .getNotebookUri(OutlineCustodian.MR_DOC_NOTEBOOK_DOCUMENTATION_LOCAL_NAME)));
                OutlineJPanel.getInstance().refresh();
            } catch (Exception e1) {
                logger.error(Messages.getString("MindRaiderJFrame.unableToLoadHelp", e1.getMessage()));
            }
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.webHomepage"));
    menuItem.setMnemonic(KeyEvent.VK_H);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Launcher.launchInBrowser("http://mindraider.sourceforge.net");
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.reportBug"));
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Launcher.launchInBrowser("http://sourceforge.net/forum/?group_id=128454");
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.updateCheck"));
    menuItem.setMnemonic(KeyEvent.VK_F);
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // just open html page at:
            //   http://mindraider.sourceforge.net/update-7.2.html
            // this page will either contain "you have the last version" or will ask user to
            // download the latest version from main page
            Launcher.launchInBrowser("http://mindraider.sourceforge.net/" + "update-"
                    + MindRaiderConstants.majorVersion + "." + MindRaiderConstants.minorVersion + ".html");
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.about", MindRaiderConstants.MR_TITLE));
    menuItem.setMnemonic(KeyEvent.VK_A);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new AboutJDialog();
        }
    });
    menu.add(menuItem);

    menuBar.add(menu);
}

From source file:de.huxhorn.lilith.swing.MainFrame.java

/**
 * To be called after setVisible(true)...
 *///from   w  w  w .  ja  va 2s  . c  o  m
public void startUp() {
    //Thread referenceCollection=new Thread(new ColorsCollectionRunnable(), "ColorCacheCleanupThread");
    //referenceCollection.setDaemon(true);
    //referenceCollection.start();

    setSplashStatusText("Executing autostart items.");
    // Autostart
    {
        File autostartDir = new File(startupApplicationPath, "autostart");
        if (autostartDir.mkdirs()) {
            if (logger.isDebugEnabled())
                logger.debug("Created '{}'.", autostartDir.getAbsolutePath());
        }
        File[] autoFiles = autostartDir.listFiles(new FileFilter() {
            public boolean accept(File file) {
                return file.isFile();
            }
        });

        if (autoFiles != null && autoFiles.length > 0) {
            Arrays.sort(autoFiles, new Comparator<File>() {
                public int compare(File o1, File o2) {
                    return o1.getAbsolutePath().compareTo(o2.getAbsolutePath());
                }
            });
            for (File current : autoFiles) {
                AutostartRunnable r = new AutostartRunnable(current);
                autostartProcesses.add(r);
                Thread t = new Thread(r, current.getAbsolutePath());
                t.setDaemon(true);
                t.start();
            }
        } else {
            if (logger.isInfoEnabled()) {
                logger.info("No autostart files defined in '{}'.", autostartDir.getAbsolutePath());
            }
        }
    }

    // go to source
    {
        gotoSource = new SerializingGoToSource();
        //gotoSource.start() started when needed...
    }

    setSplashStatusText("Creating global views.");
    SourceIdentifier globalSourceIdentifier = new SourceIdentifier("global", null);

    loggingFileDump = new FileDumpEventHandler<LoggingEvent>(globalSourceIdentifier, loggingFileBufferFactory);
    accessFileDump = new FileDumpEventHandler<AccessEvent>(globalSourceIdentifier, accessFileBufferFactory);
    setGlobalLoggingEnabled(applicationPreferences.isGlobalLoggingEnabled());

    BlockingCircularBuffer<EventWrapper<LoggingEvent>> loggingEventQueue = new LilithBuffer<LoggingEvent>(
            applicationPreferences, 1000);
    BlockingCircularBuffer<EventWrapper<AccessEvent>> accessEventQueue = new LilithBuffer<AccessEvent>(
            applicationPreferences, 1000);

    SourceManagerImpl<LoggingEvent> lsm = new SourceManagerImpl<LoggingEvent>(loggingEventQueue);
    // add global view
    EventSource<LoggingEvent> globalLoggingEventSource = new EventSourceImpl<LoggingEvent>(
            globalSourceIdentifier, loggingFileDump.getBuffer(), true);
    lsm.addSource(globalLoggingEventSource);

    setSplashStatusText("Creating internal view.");
    // add internal lilith logging
    EventSource<LoggingEvent> lilithLoggingEventSource = new EventSourceImpl<LoggingEvent>(
            InternalLilithAppender.getSourceIdentifier(), InternalLilithAppender.getBuffer(), false);
    lsm.addSource(lilithLoggingEventSource);

    setLoggingEventSourceManager(lsm);

    SourceManagerImpl<AccessEvent> asm = new SourceManagerImpl<AccessEvent>(accessEventQueue);
    // add global view
    EventSource<AccessEvent> globalAccessEventSource = new EventSourceImpl<AccessEvent>(globalSourceIdentifier,
            accessFileDump.getBuffer(), true);
    asm.addSource(globalAccessEventSource);
    setAccessEventSourceManager(asm);

    ConverterRegistry<LoggingEvent> loggingConverterRegistry = new ConverterRegistry<LoggingEvent>();
    loggingConverterRegistry.addConverter(new LogbackLoggingConverter());
    loggingConverterRegistry.addConverter(new Log4jLoggingConverter());
    loggingConverterRegistry.addConverter(new Log4j2LoggingConverter());

    ConverterRegistry<AccessEvent> accessConverterRegistry = new ConverterRegistry<AccessEvent>();
    accessConverterRegistry.addConverter(new LogbackAccessConverter());

    setSplashStatusText("Starting event receivers.");

    try {
        ConvertingServerSocketEventSourceProducer<LoggingEvent> producer = new ConvertingServerSocketEventSourceProducer<LoggingEvent>(
                4560, loggingConverterRegistry, new LoggingEventSourceIdentifierUpdater());
        loggingEventSourceManager.addEventSourceProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        ConvertingServerSocketEventSourceProducer<LoggingEvent> producer = new ConvertingServerSocketEventSourceProducer<LoggingEvent>(
                4445, loggingConverterRegistry, new LoggingEventSourceIdentifierUpdater());
        loggingEventSourceManager.addEventSourceProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        LoggingEventProtobufServerSocketEventSourceProducer producer = new LoggingEventProtobufServerSocketEventSourceProducer(
                ClassicMultiplexSocketAppender.COMPRESSED_DEFAULT_PORT, true);

        loggingEventSourceManager.addEventSourceProducer(producer);
        // TODO: senderService.addLoggingProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        LoggingEventProtobufServerSocketEventSourceProducer producer = new LoggingEventProtobufServerSocketEventSourceProducer(
                ClassicMultiplexSocketAppender.UNCOMPRESSED_DEFAULT_PORT, false);

        loggingEventSourceManager.addEventSourceProducer(producer);
        // TODO: senderService.addLoggingProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        LilithXmlMessageLoggingServerSocketEventSourceProducer producer = new LilithXmlMessageLoggingServerSocketEventSourceProducer(
                ClassicXmlMultiplexSocketAppender.UNCOMPRESSED_DEFAULT_PORT, false);

        loggingEventSourceManager.addEventSourceProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        LilithXmlMessageLoggingServerSocketEventSourceProducer producer = new LilithXmlMessageLoggingServerSocketEventSourceProducer(
                ClassicXmlMultiplexSocketAppender.COMPRESSED_DEFAULT_PORT, true);

        loggingEventSourceManager.addEventSourceProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        LilithJsonMessageLoggingServerSocketEventSourceProducer producer = new LilithJsonMessageLoggingServerSocketEventSourceProducer(
                ClassicJsonMultiplexSocketAppender.UNCOMPRESSED_DEFAULT_PORT, false);

        loggingEventSourceManager.addEventSourceProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        LilithJsonMessageLoggingServerSocketEventSourceProducer producer = new LilithJsonMessageLoggingServerSocketEventSourceProducer(
                ClassicJsonMultiplexSocketAppender.COMPRESSED_DEFAULT_PORT, true);

        loggingEventSourceManager.addEventSourceProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        LilithXmlStreamLoggingServerSocketEventSourceProducer producer = new LilithXmlStreamLoggingServerSocketEventSourceProducer(
                ZeroDelimitedClassicXmlMultiplexSocketAppender.DEFAULT_PORT);

        loggingEventSourceManager.addEventSourceProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        LilithJsonStreamLoggingServerSocketEventSourceProducer producer = new LilithJsonStreamLoggingServerSocketEventSourceProducer(
                ZeroDelimitedClassicJsonMultiplexSocketAppender.DEFAULT_PORT);

        loggingEventSourceManager.addEventSourceProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        JulXmlStreamLoggingServerSocketEventSourceProducer producer = new JulXmlStreamLoggingServerSocketEventSourceProducer(
                11020);

        loggingEventSourceManager.addEventSourceProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        ConvertingServerSocketEventSourceProducer<AccessEvent> producer = new ConvertingServerSocketEventSourceProducer<AccessEvent>(
                4570, accessConverterRegistry, null);
        accessEventSourceManager.addEventSourceProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }
    try {
        AccessEventProtobufServerSocketEventSourceProducer producer = new AccessEventProtobufServerSocketEventSourceProducer(
                AccessMultiplexSocketAppender.COMPRESSED_DEFAULT_PORT, true);

        accessEventSourceManager.addEventSourceProducer(producer);
        // TODO: senderService.addAccessProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    try {
        AccessEventProtobufServerSocketEventSourceProducer producer = new AccessEventProtobufServerSocketEventSourceProducer(
                AccessMultiplexSocketAppender.UNCOMPRESSED_DEFAULT_PORT, false);

        accessEventSourceManager.addEventSourceProducer(producer);
        // TODO: senderService.addAccessProducer(producer);
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception while creating event producer!", ex);
    }

    setSplashStatusText("Setting up event handlers.");

    rrdLoggingEventHandler = new RrdLoggingEventHandler();
    rrdLoggingEventHandler.setBasePath(new File(startupApplicationPath, "statistics"));
    setStatisticsEnabled(applicationPreferences.isLoggingStatisticEnabled());
    AlarmSoundLoggingEventHandler loggingEventAlarmSound = new AlarmSoundLoggingEventHandler();
    loggingEventAlarmSound.setSounds(sounds);

    FileSplitterEventHandler<LoggingEvent> fileSplitterLoggingEventHandler = new FileSplitterEventHandler<LoggingEvent>(
            loggingFileBufferFactory, loggingEventSourceManager);

    List<EventHandler<LoggingEvent>> loggingHandlers = new ArrayList<EventHandler<LoggingEvent>>();

    loggingHandlers.add(rrdLoggingEventHandler);
    loggingHandlers.add(loggingEventAlarmSound);
    loggingHandlers.add(fileSplitterLoggingEventHandler);
    loggingHandlers.add(loggingFileDump);

    // crashes the app using j2se 6
    //if(application.isMac())
    //{
    //   UserNotificationLoggingEventHandler notification = new UserNotificationLoggingEventHandler(application);
    //   loggingHandlers.add(notification);
    //}
    loggingEventSourceManager.setEventHandlers(loggingHandlers);
    loggingEventSourceManager.start();

    List<EventHandler<AccessEvent>> accessHandlers = new ArrayList<EventHandler<AccessEvent>>();

    FileSplitterEventHandler<AccessEvent> fileSplitterAccessEventHandler = new FileSplitterEventHandler<AccessEvent>(
            accessFileBufferFactory, accessEventSourceManager);
    AlarmSoundAccessEventHandler accessEventAlarmSound = new AlarmSoundAccessEventHandler();
    accessEventAlarmSound.setSounds(sounds);
    accessHandlers.add(accessEventAlarmSound);
    accessHandlers.add(fileSplitterAccessEventHandler);
    accessHandlers.add(accessFileDump);

    // crashes the app using j2se 6
    //if(application.isMac())
    //{
    //   UserNotificationAccessEventHandler notification = new UserNotificationAccessEventHandler(application);
    //   accessHandlers.add(notification);
    //}

    accessEventSourceManager.setEventHandlers(accessHandlers);
    accessEventSourceManager.start();

    viewActions.updateWindowMenu();
    application.setEnabledAboutMenu(true);
    application.setEnabledPreferencesMenu(true);
    application.addApplicationListener(new MyApplicationListener());

    if (enableBonjour) {
        senderService.start();
    }
    if (applicationPreferences.isCheckingForUpdate()) {
        checkForUpdate(false);
    }
    updateConditions(); // to initialize active conditions.

    if (applicationPreferences.isShowingTipOfTheDay()) {
        showTipOfTheDayDialog();
    }

    cleanObsoleteFiles();

    traySupport = TraySupport.getInstance();
    if (traySupport != null) {
        traySupport.setMainFrame(this);
    }
    setSplashStatusText("Finished.");
    //      viewActions.requestMenuBarFocus();
}

From source file:com.buaa.cfs.security.UserGroupInformation.java

/** Spawn a thread to do periodic renewals of kerberos credentials */
private void spawnAutoRenewalThreadForUserCreds() {
    if (isSecurityEnabled()) {
        //spawn thread only if we have kerb credentials
        if (user.getAuthenticationMethod() == AuthenticationMethod.KERBEROS && !isKeytab) {
            Thread t = new Thread(new Runnable() {

                @Override/*from  w ww . ja  v a 2 s.co m*/
                public void run() {
                    String cmd = conf.get("hadoop.kerberos.kinit.command", "kinit");
                    KerberosTicket tgt = getTGT();
                    if (tgt == null) {
                        return;
                    }
                    long nextRefresh = getRefreshTime(tgt);
                    while (true) {
                        try {
                            long now = Time.now();
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Current time is " + now);
                                LOG.debug("Next refresh is " + nextRefresh);
                            }
                            if (now < nextRefresh) {
                                Thread.sleep(nextRefresh - now);
                            }
                            Shell.execCommand(cmd, "-R");
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("renewed ticket");
                            }
                            reloginFromTicketCache();
                            tgt = getTGT();
                            if (tgt == null) {
                                LOG.warn("No TGT after renewal. Aborting renew thread for " + getUserName());
                                return;
                            }
                            nextRefresh = Math.max(getRefreshTime(tgt), now + MIN_TIME_BEFORE_RELOGIN);
                        } catch (InterruptedException ie) {
                            LOG.warn("Terminating renewal thread");
                            return;
                        } catch (IOException ie) {
                            LOG.warn("Exception encountered while running the"
                                    + " renewal command. Aborting renew thread. " + ie);
                            return;
                        }
                    }
                }
            });
            t.setDaemon(true);
            t.setName("TGT Renewer for " + getUserName());
            t.start();
        }
    }
}