Skip to content

Commit

Permalink
2.27
Browse files Browse the repository at this point in the history
Added:

MessageQueue for improved message handling and responsive GUI

Fixed:

Overall improved message handling (TDuva is based)
Null check for twitch faces (deleted sets on Twitch are now deleted locally)
BanQueue is a little more responsive now
  • Loading branch information
Gocnak committed Jan 15, 2015
1 parent 1e684cc commit a68f7bf
Show file tree
Hide file tree
Showing 20 changed files with 406 additions and 237 deletions.
95 changes: 57 additions & 38 deletions src/main/java/face/FaceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import javax.swing.*;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
Expand Down Expand Up @@ -215,34 +215,37 @@ public static void loadDefaultFaces() {
for (int localEmoteSet : keyLocal) {
ArrayList<TwitchFace> localEmotes = loadedTwitchFaces.get(localEmoteSet);
ArrayList<TwitchFace> externalEmotes = twitchFaceMap.get(localEmoteSet);

for (TwitchFace external : externalEmotes) {
boolean flag = false;
for (TwitchFace internal : localEmotes) {
if (internal.getFilePath().contains(external.getFilePath().split("-")[4])) {
flag = true;
break;
if (externalEmotes != null) {
for (TwitchFace external : externalEmotes) {
boolean flag = false;
for (TwitchFace internal : localEmotes) {
if (internal.getFilePath().contains(external.getFilePath().split("-")[4])) {
flag = true;
break;
}
}
}
if (!flag) {//add new faces that I need
try {
String newFaceToAddFileName = Utils.setExtension(external.getFilePath().split("-")[4], ".png");
File newFaceToAdd = new File(GUIMain.currentSettings.twitchFaceDir + File.separator + newFaceToAddFileName);
if (download(external.getFilePath(), newFaceToAdd)) {
localEmotes.add(new TwitchFace(external.getRegex(), newFaceToAdd.getAbsolutePath(), true));
if (!flag) {//add new faces that I need
try {
String newFaceToAddFileName = Utils.setExtension(external.getFilePath().split("-")[4], ".png");
File newFaceToAdd = new File(GUIMain.currentSettings.twitchFaceDir + File.separator + newFaceToAddFileName);
if (download(external.getFilePath(), newFaceToAdd)) {
localEmotes.add(new TwitchFace(external.getRegex(), newFaceToAdd.getAbsolutePath(), true));
}
} catch (Exception ignored) {
}
} catch (Exception ignored) {
}
}
}
//remove the ones I shouldn't have
ArrayList<TwitchFace> toRemove = new ArrayList<>();
for (TwitchFace internal : localEmotes) {
boolean flag = false;
for (TwitchFace external : externalEmotes) {
if (internal.getFilePath().contains(external.getFilePath().split("-")[4])) {
flag = true;
break;
if (externalEmotes != null) {//if it's null, that means the set is gone now, delete it
for (TwitchFace external : externalEmotes) {
if (internal.getFilePath().contains(external.getFilePath().split("-")[4])) {
flag = true;
break;
}
}
}
if (!flag) {
Expand Down Expand Up @@ -294,17 +297,18 @@ public static Response toggleFace(String faceName) {
return toReturn;
}

public static void handleFaces(final StyledDocument doc, final int start, final String object, final FACE_TYPE type) {
switch (type) {
case NAME_FACE:
Set<String> names = nameFaceMap.keySet();
for (String s : names) {
if (object.equalsIgnoreCase(s)) {
insertFace(doc, start, object, nameFaceMap.get(s).getFilePath());
break;
}
}
public static void handleNameFaces(String object, SimpleAttributeSet set) {
Set<String> names = nameFaceMap.keySet();
for (String s : names) {
if (object.equalsIgnoreCase(s)) {
insertFace(set, nameFaceMap.get(s).getFilePath());
break;
}
}
}

public static void handleFaces(Map<Integer, Integer> ranges, Map<Integer, SimpleAttributeSet> rangeStyles, final String object, final FACE_TYPE type) {
switch (type) {
case TWITCH_FACE:
if (doneWithTwitchFaces) {
Set<Integer> sets = loadedTwitchFaces.keySet();
Expand All @@ -320,7 +324,16 @@ public static void handleFaces(final StyledDocument doc, final int start, final
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(object);
while (m.find() && !GUIMain.shutDown) {
insertFace(doc, start + m.start(), m.group(), f.getFilePath());
int start = m.start();
int end = m.end() - 1;
if (!Utils.inRanges(start, ranges) && !Utils.inRanges(end, ranges)) {
ranges.put(start, end);
SimpleAttributeSet attrs = new SimpleAttributeSet();
insertFace(attrs, f.getFilePath());
attrs.addAttribute("start", start);
rangeStyles.put(start, attrs);
}
//insertFace(doc, start + m.start(), m.group(), f.getFilePath());
}
}
}
Expand All @@ -335,7 +348,16 @@ public static void handleFaces(final StyledDocument doc, final int start, final
Pattern p = Pattern.compile(f.getRegex());
Matcher m = p.matcher(object);
while (m.find() && !GUIMain.shutDown) {
insertFace(doc, start + m.start(), m.group(), f.getFilePath());
int start = m.start();
int end = m.end() - 1;
if (!Utils.inRanges(start, ranges) && !Utils.inRanges(end, ranges)) {
ranges.put(start, end);
SimpleAttributeSet attrs = new SimpleAttributeSet();
insertFace(attrs, f.getFilePath());
attrs.addAttribute("start", start);
rangeStyles.put(start, attrs);
}
//insertFace(doc, start + m.start(), m.group(), f.getFilePath());
}
}
}
Expand All @@ -345,18 +367,15 @@ public static void handleFaces(final StyledDocument doc, final int start, final
}
}

private static synchronized void insertFace(StyledDocument doc, int start, String name, String face) {
private static void insertFace(SimpleAttributeSet set, String face) {
try {
//finds the index of the face while not replacing the old ones
final SimpleAttributeSet attrs = new SimpleAttributeSet(doc.getCharacterElement(start).getAttributes());
StyleConstants.setIcon(attrs, sizeIcon(new File(face).toURI().toURL()));
doc.remove(start, name.length());
doc.insertString(start, name, attrs);
StyleConstants.setIcon(set, sizeIcon(new File(face).toURI().toURL()));
} catch (Exception e) {
GUIMain.log(e.getMessage());
}
}


private static ImageIcon sizeIcon(URL image) {
ImageIcon icon;
try {
Expand Down
Loading

0 comments on commit a68f7bf

Please sign in to comment.