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

Add Touch Bar support #387

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions enigma-swing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation 'de.sciss:syntaxpane:1.2.0'
implementation 'com.github.lukeu:swing-dpi:0.9'
implementation 'org.drjekyll:fontchooser:2.4'
implementation 'com.thizzer.jtouchbar:jtouchbar:1.0.0'
}

mainClassName = 'cuchaz.enigma.gui.Main'
Expand Down
7 changes: 7 additions & 0 deletions enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import cuchaz.enigma.translation.representation.entry.FieldEntry;
import cuchaz.enigma.translation.representation.entry.MethodEntry;
import cuchaz.enigma.utils.I18n;
import cuchaz.enigma.utils.Os;
import cuchaz.enigma.utils.validation.ParameterizedMessage;
import cuchaz.enigma.utils.validation.ValidationContext;

Expand Down Expand Up @@ -408,6 +409,12 @@ public void windowClosing(WindowEvent event) {

this.frame.setVisible(true);

// init touch bar
// must be called after frame is visible
if (Os.getOs() == Os.MAC) {
this.menuBar.initTouchBar(this.frame);
}

LanguageUtil.addListener(this);
}

Expand Down
26 changes: 26 additions & 0 deletions enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
import cuchaz.enigma.utils.I18n;
import cuchaz.enigma.utils.Pair;

import com.thizzer.jtouchbar.JTouchBar;
import com.thizzer.jtouchbar.common.Image;
import com.thizzer.jtouchbar.item.TouchBarItem;
import com.thizzer.jtouchbar.item.view.TouchBarButton;
import com.thizzer.jtouchbar.item.view.action.TouchBarViewAction;

public class MenuBar {

private final JMenuBar ui = new JMenuBar();
Expand Down Expand Up @@ -212,6 +218,26 @@ public void retranslateUi() {
this.githubItem.setText(I18n.translate("menu.help.github"));
}

private static void addTouchBarButton(JTouchBar touchBar, String id, String labelKey, String icon, TouchBarViewAction action) {
Image image = new Image(icon, false);

TouchBarButton button = new TouchBarButton();
button.setImage(image);
button.setAction(action);

TouchBarItem item = new TouchBarItem(id, button, true);
item.setCustomizationLabel(I18n.translate(labelKey));

touchBar.addItem(item);
}

public void initTouchBar(JFrame frame) {
JTouchBar touchBar = new JTouchBar();
touchBar.setCustomizationIdentifier("Enigma");

touchBar.show(frame);
}

public JMenuBar getUi() {
return this.ui;
}
Expand Down