private void savePreferredSizes(Component comp, PersistedPreferences prefs, int[] counter) throws BackingStoreException { if (comp instanceof JScrollPane) { counter[0]++; prefs.putInt("height_" + counter[0] , comp.getHeight()); // NOI18N prefs.putInt("width_" + counter[0], comp.getWidth()); // NOI18N prefs.flush(); } else if (comp instanceof Container) { for (Component component : ((Container) comp).getComponents()) { // go down the component tree recursively for standard elements savePreferredSizes(component, prefs, counter); } } }
/** * Gets the value for a key. * Userspace overwrites systemspace. * * @param key the preferences key * @return the value string or null if no such value */ public String getString(String key) { String val = null; if (!systemOnly) { val = getUserPrefs().get(key, null); } if (val == null) { val = getSystemPrefs().get(key, null); } return val; }
/** * Loads the preferences of a component.<br> * Use it whenever there is no table in it (FormTable provide setting too) * or some other scrolling regions need to be preset. * The method scans for all scrolling regions contained in component * and sets their preferred-sizes. * * @param comp is the component (usually a panel, srolling area or window) * @param prefName is the preferences name * @param system is true if load from system-preferences, else try userprefs first */ public void loadPreferredSizes(Component comp, String prefName, boolean system) { int[] counter = new int[] { 0 }; try { PersistedPreferences sysPrefs = PersistedPreferences.systemRoot().node(prefName); PersistedPreferences userPrefs = system ? null : PersistedPreferences.userRoot().node(prefName); loadPreferredSizes(comp, sysPrefs, userPrefs, counter); } catch (BackingStoreException | RuntimeException ex) { FormError.showException(SwingSwingBundle.getString("PREFERENCES COULD NOT BE LOADED"), ex); } }
PersistedPreferences.systemRoot().node(prefName.toString()) : PersistedPreferences.userRoot().node(prefName.toString()); TableColumnConfiguration<S, ?> columnConfig = getColumnConfiguration(column); if (columnConfig != null) { PersistedPreferences columnPrefs = prefs.node(columnConfig.getName()); columnPrefs.putInt(PREF_COLUMN_VISIBILITY, column.isVisible() ? 1 : 0); columnPrefs.putDouble(PREF_WIDTH, column.getWidth()); columnPrefs.putInt(PREF_COLUMN_INDEX, viewIndex); int sortIndex = sortOrder.indexOf(column); if (isSortingIncluded() && sortIndex >= 0) { columnPrefs.putInt(PREF_COLUMN_SORT_TYPE, column.getSortType().ordinal()); columnPrefs.putInt(PREF_COLUMN_SORT_INDEX, sortIndex); columnPrefs.remove(PREF_COLUMN_SORT_TYPE); columnPrefs.remove(PREF_COLUMN_SORT_INDEX); prefs.putDouble(PREF_TABLE_HEIGHT, height); prefs.putDouble(PREF_WIDTH, table.getWidth()); prefs.flush();
PersistedPreferences.systemRoot().node(prefName) : PersistedPreferences.userRoot().node(prefName); TableColumnModel cm = getColumnModel(); TableColumn tc = ocols.nextElement(); String columnIdentifier = createColumnIdentifier(tc); prefs.putInt(PREF_COLUMN_WIDTH + columnIdentifier, tc.getPreferredWidth()); prefs.putInt(PREF_COLUMN_INDEX + columnIdentifier, viewIndex); prefs.putInt(PREF_COLUMN_VISIBILITY + columnIdentifier, fcm.isOriginalColumnVisible(viewIndex) ? 1 : 0); // not bool, cause of default is unknown viewIndex++; TableColumn tc = cols.nextElement(); String columnIdentifier = createColumnIdentifier(tc); prefs.putInt(PREF_COLUMN_WIDTH + columnIdentifier, tc.getPreferredWidth()); prefs.putInt(PREF_COLUMN_INDEX + columnIdentifier, viewIndex); viewIndex++; if (p instanceof JScrollPane) { prefs.putInt(PREF_TABLE_HEIGHT, p.getHeight()); prefs.putInt(PREF_TABLE_WIDTH, p.getWidth()); prefs.putInt(PREF_TABLE_HEIGHT, -1); // makes no sense if not in a viewport prefs.putInt(PREF_TABLE_WIDTH, getWidth()); // store just for documentation prefs.flush();
PersistedPreferences systemPref = PersistedPreferences.systemRoot().node(prefName.toString()); PersistedPreferences userPref = system ? null : PersistedPreferences.userRoot().node(prefName.toString()); for (String columnName : systemPref.childrenNames()) { columnMapByName.put(columnName, systemPref.node(columnName)); for (String columnName : userPref.childrenNames()) { columnMapByName.put(columnName, userPref.node(columnName)); if (column != null) { PersistedPreferences columnPref = entry.getValue(); int visibility = columnPref.getInt(PREF_COLUMN_VISIBILITY, -1); column.setVisible(visibility != 0); double width = columnPref.getDouble(PREF_WIDTH, -1.0); if (width >= 0.0) { table.resizeColumn(column, width - column.getWidth()); int index = columnPref.getInt(PREF_COLUMN_INDEX, -1); if (index >= 0) { columnMapByIndex.put(index, column); if (isSortingIncluded()) { int sorting = columnPref.getInt(PREF_COLUMN_SORT_TYPE, -1); if (sorting >= 0) { column.setSortType(TableColumn.SortType.values()[sorting]); int sortIndex = columnPref.getInt(PREF_COLUMN_SORT_INDEX, -1); if (sortIndex == -1) { sortIndex = Integer.MAX_VALUE - sortOrder.size(); String key = PREF_WIDTH;
PersistedPreferences systemPref = PersistedPreferences.systemRoot().node(prefName); PersistedPreferences userPref = systemOnly ? null : PersistedPreferences.userRoot().node(prefName); String key = PREF_TABLE_WIDTH; if (!systemOnly) { width = userPref.getInt(key, width); width = systemPref.getInt(key, width); key = PREF_TABLE_HEIGHT; if (!systemOnly) { height = userPref.getInt(key, height); height = systemPref.getInt(key, height); width = userPref.getInt(key, width); width = systemPref.getInt(key, width); index = userPref.getInt(key, index); index = systemPref.getInt(key, index); int visible = -1; // unknown if (!systemOnly) { visible = userPref.getInt(key, visible); visible = systemPref.getInt(key, visible);
/** * Sets the value for a key.<br> * If the value is the same as in systemspace, the user value is removed. * Null-values also perform a remove. * * @param key the preferences key * @param val the value */ public void setString(String key, String val) { if (!systemOnly) { if (val == null || Objects.equals(val, getSystemPrefs().get(key, null))) { getUserPrefs().remove(key); } else { getUserPrefs().put(key, val); } } else { if (val == null) { getSystemPrefs().remove(key); } else { getSystemPrefs().put(key, val); } } }
/** * Sets a bytearray.<br> * If the value is the same as in systemspace, the user value is removed. * Null-values also perform a remove. * * @param key the preferences key * @param val the values */ public void setByteArray(String key, byte[] val) { if (!systemOnly) { if (val == null || areByteArraysEqual(val, getSystemPrefs().getByteArray(key, null))) { getUserPrefs().remove(key); } else { getUserPrefs().putByteArray(key, val); } } else { if (val == null) { getSystemPrefs().remove(key); } else { getSystemPrefs().putByteArray(key, val); } } }
/** * Saves the preferences of a component.<br> * Use it whenever there is no table in it (FormTable provide setting too) * or some other scrolling regions need to be preset. * The method scans for all scrolling regions contained in component * and stores their sizes. * * @param comp is the component (usually a panel, srolling area or window) * @param prefName is the preferences name * @param system is true if store to system-preferences, else store in userprefs */ public void savePreferredSizes(Component comp, String prefName, boolean system) { int[] counter = new int[] { 0 }; try { PersistedPreferences prefs = system ? PersistedPreferences.systemRoot().node(prefName) : PersistedPreferences.userRoot().node(prefName); savePreferredSizes(comp, prefs, counter); } catch (BackingStoreException | RuntimeException ex) { FormError.showException(SwingSwingBundle.getString("PREFERENCES COULD NOT BE SAVED"), ex); } }