Search in sources :

Example 1 with ColorPickerListener

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

the class ColorPanel method initColorFrame.

private void initColorFrame(Color color) {
    myColorFrame.setBackground(color);
    myColorFrame.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            ColorPicker.showDialog(myContentPane, "Edit color", color, true, new ColorPickerListener[] { new ColorPickerListener() {

                @Override
                public void colorChanged(Color color) {
                }

                @Override
                public void closed(@Nullable Color color) {
                    if (color != null) {
                        myColorName.setText(getColorHexString(color.getRGB()));
                    }
                }
            } }, true);
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            System.out.println("ColorPanel.mouseEntered");
            for (int i = 0; i < myListeners.size(); i++) {
                myListeners.get(i).entered(myExtractedColor);
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            for (int i = 0; i < myListeners.size(); i++) {
                myListeners.get(i).exited();
            }
        }
    });
}
Also used : ColorPickerListener(com.intellij.ui.ColorPickerListener) MouseEvent(java.awt.event.MouseEvent) ExtractedColor(com.android.tools.idea.uibuilder.mockup.colorextractor.ExtractedColor) JBColor(com.intellij.ui.JBColor) MouseAdapter(java.awt.event.MouseAdapter) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ColorPickerListener

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

the class UserColorLookup method handleUserSelection.

private static void handleUserSelection(InsertionContext context, @NotNull Function<Color, String> colorToStringConverter) {
    Project project = context.getProject();
    Editor editor = context.getEditor();
    int startOffset = context.getStartOffset();
    context.getDocument().deleteString(startOffset, context.getTailOffset());
    PsiElement element = context.getFile().findElementAt(editor.getCaretModel().getOffset());
    Color myColorAtCaret = element instanceof XmlToken ? getColorFromElement(element) : null;
    context.setLaterRunnable(() -> {
        if (editor.isDisposed() || project.isDisposed())
            return;
        List<ColorPickerListener> listeners = ColorPickerListenerFactory.createListenersFor(element);
        Color color = ColorChooser.chooseColor(WindowManager.getInstance().suggestParentWindow(project), XmlBundle.message("choose.color.dialog.title"), myColorAtCaret, true, listeners, true);
        if (color != null) {
            WriteCommandAction.runWriteCommandAction(project, () -> {
                editor.getCaretModel().moveToOffset(startOffset);
                EditorModificationUtil.insertStringAtCaret(editor, colorToStringConverter.fun(color));
            });
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) ColorPickerListener(com.intellij.ui.ColorPickerListener) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) XmlToken(com.intellij.psi.xml.XmlToken)

Aggregations

ColorPickerListener (com.intellij.ui.ColorPickerListener)2 ExtractedColor (com.android.tools.idea.uibuilder.mockup.colorextractor.ExtractedColor)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 XmlToken (com.intellij.psi.xml.XmlToken)1 JBColor (com.intellij.ui.JBColor)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 Nullable (org.jetbrains.annotations.Nullable)1