Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixed to spreadsheet #104

Merged
merged 5 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 119 additions & 2 deletions client/src/main/java/org/iconic/menu/MenuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.iconic.project.ProjectModel;
import org.iconic.project.ProjectService;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.net.URL;
import java.util.ResourceBundle;

Expand Down Expand Up @@ -69,6 +71,122 @@ public void initialize(URL arg1, ResourceBundle arg2) {
// Do nothing
}

/**
* <p>
*Simulates ctrl + z to undo
*
*
* @param actionEvent The action that triggered this event
*/
public void undo(ActionEvent actionEvent) throws AWTException {
Robot r = new Robot();
int keyCode = KeyEvent.VK_Z;
int keyCode2 = KeyEvent.VK_CONTROL;
r.keyPress(keyCode2);
r.keyPress(keyCode);
r.keyRelease(keyCode);
r.keyRelease(keyCode2);
}

/**
* <p>
*Simulates ctrl + y to redo
*
*
* @param actionEvent The action that triggered this event
*/
public void redo(ActionEvent actionEvent) throws AWTException {
Robot r = new Robot();
int keyCode = KeyEvent.VK_Y;
int keyCode2 = KeyEvent.VK_CONTROL;
r.keyPress(keyCode2);
r.keyPress(keyCode);
r.keyRelease(keyCode);
r.keyRelease(keyCode2);
}

/**
* <p>
*Simulates ctrl + x to cut
*
*
* @param actionEvent The action that triggered this event
*/
public void cut(ActionEvent actionEvent) throws AWTException {
Robot r = new Robot();
int keyCode = KeyEvent.VK_X;
int keyCode2 = KeyEvent.VK_CONTROL;
r.keyPress(keyCode2);
r.keyPress(keyCode);
r.keyRelease(keyCode);
r.keyRelease(keyCode2);
}

/**
* <p>
*Simulates ctrl + c to copy
*
*
* @param actionEvent The action that triggered this event
*/
public void copy(ActionEvent actionEvent) throws AWTException {
Robot r = new Robot();
int keyCode = KeyEvent.VK_C;
int keyCode2 = KeyEvent.VK_CONTROL;
r.keyPress(keyCode2);
r.keyPress(keyCode);
r.keyRelease(keyCode);
r.keyRelease(keyCode2);
}

/**
* <p>
*Simulates ctrl + v to copy
*
*
* @param actionEvent The action that triggered this event
*/
public void paste(ActionEvent actionEvent) throws AWTException {
Robot r = new Robot();
int keyCode = KeyEvent.VK_V;
int keyCode2 = KeyEvent.VK_CONTROL;
r.keyPress(keyCode2);
r.keyPress(keyCode);
r.keyRelease(keyCode);
r.keyRelease(keyCode2);
}

/**
* <p>
*Simulates delete to delete
*
*
* @param actionEvent The action that triggered this event
*/
public void delete(ActionEvent actionEvent) throws AWTException {
Robot r = new Robot();
int keyCode = KeyEvent.VK_DELETE;
r.keyPress(keyCode);
r.keyRelease(keyCode);
}

/**
* <p>
*Simulates ctrl + a to select all
*
*
* @param actionEvent The action that triggered this event
*/
public void selectAll(ActionEvent actionEvent) throws AWTException {
Robot r = new Robot();
int keyCode = KeyEvent.VK_A;
int keyCode2 = KeyEvent.VK_CONTROL;
r.keyPress(keyCode2);
r.keyPress(keyCode);
r.keyRelease(keyCode2);
r.keyRelease(keyCode);
}

