From cea932cfc4328a822b47b286934b4d0ea05949b2 Mon Sep 17 00:00:00 2001 From: lukflug Date: Wed, 11 Nov 2020 10:51:39 +0100 Subject: [PATCH] Fixed documentation, changing focus request system --- README.md | 2 +- .../java/com/lukflug/panelstudio/Context.java | 39 +++++++++++-------- .../com/lukflug/panelstudio/FocusManager.java | 13 ------- .../com/lukflug/panelstudio/Focusable.java | 9 ----- .../com/lukflug/panelstudio/Interface.java | 4 ++ 5 files changed, 27 insertions(+), 40 deletions(-) delete mode 100644 src/main/java/com/lukflug/panelstudio/FocusManager.java delete mode 100644 src/main/java/com/lukflug/panelstudio/Focusable.java diff --git a/README.md b/README.md index 830c3e8..c782530 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # PanelStudio -A simple yet flexible library to create ClickGUIs designed for use in Minecraft utility mods. It was originally designed for a private client, but made open source, so that it could be used for [GameSense](https://github.com/IUDevman/gamesense-client). Here are some screenshots of what is possible with this client: +A simple yet flexible library to create ClickGUIs designed for use in Minecraft utility mods. It was originally designed for a private client, but made open source, so that it could be used for [GameSense](https://github.com/IUDevman/gamesense-client). Here are some screenshots of what is possible with this library: * CyberHack Theme: ![cyberhack](https://cdn.discordapp.com/attachments/755077474861449277/770697901499744286/2020-10-27_18.16.50.png) * GameSense 2.0 Theme: diff --git a/src/main/java/com/lukflug/panelstudio/Context.java b/src/main/java/com/lukflug/panelstudio/Context.java index b27adbf..626829b 100644 --- a/src/main/java/com/lukflug/panelstudio/Context.java +++ b/src/main/java/com/lukflug/panelstudio/Context.java @@ -13,10 +13,6 @@ public class Context { * The current {@link Interface}. */ private Interface inter; - /** - * The current {@link FoucsManager}. - */ - private FocusManager manager; /** * The size of the component. * The width is decided by the parent, while the height is decided by the component. @@ -36,10 +32,15 @@ public class Context { * Only has meaning if the mouse cursor is hovering over the component. */ private boolean onTop; + /** + * Set to true by the child using {@link #requestFocus()}. + * Used to indicate that the focus within the parent should be given to the child component. + */ + private boolean focusRequested=false; /** * Constructor that should be used when a parent is calling a method by the child. - * {@link #inter}, {@link #manager} and {@link #onTop} are inherited without modification. + * {@link #inter} and {@link #onTop} are inherited without modification. * @param context the context of the parent * @param border the horizontal border (left and right) for the child * @param offset the vertical position of the child relative to the parent's position @@ -47,7 +48,6 @@ public class Context { */ public Context (Context context, int border, int offset, boolean focus) { inter=context.getInterface(); - manager=context.getFocusManager(); size=new Dimension(context.getSize().width-border*2,0); position=new Point(context.getPos()); position.translate(border,offset); @@ -58,15 +58,13 @@ public Context (Context context, int border, int offset, boolean focus) { /** * Constructor that should be used by the root parent (i.e. {@link ClickGUI}). * @param inter the current {@link Interface} - * @param manager the current {@link FocusManager} * @param width the width of the component * @param position the position of the component * @param focus set to false, to disable the component from having focus * @param onTop set to false, if a component is above another component at the current cursor position */ - public Context (Interface inter, FocusManager manager, int width, Point position, boolean focus, boolean onTop) { + public Context (Interface inter, int width, Point position, boolean focus, boolean onTop) { this.inter=inter; - this.manager=manager; size=new Dimension(width,0); this.position=new Point(position); this.focus=focus; @@ -81,14 +79,6 @@ public Interface getInterface() { return inter; } - /** - * Returns the current {@link FocusManager}. - * @return the current {@link FocusManager} - */ - public FocusManager getFocusManager() { - return manager; - } - /** * Returns the component size. * @return the component size @@ -128,6 +118,21 @@ public boolean hasFocus() { public boolean onTop() { return onTop; } + + /** + * Used to indicate to the parent that the current component has to have focus within the parent. + */ + public void requestFocus() { + focusRequested=true; + } + + /** + * Returns {@link #focusRequested}. + * @return whether the child is requesting focus. + */ + public boolean foucsRequested() { + return focusRequested; + } /** * Get mouse hover state. diff --git a/src/main/java/com/lukflug/panelstudio/FocusManager.java b/src/main/java/com/lukflug/panelstudio/FocusManager.java deleted file mode 100644 index ad09b26..0000000 --- a/src/main/java/com/lukflug/panelstudio/FocusManager.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.lukflug.panelstudio; - -/** - * Interface to prevent cyclical dependency between ClickGUI and {@link FixedComponent} requesting focus. - * @author lukflug - */ -public interface FocusManager { - /** - * Function to request the focus within a GUI. - * @param component the component requesting focus - */ - public void requestFocus (Focusable component); -} diff --git a/src/main/java/com/lukflug/panelstudio/Focusable.java b/src/main/java/com/lukflug/panelstudio/Focusable.java deleted file mode 100644 index adb3d6a..0000000 --- a/src/main/java/com/lukflug/panelstudio/Focusable.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.lukflug.panelstudio; - -/** - * Marker interface indicating that a {@link FixedComponent} is focusable. - * @author lukflug - * @see FixedComponent - */ -public interface Focusable { -} diff --git a/src/main/java/com/lukflug/panelstudio/Interface.java b/src/main/java/com/lukflug/panelstudio/Interface.java index 6855e6c..f4c2854 100644 --- a/src/main/java/com/lukflug/panelstudio/Interface.java +++ b/src/main/java/com/lukflug/panelstudio/Interface.java @@ -14,6 +14,10 @@ public interface Interface { * @see #getButton(int) */ public static final int LBUTTON=0; + /** + * ID for the right mouse button. + * @see #getButton(int) + */ public static final int RBUTTON=1; /**