Search in sources :

Example 1 with ColorPanel

use of com.intellij.ui.ColorPanel in project android by JetBrains.

the class ColorPropertyTest method testColorProperty.

@Test
public void testColorProperty() throws Exception {
    ColorPanel colorPanel = new ColorPanel();
    ColorProperty color = new ColorProperty(colorPanel);
    CountListener listener = new CountListener();
    color.addListener(listener);
    assertThat(color.get().isPresent()).isFalse();
    assertThat(listener.getCount()).isEqualTo(0);
    colorPanel.setSelectedColor(Color.RED);
    assertThat(color.get().isPresent()).isTrue();
    assertThat(color.getValue()).isEqualTo(Color.RED);
    // ColorPanel only fires its listener when the button is clicked, not when color is set
    // programmatically. Otherwise, this should have been true:
    // assertThat(listener.getCount()).isEqualTo(1);
    color.setValue(Color.BLUE);
    assertThat(colorPanel.getSelectedColor()).isEqualTo(Color.BLUE);
    assertThat(listener.getCount()).isEqualTo(1);
    color.clear();
    assertThat(colorPanel.getSelectedColor()).isNull();
    assertThat(listener.getCount()).isEqualTo(2);
}
Also used : ColorPanel(com.intellij.ui.ColorPanel) CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Example 2 with ColorPanel

use of com.intellij.ui.ColorPanel in project android by JetBrains.

the class TemplateWizardStep method refreshUiFromParameters.

public void refreshUiFromParameters() {
    if (myTemplateState.myTemplate == null) {
        return;
    }
    for (Parameter param : myTemplateState.myTemplate.getMetadata().getParameters()) {
        if (param.initial != null && !myTemplateState.myModified.contains(param.id)) {
            myTemplateState.myParameters.remove(param.id);
        }
    }
    myTemplateState.setParameterDefaults();
    Template.convertApisToInt(myTemplateState.getParameters());
    boolean oldIgnoreUpdates = myIgnoreUpdates;
    try {
        myIgnoreUpdates = true;
        for (String paramName : myParamFields.keySet()) {
            if (myTemplateState.myHidden.contains(paramName)) {
                continue;
            }
            JComponent component = myParamFields.get(paramName);
            Object value = myTemplateState.get(paramName);
            if (value == null) {
                continue;
            }
            if (component instanceof JCheckBox) {
                ((JCheckBox) component).setSelected(Boolean.parseBoolean(value.toString()));
            } else if (component instanceof JComboBox) {
                for (int i = 0; i < ((JComboBox) component).getItemCount(); i++) {
                    if (((ApiComboBoxItem) ((JComboBox) component).getItemAt(i)).getData().equals(value)) {
                        ((JComboBox) component).setSelectedIndex(i);
                        break;
                    }
                }
            } else if (component instanceof JTextField) {
                ((JTextField) component).setText(value.toString());
            } else if (component instanceof TextFieldWithBrowseButton) {
                ((TextFieldWithBrowseButton) component).setText(value.toString());
            } else if (component instanceof JSlider) {
                ((JSlider) component).setValue(Integer.parseInt(value.toString()));
            } else if (component instanceof JSpinner) {
                ((JSpinner) component).setValue(Integer.parseInt(value.toString()));
            } else if (component instanceof ColorPanel) {
                ((ColorPanel) component).setSelectedColor((Color) value);
            }
        }
    } finally {
        myIgnoreUpdates = oldIgnoreUpdates;
    }
}
Also used : ApiComboBoxItem(com.android.tools.idea.ui.ApiComboBoxItem) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ColorPanel(com.intellij.ui.ColorPanel) Parameter(com.android.tools.idea.templates.Parameter)

Example 3 with ColorPanel

use of com.intellij.ui.ColorPanel in project android by JetBrains.

the class ScopedDataBinderTest method testRegisterColorPanel.

