Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package main;
- import com.mollin.yapi.*;
- import com.mollin.yapi.enumeration.YeelightEffect;
- import com.mollin.yapi.enumeration.YeelightFlowAction;
- import com.mollin.yapi.flow.YeelightFlow;
- import java.awt.KeyEventDispatcher;
- import java.awt.KeyboardFocusManager;
- import java.awt.event.KeyEvent;
- import java.util.logging.Level;
- import java.util.logging.LogManager;
- import java.util.logging.Logger;
- import org.jnativehook.GlobalScreen;
- import org.jnativehook.NativeHookException;
- import org.jnativehook.keyboard.NativeKeyEvent;
- import org.jnativehook.keyboard.NativeKeyListener;
- import org.jnativehook.mouse.NativeMouseWheelEvent;
- import org.jnativehook.mouse.NativeMouseWheelListener;
- /**
- *
- * @author Reykez
- */
- public class Main extends javax.swing.JFrame implements NativeKeyListener, NativeMouseWheelListener{
- YeelightDevice dv1, dv2, dv3;
- boolean lampa = false;
- int bright=100;
- boolean isAltPressed = false;
- /**
- * Creates new form Main
- */
- public Main() {
- try {
- dv1 = new YeelightDevice("192.168.8.102", 55443, YeelightEffect.SMOOTH, 500);
- dv2 = new YeelightDevice("192.168.8.103", 55443, YeelightEffect.SMOOTH, 500);
- dv3 = new YeelightDevice("192.168.8.104", 55443, YeelightEffect.SMOOTH, 500);
- } catch(Exception e) { e.printStackTrace(); }
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- lgroup = new javax.swing.ButtonGroup();
- rgroup = new javax.swing.ButtonGroup();
- jPanel1 = new javax.swing.JPanel();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jRadioButton1 = new javax.swing.JRadioButton();
- jRadioButton2 = new javax.swing.JRadioButton();
- jRadioButton3 = new javax.swing.JRadioButton();
- jRadioButton4 = new javax.swing.JRadioButton();
- lr = new javax.swing.JTextField();
- lg = new javax.swing.JTextField();
- lb = new javax.swing.JTextField();
- lt1 = new javax.swing.JRadioButton();
- lt2 = new javax.swing.JRadioButton();
- lt3 = new javax.swing.JRadioButton();
- lt4 = new javax.swing.JRadioButton();
- rt1 = new javax.swing.JRadioButton();
- rt2 = new javax.swing.JRadioButton();
- rt3 = new javax.swing.JRadioButton();
- rt4 = new javax.swing.JRadioButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jPanel1.setBackground(new java.awt.Color(255, 255, 255));
- jLabel1.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
- jLabel1.setText("LAMPA");
- jLabel2.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
- jLabel2.setText("PC");
- jRadioButton1.setText("ON");
- jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton1ActionPerformed(evt);
- }
- });
- jRadioButton2.setText("OFF");
- jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton2ActionPerformed(evt);
- }
- });
- jRadioButton3.setText("ON");
- jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton3ActionPerformed(evt);
- }
- });
- jRadioButton4.setText("OFF");
- jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton4ActionPerformed(evt);
- }
- });
- lr.setText("0");
- lr.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- lrActionPerformed(evt);
- }
- });
- lg.setText("0");
- lg.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- lgActionPerformed(evt);
- }
- });
- lb.setText("0");
- lb.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- lbActionPerformed(evt);
- }
- });
- lgroup.add(lt1);
- lt1.setText("DEFAULT");
- lt1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- lt1ActionPerformed(evt);
- }
- });
- lgroup.add(lt2);
- lt2.setText("RED GAMING");
- lt2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- lt2ActionPerformed(evt);
- }
- });
- lgroup.add(lt3);
- lt3.setText("FLOW");
- lt3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- lt3ActionPerformed(evt);
- }
- });
- lgroup.add(lt4);
- lt4.setText("lt4");
- lt4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- lt4ActionPerformed(evt);
- }
- });
- rgroup.add(rt1);
- rt1.setText("DEFAULT");
- rt1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- rt1ActionPerformed(evt);
- }
- });
- rgroup.add(rt2);
- rt2.setText("RED GAMING");
- rt2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- rt2ActionPerformed(evt);
- }
- });
- rgroup.add(rt3);
- rt3.setText("FLOW");
- rt3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- rt3ActionPerformed(evt);
- }
- });
- rgroup.add(rt4);
- rt4.setText("rt4");
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(25, 25, 25)
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel2)
- .addGap(29, 29, 29))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(50, 50, 50)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(lr)
- .addComponent(jRadioButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(34, 34, 34)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jRadioButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(lg))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(33, 33, 33)
- .addComponent(lb, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1053, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jRadioButton3)
- .addGap(31, 31, 31)
- .addComponent(jRadioButton4))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(rt1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(rt4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(rt3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(rt2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
- .addGap(93, 93, 93))))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(lt3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(lt2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(lt4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(lt1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(0, 0, Short.MAX_VALUE))))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(20, 20, 20)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jLabel2))
- .addGap(18, 18, 18)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jRadioButton1)
- .addComponent(jRadioButton2)
- .addComponent(jRadioButton3)
- .addComponent(jRadioButton4))
- .addGap(39, 39, 39)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(lt1)
- .addComponent(rt1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(lt2)
- .addComponent(rt2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(lt3)
- .addComponent(rt3))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(lt4)
- .addComponent(rt4))
- .addGap(131, 131, 131)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(lr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(lg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(lb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(409, Short.MAX_VALUE))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void lampOn() {
- try {
- lampa = true;
- dv1.setPower(true);
- dv2.setPower(true);
- dv3.setPower(true);
- lampBright();
- } catch(Exception e) { e.printStackTrace(); }
- }
- private void lampOff() {
- try {
- lampa = false;
- dv1.setPower(false);
- dv2.setPower(false);
- dv3.setPower(false);
- lgroup.clearSelection();
- } catch(Exception e) { e.printStackTrace(); }
- }
- private void lampColor(String r, String g, String b) {
- try {
- if (!r.matches("[0-9]+")) {
- r = "0";
- lr.setText("0");
- }
- if (!g.matches("[0-9]+")) {
- g = "0";
- lg.setText("0");
- }
- if (!b.matches("[0-9]+")) {
- b = "0";
- lb.setText("0");
- }
- dv1.setRGB(Integer.parseInt(r),Integer.parseInt(g),Integer.parseInt(b));
- dv2.setRGB(Integer.parseInt(r),Integer.parseInt(g),Integer.parseInt(b));
- dv3.setRGB(Integer.parseInt(r),Integer.parseInt(g),Integer.parseInt(b));
- } catch(Exception e) { e.printStackTrace(); }
- }
- private void lampTemp(int temp) {
- try {
- dv1.setColorTemperature(temp);
- dv2.setColorTemperature(temp);
- dv3.setColorTemperature(temp);
- } catch(Exception e) { e.printStackTrace(); }
- }
- private void lampBright() {
- for(int i=0 ; i<=1 ; i++) {
- if(bright>=100) {
- bright = 100;
- break;
- }
- if(bright<=0) {
- bright = 0;
- break;
- }
- System.out.println("Bright = " + bright);
- try {
- dv1.setBrightness(bright);
- dv2.setBrightness(bright);
- dv3.setBrightness(bright);
- } catch(Exception e) { e.printStackTrace(); }
- }
- }
- private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- // LAMPA ON
- jRadioButton1.setSelected(true);
- jRadioButton2.setSelected(false);
- lampOn();
- }
- private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- // LAMPA OFF
- jRadioButton1.setSelected(false);
- jRadioButton2.setSelected(true);
- lampOff();
- }
- private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- // PC ON
- jRadioButton3.setSelected(true);
- jRadioButton4.setSelected(false);
- rt1.setSelected(true);
- try { Runtime.getRuntime().exec("fusion/RGBFusionTool.exe --static=White --brightness 100"); } catch(Exception e){e.printStackTrace();}
- }
- private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {
- // PC OFF
- jRadioButton3.setSelected(false);
- jRadioButton4.setSelected(true);
- lgroup.clearSelection();
- try { Runtime.getRuntime().exec("fusion/RGBFusionTool.exe --static=Red --brightness 0"); } catch(Exception e){e.printStackTrace();}
- }
- private void lrActionPerformed(java.awt.event.ActionEvent evt) {
- lampColor(lr.getText(), lg.getText(), lb.getText());
- lgroup.clearSelection();
- }
- private void lgActionPerformed(java.awt.event.ActionEvent evt) {
- lampColor(lr.getText(), lg.getText(), lb.getText());
- lgroup.clearSelection();
- }
- private void lbActionPerformed(java.awt.event.ActionEvent evt) {
- lampColor(lr.getText(), lg.getText(), lb.getText());
- lgroup.clearSelection();
- }
- private void lt1ActionPerformed(java.awt.event.ActionEvent evt) {
- // default
- jRadioButton1.doClick();
- lampTemp(4200);
- }
- private void lt2ActionPerformed(java.awt.event.ActionEvent evt) {
- // red gaming
- jRadioButton1.doClick();
- lampColor("255", "30", "0");
- }
- private void lt3ActionPerformed(java.awt.event.ActionEvent evt) {
- // flow
- try {
- YeelightFlow flow;
- YeelightFlowAction action = null;
- flow = new YeelightFlow(100, action);
- } catch(Exception e) { }
- }
- private void lt4ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void rt1ActionPerformed(java.awt.event.ActionEvent evt) {
- // DEFAULT
- jRadioButton3.doClick();
- }
- private void rt2ActionPerformed(java.awt.event.ActionEvent evt) {
- // RED GAMING
- jRadioButton3.setSelected(true);
- try { Runtime.getRuntime().exec("fusion/RGBFusionTool.exe --zone=1 --static=ff0600 --brightness=90 " + "--zone=2 --static=ff0600 --brightness=0 " + "--zone=3 --static=ff0600 --brightness=0 " + "--zone=4 --static=ff0600 --brightness=90 "); } catch(Exception e){e.printStackTrace();}
- }
- private void rt3ActionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton3.setSelected(true);
- try { Runtime.getRuntime().exec("fusion/RGBFusionTool.exe --colorcycle=16"); } catch(Exception e){e.printStackTrace();}
- }
- public void nativeKeyPressed(NativeKeyEvent e) {
- //isAltPressed = (e.getModifiers() & NativeKeyEvent.ALT_MASK) != 0;
- }
- public void nativeKeyReleased(NativeKeyEvent e) {
- //System.out.println("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
- isAltPressed = (e.getModifiers() & NativeKeyEvent.ALT_MASK) != 0;
- if(e.getKeyCode() == NativeKeyEvent.VC_8 & isAltPressed) {
- if(lampa) {
- jRadioButton2.doClick();
- } else {
- jRadioButton1.doClick();
- }
- }
- }
- public void nativeKeyTyped(NativeKeyEvent e) {
- }
- public void nativeMouseWheelMoved(NativeMouseWheelEvent e) {
- //System.out.println("Mosue Wheel Moved: " + e.getWheelRotation());
- isAltPressed = (e.getModifiers() & NativeKeyEvent.ALT_MASK) != 0;
- if(e.getWheelRotation()==1 & isAltPressed) { // w tyl
- bright = bright-10;
- lampBright();
- } else if (e.getWheelRotation()!=1 & isAltPressed) { // w przod
- bright = bright+10;
- lampBright();
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Main().setVisible(true);
- }
- });
- try {
- Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
- logger.setLevel(Level.WARNING);
- logger.setUseParentHandlers(false);
- GlobalScreen.registerNativeHook();
- }
- catch (NativeHookException ex) {
- System.err.println("There was a problem registering the native hook.");
- System.err.println(ex.getMessage());
- System.exit(1);
- }
- GlobalScreen.addNativeKeyListener(new Main());
- GlobalScreen.addNativeMouseWheelListener(new Main());
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JRadioButton jRadioButton1;
- private javax.swing.JRadioButton jRadioButton2;
- private javax.swing.JRadioButton jRadioButton3;
- private javax.swing.JRadioButton jRadioButton4;
- private javax.swing.JTextField lb;
- private javax.swing.JTextField lg;
- private javax.swing.ButtonGroup lgroup;
- private javax.swing.JTextField lr;
- private javax.swing.JRadioButton lt1;
- private javax.swing.JRadioButton lt2;
- private javax.swing.JRadioButton lt3;
- private javax.swing.JRadioButton lt4;
- private javax.swing.ButtonGroup rgroup;
- private javax.swing.JRadioButton rt1;
- private javax.swing.JRadioButton rt2;
- private javax.swing.JRadioButton rt3;
- private javax.swing.JRadioButton rt4;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement