use of java.util.WeakHashMap in project robovm by robovm.
the class WeakHashMapTest method test_size.
/**
* java.util.WeakHashMap#size()
*/
public void test_size() {
whm = new WeakHashMap();
assertEquals(0, whm.size());
}
use of java.util.WeakHashMap in project intellij-community by JetBrains.
the class IdeaHelpBroker method createHelpWindow.
private synchronized void createHelpWindow() {
JDialog tmpDialog = null;
Dimension size = null;
Point pos = null;
boolean resize = false;
createJHelp();
// Get the title from the HelpSet
String helpTitle = myHelpSet.getTitle();
if (myModallyActivated) {
// replace dialog.getOwner() with the following code
Window owner = null;
try {
Method m = Window.class.getMethod("getOwner", null);
if (m != null && myDialog != null) {
owner = (Window) m.invoke(myDialog, null);
}
} catch (NoSuchMethodError | NoSuchMethodException ex) {
// as in JDK1.1
} catch (InvocationTargetException | IllegalAccessException ex) {
//
}
if (myDialog == null || owner != myOwnerWindow || modalDeactivated) {
if (myFrame != null) {
pos = myFrame.getLocation();
size = myFrame.getSize();
myFrame.dispose();
}
if (myDialog != null) {
pos = myDialog.getLocation();
size = myDialog.getSize();
tmpDialog = myDialog;
}
myDialog = new JDialog((Dialog) myOwnerWindow, helpTitle);
// Modal dialogs are really tricky. When the modal dialog
// is dismissed the JDialog will be dismissed as well.
// When that happens we need to make sure the ownerWindow
// is set to null so that a new dialog will be created so
// that events aren't blocked in the HelpViewer.
dl = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// JDK1.2.1 bug not closing owned windows
if (myDialog.isShowing()) {
myDialog.hide();
}
if (myOwnerWindow != null) {
myOwnerWindow.removeWindowListener(dl);
}
myOwnerWindow = null;
modalDeactivated = true;
}
};
myOwnerWindow.addWindowListener(dl);
modalDeactivated = false;
if (size != null) {
myDialog.setSize(size);
} else {
myDialog.setSize(HELP_WIDTH, HELP_HEIGHT);
}
if (pos != null) {
myDialog.setLocation(pos);
}
myDialog.getContentPane().add(jhelp);
if (tmpDialog != null) {
tmpDialog.dispose();
}
}
} else {
if (myFrame == null) {
myFrame = new JFrame(helpTitle);
resize = true;
AppUIUtil.updateWindowIcon(myFrame);
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
myFrame.dispose();
WeakHashMap handlers = ReflectionUtil.getField(JHelpPrintHandler.class, null, WeakHashMap.class, "handlers");
if (handlers != null) {
// even though jHelp is a weak key in the map, corresponding map entry will never be removed, as it's also referenced
// from the mapped value
handlers.remove(jhelp);
}
}
};
myFrame.addWindowListener(l);
} else {
pos = myFrame.getLocation();
}
if (myDialog != null) {
pos = myDialog.getLocation();
size = myDialog.getSize();
myDialog.dispose();
myDialog = null;
myOwnerWindow = null;
}
if (size != null) {
myFrame.setSize(size);
} else if (resize) {
myFrame.setSize(HELP_WIDTH, HELP_HEIGHT);
}
if (pos != null) {
myFrame.setLocation(pos);
}
myFrame.getContentPane().add(jhelp);
myFrame.setTitle(myHelpSet.getTitle());
}
}
use of java.util.WeakHashMap in project robovm by robovm.
the class OldAttributedStringTest method test_ConstructorLjava_lang_StringLjava_util_Map.
/**
* java.text.AttributedString#AttributedString(AttributedCharacterIterator,
* int, int, Map<? extends AttributedCharacterIterator.Attribute,?>)
* Test of method
* java.text.AttributedString#AttributedString(AttributedCharacterIterator,
* int, int, Map<? extends
* AttributedCharacterIterator.Attribute,?>). Case 1: Try to
* construct AttributedString. Case 2: Try to construct
* AttributedString using 0-length text and not an empty Map
* attributes.
*/
public void test_ConstructorLjava_lang_StringLjava_util_Map() {
String test = "Test string";
// case 1: Try to construct AttributedString
try {
AttributedString attrString = new AttributedString(test, new WeakHashMap<AttributedCharacterIterator.Attribute, String>());
AttributedCharacterIterator it = attrString.getIterator();
StringBuffer buf = new StringBuffer();
buf.append(it.first());
char ch;
while ((ch = it.next()) != CharacterIterator.DONE) buf.append(ch);
assertTrue("Wrong string: " + buf, buf.toString().equals(test));
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
// not an empty Map attributes.
try {
Map<AttributedCharacterIterator.Attribute, String> whm = new WeakHashMap<AttributedCharacterIterator.Attribute, String>();
whm.put(new TestAttributedCharacterIteratorAttribute("test"), "value");
new AttributedString("", whm);
fail("Expected IllegalArgumentException was not thrown");
} catch (Exception e) {
// expected
}
}
use of java.util.WeakHashMap in project jdk8u_jdk by JetBrains.
the class ColorModel method getGray16TosRGB8LUT.
/*
* Return a byte LUT that converts 16-bit gray values in the grayCS
* ColorSpace to the appropriate 8-bit sRGB value. I.e., if lut
* is the byte array returned by this method and sval = lut[gval],
* then the sRGB triple (sval,sval,sval) is the best match to gval.
* Cache references to any computed LUT in a Map.
*/
static byte[] getGray16TosRGB8LUT(ICC_ColorSpace grayCS) {
if (isLinearGRAYspace(grayCS)) {
return getLinearRGB16TosRGB8LUT();
}
if (g16Tos8Map != null) {
byte[] g16Tos8LUT = g16Tos8Map.get(grayCS);
if (g16Tos8LUT != null) {
return g16Tos8LUT;
}
}
short[] tmp = new short[65536];
for (int i = 0; i <= 65535; i++) {
tmp[i] = (short) i;
}
ColorTransform[] transformList = new ColorTransform[2];
PCMM mdl = CMSManager.getModule();
ICC_ColorSpace srgbCS = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB);
transformList[0] = mdl.createTransform(grayCS.getProfile(), ColorTransform.Any, ColorTransform.In);
transformList[1] = mdl.createTransform(srgbCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
ColorTransform t = mdl.createTransform(transformList);
tmp = t.colorConvert(tmp, null);
byte[] g16Tos8LUT = new byte[65536];
for (int i = 0, j = 2; i <= 65535; i++, j += 3) {
// All three components of tmp should be equal, since
// the input color space to colorConvert is a gray scale
// space. However, there are slight anomalies in the results.
// Copy tmp starting at index 2, since colorConvert seems
// to be slightly more accurate for the third component!
// scale unsigned short (0 - 65535) to unsigned byte (0 - 255)
g16Tos8LUT[i] = (byte) (((float) (tmp[j] & 0xffff)) * (1.0f / 257.0f) + 0.5f);
}
if (g16Tos8Map == null) {
g16Tos8Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, byte[]>(2));
}
g16Tos8Map.put(grayCS, g16Tos8LUT);
return g16Tos8LUT;
}
use of java.util.WeakHashMap in project jdk8u_jdk by JetBrains.
the class ColorModel method getLinearGray16ToOtherGray8LUT.
/*
* Return a byte LUT that converts 16-bit gray values in the CS_GRAY
* linear gray ColorSpace to the appropriate 8-bit value in the
* grayCS ColorSpace. Cache references to any computed LUT in a Map.
*/
static byte[] getLinearGray16ToOtherGray8LUT(ICC_ColorSpace grayCS) {
if (lg16Toog8Map != null) {
byte[] lg16Toog8LUT = lg16Toog8Map.get(grayCS);
if (lg16Toog8LUT != null) {
return lg16Toog8LUT;
}
}
short[] tmp = new short[65536];
for (int i = 0; i <= 65535; i++) {
tmp[i] = (short) i;
}
ColorTransform[] transformList = new ColorTransform[2];
PCMM mdl = CMSManager.getModule();
ICC_ColorSpace lgCS = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_GRAY);
transformList[0] = mdl.createTransform(lgCS.getProfile(), ColorTransform.Any, ColorTransform.In);
transformList[1] = mdl.createTransform(grayCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
ColorTransform t = mdl.createTransform(transformList);
tmp = t.colorConvert(tmp, null);
byte[] lg16Toog8LUT = new byte[65536];
for (int i = 0; i <= 65535; i++) {
// scale unsigned short (0 - 65535) to unsigned byte (0 - 255)
lg16Toog8LUT[i] = (byte) (((float) (tmp[i] & 0xffff)) * (1.0f / 257.0f) + 0.5f);
}
if (lg16Toog8Map == null) {
lg16Toog8Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, byte[]>(2));
}
lg16Toog8Map.put(grayCS, lg16Toog8LUT);
return lg16Toog8LUT;
}
Aggregations