-
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.
A simple wrapper around Widget Messages; however this is currently only partly implemented. Additionally this will be the last commit for Galimulator version 4.8-beta.2 and I will be working on bumping the galimulator version to 4.8-stable soon. Hopefully it will not really fail as hard.
- Loading branch information
Showing
6 changed files
with
118 additions
and
2 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
11 changes: 11 additions & 0 deletions
11
src/main/java/de/geolykt/starloader/api/gui/WidgetAction.java
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,11 @@ | ||
package de.geolykt.starloader.api.gui; | ||
|
||
/** | ||
* Our version agnostic contemporary to Widget messages, which is an odd way to communicate within the UI System within the | ||
* snoddasmannen.galimulator.ui package | ||
*/ | ||
public enum WidgetAction { | ||
CLOSE, | ||
RESIZE, | ||
REDRAW; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/de/geolykt/starloader/api/gui/WidgetActionListener.java
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,9 @@ | ||
package de.geolykt.starloader.api.gui; | ||
|
||
/** | ||
* Listens for {@link WidgetAction} on Widgets the listener has been registered to. | ||
*/ | ||
@FunctionalInterface | ||
public interface WidgetActionListener { | ||
public void onAction(WidgetAction action); | ||
} |
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
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
95 changes: 95 additions & 0 deletions
95
src/main/java/de/geolykt/starloader/impl/WidgetActionListenerWrapper.java
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,95 @@ | ||
package de.geolykt.starloader.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import de.geolykt.starloader.DebugNagException; | ||
import de.geolykt.starloader.api.gui.AutocloseableDialog; | ||
import de.geolykt.starloader.api.gui.BasicDialogCloseListener; | ||
import de.geolykt.starloader.api.gui.DialogCloseCause; | ||
import de.geolykt.starloader.api.gui.WidgetAction; | ||
import de.geolykt.starloader.api.gui.WidgetActionListener; | ||
import snoddasmannen.galimulator.ui.Widget$WIDGET_MESSAGE; | ||
|
||
public class WidgetActionListenerWrapper implements snoddasmannen.galimulator.hg { | ||
|
||
private final List<BasicDialogCloseListener> closeListeners; | ||
private final List<WidgetActionListener> actionListeners; | ||
private final AutocloseableDialog parent; | ||
|
||
/** | ||
* Initiates the wrapper with the parent and listeners known. The listeners can be modified later however, provided | ||
* the list implementation supports that. | ||
* @param parent The parent that is closable automatically, a null value means that it will never be closed automatically. | ||
* @param closeListeners The close listeners to have initially | ||
* @param actionListeners The widget action listeners to have initially | ||
*/ | ||
WidgetActionListenerWrapper(@Nullable AutocloseableDialog parent, | ||
@NotNull List<BasicDialogCloseListener> closeListeners, @NotNull List<WidgetActionListener> actionListeners) { | ||
this.parent = parent; | ||
this.closeListeners = closeListeners; | ||
this.actionListeners = actionListeners; | ||
} | ||
|
||
/** | ||
* Initiates the wrapper with a parent that is closable automatically. If that parameter is null it should behave the | ||
* same way as {@link #WidgetActionListenerWrapper()} | ||
* @param parent The parent dialog | ||
*/ | ||
public WidgetActionListenerWrapper(@Nullable AutocloseableDialog parent) { | ||
this(parent, new ArrayList<>(), new ArrayList<>()); | ||
} | ||
|
||
/** | ||
* Initiates the wrapper with no further information. If the parent Widget is an automatically closing dialog, then | ||
* {@link #WidgetActionListenerWrapper(AutoCloseable)} should be preferred as | ||
* otherwise the {@link BasicDialogCloseListener} might get multiple automatic close notifications. | ||
*/ | ||
public WidgetActionListenerWrapper() { | ||
this(null, new ArrayList<>(), new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public void a(Widget$WIDGET_MESSAGE var1) { | ||
if (var1 == Widget$WIDGET_MESSAGE.a) { | ||
// Check if it was closed automatically due to timeout, if it was, then ignore this request | ||
if (parent == null) { | ||
notifyClose(DialogCloseCause.MANUAL_CLOSE); | ||
} else { | ||
long timeout = parent.getAutocloseTime(); | ||
if (timeout == -1 || timeout < System.currentTimeMillis()) { | ||
notifyClose(DialogCloseCause.MANUAL_CLOSE); | ||
} | ||
} | ||
for (WidgetActionListener listener : actionListeners) { | ||
listener.onAction(WidgetAction.CLOSE); | ||
} | ||
} else { | ||
if (var1 == null) { | ||
DebugNagException.nag("Null widget message!"); | ||
} | ||
WidgetAction action = var1 == Widget$WIDGET_MESSAGE.b ? WidgetAction.RESIZE : WidgetAction.REDRAW; | ||
for (WidgetActionListener listener : actionListeners) { | ||
listener.onAction(action); | ||
} | ||
} | ||
} | ||
|
||
private void notifyClose(DialogCloseCause cause) { | ||
for (BasicDialogCloseListener listener : closeListeners) { | ||
listener.onClose(cause, null); | ||
} | ||
} | ||
|
||
public void addListener(@NotNull BasicDialogCloseListener listener) { | ||
closeListeners.add(listener); | ||
} | ||
|
||
public void addListener(@NotNull WidgetActionListener listener) { | ||
actionListeners.add(listener); | ||
} | ||
|
||
} |