/**
* <p>
* Closes all stages and exits the application.
Expand All @@ -79,7 +197,6 @@ public void initialize(URL arg1, ResourceBundle arg2) {
public void exit(ActionEvent actionEvent) {
Platform.exit();
}

/**
* <p>
* Returns the root StackPane associated with this view.
Expand All @@ -104,7 +221,7 @@ public void showAbout(ActionEvent actionEvent) {
);

alert.setTitle("About");
alert.setHeaderText("Version: 1.0\n\nIcons made by Smashicons, Roundicons, Freepik and DinosoftLabs from www.flaticon.com");
alert.setHeaderText("Version: 0.7.0\n\nhttps://github.com/koosvary/Iconic\n\nIcons made by Smashicons, Roundicons, Freepik and DinosoftLabs from www.flaticon.com");

alert.showAndWait()
.filter(response -> response == ButtonType.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ private void setupContextMenu(){
extendWithClipboard();
pasteFromClipboard();
});
contextMenu.getItems().addAll(copy,paste);
MenuItem delete = new MenuItem("Delete");
delete.setAccelerator(KeyCombination.keyCombination("Delete"));
delete.setOnAction(actionEvent -> {
deleteSelection();

});
contextMenu.getItems().addAll(copy,paste,delete);
spreadsheet.setContextMenu(contextMenu);
}

Expand Down Expand Up @@ -192,8 +198,10 @@ else if (prevRow != -1) {

Object observableValue = spreadsheet.getGrid().getRows().get(row).get(col).getItem();

// add new item to clipboard
clipboardString.append(String.valueOf(observableValue));
if(observableValue != null){
// add new item to clipboard
clipboardString.append(String.valueOf(observableValue));
}

// remember previous
prevRow = row;
Expand Down Expand Up @@ -223,24 +231,16 @@ private void pasteFromClipboard() {

int rowClipboard = -1;

StringTokenizer rowTokenizer = new StringTokenizer( pasteString, "\n");
while(rowTokenizer.hasMoreTokens()) {

Scanner s = new Scanner(pasteString);
while (s.hasNextLine()) {
rowClipboard++;

String rowString = rowTokenizer.nextToken();

StringTokenizer columnTokenizer = new StringTokenizer(rowString, "\t");

String line = s.nextLine();
String[] items= line.split("\t", -1);
int colClipboard = -1;

while(columnTokenizer.hasMoreTokens()) {

for(int i = 0; i < items.length; i++){
colClipboard++;

// get next cell data from clipboard
String clipboardCellContent = columnTokenizer.nextToken();

String clipboardCellContent = items[i];
// calculate the position in the table cell
int rowTable = pasteCellPosition.getRow() + rowClipboard;
int colTable = pasteCellPosition.getColumn() + colClipboard;
Expand All @@ -262,14 +262,32 @@ private void pasteFromClipboard() {
double content = Double.parseDouble(clipboardCellContent);
spreadsheet.getGrid().getRows().get(rowTable).get(colTable).setItem(String.valueOf(content));
} catch (Exception ignored) {
spreadsheet.getGrid().getRows().get(rowTable).get(colTable).setItem(null);
updateProjectDataset(rowTable-2,colTable,null);
}
}
}

}
}

}

/**
* Finds the selected cells and deletes the values within them
*/
private void deleteSelection() {
ObservableList<TablePosition> positionList = spreadsheet.getSelectionModel().getSelectedCells();

for (TablePosition position : positionList) {
int row = position.getRow();
int col = position.getColumn();

spreadsheet.getGrid().getRows().get(row).get(col).setItem(null);

updateProjectDataset(row-2,col,null);
}
}

/**
* Calculates the size of the extended spreadsheet after the clipboard will be pasted
*/
Expand Down
17 changes: 8 additions & 9 deletions client/src/main/resources/views/menu/MenuView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@
</Menu>

<Menu text="%menu.edit">
<MenuItem text="%menu.undo" />
<MenuItem text="%menu.redo" />
<MenuItem text="%menu.undo" onAction="#undo"/>
<MenuItem text="%menu.redo" onAction="#redo"/>
<SeparatorMenuItem/>
<MenuItem text="%menu.cut" />
<MenuItem text="%menu.copy" />
<MenuItem text="%menu.paste" />
<MenuItem text="%menu.delete" />
<MenuItem text="%menu.cut" onAction="#cut"/>
<MenuItem text="%menu.copy" onAction="#copy"/>
<MenuItem text="%menu.paste" onAction="#paste"/>
<MenuItem text="%menu.delete" onAction="#delete"/>
<SeparatorMenuItem/>
<MenuItem text="%menu.selectAll" />
<MenuItem text="%menu.deselectAll" />
<MenuItem text="%menu.selectAll" onAction="#selectAll"/>
</Menu>

<Menu text="%menu.view">
Expand All @@ -62,7 +61,7 @@

<Menu text="%menu.help">
<items>
<MenuItem text="About Ionic Workbench" onAction="#showAbout"/>
<MenuItem text="About Iconic Workbench" onAction="#showAbout"/>
</items>
</Menu>
</MenuBar>
Expand Down