config file with new keys.dev
parent
2b69dcda03
commit
e4d37ab272
Binary file not shown.
@ -0,0 +1,290 @@ |
|||||||
|
package sig.modules.ChatLog; |
||||||
|
|
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Point; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Random; |
||||||
|
|
||||||
|
import javax.swing.SwingUtilities; |
||||||
|
|
||||||
|
import sig.Emoticon; |
||||||
|
import sig.Module; |
||||||
|
import sig.SubEmoticon; |
||||||
|
import sig.sigIRC; |
||||||
|
import sig.modules.ChatLogModule; |
||||||
|
import sig.utils.DrawUtils; |
||||||
|
import sig.utils.TextUtils; |
||||||
|
|
||||||
|
public class ChatLogMessage { |
||||||
|
String rawMessage; |
||||||
|
Point messageDisplaySize; //The amount of screen space (w,h) this message takes up.
|
||||||
|
public Point position; |
||||||
|
ChatLogModule refModule; |
||||||
|
String username; |
||||||
|
List<String> displayMessage = new ArrayList<String>(); |
||||||
|
final static public int MESSAGE_SPACING = 24; |
||||||
|
final static public int BORDER_SPACING = 8; |
||||||
|
final static public Color SHADOW_COL = new Color(35,35,35,255); |
||||||
|
int usernameWidth = 0; |
||||||
|
boolean active=true; |
||||||
|
|
||||||
|
public ChatLogMessage(String rawMessage) { |
||||||
|
this.refModule = ChatLogModule.chatlogmodule; |
||||||
|
this.rawMessage = rawMessage; |
||||||
|
this.position = new Point(0,(int)refModule.getPosition().getHeight()-MESSAGE_SPACING); |
||||||
|
WrapText(); |
||||||
|
for (ChatLogMessage clm : this.refModule.messageHistory) { |
||||||
|
clm.position.setLocation( |
||||||
|
clm.position.getX(), |
||||||
|
clm.position.getY()-messageDisplaySize.getY()); |
||||||
|
//System.out.println(clm.rawMessage+": "+clm.position);
|
||||||
|
} |
||||||
|
this.position.setLocation(this.position.getX(), this.position.getY()-messageDisplaySize.getY()+ChatLogModule.chatlogmodule.scrolllog_yoffset); |
||||||
|
//System.out.println(displayMessage);
|
||||||
|
DetectUsername(displayMessage); |
||||||
|
if (this.username!=null) { |
||||||
|
displayMessage.set(0,GetMessage(displayMessage.get(0))); |
||||||
|
usernameWidth = (int)TextUtils.calculateStringBoundsFont(this.username, sigIRC.panel.userFont).getWidth(); |
||||||
|
} |
||||||
|
for (int i=0;i<displayMessage.size();i++) { |
||||||
|
displayMessage.set(i, ReplaceMessageWithEmoticons(displayMessage.get(i)+" ",i*MESSAGE_SPACING)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private String ReplaceMessageWithEmoticons(String basemsg, int ypos) { |
||||||
|
int marker = basemsg.indexOf(" "); |
||||||
|
while (marker<basemsg.length()) { |
||||||
|
//Find a space.
|
||||||
|
int space = basemsg.indexOf(" ", marker+1); |
||||||
|
if (space>0) { |
||||||
|
String word = basemsg.substring(marker+1, space); |
||||||
|
//System.out.println("Word is '"+word+"'");
|
||||||
|
sigIRC.emoticons.addAll(sigIRC.emoticon_queue); |
||||||
|
sigIRC.emoticon_queue.clear(); |
||||||
|
for (Emoticon e : sigIRC.emoticons) { |
||||||
|
//System.out.println("Checking for emoticon "+e.getEmoteName());
|
||||||
|
try { |
||||||
|
if (e.getEmoteName().equals(word)) { |
||||||
|
if (e instanceof SubEmoticon) { |
||||||
|
SubEmoticon se = (SubEmoticon)e; |
||||||
|
if (!se.canUserUseEmoticon(username)) { |
||||||
|
//System.out.println("User "+username+" is not subscribed to "+se.channelName+"'s channel!");
|
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
//System.out.println(" Found one!");
|
||||||
|
basemsg = TextUtils.replaceFirst(basemsg, e.getEmoteName(), e.getSmallSpaceFiller()); |
||||||
|
GenerateEmoticon(marker+1, ypos, basemsg, e); |
||||||
|
space = basemsg.indexOf(" ", marker+1); |
||||||
|
break; |
||||||
|
} |
||||||
|
} catch (NullPointerException ex) { |
||||||
|
ex.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
marker=space; |
||||||
|
} else { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
//textMaxWidth = (int)TextUtils.calculateStringBoundsFont(basemsg, sigIRC.panel.programFont).getWidth();
|
||||||
|
//textMaxHeight = Math.max(textMaxHeight,(int)TextUtils.calculateStringBoundsFont(basemsg, sigIRC.panel.programFont).getHeight());
|
||||||
|
return basemsg; |
||||||
|
} |
||||||
|
|
||||||
|
private void GenerateEmoticon(int textpos, int ypos, String basemsg, Emoticon e) { |
||||||
|
String cutstring = basemsg.substring(0, textpos); |
||||||
|
double width = TextUtils.calculateStringBoundsFont(cutstring, sigIRC.panel.userFont).getWidth(); |
||||||
|
//System.out.println("Width of '"+cutstring+"' is "+width);
|
||||||
|
sigIRC.createEmoticon(e, this, (int)(width), ypos+16); |
||||||
|
//textMaxHeight = Math.max(textMaxHeight, e.getImage().getHeight());
|
||||||
|
//textMaxWidth = (int)(width + e.getImage().getWidth()+1);
|
||||||
|
} |
||||||
|
|
||||||
|
private String GetMessage(String msg) { |
||||||
|
String basemsg = " "+msg.substring(msg.indexOf(":")+2, msg.length())+" "; |
||||||
|
//basemsg = ConvertMessageSymbols(basemsg);
|
||||||
|
//basemsg = ReplaceMessageWithEmoticons(basemsg);
|
||||||
|
return basemsg.replaceFirst(" ", "").substring(0,basemsg.length()-1); |
||||||
|
} |
||||||
|
|
||||||
|
private void DetectUsername(List<String> messages) { |
||||||
|
if (messages.size()>0) { |
||||||
|
String username = GetUsername(messages.get(0)); |
||||||
|
if (username!=null) { |
||||||
|
this.username = username; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private Color GetUserNameColor(String username) { |
||||||
|
Random r = new Random(); |
||||||
|
r.setSeed(username.hashCode()); |
||||||
|
int randomnumb = r.nextInt(3); |
||||||
|
Color col; |
||||||
|
switch (randomnumb) { |
||||||
|
case 0:{ |
||||||
|
col=new Color(255,r.nextInt(128)+64,r.nextInt(128)+64,255); |
||||||
|
}break; |
||||||
|
case 1:{ |
||||||
|
col=new Color(r.nextInt(128)+64,255,r.nextInt(128)+64,255); |
||||||
|
}break; |
||||||
|
case 2:{ |
||||||
|
col=new Color(r.nextInt(128)+64,r.nextInt(128)+64,255,255); |
||||||
|
}break; |
||||||
|
default:{ |
||||||
|
col=Color.GREEN; |
||||||
|
} |
||||||
|
} |
||||||
|
return col; |
||||||
|
} |
||||||
|
|
||||||
|
private String GetUsername(String msg) { |
||||||
|
if (msg.contains(":")) { |
||||||
|
return msg.substring(0,msg.indexOf(":")); |
||||||
|
} else { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void WrapText() { |
||||||
|
String rawmessage = rawMessage; |
||||||
|
int textWidth = (int)TextUtils.calculateStringBoundsFont(rawmessage, sigIRC.panel.userFont).getWidth(); |
||||||
|
int maxWidth = (int)refModule.getPosition().getWidth()-BORDER_SPACING; |
||||||
|
do { |
||||||
|
rawmessage = BreakTextAtNextSection(rawmessage,maxWidth); |
||||||
|
textWidth = (int)TextUtils.calculateStringBoundsFont(rawmessage, sigIRC.panel.userFont).getWidth(); |
||||||
|
} while (textWidth>maxWidth); |
||||||
|
if (rawmessage.length()>0) { |
||||||
|
displayMessage.add(rawmessage); |
||||||
|
} |
||||||
|
messageDisplaySize = new Point((int)(refModule.getPosition().getWidth()-BORDER_SPACING),(int)(displayMessage.size()*MESSAGE_SPACING)); |
||||||
|
//System.out.println(displayMessage+": "+messageDisplaySize);
|
||||||
|
} |
||||||
|
|
||||||
|
private String BreakTextAtNextSection(String msg, int maxWidth) { |
||||||
|
int marker = 1; |
||||||
|
int textWidth = (int)TextUtils.calculateStringBoundsFont(msg.substring(0, marker), sigIRC.panel.userFont).getWidth(); |
||||||
|
while (textWidth<maxWidth) { |
||||||
|
if (marker<msg.length()) { |
||||||
|
int tempmarker = msg.indexOf(' ', marker); |
||||||
|
if (tempmarker!=-1) { |
||||||
|
textWidth = (int)TextUtils.calculateStringBoundsFont(msg.substring(0, tempmarker), sigIRC.panel.userFont).getWidth(); |
||||||
|
if (textWidth<maxWidth) { |
||||||
|
marker = tempmarker+1; |
||||||
|
} |
||||||
|
//System.out.println(msg.substring(0, marker)+" | "+textWidth);
|
||||||
|
} else { |
||||||
|
marker=msg.length(); |
||||||
|
break; |
||||||
|
} |
||||||
|
} else { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
String currentText = msg.substring(0, marker); |
||||||
|
displayMessage.add(currentText); |
||||||
|
return msg.substring(marker, msg.length()); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean run() { |
||||||
|
SwingUtilities.invokeLater(new Runnable() { |
||||||
|
public void run() { |
||||||
|
sigIRC.panel.repaint( |
||||||
|
(int)Math.max(refModule.getPosition().getX()+position.getX(),0), |
||||||
|
(int)Math.max(refModule.getPosition().getY()+position.getY(),0), |
||||||
|
(int)Math.min(sigIRC.panel.getWidth()-(refModule.getPosition().getX()+position.getX()+messageDisplaySize.getX()),messageDisplaySize.getX()), |
||||||
|
(int)Math.min(sigIRC.panel.getHeight()-(refModule.getPosition().getY()+position.getY()+messageDisplaySize.getY()),messageDisplaySize.getY())); |
||||||
|
} |
||||||
|
}); |
||||||
|
//System.out.println(refModule.getPosition()+","+position);
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public void draw(Graphics g) { |
||||||
|
if (isVisible()) { |
||||||
|
for (int i=0;i<displayMessage.size();i++) { |
||||||
|
//System.out.println(displayMessage.get(i));
|
||||||
|
if (username!=null && i==0) { |
||||||
|
DrawUtils.drawOutlineText(g, sigIRC.panel.userFont, refModule.getPosition().getX()+position.getX(), refModule.getPosition().getY()+position.getY()+(i*MESSAGE_SPACING)+32, 2, GetUserNameColor(this.username), SHADOW_COL, this.username); |
||||||
|
DrawUtils.drawTextFont(g, sigIRC.panel.userFont, refModule.getPosition().getX()+position.getX()+usernameWidth+2, refModule.getPosition().getY()+position.getY()+(i*MESSAGE_SPACING)+32, Color.BLACK, displayMessage.get(i)); |
||||||
|
} else { |
||||||
|
DrawUtils.drawTextFont(g, sigIRC.panel.userFont, refModule.getPosition().getX()+position.getX(), refModule.getPosition().getY()+position.getY()+(i*MESSAGE_SPACING)+32, Color.BLACK, displayMessage.get(i)); |
||||||
|
} |
||||||
|
} |
||||||
|
g.drawImage(Module.MSG_SEPARATOR, (int)(refModule.getPosition().getX()+position.getX()+8), (int)(refModule.getPosition().getY()+position.getY()+messageDisplaySize.getY()+12), (int)(messageDisplaySize.getX()-8), 1, sigIRC.panel); |
||||||
|
//g.drawLine((int)(refModule.getPosition().getX()+position.getX()+8), (int)(refModule.getPosition().getY()+position.getY()+messageDisplaySize.getY()+32), (int)(refModule.getPosition().getX()+position.getX()+messageDisplaySize.getX()-8), (int)(refModule.getPosition().getY()+position.getY()+messageDisplaySize.getY()+32));
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static void importMessages(String...logContents) { |
||||||
|
for (String s : logContents) { |
||||||
|
if (ChatLogModule.chatlogmodule.messageHistory.size()>=ChatLogModule.messageHistoryCount) { |
||||||
|
ChatLogModule.chatlogmodule.messageHistory.remove(0).cleanup(); |
||||||
|
} |
||||||
|
ChatLogModule.chatlogmodule.messageHistory.add(new ChatLogMessage(s)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void cleanup() { |
||||||
|
active=false; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isVisible() { |
||||||
|
return (refModule.getPosition().getY()+position.getY()+MESSAGE_SPACING)>refModule.getPosition().getY() && |
||||||
|
(refModule.getPosition().getY()+position.getY()+messageDisplaySize.getY())<refModule.getPosition().getY()+refModule.getPosition().getHeight()-16; |
||||||
|
} |
||||||
|
|
||||||
|
/* |
||||||
|
private String ReplaceMessageWithEmoticons(String basemsg) { |
||||||
|
int marker = basemsg.indexOf(" "); |
||||||
|
while (marker<basemsg.length()) { |
||||||
|
//Find a space.
|
||||||
|
int space = basemsg.indexOf(" ", marker+1); |
||||||
|
if (space>0) { |
||||||
|
String word = basemsg.substring(marker+1, space); |
||||||
|
//System.out.println("Word is '"+word+"'");
|
||||||
|
sigIRC.emoticons.addAll(sigIRC.emoticon_queue); |
||||||
|
sigIRC.emoticon_queue.clear(); |
||||||
|
for (Emoticon e : sigIRC.emoticons) { |
||||||
|
//System.out.println("Checking for emoticon "+e.getEmoteName());
|
||||||
|
try { |
||||||
|
if (e.getEmoteName().equals(word)) { |
||||||
|
if (e instanceof SubEmoticon) { |
||||||
|
SubEmoticon se = (SubEmoticon)e; |
||||||
|
if (!se.canUserUseEmoticon(username)) { |
||||||
|
//System.out.println("User "+username+" is not subscribed to "+se.channelName+"'s channel!");
|
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
//System.out.println(" Found one!");
|
||||||
|
basemsg = TextUtils.replaceFirst(basemsg, e.getEmoteName(), e.getSpaceFiller()); |
||||||
|
GenerateEmoticon(marker+1, basemsg, e); |
||||||
|
space = basemsg.indexOf(" ", marker+1); |
||||||
|
break; |
||||||
|
} |
||||||
|
} catch (NullPointerException ex) { |
||||||
|
ex.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
marker=space; |
||||||
|
} else { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
textMaxWidth = (int)TextUtils.calculateStringBoundsFont(basemsg, sigIRC.panel.programFont).getWidth(); |
||||||
|
textMaxHeight = Math.max(textMaxHeight,(int)TextUtils.calculateStringBoundsFont(basemsg, sigIRC.panel.programFont).getHeight()); |
||||||
|
return basemsg; |
||||||
|
} |
||||||
|
|
||||||
|
private void GenerateEmoticon(int pos, String basemsg, Emoticon e) { |
||||||
|
String cutstring = basemsg.substring(0, pos); |
||||||
|
double width = TextUtils.calculateStringBoundsFont(cutstring, sigIRC.panel.programFont).getWidth(); |
||||||
|
//System.out.println("Width of '"+cutstring+"' is "+width);
|
||||||
|
sigIRC.createEmoticon(e, this, (int)(width), 0); |
||||||
|
textMaxHeight = Math.max(textMaxHeight, e.getImage().getHeight()); |
||||||
|
//textMaxWidth = (int)(width + e.getImage().getWidth()+1);
|
||||||
|
}*/ |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
package sig.modules.ChatLog; |
||||||
|
|
||||||
|
import java.awt.Graphics; |
||||||
|
|
||||||
|
import javax.swing.SwingUtilities; |
||||||
|
|
||||||
|
import sig.Emoticon; |
||||||
|
import sig.ScrollingText; |
||||||
|
import sig.sigIRC; |
||||||
|
|
||||||
|
public class ChatLogTwitchEmote { |
||||||
|
Emoticon emote; |
||||||
|
int x=0; //X Offset
|
||||||
|
int y=0; //Y Offset
|
||||||
|
ChatLogMessage text; |
||||||
|
|
||||||
|
public ChatLogTwitchEmote(Emoticon emote, ChatLogMessage textref, int x, int y) { |
||||||
|
this.emote=emote; |
||||||
|
this.x=x; |
||||||
|
this.y=y+24-emote.getImage().getHeight(); |
||||||
|
this.text = textref; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean run() { |
||||||
|
//this.x-=paint.TEXTSCROLLSPD;
|
||||||
|
/*if (textRefIsVisible()) { |
||||||
|
SwingUtilities.invokeLater(new Runnable() { |
||||||
|
public void run() { |
||||||
|
sigIRC.panel.repaint( |
||||||
|
Math.max(x,0), |
||||||
|
Math.max(y, 0), |
||||||
|
Math.min(sigIRC.panel.getWidth()-x,emote.getImage().getWidth()), |
||||||
|
Math.min(sigIRC.panel.getHeight()-y,emote.getImage().getHeight())); |
||||||
|
} |
||||||
|
}); |
||||||
|
}*/ |
||||||
|
if (text==null || !text.active) { |
||||||
|
return false; |
||||||
|
} else { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void draw(Graphics g) { |
||||||
|
if (WithinBounds((int)(text.position.getX()+x), (int)(text.position.getY()+y), emote.getImage().getWidth(), emote.getImage().getHeight())) { |
||||||
|
g.drawImage(emote.getImage(), (int)(text.refModule.getPosition().getX()+text.position.getX()+x), (int)(text.refModule.getPosition().getY()+text.position.getY()+y), sigIRC.panel); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private boolean WithinBounds(double x, double y, double w, double h) { |
||||||
|
if (x<sigIRC.panel.getWidth() && x+w>0 && y<sigIRC.panel.getHeight() && y+h>0) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean textRefIsVisible() { |
||||||
|
return text.isVisible(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,182 @@ |
|||||||
|
package sig.modules; |
||||||
|
|
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.event.KeyEvent; |
||||||
|
import java.awt.event.MouseWheelEvent; |
||||||
|
import java.awt.geom.Rectangle2D; |
||||||
|
import java.io.File; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.Calendar; |
||||||
|
import java.util.ConcurrentModificationException; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import javax.imageio.ImageIO; |
||||||
|
import javax.swing.SwingUtilities; |
||||||
|
|
||||||
|
import sig.Module; |
||||||
|
import sig.sigIRC; |
||||||
|
import sig.modules.ChatLog.ChatLogMessage; |
||||||
|
import sig.utils.FileUtils; |
||||||
|
|
||||||
|
public class ChatLogModule extends Module{ |
||||||
|
public static int messageHistoryCount = 50; |
||||||
|
public List<ChatLogMessage> messageHistory = new ArrayList<ChatLogMessage>(); |
||||||
|
int delay = 150; |
||||||
|
boolean initialized=false; |
||||||
|
public static ChatLogModule chatlogmodule; |
||||||
|
public int scrolllog_yoffset = 0; |
||||||
|
|
||||||
|
public ChatLogModule(Rectangle2D bounds, String moduleName) { |
||||||
|
super(bounds, moduleName); |
||||||
|
//Initialize();
|
||||||
|
chatlogmodule = this; |
||||||
|
} |
||||||
|
|
||||||
|
private void Initialize() { |
||||||
|
messageHistoryCount = sigIRC.chatlogMessageHistory; |
||||||
|
Calendar cal = Calendar.getInstance(); |
||||||
|
String logFileLoc = sigIRC.BASEDIR+"sigIRC/logs/log_"+(cal.get(Calendar.MONTH)+1)+"_"+cal.get(Calendar.DAY_OF_MONTH)+"_"+cal.get(Calendar.YEAR)+".txt"; |
||||||
|
File todaysLogFile = new File(logFileLoc); |
||||||
|
if (todaysLogFile.exists()) { |
||||||
|
String[] logContents = FileUtils.readFromFile(logFileLoc); |
||||||
|
if (logContents.length>messageHistoryCount) { |
||||||
|
logContents = Arrays.copyOfRange(logContents, logContents.length-messageHistoryCount-1, logContents.length); |
||||||
|
} |
||||||
|
ChatLogMessage.importMessages(logContents); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void run() { |
||||||
|
super.run(); |
||||||
|
if (delay>0) { |
||||||
|
delay--; |
||||||
|
} else |
||||||
|
if (!initialized) |
||||||
|
{ |
||||||
|
Initialize(); |
||||||
|
initialized=true; |
||||||
|
} |
||||||
|
for (int i=0; i<messageHistory.size();i++) { |
||||||
|
ChatLogMessage clm = messageHistory.get(i); |
||||||
|
if (clm!=null) { |
||||||
|
try { |
||||||
|
clm.run(); |
||||||
|
} catch (ConcurrentModificationException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void draw(Graphics g) { |
||||||
|
super.draw(g); |
||||||
|
g.setColor(new Color(195,195,195,255)); |
||||||
|
g.fill3DRect((int)position.getX(), (int)position.getY(), (int)position.getWidth(), (int)position.getHeight(), true); |
||||||
|
g.setColor(Color.BLACK); |
||||||
|
for (int i=0; i<messageHistory.size();i++) { |
||||||
|
ChatLogMessage clm = messageHistory.get(i); |
||||||
|
if (clm!=null) { |
||||||
|
try { |
||||||
|
clm.draw(g); |
||||||
|
} catch (ConcurrentModificationException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void mouseWheel(MouseWheelEvent ev) { |
||||||
|
if (mouseInBounds(ev.getX(),ev.getY())) { |
||||||
|
int scrollMult = 8; |
||||||
|
int scrollAmt = -ev.getWheelRotation()*scrollMult; |
||||||
|
if (scrollAmt>0) { |
||||||
|
if (HighestMessageIsVisible()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
if (scrolllog_yoffset+scrollAmt>0) { |
||||||
|
scrolllog_yoffset+=scrollAmt; |
||||||
|
moveAllMessages(scrollAmt); |
||||||
|
//System.out.println("Moving all messages by "+(-(ev.getWheelRotation()*scrollMult)));
|
||||||
|
} else |
||||||
|
{ |
||||||
|
//System.out.println("Cannot move beyond lower bound. Moving all messages by -"+(scrolllog_yoffset)+".");
|
||||||
|
moveAllMessages(-scrolllog_yoffset); |
||||||
|
scrolllog_yoffset=0; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private boolean HighestMessageIsVisible() { |
||||||
|
if (messageHistory.size()>0) { |
||||||
|
ChatLogMessage clm = messageHistory.get(0); |
||||||
|
return clm.isVisible(); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public void moveAllMessages(int yAmt) { |
||||||
|
for (int i=0;i<messageHistory.size();i++) { |
||||||
|
ChatLogMessage clm = messageHistory.get(i); |
||||||
|
if (clm!=null) { |
||||||
|
try { |
||||||
|
clm.position.setLocation(clm.position.getX(), clm.position.getY()+yAmt); |
||||||
|
} catch (ConcurrentModificationException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private boolean mouseInBounds(int mouseX, int mouseY) { |
||||||
|
return mouseX>=position.getX() && |
||||||
|
mouseX<=position.getX()+position.getWidth() && |
||||||
|
mouseY>=position.getX() && |
||||||
|
mouseY<=position.getX()+position.getHeight(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public void keypressed(KeyEvent ev) { |
||||||
|
int key = ev.getKeyCode(); |
||||||
|
int scroll = 0; |
||||||
|
if (key==KeyEvent.VK_PAGE_UP) { |
||||||
|
scroll=8; |
||||||
|
} else |
||||||
|
if (key==KeyEvent.VK_PAGE_DOWN) { |
||||||
|
scroll=-8; |
||||||
|
} |
||||||
|
if (key==KeyEvent.VK_HOME) { |
||||||
|
scroll=Math.abs(GetHighestMessagePosition()); |
||||||
|
} |
||||||
|
if (key==KeyEvent.VK_END) { |
||||||
|
moveAllMessages(-scrolllog_yoffset); |
||||||
|
scrolllog_yoffset=0; |
||||||
|
return; |
||||||
|
} |
||||||
|
if (scroll>0) { |
||||||
|
if (HighestMessageIsVisible()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
if (scrolllog_yoffset+scroll>0) { |
||||||
|
scrolllog_yoffset+=scroll; |
||||||
|
moveAllMessages(scroll); |
||||||
|
//System.out.println("Moving all messages by "+(-(ev.getWheelRotation()*scrollMult)));
|
||||||
|
} else |
||||||
|
{ |
||||||
|
//System.out.println("Cannot move beyond lower bound. Moving all messages by -"+(scrolllog_yoffset)+".");
|
||||||
|
moveAllMessages(-scrolllog_yoffset); |
||||||
|
scrolllog_yoffset=0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private int GetHighestMessagePosition() { |
||||||
|
if (messageHistory.size()>0) { |
||||||
|
ChatLogMessage clm = messageHistory.get(0); |
||||||
|
return (int)clm.position.getY(); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue