Smarter text/chat management. Configuration file created for easy modification of channel to view. Added ability to change background color.dev
parent
b62b02b41b
commit
109b608eeb
@ -0,0 +1,53 @@ |
||||
package sig; |
||||
|
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
import java.awt.event.MouseEvent; |
||||
import java.awt.event.MouseWheelEvent; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.util.Arrays; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
|
||||
import sig.DrawUtils; |
||||
import sig.FileUtils; |
||||
import sig.TextUtils; |
||||
import sig.sigIRC; |
||||
import sig.modules.TouhouMotherModule; |
||||
|
||||
public class BackgroundColorButton { |
||||
BufferedImage buttonimg; |
||||
int x=0; |
||||
int y=0; |
||||
boolean buttonEnabled = true; |
||||
|
||||
public BackgroundColorButton(File filename, int x, int y) { |
||||
this.x=x; |
||||
this.y=y; |
||||
try { |
||||
buttonimg = ImageIO.read(filename); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
public void draw(Graphics g) { |
||||
if (buttonEnabled) { |
||||
g.drawImage(buttonimg, x, y, sigIRC.panel); |
||||
} |
||||
} |
||||
|
||||
public void onClickEvent(MouseEvent ev) { |
||||
if (buttonEnabled) { |
||||
if (ev.getX()>=x && ev.getX()<=x+buttonimg.getWidth() && |
||||
ev.getY()>=y && ev.getY()<=y+buttonimg.getHeight()) { |
||||
sigIRC.backgroundcol=sigIRC.colorpanel.getBackgroundColor(); |
||||
sigIRC.config.setProperty("backgroundColor", Integer.toString(sigIRC.backgroundcol.getRGB())); |
||||
sigIRC.config.saveProperties(); |
||||
sigIRC.panel.setBackground(sigIRC.backgroundcol); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,21 @@ |
||||
package sig; |
||||
|
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
|
||||
import javax.swing.JColorChooser; |
||||
import javax.swing.JPanel; |
||||
|
||||
public class ColorPanel extends JPanel{ |
||||
public ColorPanel() { |
||||
|
||||
} |
||||
|
||||
public Color getBackgroundColor() { |
||||
return JColorChooser.showDialog(this, "Background Color Picker", Color.CYAN); |
||||
} |
||||
|
||||
public Dimension getPreferredSize() { |
||||
return new Dimension(640,480); |
||||
} |
||||
} |
@ -0,0 +1,93 @@ |
||||
package sig; |
||||
|
||||
import java.awt.Color; |
||||
import java.io.File; |
||||
import java.io.FileNotFoundException; |
||||
import java.io.FileReader; |
||||
import java.io.FileWriter; |
||||
import java.io.IOException; |
||||
import java.util.HashMap; |
||||
import java.util.Properties; |
||||
|
||||
public class ConfigFile { |
||||
String basepath; |
||||
Properties properties; |
||||
public static HashMap<String,String> configDefaults = new HashMap<String,String>(); |
||||
|
||||
public static void configureDefaultConfiguration() { |
||||
configDefaults.put("server", "irc.chat.twitch.tv"); |
||||
configDefaults.put("nickname", "SigoNitori"); |
||||
configDefaults.put("channel", "#sigonitori"); |
||||
configDefaults.put("dingThreshold", "6"); |
||||
configDefaults.put("backgroundColor", Integer.toString(Color.CYAN.getRGB())); |
||||
} |
||||
|
||||
public static void setAllDefaultProperties(ConfigFile conf) { |
||||
for (String key : configDefaults.keySet()) { |
||||
conf.setProperty(key, configDefaults.get(key)); |
||||
} |
||||
} |
||||
|
||||
public ConfigFile(String basepath) { |
||||
this.basepath=basepath; |
||||
properties = new Properties(); |
||||
try { |
||||
FileReader reader = GetFileReader(this.basepath); |
||||
if (reader!=null) { |
||||
properties.load(reader); |
||||
} |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
public String getProperty(String key) { |
||||
String val = properties.getProperty(key); |
||||
if (val==null) { |
||||
if (configDefaults.containsKey(key)) { |
||||
this.setProperty(key, configDefaults.get(key)); |
||||
this.saveProperties(); |
||||
return properties.getProperty(key); |
||||
} else { |
||||
return null; |
||||
} |
||||
} else { |
||||
return val; |
||||
} |
||||
} |
||||
|
||||
public void setProperty(String key, String value) { |
||||
properties.setProperty(key, value); |
||||
} |
||||
|
||||
public void saveProperties() { |
||||
try { |
||||
properties.store(GetFileWriter(basepath), "Properties file for sigIRCv2\n"); |
||||
System.out.println("Properties successfully saved."); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
private FileReader GetFileReader(String basepath) { |
||||
File file = new File(sigIRC.BASEDIR+basepath); |
||||
if (file.exists()) { |
||||
try { |
||||
return new FileReader(file); |
||||
} catch (FileNotFoundException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
private FileWriter GetFileWriter(String basepath) { |
||||
File file = new File(sigIRC.BASEDIR+basepath); |
||||
try { |
||||
return new FileWriter(file,false); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,52 @@ |
||||
package sig; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.net.MalformedURLException; |
||||
import java.net.URL; |
||||
|
||||
public class FileManager { |
||||
String fileloc; |
||||
final String serverURL = "http://45.33.13.215/sigIRCv2/"; |
||||
boolean folder=false; |
||||
|
||||
public FileManager(String location) { |
||||
this.fileloc=location; |
||||
this.folder=false; |
||||
} |
||||
|
||||
public FileManager(String location, boolean folder) { |
||||
this.fileloc=location; |
||||
this.folder=folder; |
||||
} |
||||
|
||||
public String getRelativeFileLocation() { |
||||
return fileloc; |
||||
} |
||||
|
||||
public void verifyAndFetchFileFromServer() { |
||||
File file = new File(sigIRC.BASEDIR+fileloc); |
||||
if (folder) { |
||||
if (!file.exists()) { |
||||
System.out.println("Could not find "+file.getAbsolutePath()+", creating Folder "+file.getName()+"."); |
||||
if (file.mkdirs()) { |
||||
System.out.println(" >> Successfully created "+file.getAbsolutePath()+"."); |
||||
} |
||||
} |
||||
} else { |
||||
if (!file.exists()) { |
||||
System.out.println("Could not find "+file.getAbsolutePath()+", retrieving file online from "+serverURL+file.getName()+"."); |
||||
try { |
||||
org.apache.commons.io.FileUtils.copyURLToFile(new URL(serverURL+fileloc),file); |
||||
if (file.exists()) { |
||||
System.out.println(" >> Successfully downloaded "+file.getAbsolutePath()+"."); |
||||
} |
||||
} catch (MalformedURLException e) { |
||||
e.printStackTrace(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue