github: https://github.com/Al-assad/dependency_converter
项目结构:

build.gradle
group 'site.assad'
version '1.0'
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'groovy'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy:2.4.10'
compile 'org.codehaus.groovy:groovy-xml:2.4.10'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
view/App.kt
package view
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.stage.Stage
/**
* Author: Al-assad 余林颖
* E-mail: [email protected]
* Date: 2017/9/26 16:23
* Description:
*/
class App: Application() {
override fun start(primaryStage: Stage?) {
val root: Parent = FXMLLoader.load<Parent>(javaClass.classLoader.getResource("main.fxml")); //加载fxml视图资源
primaryStage!!.title = "Coord Converter";
primaryStage.scene = Scene(root,800.0,600.0);
primaryStage.show();
}
companion object {
@JvmStatic
fun main(args:Array<String>){
launch(App::class.java);
}
}
}
view/Controller.kt
package view
import core.GradleParser
import core.StrParser
import core.XMLParser
import javafx.fxml.FXML
import javafx.scene.control.*
/**
* Author: Al-assad 余林颖
* E-mail: [email protected]
* Date: 2017/9/25 19:59
* Description:
*/
class Controller{
@FXML
private lateinit var ftPatternP1: TextField
@FXML
private lateinit var tb1P1:ToggleButton
@FXML
private lateinit var tb2P1:ToggleButton
@FXML
private lateinit var tb3P1:ToggleButton
@FXML
private lateinit var tb4P1:ToggleButton
@FXML
private lateinit var tb1P2:ToggleButton
@FXML
private lateinit var tb2P2:ToggleButton
@FXML
private lateinit var tb3P2:ToggleButton
@FXML
private lateinit var tb4P2:ToggleButton
@FXML
private lateinit var tb1P3:ToggleButton
@FXML
private lateinit var tb2P3:ToggleButton
@FXML
private lateinit var tb3P3:ToggleButton
@FXML
private lateinit var tb4P3:ToggleButton
@FXML
private lateinit var taInputP1:TextArea
@FXML
private lateinit var taInputP2:TextArea
@FXML
private lateinit var taInputP3:TextArea
@FXML
private lateinit var taOutputP1:TextArea
@FXML
private lateinit var taOutputP2:TextArea
@FXML
private lateinit var taOutputP3:TextArea
private lateinit var btList1:Array<ToggleButton>;
private lateinit var btList2:Array<ToggleButton>;
private lateinit var btList3:Array<ToggleButton>;
//初始化
fun initialize(){
btList1 = arrayOf(tb1P1,tb2P1,tb3P1,tb4P1);
btList2 = arrayOf(tb1P2,tb2P2,tb3P2,tb4P2);
btList3 = arrayOf(tb1P3,tb2P3,tb3P3,tb4P3);
val group1 = ToggleGroup();
for(button in btList1){
button.setSelected(false);
button.setToggleGroup(group1);
}
val group2 = ToggleGroup();
for(button in btList2){
button.setSelected(false);
button.setToggleGroup(group2);
}
val group3 = ToggleGroup();
for(button in btList3){
button.setSelected(false);
button.setToggleGroup(group3);
}
//添加ToogleButton事件
//页面1
btList1[0].setOnAction { event ->
if(!ftPatternP1.text.trim().isEmpty() && !taInputP1.text.trim().isEmpty()){
val parser = StrParser(ftPatternP1.text.trim());
parser.complie(taInputP1.text.trim());
val result = parser.toXML(false);
taOutputP1.text = result;
}
};
btList1[1].setOnAction { event ->
if(!ftPatternP1.text.trim().isEmpty() && !taInputP1.text.trim().isEmpty()){
val parser = StrParser(ftPatternP1.text.trim());
parser.complie(taInputP1.text.trim());
val result = parser.toXML(true);
taOutputP1.text = result;
}
};
btList1[2].setOnAction { event ->
if(!ftPatternP1.text.trim().isEmpty() && !taInputP1.text.trim().isEmpty()){
val parser = StrParser(ftPatternP1.text.trim());
parser.complie(taInputP1.text.trim());
val result = parser.toGradle(false);
taOutputP1.text = result;
}
};
btList1[3].setOnAction { event ->
if(!ftPatternP1.text.trim().isEmpty() && !taInputP1.text.trim().isEmpty()){
val parser = StrParser(ftPatternP1.text.trim());
parser.complie(taInputP1.text.trim());
val result = parser.toGradle(true);
taOutputP1.text = result;
}
};
//页面2
btList2[0].setOnAction { event ->
if(!taInputP2.text.trim().isEmpty()){
val parser = XMLParser();
parser.compile(taInputP2.text.trim());
val result = parser.toXML(false);
taOutputP2.text = result;
}
};
btList2[1].setOnAction { event ->
if(!taInputP2.text.trim().isEmpty()){
val parser = XMLParser();
parser.compile(taInputP2.text.trim());
val result = parser.toXML(true);
taOutputP2.text = result;
}
};
btList2[2].setOnAction { event ->
if(!taInputP2.text.trim().isEmpty()){
val parser = XMLParser();
parser.compile(taInputP2.text.trim());
val result = parser.toGradle(false);
taOutputP2.text = result;
}
};
btList2[3].setOnAction { event ->
if(!taInputP2.text.trim().isEmpty()){
val parser = XMLParser();
parser.compile(taInputP2.text.trim());
val result = parser.toGradle(true);
taOutputP2.text = result;
}
};
//页面3
btList3[0].setOnAction { event ->
if(!taInputP3.text.trim().isEmpty()){
val parser = GradleParser();
parser.compile(taInputP3.text.trim());
val result = parser.toXML(false);
taOutputP3.text = result;
}
};
btList3[1].setOnAction { event ->
if(!taInputP3.text.trim().isEmpty()){
val parser = GradleParser();
parser.compile(taInputP3.text.trim());
val result = parser.toXML(true);
taOutputP3.text = result;
}
};
btList3[2].setOnAction { event ->
if(!taInputP3.text.trim().isEmpty()){
val parser = GradleParser();
parser.compile(taInputP3.text.trim());
val result = parser.toGradle(false);
taOutputP3.text = result;
}
};
btList3[3].setOnAction { event ->
if(!taInputP3.text.trim().isEmpty()){
val parser = GradleParser();
parser.compile(taInputP3.text.trim());
val result = parser.toGradle(true);
taOutputP3.text = result;
}
};
}
}
main.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<TabPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1000.0" prefWidth="1200.0" tabClosingPolicy="UNAVAILABLE" xmlns="<http://javafx.com/javafx/8.0.121>" xmlns:fx="<http://javafx.com/fxml/1>" fx:controller="view.Controller">
<tabs>
<Tab text="str parser">
<content>
<BorderPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<top>
<VBox prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<Label text="normal string → pom.xml/build.gradle">
<padding>
<Insets bottom="10.0" left="20.0" top="10.0" />
</padding>
<font>
<Font name="Book Antiqua" size="18.0" />
</font>
</Label>
<VBox spacing="15.0">
<children>
<Separator prefWidth="200.0" />
<FlowPane hgap="15.0">
<children>
<Label text="Pattern" />
<TextField fx:id="ftPatternP1" text="g:a:v" />
</children>
</FlowPane>
<FlowPane>
<children>
<Label text="coverting to">
<FlowPane.margin>
<Insets right="20.0" />
</FlowPane.margin>
</Label>
<ToggleButton fx:id="tb1P1" mnemonicParsing="false" text="pom.xml" />
<ToggleButton fx:id="tb2P1" mnemonicParsing="false" text="pom.xml (param)" />
<ToggleButton fx:id="tb3P1" mnemonicParsing="false" text="build.gradle" />
<ToggleButton fx:id="tb4P1" mnemonicParsing="false" text="build.gradle (param)" />
</children>
</FlowPane>
</children>
<padding>
<Insets bottom="10.0" left="15.0" right="5.0" />
</padding>
</VBox>
<Separator prefWidth="200.0" />
</children>
</VBox>
</top>
<center>
<HBox alignment="TOP_CENTER" spacing="10.0" BorderPane.alignment="CENTER">
<children>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" spacing="5.0">
<children>
<Label text="Input" />
<ScrollPane maxHeight="-Infinity" maxWidth="-Infinity">
<content>
<TextArea fx:id="taInputP1" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="800.0" prefWidth="600.0">
<font>
<Font name="Consolas" size="12.0" />
</font></TextArea>
</content>
</ScrollPane>
</children>
</VBox>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" spacing="5.0">
<children>
<Label text="output" />
<ScrollPane maxHeight="-Infinity" maxWidth="-Infinity">
<content>
<TextArea fx:id="taOutputP1" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="800.0" prefWidth="600.0">
<font>
<Font name="Consolas" size="12.0" />
</font></TextArea>
</content>
</ScrollPane>
</children>
</VBox>
</children>
<opaqueInsets>
<Insets bottom="10.0" left="10.0" right="10.0" />
</opaqueInsets>
<padding>
<Insets bottom="15.0" left="1.0" right="1.0" top="5.0" />
</padding>
</HBox>
</center>
</BorderPane>
</content>
</Tab>
<Tab text=" xml parser">
<content>
<BorderPane>
<top>
<VBox prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<Label text="pom.xml → pom.xml(param)/build.gradle">
<padding>
<Insets bottom="10.0" left="20.0" top="10.0" />
</padding>
<font>
<Font name="Book Antiqua" size="18.0" />
</font>
</Label>
<VBox spacing="15.0">
<children>
<Separator prefWidth="200.0" />
<FlowPane prefWrapLength="0.0">
<children>
<Label text="coverting to">
<FlowPane.margin>
<Insets right="10.0" />
</FlowPane.margin>
</Label>
<ToggleButton fx:id="tb1P2" mnemonicParsing="false" text="pom.xml" />
<ToggleButton fx:id="tb2P2" mnemonicParsing="false" text="pom.xml (param)" />
<ToggleButton fx:id="tb3P2" mnemonicParsing="false" text="build.gradle" />
<ToggleButton fx:id="tb4P2" mnemonicParsing="false" text="build.gradle (param)" />
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</FlowPane>
</children>
<padding>
<Insets bottom="10.0" left="15.0" right="5.0" />
</padding>
</VBox>
<Separator prefWidth="200.0" />
</children>
</VBox>
</top>
<center>
<HBox alignment="TOP_CENTER" spacing="10.0" BorderPane.alignment="CENTER">
<children>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" spacing="5.0">
<children>
<Label text="Input" />
<ScrollPane maxHeight="-Infinity" maxWidth="-Infinity">
<content>
<TextArea fx:id="taInputP2" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="800.0" prefWidth="600.0" wrapText="true" />
</content>
</ScrollPane>
</children>
</VBox>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" spacing="5.0">
<children>
<Label text="output" />
<ScrollPane maxHeight="-Infinity" maxWidth="-Infinity">
<content>
<TextArea fx:id="taOutputP2" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="800.0" prefWidth="600.0" wrapText="true" />
</content>
</ScrollPane>
</children>
</VBox>
</children>
<opaqueInsets>
<Insets bottom="10.0" left="10.0" right="10.0" />
</opaqueInsets>
<padding>
<Insets bottom="15.0" left="1.0" right="1.0" top="5.0" />
</padding>
</HBox>
</center>
</BorderPane>
</content>
</Tab>
<Tab text="grdale parser">
<content>
<BorderPane>
<top>
<VBox BorderPane.alignment="CENTER">
<children>
<Label text="build.gradle→ pom.xml/build.gradle (param)">
<padding>
<Insets bottom="10.0" left="20.0" top="10.0" />
</padding>
<font>
<Font name="Book Antiqua" size="18.0" />
</font>
</Label>
<VBox spacing="15.0">
<children>
<Separator prefWidth="200.0" />
<FlowPane prefWrapLength="0.0">
<children>
<Label text="coverting to">
<FlowPane.margin>
<Insets right="10.0" />
</FlowPane.margin>
</Label>
<ToggleButton fx:id="tb1P3" mnemonicParsing="false" text="pom.xml" />
<ToggleButton fx:id="tb2P3" mnemonicParsing="false" text="pom.xml (param)" />
<ToggleButton fx:id="tb3P3" mnemonicParsing="false" text="build.gradle" />
<ToggleButton fx:id="tb4P3" mnemonicParsing="false" text="build.gradle (param)" />
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</FlowPane>
</children>
<padding>
<Insets bottom="10.0" left="15.0" right="5.0" />
</padding>
</VBox>
<Separator prefWidth="200.0" />
</children>
</VBox>
</top>
<center>
<HBox alignment="TOP_CENTER" spacing="10.0" BorderPane.alignment="CENTER">
<children>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" spacing="5.0">
<children>
<Label text="Input" />
<ScrollPane maxHeight="-Infinity" maxWidth="-Infinity">
<content>
<TextArea fx:id="taInputP3" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="800.0" prefWidth="600.0" wrapText="true" />
</content>
</ScrollPane>
</children>
</VBox>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" spacing="5.0">
<children>
<Label text="output" />
<ScrollPane maxHeight="-Infinity" maxWidth="-Infinity">
<content>
<TextArea fx:id="taOutputP3" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="800.0" prefWidth="600.0" wrapText="true" />
</content>
</ScrollPane>
</children>
</VBox>
</children>
<opaqueInsets>
<Insets bottom="10.0" left="10.0" right="10.0" />
</opaqueInsets>
<padding>
<Insets bottom="15.0" left="1.0" right="1.0" top="5.0" />
</padding>
</HBox>
</center>
</BorderPane>
</content>
</Tab>
</tabs>
</TabPane>