List of usage examples for java.util.prefs Preferences userNodeForPackage
public static Preferences userNodeForPackage(Class<?> c)
From source file:edu.umd.cs.findbugs.gui2.GUISaveState.java
static void clear() { Preferences p = Preferences.userNodeForPackage(GUISaveState.class); try {// www. j a v a 2 s .c o m p.clear(); } catch (BackingStoreException e) { Debug.println(e); } instance = new GUISaveState(); }
From source file:org.docx4all.ui.menu.FileMenu.java
@Action public void newFile() { Preferences prefs = Preferences.userNodeForPackage(getClass()); WordMLEditor editor = WordMLEditor.getInstance(WordMLEditor.class); FileObject fo = null;/*w ww. j av a 2 s.c om*/ try { //Prepare the new file name StringBuffer newFile = new StringBuffer(); newFile.append(editor.getUntitledFileName()); newFile.append(++_untitledFileNumber); newFile.append(".docx"); //put new file in same directory as last opened local file's. //if there isn't last opened local file, put it in the //swing file chooser's default directory. String lastFile = prefs.get(Constants.LAST_OPENED_LOCAL_FILE, Constants.EMPTY_STRING); if (lastFile.length() == 0) { fo = VFSUtils.getFileSystemManager() .toFileObject(FileSystemView.getFileSystemView().getDefaultDirectory()); } else { fo = VFSUtils.getFileSystemManager().resolveFile(lastFile).getParent(); } fo = fo.resolveFile(newFile.toString()); } catch (FileSystemException exc) { exc.printStackTrace(); ResourceMap rm = editor.getContext().getResourceMap(getClass()); String title = rm.getString(FileMenu.NEW_FILE_ACTION_NAME + ".Action.text"); String message = rm.getString(FileMenu.NEW_FILE_ACTION_NAME + ".Action.errorMessage"); editor.showMessageDialog(title, message, JOptionPane.INFORMATION_MESSAGE); return; } editor.createInternalFrame(fo); }
From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java
private void initMetaDataSearchTable() { metaDataSearchTable.setModel(new DefaultTableModel(new Object[][] {}, new String[] { "Metadata", "Operator", "Value", "Ignore Case" }) { public boolean isCellEditable(int rowIndex, int columnIndex) { if (columnIndex == 3 && cachedMetaDataColumns.get(getValueAt(rowIndex, 0)) .getType() != MetaDataColumnType.STRING) { return false; }/*www .ja va2 s. c o m*/ return true; } @Override public void setValueAt(Object value, int row, int column) { int metaDataColumnIndex = findColumn("Metadata"); int operatorColumnIndex = findColumn("Operator"); int valueColumnIndex = findColumn("Value"); int ignoreCaseColumnIndex = findColumn("Ignore Case"); if (column == valueColumnIndex) { MetaDataColumn metaDataColumn = cachedMetaDataColumns.get(getValueAt(row, metaDataColumnIndex)); if (StringUtils.isNotEmpty((String) value)) { try { metaDataColumn.getType().castValue(value); } catch (MetaDataColumnException e) { parent.alertError(parent, "Invalid value for column type " + metaDataColumn.getType().toString()); return; } } } else if (column == metaDataColumnIndex) { if (!value.equals(getValueAt(row, metaDataColumnIndex))) { MetaDataSearchOperator operator = MetaDataSearchOperator.EQUAL; super.setValueAt(operator, row, operatorColumnIndex); MetaDataColumn metaDataColumn = cachedMetaDataColumns.get(value); if (metaDataColumn.getType() != MetaDataColumnType.STRING) { super.setValueAt(Boolean.FALSE, row, ignoreCaseColumnIndex); } } super.setValueAt("", row, valueColumnIndex); } super.setValueAt(value, row, column); } }); metaDataSearchTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); metaDataSearchTable.setDragEnabled(false); metaDataSearchTable.setSortable(false); metaDataSearchTable.getTableHeader().setReorderingAllowed(false); addMetaDataSearchButton.setEnabled(!messageBrowser.getMetaDataColumns().isEmpty()); metaDataSearchTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { deleteMetaDataSearchButton.setEnabled(getSelectedRow(metaDataSearchTable) != -1); } }); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { metaDataSearchTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } List<MetaDataColumn> metaDataColumns = messageBrowser.getMetaDataColumns(); cachedMetaDataColumns.clear(); String[] metaDataNames = new String[metaDataColumns.size()]; for (int i = 0; i < metaDataColumns.size(); i++) { String columnName = metaDataColumns.get(i).getName(); metaDataNames[i] = columnName; cachedMetaDataColumns.put(columnName, metaDataColumns.get(i)); } MirthComboBoxTableCellEditor metaDataEditor = new MirthComboBoxTableCellEditor(metaDataSearchTable, metaDataNames, 1, false, null); metaDataEditor.getComboBox().setAutoResizeDropdown(true); TableColumn metaDataColumn = metaDataSearchTable.getColumnModel().getColumn(0); metaDataColumn.setCellRenderer(new MirthComboBoxTableCellRenderer(metaDataNames)); metaDataColumn.setCellEditor(metaDataEditor); metaDataColumn.setMinWidth(METADATA_NAME_COLUMN_WIDTH); metaDataColumn.setMaxWidth(METADATA_NAME_COLUMN_WIDTH * 2); metaDataColumn.setPreferredWidth(METADATA_NAME_COLUMN_WIDTH); // Need to create this custom editor since the combo box values are dynamic based on metadata column type. MirthComboBoxTableCellEditor operatorEditor = new MirthComboBoxTableCellEditor(metaDataSearchTable, MetaDataSearchOperator.values(), 1, false, null) { public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { MetaDataColumn metaDataColumn = cachedMetaDataColumns.get(table.getValueAt(row, 0)); comboBox.setModel(new DefaultComboBoxModel( MetaDataSearchOperator.valuesForColumnType(metaDataColumn.getType()))); return super.getTableCellEditorComponent(table, value, isSelected, row, column); } }; TableColumn operatorColumn = metaDataSearchTable.getColumnModel().getColumn(1); operatorColumn.setCellRenderer(new MirthComboBoxTableCellRenderer(MetaDataSearchOperator.values())); operatorColumn.setCellEditor(operatorEditor); operatorColumn.setMinWidth(METADATA_OPERATOR_COLUMN_WIDTH); operatorColumn.setMaxWidth(METADATA_OPERATOR_COLUMN_WIDTH); TableColumn caseColumn = metaDataSearchTable.getColumnModel().getColumn(3); caseColumn.setMinWidth(METADATA_CASE_COLUMN_WIDTH); caseColumn.setMaxWidth(METADATA_CASE_COLUMN_WIDTH); deleteMetaDataSearchButton.setEnabled(false); }
From source file:com.mirth.connect.client.ui.editors.MapperPanel.java
public void setRegexProperties(ArrayList<String[]> properties) { Object[][] tableData = new Object[properties.size()][2]; regularExpressionsTable = new MirthTable(); for (int i = 0; i < properties.size(); i++) { tableData[i][REGEX_COLUMN] = properties.get(i)[0]; tableData[i][REPLACEWITH_COLUMN] = properties.get(i)[1]; }//from w w w. ja v a 2s. co m regularExpressionsTable.setModel(new javax.swing.table.DefaultTableModel(tableData, new String[] { REGEX_COLUMN_NAME, REPLACEWITH_COLUMN_NAME }) { boolean[] canEdit = new boolean[] { true, true }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); regularExpressionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (getSelectedRow() != -1) { lastIndex = getSelectedRow(); deleteButton.setEnabled(true); } else { deleteButton.setEnabled(false); } } }); class RegExTableCellEditor extends TextFieldCellEditor { @Override public boolean isCellEditable(EventObject evt) { boolean editable = super.isCellEditable(evt); if (editable) { deleteButton.setEnabled(false); } return editable; } @Override protected boolean valueChanged(String value) { parent.modified = true; deleteButton.setEnabled(true); return true; } } regularExpressionsTable.getColumnModel() .getColumn(regularExpressionsTable.getColumnModel().getColumnIndex(REGEX_COLUMN_NAME)) .setCellEditor(new RegExTableCellEditor()); regularExpressionsTable.getColumnModel() .getColumn(regularExpressionsTable.getColumnModel().getColumnIndex(REPLACEWITH_COLUMN_NAME)) .setCellEditor(new RegExTableCellEditor()); regularExpressionsTable.setCustomEditorControls(true); regularExpressionsTable.setSelectionMode(0); regularExpressionsTable.setRowSelectionAllowed(true); regularExpressionsTable.setRowHeight(UIConstants.ROW_HEIGHT); regularExpressionsTable.setDragEnabled(false); regularExpressionsTable.setOpaque(true); regularExpressionsTable.setSortable(false); regularExpressionsTable.getTableHeader().setReorderingAllowed(false); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR); regularExpressionsTable.setHighlighters(highlighter); } regularExpressionsScrollPane.setViewportView(regularExpressionsTable); }
From source file:de.ailis.oneinstance.OneInstance.java
/** * Returns the port which was last recorded as active. * /*w w w. j a v a2s .co m*/ * @param mainClass * The main class of the application. * @return The active port address or null if not found. */ private Integer getActivePort(Class<?> mainClass) { Preferences prefs = Preferences.userNodeForPackage(mainClass); int port = prefs.getInt(PORT_KEY, -1); return port >= MIN_PORT && port <= MAX_PORT ? port : null; }
From source file:net.chaosserver.timelord.swingui.Timelord.java
/** * Saves the current location of the applicatioFrame. *///from w w w. j a v a 2 s. c o m protected void saveFrameLocation() { if (applicationFrame != null) { Point frameLocation = applicationFrame.getLocation(); Preferences preferences = Preferences.userNodeForPackage(this.getClass()); preferences.putDouble(FRAME_X_LOCATION, frameLocation.getX()); preferences.putDouble(FRAME_Y_LOCATION, frameLocation.getY()); } }
From source file:com.mirth.connect.client.ui.DashboardPanel.java
public void switchPanel() { boolean groupViewEnabled = Preferences.userNodeForPackage(Mirth.class).getBoolean("channelGroupViewEnabled", true);//from w w w.j a va 2 s . c om switchTableMode(groupViewEnabled); if (groupViewEnabled) { tableModeGroupsButton.setSelected(true); tableModeGroupsButton.setContentFilled(true); tableModeChannelsButton.setContentFilled(false); } else { tableModeChannelsButton.setSelected(true); tableModeChannelsButton.setContentFilled(true); tableModeGroupsButton.setContentFilled(false); } }
From source file:com.tag.FramePreferences.java
private Preferences getPreferences() { Preferences prefs = Preferences.userNodeForPackage(getClass()); String pathName = getPathName(); return (pathName == null) ? prefs : prefs.node(pathName); }
From source file:verdandi.ui.ProjectViewerPanel.java
private void importProjects() { Preferences prefs = Preferences.userNodeForPackage(getClass()); File importDir = new File(prefs.get("import.dir", System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(importDir); chooser.setDialogTitle(RB.getString("projectviewer.import.filechooser.title")); chooser.setMultiSelectionEnabled(false); if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) { LOG.debug("User cancelled"); return;// ww w.jav a 2 s . c o m } File importFile = chooser.getSelectedFile(); prefs.put("import.dir", importFile.getParent()); try { prefs.flush(); } catch (BackingStoreException e) { LOG.error("Cannot write export file preference", e); } ObjectInputStream projectsIn = null; try { setCursor(CURSOR_WAIT); projectsIn = new ObjectInputStream(new FileInputStream(importFile)); Object o = projectsIn.readObject(); if (!(o instanceof Collection)) { LOG.error("The file does not contain a valid verdandi project list"); return; } Collection<?> importcoll = (Collection<?>) o; @SuppressWarnings("unchecked") List<CostUnit> projects = (List<CostUnit>) o; new ProjectImporter(projects).start(); } catch (FileNotFoundException e) { LOG.error("", e); } catch (IOException e) { LOG.error("No verdandi project list?", e); } catch (ClassNotFoundException e) { LOG.error("", e); } finally { setCursor(CURSOR_DEFAULT); if (projectsIn != null) { try { projectsIn.close(); } catch (Throwable t) { LOG.error("Cannot close stream: ", t); } } } }
From source file:com.jidesoft.spring.richclient.docking.JideApplicationLifecycleAdvisor.java
@Override public void onWindowOpened(ApplicationWindow arg0) { super.onWindowOpened(arg0); if (PreferenceRegistry.instance().getPreferenceValue("general.tipOfTheDay").equals("yes")) { GraphicUtils.showTipOfTheDay();/*from w w w . j av a 2 s . c o m*/ } // automatic version checking // get preference String pval = PreferenceRegistry.instance().getPreferenceValue("updates.autoCheckForNewVersion"); if (pval == null || pval.equals("")) { // if preference is null, ask user if they want to activate version // checking //TODO:I18N final MessageDialog dlg = new MessageDialog("Automatic version check", "As of version 1.0.4 JOverseer comes with a mechanism to automatically check for new versions on the web site.\r\n Note that if you choose yes, JOverseer will try to connect to the internet every time upon start-up to check for a new version.\n Do you wish to activate this check?") { @Override protected Object[] getCommandGroupMembers() { return new Object[] { new ActionCommand("actionYes") { @Override protected void doExecuteCommand() { PreferenceRegistry.instance().setPreferenceValue("updates.autoCheckForNewVersion", "yes"); getDialog().dispose(); } }, new ActionCommand("actionNo") { @Override protected void doExecuteCommand() { PreferenceRegistry.instance().setPreferenceValue("updates.autoCheckForNewVersion", "no"); getDialog().dispose(); } } }; } }; dlg.showDialog(); } // get preference value and do version checking if needed pval = PreferenceRegistry.instance().getPreferenceValue("updates.autoCheckForNewVersion"); if (pval.equals("yes")) { // check once every week Preferences prefs = Preferences.userNodeForPackage(JOverseerJIDEClient.class); pval = prefs.get("lastVersionCheckDate", null); Date dt = null; try { dt = new SimpleDateFormat().parse(pval); } catch (Exception exc) { // do nothing } Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.DATE, -7); Date dateMinusOneWeek = c.getTime(); if (dt == null || dateMinusOneWeek.after(dt)) { DefaultApplicationDescriptor descriptor = (DefaultApplicationDescriptor) Application.instance() .getApplicationContext().getBean("applicationDescriptor"); ThreepartVersion current = new ThreepartVersion(descriptor.getVersion()); try { if (UpdateChecker .getLatestVersion(PreferenceRegistry.instance().getPreferenceValue("updates.RSSFeed")) .isLaterThan(current)) { new com.middleearthgames.updater.UpdateInfo(UpdateChecker .getWhatsNew(PreferenceRegistry.instance().getPreferenceValue("updates.RSSFeed"))); } String str = new SimpleDateFormat().format(new Date()); prefs.put("lastVersionCheckDate", str); } catch (Exception exc) { // do nothing } } } }