-
Notifications
You must be signed in to change notification settings - Fork 33
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
Showing
11 changed files
with
521 additions
and
13 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
timelines/src/main/java/gg/xp/xivsupport/timelines/CustomEventSyncController.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,82 @@ | ||
package gg.xp.xivsupport.timelines; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import gg.xp.reevent.events.Event; | ||
import gg.xp.xivsupport.timelines.cbevents.CbEventFmt; | ||
import gg.xp.xivsupport.timelines.cbevents.CbEventType; | ||
import gg.xp.xivsupport.timelines.intl.LanguageReplacements; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CustomEventSyncController implements EventSyncController { | ||
|
||
private final Class<? extends Event> eventClass; | ||
private Map<String, List<String>> conditions; | ||
@JsonIgnore | ||
private EventSyncController wrapped; | ||
@JsonIgnore | ||
private final CbEventType eventType; | ||
|
||
@JsonCreator | ||
public CustomEventSyncController(@JsonProperty("type") CbEventType eventType, @JsonProperty("conditions") Map<String, List<String>> conditions) { | ||
this.eventType = eventType; | ||
this.eventClass = eventType.eventType(); | ||
this.conditions = new HashMap<>(conditions); | ||
recalc(); | ||
} | ||
|
||
public static CustomEventSyncController from(EventSyncController other) { | ||
return new CustomEventSyncController(other.getType(), other.getRawConditions()); | ||
} | ||
|
||
private void recalc() { | ||
wrapped = CbEventFmt.parse(eventType, conditions); | ||
} | ||
|
||
public void setConditions(Map<String, List<String>> conditions) { | ||
this.conditions = TimelineUtils.cloneConditions(conditions); | ||
recalc(); | ||
} | ||
|
||
@Override | ||
public boolean shouldSync(Event event) { | ||
return wrapped.shouldSync(event); | ||
} | ||
|
||
@Override | ||
public Class<? extends Event> eventType() { | ||
return eventClass; | ||
} | ||
|
||
@Override | ||
public EventSyncController translateWith(LanguageReplacements replacements) { | ||
// No translation for custom entries | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toTextFormat() { | ||
return wrapped.toTextFormat(); | ||
} | ||
|
||
@Override | ||
public CbEventType getType() { | ||
return eventType; | ||
} | ||
|
||
@Override | ||
public Map<String, List<String>> getRawConditions() { | ||
return TimelineUtils.cloneConditions(conditions); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
// TODO: there should be something to differentiate this from a builtin | ||
return wrapped.toString(); | ||
} | ||
} |
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
16 changes: 12 additions & 4 deletions
16
timelines/src/main/java/gg/xp/xivsupport/timelines/EventSyncController.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 |
---|---|---|
@@ -1,18 +1,26 @@ | ||
package gg.xp.xivsupport.timelines; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import gg.xp.reevent.events.Event; | ||
import gg.xp.xivsupport.timelines.cbevents.CbEventType; | ||
import gg.xp.xivsupport.timelines.intl.LanguageReplacements; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface EventSyncController { | ||
boolean shouldSync(Event event); | ||
|
||
Class<? extends Event> eventType(); | ||
|
||
default boolean isEditable() { | ||
return false; | ||
}; | ||
|
||
EventSyncController translateWith(LanguageReplacements replacements); | ||
|
||
String toTextFormat(); | ||
|
||
@JsonProperty("type") | ||
CbEventType getType(); | ||
|
||
@JsonProperty("conditions") | ||
Map<String, List<String>> getRawConditions(); | ||
} |
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
69 changes: 69 additions & 0 deletions
69
timelines/src/main/java/gg/xp/xivsupport/timelines/NullableEnumComboBox.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,69 @@ | ||
package gg.xp.xivsupport.timelines; | ||
|
||
import gg.xp.xivsupport.gui.lists.FriendlyNameListCellRenderer; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import javax.swing.event.ListDataListener; | ||
import java.awt.*; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public class NullableEnumComboBox<X extends Enum<X>> extends JComboBox<X> { | ||
|
||
private @Nullable X selectedItem; | ||
|
||
public NullableEnumComboBox(Class<X> enumCls, String nullLabel, Consumer<@Nullable X> consumer, @Nullable X initialValue) { | ||
X[] constants = enumCls.getEnumConstants(); | ||
List<X> list = new ArrayList<>(Arrays.asList(constants)); | ||
list.add(0, null); | ||
selectedItem = initialValue; | ||
ComboBoxModel<X> model = new ComboBoxModel<>() { | ||
|
||
@Override | ||
public int getSize() { | ||
return list.size(); | ||
} | ||
|
||
@Override | ||
public X getElementAt(int index) { | ||
return list.get(index); | ||
} | ||
|
||
@Override | ||
public void addListDataListener(ListDataListener l) { | ||
|
||
} | ||
|
||
@Override | ||
public void removeListDataListener(ListDataListener l) { | ||
|
||
} | ||
|
||
@Override | ||
public void setSelectedItem(Object anItem) { | ||
selectedItem = (X) anItem; | ||
consumer.accept((X) anItem); | ||
} | ||
|
||
@Override | ||
public Object getSelectedItem() { | ||
return selectedItem; | ||
} | ||
}; | ||
setModel(model); | ||
setRenderer(new FriendlyNameListCellRenderer() { | ||
@Override | ||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { | ||
if (value == null) { | ||
return super.getListCellRendererComponent(list, nullLabel, index, isSelected, cellHasFocus); | ||
} | ||
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); | ||
} | ||
}); | ||
|
||
} | ||
|
||
} |
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
20 changes: 20 additions & 0 deletions
20
timelines/src/main/java/gg/xp/xivsupport/timelines/TimelineUtils.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,20 @@ | ||
package gg.xp.xivsupport.timelines; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public final class TimelineUtils { | ||
|
||
private TimelineUtils() { | ||
} | ||
|
||
public static Map<String, List<String>> cloneConditions(Map<String, List<String>> in) { | ||
return in.entrySet().stream().collect(Collectors.toMap( | ||
Map.Entry::getKey, | ||
e -> new ArrayList<>(e.getValue()) | ||
)); | ||
} | ||
|
||
} |
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
Oops, something went wrong.