Skip to content

Commit 1b5245b

Browse files
committed
Review. RES-691
1 parent 303cbe4 commit 1b5245b

File tree

9 files changed

+145
-65
lines changed

9 files changed

+145
-65
lines changed

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@
9191
<artifactId>dom4j</artifactId>
9292
<version>${dom4j.version}</version>
9393
</dependency>
94-
<dependency>
95-
<groupId>com.formdev</groupId>
96-
<artifactId>flatlaf</artifactId>
97-
<version>2.2</version>
98-
</dependency>
99-
10094
<dependency>
10195
<groupId>com.itextpdf</groupId>
10296
<artifactId>pdftest</artifactId>

src/main/java/com/itextpdf/rups/Rups.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ static void loadDocumentFromFile(IRupsController rupsController, File f) {
8585

8686
static void setLookandFeel() {
8787
try {
88-
if ( !FlatLightLaf.setup()) {
89-
UIManager.setLookAndFeel(RupsConfiguration.INSTANCE.getLookAndFeel());
90-
}
88+
UIManager.setLookAndFeel(RupsConfiguration.INSTANCE.getLookAndFeel());
9189
} catch (
9290
ClassNotFoundException | InstantiationException |
9391
IllegalAccessException | UnsupportedLookAndFeelException e) {

src/main/java/com/itextpdf/rups/view/Language.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public enum Language {
197197
PREFERENCES_RESET_TO_DEFAULTS_CONFIRM,
198198
PREFERENCES_RUPS_SETTINGS,
199199
PREFERENCES_SELECT_NEW_DEFAULT_FOLDER,
200+
PREFERENCES_VISUAL_SETTINGS,
200201

201202
RAW_BYTES,
202203

src/main/java/com/itextpdf/rups/view/PreferencesWindow.java

Lines changed: 112 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import com.itextpdf.rups.view.icons.FrameIconUtil;
55

66
import java.awt.BorderLayout;
7+
import java.awt.Component;
78
import java.awt.GridBagConstraints;
89
import java.awt.GridBagLayout;
10+
import java.util.Locale;
911
import javax.swing.JButton;
1012
import javax.swing.JCheckBox;
1113
import javax.swing.JComboBox;
14+
import javax.swing.JDialog;
1215
import javax.swing.JFileChooser;
13-
import javax.swing.JFrame;
1416
import javax.swing.JLabel;
1517
import javax.swing.JOptionPane;
1618
import javax.swing.JPanel;
@@ -24,114 +26,177 @@
2426
*/
2527
public class PreferencesWindow {
2628

27-
private JFrame jFrame;
29+
private JDialog jDialog;
30+
31+
private GridBagLayout gridBagLayout;
32+
private GridBagConstraints left;
33+
private GridBagConstraints right;
34+
35+
private JPanel visualPanel;
36+
private JScrollPane generalSettingsScrollPane;
37+
38+
// Fields to reset
39+
private JCheckBox openDuplicateFiles;
40+
private JTextField pathField;
2841

2942
public PreferencesWindow() {
30-
jFrame = new JFrame();
31-
jFrame.setTitle(Language.PREFERENCES.getString());
32-
jFrame.setIconImages(FrameIconUtil.loadFrameIcons());
33-
jFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
34-
jFrame.setLayout(new BorderLayout());
43+
initializeJDialog();
44+
initializeLayout();
45+
46+
createGeneralSettingsTab();
47+
createVisualSettingsTab();
48+
createTabbedPane();
49+
createSaveCancelResetSection();
50+
51+
completeJDialogCreation();
52+
}
53+
54+
private void initializeJDialog() {
55+
this.jDialog = new JDialog();
56+
57+
this.jDialog.setTitle(Language.PREFERENCES.getString());
58+
this.jDialog.setIconImages(FrameIconUtil.loadFrameIcons());
59+
this.jDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
60+
this.jDialog.setModal(true);
61+
this.jDialog.setLayout(new BorderLayout());
62+
}
63+
64+
private void initializeLayout() {
65+
this.gridBagLayout = new GridBagLayout();
66+
67+
this.left = new GridBagConstraints();
68+
this.left.anchor = GridBagConstraints.EAST;
3569

36-
JTabbedPane tabbedPane = new JTabbedPane();
70+
this.right = new GridBagConstraints();
71+
this.right.weightx = 2.0;
72+
this.right.fill = GridBagConstraints.HORIZONTAL;
73+
this.right.gridwidth = GridBagConstraints.REMAINDER;
74+
}
3775

38-
JTextField pathField = new JTextField(RupsConfiguration.INSTANCE.getHomeFolder().getPath(), 30);
76+
private void createGeneralSettingsTab() {
77+
this.pathField = new JTextField(RupsConfiguration.INSTANCE.getHomeFolder().getPath(), 30);
3978
JLabel pathLabel = new JLabel(Language.PREFERENCES_OPEN_FOLDER.getString());
40-
pathLabel.setLabelFor(pathField);
79+
pathLabel.setLabelFor(this.pathField);
4180

4281
JButton pathChooser = new JButton(Language.PREFERENCES_SELECT_NEW_DEFAULT_FOLDER.getString());
4382
pathChooser.addActionListener(e -> {
4483
JFileChooser fileChooser = new JFileChooser(RupsConfiguration.INSTANCE.getHomeFolder());
4584
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
46-
int choice = fileChooser.showOpenDialog(jFrame);
85+
int choice = fileChooser.showOpenDialog(jDialog);
4786

4887
if (choice == JFileChooser.APPROVE_OPTION) {
4988
String path = fileChooser.getSelectedFile().getPath();
50-
pathField.setText(path);
89+
this.pathField.setText(path);
5190
RupsConfiguration.INSTANCE.setHomeFolder(path);
5291
}
5392
});
5493

5594
JPanel fieldsPanel = new JPanel();
56-
fieldsPanel.add(pathField);
95+
fieldsPanel.add(this.pathField);
5796
fieldsPanel.add(pathChooser);
5897

59-
JCheckBox openDuplicateFiles = new JCheckBox("", RupsConfiguration.INSTANCE.canOpenDuplicateFiles());
60-
openDuplicateFiles.addActionListener(
98+
this.openDuplicateFiles = new JCheckBox("", RupsConfiguration.INSTANCE.canOpenDuplicateFiles());
99+
this.openDuplicateFiles.addActionListener(
61100
e -> RupsConfiguration.INSTANCE.setOpenDuplicateFiles(((JCheckBox) e.getSource()).isSelected())
62101
);
63102
JLabel openDuplicateFilesLabel = new JLabel(Language.PREFERENCES_ALLOW_DUPLICATE_FILES.getString());
64-
openDuplicateFilesLabel.setLabelFor(openDuplicateFiles);
103+
openDuplicateFilesLabel.setLabelFor(this.openDuplicateFiles);
104+
105+
JPanel generalSettingsPanel = new JPanel();
106+
generalSettingsPanel.setLayout(this.gridBagLayout);
107+
108+
generalSettingsPanel.add(pathLabel, this.left);
109+
generalSettingsPanel.add(fieldsPanel, this.right);
65110

66-
JPanel outerPanel = new JPanel();
67-
GridBagLayout gridBagLayout = new GridBagLayout();
68-
outerPanel.setLayout(gridBagLayout);
111+
generalSettingsPanel.add(openDuplicateFilesLabel, this.left);
112+
generalSettingsPanel.add(this.openDuplicateFiles, this.right);
69113

70-
GridBagConstraints left = new GridBagConstraints();
71-
left.anchor = GridBagConstraints.EAST;
72-
GridBagConstraints right = new GridBagConstraints();
73-
right.weightx = 2.0;
74-
right.fill = GridBagConstraints.HORIZONTAL;
75-
right.gridwidth = GridBagConstraints.REMAINDER;
114+
this.generalSettingsScrollPane = new JScrollPane(generalSettingsPanel);
115+
}
76116

77-
outerPanel.add(pathLabel, left);
78-
outerPanel.add(fieldsPanel, right);
117+
private void createVisualSettingsTab() {
118+
final JComboBox<String> localeBox = new JComboBox<>();
119+
localeBox.addItem("nl-NL");
120+
localeBox.addItem("en-US");
121+
localeBox.setSelectedItem(RupsConfiguration.INSTANCE.getUserLocale().toLanguageTag());
122+
final JLabel localeLabel = new JLabel("Locale");
123+
localeLabel.setLabelFor(localeBox);
124+
125+
localeBox.addActionListener(e -> {
126+
Object selectedItem = localeBox.getSelectedItem();
127+
String selectedString = (String) selectedItem;
128+
RupsConfiguration.INSTANCE.setUserLocale(Locale.forLanguageTag(selectedString));
129+
});
79130

80-
outerPanel.add(openDuplicateFilesLabel, left);
81-
outerPanel.add(openDuplicateFiles, right);
131+
this.visualPanel = new JPanel();
132+
this.visualPanel.setLayout(this.gridBagLayout);
82133

83-
JScrollPane scrollPane = new JScrollPane(outerPanel);
134+
this.visualPanel.add(localeLabel, this.left);
135+
this.visualPanel.add(localeBox, this.right);
136+
}
84137

85-
tabbedPane.add(Language.PREFERENCES_RUPS_SETTINGS.getString(), scrollPane);
138+
private void createTabbedPane() {
139+
final JTabbedPane tabbedPane = new JTabbedPane();
86140

87-
jFrame.add(tabbedPane, BorderLayout.CENTER);
141+
tabbedPane.add(Language.PREFERENCES_RUPS_SETTINGS.getString(), this.generalSettingsScrollPane);
142+
tabbedPane.add(Language.PREFERENCES_VISUAL_SETTINGS.getString(), this.visualPanel);
88143

144+
this.jDialog.add(tabbedPane, BorderLayout.CENTER);
145+
}
146+
147+
private void createSaveCancelResetSection() {
89148
JPanel buttons = new JPanel();
90149

91150
JButton save = new JButton(Language.SAVE.getString());
92-
save.addActionListener(e -> RupsConfiguration.INSTANCE.saveConfiguration());
151+
save.addActionListener(e -> {
152+
RupsConfiguration.INSTANCE.saveConfiguration();
153+
this.jDialog.dispose();
154+
});
93155
buttons.add(save);
94156

95157
JButton cancel = new JButton(Language.DIALOG_CANCEL.getString());
96158
cancel.addActionListener(e -> {
97159
if (RupsConfiguration.INSTANCE.hasUnsavedChanges()) {
98-
int choice = JOptionPane.showConfirmDialog(jFrame,
160+
int choice = JOptionPane.showConfirmDialog(jDialog,
99161
Language.SAVE_UNSAVED_CHANGES.getString());
100162
if (choice == JOptionPane.OK_OPTION) {
101163
RupsConfiguration.INSTANCE.cancelTemporaryChanges();
102-
jFrame.dispose();
164+
this.jDialog.dispose();
103165
}
104166
} else {
105-
jFrame.dispose();
167+
this.jDialog.dispose();
106168
}
107169
});
108170
buttons.add(cancel);
109171

110172
JButton reset = new JButton(Language.PREFERENCES_RESET_TO_DEFAULTS.getString());
111173

112174
reset.addActionListener(e -> {
113-
int choice = JOptionPane.showConfirmDialog(jFrame,
175+
int choice = JOptionPane.showConfirmDialog(jDialog,
114176
Language.PREFERENCES_RESET_TO_DEFAULTS_CONFIRM.getString());
115177
if (choice == JOptionPane.OK_OPTION) {
116178
RupsConfiguration.INSTANCE.resetToDefaultProperties();
117179

118-
resetView(pathField, openDuplicateFiles);
180+
resetView();
119181
}
120182
});
121183
buttons.add(reset);
122184

123-
jFrame.add(buttons, BorderLayout.SOUTH);
124-
jFrame.pack();
125-
jFrame.setResizable(false);
185+
jDialog.add(buttons, BorderLayout.SOUTH);
186+
}
187+
188+
private void completeJDialogCreation() {
189+
this.jDialog.pack();
190+
this.jDialog.setResizable(false);
126191
}
127192

128-
private void resetView(JTextField pathField, JCheckBox openDuplicateFiles) {
129-
pathField.setText(RupsConfiguration.INSTANCE.getHomeFolder().getPath());
130-
openDuplicateFiles.setSelected(RupsConfiguration.INSTANCE.canOpenDuplicateFiles());
193+
private void resetView() {
194+
this.pathField.setText(RupsConfiguration.INSTANCE.getHomeFolder().getPath());
195+
this.openDuplicateFiles.setSelected(RupsConfiguration.INSTANCE.canOpenDuplicateFiles());
131196
}
132197

133-
public void show() {
134-
jFrame.setLocationRelativeTo(null);
135-
jFrame.setVisible(true);
198+
public void show(Component component) {
199+
jDialog.setLocationRelativeTo(component);
200+
jDialog.setVisible(true);
136201
}
137202
}

src/main/java/com/itextpdf/rups/view/RupsMenuBar.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,19 @@ public class RupsMenuBar extends JMenuBar implements Observer {
8888
* The HashMap with all the actions.
8989
*/
9090
protected HashMap<String, JMenuItem> items;
91+
/**
92+
* The Preferences Window
93+
*/
94+
private final PreferencesWindow preferencesWindow;
9195

9296
/**
9397
* Creates a JMenuBar.
9498
*/
9599
public RupsMenuBar(RupsController controller) {
96100
items = new HashMap<>();
97101

102+
preferencesWindow = new PreferencesWindow();
103+
98104
fileOpenAction = new FileOpenAction(controller, PdfFilter.INSTANCE, controller.getMasterComponent());
99105
fileCloseAction = new FileCloseAction(controller);
100106
openInViewerAction = new OpenInViewerAction(controller);
@@ -119,7 +125,10 @@ public RupsMenuBar(RupsController controller) {
119125
add(file);
120126

121127
final JMenu edit = new JMenu(Language.MENU_BAR_EDIT.getString());
122-
addItem(edit, Language.PREFERENCES.getString(), e -> new PreferencesWindow().show());
128+
addItem(edit, Language.PREFERENCES.getString(), e -> {
129+
preferencesWindow.show(controller.getMasterComponent());
130+
}
131+
);
123132
add(edit);
124133

125134
add(Box.createGlue());

src/main/java/com/itextpdf/rups/view/RupsTabbedPane.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,22 @@ public Component getJTabbedPane() {
121121
*/
122122
public boolean isFileAlreadyOpen(File file) {
123123
for (int tabIndex = 0; tabIndex < this.jTabbedPane.getTabCount(); tabIndex++) {
124-
final String title = this.jTabbedPane.getTitleAt(tabIndex);
124+
Component component = this.jTabbedPane.getComponentAt(tabIndex);
125125

126-
if (title.equals(file.getName())) {
127-
return true;
126+
if ( component instanceof RupsPanel ) {
127+
RupsPanel rupsPanel = (RupsPanel) component;
128+
PdfFile pdfFile = rupsPanel.getPdfFile();
129+
File directory = pdfFile.getDirectory();
130+
String fileName = pdfFile.getFilename();
131+
132+
File openedFile = new File(directory, fileName);
133+
134+
if (openedFile.equals(file)) {
135+
return true;
136+
}
128137
}
129138
}
139+
130140
return false;
131141
}
132142
}

src/main/java/com/itextpdf/rups/view/itext/contentstream/ContentStreamWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ This file is part of the iText (R) project.
4747
import com.itextpdf.rups.RupsConfiguration;
4848
import com.itextpdf.rups.view.Language;
4949

50+
import java.util.Locale;
5051
import javax.swing.text.AttributeSet;
5152
import javax.swing.text.BadLocationException;
5253
import javax.swing.text.Document;
@@ -109,7 +110,7 @@ private Element handleHexContent(Element initElement, ElementIterator it) throws
109110
final int start = current.getStartOffset();
110111
final int end = current.getEndOffset();
111112
try {
112-
hexBuf.append(doc.getText(start, end - start).toLowerCase(RupsConfiguration.INSTANCE.getUserLocale()));
113+
hexBuf.append(doc.getText(start, end - start).toLowerCase(Locale.getDefault()));
113114
} catch (BadLocationException e) {
114115
throw new ITextException(Language.ERROR_QUERY_CONTENT_STREAM.getString(), e);
115116
}

src/main/resources/bundles/rups-lang.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ DICTIONARY_KEY=Key
3434
DICTIONARY_OF_TYPE=Dictionary of type: %s
3535
DICTIONARY_VALUE=Value
3636

37-
DUPLICATE_FILES_OFF=Opening duplicate files has been turned off. Please turn this on in the properties file to enable duplicate files. See README.md for more information.
37+
DUPLICATE_FILES_OFF=Opening duplicate files has been turned off. Please turn this on in the Preferences to enable duplicate files.
3838

3939
EDITOR_CONSOLE=Console
4040
EDITOR_CONSOLE_TOOLTIP=Console window (System.out/System.err)
@@ -153,8 +153,9 @@ PREFERENCES_ALLOW_DUPLICATE_FILES=Allow duplicate files in viewer
153153
PREFERENCES_OPEN_FOLDER=Default Open File Folder
154154
PREFERENCES_RESET_TO_DEFAULTS=Reset to Defaults
155155
PREFERENCES_RESET_TO_DEFAULTS_CONFIRM=Do you want to reset all settings?
156-
PREFERENCES_RUPS_SETTINGS=RUPS Settings
156+
PREFERENCES_RUPS_SETTINGS=General Settings
157157
PREFERENCES_SELECT_NEW_DEFAULT_FOLDER=Select new default folder
158+
PREFERENCES_VISUAL_SETTINGS=Visual Settings
158159
159160
RAW_BYTES= raw bytes
160161

src/main/resources/bundles/rups-lang_nl_NL.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ DICTIONARY_KEY=Key
3232
DICTIONARY_OF_TYPE=Dictionary van het type: %s
3333
DICTIONARY_VALUE=Value
3434

35-
DUPLICATE_FILES_OFF=Het openen van duplicate bestanden is niet toegestaan. Je kan deze optie aanzetten in de properties file. Bekijk de README.md file voor meer informatie.
35+
DUPLICATE_FILES_OFF=Het openen van duplicate bestanden is niet toegestaan. Je kan deze optie aanzetten in de Voorkeuren.
3636

3737
EDITOR_CONSOLE=Console
3838
EDITOR_CONSOLE_TOOLTIP=Consolevenster (System.out/System.err)
@@ -149,8 +149,9 @@ PREFERENCES_ALLOW_DUPLICATE_FILES=Sta het openen van duplicate bestanden toe
149149
PREFERENCES_OPEN_FOLDER=Standaard folder om bestanden te openen
150150
PREFERENCES_RESET_TO_DEFAULTS=Herstel beginwaarden
151151
PREFERENCES_RESET_TO_DEFAULTS_CONFIRM=Wilt u de beginwaarden herstellen?
152-
PREFERENCES_RUPS_SETTINGS=RUPS Instellingen
152+
PREFERENCES_RUPS_SETTINGS=Algemene Voorkeuren
153153
PREFERENCES_SELECT_NEW_DEFAULT_FOLDER=Kies standaard folder
154+
PREFERENCES_VISUAL_SETTINGS=Visuele Voorkeuren
154155
155156
RAW_BYTES= raw bytes
156157

0 commit comments

Comments
 (0)