public void testRegisterColorPanel() throws Exception {
    Key<Color> colorKey = myState.createKey("colorPanel", Color.class);
    Key<Color> colorKey2 = myState.createKey("boundSecond", Color.class);
    final Key<String> triggerKey = myState.createKey("triggerKey", String.class);
    ColorPanel colorPanel = new ColorPanel();
    myScopedDataBinder.register(colorKey, colorPanel);
    myScopedDataBinder.register(colorKey2, colorPanel);
    // Test binding UI -> Store
    colorPanel.setSelectedColor(Color.BLUE);
    // ColorPanel doesn't call listeners on setSelectedColor, so we manually invoke here
    myScopedDataBinder.saveState(colorPanel);
    assertEquals(Color.BLUE, myState.get(colorKey));
    assertEquals(Color.BLUE, myState.get(colorKey2));
    // Test binding Store -> UI
    myState.put(colorKey, Color.RED);
    // ColorPanel doesn't call listeners on setSelectedColor, so we manually invoke here
    myScopedDataBinder.saveState(colorPanel);
    assertEquals(Color.RED, colorPanel.getSelectedColor());
    assertEquals(Color.RED, myState.get(colorKey2));
    myState.put(colorKey2, Color.GREEN);
    // ColorPanel doesn't call listeners on setSelectedColor, so we manually invoke here
    myScopedDataBinder.saveState(colorPanel);
    assertEquals(Color.GREEN, colorPanel.getSelectedColor());
    assertEquals(Color.GREEN, myState.get(colorKey));
    final AtomicBoolean respectsUserEdits = new AtomicBoolean(true);
    // Test value derivation
    myScopedDataBinder.registerValueDeriver(colorKey, new ValueDeriver<Color>() {

        @Nullable
        @Override
        public Set<Key<?>> getTriggerKeys() {
            return makeSetOf(triggerKey);
        }

        @Override
        public boolean respectUserEdits() {
            return respectsUserEdits.get();
        }

        @Override
        public Color deriveValue(ScopedStateStore state, Key changedKey, @Nullable Color currentValue) {
            String trigger = state.get(triggerKey);
            if (trigger == null) {
                return null;
            } else {
                return Color.decode(trigger);
            }
        }
    });
    myState.put(triggerKey, "Not A Value");
    // The deriver does not fire because user edits are respected
    assertEquals(Color.GREEN, colorPanel.getSelectedColor());
    respectsUserEdits.set(false);
    myState.put(triggerKey, "#FFFFFF");
    // The deriver fires because user edits are not respected
    assertEquals(Color.WHITE, colorPanel.getSelectedColor());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Set(java.util.Set) ColorPanel(com.intellij.ui.ColorPanel) Nullable(org.jetbrains.annotations.Nullable) Key(com.android.tools.idea.wizard.dynamic.ScopedStateStore.Key)

Example 4 with ColorPanel

use of com.intellij.ui.ColorPanel in project intellij-community by JetBrains.

the class ConfigUI method init.

private void init() {
    setLayout(new BorderLayout());
    JPanel c = this;
    scrollToFirst = new JCheckBox("Scroll first hit into visible area");
    scrollToFirst.setMnemonic('S');
    useContextAtCursor = new JCheckBox("Use node at cursor as context node");
    useContextAtCursor.setMnemonic('N');
    useContextAtCursor.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            stateChanged();
        }
    });
    highlightStartTagOnly = new JCheckBox("Highlight only start tag instead of whole tag content");
    highlightStartTagOnly.setMnemonic('H');
    addErrorStripe = new JCheckBox("Add error stripe markers for each result");
    addErrorStripe.setMnemonic('A');
    showInToolbar = new JCheckBox("Show actions in Toolbar");
    showInToolbar.setMnemonic('T');
    showInToolbar.setToolTipText("Uncheck to remove XPath-related actions from the toolbar");
    showInMainMenu = new JCheckBox("Show actions in Main Menu");
    showInMainMenu.setMnemonic('M');
    showInMainMenu.setToolTipText("Uncheck to remove XPath-related actions from the Main-Menubar");
    JPanel settings = new JPanel(new BorderLayout());
    settings.setBorder(IdeBorderFactory.createTitledBorder("Settings", true));
    c.add(c = new JPanel(new BorderLayout()), BorderLayout.NORTH);
    c.add(settings, BorderLayout.NORTH);
    settings.add(scrollToFirst, BorderLayout.NORTH);
    settings.add(settings = new JPanel(new BorderLayout()), BorderLayout.SOUTH);
    settings.add(useContextAtCursor, BorderLayout.NORTH);
    settings.add(settings = new JPanel(new BorderLayout()), BorderLayout.SOUTH);
    settings.add(highlightStartTagOnly, BorderLayout.NORTH);
    settings.add(settings = new JPanel(new BorderLayout()), BorderLayout.SOUTH);
    settings.add(addErrorStripe, BorderLayout.NORTH);
    settings.add(settings = new JPanel(new BorderLayout()), BorderLayout.SOUTH);
    settings.add(showInToolbar, BorderLayout.NORTH);
    settings.add(settings = new JPanel(new BorderLayout()), BorderLayout.SOUTH);
    settings.add(showInMainMenu, BorderLayout.NORTH);
    settings.add(/*settings = */
    new JPanel(new BorderLayout()), BorderLayout.SOUTH);
    JPanel colors = new JPanel(new GridBagLayout());
    colors.setBorder(IdeBorderFactory.createTitledBorder("Colors", true));
    c.add(c = new JPanel(new BorderLayout()), BorderLayout.SOUTH);
    c.add(colors, BorderLayout.NORTH);
    final GridBagConstraints constraints = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0);
    colors.add(new JLabel("Highlight color:"), constraints);
    constraints.gridx = 1;
    constraints.weightx = 1;
    chooseHighlight = new ColorPanel();
    colors.add(chooseHighlight, constraints);
    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.weightx = 0;
    colors.add(new JLabel("Context node color:"), constraints);
    constraints.gridx = 1;
    constraints.gridy = 1;
    constraints.weightx = 1;
    chooseContext = new ColorPanel();
    colors.add(chooseContext, constraints);
}
Also used : ActionListener(java.awt.event.ActionListener) ColorPanel(com.intellij.ui.ColorPanel) ActionEvent(java.awt.event.ActionEvent)

Aggregations

ColorPanel (com.intellij.ui.ColorPanel)4 Parameter (com.android.tools.idea.templates.Parameter)1 ApiComboBoxItem (com.android.tools.idea.ui.ApiComboBoxItem)1 CountListener (com.android.tools.idea.ui.properties.CountListener)1 Key (com.android.tools.idea.wizard.dynamic.ScopedStateStore.Key)1 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Nullable (org.jetbrains.annotations.Nullable)1 Test (org.junit.Test)1