Skip to content

Commit

Permalink
finished with polishing the guis
Browse files Browse the repository at this point in the history
  • Loading branch information
Liew Jun Tung committed May 28, 2015
1 parent 14e5d92 commit b6ae309
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
Expand Up @@ -110,7 +110,7 @@ class Controller {
c2x_indicator.setTextFill(Color.RED)
} else {
c2x_txtCSVFile.clear()
c2x_txtXMLFolder.clear()
// c2x_txtXMLFolder.clear()
c2x_indicator.setText("SUCCESS!")
c2x_indicator.setTextFill(Color.GREEN)
}
Expand Down
6 changes: 2 additions & 4 deletions plugin/META-INF/plugin.xml
@@ -1,15 +1,13 @@
<idea-plugin version="2">
<id>com.pandawarrior.androidXMLConverter</id>
<name>Android Strings.xml To CSV Converter</name>
<version>1.0</version>
<version>1.1</version>
<vendor email="pandawarrior91@gmail.com" url="https://github.com/pandawarrior91">Liew Jun Tung</vendor>

<description><![CDATA[
<h1>Android XML to CSV converter.</h1><br>
<p>Allows you to translate strings.xml into different languages in spreadsheet form, and vice versa.</p>
<p>Allows you to translate strings.xml, arrays.xml, plurals.xml into different languages in spreadsheet form, and vice versa.</p>
<p><em>NOTE<em></p>
<p>It can't convert plurals and arrays, and it will override you current xml strings if you select your android res</br>
folder when you convert CSV to XML.</p>
<p>You can access the plugin from the "Other" tab besides "Help" at the toolbar</p>
</br>
<a href ="https://github.com/pandawarrior91/Android-strings-xml-csv-converter">GitHub</a>
Expand Down
46 changes: 28 additions & 18 deletions plugin/src/org/pandawarrior/androidXMLConverter/GUI.java
Expand Up @@ -39,27 +39,32 @@ public class GUI extends DialogWrapper {
private String currentFolder;
private String selected;
private final static String ERROR_MSG1 = "Error! Your csv file might have a data that is empty. use 'null' or ' ' to replace it.";

public GUI(Project project, String initialFolder) {
super(project, true);
this.setTitle("Android Parser");
this.setSize(480, 300);
this.setResizable(true);
// setContentPane(rootPane);
// setVisible(true);
// setContentPane(rootPane);
// setVisible(true);
//setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
currentFolder = initialFolder;

xcReadField.setText(currentFolder);
xcReadBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
xcReadField.setText(chooseFolder());
String folder = chooseFolder();
if (folder != null)
xcReadField.setText(folder);
}
});
xcWriteBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
xcWriteField.setText(chooseFolder());
String folder = chooseFolder();
if (folder != null)
xcWriteField.setText(folder);
}
});
xcOKButton.addActionListener(new ActionListener() {
Expand All @@ -73,7 +78,7 @@ public void actionPerformed(ActionEvent e) {
xcWriteField.setText("");
xcLabel.setText("SUCCESS!");
xcLabel.setForeground(JBColor.GREEN);
}catch (ArrayIndexOutOfBoundsException e1){
} catch (ArrayIndexOutOfBoundsException e1) {
xcLabel.setText(ERROR_MSG1);
xcLabel.setForeground(JBColor.RED);
}
Expand All @@ -83,13 +88,17 @@ public void actionPerformed(ActionEvent e) {
cxReadBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cxReadField.setText(chooseCSV());
String csv = chooseCSV();
if (csv != null)
cxReadField.setText(csv);
}
});
cxWriteBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cxWriteField.setText(chooseFolder());
String folder = chooseFolder();
if (folder != null)
cxWriteField.setText(folder);
}
});
cxOKButton.addActionListener(new ActionListener() {
Expand All @@ -100,10 +109,10 @@ public void actionPerformed(ActionEvent e) {
String folder = cxWriteField.getText();
writeXML(folder, csv);
cxReadField.setText("");
cxWriteField.setText("");
// cxWriteField.setText("");
cxLabel.setText("SUCCESS!");
cxLabel.setForeground(JBColor.GREEN);
} catch (ArrayIndexOutOfBoundsException e1){
} catch (ArrayIndexOutOfBoundsException e1) {
cxLabel.setText(ERROR_MSG1);
cxLabel.setForeground(JBColor.RED);
}
Expand Down Expand Up @@ -134,18 +143,19 @@ public void actionPerformed(ActionEvent e) {
this.init();

}

private String chooseFolder() {
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = jFileChooser.showOpenDialog(getContentPane());
if (returnVal == JFileChooser.APPROVE_OPTION) {
return jFileChooser.getSelectedFile().getAbsolutePath();
} else {
return "";
return null;
}
}

private String saveCSV(){
private String saveCSV() {
JFileChooser jFileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("CSV FILES", "csv", "comma separate value");
jFileChooser.setFileFilter(filter);
Expand All @@ -156,7 +166,7 @@ private String saveCSV(){
if (returnVal == JFileChooser.APPROVE_OPTION) {
return jFileChooser.getSelectedFile().getAbsolutePath();
} else {
return "";
return null;
}
}

Expand All @@ -169,27 +179,27 @@ private String chooseCSV() {
if (returnVal == JFileChooser.APPROVE_OPTION) {
return jFileChooser.getSelectedFile().getAbsolutePath();
} else {
return "";
return null;
}
}

private void writeXML(final String folder, final String csv) throws ArrayIndexOutOfBoundsException{
private void writeXML(final String folder, final String csv) throws ArrayIndexOutOfBoundsException {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (selected.equals("strings.xml")){
if (selected.equals("strings.xml")) {
WriteXml.parse(csv, folder);
}else if(selected.equals("arrays.xml")){
} else if (selected.equals("arrays.xml")) {
WriteXml.parseArray(csv, folder, WriteXml.getARRAY_FILE());
}else if (selected.equals("plurals.xml")){
} else if (selected.equals("plurals.xml")) {
WriteXml.parseArray(csv, folder, WriteXml.getPLURALS_FILE());
}
}
});

}

private void readXML(final String folder, final String csv) throws ArrayIndexOutOfBoundsException{
private void readXML(final String folder, final String csv) throws ArrayIndexOutOfBoundsException {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Expand Down

0 comments on commit b6ae309

Please sign in to comment.