From 7c710b51bdb715a4a4fcdc370ae6e04a4170e64e Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Tue, 23 Sep 2014 12:48:16 +0400 Subject: [PATCH] [push] Remove LoadingTreeNode as not used, move everything related to LoadingIconProvider --- ...TreeNode.java => LoadingIconProvider.java} | 52 ++++++++++++------- .../dvcs/push/ui/NodeImageObserver.java | 51 ------------------ .../intellij/dvcs/push/ui/RepositoryNode.java | 4 +- 3 files changed, 34 insertions(+), 73 deletions(-) rename platform/dvcs-impl/src/com/intellij/dvcs/push/ui/{LoadingTreeNode.java => LoadingIconProvider.java} (51%) delete mode 100644 platform/dvcs-impl/src/com/intellij/dvcs/push/ui/NodeImageObserver.java diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/LoadingTreeNode.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/LoadingIconProvider.java similarity index 51% rename from platform/dvcs-impl/src/com/intellij/dvcs/push/ui/LoadingTreeNode.java rename to platform/dvcs-impl/src/com/intellij/dvcs/push/ui/LoadingIconProvider.java index 36958a00c64b..a1179e933514 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/LoadingTreeNode.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/LoadingIconProvider.java @@ -15,29 +15,23 @@ */ package com.intellij.dvcs.push.ui; -import com.intellij.ui.ColoredTreeCellRenderer; -import com.intellij.ui.JBColor; -import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.ImageLoader; import com.intellij.util.ui.JBImageIcon; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; -import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; import java.awt.*; import java.awt.image.BufferedImage; +import java.awt.image.ImageObserver; -public class LoadingTreeNode extends DefaultMutableTreeNode implements CustomRenderedTreeNode { +class LoadingIconProvider { private static final String LOADING_ICON = "/icons/loading.gif"; private static final JBImageIcon EMPTY_ICON = new JBImageIcon(UIUtil.createImage(18, 18, BufferedImage.TYPE_3BYTE_BGR)); - @NotNull private ImageIcon myLoadingIcon; - - public LoadingTreeNode() { - super(null, false); - myLoadingIcon = getLoadingIcon(); - } @NotNull public static JBImageIcon getLoadingIcon() { @@ -45,16 +39,34 @@ public class LoadingTreeNode extends DefaultMutableTreeNode implements CustomRen return image == null ? EMPTY_ICON : new JBImageIcon(image); } - @Override - public void render(@NotNull ColoredTreeCellRenderer renderer) { - renderer.setIcon(myLoadingIcon); - // loading icon should be on the left and do not inherit parent config - renderer.setIconOnTheRight(false); - renderer.append("Loading Commits...", new SimpleTextAttributes(SimpleTextAttributes.STYLE_SMALLER, JBColor.GRAY)); + @NotNull + public static ImageObserver createObserver(@NotNull JTree tree, @NotNull TreeNode treeNode) { + return new NodeImageObserver(tree, treeNode); } - @NotNull - public ImageIcon getIcon() { - return myLoadingIcon; + private static class NodeImageObserver implements ImageObserver { + @NotNull private final JTree myTree; + @NotNull private final DefaultTreeModel myModel; + @NotNull private final TreeNode myNode; + + NodeImageObserver(@NotNull JTree tree, @NotNull TreeNode node) { + myTree = tree; + myModel = (DefaultTreeModel)tree.getModel(); + myNode = node; + } + + public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h) { + if ((flags & (FRAMEBITS | ALLBITS)) != 0) { + TreeNode[] pathToRoot = myModel.getPathToRoot(myNode); + if (pathToRoot != null) { + TreePath path = new TreePath(pathToRoot); + Rectangle rect = myTree.getPathBounds(path); + if (rect != null) { + myTree.repaint(rect); + } + } + } + return (flags & (ALLBITS | ABORT)) == 0; + } } } diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/NodeImageObserver.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/NodeImageObserver.java deleted file mode 100644 index 92130775f894..000000000000 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/NodeImageObserver.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.dvcs.push.ui; - -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; -import java.awt.*; -import java.awt.image.ImageObserver; - -class NodeImageObserver implements ImageObserver { - @NotNull private final JTree myTree; - @NotNull private final DefaultTreeModel myModel; - @NotNull private final TreeNode myNode; - - NodeImageObserver(@NotNull JTree tree, @NotNull TreeNode node) { - myTree = tree; - myModel = (DefaultTreeModel)tree.getModel(); - myNode = node; - } - - public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h) { - if ((flags & (FRAMEBITS | ALLBITS)) != 0) { - TreeNode[] pathToRoot = myModel.getPathToRoot(myNode); - if (pathToRoot != null) { - TreePath path = new TreePath(pathToRoot); - Rectangle rect = myTree.getPathBounds(path); - if (rect != null) { - myTree.repaint(rect); - } - } - } - return (flags & (ALLBITS | ABORT)) == 0; - } -} \ No newline at end of file diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/RepositoryNode.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/RepositoryNode.java index be57fee704c1..6fb6d71ffc20 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/RepositoryNode.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/RepositoryNode.java @@ -45,7 +45,7 @@ public class RepositoryNode extends CheckedTreeNode implements EditableTreeNode, setChecked(false); setEnabled(enabled); myRepositoryPanel = repositoryPanel; - myLoadingIcon = LoadingTreeNode.getLoadingIcon(); + myLoadingIcon = LoadingIconProvider.getLoadingIcon(); } public boolean isCheckboxVisible() { @@ -102,7 +102,7 @@ public class RepositoryNode extends CheckedTreeNode implements EditableTreeNode, public void startLoading(@NotNull JTree tree, @NotNull Future> future) { myFuture = future; myLoading.set(true); - myLoadingIcon.setImageObserver(new NodeImageObserver(tree, this)); + myLoadingIcon.setImageObserver(LoadingIconProvider.createObserver(tree, this)); } public int compareTo(@NotNull RepositoryNode repositoryNode) {