List of usage examples for java.util.prefs Preferences node
public abstract Preferences node(String pathName);
From source file:org.multicore_association.measure.mem.generate.MemCodeGen.java
/** * Check of the entry presense./*from w w w. j a va 2s .com*/ * @param prefs read configuration data * @param section section name * @param entry entry name * @return Flag of presense */ private boolean checkPrefEntry(Preferences prefs, String section, String entry) { boolean ret = false; String buf; Preferences s = null; try { s = prefs.node(section); buf = s.get(entry, null); if (buf != null) { ret = true; } } catch (Exception e) { ret = false; } return ret; }
From source file:com.github.fritaly.dualcommander.DualCommander.java
public DualCommander() { // TODO Generate a fat jar at build time super(String.format("Dual Commander %s", Utils.getApplicationVersion())); if (logger.isInfoEnabled()) { logger.info(String.format("Dual Commander %s", Utils.getApplicationVersion())); }/*w ww . ja va 2s . co m*/ try { // Apply the JGoodies L&F UIManager.setLookAndFeel(new WindowsLookAndFeel()); } catch (Exception e) { // Not supposed to happen } // Layout, columns & rows setLayout(new MigLayout("insets 0px", "[grow]0px[grow]", "[grow]0px[]")); // Create a menu bar final JMenu fileMenu = new JMenu("File"); fileMenu.add(new JMenuItem(preferencesAction)); fileMenu.add(new JSeparator()); fileMenu.add(new JMenuItem(quitAction)); final JMenu helpMenu = new JMenu("Help"); helpMenu.add(new JMenuItem(aboutAction)); final JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); menuBar.add(helpMenu); setJMenuBar(menuBar); this.leftPane = new TabbedPane(preferences); this.leftPane.setName("Left"); this.leftPane.addChangeListener(this); this.leftPane.addKeyListener(this); this.leftPane.addFocusListener(this); this.rightPane = new TabbedPane(preferences); this.rightPane.setName("Right"); this.rightPane.addChangeListener(this); this.rightPane.addKeyListener(this); this.rightPane.addFocusListener(this); // Adding the 2 components to the same sizegroup ensures they always // keep the same width getContentPane().add(leftPane, "grow, sizegroup g1"); getContentPane().add(rightPane, "grow, sizegroup g1, wrap"); // The 7 buttons must all have the same width (they must belong to the // same size group) final JPanel buttonPanel = new JPanel( new MigLayout("insets 0px", StringUtils.repeat("[grow, sizegroup g1]", 7), "[grow]")); buttonPanel.add(viewButton, "grow"); buttonPanel.add(editButton, "grow"); buttonPanel.add(copyButton, "grow"); buttonPanel.add(moveButton, "grow"); buttonPanel.add(mkdirButton, "grow"); buttonPanel.add(deleteButton, "grow"); buttonPanel.add(quitButton, "grow"); getContentPane().add(buttonPanel, "grow, span 2"); // Register shortcuts at a global level (not on every component) final InputMap inputMap = this.leftPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0, true), "view"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0, true), "edit"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, true), "copy"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0, true), "move"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0, true), "mkdir"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0, true), "delete"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, KeyEvent.ALT_DOWN_MASK), "quit"); final ActionMap actionMap = this.leftPane.getActionMap(); actionMap.put("view", viewAction); actionMap.put("edit", editAction); actionMap.put("copy", copyAction); actionMap.put("move", moveAction); actionMap.put("mkdir", mkdirAction); actionMap.put("delete", deleteAction); actionMap.put("quit", quitAction); addWindowListener(this); addKeyListener(this); // Listen to preference change events this.preferences.addPropertyChangeListener(this); // Reload the last configuration and init the left & right panels // accordingly final Preferences prefs = Preferences.userNodeForPackage(this.getClass()); // The user preferences must be loaded first because they're needed to // init the UI this.preferences.init(prefs.node("user.preferences")); this.leftPane.init(prefs.node("left.panel")); this.rightPane.init(prefs.node("right.panel")); if (logger.isInfoEnabled()) { logger.info("Loaded preferences"); } // Init the buttons refreshButtons(this.leftPane.getActiveBrowser().getSelection()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setExtendedState(JFrame.MAXIMIZED_BOTH); if (logger.isInfoEnabled()) { logger.info("UI initialized"); } }
From source file:org.dllearner.scripts.evaluation.EnrichmentEvaluation.java
private void initDBConnection() { try {//from w ww . j a va 2 s .c om String iniFile = "db_settings.ini"; Preferences prefs = new IniPreferences(new FileReader(iniFile)); String dbServer = prefs.node("database").get("server", null); String dbName = prefs.node("database").get("name", null); String dbUser = prefs.node("database").get("user", null); String dbPass = prefs.node("database").get("pass", null); Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://" + dbServer + "/" + dbName; conn = DriverManager.getConnection(url, dbUser, dbPass); ps = conn.prepareStatement("INSERT INTO evaluation (" + "entity, algorithm, axiom, score, runtime_ms, entailed ) " + "VALUES(?,?,?,?,?,?)"); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (InvalidFileFormatException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.kuali.test.creator.TestCreator.java
private void loadPreferences() { try {/*from ww w . j a va 2 s. c o m*/ Preferences proot = Preferences.userRoot(); Preferences node = proot.node(Constants.PREFS_ROOT_NODE); int left = node.getInt(Constants.PREFS_MAINFRAME_LEFT, Constants.MAINFRAME_DEFAULT_LEFT); int top = node.getInt(Constants.PREFS_MAINFRAME_TOP, Constants.MAINFRAME_DEFAULT_TOP); int width = node.getInt(Constants.PREFS_MAINFRAME_WIDTH, Constants.MAINFRAME_DEFAULT_WIDTH); int height = node.getInt(Constants.PREFS_MAINFRAME_HEIGHT, Constants.MAINFRAME_DEFAULT_HEIGHT); setState(node.getInt(Constants.PREFS_MAINFRAME_WINDOW_STATE, Frame.NORMAL)); setBounds(left, top, width, height); node.flush(); } catch (BackingStoreException ex) { LOG.error(ex.toString(), ex); } }
From source file:org.kuali.test.creator.TestCreator.java
private void savePreferences() { try {/* w ww .j a v a 2 s . co m*/ Preferences proot = Preferences.userRoot(); Preferences node = proot.node(Constants.PREFS_ROOT_NODE); Rectangle rect = getBounds(); node.putInt(Constants.PREFS_MAINFRAME_LEFT, rect.x); node.putInt(Constants.PREFS_MAINFRAME_TOP, rect.y); node.putInt(Constants.PREFS_MAINFRAME_WIDTH, rect.width); node.putInt(Constants.PREFS_MAINFRAME_HEIGHT, rect.height); node.putInt(Constants.PREFS_HORIZONTAL_DIVIDER_LOCATION, hsplitPane.getDividerLocation()); node.putInt(Constants.PREFS_VERTICAL_DIVIDER_LOCATION, vsplitPane.getDividerLocation()); node.putInt(Constants.PREFS_MAINFRAME_WINDOW_STATE, getState()); node.flush(); } catch (BackingStoreException ex) { LOG.error(ex.toString(), ex); } }
From source file:org.kuali.test.creator.TestCreator.java
private void loadSplitPanes() { if (hsplitPane != null) { desktopPane.remove(hsplitPane);// w ww . j a v a2 s . com } hsplitPane = new JSplitPane(); vsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); JPanel p = new JPanel(new BorderLayout()); p.add(new JScrollPane(testRepositoryTree = new RepositoryTree(this)), BorderLayout.CENTER); hsplitPane.setDividerLocation(150); hsplitPane.setOneTouchExpandable(true); vsplitPane.setDividerLocation(250); vsplitPane.setTopComponent(p); vsplitPane.setBottomComponent(platformTestsPanel = new PlatformTestsPanel(this)); testRepositoryTree.addTreeSelectionListener(platformTestsPanel); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab(Constants.REPOSITORY, vsplitPane); tabbedPane.addTab(Constants.DATABASES, new JScrollPane(databaseTree = new DatabaseTree(this, getConfiguration()))); tabbedPane.addTab(Constants.WEBSERVICES, new JScrollPane(webServiceTree = new WebServiceTree(this, getConfiguration()))); tabbedPane.addTab(Constants.JMX, new JScrollPane(jmxTree = new JmxTree(this, getConfiguration()))); hsplitPane.setLeftComponent(tabbedPane); hsplitPane.setRightComponent(createTestPanel = new CreateTestPanel(this)); Preferences proot = Preferences.userRoot(); Preferences node = proot.node(Constants.PREFS_ROOT_NODE); hsplitPane.setDividerLocation(node.getInt(Constants.PREFS_HORIZONTAL_DIVIDER_LOCATION, Constants.DEFAULT_HORIZONTAL_DIVIDER_LOCATION)); vsplitPane.setDividerLocation(node.getInt(Constants.PREFS_VERTICAL_DIVIDER_LOCATION, Constants.DEFAULT_VERTICAL_DIVIDER_LOCATION)); desktopPane.add(hsplitPane, BorderLayout.CENTER); }
From source file:org.nuclos.client.common.NuclosCollectController.java
/** * restores the state of this <code>CollectController</code> from the preferences. * @param prefs/* ww w. j a v a 2s . co m*/ * @return the stored collect state. * @throws NuclosBusinessException */ @Deprecated protected int restoreStateFromPreferences(Preferences prefs) throws CommonBusinessException { if (this.isSearchPanelAvailable()) { assert this.getCollectStateModel().getOuterState() == CollectState.OUTERSTATE_UNDEFINED; final CollectableSearchCondition cond = SearchConditionUtils.getSearchCondition( prefs.node(PREFS_NODE_SEARCHCONDITION), this.getCollectableEntity().getName()); // Always set Search mode initially, to restore the search criteria. // Later, the previous state is restored. if (cond != null) { this.setCollectState(CollectState.OUTERSTATE_SEARCH, CollectState.SEARCHMODE_UNSYNCHED); this.restoreSearchCriteriaFromPreferences(prefs); } } // restore collect state: return prefs.getInt(PREFS_KEY_OUTERSTATE, CollectState.OUTERSTATE_UNDEFINED); }
From source file:org.nuclos.client.common.NuclosCollectController.java
/** * @param prefs/*from ww w . j a v a 2 s. com*/ * @throws CommonBusinessException * @precondition this.isSearchPanelVisible() */ @Deprecated protected void restoreSearchCriteriaFromPreferences(Preferences prefs) throws CommonBusinessException { if (!this.isSearchPanelAvailable()) { throw new IllegalStateException("!isSearchPanelVisible()"); } // restore search condition: final CollectableSearchCondition cond = SearchConditionUtils .getSearchCondition(prefs.node(PREFS_NODE_SEARCHCONDITION), this.getCollectableEntity().getName()); this.restoreSearchCriteriaFromPreferences(cond); }
From source file:com.adito.server.DefaultAditoServerFactory.java
void copyNode(Preferences from, Preferences to) throws BackingStoreException { String[] keys = from.keys();// w ww . j a va 2 s . c o m for (String key : keys) { to.put(key, from.get(key, "")); } String childNodes[] = from.childrenNames(); for (String childNode : childNodes) { Preferences cn = from.node(childNode); Preferences tn = to.node(childNode); copyNode(cn, tn); } }
From source file:com.adito.server.DefaultAditoServerFactory.java
public Integer start(String[] args) { startupStarted = System.currentTimeMillis(); // Inform the wrapper the startup process may take a while if (useWrapper) { WrapperManager.signalStarting(60000); }/*from www.j a v a 2 s . c o m*/ // Parse the command line Integer returnCode = parseCommandLine(args); if (returnCode != null) { if (returnCode == 999) { return null; } return returnCode; } // Create the boot progress monitor if (gui) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { } catch (InstantiationException e) { } catch (IllegalAccessException e) { } catch (UnsupportedLookAndFeelException e) { } bootProgressMonitor = new SwingBootProgressMonitor(); } else { bootProgressMonitor = new LogBootProgressMonitor(); } // resourceCaches = new HashMap<URL, ResourceCache>(); contextListeners = new ArrayList<ContextListener>(); loadSystemProperties(); initialiseLogging(); /* * Migrate preferences. */ File newPrefDir = new File(ContextHolder.getContext().getConfDirectory(), "prefs"); PREF = PropertyPreferences.SYSTEM_ROOT; try { if (!newPrefDir.exists() && Preferences.systemRoot().node("/com").nodeExists("adito")) { Preferences from = Preferences.systemRoot().node("/com/adito"); LOG.warn("Migrating preferences"); try { copyNode(from.node("core"), PREF.node("core")); from.node("core").removeNode(); copyNode(from.node("plugin"), PREF.node("plugin")); from.node("plugin").removeNode(); copyNode(from.node("extensions"), PREF.node("extensions")); from.node("extensions").removeNode(); copyNode(from.node("dbupgrader"), PREF.node("dbupgrader")); from.node("dbupgrader").removeNode(); } catch (BackingStoreException e) { LOG.error("Failed to migrate preferences.", e); } try { from.flush(); } catch (BackingStoreException bse) { LOG.error("Failed to flush old preferences"); } try { PREF.flush(); } catch (BackingStoreException bse) { LOG.error("Failed to flush new preferences"); } if (LOG.isInfoEnabled()) { LOG.info("Flushing preferences"); } } } catch (BackingStoreException bse) { LOG.error("Failed to migrate preferences.", bse); } // Inform the wrapper the startup process is going ok if (useWrapper) { WrapperManager.signalStarting(60000); } try { clearTemp(); try { hostname = Inet4Address.getLocalHost().getCanonicalHostName(); hostAddress = Inet4Address.getLocalHost().getHostAddress(); } catch (UnknownHostException ex) { // This should be fatal, we now rely on the hostname being // available throw new Exception("The host name or address on which this service is running could not " + "be determined. Check you network configuration. One possible cause is " + "a misconfigured 'hosts' file (e.g. on UNIX-like systems this would be " + "/etc/hosts, on Windows XP it would be " + "C:\\Windows\\System32\\Drivers\\Etc\\Hosts)."); } PropertyClassManager.getInstance() .registerPropertyClass(contextConfiguration = new ContextConfig(getClass().getClassLoader())); // Display some information about the system we are running on displaySystemInfo(); // Load the context property definitions loadContextProperties(); // Inform the wrapper the startup process is going ok if (useWrapper) { WrapperManager.signalStarting(60000); } // Configure any HTTP / HTTPS / SOCKS proxy servers configureProxyServers(); PropertyList l = contextConfiguration.retrievePropertyList(new ContextKey("webServer.bindAddress")); getBootProgressMonitor().updateMessage("Creating server lock"); getBootProgressMonitor().updateProgress(6); serverLock = new ServerLock(l.get(0)); if (serverLock.isLocked()) { if (!isSetupMode()) { if (serverLock.isSetup()) { throw new Exception("The installation wizard is currently running. " + "Please shut this down by pointing your browser " + "to http://" + getHostname() + ":" + serverLock.getPort() + "/showShutdown.do before attempting to start the server again."); } else { throw new Exception("The server is already running."); } } else { if (!serverLock.isSetup()) { throw new Exception("The server is currently already running. " + "Please shut this down by pointing your browser " + "to https://" + getHostname() + ":" + serverLock.getPort() + "/showShutdown.do before attempting to start the server again."); } else { throw new Exception("The installation wizard is running.."); } } } // Inform the wrapper the startup process is going ok if (useWrapper) { WrapperManager.signalStarting(60000); } Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { serverLock.stop(); } }); // registerKeyStores(); // threadGroup = new ThreadGroup("MainThreadGroup"); if (install) { setupMode(); } else { normalMode(); startHttpServer(); } } catch (Exception t) { startupException = t; LOG.error("Failed to start the server. " + t.getMessage(), t); return 1; } return null; }