Search in sources :

Example 6 with EditedStyleItem

use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.

the class AttributesGrouper method generateLabelsForGroup.

@NotNull
private static List<TableLabel> generateLabelsForGroup(final List<EditedStyleItem> source, final List<EditedStyleItem> sink) {
    // A TreeMap is used to ensure the keys are sorted in alphabetical order
    // ArrayLists are used for values to ensure that they stay in the same order they came in
    Multimap<String, EditedStyleItem> classes = Multimaps.newListMultimap(new TreeMap<String, Collection<EditedStyleItem>>(), new Supplier<List<EditedStyleItem>>() {

        @Override
        public List<EditedStyleItem> get() {
            return new ArrayList<EditedStyleItem>();
        }
    });
    for (EditedStyleItem item : source) {
        String group = item.getAttrGroup();
        classes.put(group, item);
    }
    final List<TableLabel> labels = new ArrayList<TableLabel>();
    int offset = 0;
    sink.clear();
    for (String group : classes.keySet()) {
        final int size = classes.get(group).size();
        sink.addAll(classes.get(group));
        if (size != 0) {
            labels.add(new TableLabel(group, offset));
        }
        offset += size;
    }
    return labels;
}
Also used : EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) ImmutableList(com.google.common.collect.ImmutableList) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with EditedStyleItem

use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.

the class AttributesModelColorPaletteModel method loadColors.

private void loadColors() {
    if (myResourceResolver == null) {
        myColorList = Collections.emptyList();
        return;
    }
    int rows = myModel.getRowCount();
    Multiset<Color> colorSet = HashMultiset.create();
    for (int i = 0; i < rows; i++) {
        if (myModel.getCellClass(i, 0) != Color.class) {
            continue;
        }
        EditedStyleItem item = (EditedStyleItem) myModel.getValueAt(i, 0);
        for (Color color : ResourceHelper.resolveMultipleColors(myResourceResolver, item.getSelectedValue(), myProject)) {
            myColorReferences.put(color, item);
            colorSet.add(color);
        }
    }
    myColorList = ImmutableList.copyOf(Multisets.copyHighestCountFirst(colorSet).elementSet());
}
Also used : EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Example 8 with EditedStyleItem

use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.

the class ShowJavadocAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    EditedStyleItem item = myCurrentItem;
    if (item == null) {
        return;
    }
    Project project = myContext.getProject();
    DocumentationManager documentationManager = DocumentationManager.getInstance(project);
    final DocumentationComponent docComponent = new DocumentationComponent(documentationManager);
    String tooltip = ThemeEditorUtils.generateToolTipText(item.getSelectedValue(), myContext.getCurrentContextModule(), myContext.getConfiguration());
    // images will not work unless we pass a valid PsiElement {@link DocumentationComponent#myImageProvider}
    docComponent.setText(tooltip, new FakePsiElement() {

        @Override
        public boolean isValid() {
            // this needs to return true for the DocumentationComponent to accept this PsiElement {@link DocumentationComponent#setData(PsiElement, String, boolean, String, String)}
            return true;
        }

        @NotNull
        @Override
        public Project getProject() {
            // superclass implementation throws an exception
            return myContext.getProject();
        }

        @Override
        public PsiElement getParent() {
            return null;
        }

        @Override
        public PsiFile getContainingFile() {
            // superclass implementation throws an exception
            return null;
        }
    }, true);
    JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(docComponent, docComponent).setProject(project).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(item.getName()).setCancelCallback(new Computable<Boolean>() {

        @Override
        public Boolean compute() {
            Disposer.dispose(docComponent);
            return Boolean.TRUE;
        }
    }).createPopup();
    docComponent.setHint(hint);
    Disposer.register(hint, docComponent);
    hint.show(new RelativePoint(myAttributesTable.getParent(), ORIGIN));
}
Also used : DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) FakePsiElement(com.intellij.psi.impl.FakePsiElement) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) PsiFile(com.intellij.psi.PsiFile) JBPopup(com.intellij.openapi.ui.popup.JBPopup) FakePsiElement(com.intellij.psi.impl.FakePsiElement) PsiElement(com.intellij.psi.PsiElement) Computable(com.intellij.openapi.util.Computable)

Example 9 with EditedStyleItem

use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.

the class IntegerRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (!(value instanceof EditedStyleItem)) {
        LOG.error(String.format("Passed %1$s instead of EditedStyleItem", value.getClass().getName()));
        return null;
    }
    EditedStyleItem item = (EditedStyleItem) value;
    final Component component;
    if (column == 0) {
        component = table.getDefaultRenderer(String.class).getTableCellRendererComponent(table, ThemeEditorUtils.getDisplayHtml(item), isSelected, hasFocus, row, column);
    } else {
        component = super.getTableCellRendererComponent(table, item.getValue(), isSelected, hasFocus, row, column);
    }
    return component;
}
Also used : EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Example 10 with EditedStyleItem

use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.

the class ThemeEditorComponent method loadStyleAttributes.

/**
   * Loads the theme attributes table for the current selected theme or substyle.
   */
