Setup basic module display / toggling. Setup module window and event
listeners.
This commit is contained in:
parent
629f118e7c
commit
e210299f7f
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry excluding="resources/" kind="src" path="lib"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="lib" path="lib/commons-io-2.5.jar"/>
|
||||
<classpathentry kind="lib" path="lib/twitch-api-wrapper-0.3-jar-with-dependencies.jar"/>
|
||||
|
BIN
sigIRCv2.jar
BIN
sigIRCv2.jar
Binary file not shown.
@ -4,25 +4,37 @@ import java.awt.Cursor;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import sig.utils.DrawUtils;
|
||||
import sig.utils.TextUtils;
|
||||
import sig.windows.ProgramWindow;
|
||||
|
||||
public class Module extends JFrame{
|
||||
public class Module extends JFrame implements MouseListener, MouseWheelListener, KeyListener, ComponentListener, WindowListener{
|
||||
public JPanel panel;
|
||||
public Rectangle position;
|
||||
protected boolean enabled;
|
||||
@ -37,18 +49,33 @@ public class Module extends JFrame{
|
||||
boolean dragging=false;
|
||||
public static boolean DRAGGING=false;
|
||||
public Graphics myGraphics;
|
||||
|
||||
long lasttime = System.currentTimeMillis();
|
||||
float avgfps = sigIRC.framerate;
|
||||
int counter = 0;
|
||||
int avgcount = 10;
|
||||
int[] sum = new int[10];
|
||||
int windowUpdateCounter = 30;
|
||||
|
||||
public Module(Rectangle bounds, String moduleName) {
|
||||
|
||||
this.addMouseListener(this);
|
||||
this.addMouseWheelListener(this);
|
||||
this.addKeyListener(this);
|
||||
this.addComponentListener(this);
|
||||
this.addWindowListener(this);
|
||||
|
||||
this.position = bounds;
|
||||
this.name = moduleName;
|
||||
this.enabled=true;
|
||||
this.setVisible(true);
|
||||
this.setTitle(moduleName);
|
||||
panel = new JPanel(){
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
draw(g);
|
||||
}
|
||||
};
|
||||
this.setLocation((int)position.getX(), (int)position.getY());
|
||||
|
||||
this.titleHeight = (int)TextUtils.calculateStringBoundsFont(this.name, sigIRC.userFont).getHeight();
|
||||
|
||||
@ -59,8 +86,10 @@ public class Module extends JFrame{
|
||||
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
scheduler.scheduleWithFixedDelay(()->{
|
||||
updateFPSCounter();
|
||||
run();
|
||||
panel.repaint();
|
||||
},(long)((1d/sigIRC.framerate)*1000),(long)((1d/sigIRC.framerate)*1000),TimeUnit.MILLISECONDS);
|
||||
},(long)((1d/(sigIRC.framerate+1))*1000),(long)((1d/(sigIRC.framerate+1))*1000),TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public Module(Rectangle bounds, String moduleName, boolean enabled) {
|
||||
@ -68,26 +97,22 @@ public class Module extends JFrame{
|
||||
this.enabled=enabled;
|
||||
}
|
||||
|
||||
protected void mouseModuleMousePress(MouseEvent ev) {
|
||||
int mouseX = ev.getX();
|
||||
int mouseY = ev.getY();
|
||||
//System.out.println(mouseX + "," + mouseY);
|
||||
enableWindowDrag(mouseX,mouseY);
|
||||
mousePressed(ev);
|
||||
|
||||
|
||||
public void updateFPSCounter() {
|
||||
float val = 1000f/(System.currentTimeMillis()-lasttime);
|
||||
sum[counter++ % sum.length] = (int)val;
|
||||
avgfps = (float)sum(sum)/sum.length;
|
||||
this.setTitle(name+" - "+(int)Math.round(avgfps)+" FPS");
|
||||
lasttime=System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private void enableWindowDrag(int mouseX, int mouseY) {
|
||||
if (!sigIRC.overlayMode && !dragging && inDragBounds(mouseX,mouseY) && !DRAGGING) {
|
||||
//Enable dragging.
|
||||
dragOffset = new Point((int)position.getX() - mouseX,(int)position.getY()-mouseY);
|
||||
dragging=DRAGGING=true;
|
||||
private int sum(int[] array) {
|
||||
int val = 0;
|
||||
for (int i=0;i<array.length;i++) {
|
||||
val+=array[i];
|
||||
}
|
||||
}
|
||||
|
||||
public boolean inDragBounds(int x, int y) {
|
||||
return x>=position.getX() && x<=position.getX()+position.getWidth() &&
|
||||
y>=(int)position.getY()-Module.IMG_DRAGBAR.getHeight() &&
|
||||
y<=(int)position.getY();
|
||||
return val;
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent ev) {
|
||||
@ -101,52 +126,11 @@ public class Module extends JFrame{
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent ev) {
|
||||
if (dragging) {
|
||||
dragging=DRAGGING=false;
|
||||
ApplyConfigWindowProperties();
|
||||
sigIRC.config.saveProperties();
|
||||
}
|
||||
}
|
||||
|
||||
protected void moduleRun() {
|
||||
dragWindow();
|
||||
modifyCursor();
|
||||
run();
|
||||
}
|
||||
|
||||
private void modifyCursor() {
|
||||
if (!sigIRC.overlayMode) {
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (inDragZone &&
|
||||
cursortype!=Cursor.MOVE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.MOVE_CURSOR));
|
||||
} else
|
||||
if (!inDragZone && cursortype!=Cursor.DEFAULT_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dragWindow() {
|
||||
if (dragging) {
|
||||
//sigIRC.panel.repaint(getDrawBounds().getBounds());
|
||||
int mouseX = sigIRC.panel.lastMouseX+(int)dragOffset.getX();
|
||||
int mouseY = sigIRC.panel.lastMouseY+(int)dragOffset.getY();
|
||||
int oldX = (int)position.getX();
|
||||
int oldY = (int)position.getY();
|
||||
position = new Rectangle((int)Math.min(Math.max(0,mouseX),sigIRC.window.getWidth()-position.getWidth()), (int)Math.min(Math.max(titleHeight,mouseY),sigIRC.window.getHeight()-position.getHeight()-titleHeight*2),(int)position.getWidth(),(int)position.getHeight());
|
||||
//System.out.println(sigIRC.panel.lastMouseX+","+sigIRC.panel.lastMouseY);
|
||||
ModuleDragEvent(oldX,oldY,mouseX,mouseY);
|
||||
}
|
||||
if (inDragBounds(sigIRC.panel.lastMouseX,sigIRC.panel.lastMouseY)) {
|
||||
inDragZone=true;
|
||||
//System.out.println("In Drag Zone for Module "+name);
|
||||
//sigIRC.panel.setCursor(new Cursor(Cursor.MOVE_CURSOR));
|
||||
} /*else
|
||||
if (sigIRC.panel.getCursor().getType()==Cursor.MOVE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}*/
|
||||
}
|
||||
|
||||
public Rectangle2D getPosition() {
|
||||
return position;
|
||||
@ -156,27 +140,8 @@ public class Module extends JFrame{
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
g.fillRect(0, 0, (int)position.getWidth(), (int)position.getHeight());
|
||||
DrawUtils.drawText(g, 0, 16, Color.WHITE, "Test");
|
||||
System.out.println("Test");
|
||||
}
|
||||
|
||||
private void drawModuleHeader(Graphics g) {
|
||||
if (!sigIRC.overlayMode) {
|
||||
g.drawImage(Module.IMG_DRAGBAR,
|
||||
(int)position.getX()+2,
|
||||
(int)position.getY()-Module.IMG_DRAGBAR.getHeight(),
|
||||
(int)position.getWidth()-4,
|
||||
Module.IMG_DRAGBAR.getHeight(),
|
||||
sigIRC.panel);
|
||||
DrawUtils.drawTextFont(g, sigIRC.smallFont, (int)position.getX(), (int)position.getY()-titleHeight/2+4, Color.BLACK, this.name);
|
||||
//g.fillRect((int)position.getX(), (int)position.getY(), (int)position.getWidth(), (int)position.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
private Rectangle2D getDrawBounds() {
|
||||
Rectangle2D drawBounds = new Rectangle((int)position.getX()-2,(int)position.getY()-titleHeight+3-1,(int)position.getWidth()+2,(int)position.getHeight()+titleHeight+1);
|
||||
return drawBounds;
|
||||
//g.fillRect(0, 0, (int)position.getWidth(), (int)position.getHeight());
|
||||
//DrawUtils.drawText(g, 0, 16, Color.WHITE, "Test");
|
||||
}
|
||||
|
||||
public void ModuleDragEvent(int oldX, int oldY, int newX, int newY) {
|
||||
@ -196,4 +161,111 @@ public class Module extends JFrame{
|
||||
public void windowClosed(WindowEvent ev) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowActivated(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeiconified(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowIconified(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowOpened(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
UpdatePosition(e);
|
||||
}
|
||||
|
||||
private void UpdatePosition(ComponentEvent e) {
|
||||
position = new Rectangle((int)e.getComponent().getLocationOnScreen().getX(),(int)e.getComponent().getLocationOnScreen().getY(),e.getComponent().getWidth(),e.getComponent().getHeight()-16);
|
||||
//System.out.println(position);
|
||||
ApplyConfigWindowProperties();
|
||||
sigIRC.configNeedsUpdating = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
UpdatePosition(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
@ -33,16 +33,12 @@ import sig.modules.ChatLogModule;
|
||||
import sig.modules.ChatLog.ChatLogMessage;
|
||||
import sig.utils.FileUtils;
|
||||
|
||||
public class MyPanel extends JPanel implements MouseListener, ActionListener, MouseWheelListener, KeyListener, ComponentListener, WindowListener{
|
||||
public class MyPanel extends JPanel{
|
||||
public int lastMouseX = 0;
|
||||
public int lastMouseY = 0;
|
||||
|
||||
public MyPanel() {
|
||||
//setBorder(BorderFactory.createLineBorder(Color.black));
|
||||
addMouseListener(this);
|
||||
addMouseWheelListener(this);
|
||||
addComponentListener(this);
|
||||
addKeyListener(this);
|
||||
setFocusable(true);
|
||||
}
|
||||
|
||||
@ -114,71 +110,6 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo
|
||||
//ChatLogMessage.importMessages(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent ev) {
|
||||
for (Module m : sigIRC.modules) {
|
||||
m.mouseModuleMousePress(ev);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent ev) {
|
||||
for (Module m : sigIRC.modules) {
|
||||
m.mouseReleased(ev);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent ev) {
|
||||
for (Module m : sigIRC.modules) {
|
||||
m.mouseWheel(ev);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent ev) {
|
||||
for (Module m : sigIRC.modules) {
|
||||
m.keypressed(ev);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent ev) {
|
||||
for (Module m : sigIRC.modules) {
|
||||
m.keyreleased(ev);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent ev) {
|
||||
UpdateComponent(ev.getComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent ev) {
|
||||
UpdateComponent(ev.getComponent());
|
||||
}
|
||||
|
||||
public static void UpdateComponent(Component com) {
|
||||
if (sigIRC.window!=null && sigIRC.window.getLocationOnScreen()!=null) {
|
||||
sigIRC.windowX = (int)sigIRC.window.getLocationOnScreen().getX();
|
||||
@ -194,51 +125,4 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo
|
||||
sigIRC.config.saveProperties();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowActivated(WindowEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosed(WindowEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
for (Module m : sigIRC.modules) {
|
||||
m.windowClosed(ev);
|
||||
}
|
||||
sigIRC.config.saveProperties();
|
||||
if (sigIRC.autoUpdateProgram==0 && !sigIRC.offlineMode && sigIRC.updateAvailable) {
|
||||
try {
|
||||
FileUtils.copyFile(new File(sigIRC.PROGRAM_UPDATE_FILE), new File(sigIRC.BASEDIR+"sigIRCv2.jar"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeiconified(WindowEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowIconified(WindowEvent ev) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowOpened(WindowEvent ev) {
|
||||
}
|
||||
}
|
||||
|
@ -198,10 +198,10 @@ public class ChatLogMessage {
|
||||
/*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()));
|
||||
(int)Math.max(position.getX(),0),
|
||||
(int)Math.max(position.getY(),0),
|
||||
(int)Math.min(sigIRC.panel.getWidth()-(position.getX()+messageDisplaySize.getX()),messageDisplaySize.getX()),
|
||||
(int)Math.min(sigIRC.panel.getHeight()-(position.getY()+messageDisplaySize.getY()),messageDisplaySize.getY()));
|
||||
}
|
||||
});*/
|
||||
//System.out.println(refModule.getPosition()+","+position);
|
||||
@ -213,14 +213,14 @@ public class ChatLogMessage {
|
||||
for (int i=0;i<displayMessage.size();i++) {
|
||||
//System.out.println(displayMessage.get(i));
|
||||
if (username!=null && i==0) {
|
||||
DrawUtils.drawOutlineText(g, sigIRC.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.userFont, refModule.getPosition().getX()+position.getX()+usernameWidth+2, refModule.getPosition().getY()+position.getY()+(i*MESSAGE_SPACING)+32, Color.BLACK, displayMessage.get(i));
|
||||
DrawUtils.drawOutlineText(g, sigIRC.userFont, position.getX(), position.getY()+(i*MESSAGE_SPACING)+32, 2, GetUserNameColor(this.username), SHADOW_COL, this.username);
|
||||
DrawUtils.drawTextFont(g, sigIRC.userFont, position.getX()+usernameWidth+2, position.getY()+(i*MESSAGE_SPACING)+32, Color.BLACK, displayMessage.get(i));
|
||||
} else {
|
||||
DrawUtils.drawTextFont(g, sigIRC.userFont, refModule.getPosition().getX()+position.getX(), refModule.getPosition().getY()+position.getY()+(i*MESSAGE_SPACING)+32, Color.BLACK, displayMessage.get(i));
|
||||
DrawUtils.drawTextFont(g, sigIRC.userFont, position.getX(), 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));
|
||||
g.drawImage(Module.MSG_SEPARATOR, (int)(position.getX()+8), (int)(position.getY()+messageDisplaySize.getY()+12), (int)(messageDisplaySize.getX()-8), 1, sigIRC.panel);
|
||||
//g.drawLine((int)(position.getX()+8), (int)(position.getY()+messageDisplaySize.getY()+32), (int)(position.getX()+messageDisplaySize.getX()-8), (int)(position.getY()+messageDisplaySize.getY()+32));
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,8 +242,8 @@ public class ChatLogMessage {
|
||||
}
|
||||
|
||||
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;
|
||||
return (position.getY()+MESSAGE_SPACING)>0 &&
|
||||
(position.getY()+messageDisplaySize.getY())<refModule.getPosition().getHeight()-16;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2,6 +2,8 @@ package sig.modules;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
@ -29,12 +31,16 @@ public class ChatLogModule extends Module{
|
||||
public static ChatLogModule chatlogmodule;
|
||||
public int scrolllog_yoffset = 0;
|
||||
public Color backgroundColor;
|
||||
long positionsNeedUpdating = 0; //Set it to System.currentTimeMillis() to request a configuration save.
|
||||
Rectangle prevpos;
|
||||
|
||||
|
||||
public ChatLogModule(Rectangle2D bounds, String moduleName) {
|
||||
public ChatLogModule(Rectangle bounds, String moduleName) {
|
||||
super(bounds, moduleName);
|
||||
//Initialize();
|
||||
chatlogmodule = this;
|
||||
backgroundColor = DrawUtils.convertStringToColor(sigIRC.chatlogmodule_backgroundColor);
|
||||
prevpos = (Rectangle)position.clone();
|
||||
}
|
||||
|
||||
private void Initialize() {
|
||||
@ -71,12 +77,20 @@ public class ChatLogModule extends Module{
|
||||
}
|
||||
}
|
||||
}
|
||||
if (positionsNeedUpdating!=0 && System.currentTimeMillis()-positionsNeedUpdating>1000) {
|
||||
positionsNeedUpdating=0;
|
||||
int diff = (int)(position.getHeight()-prevpos.getHeight());
|
||||
prevpos = (Rectangle)position.clone();
|
||||
for (ChatLogMessage clm : messageHistory) {
|
||||
clm.position.y+=diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
super.draw(g);
|
||||
g.setColor(backgroundColor);
|
||||
g.fill3DRect((int)position.getX(), (int)position.getY(), (int)position.getWidth(), (int)position.getHeight(), true);
|
||||
g.fill3DRect(0, 0, (int)position.getWidth(), (int)position.getHeight(), true);
|
||||
g.setColor(Color.BLACK);
|
||||
for (int i=0; i<messageHistory.size();i++) {
|
||||
ChatLogMessage clm = messageHistory.get(i);
|
||||
@ -93,8 +107,12 @@ public class ChatLogModule extends Module{
|
||||
public void ApplyConfigWindowProperties() {
|
||||
sigIRC.chatlogmodule_X=(int)position.getX();
|
||||
sigIRC.chatlogmodule_Y=(int)position.getY();
|
||||
sigIRC.chatlogmodule_width=(int)position.getWidth();
|
||||
sigIRC.chatlogmodule_height=(int)position.getHeight();
|
||||
sigIRC.config.setInteger("CHATLOG_module_X", sigIRC.chatlogmodule_X);
|
||||
sigIRC.config.setInteger("CHATLOG_module_Y", sigIRC.chatlogmodule_Y);
|
||||
sigIRC.config.setInteger("CHATLOG_module_width", sigIRC.chatlogmodule_width);
|
||||
sigIRC.config.setInteger("CHATLOG_module_height", sigIRC.chatlogmodule_height);
|
||||
}
|
||||
|
||||
public void mouseWheel(MouseWheelEvent ev) {
|
||||
@ -127,6 +145,11 @@ public class ChatLogModule extends Module{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
this.positionsNeedUpdating=System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void moveAllMessages(int yAmt) {
|
||||
for (int i=0;i<messageHistory.size();i++) {
|
||||
ChatLogMessage clm = messageHistory.get(i);
|
||||
|
@ -84,8 +84,8 @@ public class sigIRC{
|
||||
public static List<ChatLogTwitchEmote> chatlogtwitchemoticons = new ArrayList<ChatLogTwitchEmote>();
|
||||
public static List<CustomSound> customsounds = new ArrayList<CustomSound>();
|
||||
public static List<Module> modules = new ArrayList<Module>();
|
||||
static UpdateEvent updater = new UpdateEvent();
|
||||
static Timer programClock = new Timer(32,updater);
|
||||
//static UpdateEvent updater = new UpdateEvent();
|
||||
//static Timer programClock = new Timer(32,updater);
|
||||
final public static int BASESCROLLSPD = 4;
|
||||
final public static int ROWSEPARATION = 64;
|
||||
final public static String BASEDIR = "./";
|
||||
@ -170,6 +170,7 @@ public class sigIRC{
|
||||
public static Image programIcon;
|
||||
final public static int MAX_CONNECTION_RETRIES = 100;
|
||||
public static int retryCounter = 0;
|
||||
public static long configNeedsUpdating = 0; //Set it to System.currentTimeMillis() to request a configuration save.
|
||||
|
||||
public static int subchannelCount = 0;
|
||||
public static HashMap<Long,String> subchannelIds = new HashMap<Long,String>();
|
||||
@ -641,7 +642,7 @@ public class sigIRC{
|
||||
f.setAlwaysOnTop(true);
|
||||
}
|
||||
//f.setOpacity(0.5f);
|
||||
f.addWindowListener(sigIRC.panel);
|
||||
//f.addWindowListener(sigIRC.panel);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,9 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.BoxLayout;
|
||||
@ -27,17 +30,27 @@ import sig.ColorPanel;
|
||||
import sig.Module;
|
||||
import sig.MyPanel;
|
||||
import sig.sigIRC;
|
||||
import sig.modules.ChatLogModule;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ProgramWindow extends JFrame{
|
||||
|
||||
static Icon deselected_icon,selected_icon;
|
||||
|
||||
public static Icon deselected_icon,selected_icon;
|
||||
|
||||
List<ModuleButton> buttons = new ArrayList<ModuleButton>();
|
||||
|
||||
public ProgramWindow() {
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
scheduler.scheduleWithFixedDelay(()->{
|
||||
if (sigIRC.configNeedsUpdating>0 &&
|
||||
System.currentTimeMillis()-sigIRC.configNeedsUpdating>1000) {
|
||||
sigIRC.config.saveProperties();
|
||||
sigIRC.configNeedsUpdating=0;
|
||||
}
|
||||
},1000,1000,TimeUnit.MILLISECONDS);
|
||||
|
||||
try {
|
||||
sigIRC.programIcon = ImageIO.read(new File(sigIRC.BASEDIR+"/sigIRC/sigIRCicon.png"));
|
||||
sigIRC.programIcon = ImageIO.read(sigIRC.class.getResource("/resource/sigIRCicon.png"));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
@ -76,28 +89,28 @@ public class ProgramWindow extends JFrame{
|
||||
sigIRC.panel.add(myLabel);
|
||||
|
||||
if (!sigIRC.disableChatMessages) {
|
||||
ModuleButton button = new ModuleButton("Scrolling Chat");
|
||||
ModuleButton button = new ModuleButton("Scrolling Chat",new Module(new Rectangle(0,0,0,0),"Test"));
|
||||
sigIRC.panel.add(button);
|
||||
}
|
||||
if (sigIRC.chatlogmodule_enabled) {
|
||||
ModuleButton button = new ModuleButton("Chat Log");
|
||||
ChatLogModule mod = new ChatLogModule(new Rectangle(sigIRC.chatlogmodule_X,sigIRC.chatlogmodule_Y,sigIRC.chatlogmodule_width,sigIRC.chatlogmodule_height),"Chat Log");
|
||||
ModuleButton button = new ModuleButton("Chat Log",mod);
|
||||
sigIRC.panel.add(button);
|
||||
}
|
||||
if (sigIRC.controllermodule_enabled) {
|
||||
ModuleButton button = new ModuleButton("Controller");
|
||||
ModuleButton button = new ModuleButton("Controller",new Module(new Rectangle(0,0,0,0),"Test"));
|
||||
sigIRC.panel.add(button);
|
||||
}
|
||||
if (sigIRC.twitchmodule_enabled) {
|
||||
ModuleButton button = new ModuleButton("Twitch");
|
||||
ModuleButton button = new ModuleButton("Twitch",new Module(new Rectangle(0,0,0,0),"Test"));
|
||||
sigIRC.panel.add(button);
|
||||
}
|
||||
if (sigIRC.rabiracemodule_enabled) {
|
||||
ModuleButton button = new ModuleButton("Rabi-Race");
|
||||
ModuleButton button = new ModuleButton("Rabi-Race",new Module(new Rectangle(0,0,0,0),"Test"));
|
||||
sigIRC.panel.add(button);
|
||||
sigIRC.panel.add(new ModuleButton("Rabi-Race"));
|
||||
}
|
||||
if (sigIRC.touhoumothermodule_enabled) {
|
||||
ModuleButton button = new ModuleButton("Touhou Mother");
|
||||
ModuleButton button = new ModuleButton("Touhou Mother",new Module(new Rectangle(0,0,0,0),"Test"));
|
||||
sigIRC.panel.add(button);
|
||||
}
|
||||
GridLayout myLayout = new GridLayout(0,1);
|
||||
@ -120,26 +133,29 @@ public class ProgramWindow extends JFrame{
|
||||
this.setAlwaysOnTop(true);
|
||||
}
|
||||
//this.setOpacity(0.5f);
|
||||
this.addWindowListener(sigIRC.panel);
|
||||
//this.addWindowListener(sigIRC.panel);
|
||||
|
||||
Module testMod = new Module(new Rectangle(0,0,640,480),"Test");
|
||||
//Module testMod = new Module(new Rectangle(0,0,640,480),"Test");
|
||||
}
|
||||
}
|
||||
|
||||
class ModuleButton extends JToggleButton {
|
||||
@SuppressWarnings("serial")
|
||||
class ModuleButton extends JToggleButton{
|
||||
String label = "";
|
||||
ModuleButton button;
|
||||
public ModuleButton(String label) {
|
||||
Module myModule;
|
||||
public ModuleButton(String label, Module module) {
|
||||
this.label=label;
|
||||
this.button=this;
|
||||
this.myModule=module;
|
||||
this.setBackground(Color.DARK_GRAY);
|
||||
this.setText(label);
|
||||
this.setToolTipText("Click to enable and disable the \n"+label+" module.");
|
||||
this.setPreferredSize(new Dimension(160,56));
|
||||
this.setForeground(Color.GRAY);
|
||||
this.setIconTextGap(4);
|
||||
this.setIcon(ProgramWindow.deselected_icon);
|
||||
this.setSelectedIcon(ProgramWindow.selected_icon);
|
||||
this.setIcon(ProgramWindow.deselected_icon);
|
||||
this.setSelected(true);
|
||||
button.setForeground(Color.BLUE);
|
||||
this.addChangeListener(new ChangeListener() {
|
||||
@ -152,9 +168,9 @@ class ModuleButton extends JToggleButton {
|
||||
button.setBackground(Color.DARK_GRAY);
|
||||
button.setForeground(Color.GRAY);
|
||||
}
|
||||
myModule.setVisible(button.isSelected());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user