From f6bf771eb2f7463e1e347d8a1eb08b95663a202b Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Tue, 17 Jul 2012 15:32:49 +0400 Subject: [PATCH] Work on Android Resources --- .../propertyTable/editors/ResourceDialog.java | 38 +- .../propertyTable/editors/ResourceEditor.java | 636 +++++++++--------- .../renderers/ResourceRenderer.java | 19 +- 3 files changed, 375 insertions(+), 318 deletions(-) diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/editors/ResourceDialog.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/editors/ResourceDialog.java index b2a9055fca5e..464d3b747d8c 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/editors/ResourceDialog.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/editors/ResourceDialog.java @@ -29,6 +29,7 @@ import com.intellij.ide.util.treeView.NodeDescriptor; import com.intellij.ide.util.treeView.NodeRenderer; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.module.Module; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.Disposer; @@ -368,7 +369,7 @@ public class ResourceDialog extends DialogWrapper implements TreeSelectionListen myResultResourceName = prefix + element.getName(); } - panel.showPreview(element, isProjectPanel); + panel.showPreview(element); } } @@ -469,7 +470,7 @@ public class ResourceDialog extends DialogWrapper implements TreeSelectionListen myPreviewPanel.add(myNoPreviewComponent, NONE); } - public void showPreview(@Nullable ResourceItem element, boolean isProjectPanel) { + public void showPreview(@Nullable ResourceItem element) { CardLayout layout = (CardLayout)myPreviewPanel.getLayout(); if (element == null) { @@ -487,7 +488,9 @@ public class ResourceDialog extends DialogWrapper implements TreeSelectionListen if (values == null) { long time = System.currentTimeMillis(); List resources = myManager.findValueResources(element.getGroup().getType().getName(), element.toString()); - System.out.println("Time: " + (System.currentTimeMillis() - time)); + if (ApplicationManagerEx.getApplicationEx().isInternal()) { + System.out.println("Time: " + (System.currentTimeMillis() - time)); // XXX + } int size = resources.size(); if (size == 1) { @@ -506,25 +509,48 @@ public class ResourceDialog extends DialogWrapper implements TreeSelectionListen } element.setPreviewStrings(values, tabNames); } + else { + layout.show(myPreviewPanel, NONE); + return; + } } if (values != null) { + int selectedIndex = myTabbedPane.getSelectedIndex(); myTabbedPane.removeAll(); String[] tabNames = element.getTabNames(); + + if (selectedIndex == -1) { + for (int i = 0; i < tabNames.length; i++) { + if (tabNames[i].startsWith("en")) { + selectedIndex = i; + break; + } + } + } + for (int i = 0; i < tabNames.length; i++) { JTextArea textArea = new JTextArea(5, 20); textArea.setText(values[i]); - textArea.setEditable(isProjectPanel); + textArea.setEditable(false); myTabbedPane.addTab(tabNames[i], ScrollPaneFactory.createScrollPane(textArea)); } + if (selectedIndex >= 0 && selectedIndex < tabNames.length) { + myTabbedPane.setSelectedIndex(selectedIndex); + } layout.show(myPreviewPanel, TABS); return; } } + if (value == null) { + layout.show(myPreviewPanel, NONE); + return; + } + myTextArea.setText(value); - myTextArea.setEditable(isProjectPanel); + myTextArea.setEditable(false); layout.show(myPreviewPanel, TEXT); } else if (ImageFileTypeManager.getInstance().isImage(file)) { @@ -543,7 +569,7 @@ public class ResourceDialog extends DialogWrapper implements TreeSelectionListen element.setPreviewString(value); } myTextArea.setText(value); - myTextArea.setEditable(isProjectPanel); + myTextArea.setEditable(false); layout.show(myPreviewPanel, TEXT); } else { diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/editors/ResourceEditor.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/editors/ResourceEditor.java index 08e77149986c..0a3cd6adbce9 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/editors/ResourceEditor.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/editors/ResourceEditor.java @@ -1,309 +1,329 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.android.designer.propertyTable.editors; - -import com.android.resources.ResourceType; -import com.intellij.android.designer.model.ModelParser; -import com.intellij.android.designer.model.RadViewComponent; -import com.intellij.designer.ModuleProvider; -import com.intellij.designer.model.RadComponent; -import com.intellij.designer.propertyTable.InplaceContext; -import com.intellij.designer.propertyTable.PropertyEditor; -import com.intellij.designer.propertyTable.editors.ComboEditor; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.ComponentWithBrowseButton; -import com.intellij.openapi.ui.TextFieldWithBrowseButton; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.ui.ComboboxWithBrowseButton; -import com.intellij.ui.DocumentAdapter; -import org.jetbrains.android.dom.attrs.AttributeFormat; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.border.Border; -import javax.swing.event.DocumentEvent; -import java.awt.*; -import java.awt.event.*; -import java.util.EnumSet; -import java.util.Set; - -/** - * @author Alexander Lobas - */ -public class ResourceEditor extends PropertyEditor { - private final ResourceType[] myTypes; - private ComponentWithBrowseButton myEditor; - protected RadComponent myRootComponent; - private RadComponent myComponent; - private JCheckBox myCheckBox; - private final Border myCheckBoxBorder = new JTextField().getBorder(); - private boolean myIgnoreCheckBoxValue; - private String myBooleanResourceValue; - - public ResourceEditor(Set formats, String[] values) { - this(convertTypes(formats), formats, values); - } - - public ResourceEditor(ResourceType[] types, Set formats, String[] values) { - myTypes = types; - - if (formats.contains(AttributeFormat.Boolean)) { - myCheckBox = new JCheckBox(); - myEditor = new ComponentWithBrowseButton(myCheckBox, null) { - @Override - public Dimension getPreferredSize() { - return getComponentPreferredSize(); - } - }; - myCheckBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - if (!myIgnoreCheckBoxValue) { - myBooleanResourceValue = null; - fireValueCommitted(true, true); - } - } - }); - } - else if (formats.contains(AttributeFormat.Enum)) { - ComboboxWithBrowseButton editor = new ComboboxWithBrowseButton() { - @Override - public Dimension getPreferredSize() { - return getComponentPreferredSize(); - } - }; - - final JComboBox comboBox = editor.getComboBox(); - DefaultComboBoxModel model; - if (formats.contains(AttributeFormat.Boolean)) { - model = new DefaultComboBoxModel(new String[]{StringsComboEditor.UNSET, "true", "false"}); - } - else { - model = new DefaultComboBoxModel(values); - model.insertElementAt(StringsComboEditor.UNSET, 0); - } - comboBox.setModel(model); - comboBox.setEditable(true); - ComboEditor.addEditorSupport(this, comboBox); - comboBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (comboBox.getSelectedItem() == StringsComboEditor.UNSET) { - comboBox.setSelectedItem(null); - } - fireValueCommitted(true, true); - } - }); - myEditor = editor; - comboBox.setSelectedIndex(0); - } - else { - myEditor = new TextFieldWithBrowseButton() { - @Override - protected void installPathCompletion(@Nullable Project project, - FileChooserDescriptor fileChooserDescriptor, - @Nullable Disposable parent) { - } - - @Override - public Dimension getPreferredSize() { - return getComponentPreferredSize(); - } - }; - myEditor.registerKeyboardAction(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - } - }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - - JTextField textField = getComboText(); - textField.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - fireValueCommitted(true, true); - } - }); - textField.getDocument().addDocumentListener( - new DocumentAdapter() { - protected void textChanged(final DocumentEvent e) { - preferredSizeChanged(); - } - } - ); - } - - myEditor.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - showDialog(); - } - }); - myEditor.addFocusListener(new FocusAdapter() { - @Override - public void focusGained(FocusEvent e) { - myEditor.getChildComponent().requestFocus(); - } - }); - } - - private Dimension getComponentPreferredSize() { - Dimension size1 = myEditor.getChildComponent().getPreferredSize(); - Dimension size2 = myEditor.getButton().getPreferredSize(); - return new Dimension(Math.max(size1.width, 25) + 5 + size2.width, size1.height); - } - - public static ResourceType[] COLOR_TYPES = {ResourceType.COLOR, ResourceType.DRAWABLE}; - - private static ResourceType[] convertTypes(Set formats) { - Set types = EnumSet.noneOf(ResourceType.class); - for (AttributeFormat format : formats) { - switch (format) { - case Boolean: - types.add(ResourceType.BOOL); - break; - case Color: - return COLOR_TYPES; - case Dimension: - types.add(ResourceType.DIMEN); - break; - case Integer: - types.add(ResourceType.INTEGER); - break; - case String: - types.add(ResourceType.STRING); - break; - case Reference: - types.add(ResourceType.COLOR); - types.add(ResourceType.DRAWABLE); - types.add(ResourceType.STRING); - types.add(ResourceType.ID); - types.add(ResourceType.STYLE); - break; - } - } - - return types.toArray(new ResourceType[types.size()]); - } - - @NotNull - @Override - public JComponent getComponent(@NotNull RadComponent rootComponent, - @Nullable RadComponent component, - Object object, - @Nullable InplaceContext inplaceContext) { - myRootComponent = rootComponent; - myComponent = component; - String value = (String)object; - JTextField text = getComboText(); - - if (text == null) { - if (StringUtil.isEmpty(value) || value.equals("true") || value.equals("false")) { - myBooleanResourceValue = null; - } - else { - myBooleanResourceValue = value; - } - - try { - myIgnoreCheckBoxValue = true; - myCheckBox.setSelected(Boolean.parseBoolean(value)); - } - finally { - myIgnoreCheckBoxValue = false; - } - - if (inplaceContext == null) { - myEditor.setBorder(null); - myCheckBox.setText(null); - } - else { - myEditor.setBorder(myCheckBoxBorder); - myCheckBox.setText(myBooleanResourceValue); - } - } - else { - text.setText(value); - if (inplaceContext != null) { - text.setColumns(0); - if (inplaceContext.isStartChar()) { - text.setText(inplaceContext.getText(text.getText())); - } - } - } - return myEditor; - } - - @Override - public JComponent getPreferredFocusedComponent() { - JTextField text = getComboText(); - return text == null ? myCheckBox : text; - } - - @Override - public Object getValue() { - JTextField text = getComboText(); - if (text == null) { - return myBooleanResourceValue == null ? Boolean.toString(myCheckBox.isSelected()) : myBooleanResourceValue; - } - String value = text.getText(); - return value == StringsComboEditor.UNSET || StringUtil.isEmpty(value) ? null : value; - } - - @Override - public void updateUI() { - SwingUtilities.updateComponentTreeUI(myEditor); - } - - protected void showDialog() { - ModuleProvider moduleProvider = myRootComponent.getClientProperty(ModelParser.MODULE_KEY); - ResourceDialog dialog = new ResourceDialog(moduleProvider.getModule(), myTypes, (String)getValue(), (RadViewComponent)myComponent); - dialog.show(); - - if (dialog.isOK()) { - setValue(dialog.getResourceName()); - } - else if (myBooleanResourceValue != null) { - fireEditingCancelled(); - } - } - - protected final void setValue(String value) { - JTextField text = getComboText(); - if (text == null) { - myBooleanResourceValue = value; - fireValueCommitted(false, true); - } - else { - text.setText(value); - fireValueCommitted(true, true); - } - } - - private JTextField getComboText() { - JComponent component = myEditor.getChildComponent(); - if (component instanceof JTextField) { - return (JTextField)component; - } - if (component instanceof JComboBox) { - JComboBox combo = (JComboBox)component; - return (JTextField)combo.getEditor().getEditorComponent(); - } - return null; - } +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.android.designer.propertyTable.editors; + +import com.android.resources.ResourceType; +import com.intellij.android.designer.model.ModelParser; +import com.intellij.android.designer.model.RadViewComponent; +import com.intellij.android.designer.propertyTable.renderers.ResourceRenderer; +import com.intellij.designer.ModuleProvider; +import com.intellij.designer.model.RadComponent; +import com.intellij.designer.propertyTable.InplaceContext; +import com.intellij.designer.propertyTable.PropertyEditor; +import com.intellij.designer.propertyTable.editors.ComboEditor; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.ComponentWithBrowseButton; +import com.intellij.openapi.ui.TextFieldWithBrowseButton; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.ComboboxWithBrowseButton; +import com.intellij.ui.DocumentAdapter; +import com.intellij.util.ArrayUtil; +import org.jetbrains.android.dom.attrs.AttributeFormat; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.event.DocumentEvent; +import java.awt.*; +import java.awt.event.*; +import java.util.EnumSet; +import java.util.Set; + +/** + * @author Alexander Lobas + */ +public class ResourceEditor extends PropertyEditor { + private final ResourceType[] myTypes; + private ComponentWithBrowseButton myEditor; + protected RadComponent myRootComponent; + private RadComponent myComponent; + private JCheckBox myCheckBox; + private final Border myCheckBoxBorder = new JTextField().getBorder(); + private boolean myIgnoreCheckBoxValue; + private String myBooleanResourceValue; + private final boolean myIsDimension; + + public ResourceEditor(Set formats, String[] values) { + this(convertTypes(formats), formats, values); + } + + public ResourceEditor(ResourceType[] types, Set formats, String[] values) { + myTypes = types; + myIsDimension = formats.contains(AttributeFormat.Dimension); + + if (formats.contains(AttributeFormat.Boolean)) { + myCheckBox = new JCheckBox(); + myEditor = new ComponentWithBrowseButton(myCheckBox, null) { + @Override + public Dimension getPreferredSize() { + return getComponentPreferredSize(); + } + }; + myCheckBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (!myIgnoreCheckBoxValue) { + myBooleanResourceValue = null; + fireValueCommitted(true, true); + } + } + }); + } + else if (formats.contains(AttributeFormat.Enum)) { + ComboboxWithBrowseButton editor = new ComboboxWithBrowseButton() { + @Override + public Dimension getPreferredSize() { + return getComponentPreferredSize(); + } + }; + + final JComboBox comboBox = editor.getComboBox(); + DefaultComboBoxModel model; + if (formats.contains(AttributeFormat.Boolean)) { + model = new DefaultComboBoxModel(new String[]{StringsComboEditor.UNSET, "true", "false"}); + } + else { + model = new DefaultComboBoxModel(values); + model.insertElementAt(StringsComboEditor.UNSET, 0); + } + comboBox.setModel(model); + comboBox.setEditable(true); + ComboEditor.addEditorSupport(this, comboBox); + comboBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (comboBox.getSelectedItem() == StringsComboEditor.UNSET) { + comboBox.setSelectedItem(null); + } + fireValueCommitted(true, true); + } + }); + myEditor = editor; + comboBox.setSelectedIndex(0); + } + else { + myEditor = new TextFieldWithBrowseButton() { + @Override + protected void installPathCompletion(@Nullable Project project, + FileChooserDescriptor fileChooserDescriptor, + @Nullable Disposable parent) { + } + + @Override + public Dimension getPreferredSize() { + return getComponentPreferredSize(); + } + }; + myEditor.registerKeyboardAction(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + + JTextField textField = getComboText(); + textField.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + fireValueCommitted(true, true); + } + }); + textField.getDocument().addDocumentListener( + new DocumentAdapter() { + protected void textChanged(final DocumentEvent e) { + preferredSizeChanged(); + } + } + ); + } + + myEditor.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + showDialog(); + } + }); + myEditor.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + myEditor.getChildComponent().requestFocus(); + } + }); + } + + private Dimension getComponentPreferredSize() { + Dimension size1 = myEditor.getChildComponent().getPreferredSize(); + Dimension size2 = myEditor.getButton().getPreferredSize(); + return new Dimension(Math.max(size1.width, 25) + 5 + size2.width, size1.height); + } + + public static ResourceType[] COLOR_TYPES = {ResourceType.COLOR, ResourceType.DRAWABLE}; + + private static ResourceType[] convertTypes(Set formats) { + Set types = EnumSet.noneOf(ResourceType.class); + for (AttributeFormat format : formats) { + switch (format) { + case Boolean: + types.add(ResourceType.BOOL); + break; + case Color: + return COLOR_TYPES; + case Dimension: + types.add(ResourceType.DIMEN); + break; + case Integer: + types.add(ResourceType.INTEGER); + break; + case String: + types.add(ResourceType.STRING); + break; + case Reference: + types.add(ResourceType.COLOR); + types.add(ResourceType.DRAWABLE); + types.add(ResourceType.STRING); + types.add(ResourceType.ID); + types.add(ResourceType.STYLE); + break; + } + } + + return types.toArray(new ResourceType[types.size()]); + } + + @NotNull + @Override + public JComponent getComponent(@NotNull RadComponent rootComponent, + @Nullable RadComponent component, + Object object, + @Nullable InplaceContext inplaceContext) { + myRootComponent = rootComponent; + myComponent = component; + String value = (String)object; + JTextField text = getComboText(); + + if (text == null) { + if (StringUtil.isEmpty(value) || value.equals("true") || value.equals("false")) { + myBooleanResourceValue = null; + } + else { + myBooleanResourceValue = value; + } + + try { + myIgnoreCheckBoxValue = true; + myCheckBox.setSelected(Boolean.parseBoolean(value)); + } + finally { + myIgnoreCheckBoxValue = false; + } + + if (inplaceContext == null) { + myEditor.setBorder(null); + myCheckBox.setText(null); + } + else { + myEditor.setBorder(myCheckBoxBorder); + myCheckBox.setText(myBooleanResourceValue); + } + } + else { + text.setText(value); + if (inplaceContext != null) { + text.setColumns(0); + if (inplaceContext.isStartChar()) { + text.setText(inplaceContext.getText(text.getText())); + } + } + } + return myEditor; + } + + @Override + public JComponent getPreferredFocusedComponent() { + JTextField text = getComboText(); + return text == null ? myCheckBox : text; + } + + @Override + public Object getValue() { + JTextField text = getComboText(); + if (text == null) { + return myBooleanResourceValue == null ? Boolean.toString(myCheckBox.isSelected()) : myBooleanResourceValue; + } + String value = text.getText(); + if (value == StringsComboEditor.UNSET || StringUtil.isEmpty(value)) { + return null; + } + if (myIsDimension && + !value.equalsIgnoreCase("wrap_content") && + !value.equalsIgnoreCase("fill_parent") && + !value.equalsIgnoreCase("match_parent")) { + if (value.length() <= 2) { + return value + "dp"; + } + int index = value.length() - 2; + String dimension = value.substring(index); + if (ArrayUtil.indexOf(ResourceRenderer.DIMENSIONS, dimension) == -1) { + return value + "dp"; + } + } + return value; + } + + @Override + public void updateUI() { + SwingUtilities.updateComponentTreeUI(myEditor); + } + + protected void showDialog() { + ModuleProvider moduleProvider = myRootComponent.getClientProperty(ModelParser.MODULE_KEY); + ResourceDialog dialog = new ResourceDialog(moduleProvider.getModule(), myTypes, (String)getValue(), (RadViewComponent)myComponent); + dialog.show(); + + if (dialog.isOK()) { + setValue(dialog.getResourceName()); + } + else if (myBooleanResourceValue != null) { + fireEditingCancelled(); + } + } + + protected final void setValue(String value) { + JTextField text = getComboText(); + if (text == null) { + myBooleanResourceValue = value; + fireValueCommitted(false, true); + } + else { + text.setText(value); + fireValueCommitted(true, true); + } + } + + private JTextField getComboText() { + JComponent component = myEditor.getChildComponent(); + if (component instanceof JTextField) { + return (JTextField)component; + } + if (component instanceof JComboBox) { + JComboBox combo = (JComboBox)component; + return (JTextField)combo.getEditor().getEditorComponent(); + } + return null; + } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/renderers/ResourceRenderer.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/renderers/ResourceRenderer.java index c669a9ab0a65..8c1e81bbee35 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/renderers/ResourceRenderer.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/renderers/ResourceRenderer.java @@ -27,6 +27,7 @@ import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.ArrayUtil; import com.intellij.util.ui.EmptyIcon; import org.jetbrains.android.dom.attrs.AttributeFormat; +import org.jetbrains.android.dom.resources.ResourceElement; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.android.resourceManagers.ResourceManager; import org.jetbrains.android.util.AndroidUtils; @@ -35,7 +36,8 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.util.Set; +import java.util.*; +import java.util.List; /** * @author Alexander Lobas @@ -77,6 +79,7 @@ public class ResourceRenderer implements PropertyRenderer { protected void formatValue(RadComponent component, String value) { if (!StringUtil.isEmpty(value)) { + StringBuilder colorValue = new StringBuilder(); boolean system = false; int prefix = -1; if (value.startsWith("#")) { @@ -91,7 +94,7 @@ public class ResourceRenderer implements PropertyRenderer { } if (prefix != -1) { myColoredComponent.append(value.substring(0, prefix), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); - myColoredComponent.append(value.substring(prefix), textStyle(component, value, system)); + myColoredComponent.append(value.substring(prefix), textStyle(component, value, system, colorValue)); } else if (myFormats.contains(AttributeFormat.Dimension) && value.length() > 2) { int index = value.length() - 2; @@ -107,6 +110,9 @@ public class ResourceRenderer implements PropertyRenderer { else { myColoredComponent.append(value); } + if (colorValue.length() > 0) { + value = colorValue.toString(); + } if (myFormats.contains(AttributeFormat.Color) && value.startsWith("#")) { try { Color color = parseColor(value); @@ -121,7 +127,7 @@ public class ResourceRenderer implements PropertyRenderer { } } - private static SimpleTextAttributes textStyle(RadComponent component, String value, boolean system) { + private static SimpleTextAttributes textStyle(RadComponent component, String value, boolean system, StringBuilder colorValue) { if (value.startsWith("@") && !value.startsWith("@id/") && !value.startsWith("@+id/") && !value.startsWith("@android:id/")) { try { int start = system ? ANDROID_PREFIX.length() : 1; @@ -132,8 +138,13 @@ public class ResourceRenderer implements PropertyRenderer { ModuleProvider moduleProvider = component.getRoot().getClientProperty(ModelParser.MODULE_KEY); AndroidFacet facet = AndroidFacet.getInstance(moduleProvider.getModule()); ResourceManager manager = facet.getResourceManager(system ? AndroidUtils.SYSTEM_RESOURCE_PACKAGE : null); + List resources = manager.findValueResources(type, name, false); - if (manager.findValueResources(type, name, false).isEmpty() && manager.findResourceFiles(type, name, false).isEmpty()) { + if ("color".equalsIgnoreCase(type) && !resources.isEmpty()) { + colorValue.append(resources.get(0).getRawText()); + } + + if (resources.isEmpty() && manager.findResourceFiles(type, name, false).isEmpty()) { return SimpleTextAttributes.ERROR_ATTRIBUTES; } }