-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02c2992
commit a2a38d2
Showing
154 changed files
with
68,822 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Proto4j | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
A module for generating Java-Swing applications just from placing annotations on its components. Read the full JavaDoc-Documentation [here »](https://proto4j.github.io/proto4j-swing/javadoc/index.html) | ||
|
||
## First steps | ||
|
||
This small chapter tries to show the basic usage of this library with a small example covering some key components. Let's consider the following scenario: | ||
|
||
* the window should have the size 200*200 | ||
* the GUI should display a button with the text `click me!` | ||
* by clicking this button a simple dialog should pop up | ||
|
||
### 1. Class definition | ||
|
||
At first, the class where all components are stored has to be created. A GUI generated by `proto4j-swing` may contain components annotated with `Swing` or `SwingWindow`, as well as `Nested`. Only fields with these annotations are covered while processing. | ||
|
||
````java | ||
@GUI | ||
public class HelloWorldGUI { | ||
// element declarations would follow here | ||
} | ||
```` | ||
|
||
Next, the components have to be specified. Most likely these components are not final (but it is possible). The frame where the button will be added to could be defined as follows: | ||
|
||
````java | ||
// in class HelloWorldGUI | ||
@SwingWindow | ||
@Layout(BorderLayout.class) | ||
@Bounds(size = {200, 200}) | ||
private JFrame mainFrame; | ||
```` | ||
|
||
Although, it is not necessary to put a `SwingWindow` annotation on this field, there are more individual options provided by this annotation like `defaultCloseOperation` or `resizable`. With `Layout` the content-pane layout is set to the `Borderlayout` and the position specifies the size of this frame. | ||
|
||
Now, the button has to be specified: | ||
````java | ||
@Swing(2) // see TIP below | ||
@Option(text = "Click Me!", target = "mainFrame") | ||
@Position(constraints = BorderLayout.CENTER) | ||
private JButton button; | ||
```` | ||
Here, the text and component this button should be added to is specified with the `Option` annotation. With `constraints = BorderLayout.CENTER` the button will be placed in the middle of the frame. | ||
|
||
> TIP: The number given in the `Swing` annotation is *optional* and should be used if layout managers place their components in the order they were added to the parent component. | ||
Before the GUI can be created an `EntryPoint` should be specified as follows (optional): | ||
````java | ||
@EntryPoint | ||
public void showGui() { | ||
// You can use all fields as they will be initialized after | ||
// the generation process has finished. | ||
mainFrame.setVisible(true); | ||
} | ||
```` | ||
|
||
> TIP: This method is designed to have optional arguments, so if parameters are defined, the corresponding arguments have to be provided when calling the start()-method of an `Entry`. | ||
### 2. Listener creation | ||
|
||
For now, we created the GUI without any action listeners. The frame and button would be visible but nothing happens if the button gets pressed. The `ActionListener` interface is used by the `JButton` to indicate whether it was pressed. This listener can be created in two ways: | ||
|
||
1. Annotated class with implemented interface | ||
````java | ||
// the default listener type is ActionListener.class, so the type | ||
// doesn't have to be specified. | ||
@ActionHandler({"button"}) | ||
public class HelloWorldListener implements ActionListener { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
// JOptionPane.showMessageDialog(...) | ||
} | ||
} | ||
```` | ||
|
||
2. Annotated method in a class | ||
````java | ||
// the default listener type is ActionListener.class, so the type | ||
// doesn't have to be specified. | ||
@ActionHandler(value = {"button"}, type = ActionListener.class) | ||
public void myMethod(ActionEvent e) { | ||
// JOptionPane.showMessageDialog(...) | ||
} | ||
```` | ||
|
||
### 3. Starting the GUI | ||
|
||
At this point everything is ready to use: | ||
|
||
````java | ||
public static void main(String[]args){ | ||
// create a basic entry | ||
Entry<HelloWorldGUI> entry = Entry.of(HelloWorldGUI.class); | ||
// add the action listener by adding it with the ActionHandler annotation | ||
entry.linkAction(new HelloWorldListener()); | ||
// or add it directly | ||
entry.linkAction("button", ActionListener.class, new HelloWorldListener()); | ||
entry.start(); | ||
} | ||
```` |
Oops, something went wrong.