Initial commit...
This commit is contained in:
85
Java Peojects/JPath/src/Controller.java
Normal file
85
Java Peojects/JPath/src/Controller.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.itdominator.jpath;
|
||||
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.event.ActionEvent;
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
import java.lang.Process;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class Controller {
|
||||
// Classes
|
||||
|
||||
// FXML Stuff
|
||||
@FXML private ListView<String> pathListView;
|
||||
@FXML private TextField newEntry;
|
||||
|
||||
// Generics
|
||||
private static ArrayList<String> history = new ArrayList<String>();
|
||||
private static ObservableList<String> paths;
|
||||
private static Process proc;
|
||||
|
||||
|
||||
@FXML void initialize() {
|
||||
assert pathListView != null : "fx:id=\"pathListView\" was not injected: check your FXML file 'JPath.fxml'.";
|
||||
assert newEntry != null : "fx:id=\"newEntry\" was not injected: check your FXML file 'JPath.fxml'.";
|
||||
|
||||
paths = FXCollections.observableArrayList(System.getenv("PATH").split(":"));
|
||||
pathListView.setItems(paths);
|
||||
}
|
||||
|
||||
@FXML void addEntryBttn(ActionEvent event) {
|
||||
addEntry();
|
||||
}
|
||||
|
||||
@FXML void addEntryEnter(KeyEvent event) {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
addEntry();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML void delEntry(ActionEvent event) {
|
||||
int index = pathListView.getSelectionModel().getSelectedIndex();
|
||||
if (index >= 0) {
|
||||
String path = pathListView.getItems().get(index);
|
||||
history.add(path);
|
||||
paths.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML void saveEnteriesToPATH(ActionEvent event) throws IOException {
|
||||
String PATH = "bash -c 'export PATH=\"" + String.join(":", paths) + "\" &'";
|
||||
System.out.println(PATH);
|
||||
Runtime.getRuntime().exec(PATH);
|
||||
}
|
||||
|
||||
@FXML void addBack(ActionEvent event) {
|
||||
if ((history.size() - 1) != -1) {
|
||||
String path = history.get(history.size() - 1);
|
||||
paths.addAll(path);
|
||||
history.remove(path);
|
||||
}
|
||||
}
|
||||
|
||||
private void addEntry() {
|
||||
String path = newEntry.getText();
|
||||
|
||||
if (!path.isEmpty()) {
|
||||
if (history.contains(path))
|
||||
history.remove(path);
|
||||
|
||||
paths.add(path);
|
||||
newEntry.setText("");
|
||||
}
|
||||
}
|
||||
}
|
38
Java Peojects/JPath/src/JPath.java
Normal file
38
Java Peojects/JPath/src/JPath.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.itdominator.jpath;
|
||||
|
||||
import com.itdominator.jpath.utils.JPathLogger;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class JPath extends Application {
|
||||
// Classes
|
||||
private JPathLogger jpathLogger = JPathLogger.getInstance();
|
||||
|
||||
@Override public void start(Stage stage) {
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("resources/JPath.fxml"));
|
||||
loader.setController(new Controller());
|
||||
loader.load();
|
||||
Scene scene = new Scene(loader.getRoot());
|
||||
scene.getStylesheets().add("/com/itdominator/jpath/resources/stylesheet.css");
|
||||
stage.setTitle("JPath");
|
||||
stage.setScene(scene);
|
||||
} catch (IOException startException) {
|
||||
String message = "\nJPath Failed to launch...\n";
|
||||
System.out.println(message + startException);
|
||||
jpathLogger.insertToLog(Level.SEVERE, message, startException);
|
||||
}
|
||||
// stage.getIcons().add(new Image(JPath.class.getResourceAsStream("resources/JPath.png")));
|
||||
stage.setResizable(true);
|
||||
stage.show();
|
||||
}
|
||||
public static void main(String[] args) { launch(args); }
|
||||
}
|
12
Java Peojects/JPath/src/unix_compile.sh
Executable file
12
Java Peojects/JPath/src/unix_compile.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
# -Xlint:unchecked
|
||||
function main() {
|
||||
javac *.java utils/*.java
|
||||
|
||||
rm ../com/itdominator/jpath/*.class
|
||||
rm ../com/itdominator/jpath/utils/*.class
|
||||
|
||||
mv *.class ../com/itdominator/jpath/
|
||||
mv utils/*.class ../com/itdominator/jpath/utils/
|
||||
}
|
||||
main;
|
31
Java Peojects/JPath/src/utils/JPathLogger.java
Normal file
31
Java Peojects/JPath/src/utils/JPathLogger.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.itdominator.jpath.utils;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class JPathLogger {
|
||||
private static JPathLogger jpathLogger = new JPathLogger();
|
||||
private Logger logger = Logger.getLogger(JPathLogger.class.getName());
|
||||
private boolean append = false;
|
||||
|
||||
// Instance passer
|
||||
public static JPathLogger getInstance() { return jpathLogger; }
|
||||
|
||||
// Init JPathLogger
|
||||
private JPathLogger() {
|
||||
try {
|
||||
FileHandler logFile = new FileHandler("jpath_error.log", append);
|
||||
logger.addHandler(logFile);
|
||||
} catch (IOException e) {
|
||||
insertToLog(Level.SEVERE, "Can not access error log file...", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void insertToLog(Level severity, String message, Exception stackTrace) {
|
||||
logger.log(severity, message, stackTrace);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user