List of usage examples for java.util.prefs Preferences userNodeForPackage
public static Preferences userNodeForPackage(Class<?> c)
From source file:ffx.ui.ModelingPanel.java
private void initialize() { // Command Description descriptTextArea = new JTextArea(); descriptTextArea.setEditable(false); descriptTextArea.setLineWrap(true);//from ww w . ja v a 2s. c o m descriptTextArea.setWrapStyleWord(true); descriptTextArea.setDoubleBuffered(true); Insets insets = descriptTextArea.getInsets(); insets.set(5, 5, 5, 5); descriptTextArea.setMargin(insets); descriptScrollPane = new JScrollPane(descriptTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); descriptScrollPane.setBorder(etchedBorder); // Command Input commandTextArea = new JTextArea(); commandTextArea.setEditable(false); commandTextArea.setLineWrap(true); commandTextArea.setWrapStyleWord(true); commandTextArea.setDoubleBuffered(true); commandTextArea.setMargin(insets); // Command Options optionsTabbedPane = new JTabbedPane(); statusLabel = new JLabel(); statusLabel.setBorder(etchedBorder); statusLabel.setToolTipText(" Modeling command that will be executed"); commandPanel = new JPanel(flowLayout); commandPanel.add(optionsTabbedPane); splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, commandPanel, descriptScrollPane); splitPane.setContinuousLayout(true); splitPane.setResizeWeight(1.0d); splitPane.setOneTouchExpandable(true); setLayout(new BorderLayout()); add(splitPane, BorderLayout.CENTER); add(statusLabel, BorderLayout.SOUTH); // Initialize the Amino/Nucleic Acid ComboBox. acidComboBox.setEditable(false); acidComboBox.setMaximumSize(sizer.getPreferredSize()); acidComboBox.setPreferredSize(sizer.getPreferredSize()); acidComboBox.setMinimumSize(sizer.getPreferredSize()); acidComboBox.setFont(Font.decode("Monospaced")); acidTextField.setMaximumSize(sizer.getPreferredSize()); acidTextField.setMinimumSize(sizer.getPreferredSize()); acidTextField.setPreferredSize(sizer.getPreferredSize()); acidTextArea.setEditable(false); acidTextArea.setWrapStyleWord(true); acidTextArea.setLineWrap(true); acidTextArea.setFont(Font.decode("Monospaced")); acidScrollPane = new JScrollPane(acidTextArea); Dimension d = new Dimension(300, 400); acidScrollPane.setPreferredSize(d); acidScrollPane.setMaximumSize(d); acidScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); // Load the FFX commands.xml file that defines FFX commands. try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver(new DTDResolver()); URL comURL = getClass().getClassLoader().getResource("ffx/ui/commands/commands.xml"); Document doc = db.parse(comURL.openStream()); NodeList nodelist = doc.getChildNodes(); Node commandroot = null; for (int i = 0; i < nodelist.getLength(); i++) { commandroot = nodelist.item(i); if (commandroot.getNodeName().equals("FFXCommands") && commandroot instanceof Element) { break; } } if (commandroot == null || !(commandroot instanceof Element)) { commandList = null; } commandList = ((Element) commandroot).getElementsByTagName("Command"); } catch (ParserConfigurationException | SAXException | IOException e) { System.err.println(e); } finally { if (commandList == null) { System.out.println("Force Field X commands.xml could not be parsed."); logger.severe("Force Field X will exit."); System.exit(-1); } } // Create a ComboBox with commands specific to each type of coordinate // file. xyzCommands = new JComboBox<>(); intCommands = new JComboBox<>(); arcCommands = new JComboBox<>(); pdbCommands = new JComboBox<>(); anyCommands = new JComboBox<>(); Element command; String name; int numcommands = commandList.getLength(); for (int i = 0; i < numcommands; i++) { command = (Element) commandList.item(i); name = command.getAttribute("name"); String temp = command.getAttribute("fileType"); if (temp.contains("ANY")) { temp = "XYZ INT ARC PDB"; anyCommands.addItem(name); } String[] types = temp.split(" +"); for (String type : types) { if (type.contains("XYZ")) { xyzCommands.addItem(name); } if (type.contains("INT")) { intCommands.addItem(name); } if (type.contains("ARC")) { arcCommands.addItem(name); } if (type.contains("PDB")) { pdbCommands.addItem(name); } } } initCommandComboBox(xyzCommands); initCommandComboBox(intCommands); initCommandComboBox(arcCommands); initCommandComboBox(pdbCommands); initCommandComboBox(anyCommands); currentCommandBox = anyCommands; activeCommand = (String) anyCommands.getSelectedItem(); // Load the default Command. loadCommand(); // Load the default Log File Settings. logSettings.setActionCommand("LogSettings"); loadLogSettings(); // Create the Toolbar. toolBar = new JToolBar("Modeling Commands", JToolBar.HORIZONTAL); toolBar.setLayout(new FlowLayout(FlowLayout.LEFT)); jbLaunch = new JButton(new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/cog_go.png"))); jbLaunch.setActionCommand("Launch"); jbLaunch.setToolTipText("Launch the Force Field X Command"); jbLaunch.addActionListener(this); insets.set(2, 2, 2, 2); jbLaunch.setMargin(insets); toolBar.add(jbLaunch); jbStop = new JButton(new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/stop.png"))); jbStop.setActionCommand("End"); jbStop.setToolTipText("Terminate the Current Force Field X Command"); jbStop.addActionListener(this); jbStop.setMargin(insets); jbStop.setEnabled(false); toolBar.add(jbStop); toolBar.addSeparator(); toolBar.add(anyCommands); currentCommandBox = anyCommands; toolBar.addSeparator(); /* toolBar.add(logSettings); JButton jbdelete = new JButton(new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/page_delete.png"))); jbdelete.setActionCommand("Delete"); jbdelete.setToolTipText("Delete Log Files"); jbdelete.addActionListener(this); jbdelete.setMargin(insets); toolBar.add(jbdelete); toolBar.addSeparator(); */ ImageIcon icinfo = new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/information.png")); descriptCheckBox = new JCheckBoxMenuItem(icinfo); descriptCheckBox.addActionListener(this); descriptCheckBox.setActionCommand("Description"); descriptCheckBox.setToolTipText("Show/Hide Modeling Command Descriptions"); descriptCheckBox.setMargin(insets); toolBar.add(descriptCheckBox); toolBar.add(new JLabel("")); toolBar.setBorderPainted(false); toolBar.setFloatable(false); toolBar.setRollover(true); add(toolBar, BorderLayout.NORTH); // Load ModelingPanel preferences. Preferences prefs = Preferences.userNodeForPackage(ffx.ui.ModelingPanel.class); descriptCheckBox.setSelected(!prefs.getBoolean("JobPanel_description", true)); descriptCheckBox.doClick(); }
From source file:jgnash.report.pdf.Report.java
public final Preferences getPreferences() { return Preferences.userNodeForPackage(getClass()).node(getClass().getSimpleName()); }
From source file:com.delcyon.capo.Configuration.java
@SuppressWarnings({ "unchecked", "static-access" }) public Configuration(String... programArgs) throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilder = documentBuilderFactory.newDocumentBuilder(); options = new Options(); // the enum this is a little complicated, but it gives us a nice // centralized place to put all of the system parameters // and lets us iterate of the list of options and preferences PREFERENCE[] preferences = PREFERENCE.values(); for (PREFERENCE preference : preferences) { // not the most elegant, but there is no default constructor, but // the has arguments value is always there OptionBuilder optionBuilder = OptionBuilder.hasArg(preference.hasArgument); if (preference.hasArgument == true) { String[] argNames = preference.arguments; for (String argName : argNames) { optionBuilder = optionBuilder.withArgName(argName); }/*from w w w . j a v a 2s .c o m*/ } optionBuilder = optionBuilder.withDescription(preference.getDescription()); optionBuilder = optionBuilder.withLongOpt(preference.getLongOption()); options.addOption(optionBuilder.create(preference.getOption())); preferenceHashMap.put(preference.toString(), preference); } //add dynamic options Set<String> preferenceProvidersSet = CapoApplication.getAnnotationMap() .get(PreferenceProvider.class.getCanonicalName()); if (preferenceProvidersSet != null) { for (String className : preferenceProvidersSet) { Class preferenceClass = Class.forName(className).getAnnotation(PreferenceProvider.class) .preferences(); if (preferenceClass.isEnum()) { Object[] enumObjects = preferenceClass.getEnumConstants(); for (Object enumObject : enumObjects) { Preference preference = (Preference) enumObject; //filter out any preferences that don't belong on this server or client. if (preference.getLocation() != Location.BOTH) { if (CapoApplication.isServer() == true && preference.getLocation() == Location.CLIENT) { continue; } else if (CapoApplication.isServer() == false && preference.getLocation() == Location.SERVER) { continue; } } preferenceHashMap.put(preference.toString(), preference); boolean hasArgument = false; if (preference.getArguments() == null || preference.getArguments().length == 0) { hasArgument = false; } else { hasArgument = true; } OptionBuilder optionBuilder = OptionBuilder.hasArg(hasArgument); if (hasArgument == true) { String[] argNames = preference.getArguments(); for (String argName : argNames) { optionBuilder = optionBuilder.withArgName(argName); } } optionBuilder = optionBuilder.withDescription(preference.getDescription()); optionBuilder = optionBuilder.withLongOpt(preference.getLongOption()); options.addOption(optionBuilder.create(preference.getOption())); } } } } // create parser CommandLineParser commandLineParser = new GnuParser(); this.commandLine = commandLineParser.parse(options, programArgs); Preferences systemPreferences = Preferences .systemNodeForPackage(CapoApplication.getApplication().getClass()); String capoDirString = null; while (true) { capoDirString = systemPreferences.get(PREFERENCE.CAPO_DIR.longOption, null); if (capoDirString == null) { systemPreferences.put(PREFERENCE.CAPO_DIR.longOption, PREFERENCE.CAPO_DIR.defaultValue); capoDirString = PREFERENCE.CAPO_DIR.defaultValue; try { systemPreferences.sync(); } catch (BackingStoreException e) { //e.printStackTrace(); if (systemPreferences.isUserNode() == false) { System.err.println("Problem with System preferences, trying user's"); systemPreferences = Preferences .userNodeForPackage(CapoApplication.getApplication().getClass()); continue; } else //just bail out { throw e; } } } break; } disableAutoSync = hasOption(PREFERENCE.DISABLE_CONFIG_AUTOSYNC); File capoDirFile = new File(capoDirString); if (capoDirFile.exists() == false) { if (disableAutoSync == false) { capoDirFile.mkdirs(); } } File configDir = new File(capoDirFile, PREFERENCE.CONFIG_DIR.defaultValue); if (configDir.exists() == false) { if (disableAutoSync == false) { configDir.mkdirs(); } } if (disableAutoSync == false) { capoConfigFile = new File(configDir, CONFIG_FILENAME); if (capoConfigFile.exists() == false) { Document configDocument = CapoApplication.getDefaultDocument("config.xml"); FileOutputStream configFileOutputStream = new FileOutputStream(capoConfigFile); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(configDocument), new StreamResult(configFileOutputStream)); configFileOutputStream.close(); } configDocument = documentBuilder.parse(capoConfigFile); } else //going memory only, because of disabled auto sync { configDocument = CapoApplication.getDefaultDocument("config.xml"); } if (configDocument instanceof CDocument) { ((CDocument) configDocument).setSilenceEvents(true); } loadPreferences(); preferenceValueHashMap.put(PREFERENCE.CAPO_DIR.longOption, capoDirString); //print out preferences //this also has the effect of persisting all of the default values if a values doesn't already exist for (PREFERENCE preference : preferences) { if (getValue(preference) != null) { CapoApplication.logger.log(Level.CONFIG, preference.longOption + "='" + getValue(preference) + "'"); } } CapoApplication.logger.setLevel(Level.parse(getValue(PREFERENCE.LOGGING_LEVEL))); }
From source file:com.sittinglittleduck.DirBuster.Manager.java
public void loadPrefs() { userPrefs = Preferences.userNodeForPackage(Manager.class); lastUpdateCheck = new Date(userPrefs.getLong("LastUpdateCheck", 0L)); defaultNoThreads = userPrefs.getInt("DefaultNoTreads", 10); defaultList = userPrefs.get("DefaultList", ""); defaultExts = userPrefs.get("DefaultExts", "php"); }
From source file:com.concursive.connect.config.ApplicationPrefs.java
/** * Save a name/value pair to the Java Preferences store * * @param instanceName Description of the Parameter * @param fileLibraryLocation Description of the Parameter * @return Description of the Return Value *//*from ww w . j a v a 2s . c om*/ public static boolean saveFileLibraryLocation(String instanceName, String fileLibraryLocation) { try { if (instanceName == null || fileLibraryLocation == null) { LOG.error("Invalid parameters: " + instanceName + "=" + fileLibraryLocation); } Preferences javaPrefs = Preferences.userNodeForPackage(ApplicationPrefs.class); if (javaPrefs == null) { LOG.error("Couldn't create java preferences for: " + ApplicationPrefs.class); } if (instanceName.length() <= Preferences.MAX_KEY_LENGTH) { javaPrefs.put(instanceName, fileLibraryLocation); } else { javaPrefs.put(instanceName.substring(instanceName.length() - Preferences.MAX_KEY_LENGTH), fileLibraryLocation); } javaPrefs.flush(); return true; } catch (Exception e) { LOG.error("saveFileLibraryLocation", e); e.printStackTrace(System.out); return false; } }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Returns the pathname string of the default folder. * //from w w w .ja va 2s . com * @return See above. */ public static String getDefaultFolderAsString() { Preferences prefs = Preferences.userNodeForPackage(UIUtilities.class); if (prefs == null) return null; return prefs.get(DEFAULT_FOLDER, null); }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Sets the pathname string of the default folder. * /*from w w w.ja v a 2 s . co m*/ * @param f The value to set. */ public static void setDefaultFolder(String f) { Preferences prefs = Preferences.userNodeForPackage(UIUtilities.class); if (prefs == null) return; if (f == null) f = ""; prefs.put(DEFAULT_FOLDER, f); }
From source file:com.nbt.TreeFrame.java
public Preferences getPreferences() { return Preferences.userNodeForPackage(getClass()); }
From source file:com.mirth.connect.client.ui.DashboardPanel.java
private void switchTableMode(boolean groupModeEnabled) { DashboardTreeTableModel model = (DashboardTreeTableModel) dashboardTable.getTreeTableModel(); if (model.isGroupModeEnabled() != groupModeEnabled) { Preferences.userNodeForPackage(Mirth.class).putBoolean("channelGroupViewEnabled", groupModeEnabled); if (groupModeEnabled) { tableModeChannelsButton.setContentFilled(false); } else {/* w ww. jav a2s. c o m*/ tableModeGroupsButton.setContentFilled(false); } TableState tableState = getCurrentTableState(); model.setGroupModeEnabled(groupModeEnabled); restoreTableState(tableState); updatePopupMenu(false); int totalGroupCount = parent.channelPanel.getCachedGroupStatuses().size(); int totalChannelCount = parent.status != null ? parent.status.size() : 0; ChannelTagInfo channelTagInfo = parent.getChannelTagInfo(true); if (channelTagInfo.isEnabled()) { int visibleGroupCount = 0; int visibleChannelCount = 0; if (model.isGroupModeEnabled()) { for (Enumeration<? extends MutableTreeTableNode> groupNodes = ((MutableTreeTableNode) model .getRoot()).children(); groupNodes.hasMoreElements();) { visibleGroupCount++; visibleChannelCount += ((MutableTreeTableNode) groupNodes.nextElement()).getChildCount(); } } else { visibleChannelCount = ((MutableTreeTableNode) model.getRoot()).getChildCount(); } updateTagsLabel(totalGroupCount, visibleGroupCount, totalChannelCount, visibleChannelCount); } else { updateTagsLabel(totalGroupCount, totalGroupCount, totalChannelCount, totalChannelCount); } } }
From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowser.java
/** * Sets the properties and adds the listeners for the Message Table. No data is loaded at this * point.//from w w w .j a v a2s . c om */ private void makeMessageTable() { messageTreeTable.setDragEnabled(true); messageTreeTable.setSortable(false); messageTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); messageTreeTable.setColumnFactory(new MessageBrowserTableColumnFactory()); messageTreeTable.setLeafIcon(null); messageTreeTable.setOpenIcon(null); messageTreeTable.setClosedIcon(null); messageTreeTable.setAutoCreateColumnsFromModel(false); messageTreeTable.setMirthColumnControlEnabled(true); messageTreeTable.setShowGrid(true, true); messageTreeTable.setHorizontalScrollEnabled(true); messageTreeTable.setPreferredScrollableViewportSize(messageTreeTable.getPreferredSize()); messageTreeTable.setMirthTransferHandlerEnabled(true); tableModel = new MessageBrowserTableModel(columnMap.size()); // Add a blank column to the column initially, otherwise it return an exception on load // Columns will be re-generated when the message browser is viewed tableModel.setColumnIdentifiers(Arrays.asList(new String[] { "" })); messageTreeTable.setTreeTableModel(tableModel); // Sets the alternating highlighter for the table if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR); messageTreeTable.setHighlighters(highlighter); } // Add the listener for when the table selection changes messageTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { MessageListSelected(evt); } }); // Add the mouse listener messageTreeTable.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { checkMessageSelectionAndPopupMenu(evt); } public void mouseReleased(java.awt.event.MouseEvent evt) { checkMessageSelectionAndPopupMenu(evt); } // Opens the send message dialog when a message is double clicked. // If the root message or source connector is selected, select all destination connectors initially // If a destination connector is selected, select only that destination connector initially public void mouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() >= 2) { int row = getSelectedMessageIndex(); if (row >= 0) { MessageBrowserTableNode messageNode = (MessageBrowserTableNode) messageTreeTable .getPathForRow(row).getLastPathComponent(); if (messageNode.isNodeActive()) { Long messageId = messageNode.getMessageId(); Integer metaDataId = messageNode.getMetaDataId(); Message currentMessage = messageCache.get(messageId); ConnectorMessage connectorMessage = currentMessage.getConnectorMessages() .get(metaDataId); List<Integer> selectedMetaDataIds = new ArrayList<Integer>(); Map<String, Object> sourceMap = new HashMap<String, Object>(); if (connectorMessage.getSourceMap() != null) { sourceMap.putAll(connectorMessage.getSourceMap()); // Remove the destination set if it exists, because that will be determined by the selected metadata IDs sourceMap.remove("destinationSet"); } if (metaDataId == 0) { selectedMetaDataIds = null; } else { selectedMetaDataIds.add(metaDataId); } if (connectorMessage.getRaw() != null) { parent.editMessageDialog.setPropertiesAndShow( connectorMessage.getRaw().getContent(), connectorMessage.getRaw().getDataType(), channelId, parent.dashboardPanel.getDestinationConnectorNames(channelId), selectedMetaDataIds, sourceMap); } } } } } }); // Key Listener trigger for DEL messageTreeTable.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int row = getSelectedMessageIndex(); if (row >= 0) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { MessageBrowserTableNode messageNode = (MessageBrowserTableNode) messageTreeTable .getPathForRow(row).getLastPathComponent(); if (messageNode.isNodeActive()) { parent.doRemoveMessage(); } } else if (descriptionTabbedPane.getTitleAt(descriptionTabbedPane.getSelectedIndex()) .equals("Messages")) { if (e.getKeyCode() == KeyEvent.VK_LEFT) { List<AbstractButton> buttons = Collections.list(messagesGroup.getElements()); boolean passedSelected = false; for (int i = buttons.size() - 1; i >= 0; i--) { AbstractButton button = buttons.get(i); if (passedSelected && button.isShowing()) { lastUserSelectedMessageType = buttons.get(i).getText(); updateMessageRadioGroup(); break; } else if (button.isSelected()) { passedSelected = true; } } } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { List<AbstractButton> buttons = Collections.list(messagesGroup.getElements()); boolean passedSelected = false; for (int i = 0; i < buttons.size(); i++) { AbstractButton button = buttons.get(i); if (passedSelected && button.isShowing()) { lastUserSelectedMessageType = buttons.get(i).getText(); updateMessageRadioGroup(); break; } else if (button.isSelected()) { passedSelected = true; } } } } } } }); }