private void loadStyleAttributes() {
    ConfiguredThemeEditorStyle selectedTheme = getPreviewTheme();
    ConfiguredThemeEditorStyle selectedStyle = null;
    if (selectedTheme == null) {
        selectedTheme = getSelectedTheme();
        selectedStyle = getCurrentSubStyle();
    }
    // Clean any previous row sorters.
    myAttributesTable.setRowSorter(null);
    myPanel.setSubstyleName(mySubStyleName);
    myPanel.getBackButton().setVisible(mySubStyleName != null);
    AndroidThemePreviewPanel previewPanel = myPreviewComponent.getPreviewPanel();
    if (selectedTheme == null) {
        if (myThemeName != null) {
            previewPanel.setErrorMessage("The theme " + myThemeName + " cannot be rendered in the current configuration");
        } else {
            previewPanel.setErrorMessage("No theme selected");
        }
        myAttributesTable.setModel(EMPTY_TABLE_MODEL);
        return;
    }
    previewPanel.setErrorMessage(null);
    myPanel.setShowThemeNotUsedWarning(false);
    if (selectedTheme.isProjectStyle()) {
        // Check whenever we reload the theme as any external file could have been changed that would affect this.
        // e.g. change to the manifest to use a theme.
        final PsiElement name = selectedTheme.getNamePsiElement();
        mySwingWorker = new SwingWorker<Boolean, Object>() {

            @Override
            protected Boolean doInBackground() throws Exception {
                // it's a project theme, so we should always have a name.
                assert name != null;
                return ReferencesSearch.search(name).findFirst() == null;
            }

            @Override
            protected void done() {
                if (isCancelled()) {
                    return;
                }
                try {
                    myPanel.setShowThemeNotUsedWarning(get());
                } catch (Exception ex) {
                    // should never happen, as we are calling get from done.
                    throw new RuntimeException(ex);
                }
            }
        };
        mySwingWorker.execute();
    }
    myThemeEditorContext.setCurrentTheme(selectedTheme);
    final Configuration configuration = myThemeEditorContext.getConfiguration();
    configuration.setTheme(selectedTheme.getStyleResourceUrl());
    myModel = new AttributesTableModel(selectedStyle != null ? selectedStyle : selectedTheme, getSelectedAttrGroup(), myThemeEditorContext);
    myModel.addThemePropertyChangedListener(new AttributesTableModel.ThemePropertyChangedListener() {

        @Override
        public void attributeChangedOnReadOnlyTheme(final EditedStyleItem attribute, final String newValue) {
            createNewThemeWithAttributeValue(attribute, newValue);
        }
    });
    myAttributesSorter = new TableRowSorter<AttributesTableModel>(myModel);
    // This is only used when the sort keys are set (only set in simple mode).
    myAttributesSorter.setComparator(0, SIMPLE_MODE_COMPARATOR);
    configureFilter();
    int row = myAttributesTable.getEditingRow();
    int column = myAttributesTable.getEditingColumn();
    // If an editor is present, remove it to update the entire table, do nothing otherwise
    myAttributesTable.removeEditor();
    // update the table
    myAttributesTable.setModel(myModel);
    myAttributesTable.setRowSorter(myAttributesSorter);
    myAttributesTable.updateRowHeights();
    // as a refresh can happen at any point, we want to restore the editor if one was present, do nothing otherwise
    myAttributesTable.editCellAt(row, column);
    myPanel.getPalette().setModel(new AttributesModelColorPaletteModel(configuration, myModel));
    myPanel.getPalette().addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                AttributesModelColorPaletteModel model = (AttributesModelColorPaletteModel) myPanel.getPalette().getModel();
                List<EditedStyleItem> references = model.getReferences((Color) e.getItem());
                if (references.isEmpty()) {
                    return;
                }
                HashSet<String> attributeNames = new HashSet<String>(references.size());
                for (EditedStyleItem item : references) {
                    attributeNames.add(item.getQualifiedName());
                }
                myAttributesFilter.setAttributesFilter(attributeNames);
                myAttributesFilter.setFilterEnabled(true);
            } else {
                myAttributesFilter.setFilterEnabled(false);
            }
            if (myAttributesTable.isEditing()) {
                myAttributesTable.getCellEditor().cancelCellEditing();
            }
            ((TableRowSorter) myAttributesTable.getRowSorter()).sort();
            myPanel.getAdvancedFilterCheckBox().getModel().setSelected(!myAttributesFilter.myIsFilterEnabled);
        }
    });
    myAttributesTable.updateRowHeights();
    ResourceResolver resourceResolver = myThemeEditorContext.getResourceResolver();
    assert resourceResolver != null;
    myPreviewComponent.setPreviewBackground(ThemeEditorUtils.getGoodContrastPreviewBackground(selectedTheme, resourceResolver));
    myPreviewComponent.reloadPreviewContents();
    myAttributesTable.repaint();
    myPanel.getThemeCombo().repaint();
}
Also used : AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel) ItemEvent(java.awt.event.ItemEvent) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) AndroidThemePreviewPanel(com.android.tools.idea.editors.theme.preview.AndroidThemePreviewPanel) AttributesModelColorPaletteModel(com.android.tools.idea.editors.theme.attributes.AttributesModelColorPaletteModel) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ItemListener(java.awt.event.ItemListener) List(java.util.List) PsiElement(com.intellij.psi.PsiElement)

Aggregations

EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)17 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)6 Configuration (com.android.tools.idea.configurations.Configuration)5 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)4 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)4 ResourceResolver (com.android.ide.common.resources.ResourceResolver)2 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)2 ImmutableList (com.google.common.collect.ImmutableList)2 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 Configurable (com.android.ide.common.resources.configuration.Configurable)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 AttributesModelColorPaletteModel (com.android.tools.idea.editors.theme.attributes.AttributesModelColorPaletteModel)1 ConfiguredElement (com.android.tools.idea.editors.theme.datamodels.ConfiguredElement)1 ThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle)1 AndroidThemePreviewPanel (com.android.tools.idea.editors.theme.preview.AndroidThemePreviewPanel)1 RestrictedConfiguration (com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration)1