Skip to content

Commit

Permalink
Added plurals and arrays functions, wip on try catch in plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Liew Jun Tung committed May 27, 2015
1 parent 4cc9860 commit c00db6c
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 154 deletions.
82 changes: 53 additions & 29 deletions javafx_gui/src/main/groovy/org/pandawarrior/Controller.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package org.pandawarrior

import javafx.event.ActionEvent
import javafx.scene.control.Label
import javafx.scene.control.RadioButton
import javafx.scene.control.TextField
import javafx.scene.control.ToggleGroup
import javafx.scene.paint.Color
import javafx.stage.DirectoryChooser
import javafx.stage.FileChooser
Expand All @@ -22,6 +24,10 @@ class Controller {
public TextField c2x_txtXMLFolder
public Label c2x_indicator
public Label x2c_indicator
public RadioButton c2x_strings_radio
public ToggleGroup myToggleGroup
public RadioButton c2x_plurals_radio
public RadioButton c2x_arrays_radio

/**
* XML to CSV
Expand All @@ -35,35 +41,37 @@ class Controller {
}

public void x2c_saveDestination(ActionEvent actionEvent) {
FileChooser chooser = new FileChooser();
chooser.setTitle("Open File");
chooser.getExtensionFilters().add(
new FileChooser.ExtensionFilter("CSV File (*.csv)", "*.csv")
)
chooser.setInitialFileName("new.csv")
File file = chooser.showSaveDialog(new Stage());
DirectoryChooser chooser = new DirectoryChooser();
chooser.setTitle("Select Save Folder");
File file = chooser.showDialog(new Stage())
x2c_txtCSVFile.setText "${file.absolutePath}"

}

public void x2c_runXMLtoCSV(ActionEvent actionEvent) {
String folderPath = x2c_txtXMLFolder.getText()
String filePath = x2c_txtCSVFile.getText()
if (folderPath.length() > 0 && filePath.length() > 0) {
boolean result = ReadXml.parse(folderPath, filePath)
if (!result) {
x2c_indicator.setText("UNSUCESSFUL!")
x2c_indicator.setTextFill(Color.RED)
try{
String folderPath = x2c_txtXMLFolder.getText()
String filePath = x2c_txtCSVFile.getText()
if (folderPath.length() > 0 && filePath.length() > 0) {
boolean result = ReadXml.parseAll(folderPath, filePath)
if (!result) {
x2c_indicator.setText("UNSUCESSFUL!")
x2c_indicator.setTextFill(Color.RED)
} else {
x2c_txtCSVFile.clear()
x2c_txtXMLFolder.clear()
x2c_indicator.setText("SUCCESS!")
x2c_indicator.setTextFill(Color.GREEN)
}
} else {
x2c_txtCSVFile.clear()
x2c_txtXMLFolder.clear()
x2c_indicator.setText("SUCCESS!")
x2c_indicator.setTextFill(Color.GREEN)
x2c_indicator.setText("Please set folder or file location!")
x2c_indicator.setTextFill(Color.RED)
}
} else {
x2c_indicator.setText("Please set folder or file location!")
}catch (ArrayIndexOutOfBoundsException e){
x2c_indicator.setText("Error! Try adding a space or null in the empty values")
x2c_indicator.setTextFill(Color.RED)
}

}

public void c2x_openCSVFile(ActionEvent actionEvent) {
Expand All @@ -74,7 +82,6 @@ class Controller {
)
File file = chooser.showOpenDialog(new Stage());
c2x_txtCSVFile.setText "${file.absolutePath}"

}

public void c2x_saveDestination(ActionEvent actionEvent) {
Expand All @@ -85,16 +92,33 @@ class Controller {
}

public void c2x_runCSVtoXML(ActionEvent actionEvent) {
boolean result = WriteXml.parse(c2x_txtCSVFile.getText(), c2x_txtXMLFolder.getText())
if (!result) {
c2x_indicator.setText("UNSUCESSFUL!")
try{
String selected = (myToggleGroup.selectedToggle as RadioButton).text
boolean result
switch (selected){
case "arrays.xml":
result = WriteXml.parseArray(c2x_txtCSVFile.getText(), c2x_txtXMLFolder.getText(), WriteXml.ARRAY_FILE)
break;
case "plurals.xml":
result = WriteXml.parseArray(c2x_txtCSVFile.getText(), c2x_txtXMLFolder.getText(), WriteXml.PLURALS_FILE)
break;
default:
result = WriteXml.parse(c2x_txtCSVFile.getText(), c2x_txtXMLFolder.getText())
}
if (!result) {
c2x_indicator.setText("UNSUCESSFUL!")
c2x_indicator.setTextFill(Color.RED)
} else {
c2x_txtCSVFile.clear()
c2x_txtXMLFolder.clear()
c2x_indicator.setText("SUCCESS!")
c2x_indicator.setTextFill(Color.GREEN)
}
}catch (ArrayIndexOutOfBoundsException e){
c2x_indicator.setText("Error! Try adding a space or null in the empty values")
c2x_indicator.setTextFill(Color.RED)
} else {
c2x_txtCSVFile.clear()
c2x_txtXMLFolder.clear()
c2x_indicator.setText("SUCCESS!")
c2x_indicator.setTextFill(Color.GREEN)
}

}


Expand Down
57 changes: 24 additions & 33 deletions javafx_gui/src/main/resources/fxml/app.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,20 @@
<?import java.lang.*?>
<?import javafx.scene.control.*?>

<TabPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity " minWidth="-Infinity"
prefHeight="400.0" prefWidth="600.0" tabClosingPolicy="UNAVAILABLE" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.pandawarrior.Controller">
<TabPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" tabClosingPolicy="UNAVAILABLE" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.pandawarrior.Controller">
<tabs>
<Tab text="XML to CSV">
<content>
<Pane prefHeight="200.0" prefWidth="200.0">
<children>
<Button layoutX="282.0" layoutY="261.0" mnemonicParsing="false" onAction="#x2c_runXMLtoCSV"
text="OK"/>
<TextField layoutX="30.0" layoutY="87.0" prefHeight="26.0" prefWidth="449.0"
fx:id="x2c_txtXMLFolder"/>
<TextField layoutX="28.0" layoutY="171.0" prefHeight="26.0" prefWidth="453.0"
fx:id="x2c_txtCSVFile"/>
<Label layoutX="229.0" layoutY="48.0" text="Android Resource File"/>
<Label layoutX="240.0" layoutY="145.0" text="Destination Folder"/>
<Button layoutX="501.0" layoutY="87.0" mnemonicParsing="false" onAction="#x2c_openXMLFolder"
text="..."/>
<Button layoutX="501.0" layoutY="171.0" mnemonicParsing="false" onAction="#x2c_saveDestination"
text="..."/>
<Label layoutX="283.0" layoutY="218.0" text="" fx:id="x2c_indicator"/>
<Button layoutX="282.0" layoutY="230.0" mnemonicParsing="false" onAction="#x2c_runXMLtoCSV" text="OK" />
<TextField layoutX="30.0" layoutY="68.0" prefHeight="26.0" prefWidth="449.0" fx:id="x2c_txtXMLFolder" />
<TextField layoutX="28.0" layoutY="145.0" prefHeight="26.0" prefWidth="453.0" fx:id="x2c_txtCSVFile" />
<Label layoutX="220.0" layoutY="33.0" text="Android Resource Folder" />
<Label layoutX="240.0" layoutY="113.0" text="Destination Folder" />
<Button layoutX="501.0" layoutY="68.0" mnemonicParsing="false" onAction="#x2c_openXMLFolder" text="..." />
<Button layoutX="501.0" layoutY="145.0" mnemonicParsing="false" onAction="#x2c_saveDestination" text="..." />
<Label layoutX="282.0" layoutY="200.0" text="" fx:id="x2c_indicator" />
</children>
</Pane>
</content>
Expand All @@ -33,26 +26,24 @@
<content>
<Pane prefHeight="200.0" prefWidth="200.0">
<children>
<Button layoutX="282.0" layoutY="261.0" mnemonicParsing="false" onAction="#c2x_runCSVtoXML"
text="OK"/>
<TextField fx:id="c2x_txtCSVFile" layoutX="30.0" layoutY="87.0" prefHeight="26.0"
prefWidth="449.0"/>
<TextField fx:id="c2x_txtXMLFolder" layoutX="32.0" layoutY="170.0" prefHeight="26.0"
prefWidth="453.0"/>
<Label layoutX="276.0" layoutY="49.0" text="csv File"/>
<Label layoutX="220.0" layoutY="141.0" text="Android Resource Folder"/>
<Label layoutX="30.0" layoutY="208.0"
text="WARNING: &#10;It wil replace the current XML &#10;Files. Arrays, plurals&#10;WILL BE DELETED. &#10;It's better to save in an external&#10;folder and copy paste everything"
textFill="RED"/>
<Button layoutX="501.0" layoutY="87.0" mnemonicParsing="false" onAction="#c2x_openCSVFile"
text="..."/>
<Button layoutX="501.0" layoutY="171.0" mnemonicParsing="false" onAction="#c2x_saveDestination"
text="..."/>
<Label layoutX="283.0" layoutY="218.0" text="" fx:id="c2x_indicator"/>
<Button layoutX="280.0" layoutY="256.0" mnemonicParsing="false" onAction="#c2x_runCSVtoXML" text="OK" />
<TextField fx:id="c2x_txtCSVFile" layoutX="34.0" layoutY="61.0" prefHeight="26.0" prefWidth="449.0" />
<TextField fx:id="c2x_txtXMLFolder" layoutX="32.0" layoutY="145.0" prefHeight="26.0" prefWidth="453.0" />
<Label layoutX="275.0" layoutY="33.0" text="CSV File" />
<Label layoutX="219.0" layoutY="113.0" text="Android Resource Folder" />
<Button layoutX="501.0" layoutY="61.0" mnemonicParsing="false" onAction="#c2x_openCSVFile" text="..." />
<Button layoutX="501.0" layoutY="145.0" mnemonicParsing="false" onAction="#c2x_saveDestination" text="..." />
<Label fx:id="c2x_indicator" layoutX="290.0" layoutY="292.0" />
<fx:define>
<ToggleGroup fx:id="myToggleGroup"/>
</fx:define>
<RadioButton fx:id="c2x_strings_radio" layoutX="122.0" layoutY="209.0" mnemonicParsing="false" selected="true" text="strings.xml" toggleGroup="$myToggleGroup" />
<RadioButton fx:id="c2x_plurals_radio" layoutX="379.0" layoutY="209.0" mnemonicParsing="false" text="plurals.xml" toggleGroup="$myToggleGroup" />
<RadioButton fx:id="c2x_arrays_radio" layoutX="253.0" layoutY="209.0" mnemonicParsing="false" text="arrays.xml" toggleGroup="$myToggleGroup" />
<Label layoutX="266.0" layoutY="184.0" text="Convert to" />
</children>
</Pane>
</content>
</Tab>

</tabs>
</TabPane>

0 comments on commit c00db6c

Please sign in to comment.