mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Continues work on HyperCon for effect engine
Former-commit-id: d8645606333a09d0c4a5f4aa7ee15cd04e0ee27d
This commit is contained in:
parent
3531bab2a1
commit
f4ef83b171
@ -7,9 +7,11 @@ import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
@ -20,6 +22,8 @@ public class EffectEnginePanel extends JPanel {
|
||||
|
||||
private final EffectEngineConfig mEffectEngingeConfig;
|
||||
|
||||
private final DefaultComboBoxModel<EffectConfig> mEffectModel;
|
||||
|
||||
private JPanel mControlPanel;
|
||||
private JComboBox<EffectConfig> mEffectCombo;
|
||||
private JButton mAddButton;
|
||||
@ -35,8 +39,11 @@ public class EffectEnginePanel extends JPanel {
|
||||
super();
|
||||
|
||||
mEffectEngingeConfig = pEffectEngineConfig;
|
||||
mEffectModel = new DefaultComboBoxModel<EffectConfig>(mEffectEngingeConfig.mEffects);
|
||||
|
||||
initialise();
|
||||
|
||||
effectSelectionChanged();
|
||||
}
|
||||
|
||||
private void initialise() {
|
||||
@ -46,25 +53,82 @@ public class EffectEnginePanel extends JPanel {
|
||||
add(getEffectPanel(), BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private void effectSelectionChanged() {
|
||||
EffectConfig effect = (EffectConfig)mEffectModel.getSelectedItem();
|
||||
|
||||
// Enable option for the selected effect or disable if none selected
|
||||
mEffectPanel.setEnabled(effect != null);
|
||||
mPythonLabel.setEnabled(effect != null);
|
||||
mPythonCombo.setEnabled(effect != null);
|
||||
mJsonArgumentLabel.setEnabled(effect != null);
|
||||
mJsonArgumentArea.setEnabled(effect != null);
|
||||
|
||||
|
||||
if (effect == null) {
|
||||
// Clear all fields
|
||||
mEffectPanel.setBorder(BorderFactory.createTitledBorder(""));
|
||||
mPythonCombo.setSelectedIndex(-1);
|
||||
mJsonArgumentArea.setText("");
|
||||
return;
|
||||
} else {
|
||||
// Update fields based on the selected effect
|
||||
mEffectPanel.setBorder(BorderFactory.createTitledBorder(effect.mId));
|
||||
mPythonCombo.setSelectedItem(effect.mScript);
|
||||
mJsonArgumentArea.setText(effect.mArgs);
|
||||
}
|
||||
}
|
||||
|
||||
private JPanel getControlPanel() {
|
||||
if (mControlPanel == null) {
|
||||
mControlPanel = new JPanel();
|
||||
mControlPanel.setPreferredSize(new Dimension(150, 35));
|
||||
mControlPanel.setLayout(new BoxLayout(mControlPanel, BoxLayout.LINE_AXIS));
|
||||
|
||||
mEffectCombo = new JComboBox<>(mEffectEngingeConfig.mEffects);
|
||||
mEffectCombo = new JComboBox<>(mEffectModel);
|
||||
mEffectCombo.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
effectSelectionChanged();
|
||||
}
|
||||
});
|
||||
mControlPanel.add(mEffectCombo);
|
||||
|
||||
mAddButton = new JButton("Add");
|
||||
mAddButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String newId = JOptionPane.showInputDialog(mAddButton, "Name of the new effect: ", "Effect Name", JOptionPane.QUESTION_MESSAGE);
|
||||
// Make that an ID is set
|
||||
if (newId == null || newId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// Make sure the ID does not yet exist
|
||||
for (EffectConfig effect : mEffectEngingeConfig.mEffects) {
|
||||
if (effect.mId.equalsIgnoreCase(newId)) {
|
||||
JOptionPane.showMessageDialog(mAddButton, "Given name(" + effect.mId + ") allready exists", "Duplicate effect name", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
EffectConfig newConfig = new EffectConfig();
|
||||
newConfig.mId = newId;
|
||||
mEffectModel.addElement(newConfig);
|
||||
mEffectModel.setSelectedItem(newConfig);
|
||||
}
|
||||
});
|
||||
mControlPanel.add(mAddButton);
|
||||
|
||||
mDelButton = new JButton("Del");
|
||||
mDelButton.setEnabled(mEffectModel.getSize() > 0);
|
||||
mDelButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (mEffectModel.getSelectedItem() != null) {
|
||||
mEffectModel.removeElement(mEffectModel.getSelectedItem());
|
||||
}
|
||||
mDelButton.setEnabled(mEffectModel.getSize() > 0);
|
||||
}
|
||||
});
|
||||
mControlPanel.add(mDelButton);
|
||||
}
|
||||
return mControlPanel;
|
||||
@ -73,7 +137,6 @@ public class EffectEnginePanel extends JPanel {
|
||||
private JPanel getEffectPanel() {
|
||||
if (mEffectPanel == null) {
|
||||
mEffectPanel = new JPanel();
|
||||
mEffectPanel.setBorder(BorderFactory.createTitledBorder("test-slow"));
|
||||
mEffectPanel.setLayout(new BoxLayout(mEffectPanel, BoxLayout.PAGE_AXIS));
|
||||
|
||||
JPanel subPanel = new JPanel(new BorderLayout());
|
||||
@ -83,6 +146,7 @@ public class EffectEnginePanel extends JPanel {
|
||||
subPanel.add(mPythonLabel, BorderLayout.WEST);
|
||||
|
||||
mPythonCombo = new JComboBox<>(new String[] {"test.py", "rainbow-swirl.py", "rainbow-mood.py"});
|
||||
// mPythonCombo.setEditable(true);
|
||||
mPythonCombo.setMaximumSize(new Dimension(150, 25));
|
||||
subPanel.add(mPythonCombo);
|
||||
|
||||
@ -90,6 +154,8 @@ public class EffectEnginePanel extends JPanel {
|
||||
mEffectPanel.add(mJsonArgumentLabel);
|
||||
|
||||
mJsonArgumentArea = new JTextArea();
|
||||
mJsonArgumentArea.setLineWrap(true);
|
||||
mJsonArgumentArea.setWrapStyleWord(true);
|
||||
mEffectPanel.add(mJsonArgumentArea);
|
||||
}
|
||||
return mEffectPanel;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.hyperion.hypercon.spec;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.hyperion.hypercon.JsonStringBuffer;
|
||||
|
||||
/**
|
||||
@ -20,10 +22,9 @@ public class EffectConfig {
|
||||
pJsonBuf.startObject(mId);
|
||||
pJsonBuf.addValue("script", mScript, false);
|
||||
|
||||
pJsonBuf.startObject("args");
|
||||
pJsonBuf.stopObject();
|
||||
pJsonBuf.addRawValue("args", String.format(Locale.ENGLISH, "{\n%s\n}", mArgs), true);
|
||||
|
||||
pJsonBuf.stopObject(!endOfEffects);
|
||||
pJsonBuf.stopObject(endOfEffects);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,29 +14,29 @@ public class EffectEngineConfig {
|
||||
{
|
||||
EffectConfig testSlow = new EffectConfig();
|
||||
testSlow.mId = "test-slow";
|
||||
testSlow.mScript = "/home/pi/hyperion/test.py";
|
||||
testSlow.mArgs = "speed : 0.5";
|
||||
testSlow.mScript = "test.py";
|
||||
testSlow.mArgs = "\"speed\" : 0.5";
|
||||
|
||||
EffectConfig testFast = new EffectConfig();
|
||||
testFast.mId = "test-fast";
|
||||
testFast.mScript = "/home/pi/hyperion/test.py";
|
||||
testFast.mArgs = "speed : 2.0";
|
||||
testFast.mScript = "test.py";
|
||||
testFast.mArgs = "\"speed\" : 2.0";
|
||||
|
||||
EffectConfig rainbowSwirl = new EffectConfig();
|
||||
rainbowSwirl.mId = "Rainbow swirl";
|
||||
rainbowSwirl.mScript = "/home/pi/hyperion/rainbow-swirl.py";
|
||||
rainbowSwirl.mScript = "rainbow-swirl.py";
|
||||
rainbowSwirl.mArgs =
|
||||
"\"rotation-time\" : 10.0,\n" +
|
||||
"\"brightness\" : 1.0,\n" +
|
||||
"\"reverse\" : false\n";
|
||||
"\"reverse\" : false";
|
||||
|
||||
EffectConfig rainbowMood = new EffectConfig();
|
||||
rainbowMood.mId = "Rainbow mood";
|
||||
rainbowMood.mScript = "/home/pi/hyperion/rainbow-mood.py";
|
||||
rainbowMood.mScript = "rainbow-mood.py";
|
||||
rainbowMood.mArgs =
|
||||
"\"rotation-time\" : 10.0,\n" +
|
||||
"\"brightness\" : 1.0,\n" +
|
||||
"\"reverse\" : false\n";
|
||||
"\"reverse\" : false";
|
||||
|
||||
mEffects.add(testSlow);
|
||||
mEffects.add(testFast);
|
||||
@ -51,8 +51,6 @@ public class EffectEngineConfig {
|
||||
effect.append(pJsonBuf, effect.equals(mEffects.get(mEffects.size()-1)));
|
||||
}
|
||||
|
||||
pJsonBuf.addValue("endOfEffect", "endOfEffect", true);
|
||||
|
||||
pJsonBuf.stopObject();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user