Implemented full features and integration of Displays with the

DisplayManager form.
secondmonitor
sigonasr2 5 years ago
parent f8f6cabf06
commit 4d76f9db12
  1. 13
      DivaBot/config.txt
  2. 186
      DivaBot/src/sig/Display.java
  3. 271
      DivaBot/src/sig/DisplayManager.java
  4. 142
      DivaBot/src/sig/DrawCanvas.java
  5. 8
      DivaBot/src/sig/ListTransferHandler.java
  6. 2
      DivaBot/src/sig/MyRobot.java

@ -1,3 +1,10 @@
WIDTH 546
HEIGHT 384
BACKGROUND -10092442
LAST_HEIGHT 48
WIDTH 1071
HEIGHT 765
BACKGROUND -6697729
LAST_TEXT -6723841
LAST_FONT Serif.italic
LAST_FONTSIZE 32
LAST_BACKGROUND -16776961
LAST_WIDTH 200
LAST_DELAY 10000

@ -0,0 +1,186 @@
package sig;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.HashMap;
public class Display {
Color backgroundCol=Color.BLUE;
Color textCol=Color.WHITE;
Font font=new Font("Batang",Font.PLAIN,32);
int fontSize=32;
int x;
int y;
int width=200;
int height=48;
int delay=10000;
String[] labels;
String currentText;
int cycle=0;
boolean deleted=false;
Display() {
HashMap<String,String> config = MyRobot.p.configData;
if (config.containsKey("LAST_BACKGROUND")) {
try {
backgroundCol=new Color(Integer.parseInt(config.get("LAST_BACKGROUND")));
} catch (NumberFormatException e) {
backgroundCol=Color.BLUE;
}
}
if (config.containsKey("LAST_TEXT")) {
try {
textCol=new Color(Integer.parseInt(config.get("LAST_TEXT")));
} catch (NumberFormatException e) {
textCol=Color.WHITE;
}
}
if (config.containsKey("LAST_WIDTH")) {
try {
width=Integer.parseInt(config.get("LAST_WIDTH"));
} catch (NumberFormatException e) {
width=200;
}
}
if (config.containsKey("LAST_HEIGHT")) {
try {
height=Integer.parseInt(config.get("LAST_HEIGHT"));
} catch (NumberFormatException e) {
height=48;
}
}
x=0;
y=0;
if (config.containsKey("LAST_DELAY")) {
try {
delay=Integer.parseInt(config.get("LAST_DELAY"));
} catch (NumberFormatException e) {
delay=10000;
}
}
cycle=0;
if (config.containsKey("LAST_FONTSIZE")) {
try {
fontSize=Integer.parseInt(config.get("LAST_FONTSIZE"));
} catch (NumberFormatException e) {
fontSize=32;
}
}
if (config.containsKey("LAST_FONT")) {
try {
font = new Font(config.get("LAST_FONT"),Font.PLAIN,fontSize);
} catch (NumberFormatException e) {
font = new Font("Batang",Font.PLAIN,fontSize);
}
}
labels = new String[]{"Add a label!"};
currentText=interpretLabel(labels[cycle]);
Thread t = new Thread() {
public void run() {
try {
while (!deleted) {
AdvanceCycle();
MyRobot.p.repaint();
Thread.sleep(delay);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void AdvanceCycle() {
cycle=(cycle+1)%labels.length;
currentText=interpretLabel(labels[cycle]);
}
};
t.start();
}
public void draw(Graphics g) {
g.setColor(backgroundCol);
g.fill3DRect(x, y, width, height, true);
g.setColor(textCol);
g.setFont(font);
g.drawString(currentText,x,y+fontSize);
}
private String interpretLabel(String string){
DrawCanvas data = MyRobot.p;
try {
switch (string) {
case "Best Play":{
if (data.bestPlayTime>System.currentTimeMillis()-10000) {
return "New Record!";
} else {
return ((data.bestPlay!=null)?data.bestPlay.display():"");
}
}
case "Overall Rating":{
if (data.ratingTime>System.currentTimeMillis()-10000) {
return "Rating up! "+data.lastRating+" -> "+data.overallrating;
} else {
return Integer.toString(data.overallrating);
}
}
case "Song Difficulty":{
return data.difficultyRating + " - " + fullNameDifficulty(data.difficulty);
}
case "Song Title (Japanese)":{
return data.songname + " by "+data.artist;
}
case "Song Title (Romanized)":{
return ((data.romanizedname.length()>0)?data.romanizedname:data.englishname) + " by "+data.artist;
}
case "Song Title (Japanese+Romanized)":{
return (data.songname + " - " + ((data.romanizedname.length()>0)?data.romanizedname:data.englishname)) + " by "+data.artist;
}
case "Song Title (English)":{
return data.englishname + " by "+data.artist;
}
case "Song Title (Japanese+Romanized+ENG)":{
return (data.songname + " - " + ((data.romanizedname.length()>0)?(data.romanizedname.equalsIgnoreCase(data.englishname))?data.romanizedname:data.romanizedname+" ("+data.englishname+")":data.englishname)) + " by "+data.artist;
}
case "Play Count":{
return Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":"");
}
case "Pass/Play Count":{
return Integer.toString(data.passes) + "/" + Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":"");
}
case "Pass/Play Count (+%)":{
return (data.passes)+"/"+(data.plays)+" play"+((data.plays!=1)?"s":"")+" "+"("+((int)(Math.floor(((float)data.passes)/data.plays*100)))+"% pass rate)";
}
case "FC Count":{
return data.fcCount +" FC"+(data.fcCount==1?"":"s");
}
case "FC Count (+%)":{
return data.fcCount +" FC"+(data.fcCount==1?"":"s")+" "+((int)(Math.floor(((float)data.fcCount)/data.plays*100)))+"% FC rate";
}
default:{
return string;
}
}
} catch(NullPointerException e) {
return string;
}
}
private String fullNameDifficulty(String difficulty) {
switch (difficulty) {
case "E":{
return "Easy";
}
case "N":{
return "Normal";
}
case "H":{
return "Hard";
}
case "EX":{
return "Extreme";
}
case "EXEX":{
return "Extra Extreme";
}
}
return "";
}
}

@ -9,6 +9,8 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
@ -30,36 +32,42 @@ import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.BadLocationException;
public class DisplayManager extends JPanel implements MouseListener,ListSelectionListener{
JFrame f = new JFrame();
GridBagConstraints g = new GridBagConstraints();
Font[] fontList = null;
ColorButton colorButton;
ColorButton colorButton2;
JTextField fontSizeInput;
JTextField widthInput;
JTextField heightInput;
JTextField delayInput;
DefaultListModel model = new DefaultListModel();
DefaultListModel model2 = new DefaultListModel();
public class DisplayManager extends JPanel implements MouseListener,ListSelectionListener,ItemListener{
public static JFrame f = new JFrame();
static GridBagConstraints g = new GridBagConstraints();
static Font[] fontList = null;
static ColorButton colorButton;
static ColorButton colorButton2;
static JTextField fontSizeInput;
static JTextField widthInput;
static JTextField heightInput;
static JTextField delayInput;
static DefaultListModel model = new DefaultListModel();
static DefaultListModel model2 = new DefaultListModel();
static JComboBox fonts;
JList labels = new JList(model);
JList displayedLabels = new JList(model2);
String[] AVAILABLELABELS = new String[] {
public static Display selectedDisplay;
static String[] AVAILABLELABELS = new String[] {
"Best Play",
"Overall Rating",
"Song Difficulty",
"Song Title (Japanese)",
"Song Title (Romanized)",
"Song Title (Japanese+Romanized)",
"Song Title (English)",
"Play",
"Play/Pass Count (+%)",
"Play/Pass Count (+%)",
"Song Title (Japanese+Romanized+ENG)",
"Play Count",
"Pass/Play Count",
"Pass/Play Count (+%)",
"FC Count",
"FC/Play Count",
"FC/Play Count (+%)"
"FC Count (+%)"
};
DisplayManager() throws IOException {
@ -70,8 +78,9 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio
List<Font> tempFontList = new ArrayList(Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()));
for (int i=0;i<tempFontList.size();i++) {
//System.out.println(tempFontList.get(i));
if (!tempFontList.get(i).canDisplay(12479) || tempFontList.get(i).getFontName().equals("Dialog.plain")) {
tempFontList.remove(i);
tempFontList.remove(i--);
}
}
@ -81,26 +90,85 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio
g.anchor=GridBagConstraints.EAST;
addComponent(1,1,3,1,new JLabel("Background Color"));
g.anchor=GridBagConstraints.WEST;
colorButton = (ColorButton)addComponent(4,1,4,1,new ColorButton("Color"));
JComboBox fonts = new JComboBox(fontList) {
colorButton = (ColorButton)addComponent(4,1,4,1,new ColorButton("Color","background"));
fonts = new JComboBox(fontList) {
@Override
public Dimension getPreferredSize() {
return new Dimension(300,40);
}
};
if (MyRobot.p.configData.containsKey("LAST_BACKGROUND")) {
colorButton.setBackground(new Color(Integer.parseInt(MyRobot.p.configData.get("LAST_BACKGROUND"))));
}
addComponent(9,1,2,1,new JLabel(" "));
fonts.setRenderer(new FontRenderer());
fonts.setMaximumRowCount(5);
fonts.addItemListener(this);
g.anchor=GridBagConstraints.EAST;
addComponent(1,3,3,1,new JLabel("Font"));
g.anchor=GridBagConstraints.WEST;
addComponent(4,3,4,1,fonts);
if (MyRobot.p.configData.containsKey("LAST_FONT")) {
for (int i=0;i<fontList.length;i++) {
if (MyRobot.p.configData.get("LAST_FONT").equals(fontList[i].getFontName())) {
fonts.setSelectedItem(fontList[i]);
break;
}
}
//fonts.setSelectedItem(new Font(MyRobot.p.configData.get("LAST_FONT"),Font.PLAIN,32));
}
g.anchor=GridBagConstraints.EAST;
addComponent(1,5,3,1,new JLabel("Font Color"));
g.anchor=GridBagConstraints.WEST;
colorButton = (ColorButton)addComponent(4,5,4,1,new ColorButton("Color"));
colorButton2 = (ColorButton)addComponent(4,5,2,1,new ColorButton("Color","foreground"));
colorButton2.setColor(Color.WHITE);
if (MyRobot.p.configData.containsKey("LAST_TEXT")) {
colorButton.setBackground(new Color(Integer.parseInt(MyRobot.p.configData.get("LAST_TEXT"))));
}
g.anchor=GridBagConstraints.EAST;
addComponent(7,5,1,1,new JLabel("Size"));
g.anchor=GridBagConstraints.WEST;
fontSizeInput = (JTextField)addComponent(8,5,1,1,new JTextField() {
@Override
public Dimension getPreferredSize() {
return new Dimension(50,20);
}
});
if (MyRobot.p.configData.containsKey("LAST_FONTSIZE")) {
fontSizeInput.setText(MyRobot.p.configData.get("LAST_FONTSIZE"));
}
fontSizeInput.getDocument().addDocumentListener(new DocumentListener() {
void updateField(JTextField c, DocumentEvent e) {
try {
selectedDisplay.font=new Font(selectedDisplay.font.getFontName(),Font.PLAIN,Integer.parseInt(e.getDocument().getText(0, e.getDocument().getLength())));
selectedDisplay.fontSize=Integer.parseInt(e.getDocument().getText(0, e.getDocument().getLength()));
MyRobot.p.repaint();
c.setBackground(Color.WHITE);
} catch (NullPointerException | NumberFormatException | BadLocationException e1) {
c.setBackground(Color.RED);
}
}
@Override
public void insertUpdate(DocumentEvent e) {
updateField(fontSizeInput,e);
}
@Override
public void removeUpdate(DocumentEvent e) {
updateField(fontSizeInput,e);
}
@Override
public void changedUpdate(DocumentEvent e) {
}
});
//addComponent(1,5,3,1,new JLabel("Font Color"));
g.anchor=GridBagConstraints.EAST;
addComponent(1,7,1,1,new JLabel("Width"));
addComponent(2,7,1,1,new JLabel("Width"));
g.anchor=GridBagConstraints.WEST;
widthInput = (JTextField)addComponent(3,7,1,1,new JTextField() {
@Override
@ -108,6 +176,36 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio
return new Dimension(50,20);
}
});
if (MyRobot.p.configData.containsKey("LAST_WIDTH")) {
widthInput.setText(MyRobot.p.configData.get("LAST_WIDTH"));
}
widthInput.getDocument().addDocumentListener(new DocumentListener() {
void updateField(JTextField c, DocumentEvent e) {
try {
selectedDisplay.width=Integer.parseInt(e.getDocument().getText(0, e.getDocument().getLength()));
MyRobot.p.repaint();
c.setBackground(Color.WHITE);
} catch (NullPointerException | NumberFormatException | BadLocationException e1) {
c.setBackground(Color.RED);
}
}
@Override
public void insertUpdate(DocumentEvent e) {
updateField(widthInput,e);
}
@Override
public void removeUpdate(DocumentEvent e) {
updateField(widthInput,e);
}
@Override
public void changedUpdate(DocumentEvent e) {
}
});
g.anchor=GridBagConstraints.EAST;
addComponent(4,7,2,1,new JLabel("Height"));
g.anchor=GridBagConstraints.WEST;
@ -117,6 +215,36 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio
return new Dimension(50,20);
}
});
if (MyRobot.p.configData.containsKey("LAST_HEIGHT")) {
heightInput.setText(MyRobot.p.configData.get("LAST_HEIGHT"));
}
heightInput.getDocument().addDocumentListener(new DocumentListener() {
void updateField(JTextField c, DocumentEvent e) {
try {
selectedDisplay.height=Integer.parseInt(e.getDocument().getText(0, e.getDocument().getLength()));
MyRobot.p.repaint();
c.setBackground(Color.WHITE);
} catch (NullPointerException | NumberFormatException | BadLocationException e1) {
c.setBackground(Color.RED);
}
}
@Override
public void insertUpdate(DocumentEvent e) {
updateField(heightInput,e);
}
@Override
public void removeUpdate(DocumentEvent e) {
updateField(heightInput,e);
}
@Override
public void changedUpdate(DocumentEvent e) {
}
});
g.anchor=GridBagConstraints.WEST;
addComponent(1,10,6,1,new JLabel(" "));
g.anchor=GridBagConstraints.WEST;
@ -126,6 +254,36 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio
return new Dimension(50,20);
}
});
delayInput.getDocument().addDocumentListener(new DocumentListener() {
void updateField(JTextField c, DocumentEvent e) {
try {
selectedDisplay.delay=Integer.parseInt(e.getDocument().getText(0, e.getDocument().getLength()));
MyRobot.p.repaint();
c.setBackground(Color.WHITE);
} catch (NullPointerException | NumberFormatException | BadLocationException e1) {
c.setBackground(Color.RED);
}
}
@Override
public void insertUpdate(DocumentEvent e) {
updateField(delayInput,e);
}
@Override
public void removeUpdate(DocumentEvent e) {
updateField(delayInput,e);
}
@Override
public void changedUpdate(DocumentEvent e) {
}
});
if (MyRobot.p.configData.containsKey("LAST_DELAY")) {
delayInput.setText(MyRobot.p.configData.get("LAST_DELAY"));
}
g.anchor=GridBagConstraints.WEST;
addComponent(6,10,1,1,new JLabel("ms"));
@ -170,12 +328,13 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio
addComponent(7,12,2,1,new JLabel("Active Labels:"));
widthInput.setText("200");
heightInput.setText("200");
heightInput.setText("48");
fontSizeInput.setText("32");
delayInput.setText("10000");
f.add(this);
f.pack();
f.setResizable(false);
//f.setVisible(true);
f.setVisible(false);
}
private Component addComponent(int x, int y, int w, int h,Component component) {
g.gridx=x;
@ -185,6 +344,46 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio
this.add(component,g);
return component;
}
public static void setupSettings(Display d) {
selectedDisplay=d;
colorButton.setBackground(d.backgroundCol);
MyRobot.p.configData.put("LAST_BACKGROUND",Integer.toString(d.backgroundCol.getRGB()));
colorButton2.setBackground(d.textCol);
MyRobot.p.configData.put("LAST_TEXT",Integer.toString(d.textCol.getRGB()));
for (int i=0;i<fonts.getItemCount();i++) {
if (d.font.getFontName().equals(((Font)(fonts.getItemAt(i))).getFontName())) {
fonts.setSelectedItem(fonts.getItemAt(i));
break;
}
}
MyRobot.p.configData.put("LAST_FONT",d.font.getFontName());
widthInput.setText(Integer.toString(d.width));
MyRobot.p.configData.put("LAST_WIDTH",Integer.toString(d.width));
heightInput.setText(Integer.toString(d.height));
MyRobot.p.configData.put("LAST_HEIGHT",Integer.toString(d.height));
delayInput.setText(Integer.toString(d.delay));
MyRobot.p.configData.put("LAST_DELAY",Integer.toString(d.delay));
fontSizeInput.setText(Integer.toString(d.fontSize));
MyRobot.p.configData.put("LAST_FONTSIZE",Integer.toString(d.fontSize));
model.clear();
model2.clear();
for (int i=0;i<d.labels.length;i++) {
if (!d.labels[i].equalsIgnoreCase("Add a label!")) {
model2.add(i, d.labels[i]);
}
}
first:
for (int j=0;j<AVAILABLELABELS.length;j++) {
String labelCheck = AVAILABLELABELS[j];
for (int i=0;i<d.labels.length;i++) {
if (labelCheck.equalsIgnoreCase(d.labels[i])) {
continue first;
}
}
model.add(model.getSize(),labelCheck);
}
f.setVisible(true);
}
class FontRenderer extends JLabel
implements ListCellRenderer {
@ -215,7 +414,8 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio
class ColorButton extends JButton{
protected Color col = Color.BLUE;
public ColorButton(String string) {
String type = "background";
public ColorButton(String string,final String type) {
super(string);
this.setColor(col);
this.addActionListener(new ActionListener(){
@ -224,6 +424,16 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio
Color c = MyRobot.CP.getColor(col);
if (c!=null) {
((ColorButton)(e.getSource())).setColor(c);
switch (type) {
case "background":{
selectedDisplay.backgroundCol=c;
MyRobot.p.repaint();
}break;
case "foreground":{
selectedDisplay.textCol=c;
MyRobot.p.repaint();
}break;
}
}
}
});
@ -272,7 +482,12 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio
}
@Override
public void valueChanged(ListSelectionEvent e) {
// TODO Auto-generated method stub
}
@Override
public void itemStateChanged(ItemEvent e) {
if (selectedDisplay!=null) {
selectedDisplay.font=new Font(((Font)fonts.getSelectedItem()).getFontName(),Font.PLAIN,selectedDisplay.fontSize);
MyRobot.p.repaint();
}
}
}

@ -18,6 +18,7 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.font.TextAttribute;
@ -28,12 +29,15 @@ import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.AttributedString;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import org.json.JSONArray;
@ -45,7 +49,7 @@ import sig.utils.FileUtils;
import sig.utils.ImageUtils;
import sig.utils.TextUtils;
public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,WindowListener,MouseListener{
public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,WindowListener,MouseListener,MouseMotionListener{
String difficulty;
String panelText;
//Font programFont = new Font("Alata Regular", Font.PLAIN, 32);
@ -76,6 +80,9 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
boolean targetBuffer=false;
static Color background = new Color(170,170,170);
public static HashMap<String,String> configData = new HashMap<String,String>();
List<Display> displays = new ArrayList<Display>();
public static Display selectedDisplay = null;
public static Display draggedDisplay = null;
DrawCanvas() throws FontFormatException, IOException {
loadConfig();
addConfigButton = ImageIO.read(new File("addDisplay.png"));
@ -209,41 +216,9 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
g2.drawImage(addConfigButton,getWidth()-addConfigButton.getWidth()+1,0,this);
g2.drawImage(backgroundColorButton,getWidth()-backgroundColorButton.getWidth()+1,backgroundColorButton.getHeight()+1,this);
// String songDisplay = ((romanizedname.length()>0)?romanizedname:englishname) + " - " + artist;
// Rectangle2D bounds = TextUtils.calculateStringBoundsFont(songDisplay, programFont);
// if (bounds.getWidth()>675) {
// DrawUtils.drawOutlineText(g2, programFontSmall, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), songDisplay);
// } else {
// DrawUtils.drawOutlineText(g2, programFont, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), songDisplay);
// }
//
// if ((bestPlayTime>System.currentTimeMillis()-10000)) {
// DrawUtils.drawOutlineText(g2, programFont, 8, 935+42, 1, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-bestPlayTime))/5,255)), new Color(0,0,0,64),"New Record!");
// } else {
// DrawUtils.drawOutlineText(g2, programFontSmall, 8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),((bestPlay!=null)?bestPlay.display():""));
// }
// if ((ratingTime>System.currentTimeMillis()-10000)) {
// DrawUtils.drawOutlineText(g2, programFontSmall, 484+8, 935+42, 1, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-ratingTime))/5,255)), new Color(0,0,0,64),"Rating up! "+lastRating+" -> "+overallrating);
// } else {
// DrawUtils.drawOutlineText(g2, programFont, 484+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),Integer.toString(overallrating));
// }
// if (displayTimer%3==0) {
// DrawUtils.drawOutlineText(g2, programFont, 968+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),difficultyRating + " - " + fullNameDifficulty());
// } else
// if (displayTimer%3==1) {
// if (plays>0) {
// DrawUtils.drawOutlineText(g2, programFontSmall, 968+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),""+(passes)+"/"+(plays)+" play"+((plays!=1)?"s":"")+" "+"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate)");
// } else {
// DrawUtils.drawOutlineText(g2, programFont, 968+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),"No plays");
// }
// } else {
// if (fcCount>0) {
// DrawUtils.drawOutlineText(g2, programFont, 968+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),fcCount +" FC"+(fcCount==1?"":"s")+" "+((int)(Math.floor(((float)fcCount)/plays*100)))+"% FC rate");
// } else {
// DrawUtils.drawOutlineText(g2, programFont, 968+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),difficultyRating + " - " + fullNameDifficulty());
// }
// }
for (int i=0;i<displays.size();i++) {
displays.get(i).draw(g);
}
}
private String fullNameDifficulty() {
@ -275,6 +250,20 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
@Override
public void keyPressed(KeyEvent e) {
if (selectedDisplay!=null && e.getKeyCode()==KeyEvent.VK_DELETE) {
DeleteDisplay();
}
}
private void DeleteDisplay() {
if (selectedDisplay!=null) {
int dialogResult = JOptionPane.showConfirmDialog (null, "Are you sure you would like to delete this display box?","Warning",JOptionPane.YES_NO_OPTION);
if(dialogResult == JOptionPane.YES_OPTION){
selectedDisplay.deleted=true;
selectedDisplay=(displays.remove(selectedDisplay))?null:selectedDisplay;
repaint();
}
}
}
@Override
@ -354,14 +343,33 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
@Override
public void mousePressed(MouseEvent e) {
Point cursor = e.getPoint();
cursor.translate(-MyRobot.FRAME.getInsets().left,-MyRobot.FRAME.getInsets().top);
System.out.println(cursor+"/"+addConfigButton.getHeight());
Point cursor = GetCursorPosition(e);
switch (e.getButton()) {
case MouseEvent.BUTTON3:{
selectedDisplay=null;
for (int i=0;i<displays.size();i++) {
Display d = displays.get(i);
if (cursor.x>=d.x&&
cursor.x<=d.x+d.width&&
cursor.y>=d.y&&
cursor.y<=d.y+d.height) {
selectedDisplay=d;
break;
}
}
DeleteDisplay();
}break;
case MouseEvent.BUTTON1:{
//System.out.println(cursor+"/"+addConfigButton.getHeight());
if (cursor.x>=getWidth()-addConfigButton.getWidth()&&
cursor.x<=getWidth()&&
cursor.y>=0&&
cursor.y<=addConfigButton.getHeight()) {
MyRobot.FRAME.setCursor(new Cursor(Cursor.HAND_CURSOR));
Display d = new Display();
displays.add(d);
selectedDisplay=d;
DisplayManager.setupSettings(selectedDisplay);
return;
} else
if (cursor.x>=getWidth()-addConfigButton.getWidth()&&
cursor.x<=getWidth()&&
@ -372,16 +380,46 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
configData.put("BACKGROUND",Integer.toString(c.getRGB()));
applyConfig();
}
} else
{
return;
}
Display previousDisplay = selectedDisplay;
selectedDisplay=null;
for (int i=0;i<displays.size();i++) {
Display d = displays.get(i);
if (cursor.x>=d.x&&
cursor.x<=d.x+d.width&&
cursor.y>=d.y&&
cursor.y<=d.y+d.height) {
selectedDisplay=d;
break;
}
}
if (selectedDisplay==null) {
MyRobot.FRAME.setCursor(Cursor.getDefaultCursor());
DisplayManager.f.setVisible(false);
} else {
MyRobot.FRAME.setCursor(new Cursor(Cursor.MOVE_CURSOR));
draggedDisplay=selectedDisplay;
if (selectedDisplay.equals(previousDisplay)) {
//System.out.println("Double click");
DisplayManager.setupSettings(selectedDisplay);
}
}
}break;
}
}
private Point GetCursorPosition(MouseEvent e) {
Point cursor = e.getPoint();
cursor.translate(-MyRobot.FRAME.getInsets().left,-MyRobot.FRAME.getInsets().top);
return cursor;
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
draggedDisplay=null;
}
@Override
@ -395,4 +433,20 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(MouseEvent e) {
if (draggedDisplay!=null) {
Point cursor = GetCursorPosition(e);
draggedDisplay.x=(int)(Math.floor((cursor.x-draggedDisplay.width/2)/8)*8);
draggedDisplay.y=(int)(Math.floor((cursor.y-draggedDisplay.height/2)/8)*8);
MyRobot.p.repaint();
}
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
}
}

@ -104,7 +104,13 @@ public class ListTransferHandler extends TransferHandler {
}
}
}
System.out.println("Selected indexes: "+Arrays.toString(indices));
String[] labels = new String[listModel.getSize()];
for (int i=0;i<listModel.getSize();i++) {
labels[i]=(String)listModel.get(i);
}
DisplayManager.selectedDisplay.labels=labels;
MyRobot.p.repaint();
//System.out.println("Selected indexes: "+Arrays.toString(indices));
for (int i=0;i<indices.length;i++) {
if (addIndex<indices[i]) {
listModel.add(addIndex, listModel.get(indices[i]));

@ -602,6 +602,8 @@ public class MyRobot{
FRAME.addComponentListener(p);
FRAME.addWindowListener(p);
FRAME.addMouseListener(p);
FRAME.addMouseMotionListener(p);
FRAME.addKeyListener(p);
if (DrawCanvas.configData.containsKey("WIDTH")&&DrawCanvas.configData.containsKey("HEIGHT")) {
try {
FRAME.setSize(

Loading…
Cancel
Save