biskuteri-cafe-JKomasto2/ImageApi.java
Snowyfox e6fea4c061 Fixed bug when redraft makes no changes
(Before this, JKomasto and sometimes the Mastodon web client would get '411 Record Not Found' when submitting the same text after deleting and redrafting. Presumably the Mastodon server caches both whether an idempotency key was fulfilled and which post it leads to, and for some reason it looks up the second and fails.)
2022-05-31 03:39:56 -04:00

50 lines
998 B
Java

import javax.swing.ImageIcon;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import java.net.MalformedURLException;
interface
ImageApi {
public static Image
local(String name)
{
String path = "graphics/" + name + ".png";
URL url = ImageApi.class.getResource(path);
if (url == null) return null;
return new ImageIcon(url).getImage();
}
public static Image
remote(String urlr)
{
try
{
URL url = new URL(urlr);
Toolkit TK = Toolkit.getDefaultToolkit();
return TK.createImage(url);
}
catch (MalformedURLException eMu)
{
return null;
}
}
public static ImageIcon
iconRemote(String urlr)
{
if (urlr == null) return null;
try
{
return new ImageIcon(new URL(urlr));
}
catch (MalformedURLException eMu)
{
return null;
}
}
}