Skip to content
This repository was archived by the owner on Mar 15, 2023. It is now read-only.

Commit 24cf348

Browse files
author
Jacob van Mourik
committed
Final touches for 1.0.0 release
1 parent 7b208aa commit 24cf348

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+147
-102
lines changed

src/main/java/com/jvms/i18neditor/Main.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,38 @@
77
import javax.swing.UIManager;
88

99
import org.apache.commons.lang3.SystemUtils;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
1012

1113
import com.google.common.collect.Sets;
1214
import com.jvms.i18neditor.editor.Editor;
1315

1416
/**
1517
*
16-
* @author Jacob
18+
* @author Jacob van Mourik
1719
*/
1820
public class Main {
19-
21+
private final static Logger log = LoggerFactory.getLogger(Main.class);
22+
2023
public static void main(String[] args) {
2124
SwingUtilities.invokeLater(() -> {
22-
// For MAC OS enable global menu
25+
// Enable global menu on MAC OS
2326
if (SystemUtils.IS_OS_MAC) {
2427
System.setProperty("apple.laf.useScreenMenuBar", "true");
2528
}
26-
// For non Linux use native look an feel
27-
if (!SystemUtils.IS_OS_LINUX) {
28-
try {
29-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
30-
} catch (Exception e) {
31-
//
29+
try {
30+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
31+
// For windows use menu font for entire UI
32+
if (SystemUtils.IS_OS_WINDOWS) {
33+
setUIFont(UIManager.getFont("Menu.font"));
3234
}
35+
} catch (Exception e) {
36+
log.warn("Unable to use native look and feel");
3337
}
34-
// For windows use menu font for entire UI
35-
if (SystemUtils.IS_OS_WINDOWS) {
36-
Font menuFont = UIManager.getFont("Menu.font");
37-
setUIFont(menuFont);
38-
}
39-
// Launch the editor
4038
new Editor().launch();
4139
});
4240
}
43-
41+
4442
private static void setUIFont(Font font) {
4543
UIDefaults defaults = UIManager.getDefaults();
4644
Sets.newHashSet(
@@ -74,4 +72,4 @@ private static void setUIFont(Font font) {
7472
"Button.font"
7573
).forEach(key -> defaults.put(key, font));
7674
}
77-
}
75+
}

src/main/java/com/jvms/i18neditor/Resource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* <p>Objects can listen to a resource by adding a {@link ResourceListener} which
2727
* will be called when any change is made to the {@code translations}.</p>
2828
*
29-
* @author Jacob
29+
* @author Jacob van Mourik
3030
*/
3131
public class Resource {
3232
private final Path path;

src/main/java/com/jvms/i18neditor/ResourceEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* An event wrapper for a {@link Resource}.
55
*
6-
* @author Jacob
6+
* @author Jacob van Mourik
77
*/
88
public class ResourceEvent {
99
private final Resource resource;

src/main/java/com/jvms/i18neditor/ResourceListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Defines an object which listens for {@link ResourceEvent}s.
77
*
8-
* @author Jacob
8+
* @author Jacob van Mourik
99
*/
1010
public interface ResourceListener extends EventListener {
1111

src/main/java/com/jvms/i18neditor/ResourceType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* An enum describing the type of a {@link Resource}.
55
*
66
* <p>A resource type additionally holds information about the filename representation.</p>
7+
*
8+
* @author Jacob van Mourik
79
*/
810
public enum ResourceType {
911
JSON(".json", false),

src/main/java/com/jvms/i18neditor/editor/AbstractSettingsPane.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
/**
1111
* This class represents an abstract base class for all setting panes.
1212
*
13-
* @author Jacob
13+
* @author Jacob van Mourik
1414
*/
1515
public abstract class AbstractSettingsPane extends JPanel {
1616
private GridBagConstraints vGridBagConstraints;
1717

1818
protected AbstractSettingsPane() {
1919
super();
2020
vGridBagConstraints = new GridBagConstraints();
21-
vGridBagConstraints.insets = new Insets(5,5,5,5);
21+
vGridBagConstraints.insets = new Insets(2,2,2,2);
2222
vGridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
2323
vGridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
2424
vGridBagConstraints.weightx = 1;

src/main/java/com/jvms/i18neditor/editor/Editor.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
/**
7676
* This class represents the main class of the editor.
7777
*
78-
* @author Jacob
78+
* @author Jacob van Mourik
7979
*/
8080
public class Editor extends JFrame {
8181
private final static long serialVersionUID = 1113029729495390082L;
@@ -147,7 +147,7 @@ public void createProject(Path dir, ResourceType type) {
147147

148148
updateHistory();
149149
updateUI();
150-
requestFocusToFirstResourceField();
150+
requestFocusInFirstResourceField();
151151
} catch (IOException e) {
152152
log.error("Error creating resource files", e);
153153
showError(MessageBundle.get("resources.create.error"));
@@ -198,7 +198,7 @@ public void importProject(Path dir, boolean showEmptyProjectError) {
198198

199199
updateHistory();
200200
updateUI();
201-
requestFocusToFirstResourceField();
201+
requestFocusInFirstResourceField();
202202
} catch (IOException e) {
203203
log.error("Error importing resource files", e);
204204
showError(MessageBundle.get("resources.import.error.multiple"));
@@ -263,31 +263,31 @@ public void addTranslationKey(String key) {
263263
}
264264
translationTree.addNodeByKey(key);
265265
}
266-
requestFocusToFirstResourceField();
266+
requestFocusInFirstResourceField();
267267
}
268268

269269
public void removeTranslationKey(String key) {
270270
if (project != null) {
271271
project.getResources().forEach(resource -> resource.removeTranslation(key));
272272
}
273273
translationTree.removeNodeByKey(key);
274-
requestFocusToFirstResourceField();
274+
requestFocusInFirstResourceField();
275275
}
276276

277277
public void renameTranslationKey(String key, String newKey) {
278278
if (project != null) {
279279
project.getResources().forEach(resource -> resource.renameTranslation(key, newKey));
280280
}
281281
translationTree.renameNodeByKey(key, newKey);
282-
requestFocusToFirstResourceField();
282+
requestFocusInFirstResourceField();
283283
}
284284

285285
public void duplicateTranslationKey(String key, String newKey) {
286286
if (project != null) {
287287
project.getResources().forEach(resource -> resource.duplicateTranslation(key, newKey));
288288
}
289289
translationTree.duplicateNodeByKey(key, newKey);
290-
requestFocusToFirstResourceField();
290+
requestFocusInFirstResourceField();
291291
}
292292

293293
public void addResource(Resource resource) {
@@ -480,7 +480,8 @@ public void showFindTranslationDialog() {
480480

481481
public void showAboutDialog() {
482482
Dialogs.showHtmlDialog(this, MessageBundle.get("dialogs.about.title", TITLE),
483-
"<span style=\"font-size:1.5em;\"><strong>" + TITLE + "</strong></span><br>" +
483+
"<img src=\"" + Images.getClasspathURL("images/icon-48.png") + "\"><br>" +
484+
"<span style=\"font-size:1.4em;\"><strong>" + TITLE + "</strong></span><br>" +
484485
VERSION + "<br><br>" +
485486
"Copyright (c) 2015 - 2017<br>" +
486487
"Jacob van Mourik<br>" +
@@ -624,7 +625,7 @@ public void updateUI() {
624625
repaint();
625626
}
626627

627-
private void requestFocusToFirstResourceField() {
628+
private void requestFocusInFirstResourceField() {
628629
resourceFields.stream().findFirst().ifPresent(f -> {
629630
f.requestFocusInWindow();
630631
});
@@ -645,7 +646,7 @@ private void setupUI() {
645646
addWindowListener(new EditorWindowListener());
646647

647648
setIconImages(Lists.newArrayList("512","256","128","64","48","32","24","20","16").stream()
648-
.map(size -> Images.getFromClasspath("images/icon-" + size + ".png").getImage())
649+
.map(size -> Images.loadFromClasspath("images/icon-" + size + ".png").getImage())
649650
.collect(Collectors.toList()));
650651

651652
translationTree = new TranslationTree();
@@ -662,8 +663,7 @@ private void setupUI() {
662663
JScrollPane translationsScrollPane = new JScrollPane(translationTree);
663664
translationsScrollPane.getViewport().setOpaque(false);
664665
translationsScrollPane.setOpaque(false);
665-
translationsScrollPane.setBorder(
666-
BorderFactory.createMatteBorder(0,0,0,1,borderColor));
666+
translationsScrollPane.setBorder(BorderFactory.createMatteBorder(0,0,0,1,borderColor));
667667

668668
translationsPanel = new JPanel(new BorderLayout());
669669
translationsPanel.add(translationsScrollPane);
@@ -702,7 +702,7 @@ private void setupUI() {
702702
introText.setHorizontalAlignment(JLabel.CENTER);
703703
introText.setVerticalAlignment(JLabel.CENTER);
704704
introText.setForeground(getBackground().darker());
705-
introText.setIcon(Images.getFromClasspath("images/icon-intro.png"));
705+
introText.setIcon(Images.loadFromClasspath("images/icon-intro.png"));
706706

707707
Container container = getContentPane();
708708
container.add(introText);
@@ -755,13 +755,18 @@ private void setupGlobalKeyEventDispatcher() {
755755
result = true;
756756
break;
757757
case KeyEvent.VK_UP:
758-
translationTree.setSelectionRow(Math.max(0, row-1));
758+
TreePath prev = translationTree.getPathForRow(Math.max(0, row-1));
759+
if (prev != null) {
760+
translationTree.setSelectionPath(prev);
761+
translationTree.scrollPathToVisible(prev);
762+
}
759763
result = true;
760764
break;
761765
case KeyEvent.VK_DOWN:
762766
TreePath next = translationTree.getPathForRow(row+1);
763767
if (next != null) {
764-
translationTree.setSelectionPath(next);
768+
translationTree.setSelectionPath(next);
769+
translationTree.scrollPathToVisible(next);
765770
}
766771
result = true;
767772
break;
@@ -773,7 +778,7 @@ private void setupGlobalKeyEventDispatcher() {
773778
if (!current.isLeaf() || current.isRoot()) {
774779
requestFocusInWindow();
775780
} else if (comp.equals(this)) {
776-
requestFocusToFirstResourceField();
781+
requestFocusInFirstResourceField();
777782
}
778783
}
779784
}

src/main/java/com/jvms/i18neditor/editor/EditorMenuBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* This class represents the top bar menu of the editor.
3131
*
32-
* @author Jacob
32+
* @author Jacob van Mourik
3333
*/
3434
public class EditorMenuBar extends JMenuBar {
3535
private final static long serialVersionUID = -101788804096708514L;

src/main/java/com/jvms/i18neditor/editor/EditorProject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* This class represents an editor project.
1313
*
14-
* @author Jacob
14+
* @author Jacob van Mourik
1515
*/
1616
public class EditorProject {
1717
private Path path;

src/main/java/com/jvms/i18neditor/editor/EditorProjectSettingsPane.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* This class represents the project settings pane.
1818
*
19-
* @author Jacob
19+
* @author Jacob van Mourik
2020
*/
2121
public class EditorProjectSettingsPane extends AbstractSettingsPane {
2222
private final static long serialVersionUID = 5665963334924596315L;
@@ -35,6 +35,13 @@ private void setupUI() {
3535
// General settings
3636
JPanel fieldset1 = createFieldset(MessageBundle.get("settings.fieldset.general"));
3737

38+
if (project.getResourceType() != ResourceType.Properties) {
39+
JCheckBox minifyBox = new JCheckBox(MessageBundle.get("settings.minify.title"));
40+
minifyBox.setSelected(project.isMinifyResources());
41+
minifyBox.addChangeListener(e -> project.setMinifyResources(minifyBox.isSelected()));
42+
fieldset1.add(minifyBox, createVerticalGridBagConstraints());
43+
}
44+
3845
JPanel resourcePanel = new JPanel(new GridLayout(0, 1));
3946
JLabel resourceNameLabel = new JLabel(MessageBundle.get("settings.resourcename.title"));
4047
JTextField resourceNameField = new JTextField(project.getResourceName());
@@ -49,13 +56,6 @@ public void keyReleased(KeyEvent e) {
4956
resourcePanel.add(resourceNameField);
5057
fieldset1.add(resourcePanel, createVerticalGridBagConstraints());
5158

52-
if (project.getResourceType() != ResourceType.Properties) {
53-
JCheckBox minifyBox = new JCheckBox(MessageBundle.get("settings.minify.title"));
54-
minifyBox.setSelected(project.isMinifyResources());
55-
minifyBox.addChangeListener(e -> project.setMinifyResources(minifyBox.isSelected()));
56-
fieldset1.add(minifyBox, createVerticalGridBagConstraints());
57-
}
58-
5959
setLayout(new GridBagLayout());
6060
add(fieldset1, createVerticalGridBagConstraints());
6161
}

0 commit comments

Comments
 (0)