Android Designer

This commit is contained in:
Alexander Lobas
2012-02-08 23:01:34 +04:00
parent 00798bd9a1
commit 64e49569a2
18 changed files with 735 additions and 1 deletions
@@ -22,6 +22,8 @@
<orderEntry type="module" module-name="spellchecker" />
<orderEntry type="module" module-name="android" />
<orderEntry type="module" module-name="ui-designer-new" />
<orderEntry type="module" module-name="dom-impl" />
<orderEntry type="module" module-name="dom-openapi" />
</component>
</module>
@@ -2,9 +2,16 @@
<name>Android Designer</name>
<id>com.intellij.android-designer</id>
<vendor logo="/general/ijLogo.png">JetBrains</vendor>
<resource-bundle>messages.AndroidDesignerBundle</resource-bundle>
<depends>com.intellij.java-i18n</depends>
<depends>com.intellij.properties</depends>
<depends>org.jetbrains.android</depends>
<depends>com.intellij.ui-designer-new</depends>
<extensions defaultExtensionNs="com.intellij">
<fileEditorProvider implementation="com.intellij.android.designer.AndroidDesignerEditorProvider"/>
</extensions>
</idea-plugin>
@@ -0,0 +1,50 @@
/*
* 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;
import com.intellij.CommonBundle;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.PropertyKey;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.util.ResourceBundle;
/**
* @author yole
*/
public class AndroidDesignerBundle {
private static Reference<ResourceBundle> ourBundle;
@NonNls private static final String BUNDLE = "messages.AndroidDesignerBundle";
private AndroidDesignerBundle() {
}
public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) {
return CommonBundle.message(getBundle(), key, params);
}
private static ResourceBundle getBundle() {
ResourceBundle bundle = null;
if (ourBundle != null) bundle = ourBundle.get();
if (bundle == null) {
bundle = ResourceBundle.getBundle(BUNDLE);
ourBundle = new SoftReference<ResourceBundle>(bundle);
}
return bundle;
}
}
@@ -0,0 +1,65 @@
/*
* 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;
import com.intellij.openapi.fileEditor.FileEditorState;
import com.intellij.openapi.fileEditor.FileEditorStateLevel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.uiDesigner.DesignerEditor;
import org.jetbrains.annotations.NotNull;
/**
* @author Alexander Lobas
*/
public final class AndroidDesignerEditor extends DesignerEditor {
public AndroidDesignerEditor(Project project, VirtualFile file) {
super(project, file);
}
@NotNull
@Override
public String getName() {
return AndroidDesignerBundle.message("editor.tab.title");
}
@Override
public boolean isValid() {
return true; // TODO: Auto-generated method stub
}
@NotNull
@Override
public FileEditorState getState(@NotNull FileEditorStateLevel level) {
// TODO: Auto-generated method stub
return new FileEditorState() {
@Override
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
return false;
}
};
}
@Override
public void setState(@NotNull FileEditorState state) {
// TODO: Auto-generated method stub
}
@Override
public boolean isModified() {
return false;
}
}
@@ -0,0 +1,87 @@
/*
* 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;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.xml.XmlFile;
import org.jdom.Element;
import org.jetbrains.android.dom.layout.LayoutDomFileDescription;
import org.jetbrains.android.facet.AndroidFacet;
import org.jetbrains.annotations.NotNull;
/**
* @author Alexander Lobas
*/
public final class AndroidDesignerEditorProvider implements FileEditorProvider, DumbAware {
@Override
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null) {
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
return psiFile instanceof XmlFile &&
AndroidFacet.getInstance(psiFile) != null &&
LayoutDomFileDescription.isLayoutFile((XmlFile)psiFile);
}
return false;
}
@NotNull
@Override
public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
return new AndroidDesignerEditor(project, file);
}
@Override
public void disposeEditor(@NotNull FileEditor editor) {
Disposer.dispose(editor);
}
@NotNull
@Override
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
// TODO: Auto-generated method stub
return new FileEditorState() {
@Override
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
return false;
}
};
}
@Override
public void writeState(@NotNull FileEditorState state, @NotNull Project project, @NotNull Element targetElement) {
// TODO: Auto-generated method stub
}
@NotNull
@Override
public String getEditorTypeId() {
return "android-designer";
}
@NotNull
@Override
public FileEditorPolicy getPolicy() {
return FileEditorPolicy.PLACE_BEFORE_DEFAULT_EDITOR;
}
}
@@ -0,0 +1 @@
editor.tab.title=Design
@@ -1,8 +1,17 @@
<idea-plugin version="2">
<name>UI Designer</name>
<name>UI Designer (Core)</name>
<id>com.intellij.ui-designer-new</id>
<vendor logo="/general/ijLogo.png">JetBrains</vendor>
<resource-bundle>messages.UIDesignerBundle</resource-bundle>
<depends>com.intellij.java-i18n</depends>
<depends>com.intellij.properties</depends>
<project-components>
<component>
<implementation-class>com.intellij.uiDesigner.UIDesignerToolWindowManager</implementation-class>
</component>
</project-components>
</idea-plugin>
@@ -0,0 +1,97 @@
/*
* 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.uiDesigner;
import com.intellij.codeHighlighting.BackgroundEditorHighlighter;
import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorLocation;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.LightVirtualFile;
import com.intellij.uiDesigner.designSurface.DesignerEditorPanel;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.beans.PropertyChangeListener;
/**
* @author Alexander Lobas
*/
public abstract class DesignerEditor extends UserDataHolderBase implements FileEditor {
private final DesignerEditorPanel myDesignerPanel;
public DesignerEditor(Project project, VirtualFile file) {
if (file instanceof LightVirtualFile) {
file = ((LightVirtualFile)file).getOriginalFile();
}
Module module = ModuleUtil.findModuleForFile(file, project);
if (module == null) {
throw new IllegalArgumentException("No module for file " + file + " in project " + project);
}
myDesignerPanel = new DesignerEditorPanel(module, file);
}
@NotNull
@Override
public JComponent getComponent() {
return myDesignerPanel;
}
@Override
public JComponent getPreferredFocusedComponent() {
return myDesignerPanel.getPreferredFocusedComponent();
}
@Override
public void dispose() {
myDesignerPanel.dispose();
}
@Override
public void selectNotify() {
}
@Override
public void deselectNotify() {
}
@Override
public void addPropertyChangeListener(@NotNull PropertyChangeListener listener) {
}
@Override
public void removePropertyChangeListener(@NotNull PropertyChangeListener listener) {
}
@Override
public BackgroundEditorHighlighter getBackgroundHighlighter() {
return null;
}
@Override
public FileEditorLocation getCurrentLocation() {
return null;
}
@Override
public StructureViewBuilder getStructureViewBuilder() {
return null;
}
}
@@ -0,0 +1,50 @@
/*
* 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.uiDesigner;
import com.intellij.CommonBundle;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.PropertyKey;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.util.ResourceBundle;
/**
* @author yole
*/
public class UIDesignerBundle {
private static Reference<ResourceBundle> ourBundle;
@NonNls private static final String BUNDLE = "messages.UIDesignerBundle";
private UIDesignerBundle() {
}
public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) {
return CommonBundle.message(getBundle(), key, params);
}
private static ResourceBundle getBundle() {
ResourceBundle bundle = null;
if (ourBundle != null) bundle = ourBundle.get();
if (bundle == null) {
bundle = ResourceBundle.getBundle(BUNDLE);
ourBundle = new SoftReference<ResourceBundle>(bundle);
}
return bundle;
}
}
@@ -0,0 +1,52 @@
/*
* 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.uiDesigner;
import com.intellij.openapi.components.ProjectComponent;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* @author Alexander Lobas
*/
public final class UIDesignerToolWindowManager implements ProjectComponent {
@Override
public void projectOpened() {
// TODO: Auto-generated method stub
}
@Override
public void projectClosed() {
// TODO: Auto-generated method stub
}
@Override
public void initComponent() {
// TODO: Auto-generated method stub
}
@Override
public void disposeComponent() {
// TODO: Auto-generated method stub
}
@NotNull
@NonNls
@Override
public String getComponentName() {
return "UIDesignerToolWindowManager2";
}
}
@@ -0,0 +1,30 @@
/*
* 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.uiDesigner.componentTree;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.ui.treeStructure.Tree;
import org.jetbrains.annotations.NonNls;
/**
* @author Alexander Lobas
*/
public final class ComponentTree extends Tree implements DataProvider {
@Override
public Object getData(@NonNls String dataId) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}
@@ -0,0 +1,48 @@
/*
* 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.uiDesigner.designSurface;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
/**
* @author Alexander Lobas
*/
public final class DesignerEditorPanel extends JPanel implements DataProvider {
public DesignerEditorPanel(@NotNull Module module, @NotNull VirtualFile file) {
setLayout(new BorderLayout());
add(new JLabel("Design Surface"), BorderLayout.CENTER);
}
@Override
public Object getData(@NonNls String dataId) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void dispose() {
// TODO: Auto-generated method stub
}
public JComponent getPreferredFocusedComponent() {
return null; // TODO: Auto-generated method stub
}
}
@@ -0,0 +1,47 @@
/*
* 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.uiDesigner.model;
import com.intellij.uiDesigner.propertyTable.Property;
import java.util.List;
/**
* @author Alexander Lobas
*/
public abstract class RadComponent {
private RadComponent myParent;
public RadComponent getRoot() {
return myParent == null ? this : myParent.getRoot();
}
public final RadComponent getParent() {
return myParent;
}
public final void setParent(RadComponent parent) {
myParent = parent;
}
public List<RadComponent> getChildren() {
return null;
}
public List<Property> getProperties() {
return null;
}
}
@@ -0,0 +1,60 @@
/*
* 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.uiDesigner.propertyTable;
import com.intellij.uiDesigner.model.RadComponent;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* @author Alexander Lobas
*/
public abstract class Property {
private final Property myParent;
@NotNull private final String myName;
public Property(Property parent, @NotNull @NonNls String name) {
myParent = parent;
myName = name;
}
public final Property getParent() {
return myParent;
}
@NotNull
public final String getName() {
return myName;
}
public List<Property> getChildren(RadComponent component) {
return null;
}
public Object getValue(RadComponent component) {
return null;
}
@NotNull
public abstract PropertyRenderer getRenderer();
@Nullable
public abstract PropertyEditor getEditor();
}
@@ -0,0 +1,29 @@
/*
* 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.uiDesigner.propertyTable;
import com.intellij.uiDesigner.model.RadComponent;
import javax.swing.*;
/**
* @author Alexander Lobas
*/
public interface PropertyEditor {
JComponent getComponent(RadComponent component, Object value);
Object getValue();
}
@@ -0,0 +1,41 @@
/*
* 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.uiDesigner.propertyTable;
import com.intellij.uiDesigner.model.RadComponent;
import javax.swing.*;
/**
* @author Alexander Lobas
*/
public interface PropertyRenderer {
/**
* @return <code>JComponent</code> to represent the <code>value</code>
* somewhere in UI (for example in the JList of in the JTree). To be
* consistent with other UI additional parameter abount selection and
* focus are also passed.
*/
JComponent getComponent(RadComponent component, Object value, boolean selected, boolean hasFocus);
/**
* Renderer should update UI of all its internal components to fit current
* IDEA Look And Feel. We cannot directly update UI of the component
* that is returned by {@link #getComponent } method
* because hidden component that are not in the Swing tree can exist.
*/
void updateUI();
}
@@ -0,0 +1,30 @@
/*
* 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.uiDesigner.propertyTable;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.ui.table.JBTable;
import org.jetbrains.annotations.NonNls;
/**
* @author Alexander Lobas
*/
public final class PropertyTable extends JBTable implements DataProvider {
@Override
public Object getData(@NonNls String dataId) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}
@@ -0,0 +1,29 @@
/*
* 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.uiDesigner.propertyTable;
import javax.swing.*;
import java.awt.*;
/**
* @author Alexander Lobas
*/
public final class PropertyTablePanel extends JPanel {
public PropertyTablePanel() {
setLayout(new BorderLayout());
add(new JLabel("Design Surface"), BorderLayout.CENTER);
}
}