mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added the multi color transform to the gui.
Former-commit-id: 96ff1aa60098871a8597f716c0788cc749e149ef
This commit is contained in:
parent
602afa14f6
commit
79f66f7db1
@ -1,5 +1,6 @@
|
||||
package org.hyperion.hypercon.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.beans.Transient;
|
||||
@ -11,11 +12,13 @@ import javax.swing.GroupLayout;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
import org.hyperion.hypercon.spec.ColorConfig;
|
||||
import org.hyperion.hypercon.spec.TransformConfig;
|
||||
|
||||
/**
|
||||
@ -23,10 +26,14 @@ import org.hyperion.hypercon.spec.TransformConfig;
|
||||
*
|
||||
* NB This has not been integrated in the GUI jet!
|
||||
*/
|
||||
public class ColorPanel extends JPanel {
|
||||
public class ColorTransformPanel extends JPanel {
|
||||
|
||||
private final TransformConfig mColorConfig;
|
||||
|
||||
private JPanel mIndexPanel;
|
||||
private JLabel mIndexLabel;
|
||||
private JTextField mIndexField;
|
||||
|
||||
private JPanel mRgbTransformPanel;
|
||||
private JLabel mThresholdLabel;
|
||||
private JLabel mGammaLabel;
|
||||
@ -54,10 +61,10 @@ public class ColorPanel extends JPanel {
|
||||
private JLabel mValueAdjustLabel;
|
||||
private JSpinner mValueAdjustSpinner;
|
||||
|
||||
public ColorPanel(ColorConfig pColorConfig) {
|
||||
public ColorTransformPanel(TransformConfig pTransformConfig) {
|
||||
super();
|
||||
|
||||
mColorConfig = pColorConfig.mTransforms.get(0);
|
||||
mColorConfig = pTransformConfig;
|
||||
|
||||
initialise();
|
||||
}
|
||||
@ -71,12 +78,32 @@ public class ColorPanel extends JPanel {
|
||||
}
|
||||
|
||||
private void initialise() {
|
||||
setBorder(BorderFactory.createTitledBorder("Color transform"));
|
||||
setBorder(BorderFactory.createTitledBorder("Transform [" + mColorConfig.mId + "]"));
|
||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
|
||||
add(getIndexPanel());
|
||||
add(Box.createVerticalStrut(10));
|
||||
add(getRgbPanel());
|
||||
add(Box.createVerticalStrut(10));
|
||||
add(getHsvPanel());
|
||||
add(Box.createVerticalGlue());
|
||||
}
|
||||
|
||||
private JPanel getIndexPanel() {
|
||||
if (mIndexPanel == null) {
|
||||
mIndexPanel = new JPanel();
|
||||
mIndexPanel.setMaximumSize(new Dimension(1024, 25));
|
||||
mIndexPanel.setLayout(new BorderLayout(10,10));
|
||||
|
||||
mIndexLabel = new JLabel("Indices:");
|
||||
mIndexPanel.add(mIndexLabel, BorderLayout.WEST);
|
||||
|
||||
mIndexField = new JTextField(mColorConfig.mLedIndexString);
|
||||
mIndexField.setToolTipText("Comma seperated indices or index ranges (eg '1-10, 13, 14, 17-19')");
|
||||
mIndexField.getDocument().addDocumentListener(mDocumentListener);
|
||||
mIndexPanel.add(mIndexField, BorderLayout.CENTER);
|
||||
}
|
||||
return mIndexPanel;
|
||||
}
|
||||
|
||||
private JPanel getRgbPanel() {
|
||||
@ -217,4 +244,18 @@ public class ColorPanel extends JPanel {
|
||||
mColorConfig.mValueGain = (Double)mValueAdjustSpinner.getValue();
|
||||
}
|
||||
};
|
||||
private final DocumentListener mDocumentListener = new DocumentListener() {
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
mColorConfig.mLedIndexString = mIndexField.getText();
|
||||
}
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
mColorConfig.mLedIndexString = mIndexField.getText();
|
||||
}
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
mColorConfig.mLedIndexString = mIndexField.getText();
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package org.hyperion.hypercon.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.hyperion.hypercon.spec.ColorConfig;
|
||||
import org.hyperion.hypercon.spec.TransformConfig;
|
||||
|
||||
public class ColorsPanel extends JPanel {
|
||||
|
||||
private final ColorConfig mColorConfig;
|
||||
private final DefaultComboBoxModel<TransformConfig> mTransformsModel;
|
||||
|
||||
private JPanel mControlPanel;
|
||||
private JComboBox<TransformConfig> mTransformCombo;
|
||||
private JButton mAddTransformButton;
|
||||
private JButton mDelTransformButton;
|
||||
|
||||
private JPanel mTransformPanel;
|
||||
|
||||
private final Map<TransformConfig, ColorTransformPanel> mTransformPanels = new HashMap<>();
|
||||
|
||||
|
||||
public ColorsPanel(ColorConfig pColorConfig) {
|
||||
super();
|
||||
|
||||
mColorConfig = pColorConfig;
|
||||
mTransformsModel = new DefaultComboBoxModel<TransformConfig>(mColorConfig.mTransforms);
|
||||
|
||||
initialise();
|
||||
}
|
||||
|
||||
private void initialise() {
|
||||
setLayout(new BorderLayout(10,10));
|
||||
setBorder(BorderFactory.createTitledBorder("Colors"));
|
||||
|
||||
add(getControlPanel(), BorderLayout.NORTH);
|
||||
|
||||
mTransformPanel = new JPanel();
|
||||
mTransformPanel.setLayout(new BorderLayout());
|
||||
add(mTransformPanel, BorderLayout.CENTER);
|
||||
|
||||
for (TransformConfig config : mColorConfig.mTransforms) {
|
||||
mTransformPanels.put(config, new ColorTransformPanel(config));
|
||||
}
|
||||
ColorTransformPanel currentPanel = mTransformPanels.get(mColorConfig.mTransforms.get(0));
|
||||
mTransformPanel.add(currentPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private JPanel getControlPanel() {
|
||||
if (mControlPanel == null) {
|
||||
mControlPanel = new JPanel();
|
||||
mControlPanel.setLayout(new BoxLayout(mControlPanel, BoxLayout.LINE_AXIS));
|
||||
|
||||
mTransformCombo = new JComboBox<>(mTransformsModel);
|
||||
mTransformCombo.addActionListener(mComboListener);
|
||||
mControlPanel.add(mTransformCombo);
|
||||
|
||||
mAddTransformButton = new JButton(mAddAction);
|
||||
mControlPanel.add(mAddTransformButton);
|
||||
|
||||
mDelTransformButton = new JButton(mDelAction);
|
||||
mDelTransformButton.setEnabled(mTransformCombo.getItemCount() > 1);
|
||||
mControlPanel.add(mDelTransformButton);
|
||||
}
|
||||
return mControlPanel;
|
||||
}
|
||||
|
||||
private final Action mAddAction = new AbstractAction("Add") {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String newId = JOptionPane.showInputDialog("Give an identifier for the new color-transform:");
|
||||
if (newId == null || newId.isEmpty()) {
|
||||
// No proper value given
|
||||
return;
|
||||
}
|
||||
|
||||
TransformConfig config = new TransformConfig();
|
||||
config.mId = newId;
|
||||
|
||||
ColorTransformPanel panel = new ColorTransformPanel(config);
|
||||
mTransformPanels.put(config, panel);
|
||||
|
||||
mTransformsModel.addElement(config);
|
||||
mTransformsModel.setSelectedItem(config);
|
||||
|
||||
mDelTransformButton.setEnabled(true);
|
||||
}
|
||||
};
|
||||
private final Action mDelAction = new AbstractAction("Del") {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
TransformConfig config = (TransformConfig) mTransformCombo.getSelectedItem();
|
||||
mTransformPanels.remove(config);
|
||||
mTransformsModel.removeElement(config);
|
||||
|
||||
mDelTransformButton.setEnabled(mTransformCombo.getItemCount() > 1);
|
||||
}
|
||||
};
|
||||
|
||||
private final ActionListener mComboListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
TransformConfig selConfig = (TransformConfig) mTransformsModel.getSelectedItem();
|
||||
if (selConfig == null) {
|
||||
// Something went wrong here, there should always be a selection!
|
||||
return;
|
||||
}
|
||||
|
||||
ColorTransformPanel panel = mTransformPanels.get(selConfig);
|
||||
mTransformPanel.removeAll();
|
||||
mTransformPanel.add(panel, BorderLayout.CENTER);
|
||||
mTransformPanel.revalidate();
|
||||
mTransformPanel.repaint();
|
||||
}
|
||||
};
|
||||
}
|
@ -174,7 +174,7 @@ public class ConfigPanel extends JPanel {
|
||||
mProcessPanel.add(new BootSequencePanel(ledString.mMiscConfig));
|
||||
mProcessPanel.add(new FrameGrabberPanel(ledString.mMiscConfig));
|
||||
mProcessPanel.add(new ColorSmoothingPanel(ledString.mColorConfig));
|
||||
mProcessPanel.add(new ColorPanel(ledString.mColorConfig));
|
||||
mProcessPanel.add(new ColorsPanel(ledString.mColorConfig));
|
||||
mProcessPanel.add(Box.createVerticalGlue());
|
||||
}
|
||||
return mProcessPanel;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.hyperion.hypercon.spec;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Vector;
|
||||
|
||||
@ -10,7 +9,7 @@ import java.util.Vector;
|
||||
public class ColorConfig {
|
||||
|
||||
/** List with color transformations */
|
||||
public List<TransformConfig> mTransforms = new Vector<>();
|
||||
public Vector<TransformConfig> mTransforms = new Vector<>();
|
||||
{
|
||||
mTransforms.add(new TransformConfig());
|
||||
}
|
||||
@ -31,16 +30,27 @@ public class ColorConfig {
|
||||
public String toJsonString() {
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
|
||||
strBuf.append("\t/// Color manipulation configuration used to tune the output colors to specific surroundings. Contains the following fields:\n");
|
||||
strBuf.append("\t/// * 'hsv' : The manipulation in the Hue-Saturation-Value color domain with the following tuning parameters:\n");
|
||||
strBuf.append("\t/// Color manipulation configuration used to tune the output colors to specific surroundings. \n");
|
||||
strBuf.append("\t/// The configuration contains a list of color-transforms. Each transform contains the \n");
|
||||
strBuf.append("\t/// following fields:\n");
|
||||
strBuf.append("\t/// * 'id' : The unique identifier of the color transformation (eg 'device_1')");
|
||||
strBuf.append("\t/// * 'leds' : The indices (or index ranges) of the leds to which this color transform applies\n");
|
||||
strBuf.append("\t/// (eg '0-5, 9, 11, 12-17'). The indices are zero based.");
|
||||
strBuf.append("\t/// * 'hsv' : The manipulation in the Hue-Saturation-Value color domain with the following \n");
|
||||
strBuf.append("\t/// tuning parameters:\n");
|
||||
strBuf.append("\t/// - 'saturationGain' The gain adjustement of the saturation\n");
|
||||
strBuf.append("\t/// - 'valueGain' The gain adjustement of the value\n");
|
||||
strBuf.append("\t/// * 'red'/'green'/'blue' : The manipulation in the Red-Green-Blue color domain with the following tuning parameters for each channel:\n");
|
||||
strBuf.append("\t/// - 'threshold' The minimum required input value for the channel to be on (else zero)\n");
|
||||
strBuf.append("\t/// * 'red'/'green'/'blue' : The manipulation in the Red-Green-Blue color domain with the \n");
|
||||
strBuf.append("\t/// following tuning parameters for each channel:\n");
|
||||
strBuf.append("\t/// - 'threshold' The minimum required input value for the channel to be on \n");
|
||||
strBuf.append("\t/// (else zero)\n");
|
||||
strBuf.append("\t/// - 'gamma' The gamma-curve correction factor\n");
|
||||
strBuf.append("\t/// - 'blacklevel' The lowest possible value (when the channel is black)\n");
|
||||
strBuf.append("\t/// - 'whitelevel' The highest possible value (when the channel is white)\n");
|
||||
strBuf.append("\t/// * 'smoothing' : Smoothing of the colors in the time-domain with the following tuning parameters:\n");
|
||||
strBuf.append("\t///");
|
||||
strBuf.append("\t/// Next to the list with color transforms there is also a smoothing option.");
|
||||
strBuf.append("\t/// * 'smoothing' : Smoothing of the colors in the time-domain with the following tuning \n");
|
||||
strBuf.append("\t/// parameters:\n");
|
||||
strBuf.append("\t/// - 'type' The type of smoothing algorithm ('linear' or 'none')\n");
|
||||
strBuf.append("\t/// - 'time_ms' The time constant for smoothing algorithm in milliseconds\n");
|
||||
strBuf.append("\t/// - 'updateFrequency' The update frequency of the leds in Hz\n");
|
||||
|
@ -4,7 +4,10 @@ import java.util.Locale;
|
||||
|
||||
public class TransformConfig {
|
||||
/** The identifier of this ColorTransform configuration */
|
||||
public String mId = "";
|
||||
public String mId = "default";
|
||||
|
||||
/** The indices to which this transform applies */
|
||||
public String mLedIndexString = "0-49";
|
||||
|
||||
/** The saturation gain (in HSV space) */
|
||||
public double mSaturationGain = 1.0;
|
||||
@ -42,6 +45,8 @@ public class TransformConfig {
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
|
||||
strBuf.append("\t\t\t{\n");
|
||||
strBuf.append("\t\t\t\t\"id\" : \"" + mId + "\",\n");
|
||||
strBuf.append("\t\t\t\t\"leds\" : \"" + mLedIndexString + "\",\n");
|
||||
strBuf.append(hsvToJsonString() + ",\n");
|
||||
strBuf.append(rgbToJsonString() + "\n");
|
||||
strBuf.append("\t\t\t}");
|
||||
@ -98,4 +103,9 @@ public class TransformConfig {
|
||||
|
||||
return strBuf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mId;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user