Search in sources :

Example 1 with ColourRamp

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;
}
Also used : XMLTwoColourRamp(com.sldeditor.common.xml.ui.XMLTwoColourRamp) XMLTwoColourRamp(com.sldeditor.common.xml.ui.XMLTwoColourRamp) ColourRamp(com.sldeditor.colourramp.ColourRamp) Color(java.awt.Color) ArrayList(java.util.ArrayList)

Example 2 with ColourRamp

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);
}
Also used : JPanel(javax.swing.JPanel) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) XMLTwoColourRamp(com.sldeditor.common.xml.ui.XMLTwoColourRamp) ColourRamp(com.sldeditor.colourramp.ColourRamp) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldPanel(com.sldeditor.ui.widgets.FieldPanel) ColourRampConfigPanel(com.sldeditor.colourramp.ColourRampConfigPanel) ColourMapModel(com.sldeditor.ui.detail.config.colourmap.ColourMapModel)

Example 3 with ColourRamp

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;
}
Also used : XMLTwoColourRamp(com.sldeditor.common.xml.ui.XMLTwoColourRamp) ColourRamp(com.sldeditor.colourramp.ColourRamp) ArrayList(java.util.ArrayList) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData)

Example 4 with ColourRamp

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);
}
Also used : ColourRampData(com.sldeditor.colourramp.ramp.ColourRampData) ImageIcon(javax.swing.ImageIcon) ColourRamp(com.sldeditor.colourramp.ColourRamp) Expression(org.opengis.filter.expression.Expression) Color(java.awt.Color) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 5 with ColourRamp

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());
}
Also used : ColourRampData(com.sldeditor.colourramp.ramp.ColourRampData) ColourRamp(com.sldeditor.colourramp.ColourRamp) Test(org.junit.Test)

Aggregations

ColourRamp (com.sldeditor.colourramp.ColourRamp)5 XMLTwoColourRamp (com.sldeditor.common.xml.ui.XMLTwoColourRamp)3 ColourRampData (com.sldeditor.colourramp.ramp.ColourRampData)2 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)2 Color (java.awt.Color)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ColourRampConfigPanel (com.sldeditor.colourramp.ColourRampConfigPanel)1 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)1 FieldConfigInteger (com.sldeditor.ui.detail.config.FieldConfigInteger)1 ColourMapModel (com.sldeditor.ui.detail.config.colourmap.ColourMapModel)1 FieldPanel (com.sldeditor.ui.widgets.FieldPanel)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 BoxLayout (javax.swing.BoxLayout)1 ImageIcon (javax.swing.ImageIcon)1 JButton (javax.swing.JButton)1