diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperOrMembersHandler.java b/java/java-impl-refactorings/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperOrMembersHandler.java index d4db4dae08d0..baa2e8ad2681 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperOrMembersHandler.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/move/moveInner/MoveInnerToUpperOrMembersHandler.java @@ -134,7 +134,7 @@ public class MoveInnerToUpperOrMembersHandler extends MoveHandlerDelegate { gr.add(myRbMoveInner); gr.add(myRbMoveMembers); - new RadioUpDownListener(myRbMoveInner, myRbMoveMembers); + RadioUpDownListener.installOn(myRbMoveInner, myRbMoveMembers); Box box = Box.createVerticalBox(); box.add(Box.createVerticalStrut(5)); diff --git a/platform/lang-impl/src/com/intellij/analysis/BaseAnalysisActionDialog.java b/platform/lang-impl/src/com/intellij/analysis/BaseAnalysisActionDialog.java index a6d76874cc3e..f0435416e5d3 100644 --- a/platform/lang-impl/src/com/intellij/analysis/BaseAnalysisActionDialog.java +++ b/platform/lang-impl/src/com/intellij/analysis/BaseAnalysisActionDialog.java @@ -110,7 +110,7 @@ public class BaseAnalysisActionDialog extends DialogWrapper { getAdditionalActionSettings(myProject)); preselectButton(); - new RadioUpDownListener(radioButtons.toArray(new JRadioButton[0])); + RadioUpDownListener.installOn(radioButtons.toArray(new JRadioButton[0])); panel.setPreferredSize(panel.getMinimumSize()); return panel; diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/ui/Util.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/ui/Util.java index 300263f05c70..8a516badbec6 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/ui/Util.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/ui/Util.java @@ -30,6 +30,7 @@ public final class Util{ @Override public boolean canClose(String inputString) { try { + //noinspection ResultOfObjectAllocationIgnored new URL(inputString); return true; } diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java index f5ab17148864..e7f2f5133efe 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java @@ -38,7 +38,7 @@ public class DefaultValueChooser extends DialogWrapper{ public DefaultValueChooser(Project project, String name, String defaultValue) { super(project); - new RadioUpDownListener(myLeaveBlankRadioButton, myFeelLuckyRadioButton, myUseValueRadioButton); + RadioUpDownListener.installOn(myLeaveBlankRadioButton, myFeelLuckyRadioButton, myUseValueRadioButton); final ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsDialog.java b/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsDialog.java index 10dc4b21fe17..424b0d76eb2f 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsDialog.java +++ b/platform/lang-impl/src/com/intellij/refactoring/inline/InlineOptionsDialog.java @@ -87,7 +87,7 @@ public abstract class InlineOptionsDialog extends RefactoringDialog implements I for (JRadioButton button : buttons) { bg.add(button); } - new RadioUpDownListener(buttons); + RadioUpDownListener.installOn(buttons); myRbInlineThisOnly.setEnabled(myInvokedOnReference); myRbInlineAll.setEnabled(writable); diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java index c5e8efb607d7..e6ecf033c1ee 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameHandlerRegistry.java @@ -172,7 +172,7 @@ public class RenameHandlerRegistry { bg.add(rb); radioPanel.add(rb); } - new RadioUpDownListener(myRButtons); + RadioUpDownListener.installOn(myRButtons); return radioPanel; } diff --git a/platform/lang-impl/src/com/intellij/refactoring/util/RadioUpDownListener.java b/platform/lang-impl/src/com/intellij/refactoring/util/RadioUpDownListener.java index 6b687ab32f92..0543dfe0d4e8 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/util/RadioUpDownListener.java +++ b/platform/lang-impl/src/com/intellij/refactoring/util/RadioUpDownListener.java @@ -11,9 +11,18 @@ import java.awt.event.KeyEvent; public class RadioUpDownListener extends KeyAdapter { private final JRadioButton[] myRadioButtons; - public RadioUpDownListener(final JRadioButton... radioButtons) { + private RadioUpDownListener(final JRadioButton... radioButtons) { myRadioButtons = radioButtons; - for (JRadioButton radioButton : radioButtons) { + } + + public static RadioUpDownListener installOn(final JRadioButton... radioButtons) { + RadioUpDownListener listener = new RadioUpDownListener(radioButtons); + listener.setupListeners(); + return listener; + } + + private void setupListeners() { + for (JRadioButton radioButton : myRadioButtons) { radioButton.addKeyListener(this); } } diff --git a/platform/platform-api/src/com/intellij/ide/dnd/DnDSupport.java b/platform/platform-api/src/com/intellij/ide/dnd/DnDSupport.java index 530ae9f4e81c..3c7ed5a388fc 100644 --- a/platform/platform-api/src/com/intellij/ide/dnd/DnDSupport.java +++ b/platform/platform-api/src/com/intellij/ide/dnd/DnDSupport.java @@ -250,6 +250,7 @@ public final class DnDSupport implements DnDTarget, DnDSource, DnDDropHandler.Wi @Override public void install() { + //noinspection ResultOfObjectAllocationIgnored new DnDSupport(myComponent, beanProvider.get(), imageProvider.get(), diff --git a/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java b/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java index b2c4b6b437f3..f495ffea8b2c 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java @@ -94,7 +94,7 @@ public class ComponentWithBrowseButton extends JPanel i } else if (Registry.is("ide.browse.button.always.focusable", false)) { myBrowseButton.setFocusable(true); } - new LazyDisposable(this); + LazyDisposable.installOn(this); Insets insets = myComponent.getInsets(); Gaps visualPaddings = new Gaps(insets.top, insets.left, insets.bottom, inlineBrowseButton ? insets.right : myBrowseButton.getInsets().right); @@ -329,7 +329,11 @@ public class ComponentWithBrowseButton extends JPanel i private LazyDisposable(ComponentWithBrowseButton component) { reference = new WeakReference<>(component); - UiNotifyConnector.Once.installOn(component, this); + } + + private static void installOn(ComponentWithBrowseButton component) { + LazyDisposable disposable = new LazyDisposable(component); + UiNotifyConnector.Once.installOn(component, disposable); } @Override diff --git a/platform/platform-api/src/com/intellij/ui/table/JBTable.java b/platform/platform-api/src/com/intellij/ui/table/JBTable.java index 462f9886e68e..675a67d1566b 100644 --- a/platform/platform-api/src/com/intellij/ui/table/JBTable.java +++ b/platform/platform-api/src/com/intellij/ui/table/JBTable.java @@ -177,7 +177,7 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component myUiUpdating = false; - new MyCellEditorRemover(); + new MyCellEditorRemover().setupListeners(); } protected void onTableChanged(@NotNull TableModelEvent e) { @@ -798,7 +798,7 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component private final class MyCellEditorRemover implements PropertyChangeListener, Activatable { private boolean myIsActive = false; - MyCellEditorRemover() { + private void setupListeners() { addPropertyChangeListener("tableCellEditor", this); UiNotifyConnector.installOn(JBTable.this, this); } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java index df51e69287be..b219f417539e 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java @@ -389,7 +389,7 @@ public class JBTabsImpl extends JComponent } }); - new LazyUiDisposable<>(parentDisposable, this, this) { + LazyUiDisposable listener1 = new LazyUiDisposable<>(parentDisposable, this, this) { @Override protected void initialize(@NotNull Disposable parent, @NotNull JBTabsImpl child, @Nullable Project project) { if (myProject == null && project != null) { @@ -418,6 +418,7 @@ public class JBTabsImpl extends JComponent } } }; + listener1.setupListeners(); ComponentUtil.putClientProperty(this, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, (Iterable)(Iterable)() -> { return JBIterable.from(getVisibleInfos()) diff --git a/platform/platform-api/src/com/intellij/util/text/DateTimeFormatManager.java b/platform/platform-api/src/com/intellij/util/text/DateTimeFormatManager.java index a0b0af0aebf5..65fa67ec1d31 100644 --- a/platform/platform-api/src/com/intellij/util/text/DateTimeFormatManager.java +++ b/platform/platform-api/src/com/intellij/util/text/DateTimeFormatManager.java @@ -81,6 +81,7 @@ public final class DateTimeFormatManager implements PersistentStateComponent implements Activatable { myUI = new AtomicReference<>(ui); myParent = parent; myChild = child; + } - UiNotifyConnector.Once.installOn(ui, this); + public void setupListeners() { + UiNotifyConnector.Once.installOn(myUI.get(), this); } @Override diff --git a/platform/platform-impl/src/com/intellij/ide/dnd/DnDManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/dnd/DnDManagerImpl.java index 11bc71bc7592..e5b4f69b8d89 100644 --- a/platform/platform-impl/src/com/intellij/ide/dnd/DnDManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/dnd/DnDManagerImpl.java @@ -136,6 +136,7 @@ public final class DnDManagerImpl extends DnDManager { @Override public void registerTarget(DnDTarget target, JComponent component) { component.putClientProperty(TARGET_KEY, target); + //noinspection ResultOfObjectAllocationIgnored new DropTarget(component, DnDConstants.ACTION_COPY_OR_MOVE, myDropTargetListener); } diff --git a/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java b/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java index 2562f2caa826..29c5b42e37e8 100644 --- a/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java +++ b/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java @@ -555,6 +555,7 @@ final class ComponentPanelTestAction extends DumbAwareAction { ComponentWithBrowseButton etfbb = new ComponentWithBrowseButton<>(editor, e -> System.out.println("JTextField browse button pressed")); new ComponentValidator(getDisposable()).withValidator(() -> { try { + //noinspection ResultOfObjectAllocationIgnored new URL(etfbb.getChildComponent().getDocument().getText()); return null; } catch (MalformedURLException mex) { diff --git a/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java b/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java index 2882bce7a411..b821766ebcfe 100644 --- a/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java @@ -1142,14 +1142,16 @@ public final class NotificationsManagerImpl extends NotificationsManager { private boolean myHandleDispose = true; private BalloonPopupSupport(@NotNull JPopupMenu popupMenu, - @NotNull Balloon balloon, @NotNull JComponent component, @NotNull Alarm popupAlarm) { myPopupMenu = popupMenu; myComponent = component; myAlarm = popupAlarm; - popupAlarm.cancelAllRequests(); - popupMenu.addPopupMenuListener(this); + } + + private void setupListeners(@NotNull Balloon balloon) { + myAlarm.cancelAllRequests(); + myPopupMenu.addPopupMenuListener(this); Disposer.register(balloon, this); } @@ -1213,7 +1215,7 @@ public final class NotificationsManagerImpl extends NotificationsManager { JPopupMenu menu = showPopup(link, group); Balloon balloon = notification.getBalloon(); if (menu != null && balloon != null) { - new BalloonPopupSupport(menu, balloon, link, popupAlarm); + new BalloonPopupSupport(menu, link, popupAlarm).setupListeners(balloon); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileTextFieldImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileTextFieldImpl.java index b6a52ded5101..06734cc4c886 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileTextFieldImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileTextFieldImpl.java @@ -130,12 +130,13 @@ public class FileTextFieldImpl implements FileTextField, Disposable { myCancelAction = new CancelAction(); - new LazyUiDisposable<>(parent, field, this) { + LazyUiDisposable disposable = new LazyUiDisposable<>(parent, field, this) { @Override protected void initialize(@NotNull Disposable parent, @NotNull FileTextFieldImpl child, @Nullable Project project) { Disposer.register(child, myUiUpdater); } }; + disposable.setupListeners(); } @SuppressWarnings("unused") //used by rider diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java index d16aef50470f..1402a6cb78c5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java @@ -69,7 +69,7 @@ public class LocalFileSystemImpl extends LocalFileSystemBase implements Disposab myWatchRootsManager = new WatchRootsManager(myWatcher, this); Disposer.register(ApplicationManager.getApplication(), this); - new SymbolicLinkRefresher(this); + new SymbolicLinkRefresher(this).refresh(); } public @NotNull FileWatcher getFileWatcher() { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/SymbolicLinkRefresher.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/SymbolicLinkRefresher.java index 651f85dda670..0a3ec2f9b8a7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/SymbolicLinkRefresher.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/SymbolicLinkRefresher.java @@ -35,7 +35,10 @@ final class SymbolicLinkRefresher { SymbolicLinkRefresher(LocalFileSystemImpl system) { mySystem = system; - ApplicationManager.getApplication().getMessageBus().connect(system).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() { + } + + void refresh() { + ApplicationManager.getApplication().getMessageBus().connect(mySystem).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() { @Override public void after(@NotNull List events) { analyzeEvents(events); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/SingleRemoteServerConfigurable.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/SingleRemoteServerConfigurable.java index 603cb5efc16f..86a5de010e26 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/SingleRemoteServerConfigurable.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/configuration/SingleRemoteServerConfigurable.java @@ -88,6 +88,7 @@ public class SingleRemoteServerConfigurable extends NamedConfigurable RemoteServerConfigurable createConfigurable(RemoteServer server, C configuration) { diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/DelayedRunner.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/DelayedRunner.java index eceebf9221f4..3ac69ead4fbb 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/DelayedRunner.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/DelayedRunner.java @@ -33,12 +33,14 @@ public abstract class DelayedRunner implements Disposable { private int myChangesPastTime = NO_CHANGES; + /** + * Call {@link DelayedRunner#queueChangesCheck()} to start the runner + */ public DelayedRunner(@NotNull JComponent activationComponent) { myAlarm = new Alarm(activationComponent, this); - queueChangesCheck(); } - private void queueChangesCheck() { + public void queueChangesCheck() { if (myAlarm.isDisposed()) { return; } diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java index 2f4a6471537a..b05759cc9dfc 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java @@ -243,6 +243,7 @@ public final class InjectorUtils { } if (hasReChars) { try { + //noinspection ResultOfObjectAllocationIgnored new URL(s); } catch (MalformedURLException e) { diff --git a/plugins/ant/src/com/intellij/lang/ant/config/execution/AntBuildMessageView.java b/plugins/ant/src/com/intellij/lang/ant/config/execution/AntBuildMessageView.java index 51efc89c4818..f18ced92bec2 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/execution/AntBuildMessageView.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/execution/AntBuildMessageView.java @@ -289,7 +289,7 @@ public final class AntBuildMessageView extends JPanel implements DataProvider, O ijMessageView.getContentManager().addContent(content); ijMessageView.getContentManager().setSelectedContent(content); content.setDisposer(() -> Disposer.dispose(messageView)); - new CloseListener(content, ijMessageView.getContentManager(), project); + new CloseListener(content, ijMessageView.getContentManager(), project).setupListeners(); if (!buildFile.isRunInBackground()) { final ToolWindow tw = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW); @@ -564,10 +564,13 @@ public final class AntBuildMessageView extends JPanel implements DataProvider, O myContent = content; myContentManager = contentManager; myProject = project; - contentManager.addContentManagerListener(this); + } + + private void setupListeners() { + myContentManager.addContentManagerListener(this); ProjectManager.getInstance().addProjectManagerListener(myProject, this); - Disposer.register(content, () -> { + Disposer.register(myContent, () -> { myContentManager.removeContentManagerListener(this); ProjectManager.getInstance().removeProjectManagerListener(myProject, this); }); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldDialog.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldDialog.java index aa73bd863a2e..4a8b8de1f2a6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldDialog.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldDialog.java @@ -104,7 +104,7 @@ public class GrIntroduceFieldDialog extends DialogWrapper implements GrIntroduce for (JRadioButton init : inits) { initialization.add(init); } - new RadioUpDownListener(inits.toArray(new JRadioButton[0])); + RadioUpDownListener.installOn(inits.toArray(new JRadioButton[0])); if (clazz instanceof GroovyScriptClass) { myClassConstructorSRadioButton.setEnabled(false); @@ -231,7 +231,7 @@ public class GrIntroduceFieldDialog extends DialogWrapper implements GrIntroduce else { myPrivateRadioButton.setSelected(true); } - new RadioUpDownListener(myPrivateRadioButton, myProtectedRadioButton, myPublicRadioButton, myPropertyRadioButton); + RadioUpDownListener.installOn(myPrivateRadioButton, myProtectedRadioButton, myPublicRadioButton, myPropertyRadioButton); } private static boolean isAlwaysInvokedConstructor(@Nullable PsiMethod method, @NotNull PsiClass clazz) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenamePropertyUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenamePropertyUtil.java index f46fb61ad95c..1f3f4bbc943b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenamePropertyUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenamePropertyUtil.java @@ -145,7 +145,7 @@ public final class RenamePropertyUtil { box.add(myRbRenameMember); panel.add(box, BorderLayout.CENTER); - new RadioUpDownListener(myRbRenameMember, myRbRenameProperty); + RadioUpDownListener.installOn(myRbRenameMember, myRbRenameProperty); return panel; } diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/KotlinSelectNestedClassRefactoringDialog.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/KotlinSelectNestedClassRefactoringDialog.kt index e94b4a46ab1c..500c269be89c 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/KotlinSelectNestedClassRefactoringDialog.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/KotlinSelectNestedClassRefactoringDialog.kt @@ -48,7 +48,7 @@ internal class KotlinSelectNestedClassRefactoringDialog private constructor( add(moveMembersButton) } - RadioUpDownListener(moveToUpperLevelButton, moveMembersButton) + RadioUpDownListener.installOn(moveToUpperLevelButton, moveMembersButton) return JPanel(BorderLayout()).apply { val box = Box.createVerticalBox().apply { diff --git a/plugins/ui-designer-core/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java b/plugins/ui-designer-core/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java index f605bd3f665a..a346ae77a302 100644 --- a/plugins/ui-designer-core/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java +++ b/plugins/ui-designer-core/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java @@ -47,7 +47,7 @@ public final class ComponentTreeBuilder implements ComponentSelectionListener, D tree.setArea(myTreeArea); designer.handleTreeArea(myTreeArea); - new TreeDropListener(tree, myTreeArea, designer.getToolProvider()); + TreeDropListener.installOn(tree, myTreeArea, designer.getToolProvider()); selectFromSurface(); expandFromState(); diff --git a/plugins/ui-designer-core/src/com/intellij/designer/componentTree/TreeDropListener.java b/plugins/ui-designer-core/src/com/intellij/designer/componentTree/TreeDropListener.java index 994c8b2395d4..f0c9afa52566 100644 --- a/plugins/ui-designer-core/src/com/intellij/designer/componentTree/TreeDropListener.java +++ b/plugins/ui-designer-core/src/com/intellij/designer/componentTree/TreeDropListener.java @@ -51,21 +51,30 @@ public class TreeDropListener extends DropTargetAdapter { private boolean myExecuteEnabled; private boolean myShowFeedback; - public TreeDropListener(ComponentTree tree, EditableArea area, ToolProvider provider) { - this(tree, area, provider, TreeDropListener.class, PaletteItem.class); - if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { - tree.setDragEnabled(true); - tree.setTransferHandler(new TreeTransfer(TreeDropListener.class)); - } + private TreeDropListener(EditableArea area, ToolProvider provider) { + this(area, provider, TreeDropListener.class, PaletteItem.class); } - public TreeDropListener(JComponent component, EditableArea area, ToolProvider provider, Class... dragTargets) { + private TreeDropListener(EditableArea area, ToolProvider provider, Class... dragTargets) { myArea = area; myContext.setArea(area); myToolProvider = provider; myDragTargets = dragTargets; + } + + public static void installOn(ComponentTree tree, EditableArea area, ToolProvider provider) { + TreeDropListener listener = new TreeDropListener(area, provider); if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { - component.setDropTarget(new DropTarget(component, this)); + tree.setDragEnabled(true); + tree.setTransferHandler(new TreeTransfer(TreeDropListener.class)); + tree.setDropTarget(new DropTarget(tree, listener)); + } + } + + public static void installOn(JComponent component, EditableArea area, ToolProvider provider, Class... dragTargets) { + TreeDropListener listener = new TreeDropListener(area, provider, dragTargets); + if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { + component.setDropTarget(new DropTarget(component, listener)); } } diff --git a/plugins/ui-designer-core/src/com/intellij/designer/designSurface/GlassLayer.java b/plugins/ui-designer-core/src/com/intellij/designer/designSurface/GlassLayer.java index 40885415d226..ec3bea6ccef8 100644 --- a/plugins/ui-designer-core/src/com/intellij/designer/designSurface/GlassLayer.java +++ b/plugins/ui-designer-core/src/com/intellij/designer/designSurface/GlassLayer.java @@ -40,7 +40,7 @@ public class GlassLayer extends JComponent implements DataProvider { myToolProvider = provider; myArea = area; enableEvents(EVENT_FLAGS); - new TreeDropListener(this, area, provider, PaletteItem.class); + TreeDropListener.installOn(this, area, provider, PaletteItem.class); } @Override diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionWatcher.java b/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionWatcher.java index ea30728ce73d..3c216d7ddab3 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionWatcher.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionWatcher.java @@ -20,7 +20,6 @@ public abstract class SelectionWatcher { myEditor = editor; myChangeListener = new MyPropertyChangeListener(); myRootContainer = editor.getRootContainer(); - install(myRootContainer); myHierarchyChangeListener = new HierarchyChangeListener() { @Override @@ -32,7 +31,11 @@ public abstract class SelectionWatcher { } } }; - editor.addHierarchyChangeListener(myHierarchyChangeListener); + } + + public void setupListeners() { + install(myRootContainer); + myEditor.addHierarchyChangeListener(myHierarchyChangeListener); } public void dispose() { 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 71ccd2646c21..55e856e1afb0 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/componentTree/ComponentTreeBuilder.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/componentTree/ComponentTreeBuilder.java @@ -55,6 +55,7 @@ public final class ComponentTreeBuilder implements Disposable { myEditor = editor; mySelectionWatcher = new MySelectionWatcher(editor); + mySelectionWatcher.setupListeners(); syncSelection(); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/ActiveDecorationLayer.java b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/ActiveDecorationLayer.java index 67ee236dff5c..ed9ad27e09dd 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/ActiveDecorationLayer.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/ActiveDecorationLayer.java @@ -39,7 +39,7 @@ final class ActiveDecorationLayer extends JComponent implements FeedbackLayer { } public void installSelectionWatcher() { - new MyNavigateButtonSelectionWatcher(myEditor); + new MyNavigateButtonSelectionWatcher(myEditor).setupListeners(); } @Override 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 b984231ddb18..7e5229a3bb54 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/designSurface/GuiEditor.java @@ -339,6 +339,7 @@ public final class GuiEditor extends JPanel implements DesignerEditorPanelFacade myDropTargetListener = new DesignDropTargetListener(this); if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { + //noinspection ResultOfObjectAllocationIgnored new DropTarget(getGlassLayer(), DnDConstants.ACTION_COPY_OR_MOVE, myDropTargetListener); } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/quickFixes/QuickFixManager.java b/plugins/ui-designer/src/com/intellij/uiDesigner/quickFixes/QuickFixManager.java index f81bb48a468c..7ea314ee65a3 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/quickFixes/QuickFixManager.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/quickFixes/QuickFixManager.java @@ -58,7 +58,7 @@ public abstract class QuickFixManager { myComponent.addFocusListener(new FocusListenerImpl(this)); // Alt+Enter - new ShowHintAction(this, component); + new ShowHintAction(this).registerShortcutSet(component); viewPort.addChangeListener(new ChangeListener() { @Override 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 a13c1df1f84d..636f470a379a 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/quickFixes/ShowHintAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/quickFixes/ShowHintAction.java @@ -12,8 +12,11 @@ import javax.swing.*; final class ShowHintAction extends AnAction { private final QuickFixManager myManager; - ShowHintAction(@NotNull final QuickFixManager manager, @NotNull final JComponent component) { + ShowHintAction(@NotNull final QuickFixManager manager) { myManager = manager; + } + + void registerShortcutSet(@NotNull JComponent component) { registerCustomShortcutSet( ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS).getShortcutSet(), component