Skip to content

Commit

Permalink
Fixed deleting lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Asis2019 committed Aug 30, 2020
1 parent 7c21b87 commit a9ba4d1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 42 deletions.
77 changes: 39 additions & 38 deletions src/com/asis/controllers/tabs/TabNormalOperationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public TabNormalOperationController(String tabTitle, Scene scene) {

mainTextArea.textProperty().addListener((observable, oldValue, newValue) -> {
String text = newValue.trim().replaceAll("\\n", "#");
getScene().getComponent(LineGroup.class).getLine(onLine-1).setText(text);
getScene().getComponent(LineGroup.class).getLine(onLine - 1).setText(text);
});

textTextField.textProperty().bindBidirectional(mainTextArea.textProperty());
Expand All @@ -60,7 +60,7 @@ public TabNormalOperationController(String tabTitle, Scene scene) {
totalLines = getScene().getComponent(LineGroup.class).getLineArrayList().size();

//Fix extra line bug
if(totalLines <= 0) {
if (totalLines <= 0) {
totalLines = 1;
}

Expand All @@ -71,21 +71,21 @@ public TabNormalOperationController(String tabTitle, Scene scene) {
setVisibleImage();

//Set line counter
lineCounterLabel.setText(onLine+"/"+totalLines);
lineCounterLabel.setText(onLine + "/" + totalLines);
});
}

private void addColorPickerListeners() {
textOutlineColorPicker.valueProperty().addListener((observableValue, color, t1) -> {
outlineColor = removeLastTwoLetters("#"+colorToHex(t1));
outlineColor = removeLastTwoLetters("#" + colorToHex(t1));
setNodeColorStyle(mainTextArea, fillColor, outlineColor);
getScene().getComponent(LineGroup.class).getLine(onLine-1).setOutlineColor(outlineColor);
getScene().getComponent(LineGroup.class).getLine(onLine - 1).setOutlineColor(outlineColor);
});

textColorPicker.valueProperty().addListener((observableValue, color, t1) -> {
fillColor = removeLastTwoLetters("#"+colorToHex(t1));
fillColor = removeLastTwoLetters("#" + colorToHex(t1));
setNodeColorStyle(mainTextArea, fillColor, outlineColor);
getScene().getComponent(LineGroup.class).getLine(onLine-1).setFillColor(fillColor);
getScene().getComponent(LineGroup.class).getLine(onLine - 1).setFillColor(fillColor);
});
}

Expand All @@ -95,15 +95,15 @@ private void addBeatFieldListeners() {
//Process beat pitch
try {
final double pitch = Double.parseDouble(t1);
getScene().getComponent(LineGroup.class).getLine(onLine-1).setChangeBeatPitch(pitch);
getScene().getComponent(LineGroup.class).getLine(onLine - 1).setChangeBeatPitch(pitch);
} catch (NumberFormatException e) {
System.out.println("User put bad value into beat pitch");
if(t1.isEmpty()) {
getScene().getComponent(LineGroup.class).getLine(onLine-1).setChangeBeatPitch(null);
if (t1.isEmpty()) {
getScene().getComponent(LineGroup.class).getLine(onLine - 1).setChangeBeatPitch(null);
textFieldBeatPitch.clear();
return;
}
final String backspacedText = t1.substring(0, t1.length()-1);
final String backspacedText = t1.substring(0, t1.length() - 1);
textFieldBeatPitch.setText(backspacedText);
}
});
Expand All @@ -113,15 +113,15 @@ private void addBeatFieldListeners() {
//Process beat speed
try {
final int speed = Integer.parseInt(t1);
getScene().getComponent(LineGroup.class).getLine(onLine-1).setChangeBeatSpeed(speed);
getScene().getComponent(LineGroup.class).getLine(onLine - 1).setChangeBeatSpeed(speed);
} catch (NumberFormatException e) {
System.out.println("User put bad value into beat speed");
if(t1.isEmpty()) {
getScene().getComponent(LineGroup.class).getLine(onLine-1).setChangeBeatSpeed(null);
if (t1.isEmpty()) {
getScene().getComponent(LineGroup.class).getLine(onLine - 1).setChangeBeatSpeed(null);
textFieldBeatSpeed.clear();
return;
}
final String backspacedText = t1.substring(0, t1.length()-1);
final String backspacedText = t1.substring(0, t1.length() - 1);
textFieldBeatSpeed.setText(backspacedText);
}
});
Expand All @@ -130,7 +130,7 @@ private void addBeatFieldListeners() {
public void actionAddImage() {
File file = AsisUtils.imageFileChooser();

if(file != null) {
if (file != null) {
//Add image to json object
SceneImage image = new SceneImage();
image.setImage(file);
Expand All @@ -143,19 +143,19 @@ public void actionAddImage() {
public void actionAddLineImage() {
File file = AsisUtils.imageFileChooser();

if(file != null) {
if (file != null) {
//Add image to json object
getScene().getComponent(LineGroup.class).getLine(onLine-1).setLineImage(file);
getScene().getComponent(LineGroup.class).getLine(onLine - 1).setLineImage(file);

setVisibleImage();
}
}

public void actionPreviousLine() {
if(onLine <= 1) onLine = 1;
if (onLine <= 1) onLine = 1;
else onLine--;

if(onLine <= 1) {
if (onLine <= 1) {
previousLineButton.setDisable(true);
deleteLineButton.setDisable(true);
}
Expand All @@ -164,41 +164,41 @@ public void actionPreviousLine() {
setVisibleImage();


lineCounterLabel.setText(onLine+"/"+totalLines);
lineCounterLabel.setText(onLine + "/" + totalLines);
}

public void actionNextLine() {
if(onLine == totalLines) totalLines++;
if (onLine == totalLines) totalLines++;
onLine++;

setLineVariables();
setVisibleImage();

lineCounterLabel.setText(onLine+"/"+totalLines);
lineCounterLabel.setText(onLine + "/" + totalLines);

deleteLineButton.setDisable(false);
previousLineButton.setDisable(false);
}

public void actionDeleteLine() {
getScene().getComponent(LineGroup.class).removeLine(onLine-1);
getScene().getComponent(LineGroup.class).removeLine(onLine - 1);

totalLines--;
actionPreviousLine();
}

public void actionStartBeat() {
setLineStartCheckBoxState(getScene().getComponent(LineGroup.class).getLine(onLine-1), checkBoxStartBeat);
setLineStartCheckBoxState(getScene().getComponent(LineGroup.class).getLine(onLine - 1), checkBoxStartBeat);
}

public void actionStopBeat() {
setLineStopCheckBoxState(getScene().getComponent(LineGroup.class).getLine(onLine-1), checkBoxStopBeat);
setLineStopCheckBoxState(getScene().getComponent(LineGroup.class).getLine(onLine - 1), checkBoxStopBeat);
}

private void setLineVariables() {
initializeText();

JSONObject textObject = getScene().getComponent(LineGroup.class).getLine(onLine-1).toJSON().getJSONObject(0);
JSONObject textObject = getScene().getComponent(LineGroup.class).getLine(onLine - 1).toJSON().getJSONObject(0);
textObjectElseIf();

beatProperties(textObject, checkBoxStopBeat, "stopBeat");
Expand All @@ -209,48 +209,48 @@ private void setLineVariables() {
}

private void textObjectElseIf() {
Line workingLine = getScene().getComponent(LineGroup.class).getLine(onLine-1);
Line workingLine = getScene().getComponent(LineGroup.class).getLine(onLine - 1);
if (workingLine.getFillColor() != null)
textColorPicker.setValue(Color.web(workingLine.getFillColor()));

if (workingLine.getOutlineColor() != null)
textOutlineColorPicker.setValue(Color.web(workingLine.getOutlineColor()));

mainTextArea.setText(workingLine.getText().replaceAll("#", "\n"));
if(workingLine.getStartBeat() != null) checkBoxStartBeat.setSelected(workingLine.getStartBeat());
if (workingLine.getStartBeat() != null) checkBoxStartBeat.setSelected(workingLine.getStartBeat());
}

private File getImageFile() {
//Create and set working file to passed in var if not null
File workingFile = new File("");

//Scene image code
if(getScene().hasComponent(SceneImage.class) && getScene().getComponent(SceneImage.class).getImage() != null) {
if (getScene().hasComponent(SceneImage.class) && getScene().getComponent(SceneImage.class).getImage() != null) {
//check if file exists
if(getScene().getComponent(SceneImage.class).getImage().exists()) {
if (getScene().getComponent(SceneImage.class).getImage().exists()) {
//Set image file
workingFile = getScene().getComponent(SceneImage.class).getImage();

//Remove add image button
stackPane.getChildren().remove(iconControllerBox);
} else {
System.out.println("Scene titled: "+scene.getComponentTitle()+", contains and invalid scene image.");
System.out.println("Scene titled: " + scene.getComponentTitle() + ", contains and invalid scene image.");
}
}

//Line image code
if(getScene().getComponent(LineGroup.class).getLine(onLine-1).getLineImage() != null) {
if (getScene().getComponent(LineGroup.class).getLine(onLine - 1).getLineImage() != null) {
//Set image file
workingFile = getScene().getComponent(LineGroup.class).getLine(onLine-1).getLineImage();
workingFile = getScene().getComponent(LineGroup.class).getLine(onLine - 1).getLineImage();
}
return workingFile;
}

private void initializeText() {
if(getScene().getComponent(LineGroup.class).getLine(onLine-1) == null) {
getScene().getComponent(LineGroup.class).addNewLine(onLine-1);
getScene().getComponent(LineGroup.class).getLine(onLine-1).setFillColor(fillColor);
getScene().getComponent(LineGroup.class).getLine(onLine-1).setOutlineColor(outlineColor);
if (getScene().getComponent(LineGroup.class).getLine(onLine - 1) == null) {
getScene().getComponent(LineGroup.class).addNewLine(onLine - 1);
getScene().getComponent(LineGroup.class).getLine(onLine - 1).setFillColor(fillColor);
getScene().getComponent(LineGroup.class).getLine(onLine - 1).setOutlineColor(outlineColor);
}
}

Expand All @@ -262,6 +262,7 @@ public void setVisibleImage() {
public Scene getScene() {
return scene;
}

public void setScene(Scene scene) {
this.scene = scene;
}
Expand Down
11 changes: 8 additions & 3 deletions src/com/asis/joi/model/entities/LineGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ public void addNewLine(int lineNumber) {

public void removeLine(int lineNumber) {
getLineArrayList().remove(getLine(lineNumber));

int previousLineNumber = lineNumber;
for (Line line : getLineArrayList())
if (line.getLineNumber() > previousLineNumber) line.setLineNumber(previousLineNumber++);
}

public Line getLine(int lineNumber) {
for(Line line: getLineArrayList())
for (Line line : getLineArrayList())
if (line.getLineNumber() == lineNumber) return line;
return null;
}
Expand All @@ -31,7 +35,7 @@ public String jsonKeyName() {
@Override
public JSONObject toJSON() {
JSONObject lineGroupObject = new JSONObject();
for(Line line: getLineArrayList()) lineGroupObject.put("line" + line.getLineNumber(), line.toJSON());
for (Line line : getLineArrayList()) lineGroupObject.put("line" + line.getLineNumber(), line.toJSON());
return lineGroupObject;
}

Expand All @@ -50,7 +54,7 @@ public LineGroup clone() throws CloneNotSupportedException {
LineGroup lineGroup = (LineGroup) super.clone();

ArrayList<Line> clonedArray = new ArrayList<>();
for (Line line: getLineArrayList()) clonedArray.add(line.clone());
for (Line line : getLineArrayList()) clonedArray.add(line.clone());
lineGroup.setLineArrayList(clonedArray);

return lineGroup;
Expand All @@ -70,6 +74,7 @@ public boolean equals(Object o) {
public ArrayList<Line> getLineArrayList() {
return lineArrayList;
}

private void setLineArrayList(ArrayList<Line> lineArrayList) {
this.lineArrayList = lineArrayList;
}
Expand Down
1 change: 0 additions & 1 deletion src/com/asis/ui/asis_node/SceneNodeMainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ private void addConnectionToStory(AsisConnectionButton outputConnection, AsisCon
outputConnection.setButtonColor(AsisConnectionButton.RANDOM_OUT_COLOR);

if(component instanceof Scene) {
System.out.println("Adding connection from "+outputConnection.getParentSceneId()+" to "+inputConnection.getParentSceneId());
GotoScene gotoScene;
try {
gotoScene = ((Scene) component).getComponent(GotoScene.class);
Expand Down

0 comments on commit a9ba4d1

Please sign in to comment.