diff options
Diffstat (limited to 'plugins/ui-designer')
38 files changed, 1990 insertions, 435 deletions
diff --git a/plugins/ui-designer/src/META-INF/plugin.xml b/plugins/ui-designer/src/META-INF/plugin.xml index bca8934330a4..1dbd8d76a91c 100644 --- a/plugins/ui-designer/src/META-INF/plugin.xml +++ b/plugins/ui-designer/src/META-INF/plugin.xml @@ -9,6 +9,10 @@ <extensionPoints> <extensionPoint name="formInspectionTool" interface="com.intellij.uiDesigner.inspections.FormInspectionTool"/> + + <extensionPoint qualifiedName="com.intellij.paletteItemProvider" + area="IDEA_PROJECT" + interface="com.intellij.ide.palette.PaletteItemProvider"/> </extensionPoints> <extensions defaultExtensionNs="com.intellij.uiDesigner"> @@ -143,11 +147,14 @@ <project-components> <component> - <implementation-class>com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager</implementation-class> + <implementation-class>com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager</implementation-class> <headless-implementation-class></headless-implementation-class> <skipForDefaultProject/> </component> <component> + <implementation-class>com.intellij.ide.palette.impl.PaletteToolWindowManager</implementation-class> + </component> + <component> <implementation-class>com.intellij.uiDesigner.clientProperties.ClientPropertiesManager</implementation-class> </component> </project-components> @@ -202,6 +209,8 @@ use-shortcut-of="SurroundWith"/> <action id="GuiDesigner.Flatten" class="com.intellij.uiDesigner.actions.FlattenAction"/> <separator/> + <action id="GuiDesigner.FormSource" class="com.intellij.uiDesigner.actions.ShowFormSourceAction"/> + <separator/> <reference ref="VersionControlsGroup"/> <separator/> <reference ref="AddToFavorites"/> diff --git a/plugins/ui-designer/src/com/intellij/ide/palette/PaletteDragEventListener.java b/plugins/ui-designer/src/com/intellij/ide/palette/PaletteDragEventListener.java new file mode 100644 index 000000000000..1a6b681b2a48 --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/ide/palette/PaletteDragEventListener.java @@ -0,0 +1,24 @@ +/* + * Copyright 2000-2009 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.ide.palette; + +/** + * @author yole + */ +public interface PaletteDragEventListener { + void dropActionChanged(int gestureModifiers); +} diff --git a/plugins/ui-designer/src/com/intellij/ide/palette/PaletteGroup.java b/plugins/ui-designer/src/com/intellij/ide/palette/PaletteGroup.java new file mode 100644 index 000000000000..a19c1ab8e60d --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/ide/palette/PaletteGroup.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2009 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.ide.palette; + +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.Nullable; + +/** + * @author yole + */ +public interface PaletteGroup { + PaletteGroup[] EMPTY_ARRAY = new PaletteGroup[0]; + + PaletteItem[] getItems(); + + /** + * Returns the text of the group header for the palette group. + * + * @return the text of the group header for the palette group, or null if no header should be shown. + */ + @Nullable String getName(); + + String getTabName(); + + /** + * Returns the action group from which the context menu is built when the palette + * item is right-clicked. + * + * @return the action group, or null if no context menu should be shown. + */ + @Nullable ActionGroup getPopupActionGroup(); + + /** + * Returns the data for the specified data constant. + * + * @param project the project in the context of which data is requested. + * @param dataId the data constant id (see {@link com.intellij.openapi.actionSystem.PlatformDataKeys}). + * @return the data item, or null if no data is available for this constant. + */ + @Nullable Object getData(Project project, String dataId); + + /** + * Processes the drop of a palette item on the specified index in the palette group. + * + * @param project the project to which the drop target palette belongs. + * @param item the dropped item. + * @param index the index at which the dropped item should be inserted (from 0 to getItems().length). + */ + void handleDrop(Project project, PaletteItem item, int index); +} diff --git a/plugins/ui-designer/src/com/intellij/ide/palette/PaletteItem.java b/plugins/ui-designer/src/com/intellij/ide/palette/PaletteItem.java new file mode 100644 index 000000000000..372839d67266 --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/ide/palette/PaletteItem.java @@ -0,0 +1,56 @@ +/* + * Copyright 2000-2009 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.ide.palette; + +import com.intellij.ide.dnd.DnDDragStartBean; +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.project.Project; +import com.intellij.ui.ColoredListCellRenderer; +import org.jetbrains.annotations.Nullable; + +/** + * @author yole + */ +public interface PaletteItem { + void customizeCellRenderer(ColoredListCellRenderer cellRenderer, + boolean selected, + boolean hasFocus); + + /** + * Processes dragging the item. + * + * @return the drag start bean for the drag process, or null if the item cannot be dragged. + */ + @Nullable DnDDragStartBean startDragging(); + + /** + * Returns the action group from which the context menu is built when the palette + * item is right-clicked. + * + * @return the action group, or null if no context menu should be shown. + */ + @Nullable ActionGroup getPopupActionGroup(); + + /** + * Returns the data for the specified data constant. + * + * @param project the project in the context of which data is requested. + * @param dataId the data constant id (see {@link com.intellij.openapi.actionSystem.PlatformDataKeys}). + * @return the data item, or null if no data is available for this constant. + */ + @Nullable Object getData(Project project, String dataId); +} diff --git a/plugins/ui-designer/src/com/intellij/ide/palette/PaletteItemProvider.java b/plugins/ui-designer/src/com/intellij/ide/palette/PaletteItemProvider.java new file mode 100644 index 000000000000..3f1b99d36f52 --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/ide/palette/PaletteItemProvider.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2009 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.ide.palette; + +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.vfs.VirtualFile; + +import java.beans.PropertyChangeListener; + +/** + * @author yole + */ +public interface PaletteItemProvider { + ExtensionPointName<PaletteItemProvider> EP_NAME = ExtensionPointName.create("com.intellij.paletteItemProvider"); + + PaletteGroup[] getActiveGroups(VirtualFile virtualFile); + + void addListener(PropertyChangeListener listener); + void removeListener(PropertyChangeListener listener); +} diff --git a/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteComponentList.java b/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteComponentList.java new file mode 100644 index 000000000000..77b58a922a87 --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteComponentList.java @@ -0,0 +1,403 @@ +/* + * 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.ide.palette.impl; + +import com.intellij.ide.dnd.*; +import com.intellij.ide.palette.PaletteGroup; +import com.intellij.ide.palette.PaletteItem; +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.ActionPlaces; +import com.intellij.openapi.actionSystem.ActionPopupMenu; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Pair; +import com.intellij.ui.ColoredListCellRenderer; +import com.intellij.ui.PopupHandler; +import com.intellij.ui.components.JBList; +import com.intellij.util.ui.PlatformColors; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import javax.swing.plaf.basic.BasicListUI; +import java.awt.*; +import java.awt.event.*; + +/** + * @author yole + */ +public class PaletteComponentList extends JBList { + private final Project myProject; + private final PaletteWindow myPalette; + private final PaletteGroup myGroup; + private int myHoverIndex = -1; + private int myBeforeClickSelectedRow = -1; + private int myDropTargetIndex = -1; + private boolean myNeedClearSelection = false; + + public PaletteComponentList(Project project, PaletteWindow palette, PaletteGroup group) { + myProject = project; + myPalette = palette; + myGroup = group; + setModel(new AbstractListModel() { + public int getSize() { + return myGroup.getItems().length; + } + + public Object getElementAt(int index) { + return myGroup.getItems() [index]; + } + }); + + addMouseListener(new MouseAdapter() { + @Override public void mouseEntered(MouseEvent e) { + setHoverIndex(locationToIndex(e.getPoint())); + } + + @Override public void mouseExited(MouseEvent e) { + setHoverIndex(-1); + } + + @Override public void mousePressed(MouseEvent e) { + myNeedClearSelection = (SwingUtilities.isLeftMouseButton(e) && + myBeforeClickSelectedRow >= 0 && + locationToIndex(e.getPoint()) == myBeforeClickSelectedRow && + !UIUtil.isControlKeyDown(e) && !e.isShiftDown()); + } + + @Override public void mouseReleased(MouseEvent e) { + if (SwingUtilities.isLeftMouseButton(e) && + myBeforeClickSelectedRow >= 0 && + locationToIndex(e.getPoint()) == myBeforeClickSelectedRow && + !UIUtil.isControlKeyDown(e) && !e.isShiftDown() && myNeedClearSelection) { + clearSelection(); + } + } + }); + + addMouseListener(new PopupHandler() { + public void invokePopup(final Component comp, final int x, final int y) { + requestFocusInWindow(); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + int index = locationToIndex(new Point(x, y)); + PaletteItem[] items = myGroup.getItems(); + if (index >= 0 && index < items.length) { + if (getSelectedIndex() != index) { + addSelectionInterval(index, index); + } + PaletteItem item = items [index]; + ActionGroup group = item.getPopupActionGroup(); + if (group != null) { + ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group); + popupMenu.getComponent().show(comp, x, y); + } + } + } + }); + } + }); + + addMouseMotionListener(new MouseMotionAdapter() { + public void mouseMoved(MouseEvent e) { + setHoverIndex(locationToIndex(e.getPoint())); + } + }); + + addKeyListener(new KeyListener() { + public void keyPressed(KeyEvent e) { + myPalette.notifyKeyEvent(e); + } + + public void keyReleased(KeyEvent e) { + myPalette.notifyKeyEvent(e); + } + + public void keyTyped(KeyEvent e) { + myPalette.notifyKeyEvent(e); + } + }); + + setCellRenderer(new ComponentCellRenderer()); + + setVisibleRowCount(0); + setLayoutOrientation(HORIZONTAL_WRAP); + setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + final DnDManager dndManager = DnDManager.getInstance(); + dndManager.registerSource(new MyDnDSource(), this); + dndManager.registerTarget(new MyDnDTarget(), this); + + initActions(); + } + + private void setHoverIndex(final int index) { + if (index != myHoverIndex) { + if (myHoverIndex >= 0) repaint(getCellBounds(myHoverIndex, myHoverIndex)); + myHoverIndex = index; + if (myHoverIndex >= 0) repaint(getCellBounds(myHoverIndex, myHoverIndex)); + } + } + + private void setDropTargetIndex(final int index) { + if (index != myDropTargetIndex) { + myDropTargetIndex = index; + repaint(); + } + } + + @Override public void updateUI() { + setUI(new ComponentListUI()); + invalidate(); + } + + private void initActions() { + @NonNls ActionMap map = getActionMap(); + map.put( "selectPreviousRow", new MoveFocusAction( map.get( "selectPreviousRow" ), false ) ); + map.put( "selectNextRow", new MoveFocusAction( map.get( "selectNextRow" ), true ) ); + map.put( "selectPreviousColumn", new MoveFocusAction( new ChangeColumnAction( map.get( "selectPreviousColumn" ), false ), false ) ); + map.put( "selectNextColumn", new MoveFocusAction( new ChangeColumnAction( map.get( "selectNextColumn" ), true ), true ) ); + } + + Integer myTempWidth; + + public int getWidth () { + return (myTempWidth == null) ? super.getWidth () : myTempWidth.intValue (); + } + + public int getPreferredHeight(final int width) { + myTempWidth = width; + try { + return getUI().getPreferredSize(this).height; + } + finally { + myTempWidth = null; + } + } + + public void takeFocusFrom(PaletteGroupHeader paletteGroup, int indexToSelect) { + if (indexToSelect == -1) { + //this is not 'our' CategoryButton so we'll assume it's the one below this category list + indexToSelect = getModel().getSize() - 1; + } + else if (getModel().getSize() == 0) { + indexToSelect = -1; + } + requestFocus(); + setSelectedIndex(indexToSelect); + if (indexToSelect >= 0) { + ensureIndexIsVisible(indexToSelect); + } + } + + @Override protected void paintComponent(Graphics g) { + super.paintComponent(g); + if (myDropTargetIndex >= 0) { + int dropLineY; + Rectangle rc; + if (myDropTargetIndex == myGroup.getItems().length) { + rc = getCellBounds(myDropTargetIndex-1, myDropTargetIndex-1); + dropLineY = (int)rc.getMaxY()-1; + } + else { + rc = getCellBounds(myDropTargetIndex, myDropTargetIndex); + dropLineY = rc.y; + } + Graphics2D g2d = (Graphics2D) g; + g2d.setColor(PlatformColors.BLUE); + g2d.setStroke(new BasicStroke(2.0f)); + g2d.drawLine(rc.x, dropLineY, rc.x+rc.width, dropLineY); + g2d.drawLine(rc.x, dropLineY-2, rc.x, dropLineY+2); + g2d.drawLine(rc.x+rc.width, dropLineY-2, rc.x+rc.width, dropLineY+2); + } + } + + class ComponentListUI extends BasicListUI { + private ComponentListListener myListener; + + @Override protected void updateLayoutState() { + super.updateLayoutState(); + + if (list.getLayoutOrientation() == JList.HORIZONTAL_WRAP) { + Insets insets = list.getInsets(); + int listWidth = list.getWidth() - (insets.left + insets.right); + if (listWidth >= cellWidth) { + int columnCount = listWidth / cellWidth; + cellWidth = (columnCount == 0) ? 1 : listWidth / columnCount; + } + } + } + + @Override protected void installListeners() { + myListener = new ComponentListListener(); + addMouseListener(myListener); + super.installListeners(); + } + + @Override + protected void uninstallListeners() { + if (myListener != null) { + removeMouseListener(myListener); + } + super.uninstallListeners(); + } + + private class ComponentListListener extends MouseAdapter { + @Override public void mousePressed(MouseEvent e) { + myBeforeClickSelectedRow = list.getSelectedIndex(); + } + } + } + + private static class ComponentCellRenderer extends ColoredListCellRenderer { + protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { + PaletteItem paletteItem = (PaletteItem) value; + clear(); + paletteItem.customizeCellRenderer(this, selected, hasFocus); + } + } + + private class MoveFocusAction extends AbstractAction { + private final Action defaultAction; + private final boolean focusNext; + + public MoveFocusAction(Action defaultAction, boolean focusNext) { + this.defaultAction = defaultAction; + this.focusNext = focusNext; + } + + public void actionPerformed(ActionEvent e) { + int selIndexBefore = getSelectedIndex(); + defaultAction.actionPerformed(e); + int selIndexCurrent = getSelectedIndex(); + if (selIndexBefore != selIndexCurrent) return; + + if (focusNext && 0 == selIndexCurrent) return; + + KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + Container container = kfm.getCurrentFocusCycleRoot(); + FocusTraversalPolicy policy = container.getFocusTraversalPolicy(); + if (null == policy) policy = kfm.getDefaultFocusTraversalPolicy(); + Component next = focusNext + ? policy.getComponentAfter(container, PaletteComponentList.this) + : policy.getComponentBefore(container, PaletteComponentList.this); + if (null != next && next instanceof PaletteGroupHeader) { + clearSelection(); + next.requestFocus(); + ((PaletteGroupHeader)next).scrollRectToVisible(next.getBounds()); + } + } + } + + private class ChangeColumnAction extends AbstractAction { + private final Action defaultAction; + private final boolean selectNext; + + public ChangeColumnAction(Action defaultAction, boolean selectNext) { + this.defaultAction = defaultAction; + this.selectNext = selectNext; + } + + public void actionPerformed(ActionEvent e) { + int selIndexBefore = getSelectedIndex(); + defaultAction.actionPerformed(e); + int selIndexCurrent = getSelectedIndex(); + if ((selectNext && selIndexBefore < selIndexCurrent) || (!selectNext && selIndexBefore > selIndexCurrent)) return; + + if (selectNext) { + if (selIndexCurrent == selIndexBefore + 1) selIndexCurrent++; + if (selIndexCurrent < getModel().getSize() - 1) { + setSelectedIndex(selIndexCurrent + 1); + scrollRectToVisible(getCellBounds(selIndexCurrent + 1, selIndexCurrent + 1)); + } + } + else { + if (selIndexCurrent > 0) { + setSelectedIndex(selIndexCurrent - 1); + scrollRectToVisible(getCellBounds(selIndexCurrent - 1, selIndexCurrent - 1)); + } + } + } + } + + private class MyDnDTarget implements DnDTarget { + + public boolean update(DnDEvent aEvent) { + setHoverIndex(-1); + if (aEvent.getAttachedObject() instanceof PaletteItem) { + setDropTargetIndex(locationToTargetIndex(aEvent.getPoint())); + aEvent.setDropPossible(true); + } + else { + setDropTargetIndex(-1); + aEvent.setDropPossible(false); + } + return false; + } + + public void drop(DnDEvent aEvent) { + setDropTargetIndex(-1); + if (aEvent.getAttachedObject() instanceof PaletteItem) { + int index = locationToTargetIndex(aEvent.getPoint()); + if (index >= 0) { + myGroup.handleDrop(myProject, (PaletteItem) aEvent.getAttachedObject(), index); + } + } + } + + public void cleanUpOnLeave() { + setDropTargetIndex(-1); + } + + private int locationToTargetIndex(Point location) { + int row = locationToIndex(location); + if (row < 0) { + return -1; + } + Rectangle rc = getCellBounds(row, row); + return location.y < rc.getCenterY() ? row : row + 1; + } + + public void updateDraggedImage(Image image, Point dropPoint, Point imageOffset) { + } + } + + private class MyDnDSource implements DnDSource { + public boolean canStartDragging(DnDAction action, Point dragOrigin) { + int index = locationToIndex(dragOrigin); + return index >= 0 && myGroup.getItems() [index].startDragging() != null; + } + + public DnDDragStartBean startDragging(DnDAction action, Point dragOrigin) { + int index = locationToIndex(dragOrigin); + if (index < 0) return null; + return myGroup.getItems() [index].startDragging(); + } + + @Nullable + public Pair<Image, Point> createDraggedImage(DnDAction action, Point dragOrigin) { + return null; + } + + public void dragDropEnd() { + } + + public void dropActionChanged(final int gestureModifiers) { + myPalette.notifyDropActionChanged(gestureModifiers); + } + } +} diff --git a/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteContentWindow.java b/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteContentWindow.java new file mode 100644 index 000000000000..b5aaccad7b29 --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteContentWindow.java @@ -0,0 +1,114 @@ +/* + * Copyright 2000-2009 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.ide.palette.impl; + +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; + +/** + * @author yole + */ +public class PaletteContentWindow extends JPanel implements Scrollable { + public PaletteContentWindow() { + setLayout(new PaletteLayoutManager()); + } + + public Dimension getPreferredScrollableViewportSize() { + return getPreferredSize(); + } + + public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { + return 20; + } + + public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { + return 100; + } + + public boolean getScrollableTracksViewportWidth() { + return true; + } + + public boolean getScrollableTracksViewportHeight() { + return false; + } + + @Nullable PaletteGroupHeader getLastGroupHeader() { + PaletteGroupHeader result = null; + for(Component comp: getComponents()) { + if (comp instanceof PaletteGroupHeader) { + result = (PaletteGroupHeader) comp; + } + } + return result; + } + + private static class PaletteLayoutManager implements LayoutManager { + + public void addLayoutComponent(String name, Component comp) { + } + + public void layoutContainer(Container parent) { + int width = parent.getWidth(); + + int height = 0; + for(Component c: parent.getComponents()) { + if (c instanceof PaletteGroupHeader) { + PaletteGroupHeader groupHeader = (PaletteGroupHeader) c; + groupHeader.setLocation(0, height); + if (groupHeader.isVisible()) { + groupHeader.setSize(width, groupHeader.getPreferredSize().height); + height += groupHeader.getPreferredSize().height; + } + else { + groupHeader.setSize(0, 0); + } + if (groupHeader.isSelected() || !groupHeader.isVisible()) { + PaletteComponentList componentList = groupHeader.getComponentList(); + componentList.setSize(width, componentList.getPreferredSize().height); + componentList.setLocation(0, height); + height += componentList.getHeight(); + } + } + } + } + + public Dimension minimumLayoutSize(Container parent) { + return new Dimension(0, 0); + } + + public Dimension preferredLayoutSize(Container parent) { + int height = 0; + int width = parent.getWidth(); + for(Component c: parent.getComponents()) { + if (c instanceof PaletteGroupHeader) { + PaletteGroupHeader groupHeader = (PaletteGroupHeader) c; + height += groupHeader.getHeight(); + if (groupHeader.isSelected()) { + height += groupHeader.getComponentList().getPreferredHeight(width); + } + } + } + return new Dimension(10 /* not used - tracks viewports width*/, height); + } + + public void removeLayoutComponent(Component comp) { + } + } +} diff --git a/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteGroupHeader.java b/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteGroupHeader.java new file mode 100644 index 000000000000..c98caefa3f75 --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteGroupHeader.java @@ -0,0 +1,211 @@ +/* + * Copyright 2000-2013 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.ide.palette.impl; + +import com.intellij.ide.dnd.DnDEvent; +import com.intellij.ide.dnd.DnDManager; +import com.intellij.ide.dnd.DnDTarget; +import com.intellij.ide.palette.PaletteGroup; +import com.intellij.ide.palette.PaletteItem; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.project.Project; +import com.intellij.ui.PopupHandler; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import javax.swing.border.CompoundBorder; +import java.awt.*; +import java.awt.event.*; + +/** + * @author yole + */ +public class PaletteGroupHeader extends JCheckBox implements DataProvider { + private final PaletteWindow myPaletteWindow; + private PaletteComponentList myComponentList; + private final PaletteGroup myGroup; + + public PaletteGroupHeader(PaletteWindow paletteWindow, PaletteGroup group) { + myPaletteWindow = paletteWindow; + myGroup = group; + if (group.getName() == null) { + setVisible(false); + } + else { + setText(group.getName()); + } + setSelected(true); + addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (myComponentList != null) { + myComponentList.setVisible(isSelected()); + } + } + }); + + addMouseListener(new PopupHandler() { + public void invokePopup(Component comp, int x, int y) { + myPaletteWindow.setLastFocusedGroup(PaletteGroupHeader.this); + showGroupPopupMenu(comp, x, y); + } + }); + + setIcon(UIUtil.getTreeCollapsedIcon()); + setSelectedIcon(UIUtil.getTreeExpandedIcon()); + setFont(getFont().deriveFont(Font.BOLD)); + setFocusPainted(false); + setMargin(new Insets(0, 3, 0, 3)); + setOpaque(true); + if (getBorder() instanceof CompoundBorder) { // from BasicLookAndFeel + Dimension pref = getPreferredSize(); + pref.height -= 3; + setPreferredSize(pref); + } + + DnDManager.getInstance().registerTarget(new DnDTarget() { + public boolean update(DnDEvent aEvent) { + setBorderPainted(true); + aEvent.setDropPossible(aEvent.getAttachedObject() instanceof PaletteItem); + return true; + } + + public void drop(DnDEvent aEvent) { + setBorderPainted(false); + if (aEvent.getAttachedObject() instanceof PaletteItem) { + myGroup.handleDrop(myPaletteWindow.getProject(), (PaletteItem) aEvent.getAttachedObject(), -1); + } + } + + public void cleanUpOnLeave() { + setBorderPainted(false); + } + + public void updateDraggedImage(Image image, Point dropPoint, Point imageOffset) { + } + }, this); + + addFocusListener(new FocusAdapter() { + @Override public void focusGained(FocusEvent e) { + myPaletteWindow.setLastFocusedGroup(PaletteGroupHeader.this); + } + }); + + initActions(); + } + + public void showGroupPopupMenu(final Component comp, final int x, final int y) { + ActionGroup group = myGroup.getPopupActionGroup(); + if (group != null) { + ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group); + popupMenu.getComponent().show(comp, x, y); + } + } + + private void initActions() { + @NonNls InputMap inputMap = getInputMap(WHEN_FOCUSED); + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, false), "moveFocusDown"); + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, false), "moveFocusUp"); + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, false), "collapse"); + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0, false), "expand"); + + @NonNls ActionMap actionMap = getActionMap(); + actionMap.put("moveFocusDown", new MoveFocusAction(true)); + actionMap.put("moveFocusUp", new MoveFocusAction(false)); + actionMap.put("collapse", new ExpandAction(false)); + actionMap.put("expand", new ExpandAction(true)); + } + + @Override public Color getBackground() { + if (isFocusOwner()) { + return UIUtil.getListSelectionBackground(); + } + return super.getBackground(); + } + + @Override public Color getForeground() { + if (isFocusOwner()) { + return UIUtil.getListSelectionForeground(); + } + return super.getForeground(); + } + + public void setComponentList(final PaletteComponentList componentList) { + myComponentList = componentList; + } + + public PaletteComponentList getComponentList() { + return myComponentList; + } + + public PaletteGroup getGroup() { + return myGroup; + } + + @Nullable public Object getData(String dataId) { + Object data = myPaletteWindow.getData(dataId); + if (data != null) return data; + Project project = CommonDataKeys.PROJECT.getData(myPaletteWindow); + return myGroup.getData(project, dataId); + } + + private class MoveFocusAction extends AbstractAction { + private final boolean moveDown; + + public MoveFocusAction(boolean moveDown) { + this.moveDown = moveDown; + } + + public void actionPerformed(ActionEvent e) { + KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + Container container = kfm.getCurrentFocusCycleRoot(); + FocusTraversalPolicy policy = container.getFocusTraversalPolicy(); + if (null == policy) policy = kfm.getDefaultFocusTraversalPolicy(); + Component next = + moveDown ? policy.getComponentAfter(container, PaletteGroupHeader.this) : policy.getComponentBefore(container, PaletteGroupHeader.this); + if (null != next && next instanceof PaletteComponentList) { + final PaletteComponentList list = (PaletteComponentList)next; + if (list.getModel().getSize() != 0) { + list.takeFocusFrom(PaletteGroupHeader.this, list == myComponentList ? 0 : -1); + return; + } + else { + next = moveDown ? policy.getComponentAfter(container, next) : policy.getComponentBefore(container, next); + } + } + if (null != next && next instanceof PaletteGroupHeader) { + next.requestFocus(); + } + } + } + + private class ExpandAction extends AbstractAction { + private final boolean expand; + + public ExpandAction(boolean expand) { + this.expand = expand; + } + + public void actionPerformed(ActionEvent e) { + if (expand == isSelected()) return; + setSelected(expand); + if (myComponentList != null) { + myComponentList.setVisible(isSelected()); + } + } + } +} diff --git a/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteToolWindowManager.java b/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteToolWindowManager.java new file mode 100644 index 000000000000..c6fe8756d1f5 --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteToolWindowManager.java @@ -0,0 +1,118 @@ +/* + * Copyright 2000-2014 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.ide.palette.impl; + +import com.intellij.designer.DesignerEditorPanelFacade; +import com.intellij.designer.LightToolWindow; +import com.intellij.icons.AllIcons; +import com.intellij.ide.IdeBundle; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ToolWindowAnchor; +import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.ui.content.Content; +import com.intellij.ui.content.ContentManager; +import com.intellij.uiDesigner.AbstractToolWindowManager; +import com.intellij.uiDesigner.designSurface.GuiEditor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Alexander Lobas + */ +public class PaletteToolWindowManager extends AbstractToolWindowManager { + private final PaletteWindow myToolWindowPanel; + + public PaletteToolWindowManager(Project project, FileEditorManager fileEditorManager) { + super(project, fileEditorManager); + myToolWindowPanel = ApplicationManager.getApplication().isHeadlessEnvironment() ? null : new PaletteWindow(project); + } + + public static PaletteWindow getInstance(GuiEditor designer) { + PaletteToolWindowManager manager = getInstance(designer.getProject()); + if (manager.isEditorMode()) { + return (PaletteWindow)manager.getContent(designer); + } + return manager.myToolWindowPanel; + } + + public static PaletteToolWindowManager getInstance(Project project) { + return project.getComponent(PaletteToolWindowManager.class); + } + + @Override + protected void initToolWindow() { + myToolWindow = ToolWindowManager.getInstance(myProject) + .registerToolWindow(IdeBundle.message("toolwindow.palette"), false, getAnchor(), myProject, true); + myToolWindow.setIcon(AllIcons.Toolwindows.ToolWindowPalette); + initGearActions(); + + ContentManager contentManager = myToolWindow.getContentManager(); + Content content = contentManager.getFactory().createContent(myToolWindowPanel, null, false); + content.setCloseable(false); + content.setPreferredFocusableComponent(myToolWindowPanel); + contentManager.addContent(content); + contentManager.setSelectedContent(content, true); + myToolWindow.setAvailable(false, null); + } + + @Override + protected void updateToolWindow(@Nullable DesignerEditorPanelFacade designer) { + myToolWindowPanel.refreshPaletteIfChanged((GuiEditor)designer); + + if (designer == null) { + myToolWindow.setAvailable(false, null); + } + else { + myToolWindow.setAvailable(true, null); + myToolWindow.show(null); + } + } + + @Override + protected ToolWindowAnchor getAnchor() { + return ToolWindowAnchor.RIGHT; + } + + @Override + protected LightToolWindow createContent(@NotNull DesignerEditorPanelFacade designer) { + PaletteWindow palettePanel = new PaletteWindow(myProject); + palettePanel.refreshPaletteIfChanged((GuiEditor)designer); + + return createContent(designer, + palettePanel, + IdeBundle.message("toolwindow.palette"), + AllIcons.Toolwindows.ToolWindowPalette, + palettePanel, + palettePanel, + 180, + null); + } + + @Override + public void disposeComponent() { + if (myToolWindowPanel != null) { + myToolWindowPanel.dispose(); + } + } + + @NotNull + @Override + public String getComponentName() { + return "PaletteManager"; + } +}
\ No newline at end of file diff --git a/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteWindow.java b/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteWindow.java new file mode 100644 index 000000000000..0c7b57ce999c --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/ide/palette/impl/PaletteWindow.java @@ -0,0 +1,351 @@ +/* + * Copyright 2000-2009 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.ide.palette.impl; + +import com.intellij.designer.LightToolWindowContent; +import com.intellij.ide.palette.PaletteGroup; +import com.intellij.ide.palette.PaletteItem; +import com.intellij.ide.palette.PaletteItemProvider; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.PopupHandler; +import com.intellij.ui.ScrollPaneFactory; +import com.intellij.ui.components.JBTabbedPane; +import com.intellij.uiDesigner.designSurface.GuiEditor; +import com.intellij.util.ArrayUtil; +import com.intellij.util.containers.HashSet; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import java.awt.*; +import java.awt.dnd.DragSource; +import java.awt.dnd.DragSourceAdapter; +import java.awt.dnd.DragSourceDropEvent; +import java.awt.dnd.DragSourceListener; +import java.awt.event.KeyEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.*; + +/** + * @author yole + */ +public class PaletteWindow extends JPanel implements LightToolWindowContent, DataProvider { + private final Project myProject; + private final ArrayList<PaletteGroupHeader> myGroupHeaders = new ArrayList<PaletteGroupHeader>(); + private final PaletteItemProvider[] myProviders; + private final MyPropertyChangeListener myPropertyChangeListener = new MyPropertyChangeListener(); + private final Set<PaletteGroup> myGroups = new HashSet<PaletteGroup>(); + private final JTabbedPane myTabbedPane = new JBTabbedPane(); + private final JScrollPane myScrollPane = ScrollPaneFactory.createScrollPane(); + private final MyListSelectionListener myListSelectionListener = new MyListSelectionListener(); + private PaletteGroupHeader myLastFocusedGroup; + + @NonNls private static final String ourHelpID = "guiDesigner.uiTour.palette"; + + private final DragSourceListener myDragSourceListener = new DragSourceAdapter() { + @Override + public void dragDropEnd(DragSourceDropEvent event) { + Component component = event.getDragSourceContext().getComponent(); + if (!event.getDropSuccess() && + component instanceof PaletteComponentList && + getRootPane() == ((JComponent)component).getRootPane()) { + clearActiveItem(); + } + } + }; + + private GuiEditor myDesigner; + + public PaletteWindow(Project project) { + myProject = project; + myProviders = Extensions.getExtensions(PaletteItemProvider.EP_NAME, project); + + setLayout(new GridLayout(1, 1)); + myScrollPane.addMouseListener(new MyScrollPanePopupHandler()); + myScrollPane.setBorder(null); + KeyStroke escStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + new ClearActiveItemAction().registerCustomShortcutSet(new CustomShortcutSet(escStroke), myScrollPane); + + if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { + DragSource.getDefaultDragSource().addDragSourceListener(myDragSourceListener); + } + } + + public void dispose() { + removePaletteProviderListener(); + + if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { + DragSource.getDefaultDragSource().removeDragSourceListener(myDragSourceListener); + } + } + + private void addPaletteProviderListener() { + for (PaletteItemProvider provider : myProviders) { + provider.addListener(myPropertyChangeListener); + } + } + + private void removePaletteProviderListener() { + for (PaletteItemProvider provider : myProviders) { + provider.removeListener(myPropertyChangeListener); + } + } + + public void refreshPaletteIfChanged(@Nullable GuiEditor designer) { + removePaletteProviderListener(); + myDesigner = designer; + if (designer != null) { + addPaletteProviderListener(); + } + + VirtualFile file = designer == null ? null : designer.getFile(); + Set<PaletteGroup> currentGroups = new HashSet<PaletteGroup>(collectCurrentGroups(file)); + if (!currentGroups.equals(myGroups)) { + refreshPalette(file); + } + } + + private void refreshPalette(@Nullable VirtualFile selectedFile) { + for (PaletteGroupHeader groupHeader : myGroupHeaders) { + groupHeader.getComponentList().removeListSelectionListener(myListSelectionListener); + } + String[] oldTabNames = collectTabNames(myGroups); + myTabbedPane.removeAll(); + myGroupHeaders.clear(); + myGroups.clear(); + + final ArrayList<PaletteGroup> currentGroups = collectCurrentGroups(selectedFile); + String[] tabNames = collectTabNames(currentGroups); + if (tabNames.length == 1) { + if (oldTabNames.length != 1) { + remove(myTabbedPane); + add(myScrollPane); + } + + PaletteContentWindow contentWindow = new PaletteContentWindow(); + myScrollPane.getViewport().setView(contentWindow); + + for (PaletteGroup group : currentGroups) { + addGroupToControl(group, contentWindow); + } + + final JComponent view = (JComponent)myScrollPane.getViewport().getView(); + if (view != null) { + view.revalidate(); + for (Component component : view.getComponents()) { + ((JComponent)component).revalidate(); + } + } + } + else { + if (oldTabNames.length <= 1) { + remove(myScrollPane); + add(myTabbedPane); + } + for (String tabName : tabNames) { + PaletteContentWindow contentWindow = new PaletteContentWindow(); + JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(contentWindow); + scrollPane.addMouseListener(new MyScrollPanePopupHandler()); + myTabbedPane.add(tabName, scrollPane); + for (PaletteGroup group : currentGroups) { + if (group.getTabName().equals(tabName)) { + addGroupToControl(group, contentWindow); + } + } + } + myTabbedPane.revalidate(); + } + } + + private void addGroupToControl(PaletteGroup group, JComponent control) { + PaletteGroupHeader groupHeader = new PaletteGroupHeader(this, group); + myGroupHeaders.add(groupHeader); + myGroups.add(group); + control.add(groupHeader); + PaletteComponentList componentList = new PaletteComponentList(myProject, this, group); + control.add(componentList); + groupHeader.setComponentList(componentList); + componentList.addListSelectionListener(myListSelectionListener); + } + + private static String[] collectTabNames(final Collection<PaletteGroup> groups) { + Set<String> result = new TreeSet<String>(); + for (PaletteGroup group : groups) { + result.add(group.getTabName()); + } + return ArrayUtil.toStringArray(result); + } + + private ArrayList<PaletteGroup> collectCurrentGroups(@Nullable VirtualFile selectedFile) { + ArrayList<PaletteGroup> result = new ArrayList<PaletteGroup>(); + if (selectedFile != null) { + for (PaletteItemProvider provider : myProviders) { + PaletteGroup[] groups = provider.getActiveGroups(selectedFile); + Collections.addAll(result, groups); + } + } + return result; + } + + public void clearActiveItem() { + if (getActiveItem() == null) return; + for (PaletteGroupHeader group : myGroupHeaders) { + group.getComponentList().clearSelection(); + } + ListSelectionEvent event = new ListSelectionEvent(this, -1, -1, false); + notifySelectionChanged(event); + } + + @Nullable + public PaletteItem getActiveItem() { + for (PaletteGroupHeader groupHeader : myGroupHeaders) { + if (groupHeader.isSelected() && groupHeader.getComponentList().getSelectedValue() != null) { + return (PaletteItem)groupHeader.getComponentList().getSelectedValue(); + } + } + return null; + } + + @Nullable + public <T extends PaletteItem> T getActiveItem(Class<T> cls) { + PaletteItem item = getActiveItem(); + if (item != null && item.getClass().isInstance(item)) { + //noinspection unchecked + return (T)item; + } + return null; + } + + @Nullable + public Object getData(String dataId) { + if (PlatformDataKeys.HELP_ID.is(dataId)) { + return ourHelpID; + } + if (CommonDataKeys.PROJECT.is(dataId)) { + return myProject; + } + PaletteItem item = getActiveItem(); + if (item != null) { + Object data = item.getData(myProject, dataId); + if (data != null) return data; + } + for (PaletteGroupHeader groupHeader : myGroupHeaders) { + if ((groupHeader.isSelected() && groupHeader.getComponentList().getSelectedValue() != null) || groupHeader == myLastFocusedGroup) { + return groupHeader.getGroup().getData(myProject, dataId); + } + } + final int tabCount = collectTabNames(myGroups).length; + if (tabCount > 0) { + JScrollPane activeScrollPane; + if (tabCount == 1) { + activeScrollPane = myScrollPane; + } + else { + activeScrollPane = (JScrollPane)myTabbedPane.getSelectedComponent(); + } + PaletteContentWindow activeContentWindow = (PaletteContentWindow)activeScrollPane.getViewport().getView(); + PaletteGroupHeader groupHeader = activeContentWindow.getLastGroupHeader(); + if (groupHeader != null) { + return groupHeader.getGroup().getData(myProject, dataId); + } + } + return null; + } + + public Project getProject() { + return myProject; + } + + void setLastFocusedGroup(final PaletteGroupHeader focusedGroup) { + myLastFocusedGroup = focusedGroup; + for (PaletteGroupHeader group : myGroupHeaders) { + group.getComponentList().clearSelection(); + } + } + + void notifyKeyEvent(final KeyEvent e) { + if (myDesigner != null) { + if (e.getID() == KeyEvent.KEY_PRESSED) { + myDesigner.paletteKeyPressed(e); + } + else if (e.getID() == KeyEvent.KEY_RELEASED) { + myDesigner.paletteKeyReleased(e); + } + } + } + + void notifyDropActionChanged(int gestureModifiers) { + if (myDesigner != null) { + myDesigner.paletteDropActionChanged(gestureModifiers); + } + } + + void notifySelectionChanged(final ListSelectionEvent event) { + if (myDesigner != null) { + myDesigner.paletteValueChanged(event); + } + } + + private class MyListSelectionListener implements ListSelectionListener { + public void valueChanged(ListSelectionEvent e) { + PaletteComponentList sourceList = (PaletteComponentList)e.getSource(); + for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) { + if (sourceList.isSelectedIndex(i)) { + // selection is being added + for (PaletteGroupHeader group : myGroupHeaders) { + if (group.getComponentList() != sourceList) { + group.getComponentList().clearSelection(); + } + } + break; + } + } + notifySelectionChanged(e); + } + } + + private class MyPropertyChangeListener implements PropertyChangeListener { + public void propertyChange(PropertyChangeEvent evt) { + refreshPalette(myDesigner.getFile()); + } + } + + private static class MyScrollPanePopupHandler extends PopupHandler { + public void invokePopup(Component comp, int x, int y) { + JScrollPane scrollPane = (JScrollPane)comp; + PaletteContentWindow contentWindow = (PaletteContentWindow)scrollPane.getViewport().getView(); + if (contentWindow != null) { + PaletteGroupHeader groupHeader = contentWindow.getLastGroupHeader(); + if (groupHeader != null) { + groupHeader.showGroupPopupMenu(comp, x, y); + } + } + } + } + + private class ClearActiveItemAction extends AnAction { + public void actionPerformed(AnActionEvent e) { + clearActiveItem(); + } + } +} diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/AbstractToolWindowManager.java b/plugins/ui-designer/src/com/intellij/uiDesigner/AbstractToolWindowManager.java new file mode 100644 index 000000000000..1a221506c1c2 --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/AbstractToolWindowManager.java @@ -0,0 +1,67 @@ +/* + * Copyright 2000-2014 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.designer.DesignerEditorPanelFacade; +import com.intellij.designer.LightToolWindowManager; +import com.intellij.designer.ToggleEditorModeAction; +import com.intellij.ide.palette.impl.PaletteToolWindowManager; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.fileEditor.FileEditor; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ToolWindowAnchor; +import com.intellij.uiDesigner.editor.UIFormEditor; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; +import org.jetbrains.annotations.Nullable; + +/** + * @author Alexander Lobas + */ +public abstract class AbstractToolWindowManager extends LightToolWindowManager { + public AbstractToolWindowManager(Project project, FileEditorManager fileEditorManager) { + super(project, fileEditorManager); + } + + @Override + public void projectOpened() { + if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { + super.projectOpened(); + } + } + + @Nullable + @Override + protected DesignerEditorPanelFacade getDesigner(FileEditor editor) { + if (editor instanceof UIFormEditor) { + UIFormEditor formEditor = (UIFormEditor)editor; + return formEditor.getEditor(); + } + return null; + } + + @Override + protected ToggleEditorModeAction createToggleAction(ToolWindowAnchor anchor) { + return new ToggleEditorModeAction(this, myProject, anchor) { + @Override + protected LightToolWindowManager getOppositeManager() { + AbstractToolWindowManager designerManager = DesignerToolWindowManager.getInstance(myProject); + AbstractToolWindowManager paletteManager = PaletteToolWindowManager.getInstance(myProject); + return myManager == designerManager ? paletteManager : designerManager; + } + }; + } +}
\ No newline at end of file diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/FormEditingUtil.java b/plugins/ui-designer/src/com/intellij/uiDesigner/FormEditingUtil.java index 6f9866018f4c..f2443b264b78 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/FormEditingUtil.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/FormEditingUtil.java @@ -41,7 +41,7 @@ import com.intellij.uiDesigner.editor.UIFormEditor; import com.intellij.uiDesigner.lw.*; import com.intellij.uiDesigner.palette.ComponentItem; import com.intellij.uiDesigner.palette.Palette; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.propertyInspector.properties.BindingProperty; import com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty; import com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager; @@ -602,7 +602,7 @@ public final class FormEditingUtil { if (project == null) { return null; } - final UIDesignerToolWindowManager toolWindowManager = UIDesignerToolWindowManager.getInstance(project); + final DesignerToolWindowManager toolWindowManager = DesignerToolWindowManager.getInstance(project); if (toolWindowManager == null) { return null; } @@ -702,7 +702,7 @@ public final class FormEditingUtil { final RadContainer root = (RadContainer)getRoot(component); if (root == null) return; - ComponentTreeBuilder builder = UIDesignerToolWindowManager.getInstance(component.getProject()).getComponentTreeBuilder(); + ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder(); // this can return null if the click to select the control also requested to grab the focus - // the component tree will be instantiated after the event has been processed completely if (builder != null) { @@ -724,7 +724,7 @@ public final class FormEditingUtil { public static void selectComponents(final GuiEditor editor, List<RadComponent> components) { if (components.size() > 0) { RadComponent component = components.get(0); - ComponentTreeBuilder builder = UIDesignerToolWindowManager.getInstance(component.getProject()).getComponentTreeBuilder(); + ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder(); if (builder == null) { // race condition when handling event? return; @@ -780,7 +780,7 @@ public final class FormEditingUtil { } public static Object getNextSaveUndoGroupId(final Project project) { - final GuiEditor guiEditor = UIDesignerToolWindowManager.getInstance(project).getActiveFormEditor(); + final GuiEditor guiEditor = DesignerToolWindowManager.getInstance(project).getActiveFormEditor(); return guiEditor == null ? null : guiEditor.getNextSaveGroupId(); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/FormHighlightingPass.java b/plugins/ui-designer/src/com/intellij/uiDesigner/FormHighlightingPass.java index dae49482b998..e78c1d957f74 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/FormHighlightingPass.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/FormHighlightingPass.java @@ -19,7 +19,7 @@ package com.intellij.uiDesigner; import com.intellij.codeHighlighting.HighlightingPass; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.uiDesigner.designSurface.GuiEditor; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import org.jetbrains.annotations.NotNull; /** @@ -37,7 +37,7 @@ public class FormHighlightingPass implements HighlightingPass { } public void applyInformationToEditor() { - UIDesignerToolWindowManager.getInstance(myEditor.getProject()).refreshErrors(); + DesignerToolWindowManager.getInstance(myEditor).refreshErrors(); myEditor.refreshIntentionHint(); } -} +}
\ No newline at end of file diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ExpandSelectionAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ExpandSelectionAction.java index c04c39ac4f4b..d1f2e6dd3688 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ExpandSelectionAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ExpandSelectionAction.java @@ -18,13 +18,14 @@ package com.intellij.uiDesigner.actions; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.uiDesigner.*; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; -import com.intellij.uiDesigner.radComponents.RadComponent; -import com.intellij.uiDesigner.radComponents.RadContainer; -import com.intellij.uiDesigner.designSurface.GuiEditor; +import com.intellij.uiDesigner.FormEditingUtil; +import com.intellij.uiDesigner.SelectionState; import com.intellij.uiDesigner.componentTree.ComponentPtr; import com.intellij.uiDesigner.componentTree.ComponentTreeBuilder; +import com.intellij.uiDesigner.designSurface.GuiEditor; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; +import com.intellij.uiDesigner.radComponents.RadComponent; +import com.intellij.uiDesigner.radComponents.RadContainer; import java.util.Stack; @@ -43,7 +44,7 @@ public final class ExpandSelectionAction extends AnAction{ final SelectionState selectionState = editor.getSelectionState(); selectionState.setInsideChange(true); - ComponentTreeBuilder builder = UIDesignerToolWindowManager.getInstance(editor.getProject()).getComponentTreeBuilder(); + ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder(); if (builder != null) { builder.beginUpdateSelection(); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ResetValueAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ResetValueAction.java index 108451fff59c..d9085a3d08c5 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ResetValueAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ResetValueAction.java @@ -18,10 +18,7 @@ package com.intellij.uiDesigner.actions; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.uiDesigner.designSurface.GuiEditor; -import com.intellij.uiDesigner.propertyInspector.Property; -import com.intellij.uiDesigner.propertyInspector.PropertyInspector; -import com.intellij.uiDesigner.propertyInspector.PropertyInspectorTable; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; +import com.intellij.uiDesigner.propertyInspector.*; import com.intellij.uiDesigner.radComponents.RadComponent; import java.util.ArrayList; @@ -44,7 +41,7 @@ public class ResetValueAction extends AbstractGuiEditorAction { public static void doResetValue(final List<RadComponent> selection, final Property property, final GuiEditor editor) { try { if (!editor.ensureEditable()) return; - final PropertyInspector propertyInspector = UIDesignerToolWindowManager.getInstance(editor.getProject()).getPropertyInspector(); + final PropertyInspector propertyInspector = DesignerToolWindowManager.getInstance(editor).getPropertyInspector(); if (propertyInspector.isEditing()) { propertyInspector.stopEditing(); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/SelectAllComponentsAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/SelectAllComponentsAction.java index cdfe0686c438..2569b4fb8477 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/SelectAllComponentsAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/SelectAllComponentsAction.java @@ -15,13 +15,13 @@ */ package com.intellij.uiDesigner.actions; -import com.intellij.uiDesigner.designSurface.GuiEditor; -import com.intellij.uiDesigner.radComponents.RadComponent; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; -import com.intellij.uiDesigner.componentTree.ComponentTreeBuilder; +import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.uiDesigner.FormEditingUtil; +import com.intellij.uiDesigner.componentTree.ComponentTreeBuilder; +import com.intellij.uiDesigner.designSurface.GuiEditor; import com.intellij.uiDesigner.lw.IComponent; -import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; +import com.intellij.uiDesigner.radComponents.RadComponent; import java.util.List; @@ -30,7 +30,7 @@ import java.util.List; */ public class SelectAllComponentsAction extends AbstractGuiEditorAction { protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) { - final ComponentTreeBuilder builder = UIDesignerToolWindowManager.getInstance(editor.getProject()).getComponentTreeBuilder(); + final ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder(); builder.beginUpdateSelection(); try { FormEditingUtil.iterate(editor.getRootContainer(), new FormEditingUtil.ComponentVisitor() { diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShowFormSourceAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShowFormSourceAction.java new file mode 100644 index 000000000000..9ff3f8f6dfa6 --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShowFormSourceAction.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2014 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.actions; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.uiDesigner.designSurface.GuiEditor; +import com.intellij.uiDesigner.radComponents.RadComponent; + +import java.util.List; + +/** + * @author Alexander Lobas + */ +public class ShowFormSourceAction extends AbstractGuiEditorAction { + @Override + protected void actionPerformed(GuiEditor editor, List<RadComponent> selection, AnActionEvent e) { + editor.showFormSource(); + } +}
\ No newline at end of file diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShrinkSelectionAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShrinkSelectionAction.java index ccbbe252164b..20d79845c45f 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShrinkSelectionAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShrinkSelectionAction.java @@ -18,12 +18,12 @@ package com.intellij.uiDesigner.actions; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.uiDesigner.SelectionState; import com.intellij.uiDesigner.FormEditingUtil; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; +import com.intellij.uiDesigner.SelectionState; import com.intellij.uiDesigner.componentTree.ComponentPtr; import com.intellij.uiDesigner.componentTree.ComponentTreeBuilder; import com.intellij.uiDesigner.designSurface.GuiEditor; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import java.util.Stack; @@ -37,7 +37,7 @@ public final class ShrinkSelectionAction extends AnAction{ assert editor != null; final SelectionState selectionState = editor.getSelectionState(); selectionState.setInsideChange(true); - ComponentTreeBuilder builder = UIDesignerToolWindowManager.getInstance(editor.getProject()).getComponentTreeBuilder(); + ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder(); builder.beginUpdateSelection(); try{ diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/componentTree/ComponentTreeBuilder.java b/plugins/ui-designer/src/com/intellij/uiDesigner/componentTree/ComponentTreeBuilder.java index 25791e2815da..aa5161ea0b96 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/componentTree/ComponentTreeBuilder.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/componentTree/ComponentTreeBuilder.java @@ -25,8 +25,8 @@ import com.intellij.uiDesigner.FormEditingUtil; import com.intellij.uiDesigner.HierarchyChangeListener; import com.intellij.uiDesigner.SelectionWatcher; import com.intellij.uiDesigner.designSurface.GuiEditor; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.propertyInspector.PropertyInspector; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; import com.intellij.uiDesigner.radComponents.RadComponent; import com.intellij.uiDesigner.radComponents.RadContainer; import org.jetbrains.annotations.NotNull; @@ -221,7 +221,7 @@ public final class ComponentTreeBuilder extends AbstractTreeBuilder { } private void updateSelection() { - final PropertyInspector propertyInspector = UIDesignerToolWindowManager.getInstance(myEditor.getProject()).getPropertyInspector(); + final PropertyInspector propertyInspector = DesignerToolWindowManager.getInstance(myEditor).getPropertyInspector(); if (propertyInspector.isEditing()) { propertyInspector.stopEditing(); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/DesignDropTargetListener.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/DesignDropTargetListener.java index d96eac097f48..f3ddc85e9280 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/DesignDropTargetListener.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/DesignDropTargetListener.java @@ -15,26 +15,26 @@ */ package com.intellij.uiDesigner.designSurface; -import com.intellij.ide.palette.impl.PaletteManager; +import com.intellij.ide.palette.impl.PaletteToolWindowManager; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.uiDesigner.CutCopyPasteSupport; import com.intellij.uiDesigner.FormEditingUtil; import com.intellij.uiDesigner.SimpleTransferable; import com.intellij.uiDesigner.UIDesignerBundle; import com.intellij.uiDesigner.componentTree.ComponentTree; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.palette.ComponentItem; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.radComponents.RadComponent; import com.intellij.uiDesigner.radComponents.RadContainer; import javax.swing.*; import java.awt.*; import java.awt.dnd.*; -import java.util.List; import java.util.ArrayList; +import java.util.List; /** * @author yole @@ -49,12 +49,10 @@ class DesignDropTargetListener implements DropTargetListener { private final GuiEditor myEditor; private final GridInsertProcessor myGridInsertProcessor; private boolean myUseDragDelta = false; - private final ComponentTree myComponentTree; public DesignDropTargetListener(final GuiEditor editor) { myEditor = editor; myGridInsertProcessor = new GridInsertProcessor(editor); - myComponentTree = UIDesignerToolWindowManager.getInstance(editor.getProject()).getComponentTree(); } public void dragEnter(DropTargetDragEvent dtde) { @@ -150,16 +148,18 @@ class DesignDropTargetListener implements DropTargetListener { myEditor.getDragLayer().repaint(); ComponentDropLocation location = myGridInsertProcessor.processDragEvent(dtde.getLocation(), myComponentDragObject); + ComponentTree componentTree = DesignerToolWindowManager.getInstance(myEditor).getComponentTree(); + if (!location.canDrop(myComponentDragObject) || (myDraggedComponentList != null && FormEditingUtil.isDropOnChild(myDraggedComponentList, location))) { - if (myComponentTree != null) { - myComponentTree.setDropTargetComponent(null); + if (componentTree != null) { + componentTree.setDropTargetComponent(null); } dtde.rejectDrag(); } else { - if (myComponentTree != null) { - myComponentTree.setDropTargetComponent(location.getContainer()); + if (componentTree != null) { + componentTree.setDropTargetComponent(location.getContainer()); } dtde.acceptDrag(dtde.getDropAction()); } @@ -178,8 +178,9 @@ class DesignDropTargetListener implements DropTargetListener { public void dragExit(DropTargetEvent dte) { try { - if (myComponentTree != null) { - myComponentTree.setDropTargetComponent(null); + ComponentTree componentTree = DesignerToolWindowManager.getInstance(myEditor).getComponentTree(); + if (componentTree != null) { + componentTree.setDropTargetComponent(null); } myUseDragDelta = false; if (myDraggedComponentList != null) { @@ -198,8 +199,9 @@ class DesignDropTargetListener implements DropTargetListener { public void drop(final DropTargetDropEvent dtde) { try { - if (myComponentTree != null) { - myComponentTree.setDropTargetComponent(null); + ComponentTree componentTree = DesignerToolWindowManager.getInstance(myEditor).getComponentTree(); + if (componentTree != null) { + componentTree.setDropTargetComponent(null); } @@ -221,7 +223,7 @@ class DesignDropTargetListener implements DropTargetListener { new InsertComponentProcessor(myEditor).processComponentInsert(dtde.getLocation(), componentItem); ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { - PaletteManager.getInstance(myEditor.getProject()).clearActiveItem(); + PaletteToolWindowManager.getInstance(myEditor).clearActiveItem(); myEditor.getActiveDecorationLayer().removeFeedback(); myEditor.getLayeredPane().setCursor(null); myEditor.getGlassLayer().requestFocus(); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GlassLayer.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GlassLayer.java index 015a9dc4653e..8122989132d8 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GlassLayer.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GlassLayer.java @@ -21,7 +21,7 @@ import com.intellij.ui.popup.PopupOwner; import com.intellij.uiDesigner.FormEditingUtil; import com.intellij.uiDesigner.actions.*; import com.intellij.uiDesigner.componentTree.ComponentTree; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.radComponents.RadComponent; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -136,7 +136,7 @@ public final class GlassLayer extends JComponent implements DataProvider, PopupO */ public Object getData(final String dataId) { if(CommonDataKeys.NAVIGATABLE.is(dataId)) { - final ComponentTree componentTree = UIDesignerToolWindowManager.getInstance(myEditor.getProject()).getComponentTree(); + final ComponentTree componentTree = DesignerToolWindowManager.getInstance(myEditor).getComponentTree(); if (componentTree != null) { return componentTree.getData(dataId); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GridCaptionPanel.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GridCaptionPanel.java index 77d3104abccc..99a982f5acd3 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GridCaptionPanel.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GridCaptionPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -20,7 +20,10 @@ import com.intellij.ide.DeleteProvider; import com.intellij.ide.dnd.*; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.colors.EditorColors; +import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.util.Pair; +import com.intellij.ui.JBColor; import com.intellij.ui.LightColors; import com.intellij.uiDesigner.CaptionSelection; import com.intellij.uiDesigner.FormEditingUtil; @@ -33,7 +36,9 @@ import com.intellij.uiDesigner.radComponents.RadContainer; import com.intellij.uiDesigner.radComponents.RadRootContainer; import com.intellij.util.Alarm; import com.intellij.util.ArrayUtil; +import com.intellij.util.NotNullProducer; import com.intellij.util.ui.PlatformColors; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -72,7 +77,7 @@ public class GridCaptionPanel extends JPanel implements ComponentSelectionListen myEditor.fireSelectedComponentChanged(); } }); - setBackground(Color.LIGHT_GRAY); + setBackground(getGutterColor()); editor.addComponentSelectionListener(this); final MyMouseListener listener = new MyMouseListener(); @@ -101,6 +106,17 @@ public class GridCaptionPanel extends JPanel implements ComponentSelectionListen }); } + public static JBColor getGutterColor() { + return new JBColor(new NotNullProducer<Color>() { + @NotNull + @Override + public Color produce() { + Color color = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.GUTTER_BACKGROUND); + return color == null ? UIUtil.getPanelBackground() : color; + } + }); + } + public RadContainer getSelectedContainer() { // when the selected component changes, and we have focus, PropertyInspector asks us about our container and selection. // PropertyInspector's selection changed listener can be called before our own listener, so we need to update ourselves diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java index dbbc27655f4e..7459a05a33c3 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -16,9 +16,11 @@ package com.intellij.uiDesigner.designSurface; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; +import com.intellij.designer.DesignerEditorPanelFacade; +import com.intellij.designer.LightFillLayout; import com.intellij.ide.DeleteProvider; -import com.intellij.ide.palette.PaletteDragEventListener; -import com.intellij.ide.palette.impl.PaletteManager; +import com.intellij.ide.highlighter.XmlFileHighlighter; +import com.intellij.ide.palette.impl.PaletteToolWindowManager; import com.intellij.lang.properties.psi.PropertiesFile; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; @@ -27,14 +29,23 @@ import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.undo.UndoManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorFactory; +import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.event.DocumentAdapter; import com.intellij.openapi.editor.event.DocumentEvent; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogBuilder; +import com.intellij.openapi.ui.ThreeComponentsSplitter; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.ReadonlyStatusHandler; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; @@ -48,19 +59,22 @@ import com.intellij.uiDesigner.componentTree.ComponentSelectionListener; import com.intellij.uiDesigner.componentTree.ComponentTree; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Util; +import com.intellij.uiDesigner.editor.UIFormEditor; import com.intellij.uiDesigner.lw.CompiledClassPropertiesProvider; import com.intellij.uiDesigner.lw.IComponent; import com.intellij.uiDesigner.lw.IProperty; import com.intellij.uiDesigner.lw.LwRootContainer; import com.intellij.uiDesigner.palette.ComponentItem; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindow; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.propertyInspector.PropertyInspector; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; import com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty; import com.intellij.uiDesigner.radComponents.RadComponent; import com.intellij.uiDesigner.radComponents.RadContainer; import com.intellij.uiDesigner.radComponents.RadRootContainer; import com.intellij.uiDesigner.radComponents.RadTabbedPane; import com.intellij.util.Alarm; +import com.intellij.util.NotNullProducer; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -69,11 +83,13 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.EventListenerList; import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.dnd.DnDConstants; import java.awt.dnd.DropTarget; -import java.awt.event.*; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Locale; @@ -87,10 +103,11 @@ import java.util.Map; * @author Anton Katilin * @author Vladimir Kondratyev */ -public final class GuiEditor extends JPanel implements DataProvider, ModuleProvider { +public final class GuiEditor extends JPanel implements DesignerEditorPanelFacade, DataProvider, ModuleProvider { private static final Logger LOG = Logger.getInstance("#com.intellij.uiDesigner.GuiEditor"); private final Project myProject; + @NotNull private final UIFormEditor myEditor; private Module myModule; @NotNull private final VirtualFile myFile; @@ -175,7 +192,9 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi */ private boolean myInsideChange; private final DocumentAdapter myDocumentListener; - private final CardLayout myCardLayout; + private final CardLayout myCardLayout = new CardLayout(); + private final ThreeComponentsSplitter myContentSplitter = new ThreeComponentsSplitter(); + private final JPanel myCardPanel = new JPanel(myCardLayout); @NonNls private final static String CARD_VALID = "valid"; @NonNls private final static String CARD_INVALID = "invalid"; @@ -198,9 +217,6 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi private final QuickFixManagerImpl myQuickFixManager; private final GridCaptionPanel myHorzCaptionPanel; private final GridCaptionPanel myVertCaptionPanel; - private final MyPaletteKeyListener myPaletteKeyListener; - private final MyPaletteDragListener myPaletteDragListener; - private final MyPaletteSelectionListener myPaletteSelectionListener; private ComponentPtr mySelectionAnchor; private ComponentPtr mySelectionLead; /** @@ -214,11 +230,11 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi /** * @param file file to be edited - * @throws java.lang.IllegalArgumentException - * if the <code>file</code> - * is <code>null</code> or <code>file</code> is not valid PsiFile + * @throws java.lang.IllegalArgumentException if the <code>file</code> + * is <code>null</code> or <code>file</code> is not valid PsiFile */ - public GuiEditor(Project project, @NotNull final Module module, @NotNull final VirtualFile file) { + public GuiEditor(@NotNull UIFormEditor editor, @NotNull Project project, @NotNull Module module, @NotNull VirtualFile file) { + myEditor = editor; LOG.assertTrue(file.isValid()); myProject = project; @@ -227,13 +243,25 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi myCutCopyPasteSupport = new CutCopyPasteSupport(this); - myCardLayout = new CardLayout(); - setLayout(myCardLayout); + setLayout(new BorderLayout()); + + myContentSplitter.setDividerWidth(0); + myContentSplitter.setDividerMouseZoneSize(Registry.intValue("ide.splitter.mouseZone")); + add(myContentSplitter, BorderLayout.CENTER); myValidCard = new JPanel(new BorderLayout()); myInvalidCard = createInvalidCard(); - add(myValidCard, CARD_VALID); - add(myInvalidCard, CARD_INVALID); + + myCardPanel.add(myValidCard, CARD_VALID); + myCardPanel.add(myInvalidCard, CARD_INVALID); + + JPanel contentPanel = new JPanel(new LightFillLayout()); + JLabel toolbar = new JLabel(); + toolbar.setVisible(false); + contentPanel.add(toolbar); + contentPanel.add(myCardPanel); + + myContentSplitter.setInnerComponent(contentPanel); myListenerList = new EventListenerList(); @@ -288,7 +316,7 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi readFromFile(false); JPanel panel = new JPanel(new GridBagLayout()); - panel.setBackground(Color.LIGHT_GRAY); + panel.setBackground(GridCaptionPanel.getGutterColor()); myHorzCaptionPanel = new GridCaptionPanel(this, false); myVertCaptionPanel = new GridCaptionPanel(this, true); @@ -311,7 +339,13 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi gbc.weighty = 1.0; myScrollPane = ScrollPaneFactory.createScrollPane(myLayeredPane); - myScrollPane.setBackground(new JBColor(Color.WHITE, UIUtil.getListBackground())); + myScrollPane.setBackground(new JBColor(new NotNullProducer<Color>() { + @NotNull + @Override + public Color produce() { + return EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground(); + } + })); panel.add(myScrollPane, gbc); myHorzCaptionPanel.attachToScrollPane(myScrollPane); myVertCaptionPanel.attachToScrollPane(myScrollPane); @@ -336,18 +370,28 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi myActiveDecorationLayer.installSelectionWatcher(); - final PaletteManager paletteManager = PaletteManager.getInstance(getProject()); - myPaletteKeyListener = new MyPaletteKeyListener(); - paletteManager.addKeyListener(myPaletteKeyListener); - myPaletteDragListener = new MyPaletteDragListener(); - paletteManager.addDragEventListener(myPaletteDragListener); - myPaletteSelectionListener = new MyPaletteSelectionListener(); - paletteManager.addSelectionListener(myPaletteSelectionListener); - ActionManager.getInstance().getAction("GuiDesigner.IncreaseIndent").registerCustomShortcutSet( new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)), myGlassLayer); ActionManager.getInstance().getAction("GuiDesigner.DecreaseIndent").registerCustomShortcutSet( new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK)), myGlassLayer); + + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + DesignerToolWindowManager.getInstance(myProject).bind(GuiEditor.this); + PaletteToolWindowManager.getInstance(myProject).bind(GuiEditor.this); + } + }); + } + + @Override + public ThreeComponentsSplitter getContentSplitter() { + return myContentSplitter; + } + + @NotNull + public UIFormEditor getEditor() { + return myEditor; } @NotNull @@ -366,13 +410,14 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi myWhere = new Exception(); } - final PaletteManager paletteManager = PaletteManager.getInstance(getProject()); - paletteManager.removeKeyListener(myPaletteKeyListener); - paletteManager.removeDragEventListener(myPaletteDragListener); - paletteManager.removeSelectionListener(myPaletteSelectionListener); myDocument.removeDocumentListener(myDocumentListener); PsiManager.getInstance(getProject()).removePsiTreeChangeListener(myPsiTreeChangeListener); + + DesignerToolWindowManager.getInstance(myProject).dispose(this); + PaletteToolWindowManager.getInstance(myProject).dispose(this); myPsiTreeChangeListener.dispose(); + + Disposer.dispose(myContentSplitter); } @NotNull @@ -440,8 +485,7 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi public void refreshAndSave(final boolean forceSync) { // Update property inspector - final UIDesignerToolWindowManager manager = UIDesignerToolWindowManager.getInstance(getProject()); - final PropertyInspector propertyInspector = manager.getPropertyInspector(); + final PropertyInspector propertyInspector = DesignerToolWindowManager.getInstance(this).getPropertyInspector(); if (propertyInspector != null) { propertyInspector.synchWithTree(forceSync); } @@ -490,8 +534,7 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi // Standard Swing cut/copy/paste actions should work if user is editing something inside property inspector Project project = getProject(); if (project.isDisposed()) return null; - final UIDesignerToolWindowManager manager = UIDesignerToolWindowManager.getInstance(project); - final PropertyInspector inspector = manager.getPropertyInspector(); + final PropertyInspector inspector = DesignerToolWindowManager.getInstance(this).getPropertyInspector(); if (inspector != null && inspector.isEditing()) { return null; } @@ -519,7 +562,7 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi /** * @return the component which represents DnD layer. All currently - * dragged (moved) component are on this layer. + * dragged (moved) component are on this layer. */ public DragLayer getDragLayer() { return myDragLayer; @@ -527,7 +570,7 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi /** * @return the topmost <code>UiConainer</code> which in the root of - * component hierarchy. This method never returns <code>null</code>. + * component hierarchy. This method never returns <code>null</code>. */ @NotNull public RadRootContainer getRootContainer() { @@ -558,7 +601,7 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi /** * @return the component which represents layer with active decorators - * such as grid edit controls, inplace editors, etc. + * such as grid edit controls, inplace editors, etc. */ public InplaceEditingLayer getInplaceEditingLayer() { return myInplaceEditingLayer; @@ -648,7 +691,7 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi public void setStringDescriptorLocale(final Locale locale) { myRootContainer.setStringDescriptorLocale(locale); refreshProperties(); - UIDesignerToolWindowManager.getInstance(getProject()).updateComponentTree(); + DesignerToolWindowManager.getInstance(this).updateComponentTree(); DaemonCodeAnalyzer.getInstance(getProject()).restart(); } @@ -686,10 +729,10 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi }); if (!anythingModified.isNull()) { refresh(); - final UIDesignerToolWindowManager twm = UIDesignerToolWindowManager.getInstance(getProject()); - ComponentTree tree = twm.getComponentTree(); + DesignerToolWindow designerToolWindow = DesignerToolWindowManager.getInstance(this); + ComponentTree tree = designerToolWindow.getComponentTree(); if (tree != null) tree.repaint(); - PropertyInspector inspector = twm.getPropertyInspector(); + PropertyInspector inspector = designerToolWindow.getPropertyInspector(); if (inspector != null) inspector.synchWithTree(true); } } @@ -852,7 +895,7 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi restoreTabbedPaneSelectedTabs(tabbedPaneSelectedTabs); } myInvalid = false; - myCardLayout.show(this, CARD_VALID); + myCardLayout.show(myCardPanel, CARD_VALID); refresh(); } catch (Exception exc) { @@ -873,7 +916,7 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi setRootContainer(new RadRootContainer(this, "0")); myFormInvalidLabel.setText(UIDesignerBundle.message("error.form.file.is.invalid.message", FormEditingUtil.getExceptionMessage(exc))); myInvalid = true; - myCardLayout.show(this, CARD_INVALID); + myCardLayout.show(myCardPanel, CARD_INVALID); repaint(); } @@ -976,14 +1019,35 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi return undoManager.isUndoInProgress() || undoManager.isRedoInProgress(); } - private boolean isActiveEditor() { - return UIDesignerToolWindowManager.getInstance(getProject()).getActiveFormEditor() == this; - } - void hideIntentionHint() { myQuickFixManager.hideIntentionHint(); } + public void showFormSource() { + EditorFactory editorFactory = EditorFactory.getInstance(); + + Editor editor = editorFactory.createViewer(myDocument, myProject); + + try { + ((EditorEx)editor).setHighlighter( + new LexerEditorHighlighter(new XmlFileHighlighter(), EditorColorsManager.getInstance().getGlobalScheme())); + + JComponent component = editor.getComponent(); + component.setPreferredSize(new Dimension(640, 480)); + + DialogBuilder dialog = new DialogBuilder(myProject); + + dialog.title("Form - " + myFile.getPresentableName()).dimensionKey("GuiDesigner.FormSource.Dialog"); + dialog.centerPanel(component).setPreferredFocusComponent(editor.getContentComponent()); + dialog.addOkAction(); + + dialog.show(); + } + finally { + editorFactory.releaseEditor(editor); + } + } + private final class MyLayeredPane extends JBLayeredPane implements Scrollable { /** * All components allocate whole pane's area. @@ -1051,8 +1115,7 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi } public void update(final AnActionEvent e) { - final UIDesignerToolWindowManager manager = UIDesignerToolWindowManager.getInstance(getProject()); - PropertyInspector inspector = manager.getPropertyInspector(); + PropertyInspector inspector = DesignerToolWindowManager.getInstance(GuiEditor.this).getPropertyInspector(); e.getPresentation().setEnabled(inspector != null && !inspector.isEditing()); } } @@ -1073,9 +1136,8 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi } public boolean canDeleteElement(@NotNull final DataContext dataContext) { - final UIDesignerToolWindowManager manager = UIDesignerToolWindowManager.getInstance(getProject()); return - !manager.getPropertyInspector().isEditing() && + !DesignerToolWindowManager.getInstance(GuiEditor.this).getPropertyInspector().isEditing() && !myInplaceEditingLayer.isEditing() && FormEditingUtil.canDeleteSelection(GuiEditor.this); } @@ -1179,39 +1241,30 @@ public final class GuiEditor extends JPanel implements DataProvider, ModuleProvi } } - private class MyPaletteKeyListener extends KeyAdapter { - @Override - public void keyPressed(KeyEvent e) { - PaletteManager paletteManager = PaletteManager.getInstance(getProject()); - if (e.getKeyCode() == KeyEvent.VK_SHIFT && paletteManager.getActiveItem(ComponentItem.class) != null && isActiveEditor()) { - setDesignTimeInsets(12); - } + public void paletteKeyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_SHIFT && PaletteToolWindowManager.getInstance(this).getActiveItem(ComponentItem.class) != null) { + setDesignTimeInsets(12); } + } - @Override - public void keyReleased(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_SHIFT) { - setDesignTimeInsets(2); - } + public void paletteKeyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_SHIFT) { + setDesignTimeInsets(2); } } - private class MyPaletteDragListener implements PaletteDragEventListener { - public void dropActionChanged(int gestureModifiers) { - if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0 && isActiveEditor()) { - setDesignTimeInsets(12); - } - else { - setDesignTimeInsets(2); - } + public void paletteDropActionChanged(int gestureModifiers) { + if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) { + setDesignTimeInsets(12); + } + else { + setDesignTimeInsets(2); } } - private class MyPaletteSelectionListener implements ListSelectionListener { - public void valueChanged(ListSelectionEvent e) { - if (PaletteManager.getInstance(getProject()).getActiveItem() == null) { - myProcessor.cancelPaletteInsert(); - } + public void paletteValueChanged(ListSelectionEvent e) { + if (PaletteToolWindowManager.getInstance(this).getActiveItem() == null) { + myProcessor.cancelPaletteInsert(); } } -} +}
\ No newline at end of file diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/InsertComponentProcessor.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/InsertComponentProcessor.java index b088447afa0b..4eb3f32a0ed3 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/InsertComponentProcessor.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/InsertComponentProcessor.java @@ -17,7 +17,7 @@ package com.intellij.uiDesigner.designSurface; import com.intellij.CommonBundle; import com.intellij.codeInsight.FileModificationService; -import com.intellij.ide.palette.impl.PaletteManager; +import com.intellij.ide.palette.impl.PaletteToolWindowManager; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; @@ -63,7 +63,6 @@ import java.util.Map; public final class InsertComponentProcessor extends EventProcessor { private static final Logger LOG = Logger.getInstance("#com.intellij.uiDesigner.designSurface.InsertComponentProcessor"); - private final PaletteManager myPaletteManager; private final GuiEditor myEditor; private boolean mySticky; private RadComponent myInsertedComponent; @@ -87,7 +86,6 @@ public final class InsertComponentProcessor extends EventProcessor { public InsertComponentProcessor(@NotNull final GuiEditor editor) { myEditor = editor; myGridInsertProcessor = new GridInsertProcessor(editor); - myPaletteManager = PaletteManager.getInstance(editor.getProject()); } public void setSticky(final boolean sticky) { @@ -261,7 +259,7 @@ public final class InsertComponentProcessor extends EventProcessor { private ComponentItem getComponentToInsert() { return (myComponentToInsert != null) ? myComponentToInsert - : myPaletteManager.getActiveItem(ComponentItem.class); + : PaletteToolWindowManager.getInstance(myEditor).getActiveItem(ComponentItem.class); } public void processComponentInsert(@NotNull final Point point, final ComponentItem item) { @@ -295,7 +293,7 @@ public final class InsertComponentProcessor extends EventProcessor { setCursor(Cursor.getDefaultCursor()); if (myInsertedComponent == null) { if (!mySticky) { - PaletteManager.getInstance(myEditor.getProject()).clearActiveItem(); + PaletteToolWindowManager.getInstance(myEditor).clearActiveItem(); } return; } @@ -328,7 +326,7 @@ public final class InsertComponentProcessor extends EventProcessor { checkBindTopLevelPanel(); if (!mySticky) { - PaletteManager.getInstance(myEditor.getProject()).clearActiveItem(); + PaletteToolWindowManager.getInstance(myEditor).clearActiveItem(); } myEditor.refreshAndSave(false); @@ -578,7 +576,7 @@ public final class InsertComponentProcessor extends EventProcessor { } public Cursor processMouseMoveEvent(final MouseEvent e) { - final ComponentItem componentItem = myPaletteManager.getActiveItem(ComponentItem.class); + final ComponentItem componentItem = PaletteToolWindowManager.getInstance(myEditor).getActiveItem(ComponentItem.class); if (componentItem != null) { return myGridInsertProcessor.processMouseMoveEvent(e.getPoint(), false, new ComponentItemDragObject(componentItem)); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/MainProcessor.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/MainProcessor.java index 3816a3aa66f8..951ae951f56e 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/MainProcessor.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/MainProcessor.java @@ -15,7 +15,7 @@ */ package com.intellij.uiDesigner.designSurface; -import com.intellij.ide.palette.impl.PaletteManager; +import com.intellij.ide.palette.impl.PaletteToolWindowManager; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.uiDesigner.FormEditingUtil; @@ -58,7 +58,7 @@ public final class MainProcessor extends EventProcessor{ if (e.getKeyCode() == KeyEvent.VK_SHIFT) { if (e.getID() == KeyEvent.KEY_PRESSED) { if ((myCurrentProcessor != null && myCurrentProcessor.isDragActive()) || - (PaletteManager.getInstance(myEditor.getProject()).getActiveItem(ComponentItem.class) != null && + (PaletteToolWindowManager.getInstance(myEditor).getActiveItem(ComponentItem.class) != null && myCurrentProcessor != myInsertComponentProcessor)) { myEditor.setDesignTimeInsets(12); } @@ -151,7 +151,7 @@ public final class MainProcessor extends EventProcessor{ Cursor cursor = Cursor.getDefaultCursor(); if(id==MouseEvent.MOUSE_MOVED){ - if (PaletteManager.getInstance(myEditor.getProject()).getActiveItem(ComponentItem.class) != null) { + if (PaletteToolWindowManager.getInstance(myEditor).getActiveItem(ComponentItem.class) != null) { if (myInsertFeedbackEnabled) { cursor = myInsertComponentProcessor.processMouseMoveEvent(e); } @@ -292,7 +292,7 @@ public final class MainProcessor extends EventProcessor{ return; } - final ComponentItem selectedItem = PaletteManager.getInstance(myEditor.getProject()).getActiveItem(ComponentItem.class); + final ComponentItem selectedItem = PaletteToolWindowManager.getInstance(myEditor).getActiveItem(ComponentItem.class); if (selectedItem != null) { myInsertComponentProcessor.setSticky(UIUtil.isControlKeyDown(e)); myCurrentProcessor = myInsertComponentProcessor; @@ -341,7 +341,7 @@ public final class MainProcessor extends EventProcessor{ return true; } } - else if (PaletteManager.getInstance(myEditor.getProject()).getActiveItem(ComponentItem.class) != null) { + else if (PaletteToolWindowManager.getInstance(myEditor).getActiveItem(ComponentItem.class) != null) { cancelPaletteInsert(); return true; } @@ -349,7 +349,7 @@ public final class MainProcessor extends EventProcessor{ } void cancelPaletteInsert() { - PaletteManager.getInstance(myEditor.getProject()).clearActiveItem(); + PaletteToolWindowManager.getInstance(myEditor).clearActiveItem(); myEditor.getLayeredPane().setCursor(Cursor.getDefaultCursor()); myEditor.getActiveDecorationLayer().removeFeedback(); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/PassiveDecorationLayer.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/PassiveDecorationLayer.java index 070612857a53..1153adadfdf0 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/PassiveDecorationLayer.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/PassiveDecorationLayer.java @@ -17,7 +17,7 @@ package com.intellij.uiDesigner.designSurface; import com.intellij.uiDesigner.FormEditingUtil; import com.intellij.uiDesigner.componentTree.ComponentTree; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.radComponents.RadButtonGroup; import com.intellij.uiDesigner.radComponents.RadComponent; import com.intellij.uiDesigner.radComponents.RadRootContainer; @@ -56,7 +56,7 @@ class PassiveDecorationLayer extends JComponent{ final Set<RadButtonGroup> paintedGroups = new HashSet<RadButtonGroup>(); final RadRootContainer rootContainer = myEditor.getRootContainer(); - final ComponentTree componentTree = UIDesignerToolWindowManager.getInstance(component.getProject()).getComponentTree(); + final ComponentTree componentTree = DesignerToolWindowManager.getInstance(myEditor).getComponentTree(); final Collection<RadButtonGroup> selectedGroups = componentTree != null ? componentTree.getSelectedElements(RadButtonGroup.class) : Collections.<RadButtonGroup>emptyList(); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/QuickFixManagerImpl.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/QuickFixManagerImpl.java index 15e1c34daf78..241ae963a3cd 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/QuickFixManagerImpl.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/QuickFixManagerImpl.java @@ -18,14 +18,12 @@ package com.intellij.uiDesigner.designSurface; import com.intellij.uiDesigner.ErrorAnalyzer; import com.intellij.uiDesigner.ErrorInfo; import com.intellij.uiDesigner.FormEditingUtil; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; +import com.intellij.uiDesigner.componentTree.ComponentSelectionListener; import com.intellij.uiDesigner.quickFixes.QuickFixManager; import com.intellij.uiDesigner.radComponents.RadComponent; import org.jetbrains.annotations.NotNull; import javax.swing.*; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; import java.awt.*; import java.util.ArrayList; @@ -35,9 +33,9 @@ import java.util.ArrayList; public class QuickFixManagerImpl extends QuickFixManager<GlassLayer> { public QuickFixManagerImpl(final GuiEditor editor, final GlassLayer component, final JViewport viewPort) { super(editor, component, viewPort); - final UIDesignerToolWindowManager toolWindowManager = UIDesignerToolWindowManager.getInstance(editor.getProject()); - toolWindowManager.addComponentSelectionListener(new TreeSelectionListener() { - public void valueChanged(TreeSelectionEvent e) { + editor.addComponentSelectionListener(new ComponentSelectionListener() { + @Override + public void selectedComponentChanged(GuiEditor source) { hideIntentionHint(); updateIntentionHintVisibility(); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/editor/UIFormEditor.java b/plugins/ui-designer/src/com/intellij/uiDesigner/editor/UIFormEditor.java index 796b880b6244..c457500c703c 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/editor/UIFormEditor.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/editor/UIFormEditor.java @@ -48,14 +48,14 @@ public final class UIFormEditor extends UserDataHolderBase implements /*Navigata private final GuiEditor myEditor; private UIFormEditor.MyBackgroundEditorHighlighter myBackgroundEditorHighlighter; - public UIFormEditor(final Project project, final VirtualFile file){ + public UIFormEditor(@NotNull final Project project, @NotNull final VirtualFile file){ final VirtualFile vf = file instanceof LightVirtualFile ? ((LightVirtualFile)file).getOriginalFile() : file; final Module module = ModuleUtil.findModuleForFile(vf, project); if (module == null) { throw new IllegalArgumentException("No module for file " + file + " in project " + project); } myFile = file; - myEditor = new GuiEditor(project, module, file); + myEditor = new GuiEditor(this, project, module, file); } @NotNull diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/editor/UIFormEditorProvider.java b/plugins/ui-designer/src/com/intellij/uiDesigner/editor/UIFormEditorProvider.java index 8500c056204a..1e043a3be4af 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/editor/UIFormEditorProvider.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/editor/UIFormEditorProvider.java @@ -15,7 +15,6 @@ */ package com.intellij.uiDesigner.editor; -import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorPolicy; @@ -66,9 +65,6 @@ public final class UIFormEditorProvider implements FileEditorProvider, DumbAware } @NotNull public FileEditorPolicy getPolicy() { - return - ApplicationManagerEx.getApplicationEx().isInternal() ? - FileEditorPolicy.PLACE_BEFORE_DEFAULT_EDITOR : FileEditorPolicy.HIDE_DEFAULT_EDITOR; + return FileEditorPolicy.HIDE_DEFAULT_EDITOR; } - -} +}
\ No newline at end of file diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/DesignerToolWindow.java b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/DesignerToolWindow.java new file mode 100644 index 000000000000..e8164e19e21e --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/DesignerToolWindow.java @@ -0,0 +1,139 @@ +/* + * Copyright 2000-2014 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.propertyInspector; + +import com.intellij.designer.LightToolWindowContent; +import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Splitter; +import com.intellij.openapi.util.Disposer; +import com.intellij.ui.IdeBorderFactory; +import com.intellij.ui.ScrollPaneFactory; +import com.intellij.ui.SideBorder; +import com.intellij.uiDesigner.componentTree.ComponentTree; +import com.intellij.uiDesigner.componentTree.ComponentTreeBuilder; +import com.intellij.uiDesigner.designSurface.GuiEditor; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import java.awt.*; + +/** + * @author Alexander Lobas + */ +public class DesignerToolWindow implements LightToolWindowContent { + private final MyToolWindowPanel myToolWindowPanel = new MyToolWindowPanel(); + private ComponentTree myComponentTree; + private ComponentTreeBuilder myComponentTreeBuilder; + private PropertyInspector myPropertyInspector; + + public DesignerToolWindow(Project project) { + myComponentTree = new ComponentTree(project); + + JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myComponentTree); + scrollPane.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM)); + scrollPane.setPreferredSize(new Dimension(250, -1)); + myComponentTree.initQuickFixManager(scrollPane.getViewport()); + + myPropertyInspector = new PropertyInspector(project, myComponentTree); + + myToolWindowPanel.setFirstComponent(scrollPane); + myToolWindowPanel.setSecondComponent(myPropertyInspector); + } + + @Override + public void dispose() { + clearTreeBuilder(); + myToolWindowPanel.dispose(); + myComponentTree = null; + myPropertyInspector = null; + } + + private void clearTreeBuilder() { + if (myComponentTreeBuilder != null) { + Disposer.dispose(myComponentTreeBuilder); + myComponentTreeBuilder = null; + } + } + + public void update(GuiEditor designer) { + clearTreeBuilder(); + + myComponentTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); + myComponentTree.setEditor(designer); + myPropertyInspector.setEditor(designer); + + if (designer == null) { + myComponentTree.setFormEditor(null); + } + else { + myComponentTree.setFormEditor(designer.getEditor()); + myComponentTreeBuilder = new ComponentTreeBuilder(myComponentTree, designer); + } + } + + public JComponent getToolWindowPanel() { + return myToolWindowPanel; + } + + public ComponentTree getComponentTree() { + return myComponentTree; + } + + public ComponentTreeBuilder getComponentTreeBuilder() { + return myComponentTreeBuilder; + } + + public void updateComponentTree() { + if (myComponentTreeBuilder != null) { + myComponentTreeBuilder.queueUpdate(); + } + } + + public PropertyInspector getPropertyInspector() { + return myPropertyInspector; + } + + public void refreshErrors() { + if (myComponentTree != null) { + myComponentTree.refreshIntentionHint(); + myComponentTree.repaint(myComponentTree.getVisibleRect()); + } + + // PropertyInspector + if (myPropertyInspector != null) { + myPropertyInspector.refreshIntentionHint(); + myPropertyInspector.repaint(myPropertyInspector.getVisibleRect()); + } + } + + private class MyToolWindowPanel extends Splitter implements DataProvider { + MyToolWindowPanel() { + super(true, 0.33f); + } + + @Nullable + public Object getData(@NonNls String dataId) { + if (GuiEditor.DATA_KEY.is(dataId) && myComponentTree != null) { + return myComponentTree.getData(dataId); + } + return null; + } + } +}
\ No newline at end of file diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/DesignerToolWindowManager.java b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/DesignerToolWindowManager.java new file mode 100644 index 000000000000..36e6935dae99 --- /dev/null +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/DesignerToolWindowManager.java @@ -0,0 +1,131 @@ +/* + * Copyright 2000-2014 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.propertyInspector; + +import com.intellij.designer.DesignerEditorPanelFacade; +import com.intellij.designer.LightToolWindow; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ToolWindowAnchor; +import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.openapi.wm.impl.content.ToolWindowContentUi; +import com.intellij.ui.content.Content; +import com.intellij.ui.content.ContentManager; +import com.intellij.uiDesigner.AbstractToolWindowManager; +import com.intellij.uiDesigner.UIDesignerBundle; +import com.intellij.uiDesigner.designSurface.GuiEditor; +import icons.UIDesignerIcons; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Alexander Lobas + */ +public class DesignerToolWindowManager extends AbstractToolWindowManager { + private final DesignerToolWindow myToolWindowPanel; + + public DesignerToolWindowManager(Project project, FileEditorManager fileEditorManager) { + super(project, fileEditorManager); + myToolWindowPanel = ApplicationManager.getApplication().isHeadlessEnvironment() ? null : new DesignerToolWindow(project); + } + + public static DesignerToolWindow getInstance(GuiEditor designer) { + DesignerToolWindowManager manager = getInstance(designer.getProject()); + if (manager.isEditorMode()) { + return (DesignerToolWindow)manager.getContent(designer); + } + return manager.myToolWindowPanel; + } + + public static DesignerToolWindowManager getInstance(Project project) { + return project.getComponent(DesignerToolWindowManager.class); + } + + @Nullable + public GuiEditor getActiveFormEditor() { + return (GuiEditor)getActiveDesigner(); + } + + @Override + protected void initToolWindow() { + myToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(UIDesignerBundle.message("toolwindow.ui.designer.name"), + false, getAnchor(), myProject, true); + myToolWindow.setIcon(UIDesignerIcons.ToolWindowUIDesigner); + + if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { + myToolWindow.getComponent().putClientProperty(ToolWindowContentUi.HIDE_ID_LABEL, "true"); + } + + initGearActions(); + + ContentManager contentManager = myToolWindow.getContentManager(); + Content content = + contentManager.getFactory() + .createContent(myToolWindowPanel.getToolWindowPanel(), UIDesignerBundle.message("toolwindow.ui.designer.title"), false); + content.setCloseable(false); + content.setPreferredFocusableComponent(myToolWindowPanel.getComponentTree()); + contentManager.addContent(content); + contentManager.setSelectedContent(content, true); + myToolWindow.setAvailable(false, null); + } + + @Override + protected void updateToolWindow(@Nullable DesignerEditorPanelFacade designer) { + myToolWindowPanel.update((GuiEditor)designer); + + if (designer == null) { + myToolWindow.setAvailable(false, null); + } + else { + myToolWindow.setAvailable(true, null); + myToolWindow.show(null); + } + } + + @Override + protected ToolWindowAnchor getAnchor() { + return ToolWindowAnchor.LEFT; + } + + @Override + protected LightToolWindow createContent(@NotNull DesignerEditorPanelFacade designer) { + DesignerToolWindow toolWindowContent = new DesignerToolWindow(myProject); + toolWindowContent.update((GuiEditor)designer); + + return createContent(designer, + toolWindowContent, + UIDesignerBundle.message("toolwindow.ui.designer.title"), + UIDesignerIcons.ToolWindowUIDesigner, + toolWindowContent.getToolWindowPanel(), + toolWindowContent.getComponentTree(), + 320, + null); + } + + @Override + public void disposeComponent() { + if (myToolWindowPanel != null) { + myToolWindowPanel.dispose(); + } + } + + @NotNull + @Override + public String getComponentName() { + return "UIDesignerToolWindowManager"; + } +}
\ No newline at end of file diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/PropertyInspectorTable.java b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/PropertyInspectorTable.java index 059ba0407107..e4b7fccedbff 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/PropertyInspectorTable.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/PropertyInspectorTable.java @@ -281,7 +281,8 @@ public final class PropertyInspectorTable extends Table implements DataProvider{ return myEditor; } else if (PlatformDataKeys.FILE_EDITOR.is(dataId)) { - return UIDesignerToolWindowManager.getInstance(myProject).getActiveFormFileEditor(); + GuiEditor designer = DesignerToolWindowManager.getInstance(myProject).getActiveFormEditor(); + return designer == null ? null : designer.getEditor(); } else if (PlatformDataKeys.HELP_ID.is(dataId)) { return ourHelpID; diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/UIDesignerToolWindowManager.java b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/UIDesignerToolWindowManager.java deleted file mode 100644 index a30b4c65db07..000000000000 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/UIDesignerToolWindowManager.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright 2000-2009 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.propertyInspector; - -import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.ProjectComponent; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.fileEditor.FileEditorManager; -import com.intellij.openapi.fileEditor.FileEditorManagerEvent; -import com.intellij.openapi.fileEditor.FileEditorManagerListener; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.startup.StartupManager; -import com.intellij.openapi.ui.Splitter; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.wm.ToolWindow; -import com.intellij.openapi.wm.ToolWindowAnchor; -import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.ui.IdeBorderFactory; -import com.intellij.ui.ScrollPaneFactory; -import com.intellij.ui.SideBorder; -import com.intellij.uiDesigner.UIDesignerBundle; -import com.intellij.uiDesigner.componentTree.ComponentTree; -import com.intellij.uiDesigner.componentTree.ComponentTreeBuilder; -import com.intellij.uiDesigner.designSurface.GuiEditor; -import com.intellij.uiDesigner.editor.UIFormEditor; -import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.ui.update.MergingUpdateQueue; -import com.intellij.util.ui.update.Update; -import icons.UIDesignerIcons; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.DefaultTreeModel; -import java.awt.*; -import java.util.List; - -/** - * @author yole - */ -public class UIDesignerToolWindowManager implements ProjectComponent { - private final Project myProject; - private MyToolWindowPanel myToolWindowPanel; - private ComponentTree myComponentTree; - private ComponentTreeBuilder myComponentTreeBuilder; - private PropertyInspector myPropertyInspector; - private final FileEditorManager myFileEditorManager; - private ToolWindow myToolWindow; - private boolean myToolWindowReady = false; - private boolean myToolWindowDisposed = false; - private final List<TreeSelectionListener> myPendingListeners = ContainerUtil.createLockFreeCopyOnWriteList(); - - public UIDesignerToolWindowManager(final Project project, final FileEditorManager fileEditorManager) { - myProject = project; - myFileEditorManager = fileEditorManager; - MyFileEditorManagerListener listener = new MyFileEditorManagerListener(); - myFileEditorManager.addFileEditorManagerListener(listener,project); - } - - public void projectOpened() { - StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() { - public void run() { - myToolWindowReady = true; - } - }); - } - - private void checkInitToolWindow() { - if (myToolWindowReady && !myToolWindowDisposed && myToolWindow == null) { - initToolWindow(); - } - } - - private void initToolWindow() { - myToolWindowPanel = new MyToolWindowPanel(); - myComponentTree = new ComponentTree(myProject); - for (TreeSelectionListener listener : myPendingListeners) { - myComponentTree.addTreeSelectionListener(listener); - } - myPendingListeners.clear(); - final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myComponentTree); - scrollPane.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM)); - scrollPane.setPreferredSize(new Dimension(250, -1)); - myComponentTree.initQuickFixManager(scrollPane.getViewport()); - myPropertyInspector= new PropertyInspector(myProject, myComponentTree); - myToolWindowPanel.setFirstComponent(scrollPane); - myToolWindowPanel.setSecondComponent(myPropertyInspector); - myToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(UIDesignerBundle.message("toolwindow.ui.designer"), - myToolWindowPanel, - ToolWindowAnchor.LEFT, myProject, true); - myToolWindow.setIcon(UIDesignerIcons.ToolWindowUIDesigner); - myToolWindow.setAvailable(false, null); - } - - public void projectClosed() { - if (myToolWindowPanel != null) { - if (myComponentTreeBuilder != null) { - Disposer.dispose(myComponentTreeBuilder); - } - myToolWindowPanel = null; - myToolWindow = null; - myToolWindowDisposed = true; - } - } - - @NotNull @NonNls - public String getComponentName() { - return "UIDesignerToolWindowManager"; - } - - public void initComponent() { - } - - public void disposeComponent() { - } - - private final MergingUpdateQueue myQueue = new MergingUpdateQueue("property.inspector", 200, true, null); - - private void processFileEditorChange(final UIFormEditor newEditor) { - myQueue.cancelAllUpdates(); - myQueue.queue(new Update("update") { - public void run() { - if (!myToolWindowReady || myToolWindowDisposed) return; - GuiEditor activeFormEditor = newEditor != null ? newEditor.getEditor() : null; - if (myToolWindow == null) { - if (activeFormEditor == null) return; - initToolWindow(); - } - if (myComponentTreeBuilder != null) { - Disposer.dispose(myComponentTreeBuilder); - myComponentTreeBuilder = null; - } - myComponentTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); - myComponentTree.setEditor(activeFormEditor); - myComponentTree.setFormEditor(newEditor); - myPropertyInspector.setEditor(activeFormEditor); - if (activeFormEditor == null) { - myToolWindow.setAvailable(false, null); - } - else { - myComponentTreeBuilder = new ComponentTreeBuilder(myComponentTree, activeFormEditor); - myToolWindow.setAvailable(true, null); - myToolWindow.show(null); - } - } - }); - } - - @Nullable - public UIFormEditor getActiveFormFileEditor() { - FileEditor[] fileEditors = myFileEditorManager.getSelectedEditors(); - for (FileEditor fileEditor : fileEditors) { - if (fileEditor instanceof UIFormEditor) { - return (UIFormEditor)fileEditor; - } - } - return null; - } - - @Nullable - public GuiEditor getActiveFormEditor() { - UIFormEditor formEditor = getActiveFormFileEditor(); - return formEditor == null ? null : formEditor.getEditor(); - } - - public static UIDesignerToolWindowManager getInstance(Project project) { - return project.getComponent(UIDesignerToolWindowManager.class); - } - - public ComponentTree getComponentTree() { - checkInitToolWindow(); - return myComponentTree; - } - - public ComponentTreeBuilder getComponentTreeBuilder() { - return myComponentTreeBuilder; - } - - public PropertyInspector getPropertyInspector() { - return myPropertyInspector; - } - - public void refreshErrors() { - if (myComponentTree != null) { - myComponentTree.refreshIntentionHint(); - myComponentTree.repaint(myComponentTree.getVisibleRect()); - } - - // PropertyInspector - if (myPropertyInspector != null) { - myPropertyInspector.refreshIntentionHint(); - myPropertyInspector.repaint(myPropertyInspector.getVisibleRect()); - } - } - - public void updateComponentTree() { - final ComponentTreeBuilder builder = myComponentTreeBuilder; - if (builder != null) { - builder.queueUpdate(); - } - } - - public void addComponentSelectionListener(TreeSelectionListener treeSelectionListener) { - if (myComponentTree != null) { - myComponentTree.addTreeSelectionListener(treeSelectionListener); - } - else { - myPendingListeners.add(treeSelectionListener); - } - } - - private class MyFileEditorManagerListener implements FileEditorManagerListener { - public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { - processFileEditorChange(getActiveFormFileEditor()); - } - - public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) { - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - processFileEditorChange(getActiveFormFileEditor()); - } - }); - } - - public void selectionChanged(@NotNull FileEditorManagerEvent event) { - UIFormEditor newEditor = event.getNewEditor() instanceof UIFormEditor ? (UIFormEditor)event.getNewEditor() : null; - processFileEditorChange(newEditor); - } - } - - private class MyToolWindowPanel extends Splitter implements DataProvider { - MyToolWindowPanel() { - super(true, 0.33f); - } - - @Nullable - public Object getData(@NonNls String dataId) { - if (GuiEditor.DATA_KEY.is(dataId)) { - return getActiveFormEditor(); - } - return null; - } - } -} diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/editors/BindingEditor.java b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/editors/BindingEditor.java index 03c65b6640b1..c7547c7ff710 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/editors/BindingEditor.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/editors/BindingEditor.java @@ -25,8 +25,8 @@ import com.intellij.uiDesigner.FormEditingUtil; import com.intellij.uiDesigner.core.Spacer; import com.intellij.uiDesigner.inspections.FormInspectionUtil; import com.intellij.uiDesigner.lw.IRootContainer; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.propertyInspector.InplaceContext; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; import com.intellij.uiDesigner.propertyInspector.properties.BindingProperty; import com.intellij.uiDesigner.radComponents.RadComponent; import com.intellij.uiDesigner.radComponents.RadErrorComponent; @@ -67,7 +67,8 @@ public final class BindingEditor extends ComboBoxPropertyEditor<String> { SwingUtilities.invokeLater( new Runnable(){ public void run(){ - UIDesignerToolWindowManager.getInstance(project).getPropertyInspector().requestFocus(); + DesignerToolWindowManager.getInstance(DesignerToolWindowManager.getInstance(project).getActiveFormEditor()) + .getPropertyInspector().requestFocus(); } } ); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/editors/string/StringEditor.java b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/editors/string/StringEditor.java index 99a6bbc82fcf..2f22910f08af 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/editors/string/StringEditor.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/editors/string/StringEditor.java @@ -26,9 +26,9 @@ import com.intellij.ui.DocumentAdapter; import com.intellij.uiDesigner.UIDesignerBundle; import com.intellij.uiDesigner.designSurface.GuiEditor; import com.intellij.uiDesigner.lw.StringDescriptor; -import com.intellij.uiDesigner.propertyInspector.PropertyEditor; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.propertyInspector.InplaceContext; +import com.intellij.uiDesigner.propertyInspector.PropertyEditor; import com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty; import com.intellij.uiDesigner.radComponents.RadComponent; import com.intellij.util.ui.UIUtil; @@ -170,7 +170,7 @@ public final class StringEditor extends PropertyEditor<StringDescriptor> { public void actionPerformed(final ActionEvent e) { // 1. Show editor dialog - final GuiEditor guiEditor = UIDesignerToolWindowManager.getInstance(myProject).getActiveFormEditor(); + final GuiEditor guiEditor = DesignerToolWindowManager.getInstance(myProject).getActiveFormEditor(); LOG.assertTrue(guiEditor != null); final StringEditorDialog dialog = new StringEditorDialog( diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/properties/BindingProperty.java b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/properties/BindingProperty.java index 58306f72167a..70d7d3017a95 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/properties/BindingProperty.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/propertyInspector/properties/BindingProperty.java @@ -39,10 +39,10 @@ import com.intellij.uiDesigner.compiler.AsmCodeGenerator; import com.intellij.uiDesigner.designSurface.GuiEditor; import com.intellij.uiDesigner.designSurface.InsertComponentProcessor; import com.intellij.uiDesigner.inspections.FormInspectionUtil; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.propertyInspector.Property; import com.intellij.uiDesigner.propertyInspector.PropertyEditor; import com.intellij.uiDesigner.propertyInspector.PropertyRenderer; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; import com.intellij.uiDesigner.propertyInspector.editors.BindingEditor; import com.intellij.uiDesigner.propertyInspector.renderers.LabelPropertyRenderer; import com.intellij.uiDesigner.quickFixes.CreateFieldFix; @@ -177,7 +177,7 @@ public final class BindingProperty extends Property<RadComponent, String> { } // Commit document before refactoring starts - GuiEditor editor = UIDesignerToolWindowManager.getInstance(project).getActiveFormEditor(); + GuiEditor editor = DesignerToolWindowManager.getInstance(project).getActiveFormEditor(); if (editor != null) { editor.refreshAndSave(false); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/quickFixes/ShowHintAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/quickFixes/ShowHintAction.java index f08294c5cbff..beb87f197151 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/quickFixes/ShowHintAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/quickFixes/ShowHintAction.java @@ -17,8 +17,8 @@ package com.intellij.uiDesigner.quickFixes; import com.intellij.openapi.actionSystem.*; import com.intellij.uiDesigner.designSurface.GuiEditor; +import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.propertyInspector.PropertyInspector; -import com.intellij.uiDesigner.propertyInspector.UIDesignerToolWindowManager; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -46,8 +46,7 @@ final class ShowHintAction extends AnAction { myManager.showIntentionHint(); // 2. Commit possible non committed value and show popup - final UIDesignerToolWindowManager manager = UIDesignerToolWindowManager.getInstance(editor.getProject()); - final PropertyInspector propertyInspector = manager.getPropertyInspector(); + final PropertyInspector propertyInspector = DesignerToolWindowManager.getInstance(myManager.getEditor()).getPropertyInspector(); if(propertyInspector != null && propertyInspector.isEditing()) { propertyInspector.stopEditing(); } diff --git a/plugins/ui-designer/src/messages/UIDesignerBundle.properties b/plugins/ui-designer/src/messages/UIDesignerBundle.properties index 9fabc533616f..d544e3993776 100644 --- a/plugins/ui-designer/src/messages/UIDesignerBundle.properties +++ b/plugins/ui-designer/src/messages/UIDesignerBundle.properties @@ -271,7 +271,8 @@ add.component.choose.icon=Choose Icon File inspection.no.scroll.pane=Scrollable component not in JScrollPane inspection.no.scroll.pane.quickfix=Surround with JScrollPane surround.with.popup.title=Surround With -toolwindow.ui.designer=UI Designer +toolwindow.ui.designer.name=UI Designer +toolwindow.ui.designer.title=Component Tree error.cannot.delete.unused.field=Cannot delete unused field: {0} command.delete.unused.field=Delete Unused Field error.for.component=Component {0}: {1} @@ -546,6 +547,8 @@ action.GuiDesigner.GenerateMain.text=Form main() action.GuiDesigner.GenerateMain.description=Generate a main() method to show the UI form action.GuiDesigner.ReloadCustomComponents.text=Reload Custom Components action.GuiDesigner.ReloadCustomComponents.description=Reload modified custom component classes and recreate forms +action.GuiDesigner.FormSource.text=Form Source +action.GuiDesigner.FormSource.description=Show form XML content action.NewDialog.text=Dialog action.NewForm.text=GUI Form default.field.accessibility=Default accessibility &for UI-bound fields\: |