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

Commit

Permalink
Final touches for 1.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob van Mourik committed Feb 12, 2017
1 parent 7b208aa commit 24cf348
Show file tree
Hide file tree
Showing 52 changed files with 147 additions and 102 deletions.
32 changes: 15 additions & 17 deletions src/main/java/com/jvms/i18neditor/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,38 @@
import javax.swing.UIManager;

import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
*
* @author Jacob
* @author Jacob van Mourik
*/
public class Main {

private final static Logger log = LoggerFactory.getLogger(Main.class);

public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
// For MAC OS enable global menu
// Enable global menu on MAC OS
if (SystemUtils.IS_OS_MAC) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
}
// For non Linux use native look an feel
if (!SystemUtils.IS_OS_LINUX) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
//
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// For windows use menu font for entire UI
if (SystemUtils.IS_OS_WINDOWS) {
setUIFont(UIManager.getFont("Menu.font"));
}
} catch (Exception e) {
log.warn("Unable to use native look and feel");
}
// For windows use menu font for entire UI
if (SystemUtils.IS_OS_WINDOWS) {
Font menuFont = UIManager.getFont("Menu.font");
setUIFont(menuFont);
}
// Launch the editor
new Editor().launch();
});
}

private static void setUIFont(Font font) {
UIDefaults defaults = UIManager.getDefaults();
Sets.newHashSet(
Expand Down Expand Up @@ -74,4 +72,4 @@ private static void setUIFont(Font font) {
"Button.font"
).forEach(key -> defaults.put(key, font));
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/jvms/i18neditor/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* <p>Objects can listen to a resource by adding a {@link ResourceListener} which
* will be called when any change is made to the {@code translations}.</p>
*
* @author Jacob
* @author Jacob van Mourik
*/
public class Resource {
private final Path path;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jvms/i18neditor/ResourceEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* An event wrapper for a {@link Resource}.
*
* @author Jacob
* @author Jacob van Mourik
*/
public class ResourceEvent {
private final Resource resource;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jvms/i18neditor/ResourceListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Defines an object which listens for {@link ResourceEvent}s.
*
* @author Jacob
* @author Jacob van Mourik
*/
public interface ResourceListener extends EventListener {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/jvms/i18neditor/ResourceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* An enum describing the type of a {@link Resource}.
*
* <p>A resource type additionally holds information about the filename representation.</p>
*
* @author Jacob van Mourik
*/
public enum ResourceType {
JSON(".json", false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
/**
* This class represents an abstract base class for all setting panes.
*
* @author Jacob
* @author Jacob van Mourik
*/
public abstract class AbstractSettingsPane extends JPanel {
private GridBagConstraints vGridBagConstraints;

protected AbstractSettingsPane() {
super();
vGridBagConstraints = new GridBagConstraints();
vGridBagConstraints.insets = new Insets(5,5,5,5);
vGridBagConstraints.insets = new Insets(2,2,2,2);
vGridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
vGridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
vGridBagConstraints.weightx = 1;
Expand Down
37 changes: 21 additions & 16 deletions src/main/java/com/jvms/i18neditor/editor/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
/**
* This class represents the main class of the editor.
*
* @author Jacob
* @author Jacob van Mourik
*/
public class Editor extends JFrame {
private final static long serialVersionUID = 1113029729495390082L;
Expand Down Expand Up @@ -147,7 +147,7 @@ public void createProject(Path dir, ResourceType type) {

updateHistory();
updateUI();
requestFocusToFirstResourceField();
requestFocusInFirstResourceField();
} catch (IOException e) {
log.error("Error creating resource files", e);
showError(MessageBundle.get("resources.create.error"));
Expand Down Expand Up @@ -198,7 +198,7 @@ public void importProject(Path dir, boolean showEmptyProjectError) {

updateHistory();
updateUI();
requestFocusToFirstResourceField();
requestFocusInFirstResourceField();
} catch (IOException e) {
log.error("Error importing resource files", e);
showError(MessageBundle.get("resources.import.error.multiple"));
Expand Down Expand Up @@ -263,31 +263,31 @@ public void addTranslationKey(String key) {
}
translationTree.addNodeByKey(key);
}
requestFocusToFirstResourceField();
requestFocusInFirstResourceField();
}

public void removeTranslationKey(String key) {
if (project != null) {
project.getResources().forEach(resource -> resource.removeTranslation(key));
}
translationTree.removeNodeByKey(key);
requestFocusToFirstResourceField();
requestFocusInFirstResourceField();
}

public void renameTranslationKey(String key, String newKey) {
if (project != null) {
project.getResources().forEach(resource -> resource.renameTranslation(key, newKey));
}
translationTree.renameNodeByKey(key, newKey);
requestFocusToFirstResourceField();
requestFocusInFirstResourceField();
}

public void duplicateTranslationKey(String key, String newKey) {
if (project != null) {
project.getResources().forEach(resource -> resource.duplicateTranslation(key, newKey));
}
translationTree.duplicateNodeByKey(key, newKey);
requestFocusToFirstResourceField();
requestFocusInFirstResourceField();
}

public void addResource(Resource resource) {
Expand Down Expand Up @@ -480,7 +480,8 @@ public void showFindTranslationDialog() {

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

private void requestFocusToFirstResourceField() {
private void requestFocusInFirstResourceField() {
resourceFields.stream().findFirst().ifPresent(f -> {
f.requestFocusInWindow();
});
Expand All @@ -645,7 +646,7 @@ private void setupUI() {
addWindowListener(new EditorWindowListener());

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

translationTree = new TranslationTree();
Expand All @@ -662,8 +663,7 @@ private void setupUI() {
JScrollPane translationsScrollPane = new JScrollPane(translationTree);
translationsScrollPane.getViewport().setOpaque(false);
translationsScrollPane.setOpaque(false);
translationsScrollPane.setBorder(
BorderFactory.createMatteBorder(0,0,0,1,borderColor));
translationsScrollPane.setBorder(BorderFactory.createMatteBorder(0,0,0,1,borderColor));

translationsPanel = new JPanel(new BorderLayout());
translationsPanel.add(translationsScrollPane);
Expand Down Expand Up @@ -702,7 +702,7 @@ private void setupUI() {
introText.setHorizontalAlignment(JLabel.CENTER);
introText.setVerticalAlignment(JLabel.CENTER);
introText.setForeground(getBackground().darker());
introText.setIcon(Images.getFromClasspath("images/icon-intro.png"));
introText.setIcon(Images.loadFromClasspath("images/icon-intro.png"));

Container container = getContentPane();
container.add(introText);
Expand Down Expand Up @@ -755,13 +755,18 @@ private void setupGlobalKeyEventDispatcher() {
result = true;
break;
case KeyEvent.VK_UP:
translationTree.setSelectionRow(Math.max(0, row-1));
TreePath prev = translationTree.getPathForRow(Math.max(0, row-1));
if (prev != null) {
translationTree.setSelectionPath(prev);
translationTree.scrollPathToVisible(prev);
}
result = true;
break;
case KeyEvent.VK_DOWN:
TreePath next = translationTree.getPathForRow(row+1);
if (next != null) {
translationTree.setSelectionPath(next);
translationTree.setSelectionPath(next);
translationTree.scrollPathToVisible(next);
}
result = true;
break;
Expand All @@ -773,7 +778,7 @@ private void setupGlobalKeyEventDispatcher() {
if (!current.isLeaf() || current.isRoot()) {
requestFocusInWindow();
} else if (comp.equals(this)) {
requestFocusToFirstResourceField();
requestFocusInFirstResourceField();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* This class represents the top bar menu of the editor.
*
* @author Jacob
* @author Jacob van Mourik
*/
public class EditorMenuBar extends JMenuBar {
private final static long serialVersionUID = -101788804096708514L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* This class represents an editor project.
*
* @author Jacob
* @author Jacob van Mourik
*/
public class EditorProject {
private Path path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* This class represents the project settings pane.
*
* @author Jacob
* @author Jacob van Mourik
*/
public class EditorProjectSettingsPane extends AbstractSettingsPane {
private final static long serialVersionUID = 5665963334924596315L;
Expand All @@ -35,6 +35,13 @@ private void setupUI() {
// General settings
JPanel fieldset1 = createFieldset(MessageBundle.get("settings.fieldset.general"));

if (project.getResourceType() != ResourceType.Properties) {
JCheckBox minifyBox = new JCheckBox(MessageBundle.get("settings.minify.title"));
minifyBox.setSelected(project.isMinifyResources());
minifyBox.addChangeListener(e -> project.setMinifyResources(minifyBox.isSelected()));
fieldset1.add(minifyBox, createVerticalGridBagConstraints());
}

JPanel resourcePanel = new JPanel(new GridLayout(0, 1));
JLabel resourceNameLabel = new JLabel(MessageBundle.get("settings.resourcename.title"));
JTextField resourceNameField = new JTextField(project.getResourceName());
Expand All @@ -49,13 +56,6 @@ public void keyReleased(KeyEvent e) {
resourcePanel.add(resourceNameField);
fieldset1.add(resourcePanel, createVerticalGridBagConstraints());

if (project.getResourceType() != ResourceType.Properties) {
JCheckBox minifyBox = new JCheckBox(MessageBundle.get("settings.minify.title"));
minifyBox.setSelected(project.isMinifyResources());
minifyBox.addChangeListener(e -> project.setMinifyResources(minifyBox.isSelected()));
fieldset1.add(minifyBox, createVerticalGridBagConstraints());
}

setLayout(new GridBagLayout());
add(fieldset1, createVerticalGridBagConstraints());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* This class represents the editor settings.
*
* @author Jacob
* @author Jacob van Mourik
*/
public class EditorSettings {
private int windowPositionX;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/jvms/i18neditor/editor/EditorSettingsPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* This class represents the editor settings pane.
*
* @author Jacob
* @author Jacob van Mourik
*/
public class EditorSettingsPane extends AbstractSettingsPane {
private final static long serialVersionUID = 4488173853564278813L;
Expand All @@ -42,6 +42,11 @@ private void setupUI() {
// New project settings
JPanel fieldset2 = createFieldset(MessageBundle.get("settings.fieldset.newprojects"));

JCheckBox minifyBox = new JCheckBox(MessageBundle.get("settings.minify.title"));
minifyBox.setSelected(settings.isMinifyResources());
minifyBox.addChangeListener(e -> settings.setMinifyResources(minifyBox.isSelected()));
fieldset2.add(minifyBox, createVerticalGridBagConstraints());

JPanel resourceNamePanel = new JPanel(new GridLayout(0, 1));
JLabel resourceNameLabel = new JLabel(MessageBundle.get("settings.resourcename.title"));
JTextField resourceNameField = new JTextField(settings.getResourceName());
Expand All @@ -56,11 +61,6 @@ public void keyReleased(KeyEvent e) {
resourceNamePanel.add(resourceNameField);
fieldset2.add(resourceNamePanel, createVerticalGridBagConstraints());

JCheckBox minifyBox = new JCheckBox(MessageBundle.get("settings.minify.title"));
minifyBox.setSelected(settings.isMinifyResources());
minifyBox.addChangeListener(e -> settings.setMinifyResources(minifyBox.isSelected()));
fieldset2.add(minifyBox, createVerticalGridBagConstraints());

// Editing settings
JPanel fieldset3 = createFieldset(MessageBundle.get("settings.fieldset.editing"));

Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/jvms/i18neditor/editor/ResourceField.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.jvms.i18neditor.editor;

import java.awt.KeyboardFocusManager;
import java.awt.Rectangle;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.util.Locale;

import javax.swing.JComponent;

import com.jvms.i18neditor.Resource;
import com.jvms.i18neditor.swing.JTextArea;

/**
* This class represents a text area to edit the value of a translation.
*
* @author Jacob
* @author Jacob van Mourik
*/
public class ResourceField extends JTextArea implements Comparable<ResourceField> {
private final static long serialVersionUID = 2034814490878477055L;
Expand Down Expand Up @@ -51,5 +56,17 @@ private void setupUI() {
// Add focus traversal support
setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
addFocusListener(new ResourceFieldFocusListener());
}

private class ResourceFieldFocusListener extends FocusAdapter {
@Override
public void focusGained(FocusEvent e) {
JComponent parent = (JComponent)getParent();
Rectangle bounds = new Rectangle(getBounds());
bounds.y -= 35; // add fixed space at the top
bounds.height += 70; // add fixed space at the bottom
parent.scrollRectToVisible(bounds);
}
}
}
Loading

0 comments on commit 24cf348

Please sign in to comment.