Skip to content

Commit

Permalink
Add graphics to context menu items. (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikmafo authored Aug 28, 2022
1 parent 99ba69f commit 5d0c997
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 39 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.erikmafo</groupId>
<artifactId>big-table-viewer</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
<packaging>jar</packaging>
<name>Big Table Viewer</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.erikmafo.btviewer.services.instance.SaveInstanceService;
import com.erikmafo.btviewer.services.project.RemoveProjectService;
import com.erikmafo.btviewer.ui.util.AlertUtil;
import com.erikmafo.btviewer.ui.util.FontAwesomeUtil;
import com.google.inject.Provider;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
Expand All @@ -17,6 +18,7 @@
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeView;
import org.controlsfx.glyphfont.FontAwesome;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -109,11 +111,13 @@ public ContextMenu createContextMenu(@NotNull TreeItemData item){
ContextMenu menu = null;
if (item.isProject()) {
var addInstance = new MenuItem("Add instance");
addInstance.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.PLUS));
addInstance.setOnAction(actionEvent ->
AddInstanceDialog
.displayAndAwaitResult(item.getProjectId())
.whenComplete(this::handleAddInstanceResult));
var removeProject = new MenuItem("Remove");
removeProject.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.REMOVE));
removeProject.setOnAction(actionEvent -> {
removeProjectService.setProjectId(item.getProjectId());
removeProjectService.setOnSucceeded(event -> ((RootTreeItem)treeView.getRoot()).removeProject((item.getProjectId())));
Expand All @@ -124,6 +128,7 @@ public ContextMenu createContextMenu(@NotNull TreeItemData item){
menu = new ContextMenu(addInstance, removeProject);
} else if (item.isInstance()) {
var refreshTables = new MenuItem("Refresh tables");
refreshTables.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.REFRESH));
refreshTables.setOnAction(e -> ((InstanceTreeItem)item.getTreeItem()).loadChildren());
menu = new ContextMenu(refreshTables);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.erikmafo.btviewer.sql.SqlQuery;
import com.erikmafo.btviewer.ui.timer.TimerView;
import com.erikmafo.btviewer.ui.util.AlertUtil;
import com.erikmafo.btviewer.ui.util.FontAwesomeUtil;
import com.erikmafo.btviewer.ui.util.ContextMenuUtil;
import com.erikmafo.btviewer.util.StringUtil;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
Expand All @@ -20,13 +20,11 @@
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ProgressBar;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import org.controlsfx.glyphfont.FontAwesome;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -165,35 +163,11 @@ private void onMousePressed(@NotNull MouseEvent event) {
private ContextMenu getOrCreateContextMenu() {
ContextMenu contextMenu = codeArea.getContextMenu();
if (contextMenu == null) {
contextMenu = new ContextMenu();
contextMenu.setAutoHide(true);
contextMenu.setHideOnEscape(true);
contextMenu.getItems().addAll(getCutMenuItem(), getCopyMenuItem(), getPastMenuItem());
contextMenu = ContextMenuUtil.createContextMenu(
ContextMenuUtil.createCutMenuItem(e -> codeArea.cut()),
ContextMenuUtil.createCopyMenuItem(e -> codeArea.copy()),
ContextMenuUtil.createPasteMenuItem(e -> codeArea.paste()));
}
return contextMenu;
}

@NotNull
private MenuItem getPastMenuItem() {
var paste = new MenuItem("Paste");
paste.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.PASTE));
paste.setOnAction(e -> codeArea.paste());
return paste;
}

@NotNull
private MenuItem getCopyMenuItem() {
var copy = new MenuItem("Copy");
copy.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.COPY));
copy.setOnAction(e -> codeArea.copy());
return copy;
}

@NotNull
private MenuItem getCutMenuItem() {
var cut = new MenuItem("Cut");
cut.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.CUT));
cut.setOnAction(e -> codeArea.cut());
return cut;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static com.erikmafo.btviewer.ui.util.ContextMenuUtil.createContextMenu;
import static com.erikmafo.btviewer.ui.util.ContextMenuUtil.createCopyMenuItem;

public class QueryResultViewController {

private static final String ROW_KEY = "key";
Expand Down Expand Up @@ -130,12 +133,7 @@ public void onTableViewKeyPressed(@NotNull KeyEvent keyEvent) {

@NotNull
private ContextMenu createTableViewContextMenu() {
ContextMenu contextMenu = new ContextMenu();
contextMenu.setAutoHide(true);
MenuItem copy = new MenuItem("Copy");
copy.setOnAction(actionEvent -> copySelectedCellsToClipboard());
contextMenu.getItems().add(copy);
return contextMenu;
return createContextMenu(createCopyMenuItem(e -> copySelectedCellsToClipboard()));
}

public void setRows(@NotNull ObservableList<QueryResultRow> rows) {
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/com/erikmafo/btviewer/ui/util/ContextMenuUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.erikmafo.btviewer.ui.util;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import org.controlsfx.glyphfont.FontAwesome;
import org.jetbrains.annotations.NotNull;


public class ContextMenuUtil {

@NotNull
public static ContextMenu createContextMenu(MenuItem... items) {
var contextMenu = new ContextMenu();
contextMenu.setStyle("");
contextMenu.setAutoHide(true);
contextMenu.setHideOnEscape(true);
contextMenu.getItems().addAll(items);
return contextMenu;
}

@NotNull
public static MenuItem createCutMenuItem(EventHandler<ActionEvent> handler) {
var menuItem = new MenuItem("Cut");
menuItem.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.CUT));
menuItem.setOnAction(handler);
return menuItem;
}

@NotNull
public static MenuItem createCopyMenuItem(EventHandler<ActionEvent> handler) {
var menuItem = new MenuItem("Copy");
menuItem.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.COPY));
menuItem.setOnAction(handler);
return menuItem;
}

@NotNull
public static MenuItem createPasteMenuItem(EventHandler<ActionEvent> handler) {
var menuItem = new MenuItem("Paste");
menuItem.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.PASTE));
menuItem.setOnAction(handler);
return menuItem;
}
}
1 change: 0 additions & 1 deletion src/main/resources/css/query_box.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

.code-area {
-fx-font-size: 14;
-fx-font-weight: 690;
}

.keyword {
Expand Down

0 comments on commit 5d0c997

Please sign in to comment.