├── .github
└── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── .gitignore
├── LICENSE
├── README.md
├── doc
└── readme
│ ├── stylus-javafx.png
│ └── stylus-swing.png
├── pom.xml
├── stylus-awt
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── lecturestudio
│ └── stylus
│ └── awt
│ ├── AwtComponentState.java
│ └── AwtStylusManager.java
├── stylus-demo
├── pom.xml
├── stylus-demo-api
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── org
│ │ └── lecturestudio
│ │ └── stylus
│ │ └── demo
│ │ ├── action
│ │ ├── Action.java
│ │ ├── ActionController.java
│ │ ├── ClearShapesAction.java
│ │ ├── NewShapeAction.java
│ │ └── ShapeAction.java
│ │ ├── beans
│ │ ├── BooleanProperty.java
│ │ ├── ChangeListener.java
│ │ ├── DoubleProperty.java
│ │ ├── IntegerProperty.java
│ │ ├── ListenerManager.java
│ │ ├── ObjectProperty.java
│ │ ├── Observable.java
│ │ ├── ObservableBase.java
│ │ ├── Property.java
│ │ ├── StringProperty.java
│ │ └── converter
│ │ │ └── Converter.java
│ │ ├── geometry
│ │ └── StylusPoint.java
│ │ ├── model
│ │ ├── Shape.java
│ │ ├── Shapes.java
│ │ ├── ShapesChangeListener.java
│ │ └── StrokeShape.java
│ │ ├── paint
│ │ ├── Color.java
│ │ ├── StylusBrush.java
│ │ └── StylusStroke.java
│ │ ├── presenter
│ │ ├── CanvasPresenter.java
│ │ ├── InfoPresenter.java
│ │ ├── MainPresenter.java
│ │ ├── Presenter.java
│ │ └── ToolbarPresenter.java
│ │ ├── render
│ │ ├── RenderSurface.java
│ │ └── RenderSurfaceRenderer.java
│ │ ├── tool
│ │ ├── ClearTool.java
│ │ ├── EraserTool.java
│ │ ├── PenTool.java
│ │ ├── RedoTool.java
│ │ ├── StylusTool.java
│ │ ├── Tool.java
│ │ ├── ToolController.java
│ │ └── UndoTool.java
│ │ └── view
│ │ ├── Action.java
│ │ ├── CanvasView.java
│ │ ├── ConsumerAction.java
│ │ ├── InfoView.java
│ │ ├── MainView.java
│ │ ├── ToolbarView.java
│ │ └── View.java
├── stylus-demo-awt
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── org
│ │ │ └── lecturestudio
│ │ │ └── stylus
│ │ │ └── demo
│ │ │ └── awt
│ │ │ ├── DemoApplication.java
│ │ │ ├── beans
│ │ │ └── converter
│ │ │ │ └── ColorConverter.java
│ │ │ ├── control
│ │ │ └── ColorChooserButton.java
│ │ │ ├── inject
│ │ │ └── AwtViewModule.java
│ │ │ ├── render
│ │ │ └── PenRenderer.java
│ │ │ ├── util
│ │ │ └── AwtUtils.java
│ │ │ └── view
│ │ │ ├── AwtCanvasView.java
│ │ │ ├── AwtInfoView.java
│ │ │ ├── AwtMainView.java
│ │ │ └── AwtToolbarView.java
│ │ └── resources
│ │ └── cursor.png
└── stylus-demo-javafx
│ ├── pom.xml
│ └── src
│ └── main
│ ├── java
│ └── org
│ │ └── lecturestudio
│ │ └── stylus
│ │ └── demo
│ │ └── javafx
│ │ ├── DemoApplication.java
│ │ ├── DemoApplicationLauncher.java
│ │ ├── beans
│ │ ├── BeanManager.java
│ │ ├── BooleanPropertyBridge.java
│ │ ├── ColorPropertyBridge.java
│ │ ├── ConvertibleObjectProperty.java
│ │ ├── DoublePropertyBridge.java
│ │ ├── IntegerPropertyBridge.java
│ │ ├── StringPropertyBridge.java
│ │ └── converter
│ │ │ └── ColorConverter.java
│ │ ├── control
│ │ ├── ButtonGroup.java
│ │ └── ButtonGroupSkin.java
│ │ ├── inject
│ │ └── FxViewModule.java
│ │ ├── render
│ │ └── PenRenderer.java
│ │ ├── util
│ │ └── FxUtils.java
│ │ └── view
│ │ ├── FxCanvasView.java
│ │ ├── FxInfoView.java
│ │ ├── FxMainView.java
│ │ └── FxToolbarView.java
│ └── resources
│ └── cursor.png
├── stylus-javafx
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── lecturestudio
│ └── stylus
│ └── javafx
│ ├── JavaFxComponentState.java
│ └── JavaFxStylusManager.java
├── stylus-jni
├── pom.xml
└── src
│ └── main
│ └── cpp
│ ├── CMakeLists.txt
│ ├── dependencies
│ ├── core
│ │ ├── CMakeLists.txt
│ │ ├── include
│ │ │ ├── Convert.h
│ │ │ ├── DeviceList.h
│ │ │ ├── Event.h
│ │ │ ├── EventDispatcher.h
│ │ │ ├── Queue.h
│ │ │ ├── Stylus.h
│ │ │ ├── StylusAxesData.h
│ │ │ ├── StylusAxisContext.h
│ │ │ ├── StylusDevice.h
│ │ │ ├── StylusDeviceListener.h
│ │ │ ├── StylusEvent.h
│ │ │ ├── StylusException.h
│ │ │ ├── StylusListener.h
│ │ │ ├── StylusManager.h
│ │ │ └── StylusUtils.h
│ │ └── src
│ │ │ ├── StylusAxesData.cpp
│ │ │ ├── StylusAxisContext.cpp
│ │ │ ├── StylusDevice.cpp
│ │ │ ├── StylusEvent.cpp
│ │ │ ├── StylusException.cpp
│ │ │ ├── StylusManager.cpp
│ │ │ └── StylusUtils.cpp
│ ├── jni-voithos
│ │ ├── CMakeLists.txt
│ │ ├── LICENSE
│ │ ├── include
│ │ │ ├── Exception.h
│ │ │ ├── JavaArray.h
│ │ │ ├── JavaArrayList.h
│ │ │ ├── JavaBigInteger.h
│ │ │ ├── JavaClass.h
│ │ │ ├── JavaClasses.h
│ │ │ ├── JavaContext.h
│ │ │ ├── JavaDimension.h
│ │ │ ├── JavaEnum.h
│ │ │ ├── JavaEnums.h
│ │ │ ├── JavaError.h
│ │ │ ├── JavaFactories.h
│ │ │ ├── JavaFactory.h
│ │ │ ├── JavaHashMap.h
│ │ │ ├── JavaIOException.h
│ │ │ ├── JavaIterable.h
│ │ │ ├── JavaList.h
│ │ │ ├── JavaMapIterator.h
│ │ │ ├── JavaNullPointerException.h
│ │ │ ├── JavaObject.h
│ │ │ ├── JavaPrimitive.h
│ │ │ ├── JavaRectangle.h
│ │ │ ├── JavaRef.h
│ │ │ ├── JavaRuntimeException.h
│ │ │ ├── JavaString.h
│ │ │ ├── JavaThreadEnv.h
│ │ │ ├── JavaThrowable.h
│ │ │ ├── JavaUtils.h
│ │ │ ├── JavaWrappedException.h
│ │ │ └── windows
│ │ │ │ ├── ComInitializer.h
│ │ │ │ ├── ComPtr.h
│ │ │ │ └── WinUtils.h
│ │ └── src
│ │ │ ├── Exception.cpp
│ │ │ ├── JavaArrayList.cpp
│ │ │ ├── JavaBigInteger.cpp
│ │ │ ├── JavaContext.cpp
│ │ │ ├── JavaDimension.cpp
│ │ │ ├── JavaHashMap.cpp
│ │ │ ├── JavaIterable.cpp
│ │ │ ├── JavaList.cpp
│ │ │ ├── JavaMapIterator.cpp
│ │ │ ├── JavaObject.cpp
│ │ │ ├── JavaRectangle.cpp
│ │ │ ├── JavaString.cpp
│ │ │ ├── JavaThreadEnv.cpp
│ │ │ ├── JavaThrowable.cpp
│ │ │ ├── JavaUtils.cpp
│ │ │ ├── JavaWrappedException.cpp
│ │ │ └── windows
│ │ │ └── ComInitializer.cpp
│ ├── linux
│ │ └── x11
│ │ │ ├── CMakeLists.txt
│ │ │ ├── include
│ │ │ ├── X11InputDevice.h
│ │ │ ├── X11MouseDevice.h
│ │ │ ├── X11StylusManager.h
│ │ │ ├── X11TabletDevice.h
│ │ │ └── X11Utils.h
│ │ │ └── src
│ │ │ ├── X11InputDevice.cpp
│ │ │ ├── X11MouseDevice.cpp
│ │ │ ├── X11StylusManager.cpp
│ │ │ ├── X11TabletDevice.cpp
│ │ │ └── X11Utils.cpp
│ ├── macos
│ │ └── cocoa
│ │ │ ├── CMakeLists.txt
│ │ │ ├── include
│ │ │ ├── CocoaStylusContext.h
│ │ │ ├── CocoaStylusDevice.h
│ │ │ ├── CocoaStylusHook.h
│ │ │ └── CocoaStylusManager.h
│ │ │ └── src
│ │ │ ├── CocoaStylusContext.mm
│ │ │ ├── CocoaStylusDevice.mm
│ │ │ ├── CocoaStylusHook.mm
│ │ │ └── CocoaStylusManager.mm
│ └── windows
│ │ ├── lib
│ │ └── x86-64
│ │ │ └── jawt.lib
│ │ └── rts
│ │ ├── CMakeLists.txt
│ │ ├── include
│ │ ├── RealTimeStylusCursorContext.h
│ │ ├── RealTimeStylusDevice.h
│ │ ├── RealTimeStylusEventHandler.h
│ │ ├── RealTimeStylusManager.h
│ │ └── RealTimeStylusUtils.h
│ │ └── src
│ │ ├── RealTimeStylusCursorContext.cpp
│ │ ├── RealTimeStylusDevice.cpp
│ │ ├── RealTimeStylusEventHandler.cpp
│ │ ├── RealTimeStylusManager.cpp
│ │ └── RealTimeStylusUtils.cpp
│ ├── include
│ ├── JNI_Stylus.h
│ ├── JNI_StylusContext.h
│ ├── JNI_StylusDevice.h
│ ├── JNI_StylusEvent.h
│ ├── JNI_StylusListener.h
│ └── JNI_StylusManager.h
│ └── src
│ ├── JNI_Stylus.cpp
│ ├── JNI_StylusContext.cpp
│ ├── JNI_StylusDevice.cpp
│ ├── JNI_StylusEvent.cpp
│ ├── JNI_StylusListener.cpp
│ └── JNI_StylusManager.cpp
└── stylus
├── pom.xml
└── src
└── main
└── java
├── module-info.java
└── org
└── lecturestudio
└── stylus
├── StylusAxesData.java
├── StylusAxis.java
├── StylusButton.java
├── StylusCursor.java
├── StylusDevice.java
├── StylusEvent.java
├── StylusListener.java
├── StylusManager.java
└── internal
└── NativeLoader.java
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. Windows]
28 |
29 | **Additional context**
30 | Add any other context about the problem here.
31 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Eclipse Core
2 | **/.classpath
3 | **/.project
4 | **/.settings/
5 |
6 | # IntelliJ IDEA
7 | **/*.iml
8 | **/.idea
9 |
10 | # Maven Build
11 | **/target
12 |
13 | # Compiled libraries
14 | *.so
15 | *.dylib
16 | *.dll
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Stylus pen input for Java
2 |
3 | Java native interface implementation for pressure-sensitive input devices.
4 |
5 | ```xml
6 |
7 | org.lecturestudio.stylus
8 | stylus
9 | 0.3.0
10 |
11 | ```
12 |
13 | Swing | JavaFX
14 | :-------------------------:|:-------------------------:
15 |  | 
16 |
17 | ### Supported Platforms
18 | By default, the main artifact depends on the native library corresponding to the system you are running your build or application on.
19 | The native libraries can be loaded on the following platforms:
20 |
21 | | Operating System | Classifier |
22 | | ---------------- |-----------------------------|
23 | | Linux | linux-x86_64 |
24 | | macOS | macos-x86_64, macos-aarch64 |
25 | | Windows | windows-x86_64 |
26 |
27 | ### Build Notes
28 |
29 | In order to build the native code, be sure to install the prerequisite software and libraries:
30 |
31 |
32 |
33 | Linux |
34 | gcc, g++, libstdc++, libX11-dev, libxi-dev (e.g. for Ubuntu, names may differ depending on your distro) |
35 |
36 |
37 | macOS |
38 | Xcode 9 or higher |
39 |
40 |
41 | Windows |
42 | Visual Studio 2017 or higher |
43 |
44 |
45 |
46 | Assuming you have all the prerequisites installed for your OS, run:
47 |
48 | ```
49 | mvn install
50 | ```
51 |
52 | #### Troubleshooting
53 |
54 | ##### On Linux
55 | If you get the error `/usr/bin/ld: cannot find -ljawt` while linking, perform following steps:
56 | 1. Find the path where JDK is installed: `which java` or `whereis java`.
57 | Exemplary output: `/usr/lib/jvm/java-16/bin/java`
58 | 2. Create a symbolic link to libjawt.so: `ln -s /usr/lib/jvm/java-16/lib/libjawt.so /usr/lib/` (according to the exemplary output above).
59 | 3. Build the project again.
60 |
--------------------------------------------------------------------------------
/doc/readme/stylus-javafx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lectureStudio/stylus/d93bf907b89bef96a625093699b7b14bfedcccdc/doc/readme/stylus-javafx.png
--------------------------------------------------------------------------------
/doc/readme/stylus-swing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lectureStudio/stylus/d93bf907b89bef96a625093699b7b14bfedcccdc/doc/readme/stylus-swing.png
--------------------------------------------------------------------------------
/stylus-awt/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.lecturestudio.stylus
7 | stylus-parent
8 | 0.4.0-SNAPSHOT
9 |
10 |
11 | stylus-awt
12 |
13 |
14 |
15 | org.lecturestudio.stylus
16 | stylus
17 | ${project.parent.version}
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/stylus-awt/src/main/java/org/lecturestudio/stylus/awt/AwtComponentState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.awt;
18 |
19 | import java.awt.Point;
20 | import java.awt.event.ComponentListener;
21 | import java.awt.event.MouseListener;
22 |
23 | import org.lecturestudio.stylus.StylusListener;
24 |
25 | class AwtComponentState {
26 |
27 | ComponentListener componentListener;
28 |
29 | MouseListener mouseListener;
30 |
31 | StylusListener stylusListener;
32 |
33 | Point location;
34 |
35 | boolean componentClicked;
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/stylus-demo/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.lecturestudio.stylus
7 | stylus-parent
8 | 0.4.0-SNAPSHOT
9 |
10 |
11 | org.lecturestudio.stylus.demo
12 | stylus-demo
13 | pom
14 |
15 |
16 | stylus-demo-api
17 | stylus-demo-javafx
18 | stylus-demo-awt
19 |
20 |
21 |
22 |
23 |
24 | org.apache.maven.plugins
25 | maven-deploy-plugin
26 |
27 | true
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | org.lecturestudio.stylus
36 | stylus
37 | ${project.version}
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.lecturestudio.stylus.demo
7 | stylus-demo
8 | 0.4.0-SNAPSHOT
9 |
10 |
11 | stylus-demo-api
12 |
13 |
14 |
15 | com.google.inject
16 | guice
17 | 5.0.1
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/action/Action.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.action;
18 |
19 | public interface Action {
20 |
21 | void execute();
22 |
23 | void undo();
24 |
25 | void redo();
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/action/ClearShapesAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.action;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import org.lecturestudio.stylus.demo.model.Shape;
23 |
24 | public class ClearShapesAction extends ShapeAction {
25 |
26 | private List removedShapes;
27 |
28 |
29 | public ClearShapesAction() {
30 | }
31 |
32 | @Override
33 | public void execute() {
34 | removedShapes = new ArrayList<>(shapes.getShapes());
35 | shapes.clear();
36 | }
37 |
38 | @Override
39 | public void undo() {
40 | shapes.addAll(removedShapes);
41 | }
42 |
43 | @Override
44 | public void redo() {
45 | execute();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/action/NewShapeAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.action;
18 |
19 | import org.lecturestudio.stylus.demo.model.Shape;
20 |
21 | public class NewShapeAction extends ShapeAction {
22 |
23 | private Shape shape;
24 |
25 |
26 | public NewShapeAction(Shape shape) {
27 | this.shape = shape;
28 | }
29 |
30 | @Override
31 | public void execute() {
32 | shapes.add(shape);
33 | }
34 |
35 | @Override
36 | public void undo() {
37 | shapes.remove(shape);
38 | }
39 |
40 | @Override
41 | public void redo() {
42 | execute();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/action/ShapeAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.action;
18 |
19 | import org.lecturestudio.stylus.demo.model.Shapes;
20 |
21 | public abstract class ShapeAction implements Action {
22 |
23 | protected Shapes shapes;
24 |
25 |
26 | public void setShapes(Shapes shapes) {
27 | this.shapes = shapes;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/BooleanProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans;
18 |
19 | public class BooleanProperty extends ObjectProperty {
20 |
21 | public BooleanProperty() {
22 | this(false);
23 | }
24 |
25 | public BooleanProperty(boolean defaultValue) {
26 | super(null);
27 |
28 | set(defaultValue);
29 | }
30 |
31 | public BooleanProperty(Object bean) {
32 | super(bean);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/ChangeListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans;
18 |
19 | import java.util.Objects;
20 |
21 | @FunctionalInterface
22 | public interface ChangeListener {
23 |
24 | /**
25 | * This method is called if the value of an {@code Observable} has changed.
26 | *
27 | * @param observable The Observable of which the value changed.
28 | * @param oldValue The old value.
29 | * @param newValue The new value.
30 | */
31 | void changed(Observable extends T> observable, T oldValue, T newValue);
32 |
33 | /**
34 | * Returns a composed {@code ChangeListener} that performs, in sequence, this
35 | * operation followed by the {@code after} operation. If performing either
36 | * operation throws an exception, it is relayed to the caller of the
37 | * composed operation. If performing this operation throws an exception,
38 | * the {@code after} operation will not be performed.
39 | *
40 | * @param after the operation to perform after this operation.
41 | *
42 | * @return a composed {@code ChangeListener} that performs in sequence this
43 | * operation followed by the {@code after} operation.
44 | *
45 | * @throws NullPointerException if {@code after} is null.
46 | */
47 | default ChangeListener andThen(ChangeListener super T> after) {
48 | Objects.requireNonNull(after);
49 |
50 | return (Observable extends T> observable, T oldValue, T newValue) -> {
51 | changed(observable, oldValue, newValue);
52 | after.changed(observable, oldValue, newValue);
53 | };
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/DoubleProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans;
18 |
19 | public class DoubleProperty extends ObjectProperty {
20 |
21 | public DoubleProperty() {
22 | this(0);
23 | }
24 |
25 | public DoubleProperty(double defaultValue) {
26 | super(null);
27 |
28 | set(defaultValue);
29 | }
30 |
31 | public DoubleProperty(Object bean) {
32 | super(bean);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/IntegerProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans;
18 |
19 | public class IntegerProperty extends ObjectProperty {
20 |
21 | public IntegerProperty() {
22 | this(0);
23 | }
24 |
25 | public IntegerProperty(int defaultValue) {
26 | super(null);
27 |
28 | set(defaultValue);
29 | }
30 |
31 | public IntegerProperty(Object bean) {
32 | super(bean);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/ListenerManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | class ListenerManager {
23 |
24 | private final List> listeners = new ArrayList<>();
25 |
26 |
27 | void addListener(ChangeListener super T> listener) {
28 | listeners.add(listener);
29 | }
30 |
31 | void removeListener(ChangeListener super T> listener) {
32 | listeners.remove(listener);
33 | }
34 |
35 | void fireChange(Observable observable, T oldValue, T newValue) {
36 | for (ChangeListener super T> listener : listeners) {
37 | listener.changed(observable, oldValue, newValue);
38 | }
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/ObjectProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans;
18 |
19 | public class ObjectProperty extends ObservableBase implements Property {
20 |
21 | private T value;
22 |
23 |
24 | public ObjectProperty() {
25 | super(null);
26 | }
27 |
28 | public ObjectProperty(Object bean) {
29 | super(bean);
30 | }
31 |
32 | @Override
33 | public T get() {
34 | return value;
35 | }
36 |
37 | @Override
38 | public void set(T newValue) {
39 | if (value != newValue) {
40 | T oldValue = value;
41 | value = newValue;
42 |
43 | fireChange(this, oldValue, newValue);
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/Observable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans;
18 |
19 | public interface Observable {
20 |
21 | /**
22 | * Adds the given listener in order to be notified whenever the value of
23 | * this Observable changes.
24 | *
25 | * @param listener The listener to register.
26 | *
27 | * @throws NullPointerException if the listener is null.
28 | */
29 | void addListener(ChangeListener super T> listener);
30 |
31 | /**
32 | * Removes the given listener from the list of listeners. This method call
33 | * has no effect if the given listener has not been previously registered.
34 | *
35 | * @param listener The listener to remove.
36 | *
37 | * @throws NullPointerException if the listener is null.
38 | */
39 | void removeListener(ChangeListener super T> listener);
40 |
41 | /**
42 | * Returns the Object that contains this Observable. If this Observable is not
43 | * contained in an Object, null is returned.
44 | *
45 | * @return The Object that contains this Observable or null.
46 | */
47 | Object getBean();
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/ObservableBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans;
18 |
19 | import static java.util.Objects.isNull;
20 | import static java.util.Objects.nonNull;
21 |
22 | public abstract class ObservableBase implements Observable {
23 |
24 | private final Object bean;
25 |
26 | private ListenerManager listenerManager;
27 |
28 |
29 | public ObservableBase() {
30 | this(null);
31 | }
32 |
33 | public ObservableBase(Object bean) {
34 | this.bean = bean;
35 | }
36 |
37 | @Override
38 | public void addListener(ChangeListener super T> listener) {
39 | if (isNull(listenerManager)) {
40 | listenerManager = new ListenerManager<>();
41 | }
42 |
43 | listenerManager.addListener(listener);
44 | }
45 |
46 | @Override
47 | public void removeListener(ChangeListener super T> listener) {
48 | if (nonNull(listenerManager)) {
49 | listenerManager.removeListener(listener);
50 | }
51 | }
52 |
53 | @Override
54 | public Object getBean() {
55 | return bean;
56 | }
57 |
58 | protected void fireChange(Observable observable, T oldValue, T newValue) {
59 | if (nonNull(listenerManager)) {
60 | listenerManager.fireChange(observable, oldValue, newValue);
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/Property.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans;
18 |
19 | public interface Property {
20 |
21 | /**
22 | * Returns the current value of this Observable.
23 | *
24 | * @return The current value.
25 | */
26 | T get();
27 |
28 | /**
29 | * Set the new value.
30 | *
31 | * @param value The new value.
32 | */
33 | void set(T value);
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/StringProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans;
18 |
19 | public class StringProperty extends ObjectProperty {
20 |
21 | public StringProperty() {
22 | super(null);
23 | }
24 |
25 | public StringProperty(String defaultValue) {
26 | super(null);
27 |
28 | set(defaultValue);
29 | }
30 |
31 | public StringProperty(Object bean) {
32 | super(bean);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/beans/converter/Converter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.beans.converter;
18 |
19 | public interface Converter {
20 |
21 | T to(S value);
22 |
23 | S from(T value);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/model/Shape.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.model;
18 |
19 | public interface Shape {
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/model/ShapesChangeListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.model;
18 |
19 | import java.util.Collection;
20 |
21 | public interface ShapesChangeListener {
22 |
23 | void onShapeInserted(Shapes shapes, Shape shape);
24 |
25 | void onShapesInserted(Shapes shapes, Collection list);
26 |
27 | void onShapeRemoved(Shapes shapes, Shape shape);
28 |
29 | void onShapesRemoved(Shapes shapes, Collection list);
30 | }
31 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/model/StrokeShape.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.model;
18 |
19 | import org.lecturestudio.stylus.demo.paint.StylusBrush;
20 | import org.lecturestudio.stylus.demo.paint.StylusStroke;
21 |
22 | public class StrokeShape implements Shape {
23 |
24 | private final StylusBrush brush;
25 |
26 | private final StylusStroke stroke;
27 |
28 |
29 | public StrokeShape(StylusStroke stroke, StylusBrush brush) {
30 | this.stroke = stroke;
31 | this.brush = brush;
32 | }
33 |
34 | public StylusBrush getBrush() {
35 | return brush;
36 | }
37 |
38 | public StylusStroke getStroke() {
39 | return stroke;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/paint/StylusBrush.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.lecturestudio.stylus.demo.paint;
17 |
18 | import org.lecturestudio.stylus.demo.beans.DoubleProperty;
19 | import org.lecturestudio.stylus.demo.beans.ObjectProperty;
20 |
21 | public class StylusBrush {
22 |
23 | private ObjectProperty color = new ObjectProperty<>();
24 |
25 | private DoubleProperty width = new DoubleProperty();
26 |
27 |
28 | public StylusBrush() {
29 | this(Color.BLUE, 12);
30 | }
31 |
32 | public StylusBrush(StylusBrush brush) {
33 | this(brush.getColor(), brush.getWidth());
34 | }
35 |
36 | public StylusBrush(Color color, double width) {
37 | setColor(color);
38 | setWidth(width);
39 | }
40 |
41 | public ObjectProperty colorProperty() {
42 | return color;
43 | }
44 |
45 | public void setColor(Color color) {
46 | this.color.set(color);
47 | }
48 |
49 | public Color getColor() {
50 | return color.get();
51 | }
52 |
53 | public DoubleProperty widthProperty() {
54 | return width;
55 | }
56 |
57 | public void setWidth(double width) {
58 | this.width.set(width);
59 | }
60 |
61 | public double getWidth() {
62 | return width.get();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/paint/StylusStroke.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.lecturestudio.stylus.demo.paint;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Collections;
20 | import java.util.List;
21 |
22 | import org.lecturestudio.stylus.demo.geometry.StylusPoint;
23 |
24 | public class StylusStroke {
25 |
26 | private final List points;
27 |
28 | private boolean changing;
29 |
30 |
31 | public StylusStroke() {
32 | this.points = Collections.synchronizedList(new ArrayList<>());
33 | this.changing = false;
34 | }
35 |
36 | public void addPoint(StylusPoint point) {
37 | points.add(point);
38 | }
39 |
40 | public List getPoints() {
41 | return points;
42 | }
43 |
44 | public boolean isChanging() {
45 | return changing;
46 | }
47 |
48 | public void setChanging(boolean changing) {
49 | this.changing = changing;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/presenter/InfoPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.presenter;
18 |
19 | import javax.inject.Inject;
20 |
21 | import org.lecturestudio.stylus.StylusEvent;
22 | import org.lecturestudio.stylus.demo.tool.ToolController;
23 | import org.lecturestudio.stylus.demo.view.InfoView;
24 |
25 | public class InfoPresenter extends Presenter {
26 |
27 | @Inject
28 | InfoPresenter(InfoView view, ToolController toolController) {
29 | super(view);
30 |
31 | toolController.setStylusEventListener(this::setStylusEvent);
32 | }
33 |
34 | void setStylusEvent(StylusEvent event) {
35 | view.update(event);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/presenter/MainPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.presenter;
18 |
19 | import javax.inject.Inject;
20 |
21 | import org.lecturestudio.stylus.demo.view.MainView;
22 |
23 | public class MainPresenter extends Presenter {
24 |
25 | @Inject
26 | private ToolbarPresenter toolbarPresenter;
27 |
28 | @Inject
29 | private CanvasPresenter canvasPresenter;
30 |
31 | @Inject
32 | private InfoPresenter infoPresenter;
33 |
34 |
35 | @Inject
36 | MainPresenter(MainView view) {
37 | super(view);
38 | }
39 |
40 | public void close() {
41 | view.close();
42 | }
43 |
44 | public void initialize() {
45 | view.setToolbar(toolbarPresenter.getView());
46 | view.setInfo(infoPresenter.getView());
47 | view.setCanvas(canvasPresenter.getView());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/presenter/Presenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.presenter;
18 |
19 | import static java.util.Objects.requireNonNull;
20 |
21 | import org.lecturestudio.stylus.demo.view.View;
22 |
23 | /**
24 | *
25 | *
26 | * @author Alex Andres
27 | *
28 | * @param The type of the view.
29 | */
30 | public abstract class Presenter {
31 |
32 | protected final T view;
33 |
34 |
35 | public Presenter(T view) {
36 | requireNonNull(view);
37 |
38 | this.view = view;
39 | }
40 |
41 | public T getView() {
42 | return view;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/presenter/ToolbarPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.presenter;
18 |
19 | import javax.inject.Inject;
20 |
21 | import org.lecturestudio.stylus.demo.action.ActionController;
22 | import org.lecturestudio.stylus.demo.tool.ToolController;
23 | import org.lecturestudio.stylus.demo.view.ToolbarView;
24 |
25 | public class ToolbarPresenter extends Presenter {
26 |
27 | private final ToolController toolController;
28 |
29 |
30 | @Inject
31 | ToolbarPresenter(ToolbarView view, ToolController toolController) {
32 | super(view);
33 |
34 | this.toolController = toolController;
35 |
36 | initialize();
37 | }
38 |
39 | private void initialize() {
40 | ActionController actionController = toolController.getActionController();
41 | actionController.setOnAction(() -> {
42 | view.setEnableUndo(actionController.canUndo());
43 | view.setEnableRedo(actionController.canRedo());
44 | });
45 |
46 | view.setBrush(toolController.getBrush());
47 | view.setOnClear(toolController::clear);
48 | view.setOnRedo(toolController::redo);
49 | view.setOnUndo(toolController::undo);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/render/RenderSurface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.render;
18 |
19 | import java.util.Collection;
20 |
21 | import org.lecturestudio.stylus.demo.model.Shape;
22 |
23 | public interface RenderSurface {
24 |
25 | void clear();
26 |
27 | void render(S shape);
28 |
29 | void render(Collection shapes);
30 |
31 | void rerender(Collection shapes);
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/render/RenderSurfaceRenderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.render;
18 |
19 | import org.lecturestudio.stylus.demo.model.Shape;
20 |
21 | public interface RenderSurfaceRenderer {
22 |
23 | void render(S shape, T renderContext);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/tool/ClearTool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.tool;
18 |
19 | import org.lecturestudio.stylus.demo.action.ActionController;
20 | import org.lecturestudio.stylus.demo.action.ClearShapesAction;
21 |
22 | public class ClearTool implements Tool {
23 |
24 | @Override
25 | public void execute(ActionController actionController) {
26 | actionController.execute(new ClearShapesAction());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/tool/PenTool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.tool;
18 |
19 | import org.lecturestudio.stylus.StylusAxesData;
20 | import org.lecturestudio.stylus.demo.action.ActionController;
21 | import org.lecturestudio.stylus.demo.action.NewShapeAction;
22 | import org.lecturestudio.stylus.demo.geometry.StylusPoint;
23 | import org.lecturestudio.stylus.demo.model.StrokeShape;
24 | import org.lecturestudio.stylus.demo.paint.StylusBrush;
25 | import org.lecturestudio.stylus.demo.paint.StylusStroke;
26 | import org.lecturestudio.stylus.demo.render.RenderSurface;
27 |
28 | public class PenTool implements StylusTool {
29 |
30 | private RenderSurface renderSurface;
31 |
32 | private StrokeShape shape;
33 |
34 | private StylusBrush brush;
35 |
36 | private StylusStroke stroke;
37 |
38 |
39 | public PenTool(StylusBrush brush, RenderSurface renderSurface) {
40 | this.brush = brush;
41 | this.renderSurface = renderSurface;
42 | }
43 |
44 | @Override
45 | public void execute(ActionController actionController) {
46 | stroke = new StylusStroke();
47 | stroke.setChanging(true);
48 |
49 | shape = new StrokeShape(stroke, new StylusBrush(brush));
50 |
51 | actionController.execute(new NewShapeAction(shape));
52 | }
53 |
54 | @Override
55 | public void process(StylusAxesData axesData) {
56 | StylusPoint p = new StylusPoint(axesData.getX(), axesData.getY(), axesData.getPressure());
57 |
58 | stroke.addPoint(p);
59 |
60 | renderSurface.render(shape);
61 | }
62 |
63 | @Override
64 | public void finish() {
65 | stroke.setChanging(false);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/tool/RedoTool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.tool;
18 |
19 | import org.lecturestudio.stylus.demo.action.ActionController;
20 |
21 | public class RedoTool implements Tool {
22 |
23 | @Override
24 | public void execute(ActionController actionController) {
25 | actionController.redo();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/tool/StylusTool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.tool;
18 |
19 | import org.lecturestudio.stylus.StylusAxesData;
20 |
21 | public interface StylusTool extends Tool {
22 |
23 | void process(StylusAxesData axesData);
24 |
25 | void finish();
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/tool/Tool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.tool;
18 |
19 | import org.lecturestudio.stylus.demo.action.ActionController;
20 |
21 | public interface Tool {
22 |
23 | void execute(ActionController actionController);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/tool/UndoTool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.tool;
18 |
19 | import org.lecturestudio.stylus.demo.action.ActionController;
20 |
21 | public class UndoTool implements Tool {
22 |
23 | @Override
24 | public void execute(ActionController actionController) {
25 | actionController.undo();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/view/CanvasView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.view;
18 |
19 | import org.lecturestudio.stylus.StylusCursor;
20 | import org.lecturestudio.stylus.StylusListener;
21 | import org.lecturestudio.stylus.demo.render.RenderSurface;
22 |
23 | public interface CanvasView extends View, RenderSurface {
24 |
25 | void setStylusCursor(StylusCursor cursor);
26 |
27 | void setStylusListener(StylusListener listener);
28 |
29 | void setOnResize(Action action);
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/view/InfoView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.view;
18 |
19 | import org.lecturestudio.stylus.StylusEvent;
20 |
21 | public interface InfoView extends View {
22 |
23 | void update(StylusEvent event);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/view/MainView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.view;
18 |
19 | public interface MainView extends View {
20 |
21 | void close();
22 |
23 | void setToolbar(ToolbarView view);
24 |
25 | void setCanvas(CanvasView view);
26 |
27 | void setInfo(InfoView view);
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/view/ToolbarView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.view;
18 |
19 | import org.lecturestudio.stylus.demo.paint.StylusBrush;
20 |
21 | public interface ToolbarView extends View {
22 |
23 | void setBrush(StylusBrush brush);
24 |
25 | void setEnableUndo(boolean enable);
26 |
27 | void setEnableRedo(boolean enable);
28 |
29 | void setOnClear(Action action);
30 |
31 | void setOnUndo(Action action);
32 |
33 | void setOnRedo(Action action);
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-api/src/main/java/org/lecturestudio/stylus/demo/view/View.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.view;
18 |
19 | import static java.util.Objects.nonNull;
20 |
21 | public interface View {
22 |
23 | default void executeAction(Action action) {
24 | if (nonNull(action)) {
25 | action.execute();
26 | }
27 | }
28 |
29 | default void executeAction(ConsumerAction action, T param) {
30 | if (nonNull(action)) {
31 | action.execute(param);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-awt/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.lecturestudio.stylus.demo
7 | stylus-demo
8 | 0.4.0-SNAPSHOT
9 |
10 |
11 | stylus-demo-awt
12 |
13 |
14 |
15 | shade
16 |
17 |
18 |
19 | org.apache.maven.plugins
20 | maven-shade-plugin
21 | 3.2.1
22 |
23 |
24 | package
25 |
26 | shade
27 |
28 |
29 |
30 |
31 | org.lecturestudio.stylus.demo.awt.DemoApplication
32 |
33 |
34 | ${project.artifactId}-${project.version}-bundle
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.lecturestudio.stylus
47 | stylus-awt
48 | ${project.parent.version}
49 |
50 |
51 | org.lecturestudio.stylus.demo
52 | stylus-demo-api
53 | ${project.version}
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-awt/src/main/java/org/lecturestudio/stylus/demo/awt/DemoApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.lecturestudio.stylus.demo.awt;
17 |
18 | import com.google.inject.Guice;
19 | import com.google.inject.Injector;
20 |
21 | import java.awt.BorderLayout;
22 | import java.awt.Container;
23 | import java.lang.System.Logger;
24 | import java.lang.System.Logger.Level;
25 |
26 | import javax.swing.JFrame;
27 | import javax.swing.SwingUtilities;
28 |
29 | import org.lecturestudio.stylus.demo.awt.inject.AwtViewModule;
30 | import org.lecturestudio.stylus.demo.presenter.MainPresenter;
31 | import org.lecturestudio.stylus.demo.view.MainView;
32 |
33 | public class DemoApplication {
34 |
35 | private static final Logger LOG = System.getLogger(DemoApplication.class.getName());
36 |
37 |
38 | private void start() {
39 | Injector injector = Guice.createInjector(new AwtViewModule());
40 |
41 | MainPresenter mainPresenter = injector.getInstance(MainPresenter.class);
42 | mainPresenter.initialize();
43 |
44 | MainView mainView = mainPresenter.getView();
45 |
46 | JFrame frame = new JFrame();
47 | frame.setTitle("AWT Stylus Demo");
48 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
49 | frame.add((Container) mainView, BorderLayout.CENTER);
50 | frame.setSize(800, 500);
51 | frame.setLocationRelativeTo(null);
52 | frame.setVisible(true);
53 | }
54 |
55 | public static void main(String[] args) {
56 | SwingUtilities.invokeLater(() -> {
57 | try {
58 | DemoApplication app = new DemoApplication();
59 | app.start();
60 | }
61 | catch (Exception e) {
62 | LOG.log(Level.ERROR, "Create window failed.", e);
63 | }
64 | });
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-awt/src/main/java/org/lecturestudio/stylus/demo/awt/beans/converter/ColorConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.awt.beans.converter;
18 |
19 | import java.awt.Color;
20 |
21 | import org.lecturestudio.stylus.demo.beans.converter.Converter;
22 |
23 | public class ColorConverter implements Converter {
24 |
25 | public static final ColorConverter INSTANCE = new ColorConverter();
26 |
27 |
28 | @Override
29 | public Color to(org.lecturestudio.stylus.demo.paint.Color c) {
30 | return new java.awt.Color(c.getRGBA(), true);
31 | }
32 |
33 | @Override
34 | public org.lecturestudio.stylus.demo.paint.Color from(Color c) {
35 | return new org.lecturestudio.stylus.demo.paint.Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-awt/src/main/java/org/lecturestudio/stylus/demo/awt/inject/AwtViewModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.awt.inject;
18 |
19 | import com.google.inject.AbstractModule;
20 |
21 | import org.lecturestudio.stylus.demo.awt.view.AwtCanvasView;
22 | import org.lecturestudio.stylus.demo.awt.view.AwtInfoView;
23 | import org.lecturestudio.stylus.demo.awt.view.AwtMainView;
24 | import org.lecturestudio.stylus.demo.awt.view.AwtToolbarView;
25 | import org.lecturestudio.stylus.demo.view.CanvasView;
26 | import org.lecturestudio.stylus.demo.view.InfoView;
27 | import org.lecturestudio.stylus.demo.view.MainView;
28 | import org.lecturestudio.stylus.demo.view.ToolbarView;
29 |
30 | public class AwtViewModule extends AbstractModule {
31 |
32 | @Override
33 | protected void configure() {
34 | bind(CanvasView.class).to(AwtCanvasView.class);
35 | bind(InfoView.class).to(AwtInfoView.class);
36 | bind(MainView.class).to(AwtMainView.class);
37 | bind(ToolbarView.class).to(AwtToolbarView.class);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-awt/src/main/resources/cursor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lectureStudio/stylus/d93bf907b89bef96a625093699b7b14bfedcccdc/stylus-demo/stylus-demo-awt/src/main/resources/cursor.png
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/DemoApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx;
18 |
19 | import com.google.inject.Guice;
20 | import com.google.inject.Injector;
21 |
22 | import javafx.application.Application;
23 | import javafx.scene.Parent;
24 | import javafx.scene.Scene;
25 | import javafx.stage.Stage;
26 |
27 | import org.lecturestudio.stylus.demo.javafx.inject.FxViewModule;
28 | import org.lecturestudio.stylus.demo.presenter.MainPresenter;
29 | import org.lecturestudio.stylus.demo.view.MainView;
30 |
31 | public class DemoApplication extends Application {
32 |
33 | @Override
34 | public void start(Stage primaryStage) {
35 | Injector injector = Guice.createInjector(new FxViewModule());
36 |
37 | MainPresenter mainPresenter = injector.getInstance(MainPresenter.class);
38 | mainPresenter.initialize();
39 |
40 | MainView mainView = mainPresenter.getView();
41 |
42 | Scene scene = new Scene((Parent) mainView, 800, 500);
43 |
44 | primaryStage.setTitle("JavaFX Stylus Demo");
45 | primaryStage.setScene(scene);
46 | primaryStage.show();
47 | primaryStage.setOnCloseRequest(event -> System.exit(0));
48 | }
49 |
50 | public static void main(String[] args) {
51 | launch(args);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/DemoApplicationLauncher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx;
18 |
19 | public class DemoApplicationLauncher {
20 |
21 | public static void main(String[] args) {
22 | DemoApplication.main(args);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/beans/BeanManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.beans;
18 |
19 | import static java.util.Objects.isNull;
20 | import static java.util.Objects.nonNull;
21 |
22 | import java.util.HashMap;
23 | import java.util.HashSet;
24 | import java.util.Map;
25 | import java.util.Set;
26 |
27 | import javafx.beans.property.Property;
28 |
29 | public class BeanManager {
30 |
31 | private final Map, Set>> propertyMap = new HashMap<>();
32 |
33 |
34 | public void bindBidirectional(Property a, Property b) {
35 | a.bindBidirectional(b);
36 |
37 | Set> set = propertyMap.get(a);
38 |
39 | if (isNull(set)) {
40 | set = new HashSet<>();
41 |
42 | propertyMap.put(a, set);
43 | }
44 |
45 | set.add(b);
46 | }
47 |
48 | @SuppressWarnings("unchecked")
49 | public void unbindBidirectional(Property property) {
50 | Set> set = propertyMap.get(property);
51 |
52 | if (nonNull(set)) {
53 | for (Property> p : set) {
54 | property.unbindBidirectional((Property) p);
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/beans/BooleanPropertyBridge.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.beans;
18 |
19 | import static java.util.Objects.nonNull;
20 |
21 | import javafx.beans.property.BooleanPropertyBase;
22 |
23 | import org.lecturestudio.stylus.demo.beans.BooleanProperty;
24 | import org.lecturestudio.stylus.demo.beans.ChangeListener;
25 |
26 | public class BooleanPropertyBridge extends BooleanPropertyBase {
27 |
28 | private final BooleanProperty wrappedProperty;
29 |
30 | private final ChangeListener changeListener;
31 |
32 |
33 | public BooleanPropertyBridge(BooleanProperty property) {
34 | this.wrappedProperty = property;
35 |
36 | changeListener = (observable, oldValue, newValue) -> {
37 | invalidated();
38 | fireValueChangedEvent();
39 | };
40 |
41 | wrappedProperty.addListener(changeListener);
42 | }
43 |
44 | @Override
45 | public Object getBean() {
46 | return null;
47 | }
48 |
49 | @Override
50 | public String getName() {
51 | return null;
52 | }
53 |
54 | @Override
55 | public boolean get() {
56 | return wrappedProperty.get();
57 | }
58 |
59 | @Override
60 | public void set(boolean value) {
61 | wrappedProperty.set(value);
62 | }
63 |
64 | @Override
65 | public void unbind() {
66 | super.unbind();
67 |
68 | if (nonNull(wrappedProperty)) {
69 | wrappedProperty.removeListener(changeListener);
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/beans/ColorPropertyBridge.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.beans;
18 |
19 | import javafx.scene.paint.Color;
20 |
21 | import org.lecturestudio.stylus.demo.beans.ObjectProperty;
22 | import org.lecturestudio.stylus.demo.javafx.beans.converter.ColorConverter;
23 |
24 | public class ColorPropertyBridge extends ConvertibleObjectProperty {
25 |
26 | public ColorPropertyBridge(ObjectProperty property) {
27 | super(property, ColorConverter.INSTANCE);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/beans/ConvertibleObjectProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.beans;
18 |
19 | import static java.util.Objects.nonNull;
20 |
21 | import javafx.beans.property.ObjectPropertyBase;
22 |
23 | import org.lecturestudio.stylus.demo.beans.ChangeListener;
24 | import org.lecturestudio.stylus.demo.beans.ObjectProperty;
25 | import org.lecturestudio.stylus.demo.beans.converter.Converter;
26 |
27 | public class ConvertibleObjectProperty extends ObjectPropertyBase {
28 |
29 | private final ChangeListener changeListener;
30 |
31 | protected final ObjectProperty wrappedProperty;
32 |
33 | protected final Converter converter;
34 |
35 |
36 | public ConvertibleObjectProperty(ObjectProperty property, Converter converter) {
37 | this.wrappedProperty = property;
38 | this.converter = converter;
39 |
40 | changeListener = (observable, oldValue, newValue) -> {
41 | invalidated();
42 | fireValueChangedEvent();
43 | };
44 |
45 | wrappedProperty.addListener(changeListener);
46 | }
47 |
48 | @Override
49 | public Object getBean() {
50 | return null;
51 | }
52 |
53 | @Override
54 | public String getName() {
55 | return null;
56 | }
57 |
58 | @Override
59 | public T get() {
60 | return converter.to(wrappedProperty.get());
61 | }
62 |
63 | @Override
64 | public void set(T value) {
65 | wrappedProperty.set(converter.from(value));
66 | }
67 |
68 | @Override
69 | public void unbind() {
70 | super.unbind();
71 |
72 | if (nonNull(wrappedProperty)) {
73 | wrappedProperty.removeListener(changeListener);
74 | }
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/beans/DoublePropertyBridge.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.beans;
18 |
19 | import static java.util.Objects.nonNull;
20 |
21 | import javafx.beans.property.DoublePropertyBase;
22 |
23 | import org.lecturestudio.stylus.demo.beans.ChangeListener;
24 | import org.lecturestudio.stylus.demo.beans.DoubleProperty;
25 |
26 | public class DoublePropertyBridge extends DoublePropertyBase {
27 |
28 | private final DoubleProperty wrappedProperty;
29 |
30 | private final ChangeListener changeListener;
31 |
32 |
33 | public DoublePropertyBridge(DoubleProperty property) {
34 | this.wrappedProperty = property;
35 |
36 | changeListener = (observable, oldValue, newValue) -> {
37 | invalidated();
38 | fireValueChangedEvent();
39 | };
40 |
41 | wrappedProperty.addListener(changeListener);
42 | }
43 |
44 | @Override
45 | public Object getBean() {
46 | return null;
47 | }
48 |
49 | @Override
50 | public String getName() {
51 | return null;
52 | }
53 |
54 | @Override
55 | public double get() {
56 | return wrappedProperty.get();
57 | }
58 |
59 | @Override
60 | public void set(double value) {
61 | wrappedProperty.set(value);
62 | }
63 |
64 | @Override
65 | public void unbind() {
66 | super.unbind();
67 |
68 | if (nonNull(wrappedProperty)) {
69 | wrappedProperty.removeListener(changeListener);
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/beans/IntegerPropertyBridge.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.beans;
18 |
19 | import static java.util.Objects.nonNull;
20 |
21 | import javafx.beans.property.IntegerPropertyBase;
22 |
23 | import org.lecturestudio.stylus.demo.beans.ChangeListener;
24 | import org.lecturestudio.stylus.demo.beans.IntegerProperty;
25 |
26 | public class IntegerPropertyBridge extends IntegerPropertyBase {
27 |
28 | private final IntegerProperty wrappedProperty;
29 |
30 | private final ChangeListener changeListener;
31 |
32 |
33 | public IntegerPropertyBridge(IntegerProperty property) {
34 | this.wrappedProperty = property;
35 |
36 | changeListener = (observable, oldValue, newValue) -> {
37 | invalidated();
38 | fireValueChangedEvent();
39 | };
40 |
41 | wrappedProperty.addListener(changeListener);
42 | }
43 |
44 | @Override
45 | public Object getBean() {
46 | return null;
47 | }
48 |
49 | @Override
50 | public String getName() {
51 | return null;
52 | }
53 |
54 | @Override
55 | public int get() {
56 | return wrappedProperty.get();
57 | }
58 |
59 | @Override
60 | public void set(int value) {
61 | wrappedProperty.set(value);
62 | }
63 |
64 | @Override
65 | public void unbind() {
66 | super.unbind();
67 |
68 | if (nonNull(wrappedProperty)) {
69 | wrappedProperty.removeListener(changeListener);
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/beans/StringPropertyBridge.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.beans;
18 |
19 | import static java.util.Objects.nonNull;
20 |
21 | import javafx.beans.property.StringPropertyBase;
22 |
23 | import org.lecturestudio.stylus.demo.beans.ChangeListener;
24 | import org.lecturestudio.stylus.demo.beans.StringProperty;
25 |
26 | public class StringPropertyBridge extends StringPropertyBase {
27 |
28 | private final StringProperty wrappedProperty;
29 |
30 | private final ChangeListener changeListener;
31 |
32 |
33 | public StringPropertyBridge(StringProperty property) {
34 | this.wrappedProperty = property;
35 |
36 | changeListener = (observable, oldValue, newValue) -> {
37 | invalidated();
38 | fireValueChangedEvent();
39 | };
40 |
41 | wrappedProperty.addListener(changeListener);
42 | }
43 |
44 | @Override
45 | public Object getBean() {
46 | return null;
47 | }
48 |
49 | @Override
50 | public String getName() {
51 | return null;
52 | }
53 |
54 | @Override
55 | public String get() {
56 | return wrappedProperty.get();
57 | }
58 |
59 | @Override
60 | public void set(String value) {
61 | wrappedProperty.set(value);
62 | }
63 |
64 | @Override
65 | public void unbind() {
66 | super.unbind();
67 |
68 | if (nonNull(wrappedProperty)) {
69 | wrappedProperty.removeListener(changeListener);
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/beans/converter/ColorConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.beans.converter;
18 |
19 | import javafx.scene.paint.Color;
20 |
21 | import org.lecturestudio.stylus.demo.beans.converter.Converter;
22 |
23 | public class ColorConverter implements Converter {
24 |
25 | public static final ColorConverter INSTANCE = new ColorConverter();
26 |
27 |
28 | @Override
29 | public Color to(org.lecturestudio.stylus.demo.paint.Color color) {
30 | return Color.rgb(color.getRed(), color.getGreen(), color.getBlue(), color.getOpacity() / 255.0);
31 | }
32 |
33 | @Override
34 | public org.lecturestudio.stylus.demo.paint.Color from(Color color) {
35 | int r = (int) Math.round(color.getRed() * 255);
36 | int g = (int) Math.round(color.getGreen() * 255);
37 | int b = (int) Math.round(color.getBlue() * 255);
38 | int a = (int) Math.round(color.getOpacity() * 255);
39 |
40 | return new org.lecturestudio.stylus.demo.paint.Color(r, g, b, a);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/control/ButtonGroup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.control;
18 |
19 | import javafx.collections.FXCollections;
20 | import javafx.collections.ObservableList;
21 | import javafx.scene.control.ButtonBase;
22 | import javafx.scene.control.Control;
23 | import javafx.scene.control.Skin;
24 |
25 | public class ButtonGroup extends Control {
26 |
27 | private static final String DEFAULT_STYLE_CLASS = "button-group";
28 |
29 | /** The list of buttons that this ButtonGroup will bound together into one 'grouped button'. */
30 | private final ObservableList buttons;
31 |
32 |
33 | public ButtonGroup() {
34 | buttons = FXCollections.observableArrayList();
35 |
36 | initialize();
37 | }
38 |
39 | /**
40 | * Returns the list of buttons that this ButtonGroup will bound together into one
41 | * 'grouped button'.
42 | *
43 | * @return The buttons of this ButtonGroup.
44 | */
45 | public final ObservableList getButtons() {
46 | return buttons;
47 | }
48 |
49 | @Override
50 | protected Skin> createDefaultSkin() {
51 | return new ButtonGroupSkin(this);
52 | }
53 |
54 | private void initialize() {
55 | getStyleClass().setAll(DEFAULT_STYLE_CLASS);
56 |
57 | setFocusTraversable(false);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/inject/FxViewModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.inject;
18 |
19 | import com.google.inject.AbstractModule;
20 |
21 | import org.lecturestudio.stylus.demo.javafx.view.FxCanvasView;
22 | import org.lecturestudio.stylus.demo.javafx.view.FxInfoView;
23 | import org.lecturestudio.stylus.demo.javafx.view.FxMainView;
24 | import org.lecturestudio.stylus.demo.javafx.view.FxToolbarView;
25 | import org.lecturestudio.stylus.demo.view.CanvasView;
26 | import org.lecturestudio.stylus.demo.view.InfoView;
27 | import org.lecturestudio.stylus.demo.view.MainView;
28 | import org.lecturestudio.stylus.demo.view.ToolbarView;
29 |
30 | public class FxViewModule extends AbstractModule {
31 |
32 | @Override
33 | protected void configure() {
34 | bind(CanvasView.class).to(FxCanvasView.class);
35 | bind(InfoView.class).to(FxInfoView.class);
36 | bind(MainView.class).to(FxMainView.class);
37 | bind(ToolbarView.class).to(FxToolbarView.class);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/java/org/lecturestudio/stylus/demo/javafx/view/FxMainView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.demo.javafx.view;
18 |
19 | import javafx.scene.Node;
20 | import javafx.scene.layout.BorderPane;
21 | import javafx.stage.Window;
22 | import javafx.stage.WindowEvent;
23 |
24 | import org.lecturestudio.stylus.demo.javafx.util.FxUtils;
25 | import org.lecturestudio.stylus.demo.view.CanvasView;
26 | import org.lecturestudio.stylus.demo.view.InfoView;
27 | import org.lecturestudio.stylus.demo.view.MainView;
28 | import org.lecturestudio.stylus.demo.view.ToolbarView;
29 |
30 | public class FxMainView extends BorderPane implements MainView {
31 |
32 | @Override
33 | public void close() {
34 | // Fire close request in order to shutdown appropriately.
35 | Window window = getScene().getWindow();
36 | window.fireEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSE_REQUEST));
37 | window.hide();
38 | }
39 |
40 | @Override
41 | public void setToolbar(ToolbarView view) {
42 | FxUtils.checkNodeView(view);
43 |
44 | setTop((Node) view);
45 | }
46 |
47 | @Override
48 | public void setCanvas(CanvasView view) {
49 | FxUtils.checkNodeView(view);
50 |
51 | setCenter((Node) view);
52 | }
53 |
54 | @Override
55 | public void setInfo(InfoView view) {
56 | FxUtils.checkNodeView(view);
57 |
58 | setLeft((Node) view);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/stylus-demo/stylus-demo-javafx/src/main/resources/cursor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lectureStudio/stylus/d93bf907b89bef96a625093699b7b14bfedcccdc/stylus-demo/stylus-demo-javafx/src/main/resources/cursor.png
--------------------------------------------------------------------------------
/stylus-javafx/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.lecturestudio.stylus
7 | stylus-parent
8 | 0.4.0-SNAPSHOT
9 |
10 |
11 | stylus-javafx
12 |
13 |
14 | 15
15 |
16 |
17 |
18 |
19 | org.lecturestudio.stylus
20 | stylus
21 | ${project.parent.version}
22 |
23 |
24 | org.openjfx
25 | javafx-controls
26 | ${javafx.version}
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/stylus-javafx/src/main/java/org/lecturestudio/stylus/javafx/JavaFxComponentState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.lecturestudio.stylus.javafx;
18 |
19 | import javafx.beans.value.ChangeListener;
20 | import javafx.event.EventHandler;
21 | import javafx.geometry.Bounds;
22 | import javafx.geometry.Point2D;
23 | import javafx.scene.input.MouseEvent;
24 |
25 | import org.lecturestudio.stylus.StylusListener;
26 |
27 | class JavaFxComponentState {
28 |
29 | EventHandler mouseEnteredHandler;
30 |
31 | EventHandler mouseExitedHandler;
32 |
33 | ChangeListener nodeLocationListener;
34 |
35 | ChangeListener windowLocationListener;
36 |
37 | StylusListener stylusListener;
38 |
39 | Point2D location;
40 |
41 | Point2D screenScale;
42 |
43 | boolean nodeClicked;
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.13)
2 | project(stylus-core)
3 |
4 | add_library(${PROJECT_NAME} STATIC)
5 |
6 | target_sources(${PROJECT_NAME}
7 | INTERFACE
8 | include/Convert.h
9 | include/DeviceList.h
10 | include/Event.h
11 | include/EventDispatcher.h
12 | include/Queue.h
13 | include/Stylus.h
14 | include/StylusAxesData.h
15 | include/StylusAxisContext.h
16 | include/StylusDevice.h
17 | include/StylusDeviceListener.h
18 | include/StylusEvent.h
19 | include/StylusException.h
20 | include/StylusListener.h
21 | include/StylusManager.h
22 | include/StylusUtils.h
23 | PRIVATE
24 | src/StylusAxesData.cpp
25 | src/StylusAxisContext.cpp
26 | src/StylusDevice.cpp
27 | src/StylusEvent.cpp
28 | src/StylusException.cpp
29 | src/StylusManager.cpp
30 | src/StylusUtils.cpp
31 | )
32 |
33 | target_include_directories(${PROJECT_NAME} PUBLIC
34 | include
35 | )
36 |
37 | if(APPLE)
38 | target_compile_options(${PROJECT_NAME} PRIVATE -x objective-c++)
39 | endif()
40 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/Convert.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_CONVERT_H_
18 | #define STYLUS_CONVERT_H_
19 |
20 | #include
21 | #include
22 |
23 | namespace stylus
24 | {
25 | template
26 | std::string toString(const T & value)
27 | {
28 | std::stringstream output;
29 | output << value;
30 | return output.str();
31 | }
32 |
33 | template
34 | auto toInteger(Enumeration const value) -> typename std::underlying_type::type
35 | {
36 | return static_cast::type>(value);
37 | }
38 | }
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/Event.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_EVENT_BASE_H_
18 | #define STYLUS_EVENT_BASE_H_
19 |
20 | #include
21 |
22 | namespace stylus
23 | {
24 | class Event
25 | {
26 | public:
27 | virtual ~Event() {};
28 | };
29 |
30 | using PEvent = std::shared_ptr;
31 | }
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/EventDispatcher.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_EVENT_DISPATCHER_H_
18 | #define STYLUS_EVENT_DISPATCHER_H_
19 |
20 | #include "Event.h"
21 |
22 | #include
23 | #include
24 |
25 | namespace stylus
26 | {
27 | template
28 | class EventDispatcher
29 | {
30 | static_assert(std::is_base_of::value, "T must derive from Event");
31 |
32 | public:
33 | virtual ~EventDispatcher() {};
34 |
35 | virtual void dispatchEvent(std::shared_ptr event) = 0;
36 | };
37 |
38 | template
39 | using PEventDispatcher = std::shared_ptr>;
40 | }
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/Queue.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_QUEUE_H_
18 | #define STYLUS_QUEUE_H_
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | template
26 | class Queue
27 | {
28 | public:
29 | Queue() {}
30 |
31 | T pop()
32 | {
33 | std::unique_lock mlock(mutex);
34 |
35 | while (queue.empty()) {
36 | cond.wait(mlock);
37 | }
38 |
39 | auto val = queue.front();
40 | queue.pop();
41 | return val;
42 | }
43 |
44 | void pop(T & item)
45 | {
46 | std::unique_lock mlock(mutex);
47 |
48 | while (queue.empty()) {
49 | cond.wait(mlock);
50 | }
51 |
52 | item = queue.front();
53 | queue.pop();
54 | }
55 |
56 | void push(const T& item)
57 | {
58 | std::unique_lock mlock(mutex);
59 | queue.push(item);
60 | mlock.unlock();
61 | cond.notify_one();
62 | }
63 |
64 | void clear()
65 | {
66 | std::unique_lock mlock(mutex);
67 |
68 | while (!queue.empty()) {
69 | queue.pop();
70 | }
71 | }
72 |
73 | private:
74 | Queue(const Queue &); // disable copying
75 | Queue& operator=(const Queue &); // disable assignment
76 |
77 | std::queue queue;
78 | std::mutex mutex;
79 | std::condition_variable cond;
80 | };
81 |
82 | #endif
83 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/Stylus.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_H_
18 | #define STYLUS_H_
19 |
20 | namespace stylus
21 | {
22 | enum class Axis : unsigned
23 | {
24 | X,
25 | Y,
26 | PRESSURE,
27 | TANGENT_PRESSURE,
28 | TILT_X,
29 | TILT_Y,
30 | ROTATION,
31 | COUNT
32 | };
33 |
34 | enum class Button : unsigned
35 | {
36 | NONE,
37 | LEFT,
38 | MIDDLE,
39 | RIGHT
40 | };
41 |
42 | enum class Cursor : unsigned
43 | {
44 | NONE,
45 | MOUSE,
46 | ERASER,
47 | PEN
48 | };
49 |
50 | enum class EventType : unsigned
51 | {
52 | NONE,
53 | MOVE,
54 | BUTTON_DOWN,
55 | BUTTON_UP,
56 | CURSOR
57 | };
58 |
59 |
60 | inline unsigned axisId(const Axis & axis)
61 | {
62 | return static_cast(axis);
63 | }
64 |
65 | inline Axis & operator++(Axis & axis, int)
66 | {
67 | return axis = (axis == Axis::COUNT) ? Axis::X : static_cast(axisId(axis) + 1);
68 | }
69 | }
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/StylusAxesData.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_AXES_DATA_H_
18 | #define STYLUS_AXES_DATA_H_
19 |
20 | #include "Stylus.h"
21 |
22 | #include
23 | #include
24 |
25 | namespace stylus
26 | {
27 | class StylusAxesData
28 | {
29 | public:
30 | StylusAxesData();
31 | StylusAxesData(StylusAxesData && other);
32 | virtual ~StylusAxesData() {};
33 |
34 | double & operator[](Axis axis);
35 | const double & operator[](Axis axis) const;
36 |
37 | StylusAxesData & operator=(StylusAxesData && other);
38 |
39 | size_t size();
40 | size_t size() const;
41 |
42 | const double * getData();
43 | const double * getData() const;
44 |
45 | private:
46 | std::array(Axis::COUNT)> data;
47 | };
48 | }
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/StylusAxisContext.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_AXIS_CONTEXT_H_
18 | #define STYLUS_AXIS_CONTEXT_H_
19 |
20 | namespace stylus
21 | {
22 | class StylusAxisContext
23 | {
24 | public:
25 | StylusAxisContext();
26 | StylusAxisContext(unsigned axisId, double min, double max);
27 |
28 | StylusAxisContext & operator=(const StylusAxisContext &);
29 |
30 | public:
31 | /** Unique axis identifier. */
32 | unsigned axisId;
33 |
34 | /** The minimum value of the axis. */
35 | double minValue;
36 |
37 | /** The maximum value of the axis. */
38 | double maxValue;
39 |
40 | /** The range between the min and max value. */
41 | double rangeValue;
42 | };
43 | }
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/StylusDevice.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_DEVICE_H_
18 | #define STYLUS_DEVICE_H_
19 |
20 | #include
21 | #include
22 |
23 | namespace stylus
24 | {
25 | class StylusDevice
26 | {
27 | public:
28 | virtual ~StylusDevice() {};
29 |
30 | virtual bool operator==(const StylusDevice & other);
31 | virtual bool operator!=(const StylusDevice & other);
32 | virtual bool operator<(const StylusDevice & other);
33 |
34 | std::string getName() const;
35 |
36 | protected:
37 | StylusDevice();
38 |
39 | protected:
40 | std::string name;
41 | };
42 |
43 |
44 | using PStylusDevice = std::shared_ptr;
45 | }
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/StylusDeviceListener.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_DEVICE_LISTENER_H_
18 | #define STYLUS_DEVICE_LISTENER_H_
19 |
20 | #include "StylusDevice.h"
21 |
22 | #include
23 |
24 | namespace stylus
25 | {
26 | class StylusDeviceListener
27 | {
28 | public:
29 | virtual ~StylusDeviceListener() {};
30 |
31 | virtual void deviceConnected(PStylusDevice device) = 0;
32 | virtual void deviceDisconnected(PStylusDevice device) = 0;
33 | };
34 |
35 |
36 | using PStylusDeviceListener = std::shared_ptr;
37 | }
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/StylusException.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_EXCEPTION_H_
18 | #define STYLUS_EXCEPTION_H_
19 |
20 | #include
21 | #include
22 |
23 | #ifndef _MSC_VER
24 | #define NOEXCEPT noexcept
25 | #else
26 | #define NOEXCEPT
27 | #endif
28 |
29 | namespace stylus
30 | {
31 | class StylusException : public std::exception
32 | {
33 | public:
34 | StylusException();
35 | StylusException(const char * msg, ...);
36 |
37 | virtual ~StylusException() throw() {}
38 |
39 | virtual const char * what() const NOEXCEPT;
40 |
41 | protected:
42 | std::string message;
43 | };
44 | }
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/StylusListener.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_LISTENER_H_
18 | #define STYLUS_LISTENER_H_
19 |
20 | #include "Stylus.h"
21 | #include "StylusEvent.h"
22 |
23 | #include
24 |
25 | namespace stylus
26 | {
27 | class StylusListener
28 | {
29 | public:
30 | virtual ~StylusListener() {};
31 |
32 | virtual void onCursorChange(PStylusEvent event) = 0;
33 | virtual void onCursorMove(PStylusEvent event) = 0;
34 | virtual void onButtonDown(PStylusEvent event) = 0;
35 | virtual void onButtonUp(PStylusEvent event) = 0;
36 | };
37 |
38 | using PStylusListener = std::shared_ptr;
39 | }
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/include/StylusUtils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef STYLUS_UTILS_H_
18 | #define STYLUS_UTILS_H_
19 |
20 | #include "JavaRef.h"
21 |
22 | #include
23 |
24 | long GetJavaWindowId(JNIEnv * env, const jni::JavaLocalRef & window);
25 | long GetJavaAwtWindowId(JNIEnv * env, const jni::JavaLocalRef & window);
26 | long GetJavaFx9WindowId(JNIEnv * env, const jni::JavaLocalRef & window);
27 | long GetComposeWindowId(JNIEnv * env, const jni::JavaLocalRef & window);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/src/StylusAxesData.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "StylusAxesData.h"
18 |
19 | namespace stylus
20 | {
21 | StylusAxesData::StylusAxesData() :
22 | data{ 0, 0, 0, 0, 0, 0 }
23 | {
24 | }
25 |
26 | StylusAxesData::StylusAxesData(StylusAxesData && other)
27 | {
28 | data = std::move(other.data);
29 | }
30 |
31 | double & StylusAxesData::operator[](Axis axis)
32 | {
33 | return data[axisId(axis)];
34 | }
35 |
36 | const double & StylusAxesData::operator[](Axis axis) const
37 | {
38 | return data[axisId(axis)];
39 | }
40 |
41 | StylusAxesData & StylusAxesData::operator=(StylusAxesData && other)
42 | {
43 | if (this != &other) {
44 | data = std::move(other.data);
45 | }
46 |
47 | return *this;
48 | }
49 |
50 | size_t StylusAxesData::size()
51 | {
52 | return data.size();
53 | }
54 |
55 | size_t StylusAxesData::size() const
56 | {
57 | return data.size();
58 | }
59 |
60 | const double * StylusAxesData::getData()
61 | {
62 | return data.data();
63 | }
64 |
65 | const double * StylusAxesData::getData() const
66 | {
67 | return data.data();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/src/StylusAxisContext.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "StylusAxisContext.h"
18 |
19 | namespace stylus
20 | {
21 | StylusAxisContext::StylusAxisContext() :
22 | axisId(0),
23 | minValue(0),
24 | maxValue(0),
25 | rangeValue(0)
26 | {
27 | }
28 |
29 | StylusAxisContext::StylusAxisContext(unsigned axisId, double min, double max) :
30 | axisId(axisId),
31 | minValue(min),
32 | maxValue(max),
33 | rangeValue(max - min)
34 | {
35 | }
36 |
37 | StylusAxisContext & StylusAxisContext::operator=(const StylusAxisContext & other)
38 | {
39 | if (this != &other) {
40 | axisId = other.axisId;
41 | minValue = other.minValue;
42 | maxValue = other.maxValue;
43 | rangeValue = other.rangeValue;
44 |
45 | }
46 |
47 | return *this;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/src/StylusDevice.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "StylusDevice.h"
18 |
19 | namespace stylus
20 | {
21 | StylusDevice::StylusDevice()
22 | {
23 | }
24 |
25 | bool StylusDevice::operator==(const StylusDevice & other)
26 | {
27 | return name == other.name;
28 | }
29 |
30 | bool StylusDevice::operator!=(const StylusDevice & other)
31 | {
32 | return !(*this == other);
33 | }
34 |
35 | bool StylusDevice::operator<(const StylusDevice & other)
36 | {
37 | return name < other.name;
38 | }
39 |
40 | std::string StylusDevice::getName() const
41 | {
42 | return name;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/core/src/StylusException.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Alex Andres
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "StylusException.h"
18 |
19 | namespace stylus
20 | {
21 | const unsigned int MAX_MESSAGE_LEN = 1024;
22 |
23 | StylusException::StylusException() : std::exception()
24 | {
25 | }
26 |
27 | StylusException::StylusException(const char * msg, ...) : std::exception()
28 | {
29 | char buffer[MAX_MESSAGE_LEN];
30 |
31 | va_list args;
32 | va_start(args, msg);
33 | vsnprintf(buffer, MAX_MESSAGE_LEN, msg, args);
34 | va_end(args);
35 |
36 | message = buffer;
37 | }
38 |
39 | const char * StylusException::what() const NOEXCEPT
40 | {
41 | return message.c_str();
42 | }
43 | }
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2019, Alex Andres. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without modification,
4 | are permitted provided that the following conditions are met:
5 |
6 | 1. Redistributions of source code must retain the above copyright notice, this
7 | list of conditions and the following disclaimer.
8 |
9 | 2. Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation and/or
11 | other materials provided with the distribution.
12 |
13 | 3. Neither the name of the copyright holder nor the names of its contributors
14 | may be used to endorse or promote products derived from this software without
15 | specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/Exception.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_EXCEPTION_H_
9 | #define JNI_EXCEPTION_H_
10 |
11 | #include
12 | #include
13 |
14 | #ifndef _MSC_VER
15 | #define NOEXCEPT noexcept
16 | #else
17 | #define NOEXCEPT
18 | #endif
19 |
20 | namespace jni
21 | {
22 | class Exception : public std::exception
23 | {
24 | public:
25 | Exception();
26 | Exception(const char * msg, ...);
27 |
28 | virtual ~Exception() throw() {}
29 |
30 | virtual const char * what() const NOEXCEPT;
31 |
32 | protected:
33 | std::string message;
34 |
35 | static const uint16_t MAX_MESSAGE_LEN = 1024;
36 | };
37 | }
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaArray.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_ARRAY_H_
9 | #define JNI_JAVA_ARRAY_H_
10 |
11 | #include "Exception.h"
12 | #include "JavaClass.h"
13 | #include "JavaRef.h"
14 |
15 | #include
16 | #include
17 |
18 | namespace jni
19 | {
20 | namespace JavaArray
21 | {
22 | template
23 | JavaLocalRef createObjectArray(JNIEnv * env, const std::vector & vector, jclass cls, Convert convert)
24 | {
25 | jsize vectorSize = static_cast(vector.size());
26 |
27 | JavaLocalRef objectArray(env, env->NewObjectArray(vectorSize, cls, nullptr));
28 |
29 | if (objectArray.get() == nullptr) {
30 | throw Exception("Create object array of type [%s] failed", typeid(T).name());
31 | }
32 |
33 | for (jsize i = 0; i < vectorSize; i++) {
34 | const T & item = vector[i];
35 |
36 | JavaLocalRef obj = jni::static_java_ref_cast(env, convert(env, item));
37 |
38 | env->SetObjectArrayElement(objectArray.get(), i, obj.get());
39 | }
40 |
41 | return objectArray;
42 | }
43 | }
44 | }
45 |
46 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaArrayList.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_ARRAY_LIST_H_
9 | #define JNI_JAVA_ARRAY_LIST_H_
10 |
11 | #include "JavaClass.h"
12 | #include "JavaRef.h"
13 |
14 | #include
15 |
16 | namespace jni
17 | {
18 | class JavaArrayList
19 | {
20 | public:
21 | explicit JavaArrayList(JNIEnv * env, size_t initialCapacity = 10);
22 | virtual ~JavaArrayList() = default;
23 |
24 | JavaArrayList(const JavaArrayList &) = delete;
25 | JavaArrayList(JavaArrayList && other) = delete;
26 |
27 | void operator=(const JavaArrayList &) = delete;
28 | JavaArrayList & operator=(JavaArrayList &&) = delete;
29 |
30 | bool add(const JavaRef & obj);
31 |
32 | JavaLocalRef get(int index);
33 |
34 | int size();
35 |
36 | JavaLocalRef listObject();
37 |
38 | private:
39 | class JavaArrayListClass : public JavaClass
40 | {
41 | public:
42 | explicit JavaArrayListClass(JNIEnv * env);
43 |
44 | jclass cls;
45 | jmethodID ctor;
46 | jmethodID size;
47 | jmethodID get;
48 | jmethodID add;
49 | };
50 |
51 | private:
52 | JNIEnv * env;
53 | JavaLocalRef list;
54 |
55 | const std::shared_ptr classDef;
56 | };
57 | }
58 |
59 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaBigInteger.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_BIG_INTEGER_H_
9 | #define JNI_JAVA_BIG_INTEGER_H_
10 |
11 | #include "JavaClass.h"
12 | #include "JavaRef.h"
13 |
14 | #include
15 | #include
16 |
17 | namespace jni
18 | {
19 | namespace JavaBigInteger
20 | {
21 | class JavaBigIntegerClass : public JavaClass
22 | {
23 | public:
24 | explicit JavaBigIntegerClass(JNIEnv * env);
25 |
26 | jclass cls;
27 | jmethodID ctor;
28 | };
29 |
30 | JavaLocalRef toJava(JNIEnv * env, const std::string & val);
31 | JavaLocalRef createArray(JNIEnv * env, const std::vector & vector);
32 | }
33 | }
34 |
35 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaClass.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_CLASS_H_
9 | #define JNI_JAVA_CLASS_H_
10 |
11 | #include
12 |
13 | namespace jni
14 | {
15 | class JavaClass
16 | {
17 | public:
18 | virtual ~JavaClass() = default;
19 |
20 | protected:
21 | constexpr JavaClass() {};
22 | };
23 | }
24 |
25 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaClasses.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_CLASSES_H_
9 | #define JNI_JAVA_CLASSES_H_
10 |
11 | #include "JavaClass.h"
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | namespace jni
20 | {
21 | class JavaClasses
22 | {
23 | public:
24 | template ::value>>
25 | static const std::shared_ptr get(JNIEnv * env)
26 | {
27 | std::lock_guard l(getMutex());
28 |
29 | const std::type_index index = std::type_index(typeid(T));
30 |
31 | auto found = map.find(index);
32 | if (found == map.end()) {
33 | auto cls = std::make_shared(env);
34 |
35 | map.emplace(index, cls);
36 |
37 | return cls;
38 | }
39 |
40 | return std::static_pointer_cast(found->second);
41 | }
42 |
43 | private:
44 | static std::mutex & getMutex()
45 | {
46 | static std::mutex mutex;
47 | return mutex;
48 | }
49 |
50 | private:
51 | JavaClasses() = default;
52 | ~JavaClasses() = default;
53 |
54 | static inline std::unordered_map> map;
55 | };
56 | }
57 |
58 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaContext.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_CONTEXT_H_
9 | #define JNI_JAVA_CONTEXT_H_
10 |
11 | #include
12 |
13 | namespace jni
14 | {
15 | class JavaContext
16 | {
17 | public:
18 | JavaContext(JavaVM * vm);
19 | virtual ~JavaContext() = default;
20 |
21 | JavaContext(const JavaContext &) = delete;
22 | JavaContext(JavaContext && other) = delete;
23 |
24 | void operator=(const JavaContext &) = delete;
25 | JavaContext & operator=(JavaContext &&) = delete;
26 |
27 | virtual void initialize(JNIEnv * env);
28 | virtual void destroy(JNIEnv * env);
29 |
30 | JavaVM * getVM();
31 |
32 | private:
33 | JavaVM * vm;
34 | };
35 | }
36 |
37 | extern jni::JavaContext * javaContext;
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaDimension.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_DIMENSION_H_
9 | #define JNI_JAVA_DIMENSION_H_
10 |
11 | #include "JavaClass.h"
12 | #include "JavaRef.h"
13 |
14 | #include
15 |
16 | namespace jni
17 | {
18 | namespace JavaDimension
19 | {
20 | class JavaDimensionClass : public JavaClass
21 | {
22 | public:
23 | explicit JavaDimensionClass(JNIEnv * env);
24 |
25 | jclass cls;
26 | jmethodID ctor;
27 | jfieldID width;
28 | jfieldID height;
29 | };
30 |
31 | JavaLocalRef toJava(JNIEnv * env, const int & width, const int & height);
32 | }
33 | }
34 |
35 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaEnums.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_ENUMS_H_
9 | #define JNI_JAVA_ENUMS_H_
10 |
11 | #include "JavaEnum.h"
12 | #include "JavaRef.h"
13 | #include "JavaUtils.h"
14 | #include "Exception.h"
15 |
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | namespace jni
22 | {
23 | class JavaEnums
24 | {
25 | public:
26 | JavaEnums() = default;
27 | ~JavaEnums() = default;
28 |
29 | template
30 | static void add(JNIEnv * env, const char * className)
31 | {
32 | map.emplace(std::type_index(typeid(T)), std::make_any>(JavaEnum(env, className)));
33 | }
34 |
35 | template
36 | static JavaLocalRef toJava(JNIEnv * env, const T & nativeType)
37 | {
38 | std::type_index index = std::type_index(typeid(T));
39 |
40 | auto found = map.find(index);
41 | if (found == map.end()) {
42 | throw Exception("JavaEnum for [%s] was not registered", typeid(T).name());
43 | }
44 |
45 | JavaEnum & e = std::any_cast &>(found->second);
46 |
47 | return JavaLocalRef(env, e.toJava(env, nativeType));
48 | }
49 |
50 | template
51 | static T toNative(JNIEnv * env, const jobject & javaType)
52 | {
53 | std::type_index index = std::type_index(typeid(T));
54 |
55 | auto found = map.find(index);
56 | if (found == map.end()) {
57 | throw Exception("JavaEnum for [%s] was not registered", typeid(T).name());
58 | }
59 |
60 | JavaEnum & e = std::any_cast &>(found->second);
61 |
62 | return JavaLocalRef(env, e.toNative(env, javaType));
63 | }
64 |
65 | private:
66 | static inline std::unordered_map map;
67 | };
68 | }
69 |
70 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaError.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_ERROR_H_
9 | #define JNI_JAVA_ERROR_H_
10 |
11 | #include "JavaThrowable.h"
12 |
13 | #include
14 |
15 | namespace jni
16 | {
17 | class JavaError : public JavaThrowable
18 | {
19 | private:
20 | class JavaErrorClass : public JavaThrowableClass
21 | {
22 | public:
23 | explicit JavaErrorClass(JNIEnv * env) :
24 | JavaThrowableClass(env, "java/lang/Error")
25 | {
26 | }
27 | };
28 |
29 | public:
30 | template
31 | JavaError(JNIEnv * env, const char * message, Args &&... args) :
32 | JavaThrowable(env, message, std::forward(args)...)
33 | {
34 | }
35 |
36 | operator jthrowable() const override
37 | {
38 | return createThrowable();
39 | }
40 | };
41 | }
42 |
43 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaFactory.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_FACTORY_H_
9 | #define JNI_JAVA_FACTORY_H_
10 |
11 | #include "JavaRef.h"
12 | #include "JavaUtils.h"
13 |
14 | #include
15 |
16 | namespace jni
17 | {
18 | template
19 | class JavaFactory
20 | {
21 | public:
22 | JavaFactory(JNIEnv * env, const char * className) :
23 | JavaFactory(env, className, "()V")
24 | {
25 | }
26 |
27 | virtual ~JavaFactory()
28 | {
29 | }
30 |
31 | virtual JavaLocalRef create(JNIEnv * env, const T * nativeObject)
32 | {
33 | jobject object = env->NewObject(javaClass, javaCtor);
34 | ExceptionCheck(env);
35 |
36 | SetHandle(env, object, nativeObject);
37 |
38 | return JavaLocalRef(env, object);
39 | }
40 |
41 | virtual JavaLocalRef createArray(JNIEnv * env, const jsize & length)
42 | {
43 | return JavaLocalRef(env, env->NewObjectArray(length, javaClass, nullptr));
44 | }
45 |
46 | protected:
47 | JavaFactory(JNIEnv * env, const char * className, const char * ctorSignature) :
48 | javaClass(nullptr),
49 | javaCtor(nullptr)
50 | {
51 | loadClass(env, className, ctorSignature);
52 | }
53 |
54 | private:
55 | void loadClass(JNIEnv * env, const char * className, const char * ctorSignature)
56 | {
57 | javaClass = JavaGlobalRef(env, FindClass(env, className));
58 |
59 | javaCtor = GetMethod(env, javaClass, "", ctorSignature);
60 | }
61 |
62 | protected:
63 | JavaGlobalRef javaClass;
64 | jmethodID javaCtor;
65 | };
66 | }
67 |
68 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaHashMap.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_HASH_MAP_H_
9 | #define JNI_JAVA_HASH_MAP_H_
10 |
11 | #include "JavaClass.h"
12 | #include "JavaRef.h"
13 | #include "JavaMapIterator.h"
14 |
15 | #include
16 |
17 | namespace jni
18 | {
19 | class JavaHashMap
20 | {
21 | public:
22 | explicit JavaHashMap(JNIEnv * env);
23 | JavaHashMap(JNIEnv * env, const JavaRef & jMap);
24 | ~JavaHashMap() = default;
25 |
26 | void operator=(const JavaHashMap &) = delete;
27 |
28 | operator JavaLocalRef() const;
29 |
30 | void put(const JavaRef & key, const JavaRef & value);
31 |
32 | /**
33 | Creates an iterator pointing to the beginning of the collection.
34 |
35 | @return An iterator pointing to the first element.
36 | */
37 | JavaMapIterator begin();
38 |
39 | /**
40 | Creates an iterator pointing to the end of the collection.
41 |
42 | @return An iterator pointing to the past-the-end element.
43 | */
44 | JavaMapIterator end();
45 |
46 | private:
47 | class JavaHashMapClass : public JavaClass
48 | {
49 | public:
50 | explicit JavaHashMapClass(JNIEnv * env);
51 |
52 | jclass cls;
53 | jmethodID defaultCtor;
54 | jmethodID put;
55 | jmethodID entrySet;
56 | };
57 |
58 | private:
59 | JNIEnv * env;
60 | JavaLocalRef jMap;
61 |
62 | const std::shared_ptr mapClass;
63 | };
64 |
65 | }
66 |
67 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaIOException.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_IO_EXCEPTION_H_
9 | #define JNI_JAVA_IO_EXCEPTION_H_
10 |
11 | #include "JavaThrowable.h"
12 |
13 | #include
14 |
15 | namespace jni
16 | {
17 | class JavaIOException : public JavaThrowable
18 | {
19 | private:
20 | class JavaIOExceptionClass : public JavaThrowableClass
21 | {
22 | public:
23 | explicit JavaIOExceptionClass(JNIEnv * env) :
24 | JavaThrowableClass(env, "java/io/IOException")
25 | {
26 | }
27 | };
28 |
29 | public:
30 | template
31 | JavaIOException(JNIEnv * env, const char * message, Args &&... args) :
32 | JavaThrowable(env, message, std::forward(args)...)
33 | {
34 | }
35 |
36 | operator jthrowable() const override
37 | {
38 | return createThrowable();
39 | }
40 | };
41 | }
42 |
43 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaList.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_LIST_H_
9 | #define JNI_JAVA_LIST_H_
10 |
11 | #include "JavaArrayList.h"
12 | #include "JavaIterable.h"
13 | #include "JavaRef.h"
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | namespace jni
20 | {
21 | namespace JavaList
22 | {
23 | std::vector toStringVector(JNIEnv * env, const JavaRef & list);
24 |
25 | template
26 | std::vector toVector(JNIEnv * env, const JavaRef & list, T conv(JNIEnv *, const JavaRef &))
27 | {
28 | std::vector vec;
29 |
30 | for (const auto & value : JavaIterable(env, list)) {
31 | vec.push_back(conv(env, value));
32 | }
33 |
34 | return vec;
35 | }
36 |
37 | template
38 | JavaLocalRef toArrayList(JNIEnv * env, const std::vector & vec, JavaLocalRef conv (JNIEnv *, const T &))
39 | {
40 | JavaArrayList list(env, vec.size());
41 |
42 | for (const T & value : vec) {
43 | list.add(conv(env, value));
44 | }
45 |
46 | return list.listObject();
47 | }
48 | }
49 | }
50 |
51 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaNullPointerException.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_NULL_POINTER_EXCEPTION_H_
9 | #define JNI_JAVA_NULL_POINTER_EXCEPTION_H_
10 |
11 | #include "JavaThrowable.h"
12 |
13 | #include
14 |
15 | namespace jni
16 | {
17 | class JavaNullPointerException : public JavaThrowable
18 | {
19 | private:
20 | class JavaNullPointerExceptionClass : public JavaThrowableClass
21 | {
22 | public:
23 | JavaNullPointerExceptionClass(JNIEnv * env) :
24 | JavaThrowableClass(env, "java/lang/NullPointerException")
25 | {
26 | }
27 | };
28 |
29 | public:
30 | template
31 | JavaNullPointerException(JNIEnv * env, const char * message, Args &&... args) :
32 | JavaThrowable(env, message, std::forward(args)...)
33 | {
34 | }
35 |
36 | operator jthrowable() const override
37 | {
38 | return createThrowable();
39 | }
40 | };
41 | }
42 |
43 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaObject.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_OBJECT_H_
9 | #define JNI_JAVA_OBJECT_H_
10 |
11 | #include "JavaRef.h"
12 |
13 | #include
14 | #include
15 |
16 | namespace jni
17 | {
18 | class JavaObject
19 | {
20 | public:
21 | JavaObject(JNIEnv * env, const JavaRef & obj);
22 | ~JavaObject() = default;
23 |
24 | jboolean getBoolean(jfieldID field);
25 | jbyte getByte(jfieldID field);
26 | jchar getChar(jfieldID field);
27 | jshort getShort(jfieldID field);
28 | jint getInt(jfieldID field);
29 | jlong getLong(jfieldID field);
30 | jfloat getFloat(jfieldID field);
31 | jdouble getDouble(jfieldID field);
32 | JavaLocalRef getObject(jfieldID field);
33 | JavaLocalRef getObjectArray(jfieldID field);
34 | JavaLocalRef getString(jfieldID field);
35 |
36 | template ::value>>
37 | T getInt(jfieldID field)
38 | {
39 | return static_cast(env->GetIntField(obj, field));
40 | }
41 |
42 | protected:
43 | JNIEnv * env;
44 | JavaLocalRef obj;
45 | };
46 | }
47 |
48 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaRectangle.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_RECTANGLE_H_
9 | #define JNI_JAVA_RECTANGLE_H_
10 |
11 | #include "JavaClass.h"
12 | #include "JavaRef.h"
13 |
14 | #include
15 |
16 | namespace jni
17 | {
18 | namespace JavaRectangle
19 | {
20 | class JavaRectangleClass : public JavaClass
21 | {
22 | public:
23 | explicit JavaRectangleClass(JNIEnv * env);
24 |
25 | jclass cls;
26 | jmethodID ctor;
27 | jfieldID x;
28 | jfieldID y;
29 | jfieldID width;
30 | jfieldID height;
31 | };
32 |
33 | JavaLocalRef toJava(JNIEnv * env, const int & x, const int & y, const int & width, const int & height);
34 | }
35 | }
36 |
37 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaRuntimeException.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_RUNTIME_EXCEPTION_H_
9 | #define JNI_JAVA_RUNTIME_EXCEPTION_H_
10 |
11 | #include "JavaThrowable.h"
12 |
13 | #include
14 |
15 | namespace jni
16 | {
17 | class JavaRuntimeException : public JavaThrowable
18 | {
19 | private:
20 | class JavaRuntimeExceptionClass : public JavaThrowableClass
21 | {
22 | public:
23 | JavaRuntimeExceptionClass(JNIEnv * env) :
24 | JavaThrowableClass(env, "java/lang/RuntimeException")
25 | {
26 | }
27 | };
28 |
29 | public:
30 | template
31 | JavaRuntimeException(JNIEnv * env, const char * message, Args &&... args) :
32 | JavaThrowable(env, message, std::forward(args)...)
33 | {
34 | }
35 |
36 | operator jthrowable() const override
37 | {
38 | return createThrowable();
39 | }
40 | };
41 | }
42 |
43 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaString.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_STRING_H_
9 | #define JNI_JAVA_STRING_H_
10 |
11 | #include "JavaClass.h"
12 | #include "JavaRef.h"
13 |
14 | #include
15 | #include
16 |
17 | namespace jni
18 | {
19 | namespace JavaString
20 | {
21 | class JavaStringClass : public JavaClass
22 | {
23 | public:
24 | explicit JavaStringClass(JNIEnv * env);
25 |
26 | jclass cls;
27 | jmethodID getBytes;
28 | };
29 |
30 | std::string toNative(JNIEnv * env, const JavaRef & jstr);
31 | JavaLocalRef toJava(JNIEnv * env, const std::string & str);
32 | JavaLocalRef createArray(JNIEnv * env, const std::vector & vector);
33 | }
34 | }
35 |
36 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaThreadEnv.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_THREAD_ENV_H_
9 | #define JNI_JAVA_THREAD_ENV_H_
10 |
11 | #include
12 |
13 | namespace jni
14 | {
15 | class JavaThreadEnv
16 | {
17 | public:
18 | explicit JavaThreadEnv(JavaVM * vm);
19 | ~JavaThreadEnv();
20 |
21 | JNIEnv * getEnv() const;
22 |
23 | private:
24 | JavaVM * vm;
25 | JNIEnv * env;
26 | };
27 | }
28 |
29 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaThrowable.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_THROWABLE_H_
9 | #define JNI_JAVA_THROWABLE_H_
10 |
11 | #include "JavaClass.h"
12 | #include "JavaClasses.h"
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | namespace jni
20 | {
21 | class JavaThrowable
22 | {
23 | public:
24 | class JavaThrowableClass : public JavaClass
25 | {
26 | public:
27 | explicit JavaThrowableClass(JNIEnv * env);
28 | JavaThrowableClass(JNIEnv * env, const char * className);
29 |
30 | jclass cls;
31 | jmethodID ctor;
32 | };
33 |
34 | public:
35 | JavaThrowable(JNIEnv * env, const char * message, ...);
36 | virtual ~JavaThrowable() = default;
37 |
38 | virtual operator jthrowable() const;
39 |
40 | protected:
41 | template ::value>>
42 | jthrowable createThrowable() const
43 | {
44 | const auto classDef = JavaClasses::get(env);
45 |
46 | jobject throwable = env->NewObject(classDef->cls, classDef->ctor, env->NewStringUTF(message.c_str()));
47 |
48 | return static_cast(throwable);
49 | }
50 |
51 | private:
52 | JNIEnv * env;
53 | std::string message;
54 |
55 | static const uint16_t MAX_MESSAGE_LEN = 1024;
56 | };
57 | }
58 |
59 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/JavaWrappedException.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_JAVA_WRAPPED_EXCEPTION_H_
9 | #define JNI_JAVA_WRAPPED_EXCEPTION_H_
10 |
11 | #include "JavaRef.h"
12 |
13 | #ifndef _MSC_VER
14 | #define NOEXCEPT noexcept
15 | #else
16 | #define NOEXCEPT
17 | #endif
18 |
19 | namespace jni
20 | {
21 | class JavaWrappedException : public std::exception
22 | {
23 | public:
24 | explicit JavaWrappedException(const JavaLocalRef & throwable);
25 |
26 | ~JavaWrappedException() throw() {}
27 |
28 | const char * what() const NOEXCEPT;
29 |
30 | JavaLocalRef exception() const;
31 |
32 | private:
33 | JavaLocalRef throwable;
34 | };
35 | }
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/windows/ComInitializer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_WINDOWS_COM_INITIALIZER_H_
9 | #define JNI_WINDOWS_COM_INITIALIZER_H_
10 |
11 | #include
12 |
13 | namespace jni
14 | {
15 | class ComInitializer
16 | {
17 | public:
18 | ComInitializer();
19 | virtual ~ComInitializer();
20 |
21 | bool isInitialized();
22 |
23 | private:
24 | bool initialized;
25 | };
26 | }
27 |
28 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/include/windows/WinUtils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #ifndef JNI_WINDOWS_WIN_UTILS_H_
9 | #define JNI_WINDOWS_WIN_UTILS_H_
10 |
11 | #include "Exception.h"
12 |
13 | #include
14 | #include
15 | #include
16 |
17 |
18 | #define THROW_IF_FAILED(hr, msg, ...) ThrowIfFailed(hr, msg, __VA_ARGS__)
19 |
20 |
21 | inline std::string WideStrToStr(LPCWSTR wstr)
22 | {
23 | int wslen = static_cast(wcslen(wstr));
24 | int length = WideCharToMultiByte(CP_UTF8, 0, wstr, wslen, nullptr, 0, nullptr, nullptr);
25 | std::string str(length, 0);
26 | WideCharToMultiByte(CP_UTF8, 0, wstr, wslen, &str[0], length, nullptr, nullptr);
27 |
28 | return str;
29 | }
30 |
31 | inline std::string BSTRToStr(BSTR bstr)
32 | {
33 | const int wslen = SysStringLen(bstr);
34 | const wchar_t * pstr = reinterpret_cast(bstr);
35 |
36 | int len = WideCharToMultiByte(CP_ACP, 0, pstr, wslen, nullptr, 0, nullptr, nullptr);
37 |
38 | std::string str(len, '\0');
39 |
40 | WideCharToMultiByte(CP_ACP, 0, pstr, wslen, &str[0], len, nullptr, nullptr);
41 |
42 | return str;
43 | }
44 |
45 | inline void ThrowIfFailed(HRESULT hr, const char * msg, ...) {
46 | if (FAILED(hr)) {
47 | char message[256];
48 |
49 | va_list args;
50 | va_start(args, msg);
51 | vsnprintf(message, 256, msg, args);
52 | va_end(args);
53 |
54 | std::string comMessage = _com_error(hr).ErrorMessage();
55 |
56 | throw jni::Exception("%s %s", message, comMessage.c_str());
57 | }
58 | }
59 |
60 | struct GUIDHasher
61 | {
62 | std::size_t operator()(const GUID & guid) const
63 | {
64 | std::size_t hash = guid.Data1;
65 | hash ^= guid.Data2;
66 | hash ^= guid.Data3;
67 |
68 | for (unsigned i = 0; i < 8; i++) {
69 | hash ^= (guid.Data4[i] << i);
70 | }
71 |
72 | return hash;
73 | }
74 | };
75 |
76 | #endif
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/src/Exception.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #include "Exception.h"
9 |
10 | namespace jni
11 | {
12 | Exception::Exception() : std::exception()
13 | {
14 | }
15 |
16 | Exception::Exception(const char * msg, ...) : std::exception()
17 | {
18 | char buffer[MAX_MESSAGE_LEN];
19 |
20 | va_list args;
21 | va_start(args, msg);
22 | vsnprintf(buffer, MAX_MESSAGE_LEN, msg, args);
23 | va_end(args);
24 |
25 | message = buffer;
26 | }
27 |
28 | const char * Exception::what() const NOEXCEPT
29 | {
30 | return message.c_str();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/stylus-jni/src/main/cpp/dependencies/jni-voithos/src/JavaArrayList.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, Alex Andres. All rights reserved.
3 | *
4 | * Use of this source code is governed by the 3-Clause BSD license that can be
5 | * found in the LICENSE file in the root of the source tree.
6 | */
7 |
8 | #include "JavaArrayList.h"
9 | #include "JavaClasses.h"
10 | #include "JavaUtils.h"
11 |
12 | namespace jni
13 | {
14 | JavaArrayList::JavaArrayList(JNIEnv * env, size_t initialCapacity) :
15 | env(env),
16 | classDef(JavaClasses::get(env))
17 | {
18 | list = JavaLocalRef(env, env->NewObject(classDef->cls, classDef->ctor, initialCapacity));
19 | }
20 |
21 | bool JavaArrayList::add(const JavaRef & obj)
22 | {
23 | return env->CallBooleanMethod(list, classDef->add, obj.get());
24 | }
25 |
26 | JavaLocalRef JavaArrayList::get(int index)
27 | {
28 | return JavaLocalRef(env, env->CallObjectMethod(list, classDef->get, index));
29 | }
30 |
31 | int JavaArrayList::size()
32 | {
33 | return env->CallIntMethod(list, classDef->size);
34 | }
35 |
36 | JavaLocalRef