diff --git a/platform/testGuiFramework/res/META-INF/plugin.xml b/platform/testGuiFramework/res/META-INF/plugin.xml
index de2722a516d7..8a266cf66f2b 100644
--- a/platform/testGuiFramework/res/META-INF/plugin.xml
+++ b/platform/testGuiFramework/res/META-INF/plugin.xml
@@ -20,8 +20,6 @@
description="Perform Script Action" text="Perform Script Action"/>
-
diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Contexts.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Contexts.kt
deleted file mode 100644
index 275282947965..000000000000
--- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Contexts.kt
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright 2000-2017 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.testGuiFramework.recorder
-
-import com.intellij.testGuiFramework.recorder.ui.GuiScriptEditorFrame
-import java.awt.Component
-import java.util.*
-import javax.swing.JComponent
-import javax.swing.JDialog
-import javax.swing.JFrame
-
-/**
- * @author Sergey Karashevich
- */
-class Contexts() {
-
- enum class Type {DIALOG, WELCOME_FRAME, PROJECT_WIZARD, IDE_FRAME }
- enum class SubType {EDITOR, TOOL_WINDOW }
-
- private var projectWizardFound = false
- private var welcomeFrameFound = false
- private var ideFrameFound = false
- private var myToolWindowId: String? = null
-
- private val indentShift = 2
- private var indentLevel: Int = 0
- private val contextArray = ArrayList()
-
- fun check(cmp: Component) {
-
- val parent = (cmp as JComponent).rootPane.parent
- if (contextArray.isEmpty()) {
- checkGlobalContext(parent)
- checkDialogContext(parent)
- contextArray.add(parent.hashCode())
- indentLevel++
- }
- //check that we increase component level or decrease component level
- else {
- //hashcode equals -> no need to change components
- if (parent.hashCode() == contextArray.last())
- //do nothing
- else {
- //current context component and the previous to last in contextArray hashcodes are same
- if (contextArray.size > 1 && parent.hashCode() == contextArray[contextArray.size - 2]) {
- contextArray.removeAt(contextArray.size - 1)
- indentLevel--
- Writer.writeln(closeContext())
- assert(indentLevel >= 0)
- }
- else
- if (contextArray.size > 1 && parent.hashCode() != contextArray[contextArray.size - 2]) {
- //start a new context
- checkGlobalContext(parent)
- checkDialogContext(parent)
- contextArray.add(parent.hashCode())
- indentLevel++
- assert(indentLevel >= 0)
- }
- else
- if (contextArray.size == 1 && parent.hashCode() != contextArray.last()) {
- //start a new context
- checkGlobalContext(parent)
- checkDialogContext(parent)
- contextArray.add(parent.hashCode())
- indentLevel++
- assert(indentLevel >= 0)
- }
- }
- }
- }
-
- companion object {
- val IDE_FRAME_VAL = "ideFrame"
- }
-
- var globalContext: Type? = null
- var currentSubContextType: SubType? = null
-
- private fun checkGlobalContext(parent: Component) {
- if (parent is JFrame && parent.title == GuiScriptEditorFrame.GUI_SCRIPT_FRAME_TITLE) return //do nothing if switch to GUI Script Editor
-
- if (contextArray.isEmpty() || contextArray.first() != parent.hashCode()) {
- when (parent) {
- is com.intellij.openapi.wm.impl.welcomeScreen.FlatWelcomeFrame -> {
- globalContext = Type.WELCOME_FRAME
- indentLevel = 0
- if (contextArray.isNotEmpty()) {
- Writer.writeln(closeContext())
- contextArray.clear()
- }
- Writer.writeln(welcomeFrameStart())
- return
- }
- is JFrame -> {
- globalContext = Type.IDE_FRAME
- indentLevel = 0
- if (contextArray.isNotEmpty()) {
- Writer.writeln(closeContext())
- contextArray.clear()
- }
- Writer.writeln(ideFrameStart())
- return
- }
- }
- }
- }
-
- private fun checkDialogContext(parent: Component) {
- if (parent is JFrame && parent.title == GuiScriptEditorFrame.GUI_SCRIPT_FRAME_TITLE) return //do nothing if switch to GUI Script Editor
- when (parent) {
- is JDialog -> {
- if (parent.title == com.intellij.ide.IdeBundle.message("title.new.project")) {
- Writer.writeln(projectWizardContextStart())
- return
- }
- else {
- Writer.writeln(dialogContextStart(parent.title))
- return
- }
- }
- }
- }
-
-
- fun getIndent(): String {
- val size = indentLevel * indentShift
- val sb = StringBuilder()
- for (i in 1..size) sb.append(" ")
- return sb.toString()
- }
-
- //*********** Context Scripts ************
-
- fun closeContext() = "}"
-
- fun dialogContextStart(title: String): String {
- globalContext = Type.DIALOG
- val withDialog = Templates.withDialog(title)
- return withDialog
- }
-
- fun projectWizardContextStart(): String {
- globalContext = Type.PROJECT_WIZARD
- val withProjectWizard = Templates.withProjectWizard()
- projectWizardFound = true
-
- return withProjectWizard
- }
-
- fun welcomeFrameStart(): String {
- globalContext = Type.WELCOME_FRAME
- val withWelcomeFrame = Templates.withWelcomeFrame()
- welcomeFrameFound = true
-
- return withWelcomeFrame
- }
-
- fun ideFrameStart(): String {
- globalContext = Type.IDE_FRAME
- val withIdeFrame = Templates.withIdeFrame()
- ideFrameFound = true
-
- return withIdeFrame
- }
-
- fun editorActivate(): String {
- currentSubContextType = SubType.EDITOR
- return "EditorFixture(robot(), $IDE_FRAME_VAL).requestFocus()"
- }
-
- fun toolWindowActivate(toolWindowId: String? = null): String {
- currentSubContextType = SubType.TOOL_WINDOW
- myToolWindowId = toolWindowId
- return "ToolWindowFixture(\"$toolWindowId\", $IDE_FRAME_VAL.getProject(), robot()).activate()"
- }
-
- fun clear() {
- currentSubContextType = null
- contextArray.clear()
- indentLevel = 0
- }
-}
diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ScriptGenerator.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ScriptGenerator.kt
index 34169ee9c676..b064bf72bf6c 100644
--- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ScriptGenerator.kt
+++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ScriptGenerator.kt
@@ -45,13 +45,13 @@ object ScriptGenerator {
val actionId = event.actionManager.getId(action)
if (actionId != null) {
if (ignore(actionId)) return
- addToScript(Templates.invokeActionComment(actionId))
+ addToScript("""//invokeAction("$actionId")""")
}
val keyStroke = getKeyStrokeForEvent(keyEvent)
val keyStrokeStr = KeyStrokeAdapter.toString(keyStroke)
if (ignore(keyStrokeStr)) return
- addToScript(Templates.shortcut(keyStrokeStr))
+ addToScript("""shortcut("$keyStrokeStr")""")
}
fun clickComponent(component: Component, convertedPoint: Point, mouseEvent: MouseEvent) {
@@ -74,7 +74,7 @@ object ScriptGenerator {
addToScript("//invokeAction(\"$actionId\")")
return
}
- addToScript(Templates.invokeMainMenuAction(actionId))
+ addToScript("""invokeMainMenu("$actionId")""")
}
fun addToScript(code: String) {
@@ -104,7 +104,7 @@ private object Typer {
fun flushBuffer() {
if (strBuffer.isEmpty()) return
- Writer.writeWithIndent(Templates.typeText(strBuffer.toString()))
+ Writer.writeWithIndent("""typeText("${strBuffer}")""")
strBuffer.setLength(0)
}
}
\ No newline at end of file
diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Templates.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Templates.kt
deleted file mode 100644
index 525e877a9f9e..000000000000
--- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Templates.kt
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2000-2017 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.testGuiFramework.recorder
-
-/**
- * @author Sergey Karashevich
- */
-object Templates {
- fun withDialog(title: String) = "dialog(\"${title}\") {"
- fun withProjectWizard() = "projectWizard {"
- fun withWelcomeFrame() = "welcomeFrame {"
- fun withIdeFrame() = "ideFrame {"
-
- fun findAndClickButton(name: String) = "button(\"${name}\").click()"
- fun findAndClickActionButton(actionId: String) = "actionButton(\"${actionId}\").click()"
-
- fun clickActionLink(text: String) = "actionLink(\"$text\").click()"
- fun clickPopupItem(itemName: String) = "popupClick(\"$itemName\")"
- fun clickLinkLabel(text: String) = "linkLabel(\"$text\").click()"
-
- fun clickListItem(name: String) = "jList(\"$name\").clickItem(\"$name\")"
- fun findJTextField() = "textfield()"
- fun findJTextFieldByLabel(labelText: String) = "textfield(\"${labelText}\").click()"
- fun findJTextFieldAndDoubleClick() = "textfield().doubleClick()"
-
- fun findJTextFieldByLabelAndDoubleClick(labelText: String) = "textfield(\"${labelText}\").doubleClick()"
- fun typeText(text: String) = "typeText(\"$text\")"
- fun clickFrameworksTree(itemName: String) = "selectFramework(\"$itemName\")"
- fun selectSimpleTreeItem(path: String) = "jTree(\"$path\").selectPath(\"$path\")"
- fun clickJBCheckBox(text: String) = "checkbox(\"$text\").click()"
-
- fun clickJCheckBox(text: String) = "checkbox(\"$text\").click()"
- fun onJComboBox(text: String) = "combobox(\"$text\")"
- fun selectComboBox(itemName: String) = ".selectItem(\"$itemName\")"
-
- fun clickRadioButton(text: String) = "radioButton(\"$text\").select()"
- fun invokeActionComment(actionId: String) = "//invokeAction(\"$actionId\")"
-
- fun shortcut(keyStrokeStr: String) = "shortcut(\"$keyStrokeStr\")"
- fun invokeMainMenuAction(menuActionId: String) = "invokeMainMenu(\"$menuActionId\")"
-
- fun selectTreePath(path: String) = "jTree(\"$path\").clickPath(\"$path\")"
-// fun selectTreePath(treeClass: String, path: String) = "//GuiTestUtil.findJTreeFixtureByClassName(robot(), this.target(), \"$treeClass\").clickPath(\"$path\")"
-}
\ No newline at end of file
diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UiDropperAction.java b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UiDropperAction.java
deleted file mode 100644
index eaafa716f541..000000000000
--- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UiDropperAction.java
+++ /dev/null
@@ -1,1280 +0,0 @@
-/*
- * Copyright 2000-2017 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.testGuiFramework.recorder.actions;
-
-import com.intellij.notification.Notification;
-import com.intellij.notification.NotificationType;
-import com.intellij.notification.Notifications;
-import com.intellij.notification.NotificationsManager;
-import com.intellij.openapi.Disposable;
-import com.intellij.openapi.actionSystem.*;
-import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
-import com.intellij.openapi.project.DumbAware;
-import com.intellij.openapi.roots.ui.configuration.actions.IconWithTextAction;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.ui.StripeTable;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.wm.IdeGlassPane;
-import com.intellij.openapi.wm.impl.IdeGlassPaneImpl;
-import com.intellij.ui.*;
-import com.intellij.ui.components.JBList;
-import com.intellij.ui.components.JBScrollPane;
-import com.intellij.ui.components.JBTextField;
-import com.intellij.ui.popup.PopupFactoryImpl;
-import com.intellij.ui.speedSearch.SpeedSearchUtil;
-import com.intellij.util.ExceptionUtil;
-import com.intellij.util.Function;
-import com.intellij.util.ObjectUtils;
-import com.intellij.util.ReflectionUtil;
-import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.containers.HashMap;
-import com.intellij.util.ui.JBUI;
-import com.intellij.util.ui.PlatformColors;
-import com.intellij.util.ui.UIUtil;
-import com.intellij.util.ui.tree.TreeUtil;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import javax.accessibility.Accessible;
-import javax.accessibility.AccessibleContext;
-import javax.swing.*;
-import javax.swing.border.Border;
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
-import javax.swing.plaf.ColorUIResource;
-import javax.swing.plaf.UIResource;
-import javax.swing.table.AbstractTableModel;
-import javax.swing.table.TableCellRenderer;
-import javax.swing.table.TableColumn;
-import javax.swing.table.TableColumnModel;
-import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.DefaultTreeModel;
-import javax.swing.tree.TreeModel;
-import javax.swing.tree.TreePath;
-import java.awt.*;
-import java.awt.event.*;
-import java.awt.geom.RoundRectangle2D;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
-import static java.awt.event.MouseEvent.BUTTON1;
-import static java.awt.event.MouseEvent.MOUSE_CLICKED;
-import static java.util.Locale.ENGLISH;
-
-public class UiDropperAction extends ToggleAction implements DumbAware {
-
-
- private static AnAction clickAction;
- final private static String UI_DROPPER_PLACE = "UI Dropper Place";
- private UiDropper myUiDropper;
-
-
- public static void setClickAction(@NotNull AnAction action) {
- clickAction = action;
- }
-
- @Override
- public boolean isSelected(AnActionEvent e) {
- return myUiDropper != null;
- }
-
- @Override
- public void setSelected(AnActionEvent e, boolean toSync) {
- if (toSync) {
- if (myUiDropper == null) {
- myUiDropper = new UiDropper();
- }
-
- UiInspectorNotification[] existing =
- NotificationsManager.getNotificationsManager().getNotificationsOfType(UiInspectorNotification.class, null);
- if (existing.length == 0) {
- Notifications.Bus.notify(new UiInspectorNotification(), null);
- }
- }
- else {
- UiDropper inspector = myUiDropper;
- myUiDropper = null;
- if (inspector != null) {
- Disposer.dispose(inspector);
- }
- }
- }
-
- private static class UiInspectorNotification extends Notification {
- private UiInspectorNotification() {
- super(Notifications.SYSTEM_MESSAGES_GROUP_ID, "UI Dropper",
- "Hold ctr + alt and navigate cursor to component.\nUse mouse wheel to get info of parent component.",
- NotificationType.INFORMATION);
- }
- }
-
- private static class InspectorWindow extends JDialog {
- private InspectorTable myInspectorTable;
- private Component myComponent;
- private HighlightComponent myHighlightComponent;
- private HierarchyTree myHierarchyTree;
- private final JPanel myWrapperPanel;
-
- private InspectorWindow(@NotNull Component component) throws HeadlessException {
- super(findWindow(component));
- Window window = findWindow(component);
- setModal(window instanceof JDialog && ((JDialog)window).isModal());
- myComponent = component;
- getRootPane().setBorder(JBUI.Borders.empty(5));
-
- setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
-
- setLayout(new BorderLayout());
- setTitle(component.getClass().getName());
-
- DefaultActionGroup actions = new DefaultActionGroup();
- actions.addAction(new IconWithTextAction("Highlight") {
- @Override
- public void actionPerformed(AnActionEvent e) {
- //highlightCmp(myHighlightComponent == null);
- }
-
- @Override
- public void update(AnActionEvent e) {
- e.getPresentation().setEnabled(myComponent != null && myComponent.isVisible());
- }
- });
-
- actions.addSeparator();
-
- actions.add(new IconWithTextAction("Refresh") {
-
- @Override
- public void actionPerformed(AnActionEvent e) {
- getCurrentTable().refresh();
- }
-
- @Override
- public void update(AnActionEvent e) {
- e.getPresentation().setEnabled(myComponent != null && myComponent.isVisible());
- }
- });
-
- ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.CONTEXT_TOOLBAR, actions, true);
- add(toolbar.getComponent(), BorderLayout.NORTH);
-
- myWrapperPanel = new JPanel(new BorderLayout());
-
- myInspectorTable = new InspectorTable(component);
- myHierarchyTree = new HierarchyTree(component) {
- @Override
- public void onComponentChanged(Component c) {
- boolean wasHighlighted = myHighlightComponent != null;
- //highlightCmp(false);
- switchInfo(c);
- //highlightCmp(wasHighlighted);
- }
- };
-
- myWrapperPanel.add(myInspectorTable, BorderLayout.CENTER);
-
- JSplitPane splitPane = new JSplitPane();
- splitPane.setDividerLocation(0.5);
- splitPane.setRightComponent(myWrapperPanel);
-
- JScrollPane pane = new JBScrollPane(myHierarchyTree);
- splitPane.setLeftComponent(pane);
- add(splitPane, BorderLayout.CENTER);
-
- myHierarchyTree.expandPath();
-
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- close();
- }
- });
-
- getRootPane().getActionMap().put("CLOSE", new AbstractAction() {
- public void actionPerformed(ActionEvent e) {
- close();
- }
- });
- //highlightCmp(true);
- getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "CLOSE");
- }
-
- private static Window findWindow(Component component) {
- DialogWrapper dialogWrapper = DialogWrapper.findInstance(component);
- if (dialogWrapper != null) {
- return dialogWrapper.getPeer().getWindow();
- }
- return null;
- }
-
- private InspectorTable getCurrentTable() {
- return myInspectorTable;
- }
-
- private void switchInfo(@Nullable Component c) {
- if (c == null) return;
- myComponent = c;
- setTitle(myComponent.getClass().getName());
- myWrapperPanel.removeAll();
- myInspectorTable = new InspectorTable(c);
- myWrapperPanel.add(myInspectorTable, BorderLayout.CENTER);
- myWrapperPanel.revalidate();
- myWrapperPanel.repaint();
- }
-
- public void close() {
- //highlightCmp(false);
- myComponent = null;
- setVisible(false);
- dispose();
- }
- }
-
- private static class ComponentTreeCellRenderer extends ColoredTreeCellRenderer {
- private final Component myInitialSelection;
-
- ComponentTreeCellRenderer(Component initialSelection) {
- myInitialSelection = initialSelection;
- setFont(JBUI.Fonts.label(11));
- setBorder(JBUI.Borders.empty(0, 3));
- }
-
- @Override
- public void customizeCellRenderer(@NotNull JTree tree,
- Object value,
- boolean selected,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus) {
- Color foreground = selected ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeForeground();
- Color background = selected ? UIUtil.getTreeSelectionBackground() : null;
- if (value instanceof HierarchyTree.ComponentNode) {
- HierarchyTree.ComponentNode componentNode = (HierarchyTree.ComponentNode)value;
- Component component = componentNode.getComponent();
- Class> clazz0 = component.getClass();
- Class> clazz = clazz0.isAnonymousClass() ? clazz0.getSuperclass() : clazz0;
- String name = component.getName();
-
- if (!selected) {
- if (!component.isVisible()) {
- foreground = JBColor.GRAY;
- }
- else if (component.getWidth() == 0 || component.getHeight() == 0) {
- foreground = new JBColor(new Color(128, 10, 0), JBColor.BLUE);
- }
- else if (component.getPreferredSize() != null &&
- (component.getSize().width < component.getPreferredSize().width
- || component.getSize().height < component.getPreferredSize().height)) {
- foreground = PlatformColors.BLUE;
- }
-
- if (myInitialSelection == componentNode.getComponent()) {
- background = new Color(31, 128, 8, 58);
- }
- }
- append(clazz.getSimpleName());
- if (StringUtil.isNotEmpty(name)) {
- append(" \"" + name + "\"");
- }
- append(": " + RectangleRenderer.toString(component.getBounds()), SimpleTextAttributes.GRAYED_ATTRIBUTES);
- if (component.isOpaque()) {
- append(", opaque", SimpleTextAttributes.GRAYED_ATTRIBUTES);
- }
- if (component.isDoubleBuffered()) {
- append(", double-buffered", SimpleTextAttributes.GRAYED_ATTRIBUTES);
- }
- componentNode.setText(toString());
- }
-
- setForeground(foreground);
- setBackground(background);
-
- SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, false, selected);
- }
- }
-
- private static TreeModel buildModel(Component c) {
- Component parent = c.getParent();
- while (parent != null) {
- c = parent;
- parent = c.getParent();//Find root window
- }
- return new DefaultTreeModel(new HierarchyTree.ComponentNode(c));
- }
-
-
- private abstract static class HierarchyTree extends JTree implements TreeSelectionListener {
- final Component myComponent;
-
- private HierarchyTree(Component c) {
- myComponent = c;
- setModel(buildModel(c));
- setCellRenderer(new ComponentTreeCellRenderer(c));
- getSelectionModel().addTreeSelectionListener(this);
- new TreeSpeedSearch(this);
- }
-
- public void expandPath() {
- TreeUtil.expandAll(this);
- int count = getRowCount();
- ComponentNode node = new ComponentNode(myComponent);
-
- for (int i = 0; i < count; i++) {
- TreePath row = getPathForRow(i);
- if (row.getLastPathComponent().equals(node)) {
- setSelectionPath(row);
- scrollPathToVisible(getSelectionPath());
- break;
- }
- }
- }
-
- @Override
- public void valueChanged(TreeSelectionEvent e) {
- TreePath path = e.getNewLeadSelectionPath();
- if (path == null) {
- onComponentChanged(null);
- return;
- }
- Object component = path.getLastPathComponent();
- if (component instanceof ComponentNode) {
- Component c = ((ComponentNode)component).getComponent();
- onComponentChanged(c);
- }
- }
-
- public abstract void onComponentChanged(Component c);
-
- private static class ComponentNode extends DefaultMutableTreeNode {
- private final Component myComponent;
- String myText;
-
- private ComponentNode(@NotNull Component component) {
- super(component);
- myComponent = component;
- children = prepareChildren(myComponent);
- }
-
- Component getComponent() {
- return myComponent;
- }
-
- @Override
- public String toString() {
- return myText != null ? myText : myComponent.getClass().getName();
- }
-
- public void setText(String value) {
- myText = value;
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj instanceof ComponentNode && ((ComponentNode)obj).getComponent() == getComponent();
- }
-
- @SuppressWarnings("UseOfObsoleteCollectionType")
- private static Vector prepareChildren(Component parent) {
- Vector result = new Vector();
- if (parent instanceof Container) {
- for (Component component : ((Container)parent).getComponents()) {
- result.add(new ComponentNode(component));
- }
- }
- if (parent instanceof Window) {
- Window[] children = ((Window)parent).getOwnedWindows();
- for (Window child : children) {
- if (child instanceof InspectorWindow) continue;
- result.add(new ComponentNode(child));
- }
- }
-
- return result;
- }
- }
- }
-
- private static class MyLabel extends JLabel {
- private final JComponent myGlasspane;
- private String myText;
-
- private MyLabel(@NotNull String text, @NotNull JComponent glasspane) {
- super(text);
- myText = text;
- myGlasspane = glasspane;
- setForeground(Gray._230);
- setFont(UIUtil.getLabelFont());
- }
-
- public MyLabel(String text, JComponent glassPane, int width) {
- super(text);
- myText = text;
- myGlasspane = glassPane;
- setForeground(Gray._230);
- setFont(new Font(UIUtil.getLabelFont().getName(), Font.PLAIN, 6));
- }
-
- public void dispose() {
- if (myGlasspane != null) myGlasspane.remove(this);
- }
-
- @Override
- protected void paintComponent(Graphics g) {
- //paint background
- int cornerRadius = 0;
- Rectangle bounds = getBounds();
- Graphics2D g2 = (Graphics2D)g;
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setColor(Gray._90);
- g2.fill(new RoundRectangle2D.Float(0, 0, bounds.width, bounds.height, cornerRadius, cornerRadius));
- super.paintComponent(g);
- }
- }
-
- private static class HighlightComponent extends JComponent {
- Color myColor;
- JComponent myGlassPane;
- Component myOriginalComponent;
-
- private HighlightComponent(@NotNull final Color c, @NotNull final JComponent glassPane, @NotNull final Component originalComponent) {
- myColor = c;
- myGlassPane = glassPane;
- myOriginalComponent = originalComponent;
- }
-
- @Override
- protected void paintComponent(Graphics g) {
- Graphics2D g2d = (Graphics2D)g;
-
- Color oldColor = g2d.getColor();
- g2d.setColor(myColor);
- Composite old = g2d.getComposite();
- g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
-
- Rectangle r = getBounds();
- g2d.fillRect(0, 0, r.width, r.height);
- g2d.setColor(myColor.darker());
- g2d.drawRect(0, 0, r.width - 1, r.height - 1);
-
- g2d.setComposite(old);
- g2d.setColor(oldColor);
- }
-
- public void dispose() {
- if (myGlassPane != null) myGlassPane.remove(this);
- }
- }
-
- private static class InspectorTable extends JPanel {
- InspectorTableModel myModel;
- DimensionsComponent myDimensionComponent;
-
- private InspectorTable(@NotNull final Component component) {
- setLayout(new BorderLayout());
-
- myModel = new InspectorTableModel(component);
- StripeTable table = new StripeTable(myModel);
- new TableSpeedSearch(table);
-
- TableColumnModel columnModel = table.getColumnModel();
- TableColumn propertyColumn = columnModel.getColumn(0);
- propertyColumn.setMinWidth(JBUI.scale(200));
- propertyColumn.setMaxWidth(JBUI.scale(200));
- propertyColumn.setResizable(false);
-
- TableColumn valueColumn = columnModel.getColumn(1);
- valueColumn.setMinWidth(JBUI.scale(200));
- valueColumn.setResizable(false);
- valueColumn.setCellRenderer(new ValueCellRenderer());
- valueColumn.setCellEditor(new DefaultCellEditor(new JBTextField()) {
- @Override
- public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
- Component comp = table.getCellRenderer(row, column).getTableCellRendererComponent(table, value, false, false, row, column);
- if (comp instanceof JLabel) {
- value = ((JLabel)comp).getText();
- }
- Component result = super.getTableCellEditorComponent(table, value, isSelected, row, column);
- ((JComponent)result).setBorder(BorderFactory.createLineBorder(JBColor.GRAY, 1));
- return result;
- }
-
- @Override
- public Object getCellEditorValue() {
- return super.getCellEditorValue();
- }
- });
-
- table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
-
- add(new JBScrollPane(table), BorderLayout.CENTER);
- myDimensionComponent = new DimensionsComponent(component);
- add(myDimensionComponent, BorderLayout.SOUTH);
- }
-
- public void refresh() {
- myModel.refresh();
- myDimensionComponent.update();
- myDimensionComponent.repaint();
- }
- }
-
- private static class DimensionsComponent extends JComponent {
- Component myComponent;
- int myWidth;
- int myHeight;
- Border myBorder;
- Insets myInsets;
-
- private DimensionsComponent(@NotNull final Component component) {
- myComponent = component;
- setOpaque(true);
- setBackground(JBColor.WHITE);
- setBorder(JBUI.Borders.empty(5, 0));
-
- setFont(JBUI.Fonts.label(9));
-
- update();
- }
-
- public void update() {
- myWidth = myComponent.getWidth();
- myHeight = myComponent.getHeight();
- if (myComponent instanceof JComponent) {
- myBorder = ((JComponent)myComponent).getBorder();
- myInsets = ((JComponent)myComponent).getInsets();
- }
- }
-
- @Override
- protected void paintComponent(final Graphics g) {
- Graphics2D g2d = (Graphics2D)g;
- Rectangle bounds = getBounds();
-
- g2d.setColor(getBackground());
- Insets insets = getInsets();
- g2d.fillRect(insets.left, insets.top, bounds.width - insets.left - insets.right, bounds.height - insets.top - insets.bottom);
- g2d.setColor(getForeground());
-
- final String sizeString = String.valueOf(myWidth) + " x " + myHeight;
-
- FontMetrics fm = g2d.getFontMetrics();
- int sizeWidth = fm.stringWidth(sizeString);
-
- int fontHeight = fm.getHeight();
-
- g2d.drawString(sizeString, bounds.width / 2 - sizeWidth / 2, bounds.height / 2 + fontHeight / 2);
-
- g2d.setColor(JBColor.GRAY);
-
- int innerX = bounds.width / 2 - sizeWidth / 2 - 20;
- int innerY = bounds.height / 2 - fontHeight / 2 - 5;
- int innerWidth = sizeWidth + 40;
- int innerHeight = fontHeight + 10;
-
- g2d.drawRect(innerX, innerY, innerWidth, innerHeight);
-
- Insets borderInsets = null;
- if (myBorder != null) borderInsets = myBorder.getBorderInsets(myComponent);
- UIUtil.drawDottedRectangle(g2d, innerX - 15, innerY - 15, innerX - 15 + innerWidth + 30, innerY - 15 + innerHeight + 30);
- drawInsets(g2d, fm, "border", borderInsets, 15, fontHeight, innerX, innerY, innerWidth, innerHeight);
-
- g2d.drawRect(innerX - 30, innerY - 30, innerWidth + 60, innerHeight + 60);
- drawInsets(g2d, fm, "insets", myInsets, 30, fontHeight, innerX, innerY, innerWidth, innerHeight);
- }
-
- private static void drawInsets(Graphics2D g2d,
- FontMetrics fm,
- String name,
- Insets insets,
- int offset,
- int fontHeight,
- int innerX,
- int innerY,
- int innerWidth,
- int innerHeight) {
- g2d.setColor(JBColor.BLACK);
- g2d.drawString(name, innerX - offset + 5, innerY - offset + fontHeight);
-
- g2d.setColor(JBColor.GRAY);
- int dashWidth = fm.stringWidth("-");
-
- if (insets != null) {
- final String top = Integer.toString(insets.top);
- final String bottom = Integer.toString(insets.bottom);
- final String left = Integer.toString(insets.left);
- final String right = Integer.toString(insets.right);
-
- g2d.drawString(top, innerX - offset + ((innerWidth + offset * 2) / 2 - fm.stringWidth(top) / 2), innerY - offset + fontHeight);
- g2d.drawString(bottom, innerX - offset + ((innerWidth + offset * 2) / 2 - fm.stringWidth(bottom) / 2),
- innerY - offset + innerHeight + offset * 2 - 8 + fontHeight / 2);
- g2d.drawString(left, innerX - offset + 7 - fm.stringWidth(left) / 2,
- innerY - offset + (innerHeight + offset * 2) / 2 + fontHeight / 2);
- g2d.drawString(right, innerX + innerWidth + offset - 7 - fm.stringWidth(right) / 2,
- innerY - offset + (innerHeight + offset * 2) / 2 + fontHeight / 2);
- }
- else {
- g2d.drawString("-", innerX - offset + ((innerWidth + offset * 2) / 2 - dashWidth / 2), innerY - offset + fontHeight);
- g2d.drawString("-", innerX - offset + ((innerWidth + offset * 2) / 2 - dashWidth / 2),
- innerY - offset + innerHeight + offset * 2 - 8 + fontHeight / 2);
- g2d.drawString("-", innerX - offset + 7 - dashWidth / 2, innerY - offset + (innerHeight + offset * 2) / 2 + fontHeight / 2);
- g2d.drawString("-", innerX + innerWidth + offset - 7 - dashWidth / 2,
- innerY - offset + (innerHeight + offset * 2) / 2 + fontHeight / 2);
- }
- }
-
- @Override
- public Dimension getMinimumSize() {
- return JBUI.size(120);
- }
-
- @Override
- public Dimension getPreferredSize() {
- return JBUI.size(150);
- }
- }
-
- private static class ValueCellRenderer implements TableCellRenderer {
- private static final Map RENDERERS = ContainerUtil.newHashMap();
-
- static {
- RENDERERS.put(Point.class, new PointRenderer());
- RENDERERS.put(Dimension.class, new DimensionRenderer());
- RENDERERS.put(Insets.class, new InsetsRenderer());
- RENDERERS.put(Rectangle.class, new RectangleRenderer());
- RENDERERS.put(Color.class, new ColorRenderer());
- RENDERERS.put(Font.class, new FontRenderer());
- RENDERERS.put(Boolean.class, new BooleanRenderer());
- RENDERERS.put(Icon.class, new IconRenderer());
- }
-
- private static final Renderer