Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roman Shevchenko
2016-03-03 17:51:00 +01:00
12 changed files with 160 additions and 69 deletions
@@ -26,7 +26,6 @@ import com.intellij.util.SystemProperties;
import com.intellij.util.containers.ContainerUtil;
import com.jgoodies.forms.layout.CellConstraints;
import io.netty.util.NetUtil;
import jsr166e.extra.SequenceLock;
import net.n3.nanoxml.IXMLBuilder;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.builders.impl.java.EclipseCompilerTool;
@@ -144,7 +143,6 @@ public class ClasspathBootstrap {
cp.add(getResourcePath(CellConstraints.class)); // jGoodies-forms
cp.add(getResourcePath(NotNullVerifyingInstrumenter.class)); // not-null
cp.add(getResourcePath(IXMLBuilder.class)); // nano-xml
cp.add(getResourcePath(SequenceLock.class)); // jsr166
cp.add(getJpsPluginSystemClassesPath().getAbsolutePath().replace('\\', '/'));
//don't forget to update layoutCommunityJps() in layouts.gant accordingly
@@ -17,27 +17,39 @@ package com.intellij.diff.tools.util;
import com.intellij.diff.tools.util.DiffSplitter.Painter;
import com.intellij.diff.util.Side;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.icons.AllIcons;
import org.jetbrains.annotations.CalledInAwt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.List;
public class ThreeDiffSplitter extends JPanel {
private static final int DIVIDER_WIDTH = 30;
@NotNull private final List<Divider> myDividers;
@NotNull private final List<? extends JComponent> myContents;
@NotNull private final Divider myDivider1;
@NotNull private final Divider myDivider2;
private float myProportion1; // first size divided by (first + second + third)
private float myProportion2; // third size divided by (first + second + third)
public ThreeDiffSplitter(@NotNull List<? extends JComponent> components) {
myDividers = ContainerUtil.list(new Divider(), new Divider());
assert components.size() == 3;
myContents = components;
myDivider1 = new Divider(Side.LEFT);
myDivider2 = new Divider(Side.RIGHT);
addAll(myContents);
addAll(myDividers);
add(myDivider1);
add(myDivider2);
for (JComponent content : myContents) {
add(content);
}
resetProportions();
}
@CalledInAwt
@@ -56,32 +68,44 @@ public class ThreeDiffSplitter extends JPanel {
@NotNull
private Divider getDivider(@NotNull Side side) {
return myDividers.get(side.getIndex());
return side.select(myDivider1, myDivider2);
}
private void addAll(@NotNull List<? extends JComponent> components) {
for (JComponent component : components) {
add(component, -1);
}
private void resetProportions() {
myProportion1 = myProportion2 = 1f / 3;
}
private void setProportion(float proportion, @NotNull Side side) {
proportion = Math.min(1f, Math.max(0f, proportion));
float otherProportion = side.select(myProportion2, myProportion1);
otherProportion = Math.min(otherProportion, 1f - proportion);
myProportion1 = side.select(proportion, otherProportion);
myProportion2 = side.select(otherProportion, proportion);
}
@Override
public void doLayout() {
int width = getWidth();
int height = getHeight();
int panelWidth = (width - DIVIDER_WIDTH * 2) / 3;
int dividersTotalWidth = DIVIDER_WIDTH * 2;
int contentsTotalWidth = Math.max(width - dividersTotalWidth, 0);
JComponent[] components = new JComponent[]{myContents.get(0), myDivider1, myContents.get(1), myDivider2, myContents.get(2)};
int[] contentWidths = new int[5];
contentWidths[1] = DIVIDER_WIDTH; // divider1
contentWidths[3] = DIVIDER_WIDTH; // divider2
contentWidths[0] = (int)(contentsTotalWidth * myProportion1); // content1
contentWidths[4] = (int)(contentsTotalWidth * myProportion2); // content3
contentWidths[2] = Math.max(contentsTotalWidth - contentWidths[0] - contentWidths[4], 0); // content2
int x = 0;
for (int i = 0; i < myContents.size(); i++) {
JComponent component = myContents.get(i);
component.setBounds(x, 0, panelWidth, height);
for (int i = 0; i < 5; i++) {
JComponent component = components[i];
component.setBounds(x, 0, contentWidths[i], height);
component.validate();
x += panelWidth;
if (i < myDividers.size()) {
JComponent divider = myDividers.get(i);
divider.setBounds(x, 0, DIVIDER_WIDTH, height);
divider.validate();
x += DIVIDER_WIDTH;
}
x += contentWidths[i];
}
}
@@ -109,12 +133,21 @@ public class ThreeDiffSplitter extends JPanel {
return new Dimension(width, height);
}
private static class Divider extends JComponent {
private class Divider extends JPanel {
@NotNull private final Side mySide;
@Nullable private Painter myPainter;
public Divider(@NotNull Side side) {
super(new GridBagLayout());
mySide = side;
enableEvents(MouseEvent.MOUSE_EVENT_MASK | MouseEvent.MOUSE_MOTION_EVENT_MASK);
setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
add(new JLabel(AllIcons.General.SplitGlueH), new GridBagConstraints());
}
@Override
public void paint(Graphics g) {
super.paint(g);
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (myPainter != null) myPainter.paint(g, this);
}
@@ -122,5 +155,32 @@ public class ThreeDiffSplitter extends JPanel {
public void setPainter(@Nullable Painter painter) {
myPainter = painter;
}
@Override
protected void processMouseMotionEvent(MouseEvent e) {
super.processMouseMotionEvent(e);
if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
int totalWidth = ThreeDiffSplitter.this.getWidth();
if (totalWidth > 0) {
Point point = SwingUtilities.convertPoint(this, e.getPoint(), ThreeDiffSplitter.this);
float proportion = (float)mySide.select(point.x, totalWidth - point.x) / (float)totalWidth;
setProportion(proportion, mySide);
revalidate();
repaint();
}
}
}
@Override
protected void processMouseEvent(MouseEvent e) {
super.processMouseEvent(e);
if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() == 2) {
resetProportions();
revalidate();
repaint();
}
}
}
}
@@ -198,6 +198,7 @@ public class DiffDividerDrawUtil {
@NotNull
private static LineRange getVisibleInterval(Editor editor) {
Rectangle area = editor.getScrollingModel().getVisibleArea();
if (area.height < 0) return new LineRange(0, 0);
LogicalPosition position1 = editor.xyToLogicalPosition(new Point(0, area.y));
LogicalPosition position2 = editor.xyToLogicalPosition(new Point(0, area.y + area.height));
return new LineRange(position1.line, position2.line);
@@ -79,7 +79,6 @@ import com.intellij.util.io.storage.HeavyProcessLatch;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.messages.MessageBusConnection;
import gnu.trove.*;
import jsr166e.extra.SequenceLock;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@@ -92,6 +91,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* @author Eugene Zhuravlev
@@ -1163,7 +1163,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
++myFilesModCount;
}
private final Lock myCalcIndexableFilesLock = new SequenceLock();
private final Lock myCalcIndexableFilesLock = new ReentrantLock();
@Nullable
public ProjectIndexableFilesFilter projectIndexableFiles(@Nullable Project project) {
@@ -290,6 +290,6 @@ public class Notification {
return myImportant;
}
return getListener() != null;
return getListener() != null || !ContainerUtil.isEmpty(myActions);
}
}
@@ -130,7 +130,7 @@ public class EventLog {
public String fun(AnAction action) {
return "<a href=\"" + index++ + "\">" + action.getTemplatePresentation().getText()+"</a>";
}
}, actions.size() > 3 ? "<br>" : "&nbsp;") + "</p>";
}, isLongLine(actions) ? "<br>" : "&nbsp;") + "</p>";
Notification n = new Notification("", "", ".", NotificationType.INFORMATION, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification n, @NotNull HyperlinkEvent event) {
@@ -169,6 +169,21 @@ public class EventLog {
return new LogEntry(logDoc.getText(), status, list);
}
private static boolean isLongLine(@NotNull List<AnAction> actions) {
int size = actions.size();
if (size > 3) {
return true;
}
if (size > 1) {
int length = 0;
for (AnAction action : actions) {
length += StringUtil.length(action.getTemplatePresentation().getText());
}
return length > 30;
}
return false;
}
@NotNull
private static String truncateLongString(AtomicBoolean showMore, String title) {
if (title.length() > 1000) {
@@ -55,7 +55,7 @@ public class IdeBackgroundUtil {
JRootPane rootPane = component.getRootPane();
Component glassPane = rootPane == null ? null : rootPane.getGlassPane();
final PaintersHelper helper = glassPane instanceof IdeGlassPaneImpl? ((IdeGlassPaneImpl)glassPane).getNamedPainters(paintersName) : null;
if (helper == null || !helper.hasPainters()) return (Graphics2D)g;
if (helper == null || !helper.needsRepaint()) return (Graphics2D)g;
return new MyGraphics(g, helper, component);
}
@@ -53,6 +53,13 @@ final class PaintersHelper implements Painter.Listener {
return !myPainters.isEmpty();
}
public boolean needsRepaint() {
for (Painter painter : myPainters) {
if (painter.needsRepaint()) return true;
}
return false;
}
public void addPainter(@NotNull Painter painter, @Nullable Component component) {
myPainters.add(painter);
myPainter2Component.put(painter, component == null ? myRootComponent : component);
@@ -125,11 +132,6 @@ final class PaintersHelper implements Painter.Listener {
}
public static void initWallpaperPainter(@NotNull String propertyName, @NotNull PaintersHelper painters) {
String value = System.getProperty(propertyName);
if (value == null && !new File(PathManager.getConfigPath(), propertyName + ".png").exists()) {
// property not set & there's no default
return;
}
ImagePainter painter = (ImagePainter)newWallpaperPainter(propertyName);
painters.addPainter(painter, null);
}
@@ -143,41 +145,59 @@ final class PaintersHelper implements Painter.Listener {
String current;
@Override
public boolean needsRepaint() {
return ensureImageLoaded();
}
@Override
public void executePaint(Component component, Graphics2D g) {
String value = StringUtil.notNullize(System.getProperty(propertyName), propertyName + ".png");
if (!ensureImageLoaded()) return;
executePaint(g, component, image, fillType, alpha, insets);
}
boolean ensureImageLoaded() {
String value = System.getProperty(propertyName);
if (!Comparing.equal(value, current)) {
current = value;
image = scaled = null;
insets = JBUI.emptyInsets();
String[] parts = value.split(",");
loadImage(value);
}
return image != null;
}
void loadImage(@Nullable String propertyValue) {
String[] parts = (propertyValue != null ? propertyValue : propertyName + ".png").split(",");
try {
alpha = StringUtil.parseInt(parts.length > 1 ? parts[1] : "", 10) / 100f;
try {
alpha = StringUtil.parseInt(parts.length > 1 ? parts[1]: "", 10) / 100f;
try {
fillType = FillType.valueOf(parts.length > 2 ? parts[2].toUpperCase(Locale.ENGLISH) : "");
}
catch (IllegalArgumentException e) {
fillType = FillType.SCALE;
}
String filePath = parts[0];
URL url = filePath.contains("://") ? new URL(filePath) :
(FileUtil.isAbsolutePlatformIndependent(filePath)
? new File(filePath)
: new File(PathManager.getConfigPath(), filePath)).toURI().toURL();
image = ImageLoader.loadFromUrl(url);
fillType = FillType.valueOf(parts.length > 2 ? parts[2].toUpperCase(Locale.ENGLISH) : "");
}
catch (Exception ignored) {
catch (IllegalArgumentException e) {
fillType = FillType.SCALE;
}
String filePath = parts[0];
URL url = filePath.contains("://") ? new URL(filePath) :
(FileUtil.isAbsolutePlatformIndependent(filePath)
? new File(filePath)
: new File(PathManager.getConfigPath(), filePath)).toURI().toURL();
image = ImageLoader.loadFromUrl(url);
}
catch (Exception ignored) {
}
if (image == null) return;
executePaint(g, component, image, fillType, alpha, insets);
}
};
}
public static AbstractPainter newImagePainter(final Image image, final FillType fillType, final float alpha, final Insets insets) {
public static AbstractPainter newImagePainter(@NotNull final Image image, final FillType fillType, final float alpha, final Insets insets) {
return new ImagePainter() {
@Override
public boolean needsRepaint() {
return true;
}
@Override
public void executePaint(Component component, Graphics2D g) {
executePaint(g, component, image, fillType, alpha, insets);
@@ -189,9 +209,6 @@ final class PaintersHelper implements Painter.Listener {
VolatileImage scaled;
@Override
public boolean needsRepaint() { return true; }
public void executePaint(Graphics2D g, Component component, Image image, FillType fillType, float alpha, Insets insets) {
int cw0 = component.getWidth();
int ch0 = component.getHeight();
@@ -16,10 +16,10 @@
package com.intellij.util.containers;
import com.intellij.openapi.util.LowMemoryWatcher;
import jsr166e.extra.SequenceLock;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* User: Maxim.Mossienko
@@ -56,7 +56,7 @@ public class RecentStringInterner {
super.putToProtectedQueue(value, value);
}
};
myStripeLocks[i] = new SequenceLock();
myStripeLocks[i] = new ReentrantLock();
}
assert Integer.highestOneBit(stripes) == stripes;
@@ -16,11 +16,11 @@
package com.intellij.util.io;
import com.intellij.util.containers.SLRUMap;
import jsr166e.extra.SequenceLock;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* @author peter
@@ -44,7 +44,7 @@ public class CachingEnumerator<Data> implements DataEnumerator<Data> {
for(int i = 0; i < STRIPE_COUNT; ++i) {
myHashcodeToIdCache[i] = new SLRUMap<Integer, Integer>(protectedSize / STRIPE_COUNT, probationalSize / STRIPE_COUNT);
myIdToStringCache[i] = new SLRUMap<Integer, Data>(protectedSize / STRIPE_COUNT, probationalSize / STRIPE_COUNT);
myStripeLocks[i] = new SequenceLock();
myStripeLocks[i] = new ReentrantLock();
}
}
@@ -22,7 +22,6 @@ import com.intellij.util.SystemProperties;
import com.intellij.util.containers.ConcurrentIntObjectMap;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.hash.LinkedHashMap;
import jsr166e.extra.SequenceLock;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -35,6 +34,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.locks.ReentrantLock;
/**
* @author max
@@ -486,10 +486,10 @@ public class PagedFileStorage implements Forceable {
private final ConcurrentIntObjectMap<PagedFileStorage> myIndex2Storage = ContainerUtil.createConcurrentIntObjectMap();
private final LinkedHashMap<Integer, ByteBufferWrapper> mySegments;
private final SequenceLock mySegmentsAccessLock = new SequenceLock(); // protects map operations of mySegments, needed for LRU order, mySize and myMappingChangeCount
private final ReentrantLock mySegmentsAccessLock = new ReentrantLock(); // protects map operations of mySegments, needed for LRU order, mySize and myMappingChangeCount
// todo avoid locking for access
private final SequenceLock mySegmentsAllocationLock = new SequenceLock();
private final ReentrantLock mySegmentsAllocationLock = new ReentrantLock();
private final ConcurrentLinkedQueue<ByteBufferWrapper> mySegmentsToRemove = new ConcurrentLinkedQueue<ByteBufferWrapper>();
private volatile long mySize;
private volatile long mySizeLimit;
@@ -780,7 +780,7 @@ public class PagedFileStorage implements Forceable {
public static class StorageLockContext {
private final boolean myCheckThreadAccess;
private final SequenceLock myLock;
private final ReentrantLock myLock;
private final StorageLock myStorageLock;
@Deprecated
@@ -789,7 +789,7 @@ public class PagedFileStorage implements Forceable {
}
private StorageLockContext(StorageLock lock, boolean checkAccess) {
myLock = new SequenceLock();
myLock = new ReentrantLock();
myStorageLock = lock;
myCheckThreadAccess = checkAccess;
}
@@ -18,7 +18,7 @@ import java.util.Set;
public class VcsLogUserFilterImpl implements VcsLogUserFilter {
public @NotNull static final String ME = "me";
@NotNull public static final String ME = "me";
@NotNull private final Collection<String> myUsers;
@NotNull private final Map<VirtualFile, VcsUser> myData;