use of com.sldeditor.colourramp.ColourRamp in project sldeditor by robward-scisys.
the class ColourRampPanel method createColourRampList.
/**
* Creates the colour ramp list.
*
* @param xmlTwoColourRampList the xml two colour ramp list
* @return the list
*/
private List<ColourRamp> createColourRampList(XMLTwoColourRampList xmlTwoColourRampList) {
List<ColourRamp> colourRampList = new ArrayList<ColourRamp>();
for (XMLTwoColourRamp ramp : xmlTwoColourRampList.getTwoColourRamp()) {
ColourRamp colourRamp = new ColourRamp();
Color startColour = ColourUtils.toColour(ramp.getStart());
Color endColour = ColourUtils.toColour(ramp.getEnd());
colourRamp.setColourRamp(startColour, endColour);
colourRampList.add(colourRamp);
}
return colourRampList;
}
use of com.sldeditor.colourramp.ColourRamp in project sldeditor by robward-scisys.
the class ColourRampPanel method createFieldPanel.
/**
* Creates the field panel.
*/
private void createFieldPanel() {
JPanel tablePanel = new JPanel();
tablePanel.setLayout(new BorderLayout());
panel.add(tablePanel, BorderLayout.CENTER);
JPanel dataPanel = new JPanel();
tablePanel.add(dataPanel, BorderLayout.NORTH);
dataPanel.setLayout(new BoxLayout(dataPanel, BoxLayout.Y_AXIS));
minValueSpinner = new FieldConfigInteger(new FieldConfigCommonData(getClass(), FieldIdEnum.UNKNOWN, Localisation.getField(ColourRampConfigPanel.class, "ColourRampPanel.minValue"), true));
minValueSpinner.createUI();
FieldPanel fieldPanel = minValueSpinner.getPanel();
dataPanel.add(fieldPanel);
JButton resetValueButton = new JButton(Localisation.getString(ColourRampConfigPanel.class, "ColourRampPanel.reset"));
minValueSpinner.addUI(resetValueButton, 20, BasePanel.WIDGET_BUTTON_WIDTH, BasePanel.WIDGET_HEIGHT);
minValueSpinner.populateField(0);
resetValueButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (parentObj != null) {
ColourMapModel model = parentObj.getColourMapModel();
populate(model.getColourMap());
}
}
});
maxValueSpinner = new FieldConfigInteger(new FieldConfigCommonData(getClass(), FieldIdEnum.UNKNOWN, Localisation.getField(ColourRampConfigPanel.class, "ColourRampPanel.maxValue"), true));
maxValueSpinner.createUI();
maxValueSpinner.populateField(100);
dataPanel.add(maxValueSpinner.getPanel());
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
buttonPanel.setSize(BasePanel.FIELD_PANEL_WIDTH, BasePanel.WIDGET_HEIGHT);
JButton applyButton = new JButton(Localisation.getString(ColourRampConfigPanel.class, "common.apply"));
applyButton.setPreferredSize(new Dimension(BasePanel.WIDGET_BUTTON_WIDTH, BasePanel.WIDGET_HEIGHT));
applyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (parentObj != null) {
ColourRampData data = new ColourRampData();
data.setMaxValue(maxValueSpinner.getIntValue());
data.setMinValue(minValueSpinner.getIntValue());
data.setReverseColours(reverseCheckbox.isSelected());
ValueComboBoxData selectedItem = (ValueComboBoxData) rampComboBox.getSelectedItem();
ColourRamp colourRamp = colourRampCache.get(selectedItem.getKey());
data.setColourRamp(colourRamp);
parentObj.colourRampUpdate(data);
}
}
});
buttonPanel.add(applyButton);
dataPanel.add(buttonPanel);
}
use of com.sldeditor.colourramp.ColourRamp in project sldeditor by robward-scisys.
the class ColourRampPanel method populateColourRamps.
/**
* Populate colour ramps.
*
* @param reverseColours the reverse colours
* @return the list
*/
private List<ValueComboBoxData> populateColourRamps(boolean reverseColours) {
List<ValueComboBoxData> dataList = new ArrayList<ValueComboBoxData>();
colourRampCache.clear();
if (rampDataList != null) {
for (ColourRamp data : rampDataList) {
String key = data.toString();
ValueComboBoxData valueData = new ValueComboBoxData(key, data.getImageIcon(reverseColours), getClass());
dataList.add(valueData);
colourRampCache.put(key, data);
}
}
return dataList;
}
use of com.sldeditor.colourramp.ColourRamp in project sldeditor by robward-scisys.
the class ColourRampTest method testColourRamp.
/**
* Test method for {@link com.sldeditor.colourramp.ColourRamp#ColourRamp()}.
*/
@Test
public void testColourRamp() {
ColourRamp ramp = new ColourRamp();
assertEquals(Color.BLACK, ramp.getStartColour());
assertEquals(Color.WHITE, ramp.getEndColour());
Color expectedStart = Color.red;
Color expectedEnd = Color.pink;
ramp.setColourRamp(expectedStart, expectedEnd);
assertEquals(expectedStart, ramp.getStartColour());
assertEquals(expectedEnd, ramp.getEndColour());
Color expectedEnd2 = Color.cyan;
ramp.addColour(expectedEnd2);
assertEquals(expectedStart, ramp.getStartColour());
assertEquals(expectedEnd2, ramp.getEndColour());
assertEquals(3, ramp.getColourList().size());
ImageIcon icon1 = ramp.getImageIcon(false);
assertNotNull(icon1);
ImageIcon icon2 = ramp.getImageIcon(true);
assertNotNull(icon2);
FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
ColourRampData data = new ColourRampData();
Expression expectedMinValue = ff.literal(1);
Expression expectedMaxValue = ff.literal(10);
data.setColourRamp(ramp);
data.setMinValue(1);
data.setMaxValue(10);
Expression actualStart = ramp.getColour(data, expectedMinValue, false);
@SuppressWarnings("unused") Expression actualEnd = ramp.getColour(data, expectedMaxValue, false);
assertEquals(ColourUtils.toColour(actualStart.toString()), expectedStart);
// Can't test end value
// assertEquals(ColourUtils.toColour(actualEnd.toString()), expectedEnd2);
// Reverse colours
actualStart = ramp.getColour(data, expectedMinValue, true);
actualEnd = ramp.getColour(data, expectedMaxValue, true);
assertEquals(ColourUtils.toColour(actualStart.toString()), expectedEnd2);
// Can't test end value
// assertEquals(ColourUtils.toColour(actualEnd.toString()), expectedStart);
}
use of com.sldeditor.colourramp.ColourRamp in project sldeditor by robward-scisys.
the class ColourRampDataTest method testColourRampData.
/**
* Test method for {@link com.sldeditor.colourramp.ramp.ColourRampData#ColourRampData()}.
*/
@Test
public void testColourRampData() {
ColourRampData obj = new ColourRampData();
assertNull(obj.getColourRamp());
assertEquals(0, obj.getMaxValue());
assertEquals(0, obj.getMinValue());
assertFalse(obj.reverseColours());
int expectedMinValue = 42;
obj.setMinValue(expectedMinValue);
assertEquals(expectedMinValue, obj.getMinValue());
int expectedMaxValue = 69;
obj.setMaxValue(expectedMaxValue);
assertEquals(expectedMaxValue, obj.getMaxValue());
ColourRamp colourRamp = new ColourRamp();
obj.setColourRamp(colourRamp);
assertEquals(colourRamp, obj.getColourRamp());
obj.setReverseColours(true);
assertTrue(obj.reverseColours());
}
Aggregations