Added python project; fixed spelling of folder

This commit is contained in:
2023-09-30 16:09:14 -05:00
parent 1f23cb73d1
commit 6bf66c5916
1075 changed files with 2165 additions and 0 deletions

View File

@@ -0,0 +1,204 @@
package com.itdominator.csvviewer;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.control.Label;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.Separator;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.AnchorPane;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.collections.ObservableList;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.collections.FXCollections;
import java.util.concurrent.atomic.AtomicLong;
import java.io.LineNumberReader;
import java.io.FileReader;
import java.io.File;
import javafx.concurrent.Task;
import javafx.application.Platform; // part of application
import javafx.scene.paint.Color;
public class CSVView extends Application {
// Classes
private Controller controller = new Controller();
private SelectFile selectFile = new SelectFile();
// Generics
private Spinner<Integer> startLineSpinner = new Spinner<Integer>(),
endLineSpinner = new Spinner<Integer>();
ChoiceBox<String> delimiterChoiceBox = new ChoiceBox<String>();
private final TableView<Record> tableView = new TableView<>();
private AnchorPane root = new AnchorPane();
private TextField fileOpenedTextField = new TextField();
private TextArea textArea = new TextArea();
private Separator separatorH = new Separator(),
separatorH2 = new Separator(),
separatorH3 = new Separator();
private VBox menuVBox = new VBox(), vBox = new VBox();
private HBox menuHBox = new HBox();
private Label startLbl = new Label("Start Line:"),
endLbl = new Label("End Line:"),
lineCountLbl = new Label("Line Count:"),
lineCountInsertLbl = new Label();
private Button openBttn = new Button("Open");
private Button clearInfoAreaBttn = new Button("Clear");
private ObservableList<String> delimiterList = FXCollections.observableArrayList(",", ";", " ", "|", ":");
private SpinnerValueFactory<Integer> valueFactory1 =
new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 4000000, 0),
valueFactory2 =
new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 4000000, 45);
private LineNumberReader lnr;
int start, end;
File selectedFile;
@Override
public void start(Stage stage) {
separatorH.setMinWidth(20.0);
separatorH2.setMinWidth(20.0);
separatorH3.setMinWidth(20.0);
delimiterChoiceBox.setItems(delimiterList);
delimiterChoiceBox.setValue(",");
startLineSpinner.setValueFactory(valueFactory1);
endLineSpinner.setValueFactory(valueFactory2);
startLineSpinner.setEditable(true);
endLineSpinner.setEditable(true);
tableView.setItems(controller.getDataList());
tableView.getSelectionModel().setCellSelectionEnabled(true);
root.setTopAnchor(menuHBox, 0.0);
root.setLeftAnchor(menuHBox, 0.0);
root.setRightAnchor(menuHBox, 5.0);
root.setTopAnchor(tableView, 50.0);
root.setLeftAnchor(tableView, 0.0);
root.setRightAnchor(tableView, 0.0);
root.setBottomAnchor(tableView, 200.0);
root.setLeftAnchor(vBox, 0.0);
root.setRightAnchor(vBox, 0.0);
root.setBottomAnchor(vBox, 0.0);
root.setTopAnchor(delimiterChoiceBox, 0.0);
root.setRightAnchor(delimiterChoiceBox, 0.0);
menuHBox.getChildren().addAll(openBttn, separatorH, startLbl,
startLineSpinner, separatorH2,
endLbl, endLineSpinner, separatorH3,
lineCountLbl, lineCountInsertLbl);
vBox.getChildren().addAll(clearInfoAreaBttn, textArea);
menuVBox.getChildren().addAll(menuHBox, fileOpenedTextField);
root.getChildren().addAll(menuVBox, delimiterChoiceBox, tableView, vBox);
stage.setTitle("CSV Viewer");
stage.setScene(new Scene(root, 800, 600));
stage.show();
setClickEevents();
}
public void setClickEevents() {
// Open file
openBttn.setOnAction(e -> {
String title = "Open CSV File",
delimiter = delimiterChoiceBox.getValue();
String[] filters = {"CSV Files", "*.csv", "*.CSV", "*.txt", "*.TXT"};
selectFile.selecteFile(title, filters); // title, filters if any
selectedFile = selectFile.getSelectedFile();
if (selectedFile != null) {
fileOpenedTextField.setText("" + selectedFile);
start = startLineSpinner.getValue();
end = endLineSpinner.getValue();
lineCountInsertLbl.setText("");
tableView.getItems().clear();
tableView.getColumns().clear();
controller.readCSV(tableView, "" + selectedFile, delimiter, start, end);
lineCountInsertLbl.setTextFill(Color.web("#0076a3"));
lineCountInsertLbl.setText("Calculating...");
Task getDir = new Task<Void>() {
@Override public Void call() {
int lineCount = 0;
try {
lnr = new LineNumberReader(new FileReader(selectedFile));
lnr.skip(Long.MAX_VALUE);
lineCount = lnr.getLineNumber() + 1;
} catch (Throwable eve) {
System.out.println("" + eve);
}
final int c = lineCount;
Platform.runLater(new Runnable() {
@Override public void run() {
lineCountInsertLbl.setTextFill(Color.web("#48A300"));
lineCountInsertLbl.setText("" + c);
}
});
return null;
}};
new Thread(getDir).start();
}
});
// clear textAreare box
clearInfoAreaBttn.setOnAction(e -> {
textArea.clear();
});
tableView.setOnMouseClicked(mouse -> {
if (mouse.getClickCount() == 2 && !mouse.isConsumed()) {
mouse.consume();
setToClipBoardAndInfoArea();
}
});
// ctrl + c
tableView.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.C && e.isControlDown())
setToClipBoardAndInfoArea();
});
}
private void setToClipBoardAndInfoArea() {
StringBuilder clipboardString = new StringBuilder();
ObservableList<TablePosition> positionList = tableView.getSelectionModel().getSelectedCells();
int prevRow = -1;
for (TablePosition position : positionList) {
int row = position.getRow(), col = position.getColumn();
Object cell = (Object) tableView.getColumns().get(col).getCellData(row);
if (cell == null) { cell = ""; }
if (prevRow == row) {
clipboardString.append('\t');
} else if (prevRow != -1) {
clipboardString.append('\n');
}
String text = cell.toString();
clipboardString.append(text);
prevRow = row;
}
final ClipboardContent clipboardContent = new ClipboardContent();
clipboardContent.putString(clipboardString.toString());
Clipboard.getSystemClipboard().setContent(clipboardContent);
textArea.appendText(clipboardString.toString() + "\n");
}
public static void main(String[] args) { launch(args); }
}

