List of usage examples for java.util.prefs Preferences userNodeForPackage
public static Preferences userNodeForPackage(Class<?> c)
From source file:kindleclippings.quizlet.QuizletSync.java
public static void clearPrefs() throws BackingStoreException { Preferences prefs = Preferences.userNodeForPackage(QuizletSync.class); prefs.clear();/* w w w .j ava2 s. c o m*/ prefs.flush(); }
From source file:eu.delving.sip.Application.java
private Application(final File storageDir) throws StorageException { GroovyCodeResource groovyCodeResource = new GroovyCodeResource(getClass().getClassLoader()); final ImageIcon backgroundIcon = new ImageIcon(getClass().getResource("/delving-background.png")); desktop = new JDesktopPane() { public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(backgroundIcon.getImage(), 0, 0, desktop); }//from www .j a va 2 s.c om }; desktop.setMinimumSize(new Dimension(MINIMUM_DESKTOP_SIZE)); resizeTimer = new Timer(DEFAULT_RESIZE_INTERVAL, new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { resizeTimer.stop(); for (JInternalFrame frame : desktop.getAllFrames()) { if (frame instanceof FrameBase) { ((FrameBase) frame).ensureOnScreen(); } } } }); desktop.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent componentEvent) { resizeTimer.restart(); } }); Preferences preferences = Preferences.userNodeForPackage(SipModel.class); feedback = new VisualFeedback(home, desktop, preferences); HttpClient httpClient = createHttpClient(storageDir); SchemaRepository schemaRepository; try { schemaRepository = new SchemaRepository(new SchemaFetcher(httpClient)); } catch (IOException e) { throw new StorageException("Unable to create Schema Repository", e); } ResolverContext context = new ResolverContext(); Storage storage = new StorageImpl(storageDir, schemaRepository, new CachedResourceResolver(context)); context.setStorage(storage); context.setHttpClient(httpClient); sipModel = new SipModel(desktop, storage, groovyCodeResource, feedback, preferences); CultureHubClient cultureHubClient = isStandalone(storageDir) ? null : new CultureHubClient(sipModel, httpClient); if (cultureHubClient != null) uploadAction = new UploadAction(sipModel, cultureHubClient); expertMenu = new ExpertMenu(desktop, sipModel, cultureHubClient, allFrames); statusPanel = new StatusPanel(sipModel); home = new JFrame(titleString()); home.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent componentEvent) { allFrames.getViewSelector().refreshView(); } }); JPanel content = (JPanel) home.getContentPane(); content.setFocusable(true); FrameBase dataSetFrame = cultureHubClient != null ? new DataSetHubFrame(sipModel, cultureHubClient) : new DataSetStandaloneFrame(sipModel, schemaRepository); LogFrame logFrame = new LogFrame(sipModel); feedback.setLog(logFrame.getLog()); allFrames = new AllFrames(sipModel, content, dataSetFrame, logFrame); desktop.setBackground(new Color(190, 190, 200)); content.add(desktop, BorderLayout.CENTER); sipModel.getMappingModel().addChangeListener(new MappingModel.ChangeListener() { @Override public void lockChanged(MappingModel mappingModel, final boolean locked) { sipModel.exec(new Swing() { @Override public void run() { unlockMappingAction.setEnabled(locked); } }); } @Override public void functionChanged(MappingModel mappingModel, MappingFunction function) { } @Override public void nodeMappingChanged(MappingModel mappingModel, RecDefNode node, NodeMapping nodeMapping, NodeMappingChange change) { } @Override public void nodeMappingAdded(MappingModel mappingModel, RecDefNode node, NodeMapping nodeMapping) { } @Override public void nodeMappingRemoved(MappingModel mappingModel, RecDefNode node, NodeMapping nodeMapping) { } @Override public void populationChanged(MappingModel mappingModel, RecDefNode node) { } }); importAction = new ImportAction(desktop, sipModel); attachAccelerator(importAction, home); validateAction = new ValidateAction(sipModel, allFrames.prepareForInvestigation(desktop)); unlockMappingAction = new UnlockMappingAction(sipModel); attachAccelerator(unlockMappingAction, home); selectAnotherMappingAction = new SelectAnotherMappingAction(sipModel); attachAccelerator(selectAnotherMappingAction, home); content.add(createStatePanel(), BorderLayout.SOUTH); content.add(allFrames.getSidePanel(), BorderLayout.WEST); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); screen.height -= 30; home.setSize(screen); home.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); ImageIcon logo = new ImageIcon(getClass().getResource("/sip-creator-logo.png")); home.setIconImage(logo.getImage()); home.setJMenuBar(createMenuBar()); home.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent windowEvent) { quit(); } }); home.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); sipModel.getDataSetModel().addListener(new DataSetModel.SwingListener() { @Override public void stateChanged(DataSetModel model, DataSetState state) { statusPanel.setState(state); switch (state) { case ABSENT: sipModel.exec(new Work() { @Override public void run() { sipModel.getDataSetFacts().set(null); sipModel.getStatsModel().setStatistics(null); } @Override public Job getJob() { return Job.CLEAR_FACTS_STATS; } }); home.setTitle(titleString()); sipModel.seekReset(); break; default: DataSetModel dataSetModel = sipModel.getDataSetModel(); home.setTitle(String.format(titleString() + " - [%s -> %s]", dataSetModel.getDataSet().getSpec(), dataSetModel.getPrefix().toUpperCase())); sipModel.getReportFileModel().refresh(); break; } } }); attachAccelerator(new QuitAction(), home); attachAccelerator(statusPanel.getButtonAction(), home); }
From source file:au.org.ala.delta.editor.EditorPreferences.java
public static Font getPreferredFont() { Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class); if (prefs != null) { String font = prefs.get(FONT_KEY, null); if (font != null) { return Font.decode(font); }//from ww w .j a v a 2 s .com } return null; }
From source file:com.mirth.connect.client.ui.EditMessageDialog.java
private void initSourceMapTable(Map<String, Object> sourceMap) { Object[][] data = new Object[sourceMap.size()][2]; int i = 0;/* ww w .j av a 2 s .c o m*/ for (Entry<String, Object> entry : sourceMap.entrySet()) { data[i][0] = entry.getKey(); data[i][1] = entry.getValue(); i++; } sourceMapTable = new MirthTable(); sourceMapTable.setModel(new RefreshTableModel(data, new Object[] { "Variable", "Value" }) { @Override public boolean isCellEditable(int row, int column) { return true; } }); sourceMapTable.setDragEnabled(false); sourceMapTable.setRowSelectionAllowed(true); sourceMapTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); sourceMapTable.setRowHeight(UIConstants.ROW_HEIGHT); sourceMapTable.setFocusable(false); sourceMapTable.setOpaque(true); sourceMapTable.getTableHeader().setResizingAllowed(false); sourceMapTable.getTableHeader().setReorderingAllowed(false); sourceMapTable.setSortable(true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { sourceMapTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } sourceMapTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { deleteButton.setEnabled(sourceMapTable.getSelectedRow() > -1); } } }); class SourceMapTableCellEditor extends AbstractCellEditor implements TableCellEditor { private JTable table; private int column; private JTextField textField; private Object originalValue; private String newValue; public SourceMapTableCellEditor(JTable table, int column) { super(); this.table = table; this.column = column; textField = new JTextField(); textField.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { textField.setCaretPosition(textField.getText().length()); } }); } @Override public boolean isCellEditable(EventObject evt) { if (evt == null) { return false; } if (evt instanceof MouseEvent) { return ((MouseEvent) evt).getClickCount() >= 2; } return true; } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { originalValue = value; newValue = null; textField.setText(String.valueOf(value)); return textField; } @Override public Object getCellEditorValue() { if (newValue != null) { return newValue; } else { return originalValue; } } @Override public boolean stopCellEditing() { if (!valueChanged()) { super.cancelCellEditing(); } else { newValue = textField.getText(); } return super.stopCellEditing(); } private boolean valueChanged() { String value = textField.getText(); if (StringUtils.isBlank(value)) { return false; } for (int i = 0; i < table.getRowCount(); i++) { Object tableValue = table.getValueAt(i, column); if (tableValue != null && String.valueOf(tableValue).equals(value)) { return false; } } return true; } } sourceMapTable.getColumnModel().getColumn(0).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 0)); sourceMapTable.getColumnModel().getColumn(1).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 1)); sourceMapScrollPane.setViewportView(sourceMapTable); deleteButton.setEnabled(false); }
From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java
private void initContentSearchTable() { contentSearchTable/* w w w . jav a 2 s .co m*/ .setModel(new DefaultTableModel(new Object[][] {}, new String[] { "Content Type", "Contains" }) { public boolean isCellEditable(int rowIndex, int columnIndex) { return true; } }); contentSearchTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); contentSearchTable.setDragEnabled(false); contentSearchTable.setSortable(false); contentSearchTable.getTableHeader().setReorderingAllowed(false); contentSearchTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { deleteContentSearchButton.setEnabled(getSelectedRow(contentSearchTable) != -1); } }); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { contentSearchTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } TableColumn column = contentSearchTable.getColumnModel().getColumn(0); column.setCellRenderer(new MirthComboBoxTableCellRenderer(ContentType.getDisplayValues())); column.setCellEditor(new MirthComboBoxTableCellEditor(contentSearchTable, ContentType.getDisplayValues(), 1, false, null)); column.setMinWidth(CONTENT_TYPE_COLUMN_WIDTH); column.setMaxWidth(CONTENT_TYPE_COLUMN_WIDTH); deleteContentSearchButton.setEnabled(false); }
From source file:com.mirth.connect.client.ui.attachments.RegexAttachmentDialog.java
private void initInboundReplacementTable() { inboundReplacementTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); DefaultTableModel model = new DefaultTableModel(new Object[][] {}, new String[] { "Replace All", "Replace With" }) { public boolean isCellEditable(int rowIndex, int columnIndex) { return true; }/*from ww w. j a v a 2s . co m*/ }; inboundReplacementTable.setSortable(false); inboundReplacementTable.getTableHeader().setReorderingAllowed(false); inboundReplacementTable.setModel(model); inboundReplacementTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { inboundDeleteButton.setEnabled(inboundReplacementTable.getSelectedRow() != -1); } }); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { inboundReplacementTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } inboundDeleteButton.setEnabled(false); }
From source file:jviewmda.JViewMda.java
@Override public void start(Stage primaryStage) { m_stage = primaryStage;//from w w w.j a va 2 s. co m String array_path = ""; Parameters params = getParameters(); List<String> unnamed_params = params.getUnnamed(); if (unnamed_params.size() > 0) { array_path = unnamed_params.get(0); } // FOR DEBUGING PURPOSES if (array_path.length() == 0) { //String debug_path = "/home/magland/wisdm/www/wisdmfileserver/files/fetalmri/sessions/SESSION1/crops/FNP001A-coronal.crop.mda"; String debug_path = "/home/magland/data/LesionProbe/Images/ID001_FLAIR.nii"; if ((new File(debug_path)).exists()) { array_path = debug_path; } } Menu menu; MenuItem item; MenuBar menubar = new MenuBar(); //file menu menu = new Menu("File"); menubar.getMenus().add(menu); item = new MenuItem("Open..."); item.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN)); item.setOnAction(e -> on_file_open()); menu.getItems().add(item); item = new MenuItem("Save As..."); item.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN)); item.setOnAction(e -> on_file_saveas()); menu.getItems().add(item); menu.getItems().add(new SeparatorMenuItem()); ///////////////////////////////////////////// item = new MenuItem("Exit"); item.setAccelerator(new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN)); item.setOnAction(e -> on_file_exit()); menu.getItems().add(item); //view menu menu = new Menu("View"); menubar.getMenus().add(menu); item = new MenuItem("Zoom In"); item.setAccelerator(new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN)); item.setOnAction(e -> on_zoom_in()); menu.getItems().add(item); item = new MenuItem("Zoom Out"); item.setAccelerator( new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN)); item.setOnAction(e -> on_zoom_out()); menu.getItems().add(item); menu.getItems().add(new SeparatorMenuItem()); ///////////////////////////////////////////// { CheckMenuItem item0 = new CheckMenuItem("Top Controls"); item0.setSelected(true); item0.setOnAction(e -> { m_widget.setTopControlsVisible(item0.isSelected()); }); menu.getItems().add(item0); } { CheckMenuItem item0 = new CheckMenuItem("Bottom Controls"); item0.setSelected(true); item0.setOnAction(e -> { m_widget.setBottomControlsVisible(item0.isSelected()); }); menu.getItems().add(item0); } { CheckMenuItem item0 = new CheckMenuItem("Brightness/Contrast"); item0.setSelected(true); item0.setOnAction(e -> { m_widget.setBrightnessContrastVisible(item0.isSelected()); }); menu.getItems().add(item0); } { CheckMenuItem item0 = new CheckMenuItem("Slice Slider"); item0.setSelected(true); item0.setOnAction(e -> { m_widget.setSliceSliderVisible(item0.isSelected()); }); menu.getItems().add(item0); } //selection menu menu = new Menu("Selection"); menubar.getMenus().add(menu); Map<String, CheckMenuItem> mode_items = new HashMap<>(); m_selection_mode_items = mode_items; mode_items.put("rectangle", new CheckMenuItem("Rectangle")); mode_items.put("ellipse", new CheckMenuItem("Ellipse")); Set<String> keys = mode_items.keySet(); for (String key : keys) { CheckMenuItem item0 = mode_items.get(key); menu.getItems().add(item0); item0.setOnAction(evt -> { on_selection_mode_changed(key); }); } mode_items.get("rectangle").setSelected(true); VBox root = new VBox(); root.getChildren().addAll(menubar, m_widget); Scene scene = new Scene(root, 500, 450); primaryStage.setTitle("JViewMda"); primaryStage.setScene(scene); primaryStage.show(); if (array_path.length() > 0) { open_file(array_path); } m_prefs = Preferences.userNodeForPackage(this.getClass()); }
From source file:org.broad.igv.DirectoryManager.java
private static File getIgvDirectoryOverride() { Preferences userPrefs = null; File override = null;//from ww w. j ava 2s. c om try { // See if an override location has been specified. This is stored with the Java Preferences API userPrefs = Preferences.userNodeForPackage(Globals.class); String userDir = userPrefs.get(IGV_DIR_USERPREF, null); if (userDir != null) { override = new File(userDir); if (!override.exists()) { override = null; userPrefs.remove(IGV_DIR_USERPREF); } } } catch (Exception e) { userPrefs.remove(IGV_DIR_USERPREF); override = null; System.err.println("Error creating user directory"); e.printStackTrace(); } return override; }
From source file:au.org.ala.delta.editor.EditorPreferences.java
public static void setPreferredFont(Font font) { Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class); if (prefs != null) { prefs.put(FONT_KEY, font.getFontName() + "-" + font.getStyle() + "-" + font.getSize()); }/*from w w w. ja v a2 s. co m*/ }
From source file:de.dal33t.powerfolder.PowerFolder.java
/** * Starts a PowerFolder controller with the given command line arguments * * @param args//from w w w.j a v a2 s . com */ public static void startPowerFolder(String[] args) { // Touch Logger immediately to initialize handlers. LoggingManager.isLogToFile(); // Default exception logger Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { e.printStackTrace(); log.log(Level.SEVERE, "Exception in " + t + ": " + e.toString(), e); } }); CommandLine commandLine = parseCommandLine(args); if (commandLine == null) { return; } // -l --log console log levels (severe, warning, info, fine and finer). if (commandLine.hasOption("l")) { String levelName = commandLine.getOptionValue("l"); Level level = LoggingManager.levelForName(levelName); if (level != null) { LoggingManager.setConsoleLogging(level); } } if (commandLine.hasOption("s")) { // Server mode, suppress debug output on console // Logger.addExcludeConsoleLogLevel(Logger.DEBUG); } if (commandLine.hasOption("h")) { // Show help HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("PowerFolder", COMMAND_LINE_OPTIONS); return; } int rconPort = Integer.valueOf(ConfigurationEntry.NET_RCON_PORT.getDefaultValue()); String portStr = commandLine.getOptionValue("k"); if (StringUtils.isNotBlank(portStr)) { try { rconPort = Integer.valueOf(portStr.trim()); } catch (Exception e) { log.warning("Unable to parse rcon port: " + portStr + ". " + e); } } boolean runningInstanceFound = RemoteCommandManager.hasRunningInstance(rconPort); if (commandLine.hasOption("k")) { if (runningInstanceFound) { System.out.println("Stopping " + NAME); // Send quit command RemoteCommandManager.sendCommand(rconPort, RemoteCommandManager.QUIT); } else { System.err.println("Process not running"); } // stop return; } // set language from commandline to preferences if (commandLine.hasOption("g")) { Preferences.userNodeForPackage(Translation.class).put("locale", commandLine.getOptionValue("g")); } if (JavaVersion.systemVersion().isOpenJDK()) { Object[] options = { "Open Oracle home page and exit", "Exit" }; int n = JOptionPane.showOptionDialog(null, "You are using OpenJDK which is unsupported.\n" + "Please install the client with bundled JRE or install the Oracle JRE", "Unsupported JRE", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); if (n == 0) { try { BrowserLauncher.openURL("http://www.java.com"); } catch (IOException e1) { e1.printStackTrace(); } } return; } // The controller. Controller controller = Controller.createController(); String[] files = commandLine.getArgs(); // Parsing of command line completed boolean commandContainsRemoteCommands = files != null && files.length >= 1 || commandLine.hasOption("e") || commandLine.hasOption("r") || commandLine.hasOption("a"); // Try to start controller boolean startController = !commandContainsRemoteCommands || !runningInstanceFound; try { log.info("PowerFolder v" + Controller.PROGRAM_VERSION); // Start controller if (startController) { controller.startConfig(commandLine); } // Send remote command if there a files in commandline if (files != null && files.length > 0) { // Parse filenames and build remote command StringBuilder openFilesRCommand = new StringBuilder(RemoteCommandManager.OPEN); for (String file : files) { openFilesRCommand.append(file); // FIXME: Add ; separator ? } // Send remote command to running PowerFolder instance RemoteCommandManager.sendCommand(openFilesRCommand.toString()); } if (commandLine.hasOption("e")) { RemoteCommandManager.sendCommand(RemoteCommandManager.MAKEFOLDER + commandLine.getOptionValue("e")); } if (commandLine.hasOption("r")) { RemoteCommandManager .sendCommand(RemoteCommandManager.REMOVEFOLDER + commandLine.getOptionValue("r")); } if (commandLine.hasOption("a")) { RemoteCommandManager.sendCommand(RemoteCommandManager.COPYLINK + commandLine.getOptionValue("a")); } } catch (Throwable t) { t.printStackTrace(); log.log(Level.SEVERE, "Throwable", t); return; } // Begin monitoring memory usage. if (controller.isStarted() && controller.isUIEnabled()) { ScheduledExecutorService service = controller.getThreadPool(); service.scheduleAtFixedRate(new MemoryMonitor(controller), 1, 1, TimeUnit.MINUTES); } // Not go into console mode if ui is open if (!startController) { if (runningInstanceFound) { RemoteCommandManager.sendCommand(RemoteCommandManager.SHOW_UI); } return; } System.out.println("------------ " + NAME + " " + Controller.PROGRAM_VERSION + " started ------------"); boolean restartRequested = false; do { // Go into restart loop while (controller.isStarted() || controller.isShuttingDown()) { try { Thread.sleep(500); } catch (InterruptedException e) { log.log(Level.WARNING, "InterruptedException", e); return; } } restartRequested = controller.isRestartRequested(); if (restartRequested) { Map<Thread, StackTraceElement[]> threads = Thread.getAllStackTraces(); for (Thread thread : threads.keySet()) { if (thread.getName().startsWith("PoolThread") || thread.getName().startsWith("Reconnector") || thread.getName().startsWith("ConHandler")) { thread.interrupt(); } } log.info("Restarting controller"); System.out.println( "------------ " + NAME + " " + Controller.PROGRAM_VERSION + " restarting ------------"); controller = null; System.gc(); controller = Controller.createController(); // Start controller controller.startConfig(commandLine); } } while (restartRequested); }