Skip to content

Java library for using the touchbar API on supported macbooks.

License

Notifications You must be signed in to change notification settings

schroederonline/jtouchbar

 
 

Repository files navigation

Build Status

JTouchBar

Java library for using the touchbar API on supported macbooks.

Visit Apple's website for more information on the touchbar itself.

Support the Developers!

Please take a look at the other stuff the developers are working on and support them in other ways.

Installation & Usage

Maven

<dependency>
	<groupId>com.thizzer.jtouchbar</groupId>
	<artifactId>jtouchbar</artifactId>
	<version>1.0.1-SNAPSHOT</version>
</dependency>

Gradle

implementation group: 'com.thizzer.jtouchbar', name: 'jtouchbar', version: '1.0.1-SNAPSHOT'

Using JTouchBar with Swing

JFrame frame = ...

JTouchBar jTouchBar = new JTouchBar();
jTouchBar.setCustomizationIdentifier("MySwingJavaTouchBar");

// Customize your touchbar

jTouchBar.show(frame);

Using JTouchBar with JavaFX

There is a separate library for adding JavaFX support.

Maven

<dependency>
	<groupId>com.thizzer.jtouchbar</groupId>
	<artifactId>jtouchbar-javafx</artifactId>
	<version>1.0.0</version>
</dependency>

Gradle

implementation group: 'com.thizzer.jtouchbar', name: 'jtouchbar-javafx', version: '1.0.0'

JavaFX Example

Stage stage = ...

JTouchBar jTouchBar = new JTouchBar();
jTouchBar.setCustomizationIdentifier("MyJavaFXJavaTouchBar");

// Customize your touchbar

JTouchBarJavaFX.show(jTouchBar, shell);

Using JTouchBar with LWJGL

long window = ... // LWJGL window

JTouchBar jTouchBar = new JTouchBar();
jTouchBar.setCustomizationIdentifier("MyLWJGLJavaTouchBar");

// Customize your touchbar

jTouchBar.show(
		GLFWNativeCocoa.glfwGetCocoaWindow(window)
	);

Using JTouchBar with SWT

There is a separate library for adding SWT support.

Maven

<dependency>
	<groupId>com.thizzer.jtouchbar</groupId>
	<artifactId>jtouchbar-swt</artifactId>
	<version>1.0.0</version>
</dependency>

Gradle

implementation group: 'com.thizzer.jtouchbar', name: 'jtouchbar-swt', version: '1.0.0'
<dependency>
	<groupId>com.thizzer.jtouchbar</groupId>
	<artifactId>jtouchbar-swt</artifactId>
	<version>1.0.0-SNAPSHOT</version>
</dependency>

SWT Example

Shell shell = ...

JTouchBar jTouchBar = new JTouchBar();
jTouchBar.setCustomizationIdentifier("MySWTJavaTouchBar");

// Customize your touchbar

JTouchBarSWT.show(jTouchBar, shell);

Adding views to your touchbar

// flexible space
jTouchBar.addItem(new TouchBarItem(TouchBarItem.NSTouchBarItemIdentifierFlexibleSpace));

// fixed space
jTouchBar.addItem(new TouchBarItem(TouchBarItem.NSTouchBarItemIdentifierFixedSpaceSmall));

// button
TouchBarButton touchBarButtonImg = new TouchBarButton();
touchBarButtonImg.setTitle("Button 1");
touchBarButtonImg.setAction(new TouchBarViewAction() {
	@Override
	public void onCall( TouchBarView view ) {
		System.out.println("Clicked Button_1.");
	}
});

Image image = new Image();
img.setName(ImageName.NSImageNameTouchBarColorPickerFill);
touchBarButtonImg.setImage(image);

jTouchBar.addItem(new TouchBarItem("Button_1", touchBarButtonImg, true));

// label
TouchBarTextField touchBarTextField = new TouchBarTextField();
touchBarTextField.setStringValue("TextField 1");

jTouchBar.addItem(new TouchBarItem("TextField_1", touchBarTextField, true));

// scrubber
TouchBarScrubber touchBarScrubber = new TouchBarScrubber();
touchBarScrubber.setActionListener(new ScrubberActionListener() {
	@Override
	public void didSelectItemAtIndex(TouchBarScrubber scrubber, long index) {
		System.out.println("Selected Scrubber Index: " + index);
	}
});
touchBarScrubber.setDataSource(new ScrubberDataSource() {
	@Override
	public ScrubberView getViewForIndex(TouchBarScrubber scrubber, long index) {
		if(index == 0) {
			ScrubberTextItemView textItemView = new ScrubberTextItemView();
			textItemView.setIdentifier("ScrubberItem_1");
			textItemView.setStringValue("Scrubber TextItem");
			
			return textItemView;
		}
		else {
			ScrubberImageItemView imageItemView = new ScrubberImageItemView();
			imageItemView.setIdentifier("ScrubberItem_2");
			imageItemView.setImage(new Image(ImageName.NSImageNameTouchBarAlarmTemplate, false));
			imageItemView.setAlignment(ImageAlignment.CENTER);
			
			return imageItemView;
		}
	}
	
	@Override
	public int getNumberOfItems(TouchBarScrubber scrubber) {
		return 2;
	}
});

jTouchBar.addItem(new TouchBarItem("Scrubber_1", touchBarScrubber, true));

License

This project is licensed under the MIT License - see the LICENSE file for details

About

Java library for using the touchbar API on supported macbooks.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C++ 46.5%
  • Java 44.2%
  • Objective-C 6.0%
  • C++ 1.3%
  • Shell 1.1%
  • C 0.9%