View File

@@ -0,0 +1,72 @@
package com.itdominator.csvviewer;
import javafx.collections.ObservableList;
import javafx.collections.FXCollections;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.logging.Logger;
import java.util.logging.Level;
public class Controller {
// Classes
private Record record;
// Generics
private final ObservableList<Record> dataList = FXCollections.observableArrayList();
private BufferedReader br;
private int currentLineNo = 0, colomnCount = 0, lineCount = 0;
private String line = "";
// Return data list to tableView
public ObservableList<Record> getDataList() {
return dataList;
}
// Collect table data
public void readCSV(TableView tableView, String csvFile, String delimiter,
int startLine, int endLine) {
currentLineNo = 0; colomnCount = 0; lineCount = 0;
try {
br = new BufferedReader(new FileReader(csvFile));
while (currentLineNo <= endLine && br.readLine() != null) {
line = br.readLine();
String[] fields = line.split("\\" + delimiter);
manageColomn(tableView, fields);
record = new Record(fields);
dataList.add(record);
currentLineNo++;
}
br.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(CSVView.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(CSVView.class.getName()).log(Level.SEVERE, null, ex);
}
}
void manageColomn(TableView tableView, String[] fields) {
if (colomnCount == 0) {
colomnCount = fields.length;
for (int i = 0; i < fields.length; i++) {
TableColumn<Record, String> colomn = new TableColumn<Record, String>("f" + i);
colomn.setCellValueFactory(new PropertyValueFactory<Record, String>("f" + i));
tableView.getColumns().add(colomn);
}
} else if (fields.length > colomnCount) {
}
}
}

View File

@@ -0,0 +1,46 @@
package com.itdominator.csvviewer;
import javafx.beans.property.SimpleStringProperty;
public class Record {
//Assume each record has 6 elements, all String
private SimpleStringProperty f1, f2, f3, f4, f5, f6,
f7, f8, f9, f10, f11, f12;
private String arrayString[] = { "", "", "", "", "", "",
"", "", "", "", "", ""};
private void setFields(String[] fields) {
for (int i = 0; i<fields.length; i++) {
arrayString[i] = fields[i];
}
}
public String getF1() { return f1.get(); }
public String getF2() { return f2.get(); }
public String getF3() { return f3.get(); }
public String getF4() { return f4.get(); }
public String getF5() { return f5.get(); }
public String getF6() { return f6.get(); }
public String getF7() { return f7.get(); }
public String getF8() { return f8.get(); }
public String getF9() { return f9.get(); }
public String getF10() { return f10.get(); }
public String getF11() { return f11.get(); }
public String getF12() { return f12.get(); }
Record(String[] fields) {
setFields(fields);
this.f1 = new SimpleStringProperty(arrayString[0]);
this.f2 = new SimpleStringProperty(arrayString[1]);
this.f3 = new SimpleStringProperty(arrayString[2]);
this.f4 = new SimpleStringProperty(arrayString[3]);
this.f5 = new SimpleStringProperty(arrayString[4]);
this.f6 = new SimpleStringProperty(arrayString[5]);
this.f7 = new SimpleStringProperty(arrayString[6]);
this.f8 = new SimpleStringProperty(arrayString[7]);
this.f9 = new SimpleStringProperty(arrayString[8]);
this.f10 = new SimpleStringProperty(arrayString[9]);
this.f11 = new SimpleStringProperty(arrayString[10]);
this.f12 = new SimpleStringProperty(arrayString[11]);
}
}

View File

@@ -0,0 +1,30 @@
package com.itdominator.csvviewer;
import javafx.stage.Stage;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import java.io.File;
public class SelectFile {
private final Stage fileOpenerStage = new Stage();
private FileChooser fileChooser = new FileChooser();
private File selectedFile;
public File getSelectedFile() {
return selectedFile;
}
public void selecteFile(String title, String[] filters) {
fileChooser.setTitle(title);
fileChooser.getExtensionFilters().addAll(
// new ExtensionFilter(filters),
new ExtensionFilter("All Files", "*.*"));
selectedFile = fileChooser.showOpenDialog(fileOpenerStage);
if (selectedFile != null)
System.out.println("Chosen File: " + selectedFile);
else
System.out.println("No File Chosen");
}
}

View File

@@ -0,0 +1,10 @@
#!/bin/bash
# -Xlint:unchecked
function main() {
package="csvviewer"
javac -Xlint:unchecked *.java
rm ../com/itdominator/"${package}"/*.class
mv *.class ../com/itdominator/"${package}"/
}
main;