Skip to content

Commit

Permalink
Added TODOs for next issues, Minor reformattings and Cleanup, Adjuste…
Browse files Browse the repository at this point in the history
…d Locale-Regex to support DE-AT and the like
  • Loading branch information
Vogel612 committed Jan 18, 2016
1 parent f20258e commit 8743841
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 72 deletions.
12 changes: 8 additions & 4 deletions src/main/java/de/vogel612/helper/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import java.nio.file.Paths;

public class Main {
public static final String RUBBERDUCK_PATH = "RetailCoder.VBE/UI";
public static final String ARGUMENT_MISMATCH = "Arguments do not match up. Please provide one single path to read the Rubberduck resx from";
public static final String ILLEGAL_FOLDER = "Rubberduck .resx files can only be found under RetailCoder.VBE/UI. Please give a path that points to a Rubberduck UI folder";
// FIXME: Don't rely on this!
private static final String RUBBERDUCK_PATH = "RetailCoder.VBE/UI";
// protected for testing verifications
protected static final String ARGUMENT_MISMATCH = "Arguments do not match up. Please provide one single path to read the Rubberduck resx from";
protected static final String ILLEGAL_FOLDER = "Rubberduck .resx files can only be found under RetailCoder.VBE/UI. Please give a path that points to a Rubberduck UI folder";

private Main() {
}
Expand All @@ -30,6 +32,7 @@ public static void main(final String[] args) {
// normalize path to allow checking
resxFolder = resxFolder.normalize();

// TODO: Check if we really need this...
if (!resxFolder.endsWith(RUBBERDUCK_PATH)) {
System.out.println(ILLEGAL_FOLDER);
return;
Expand All @@ -47,7 +50,8 @@ public static void main(final String[] args) {
if (args.length == 3) {
final String leftLocale = args[1];
final String rightLocale = args[2];
if (m.getAvailableLocales().contains(leftLocale) && m.getAvailableLocales().contains(rightLocale)) {
if (m.getAvailableLocales().contains(leftLocale)
&& m.getAvailableLocales().contains(rightLocale)) {
p.onTranslationRequest(leftLocale, Side.LEFT);
p.onTranslationRequest(rightLocale, Side.RIGHT);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/vogel612/helper/ui/OverviewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class OverviewModel {

private static final String ELEMENT_NAME = "data";
private static final String FILE_NAME_FORMAT = "RubberduckUI%s.resx";
private static final String FILENAME_REGEX = "^.*RubberduckUI\\.?([a-z]{2})?\\.resx$";
private static final String FILENAME_REGEX = "^.*RubberduckUI\\.?([a-z]{2}(?:-[a-z]{2})?)?\\.resx$";

private static final Pattern localeFinder = Pattern.compile(FILENAME_REGEX);

Expand Down Expand Up @@ -74,6 +74,7 @@ public void loadFromDirectory(final Path resxFolder) {
OverviewModel::parseFileName, this::parseFile)
));
} catch (IOException ex) {
// SMELL: Why is this the responsiblity of client code?
String errorMessage = String.format(
"Could not access %s due to %s", resxFolder, ex);
System.err.println(errorMessage);
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/de/vogel612/helper/ui/OverviewPresenter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.vogel612.helper.ui;

import static javax.swing.JOptionPane.*;

import de.vogel612.helper.data.Side;
import de.vogel612.helper.data.Translation;

Expand Down Expand Up @@ -42,18 +44,21 @@ public void initialize() {
if (initialized) {
return;
}
// TODO: Make a real event-driven model from this mess
view.register(this);
model.register(this);
translationPresenter.register(this);
initialized = true;
}

// This is some messed up Event mechanism. Possibly run over listeners instead?
public void onTranslationRequest(final String locale, final Side side) {
chosenLocale.put(side, locale);
rebuildView();
}

public void onException(final Exception e, final String message) {
// FIXME: Allow termination for unrecoverable exception
view.displayError(message, e.getMessage());
}

Expand All @@ -72,7 +77,9 @@ public void loadFiles(final Path resxFolder) {
}

public String[] getLocaleOptions() {
return model.getAvailableLocales().toArray(new String[]{});
final List<String> availableLocales = model.getAvailableLocales();
// minor performance boost over passing in an empty array
return availableLocales.toArray(new String[availableLocales.size()]);
}

public void onTranslationSubmit(final Translation t) {
Expand Down Expand Up @@ -103,16 +110,16 @@ public void onWindowCloseRequest(WindowEvent windowEvent) {
int choice = JOptionPane.showConfirmDialog(windowEvent.getWindow(),
"You have unsaved changes. Do you wish to save before exiting?",
"Unsaved Changes",
JOptionPane.YES_NO_CANCEL_OPTION);
YES_NO_CANCEL_OPTION);
switch (choice) {
case JOptionPane.YES_OPTION:
case YES_OPTION:
model.saveAll();
// fallthrough intended
case JOptionPane.NO_OPTION:
case NO_OPTION:
view.hide();
System.exit(0);
break;
case JOptionPane.CANCEL_OPTION:
case CANCEL_OPTION:
// do nothing
break;
}
Expand Down
68 changes: 6 additions & 62 deletions src/main/java/de/vogel612/helper/ui/SwingOverviewView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static de.vogel612.helper.ui.util.UiBuilder.addToGridBag;
import static java.awt.GridBagConstraints.BOTH;
import static javax.swing.JOptionPane.ERROR_MESSAGE;

import de.vogel612.helper.data.Side;
import de.vogel612.helper.data.Translation;
Expand All @@ -10,10 +11,7 @@

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.*;
import java.util.List;

public class SwingOverviewView implements OverviewView {
Expand Down Expand Up @@ -52,42 +50,11 @@ public void register(final OverviewPresenter p) {
chooseLeft.addActionListener(event -> chooseAndLoadLanguage(Side.LEFT));
chooseRight.addActionListener(event -> chooseAndLoadLanguage(Side.RIGHT));

window.addWindowListener(new WindowListener() {

@Override
public void windowOpened(WindowEvent windowEvent) {
// nothing
}

window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent windowEvent) {
p.onWindowCloseRequest(windowEvent);
}

@Override
public void windowClosed(WindowEvent windowEvent) {
// nothing
}

@Override
public void windowIconified(WindowEvent windowEvent) {
// nothing
}

@Override
public void windowDeiconified(WindowEvent windowEvent) {
// nothing
}

@Override
public void windowActivated(WindowEvent windowEvent) {
// nothing
}

@Override
public void windowDeactivated(WindowEvent windowEvent) {
// nothing
}
});
}

Expand Down Expand Up @@ -141,40 +108,18 @@ private void addTranslationContainer() {
}

private void bindEventListener() {
translationContainer.addMouseListener(new MouseListener() {
translationContainer.addMouseListener(new MouseAdapter() {

@Override
public void mouseClicked(final MouseEvent event) {
if (event.getClickCount() != 2) { // only react to doubleclicks!
return;
}
final int row = translationContainer.rowAtPoint(event
.getPoint());
final int row = translationContainer.rowAtPoint(event.getPoint());
final String key = ((TranslationTable) translationContainer
.getModel()).getKeyAt(row);
presenter.onTranslateRequest(key);
}

@Override
public void mouseEntered(final MouseEvent arg0) {
// IGNORE
}

@Override
public void mouseExited(final MouseEvent arg0) {
// IGNORE
}

@Override
public void mousePressed(final MouseEvent arg0) {
// IGNORE
}

@Override
public void mouseReleased(final MouseEvent arg0) {
// IGNORE
}

});
}

Expand Down Expand Up @@ -205,8 +150,7 @@ public void rebuildWith(final List<Translation> left, final List<Translation> ri

@Override
public void displayError(final String title, final String errorMessage) {
JOptionPane.showMessageDialog(window, errorMessage, title,
JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(window, errorMessage, title, ERROR_MESSAGE);
}

@Override
Expand Down

0 comments on commit 8743841

Please sign in to comment.