Created
February 2, 2014 15:29
-
-
Save firstspring1845/8769971 to your computer and use it in GitHub Desktop.
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
package net.firstspring.javatter.plugin; | |
import java.awt.Image; | |
import java.io.File; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Random; | |
import javax.imageio.ImageIO; | |
import javax.swing.ImageIcon; | |
import javax.swing.JLabel; | |
import javax.swing.JPanel; | |
import twitter4j.Status; | |
import com.orekyuu.javatter.plugin.JavatterPlugin; | |
import com.orekyuu.javatter.plugin.TweetObjectBuilder; | |
/* | |
* ガシャーンガシャーン | |
* アイコンを変えるやつだよ | |
* TLのアイコンを用意した奴にランダムで変えてくれるすごいやつだよ | |
*/ | |
public class IconChanger extends JavatterPlugin { | |
@Override | |
public void init() { | |
this.addTweetObjectBuider(new TweetObjectBuilder(){ | |
Random r = new Random(); | |
Map<Integer,Map<String,ImageIcon>> m = new HashMap<>(); | |
Map<String,ImageIcon> getMap(Integer size){ | |
if(!m.containsKey(size)){ | |
m.put(size, new HashMap<String,ImageIcon>()); | |
} | |
return m.get(size); | |
} | |
ImageIcon getImage(String sn, int size){ | |
if(getMap(size).containsKey(sn)){ | |
return getMap(size).get(sn); | |
} | |
try { | |
File[] files = new File(getSaveDir(), "img").listFiles(); | |
ImageIcon icon = new ImageIcon(ImageIO.read(files[r.nextInt(files.length)]).getScaledInstance(size, size, Image.SCALE_AREA_AVERAGING)); | |
getMap(size).put(sn, icon); | |
return icon; | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return new ImageIcon(); | |
} | |
} | |
@Override | |
public void createdButtonPanel(JPanel panel, Status status) { | |
} | |
@Override | |
public void createdTextAreaPanel(JPanel panel, Status status) { | |
} | |
@Override | |
public void createdImagePanel(JPanel panel, Status status) { | |
JLabel l = (JLabel)panel.getComponent(0); | |
if(status.isRetweet()){ | |
l.setIcon(getImage(status.getRetweetedStatus().getUser().getScreenName(), 48)); | |
JLabel rt = (JLabel)panel.getComponent(1); | |
rt.setIcon(getImage(status.getUser().getScreenName(), 30)); | |
}else{ | |
l.setIcon(getImage(status.getUser().getScreenName(), 48)); | |
} | |
} | |
@Override | |
public void createdObjectPanel(JPanel panel, Status status) { | |
} | |
}); | |
} | |
@Override | |
public String getPluginName() { | |
return "アイコンを変えるやつ"; | |
} | |
@Override | |
public String getVersion() { | |
return "#1"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment