use of java.util.prefs.Preferences in project jgnash by ccavanaugh.
the class AttachmentPanel method attachmentAction.
private void attachmentAction() {
final Preferences pref = Preferences.userNodeForPackage(AbstractBankTransactionPanel.class);
final String baseFile = EngineFactory.getActiveDatabase();
final String[] fileSuffixes = ImageIO.getReaderFileSuffixes();
StringBuilder description = new StringBuilder(rb.getString("Title.ImageFiles")).append(" (");
for (int i = 0; i < fileSuffixes.length; i++) {
description.append("*.");
description.append(fileSuffixes[i]);
if (i < fileSuffixes.length - 1) {
description.append(", ");
}
}
description.append(")");
FileFilter fileFilter = new FileNameExtensionFilter(description.toString(), fileSuffixes);
final JFileChooser chooser = new JFileChooser(pref.get(LAST_DIR, null));
chooser.addChoosableFileFilter(fileFilter);
chooser.setFileFilter(fileFilter);
chooser.setMultiSelectionEnabled(false);
chooser.setAcceptAllFileFilterUsed(false);
if (attachment != null) {
chooser.setSelectedFile(attachment.toFile());
}
if (chooser.showOpenDialog(UIApplication.getFrame()) == JFileChooser.APPROVE_OPTION) {
pref.put(LAST_DIR, chooser.getCurrentDirectory().getAbsolutePath());
File selectedFile = chooser.getSelectedFile();
if (selectedFile != null) {
boolean result = true;
final Path attachmentDirectory = AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile));
if (baseFile.startsWith(EngineFactory.REMOTE_PREFIX)) {
// working remotely
moveAttachment = true;
} else if (attachmentDirectory != null && !attachmentDirectory.toString().equals(selectedFile.getParent())) {
String message = ResourceUtils.getString("Message.Warn.MoveFile", selectedFile.toString(), attachmentDirectory.toString());
result = YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new JLabel(message), rb.getString("Title.MoveFile"));
if (result) {
moveAttachment = true;
Path newPath = Paths.get(AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile)) + FileUtils.separator + selectedFile.getName());
if (newPath.toFile().exists()) {
message = ResourceUtils.getString("Message.Warn.SameFile", selectedFile.toString(), attachmentDirectory.toString());
StaticUIMethods.displayWarning(message);
moveAttachment = false;
result = false;
}
}
}
if (result) {
attachment = selectedFile.toPath();
}
}
}
}
use of java.util.prefs.Preferences in project jgnash by ccavanaugh.
the class RegisterFactory method setOddColor.
public static void setOddColor(final Color color) {
Preferences p = Preferences.userNodeForPackage(RegisterFactory.class);
p.putInt(ODD_COLOR, color.getRGB());
oddBackgroundColor = color;
}
use of java.util.prefs.Preferences in project jgnash by ccavanaugh.
the class RegisterFactory method setConfirmTransactionDeleteEnabled.
/**
* Sets if confirm on transaction delete is enabled.
*
* @param enabled true if deletion confirmation is required
*/
public static void setConfirmTransactionDeleteEnabled(final boolean enabled) {
confirmTransactionDelete = enabled;
Preferences p = Preferences.userNodeForPackage(RegisterFactory.class);
p.putBoolean(CONFIRM_ON_DELETE, confirmTransactionDelete);
}
use of java.util.prefs.Preferences in project jgnash by ccavanaugh.
the class RegisterFactory method setSortingEnabled.
/**
* Sets the availability of sortable registers.
*
* @param enabled true if sorting it enabled
*/
public static void setSortingEnabled(final boolean enabled) {
sortable = enabled;
Preferences p = Preferences.userNodeForPackage(RegisterFactory.class);
p.putBoolean(SORTABLE, sortable);
}
use of java.util.prefs.Preferences in project jgnash by ccavanaugh.
the class RegisterPanel method restoreLastTabUsed.
private void restoreLastTabUsed() {
if (RegisterFactory.isRestoreLastTransactionTabEnabled()) {
Preferences tabPreferences = Preferences.userRoot().node(NODE_REG_TAB);
String id = getAccount().getUuid();
final int index = tabPreferences.getInt(id, tabbedPane.getSelectedIndex());
EventQueue.invokeLater(() -> tabbedPane.setSelectedIndex(index));
}
}
Aggregations