Skip to content

Commit

Permalink
Added translation functionality
Browse files Browse the repository at this point in the history
Started to translate application to make it more available to more
people
  • Loading branch information
james2432 committed Sep 29, 2016
1 parent b76d734 commit 0856320
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 28 deletions.
2 changes: 1 addition & 1 deletion OSVUploadr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.osmcanada</groupId>
<artifactId>OSVUploadr</artifactId>
<version>0.1.2.2-ALPHA</version>
<version>0.1.2.2.1-ALPHA</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.nio.file.StandardCopyOption;
import java.time.Instant;
import java.util.HashMap;
import java.util.Locale;
import java.util.ResourceBundle;


/**
Expand All @@ -33,6 +35,8 @@ public class FolderCleaner {
int radius_threshold = 20; // Minimum turn radius a photo should move to not be considered a duplicate (degrees)
String duplicate_folder="duplicates";
JFMain info=null;
Locale l;
ResourceBundle r;

private double calc_distance(double lon1, double lat1, double lon2, double lat2){
//haversine formula
Expand Down Expand Up @@ -156,16 +160,27 @@ public void RemoveDuplicates(){
}
do_science();
if(info!=null){
info.SetInfoBoxText("Done");
try{
info.SetInfoBoxText(new String(r.getString("done").getBytes(),"UTF-8"));
}
catch(Exception ex)
{}
}
}

public void setInfoBox(JFMain frame){
info=frame;
}

public void setLocale(Locale locale){
l=locale;
r=ResourceBundle.getBundle("Bundle",l);
}

public FolderCleaner(String Folder){
_folder=Folder;
l=Locale.getDefault();
r=ResourceBundle.getBundle("Bundle",l);
}


Expand Down
7 changes: 5 additions & 2 deletions OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JFMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
package ca.osmcanada.osvuploadr;

import java.awt.BorderLayout;
import java.util.Locale;

/**
*
* @author Jamie Nadeau
*/
public class JFMain extends javax.swing.JFrame {
static JPInfoBox jib = new JPInfoBox();
static JPInfoBox jib;
/**
* Creates new form JFMain
*/
Expand Down Expand Up @@ -91,8 +92,10 @@ public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Locale l = Locale.getDefault();
JFMain jf =new JFMain();
JPMain jp = new JPMain();
JPMain jp = new JPMain(l);
jib=new JPInfoBox(l);
jp.setVisible(true);
jib.setVisible(false);
jf.add(jp,BorderLayout.NORTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="jlCurrentlyProc" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jlProcessing" pref="426" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
Expand All @@ -35,7 +35,7 @@
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jlCurrentlyProc" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jlProcessing" alignment="3" min="-2" pref="47" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="78" max="32767" attributes="0"/>
Expand All @@ -44,7 +44,7 @@
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Component class="javax.swing.JLabel" name="jlCurrentlyProc">
<Properties>
<Property name="text" type="java.lang.String" value="Currently Processing:"/>
</Properties>
Expand Down
26 changes: 20 additions & 6 deletions OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPInfoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
package ca.osmcanada.osvuploadr;

import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.UIManager;

/**
Expand All @@ -13,17 +15,29 @@
*/
public class JPInfoBox extends javax.swing.JPanel {

private Locale l;
private ResourceBundle r;
/**
* Creates new form JPInfoBox
*/
public JPInfoBox() {
public JPInfoBox(Locale locale) {
l=locale;
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception ex){}
initComponents();
r=ResourceBundle.getBundle("Bundle",l);
SetUILang();
}

private void SetUILang(){
try{
jlCurrentlyProc.setText(new String(r.getString("currently_processing").getBytes(),"UTF-8"));
}
catch(Exception ex)
{}
}
public void SetProcessingText(String str){
jlProcessing.setText(str);
}
Expand All @@ -36,20 +50,20 @@ public void SetProcessingText(String str){
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
jlCurrentlyProc = new javax.swing.JLabel();
jlProcessing = new javax.swing.JLabel();

setPreferredSize(new java.awt.Dimension(623, 150));

jLabel1.setText("Currently Processing:");
jlCurrentlyProc.setText("Currently Processing:");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addComponent(jlCurrentlyProc)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jlProcessing, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE)
.addContainerGap())
Expand All @@ -59,15 +73,15 @@ private void initComponents() {
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jlCurrentlyProc)
.addComponent(jlProcessing, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(78, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jlCurrentlyProc;
private javax.swing.JLabel jlProcessing;
// End of variables declaration//GEN-END:variables
}
6 changes: 3 additions & 3 deletions OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.form
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel1" min="-2" pref="79" max="-2" attributes="0"/>
<Component id="jlDirectories" min="-2" pref="79" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<Component id="listDir" min="-2" pref="456" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
Expand Down Expand Up @@ -49,7 +49,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="jlDirectories" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="listDir" min="-2" pref="222" max="-2" attributes="0"/>
Expand Down Expand Up @@ -96,7 +96,7 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="listDirActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Component class="javax.swing.JLabel" name="jlDirectories">
<Properties>
<Property name="text" type="java.lang.String" value="Directories"/>
</Properties>
Expand Down
58 changes: 46 additions & 12 deletions OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
import java.util.regex.Pattern;
import ca.osmcanada.osvuploadr.Utils.*;
import ca.osmcanada.osvuploadr.struct.PageContent;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Locale;
import java.util.ResourceBundle;
import org.apache.http.client.HttpClient;
import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
Expand All @@ -74,17 +77,43 @@ public class JPMain extends javax.swing.JPanel {
private final String API_KEY = "rBWV8Eaottv44tXfdLofdNvVemHOL62Lsutpb9tw";
private final String API_SECRET = "rpmeZIp49sEjjcz91X9dsY0vD1PpEduixuPy8T6S";
private String last_dir ="";
private Locale l;
private ResourceBundle r;

UploadManager um;
/**
* Creates new form JPMain
*/
public JPMain() {
public JPMain(Locale locale) {
l = locale;
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception ex){}
initComponents();
try{
r=ResourceBundle.getBundle("Bundle",l);
}
catch(Exception ex){
System.out.println(ex.toString());
}

SetUILang();

}

private void SetUILang(){
try{
jlDirectories.setText(new String(r.getString("Directories").getBytes(),"UTF-8"));
jbAdd.setText(new String(r.getString("Add_Folder").getBytes(),"UTF-8"));
jbRemove.setText(new String(r.getString("Remove_Folder").getBytes(),"UTF-8"));
jbRemoveDup.setText(new String(r.getString("Remove_Duplicates").getBytes(),"UTF-8"));
jbUpload.setText(new String(r.getString("Upload").getBytes(),"UTF-8"));
jbExit.setText(new String(r.getString("Exit").getBytes(),"UTF-8"));
}
catch(Exception ex){

}
}

public String GetOSMUser(String usr, String psw)throws IOException{
Expand Down Expand Up @@ -208,7 +237,7 @@ public String GetOSMUser() throws IOException{
String url = service.getAuthorizationUrl(requestToken);
Helper.OpenBrowser(java.net.URI.create(url));
//java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
String pin_code = JOptionPane.showInputDialog(null, "Authorization window has opened, please paste authorization code below once authorized.\nWith out the \".\" at the end", "Authorization Required", JOptionPane.INFORMATION_MESSAGE);
String pin_code = JOptionPane.showInputDialog(null, new String(r.getString("auth_window_opened").getBytes(),"UTF-8"), new String(r.getString("auth_required").getBytes(),"UTF-8"), JOptionPane.INFORMATION_MESSAGE);
final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, pin_code);
//final OAuthRequest request = new OAuthRequest(Verb.GET, BASE_URL + "api/0.6/user/details", service);
//service.signRequest(accessToken, request);
Expand Down Expand Up @@ -724,7 +753,7 @@ private void initComponents() {

jbAdd = new javax.swing.JButton();
listDir = new java.awt.List();
jLabel1 = new javax.swing.JLabel();
jlDirectories = new javax.swing.JLabel();
jbRemoveDup = new javax.swing.JButton();
jbUpload = new javax.swing.JButton();
jbExit = new javax.swing.JButton();
Expand All @@ -747,7 +776,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

jLabel1.setText("Directories");
jlDirectories.setText("Directories");

jbRemoveDup.setText("Remove Duplicates");
jbRemoveDup.addActionListener(new java.awt.event.ActionListener() {
Expand Down Expand Up @@ -788,7 +817,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jlDirectories, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(listDir, javax.swing.GroupLayout.PREFERRED_SIZE, 456, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
Expand All @@ -809,7 +838,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jLabel1)
.addComponent(jlDirectories)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(listDir, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
Expand Down Expand Up @@ -837,14 +866,15 @@ private void jbExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:
}//GEN-LAST:event_jbExitActionPerformed

private void jbAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAddActionPerformed
try{
JFileChooser fc = new JFileChooser();
if(!last_dir.isEmpty()){
fc.setCurrentDirectory(new java.io.File(last_dir)); // start at application current directory
}
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showSaveDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
int response = JOptionPane.showConfirmDialog(null, "Do you wish to add all immediate subfolders of this folder?", "Add subfolders?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
int response = JOptionPane.showConfirmDialog(null, new String(r.getString("immediate_sub_folders").getBytes(),"UTF-8"), new String(r.getString("add_subfolders").getBytes(),"UTF-8"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(response == JOptionPane.NO_OPTION){
File folder = fc.getSelectedFile();
listDir.add(folder.getPath());
Expand All @@ -865,6 +895,9 @@ public boolean accept(File current, String name){
}
}
}
}
catch(UnsupportedEncodingException ex)
{}
}//GEN-LAST:event_jbAddActionPerformed

private void jbRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRemoveActionPerformed
Expand Down Expand Up @@ -894,8 +927,8 @@ private void jbUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
if(!id.exists())
{
try{
String[] buttons={"Automatically","Manually","Cancel"};
int rc = JOptionPane.showOptionDialog(null,"You must login to OSM to continue the upload. Would you like the automated version or the manual version?","Confirmation",JOptionPane.INFORMATION_MESSAGE,0,null,buttons,buttons[0]);
String[] buttons={new String(r.getString("automatically").getBytes(),"UTF-8"),new String(r.getString("manually").getBytes(),"UTF-8"),new String(r.getString("cancel").getBytes(),"UTF-8")};
int rc = JOptionPane.showOptionDialog(null,new String(r.getString("login_to_osm").getBytes(),"UTF-8"),new String(r.getString("confirmation").getBytes(),"UTF-8"),JOptionPane.INFORMATION_MESSAGE,0,null,buttons,buttons[0]);
String token="";
System.out.println("GetOSMUser");
switch(rc){
Expand All @@ -904,15 +937,15 @@ private void jbUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
String psw = "";
JTextField tf = new JTextField();
JPasswordField pf = new JPasswordField();
rc = JOptionPane.showConfirmDialog(null,tf,"Enter email address or OSM username", JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE);
rc = JOptionPane.showConfirmDialog(null,tf,new String(r.getString("email_osm_usr").getBytes(),"UTF-8"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE);
if(rc == JOptionPane.OK_OPTION){
usr = tf.getText();
}
else{
return;
}

rc = JOptionPane.showConfirmDialog(null,pf,"Please enter password", JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE);
rc = JOptionPane.showConfirmDialog(null,pf,new String(r.getString("enter_password").getBytes(),"UTF-8"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE);
if(rc == JOptionPane.OK_OPTION){
psw = new String(pf.getPassword());
}
Expand Down Expand Up @@ -973,6 +1006,7 @@ private void jbRemoveDupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
Thread t = new Thread(){
public void run(){
FolderCleaner fc = new FolderCleaner(item);
fc.setLocale(l);
fc.setInfoBox(topframe);
fc.RemoveDuplicates();
}
Expand All @@ -983,12 +1017,12 @@ public void run(){


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
private javax.swing.JButton jbAdd;
private javax.swing.JButton jbExit;
private javax.swing.JButton jbRemove;
private javax.swing.JButton jbRemoveDup;
private javax.swing.JButton jbUpload;
private javax.swing.JLabel jlDirectories;
private java.awt.List listDir;
// End of variables declaration//GEN-END:variables
}
Loading

0 comments on commit 0856320

Please sign in to comment.