diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java index 2b969b4bb..1f431594c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java @@ -29,83 +29,83 @@ public TreeTentController() { this.lastCellPressed = null; } -// @Override -// public void mousePressed(MouseEvent e) { -// if (e.getButton() != MouseEvent.BUTTON2) { -// BoardView boardView = getInstance().getLegupUI().getBoardView(); -// dragStart = boardView.getElement(e.getPoint()); -// lastCellPressed = boardView.getElement(e.getPoint()); -// } -// } + @Override + public void mousePressed(MouseEvent e) { + if (e.getButton() != MouseEvent.BUTTON2) { + BoardView boardView = getInstance().getLegupUI().getBoardView(); + dragStart = boardView.getElement(e.getPoint()); + lastCellPressed = boardView.getElement(e.getPoint()); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + if (GameBoardFacade.getInstance().getLegupUI().getTreePanel() != null && e.getButton() != MouseEvent.BUTTON2) { + TreePanel treePanel = GameBoardFacade.getInstance().getLegupUI().getTreePanel(); + TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); + BoardView boardView = getInstance().getLegupUI().getBoardView(); + lastCellPressed = boardView.getElement(e.getPoint()); + Board board = boardView.getBoard(); + TreeViewSelection selection = treeView.getSelection(); -// @Override -// public void mouseReleased(MouseEvent e) { -// if (GameBoardFacade.getInstance().getLegupUI().getTreePanel() != null && e.getButton() != MouseEvent.BUTTON2) { -// TreePanel treePanel = GameBoardFacade.getInstance().getLegupUI().getTreePanel(); -// TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); -// BoardView boardView = getInstance().getLegupUI().getBoardView(); -// lastCellPressed = boardView.getElement(e.getPoint()); -// Board board = boardView.getBoard(); -// TreeViewSelection selection = treeView.getSelection(); -// -// if (dragStart != null) { -// if (board instanceof CaseBoard) { -// CaseBoard caseBoard = (CaseBoard) board; -// AutoCaseRuleCommand autoCaseRuleCommand = new AutoCaseRuleCommand(dragStart, selection, caseBoard.getCaseRule(), caseBoard, e); -// if (autoCaseRuleCommand.canExecute()) { -// autoCaseRuleCommand.execute(); -// getInstance().getHistory().pushChange(autoCaseRuleCommand); -// treePanel.updateError(""); -// } -// else { -// treePanel.updateError(autoCaseRuleCommand.getError()); -// } -// } -// else { -// if (dragStart == lastCellPressed) { -// if (dragStart.getPuzzleElement().getIndex() >= 0) { -// ICommand edit = new EditDataCommand(lastCellPressed, selection, e); -// if (edit.canExecute()) { -// edit.execute(); -// getInstance().getHistory().pushChange(edit); -// treePanel.updateError(""); -// } -// else { -// treePanel.updateError(edit.getError()); -// } -// } -// else { -// ClueCommand edit = new ClueCommand(selection, (TreeTentClueView) dragStart); -// if (edit.canExecute()) { -// edit.execute(); -// getInstance().getHistory().pushChange(edit); -// treePanel.updateError(""); -// } -// else { -// treePanel.updateError(edit.getError()); -// } -// } -// } -// else { -// if (lastCellPressed != null) { -// if (dragStart instanceof TreeTentElementView) { -// ICommand editLine = new EditLineCommand(selection, (TreeTentElementView) dragStart, lastCellPressed); -// if (editLine.canExecute()) { -// editLine.execute(); -// getInstance().getHistory().pushChange(editLine); -// } -// else { -// treePanel.updateError(editLine.getError()); -// } -// } -// } -// } -// } -// } -// dragStart = null; -// lastCellPressed = null; -// } -// } + if (dragStart != null) { + if (board instanceof CaseBoard) { + CaseBoard caseBoard = (CaseBoard) board; + AutoCaseRuleCommand autoCaseRuleCommand = new AutoCaseRuleCommand(dragStart, selection, caseBoard.getCaseRule(), caseBoard, e); + if (autoCaseRuleCommand.canExecute()) { + autoCaseRuleCommand.execute(); + getInstance().getHistory().pushChange(autoCaseRuleCommand); + treePanel.updateError(""); + } + else { + treePanel.updateError(autoCaseRuleCommand.getError()); + } + } + else { + if (dragStart == lastCellPressed) { + if (dragStart.getPuzzleElement().getIndex() >= 0) { + ICommand edit = new EditDataCommand(lastCellPressed, selection, e); + if (edit.canExecute()) { + edit.execute(); + getInstance().getHistory().pushChange(edit); + treePanel.updateError(""); + } + else { + treePanel.updateError(edit.getError()); + } + } + else { + ClueCommand edit = new ClueCommand(selection, (TreeTentClueView) dragStart); + if (edit.canExecute()) { + edit.execute(); + getInstance().getHistory().pushChange(edit); + treePanel.updateError(""); + } + else { + treePanel.updateError(edit.getError()); + } + } + } + else { + if (lastCellPressed != null) { + if (dragStart instanceof TreeTentElementView) { + ICommand editLine = new EditLineCommand(selection, (TreeTentElementView) dragStart, lastCellPressed); + if (editLine.canExecute()) { + editLine.execute(); + getInstance().getHistory().pushChange(editLine); + } + else { + treePanel.updateError(editLine.getError()); + } + } + } + } + } + } + dragStart = null; + lastCellPressed = null; + } + } @Override public void changeCell(MouseEvent e, PuzzleElement element) {