Skip to content

Commit

Permalink
feat: Add autosave
Browse files Browse the repository at this point in the history
  • Loading branch information
shahrukhqasim committed Oct 14, 2017
1 parent 544e008 commit 9ced431
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.shahrukhqasim.ties.label;

import javafx.embed.swing.SwingFXUtils;
import javafx.fxml.FXML;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
Expand All @@ -9,17 +8,11 @@
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;

import javafx.scene.control.ToggleButton;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import org.json.*;

public class Controller {
Drawable image;
Expand All @@ -37,7 +30,8 @@ public class Controller {
public Label zoomLabel;
public Label fileLabel;
private IOManager ioManager;
public ToggleButton toggleButton;
public ToggleButton toggleButtonConnect;
public ToggleButton toggleButtonAutoSave;


public Controller() {
Expand Down Expand Up @@ -160,6 +154,6 @@ void onSave() {

@FXML
void onToggleConnect() {
this.interactionManager.onToggleConnect(toggleButton.isSelected());
this.interactionManager.onToggleConnect(toggleButtonConnect.isSelected());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import org.json.JSONArray;
import org.json.JSONObject;

Expand Down Expand Up @@ -181,7 +178,7 @@ void load() {
controller.connections = new Connections(new Vector<>());

controller.interactionManager = new InteractionManager(controller.boxesOcr, controller.boxesCells, controller.connections);
controller.interactionManager.onToggleConnect(controller.toggleButton.isSelected());
controller.interactionManager.onToggleConnect(controller.toggleButtonConnect.isSelected());
controller.selectionBox = controller.interactionManager.getSelectionBox();
controller.selectionConnection = controller.interactionManager.getSelectionConnection();

Expand Down Expand Up @@ -264,10 +261,16 @@ void toNewIndex(int newIndex) {
}

void next() {
if (controller.toggleButtonAutoSave.isSelected())
save();

toNewIndex(currentIndex + 1);
load();
}
void previous() {
if (controller.toggleButtonAutoSave.isSelected())
save();

toNewIndex(currentIndex - 1);
load();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import javafx.stage.Stage;

public class Main extends Application {
Controller controller;

@Override
public void start(Stage primaryStage) throws Exception{
FXMLLoader loader = new FXMLLoader(getClass().getResource("ui_layout.fxml"));
Parent root = loader.load();
Controller controller = loader.getController();
controller = loader.getController();
primaryStage.setTitle("TIES - Label Tool");
primaryStage.setScene(new Scene(root, 1024, 576));
primaryStage.show();
Expand All @@ -21,6 +22,8 @@ public void start(Stage primaryStage) throws Exception{

@Override
public void stop() throws Exception {
controller.onSave();

super.stop();
System.exit(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Button text="Zoom In" onAction="#onZoomIn"></Button>
<Button text="Zoom Out" onAction="#onZoomOut"></Button>
<Label text="Zoom: 1x" fx:id="zoomLabel"></Label>
<ToggleButton text="Connect" fx:id="toggleButton" onAction="#onToggleConnect"></ToggleButton>
<ToggleButton text="Connect" fx:id="toggleButtonConnect" onAction="#onToggleConnect"></ToggleButton>
<Label text="File" fx:id="fileLabel"></Label>
</FlowPane>
</top>
Expand All @@ -36,6 +36,7 @@
<Button text="Save" alignment="CENTER" onAction="#onSave"></Button>
<Button text="Next" alignment="CENTER" onAction="#onNext"></Button>
<Button text="Previous" alignment="CENTER" onAction="#onPrevious"></Button>
<ToggleButton text="AutoSave" alignment="CENTER" fx:id="toggleButtonAutoSave" selected="true"></ToggleButton>
</FlowPane>
</bottom>
</BorderPane>

0 comments on commit 9ced431

Please sign in to comment.