Before Width: | Height: | Size: 678 KiB After Width: | Height: | Size: 677 KiB |
Before Width: | Height: | Size: 678 KiB After Width: | Height: | Size: 677 KiB |
Before Width: | Height: | Size: 678 KiB After Width: | Height: | Size: 677 KiB |
Before Width: | Height: | Size: 675 KiB After Width: | Height: | Size: 675 KiB |
Before Width: | Height: | Size: 673 KiB After Width: | Height: | Size: 675 KiB |
After Width: | Height: | Size: 10 KiB |
@ -1,40 +0,0 @@ |
||||
package sig; |
||||
|
||||
import java.awt.Component; |
||||
import java.awt.GridBagConstraints; |
||||
import java.awt.GridBagLayout; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
import javax.swing.JFrame; |
||||
import javax.swing.JLabel; |
||||
import javax.swing.JPanel; |
||||
|
||||
public class AdditionalOptions extends JPanel{ |
||||
public static JFrame f = new JFrame(); |
||||
static GridBagConstraints g = new GridBagConstraints(); |
||||
AdditionalOptions() throws IOException{ |
||||
f = new JFrame(); |
||||
f.setIconImage(ImageIO.read(new File("cross.png"))); |
||||
f.setTitle("DivaBot - Additional Options"); |
||||
this.setLayout(new GridBagLayout()); |
||||
g.anchor=GridBagConstraints.EAST; |
||||
addComponent(1,1,5,1,new JLabel("Show Twitch Overlay Auto-Hotkey")); |
||||
addComponent(1,3,5,1,new JLabel("Hide Twitch Overlay Auto-Hotkey")); |
||||
|
||||
addComponent(1,2,12,1,new JLabel(" ")); |
||||
f.add(this); |
||||
f.pack(); |
||||
f.setResizable(false); |
||||
f.setVisible(true); |
||||
} |
||||
private Component addComponent(int x, int y, int w, int h,Component component) { |
||||
g.gridx=x; |
||||
g.gridy=y; |
||||
g.gridwidth=w; |
||||
g.gridheight=h; |
||||
this.add(component,g); |
||||
return component; |
||||
} |
||||
} |
@ -0,0 +1,196 @@ |
||||
package sig; |
||||
|
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
import java.awt.Dimension; |
||||
import java.awt.Font; |
||||
import java.awt.GridBagConstraints; |
||||
import java.awt.GridBagLayout; |
||||
import java.awt.Rectangle; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
import java.awt.event.MouseEvent; |
||||
import java.awt.event.MouseListener; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.net.URLEncoder; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.util.HashMap; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
import javax.swing.JButton; |
||||
import javax.swing.JComboBox; |
||||
import javax.swing.JFrame; |
||||
import javax.swing.JLabel; |
||||
import javax.swing.JList; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.ListCellRenderer; |
||||
|
||||
import org.json.JSONException; |
||||
import org.json.JSONObject; |
||||
|
||||
import sig.DisplayManager.FontRenderer; |
||||
import sig.utils.FileUtils; |
||||
|
||||
public class ReloadSong extends JPanel implements ItemListener,MouseListener{ |
||||
public static JFrame f = new JFrame(); |
||||
public static HashMap<String,JSONObject> SONGARRAY = new HashMap<>(); |
||||
public static JComboBox<JSONObject> songs; |
||||
static GridBagConstraints g = new GridBagConstraints(); |
||||
ReloadSong() throws IOException{ |
||||
JSONObject obj = FileUtils.readJsonFromUrl("http://projectdivar.com/songs"); |
||||
|
||||
for (String s : JSONObject.getNames(obj)) { |
||||
JSONObject songdata = obj.getJSONObject(s); |
||||
SONGARRAY.put(songdata.getString("name"),songdata); |
||||
} |
||||
|
||||
f = new JFrame(); |
||||
f.setIconImage(ImageIO.read(new File("cross.png"))); |
||||
f.setTitle("DivaBot - Reload Song"); |
||||
this.setLayout(new GridBagLayout()); |
||||
g.anchor=GridBagConstraints.EAST; |
||||
addComponent(1,1,2,1,new JLabel("Select correct song:")); |
||||
|
||||
JSONObject[] songList = new JSONObject[SONGARRAY.size()]; |
||||
int count = 0; |
||||
for (String s : SONGARRAY.keySet()) { |
||||
songList[count++]=SONGARRAY.get(s); |
||||
} |
||||
|
||||
for (int i = 0; i < count; i++) |
||||
{ |
||||
for (int j = i + 1; j < count; j++) { |
||||
if (songList[i].getString("english_name").toLowerCase().compareTo(songList[j].getString("english_name").toLowerCase())>0) |
||||
{ |
||||
JSONObject temp = songList[i]; |
||||
songList[i] = songList[j]; |
||||
songList[j] = temp; |
||||
} |
||||
} |
||||
} |
||||
|
||||
songs = new JComboBox(songList) { |
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
return new Dimension(600,40); |
||||
} |
||||
}; |
||||
songs.setRenderer(new SongRenderer()); |
||||
songs.setMaximumRowCount(12); |
||||
songs.addItemListener(this); |
||||
|
||||
JButton submit = new JButton("Recalibrate Song") { |
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
return new Dimension(600,40); |
||||
} |
||||
}; |
||||
|
||||
addComponent(3,1,10,1,songs); |
||||
addComponent(1,4,12,1,submit); |
||||
|
||||
submit.addMouseListener(this); |
||||
|
||||
addComponent(1,2,12,1,new JLabel(" ")); |
||||
addComponent(1,3,12,1,new JLabel(" ")); |
||||
f.add(this); |
||||
f.pack(); |
||||
f.setResizable(false); |
||||
f.setVisible(true); |
||||
} |
||||
private Component addComponent(int x, int y, int w, int h,Component component) { |
||||
g.gridx=x; |
||||
g.gridy=y; |
||||
g.gridwidth=w; |
||||
g.gridheight=h; |
||||
this.add(component,g); |
||||
return component; |
||||
} |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
// TODO Auto-generated method stub
|
||||
|
||||
} |
||||
class SongRenderer extends JLabel |
||||
implements ListCellRenderer { |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
return new Dimension(300,40); |
||||
} |
||||
|
||||
@Override |
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, |
||||
boolean cellHasFocus) { |
||||
JSONObject selectedSong = ((JSONObject)value); |
||||
|
||||
if (isSelected) { |
||||
setBackground(list.getSelectionBackground()); |
||||
setForeground(list.getSelectionForeground()); |
||||
} else { |
||||
setBackground(list.getBackground()); |
||||
setForeground(list.getForeground()); |
||||
} |
||||
setText(selectedSong.getString("english_name") |
||||
+" - " |
||||
+((selectedSong.getString("romanized_name").length()>0)? |
||||
(!selectedSong.getString("romanized_name").equalsIgnoreCase(selectedSong.getString("name")))? |
||||
selectedSong.getString("romanized_name")+"("+selectedSong.getString("name")+")":"":selectedSong.getString("name"))); |
||||
return this; |
||||
} |
||||
|
||||
} |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
// TODO Auto-generated method stub
|
||||
|
||||
} |
||||
@Override |
||||
public void mousePressed(MouseEvent e) { |
||||
BufferedImage img = null; |
||||
try { |
||||
ImageIO.write(img=MyRobot.MYROBOT.createScreenCapture(new Rectangle(630,80,580,380)),"png",new File("test.png")); |
||||
} catch (IOException e1) { |
||||
e1.printStackTrace(); |
||||
} |
||||
long totalr=0; |
||||
long totalg=0; |
||||
long totalb=0; |
||||
for (int i=0;i<580;i++) { |
||||
for (int j=0;j<380;j++) { |
||||
totalr+=Math.pow(new Color(img.getRGB(i,j),true).getRed(),2); |
||||
totalg+=Math.pow(new Color(img.getRGB(i,j),true).getGreen(),2); |
||||
totalb+=Math.pow(new Color(img.getRGB(i,j),true).getBlue(),2); |
||||
} |
||||
} |
||||
try { |
||||
SongData.saveSongToFile(((JSONObject)songs.getSelectedItem()).getString("name"),totalr,totalg,totalb); |
||||
} catch (JSONException | IOException e2) { |
||||
e2.printStackTrace(); |
||||
} |
||||
try { |
||||
SongData.loadSongsFromFile(); |
||||
} catch (IOException e1) { |
||||
e1.printStackTrace(); |
||||
} |
||||
f.setVisible(false); |
||||
} |
||||
@Override |
||||
public void mouseReleased(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
|
||||
|
||||
} |
||||
} |
||||
|
Before Width: | Height: | Size: 537 KiB After Width: | Height: | Size: 506 KiB |