* <li>WRAP_ALIGNMENT</li>
* <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
* style check</li>
- * <li>BITMAP_SCALE - scale factor for PNG export - default 0 - native resolution</li>
+ * <li>BITMAP_SCALE - scale factor for PNG export - default 0.0 - native
+ * resolution</li>
* <li>BITMAP_HEIGHT - height bound for PNG export or 0 for unbound</li>
* <li>BITMAP_WIDTH - width bound for PNG export or 0 for unbound</li>
* <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
url = Cache.class.getResource(resourcePath).toString();
} catch (Exception ex)
{
- jalview.bin.Console.errPrintln("Failed to resolve resource " + resourcePath
- + ": " + ex.getMessage());
+ jalview.bin.Console.errPrintln("Failed to resolve resource "
+ + resourcePath + ": " + ex.getMessage());
}
}
else
return def;
}
+ public static float getDefault(String property, float def)
+ {
+ String string = getProperty(property);
+ if (string != null)
+ {
+ try
+ {
+ def = Float.parseFloat(string);
+ } catch (NumberFormatException e)
+ {
+ if (!Jalview.quiet())
+ jalview.bin.Console.outPrintln("Error parsing float property '"
+ + property + "' with value '" + string + "'");
+ }
+ }
+
+ return def;
+ }
+
/**
* Answers the value of the given property, or the supplied default value if
* the property is not set
return date_format.parse(val);
} catch (Exception ex)
{
- jalview.bin.Console.errPrintln("Invalid or corrupt date in property '"
- + propertyName + "' : value was '" + val + "'");
+ jalview.bin.Console
+ .errPrintln("Invalid or corrupt date in property '"
+ + propertyName + "' : value was '" + val + "'");
}
}
return null;
return Integer.valueOf(val);
} catch (NumberFormatException x)
{
- jalview.bin.Console.errPrintln("Invalid integer in property '" + property
- + "' (value was '" + val + "')");
+ jalview.bin.Console.errPrintln("Invalid integer in property '"
+ + property + "' (value was '" + val + "')");
}
}
return null;
private static final Collection<String> bootstrapProperties = new ArrayList<>(
Arrays.asList(JALVIEWLOGLEVEL, BOOTSTRAP_TEST));
-
public static Properties bootstrapProperties(String filename)
{
Properties bootstrapProps = new Properties();
return null;
if (!file.exists())
{
- jalview.bin.Console.errPrintln("Could not load bootstrap preferences file '"
- + filename + "'");
+ jalview.bin.Console
+ .errPrintln("Could not load bootstrap preferences file '"
+ + filename + "'");
return null;
}
}
} catch (FileNotFoundException e)
{
- jalview.bin.Console.errPrintln("Could not find bootstrap preferences file '"
- + file.getAbsolutePath() + "'");
+ jalview.bin.Console
+ .errPrintln("Could not find bootstrap preferences file '"
+ + file.getAbsolutePath() + "'");
} catch (IOException e)
{
jalview.bin.Console.errPrintln(
if (Jalview.isHeadlessMode())
{
AnnotationLabels aal = getAlabels();
- int stringWidth = aal.drawLabels(null, false, idWidth, false, false, fm);
+ int stringWidth = aal.drawLabels(null, false, idWidth, false, false,
+ fm);
idWidth = Math.max(idWidth, stringWidth);
}
else
throws ImageOutputException
{
makeAlignmentImage(type, file, renderer,
- BitmapImageSizing.nullBitmapImageSizing());
+ BitmapImageSizing.defaultBitmapImageSizing());
}
/**
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.io.File;
-import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.FutureTask;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
}
if (waitTotal > waitMax)
{
- jalview.bin.Console.errPrintln("Timed out waiting for Jmol to load files after "
- + waitTotal + "ms");
+ jalview.bin.Console.errPrintln(
+ "Timed out waiting for Jmol to load files after "
+ + waitTotal + "ms");
// jalview.bin.Console.errPrintln("finished: " + jmb.isFinishedInit()
// + "; loaded: " + Arrays.toString(jmb.getPdbFile())
// + "; files: " + files.toString());
@Override
public void makePDBImage(ImageMaker.TYPE type)
{
- try {
- makePDBImage(null, type, null,
- BitmapImageSizing.nullBitmapImageSizing());
- } catch (ImageOutputException ioex) {
- Console.error("Unexpected error whilst writing "+type.toString(),ioex);
+ try
+ {
+ makePDBImage(null, type, null,
+ BitmapImageSizing.defaultBitmapImageSizing());
+ } catch (ImageOutputException ioex)
+ {
+ Console.error("Unexpected error whilst writing " + type.toString(),
+ ioex);
}
}
BitmapImageSizing bis = ImageMaker.getScaleWidthHeight(width, height,
userBis);
- float usescale = bis.scale;
- int usewidth = bis.width;
- int useheight = bis.height;
+ float usescale = bis.scale();
+ int usewidth = bis.width();
+ int useheight = bis.height();
ImageWriterI writer = new ImageWriterI()
{
.toLowerCase(Locale.ROOT);
final ImageExporter exporter = new ImageExporter(writer,
getProgressIndicator(), type, getTitle());
-
+
final Throwable[] exceptions = new Throwable[1];
exceptions[0] = null;
final AppJmol us = this;
try
{
- Thread runner = Executors.defaultThreadFactory().newThread(new Runnable()
- {
- @Override
- public void run()
- {
- try
- {
- exporter.doExport(file, us, width, height, view, renderer,
- userBis);
- } catch (Throwable t)
- {
- exceptions[0] = t;
- }
- }
- });
+ Thread runner = Executors.defaultThreadFactory()
+ .newThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ exporter.doExport(file, us, width, height, view,
+ renderer, userBis);
+ } catch (Throwable t)
+ {
+ exceptions[0] = t;
+ }
+ }
+ });
runner.start();
- do { Thread.sleep(25); } while (runner.isAlive());
+ do
+ {
+ Thread.sleep(25);
+ } while (runner.isAlive());
} catch (Throwable e)
{
throw new ImageOutputException(
.openURL("http://wiki.jmol.org");// http://jmol.sourceforge.net/docs/JmolUserGuide/");
} catch (Exception ex)
{
- jalview.bin.Console.errPrintln("Show Jmol help failed with: " + ex.getMessage());
+ jalview.bin.Console
+ .errPrintln("Show Jmol help failed with: " + ex.getMessage());
}
}
String imageSource) throws ImageOutputException
{
doExport(file, parent, width, height, imageSource, null,
- BitmapImageSizing.nullBitmapImageSizing());
+ BitmapImageSizing.defaultBitmapImageSizing());
}
public void doExport(File file, Component parent, int width, int height,
BitmapImageSizing bis = ImageMaker.getScaleWidthHeight(width, height,
userBis);
- float usescale = bis.scale;
- int usewidth = bis.width;
- int useheight = bis.height;
+ float usescale = bis.scale();
+ int usewidth = bis.width();
+ int useheight = bis.height();
bi = new BufferedImage(usewidth, useheight, BufferedImage.TYPE_INT_RGB);
graphics = bi.getGraphics();
}
/**
- * Takes suggested float scale, int width, int height and create a bounding
- * box returned as a BitmapImageSizing object with consistent scale, width,
- * height fields.
+ * Takes initial width and height, and suggested float scale, int width, int
+ * height and create a bounding box returned as a BitmapImageSizing object
+ * with consistent scale, width, height fields.
*
+ * @param width
+ * The unscaled image width
+ * @param height
+ * The unscaled image height
* @param scale
+ * The suggested scaling
* @param bitmapwidth
+ * The suggested width
* @param bitmapheight
- * @return BitmapImageSizing
+ * The suggested height
+ * @return BitmapImageSizing A consistent scale,width and height for the final
+ * image
*/
public static BitmapImageSizing getScaleWidthHeight(int width, int height,
float scale, int bitmapwidth, int bitmapheight)
int usewidth = width;
int useheight = height;
+ if ((width == 0 && bitmapwidth > 0)
+ || (height == 0 && bitmapheight > 0))
+ {
+ // original image is zero sized! Avoid dividing by zero!
+ return BitmapImageSizing.nullBitmapImageSizing();
+ }
+
// use the smallest positive scale (i.e. fit in the box)
if (scale > 0.0f)
{
useheight = bitmapheight;
}
}
- return new BitmapImageSizing(usescale, usewidth, useheight);
+ return new BitmapImageSizing(usescale, usewidth, useheight, false);
}
/**
public static BitmapImageSizing getScaleWidthHeight(int width, int height,
BitmapImageSizing bis)
{
- return ImageMaker.getScaleWidthHeight(width, height, bis.scale,
- bis.width, bis.height);
+ return ImageMaker.getScaleWidthHeight(width, height, bis.scale(),
+ bis.width(), bis.height());
}
/**
public static BitmapImageSizing parseScaleWidthHeightStrings(
String scaleS, String widthS, String heightS)
{
+ if (scaleS == null && widthS == null && heightS == null)
+ {
+ // if all items are null (i.e. not provided) we use the dynamic
+ // preferences set BIS
+ return BitmapImageSizing.defaultBitmapImageSizing();
+ }
+
float scale = 0.0f;
int width = 0;
int height = 0;
}
}
- return new BitmapImageSizing(scale, width, height);
+ return new BitmapImageSizing(scale, width, height, false);
}
}
public class BitmapImageSizing
{
- public final float scale;
+ private final float scale;
- public final int width;
+ private final int width;
- public final int height;
+ private final int height;
- public BitmapImageSizing(float scale, int width, int height)
+ private boolean isDefault = false;
+
+ public BitmapImageSizing(float scale, int width, int height,
+ boolean isDefault)
{
this.scale = scale;
this.width = width;
this.height = height;
+ this.isDefault = isDefault;
}
public boolean isNull()
public static BitmapImageSizing nullBitmapImageSizing()
{
- return new BitmapImageSizing(0.0f, 0, 0);
+ return new BitmapImageSizing(0.0f, 0, 0, false);
}
public static final String BITMAP_SCALE = "BITMAP_SCALE";
*/
public static BitmapImageSizing defaultBitmapImageSizing()
{
+ return new BitmapImageSizing(0f, 0, 0, true);
+ }
+
+ private float defaultScale()
+ {
+ return Cache.getDefault(BITMAP_SCALE, 0f);
+ }
+
+ private int defaultWidth()
+ {
+ return Cache.getDefault(BITMAP_WIDTH, 0);
+ }
+
+ private int defaultHeight()
+ {
+ return Cache.getDefault(BITMAP_HEIGHT, 0);
+ }
+
+ public float scale()
+ {
+ return isDefault() ? defaultScale() : scale;
+ }
+
+ public int width()
+ {
+ return isDefault() ? defaultWidth() : width;
+ }
- return new BitmapImageSizing(Cache.getDefault(BITMAP_SCALE, 0) / 10f,
- Cache.getDefault(BITMAP_WIDTH, 0),
- Cache.getDefault(BITMAP_HEIGHT, 0));
+ public int height()
+ {
+ return isDefault() ? defaultHeight() : height;
+ }
+ public boolean isDefault()
+ {
+ return isDefault;
}
}
import jalview.bin.Cache;
-public class BitmapImageSizeTest {
- @Test(groups = {"Functional"})
- public void testCacheSettingsRecovery() {
+public class BitmapImageSizeTest
+{
+ @Test(groups = { "Functional" })
+ public void testCacheSettingsRecovery()
+ {
Cache.setPropsAreReadOnly(true);
Cache.loadProperties("test/jalview/bin/testProps.jvprops");
-
+
Cache.removeProperty(BitmapImageSizing.BITMAP_HEIGHT);
Cache.removeProperty(BitmapImageSizing.BITMAP_SCALE);
Cache.removeProperty(BitmapImageSizing.BITMAP_WIDTH);
-
+
BitmapImageSizing def = BitmapImageSizing.defaultBitmapImageSizing();
BitmapImageSizing zero = BitmapImageSizing.nullBitmapImageSizing();
- assertEquals(def.height, zero.height);
- assertEquals(def.width, zero.width);
- assertEquals(def.scale, zero.scale);
-
- Cache.setProperty(BitmapImageSizing.BITMAP_HEIGHT,"120");
- Cache.setProperty(BitmapImageSizing.BITMAP_SCALE,"240");
- Cache.setProperty(BitmapImageSizing.BITMAP_WIDTH,"360");
-
- def = BitmapImageSizing.defaultBitmapImageSizing();
-
- assertEquals(def.height, 120);
- assertEquals(def.width, 360);
- assertEquals(def.scale, 24f);
-
+ assertEquals(def.height(), zero.height());
+ assertEquals(def.width(), zero.width());
+ assertEquals(def.scale(), zero.scale());
+
+ Cache.setProperty(BitmapImageSizing.BITMAP_HEIGHT, "120");
+ Cache.setProperty(BitmapImageSizing.BITMAP_SCALE, "24");
+ Cache.setProperty(BitmapImageSizing.BITMAP_WIDTH, "360");
+
+ // default now updates dynamically
+ // def = BitmapImageSizing.defaultBitmapImageSizing();
+
+ assertEquals(def.height(), 120);
+ assertEquals(def.width(), 360);
+ assertEquals(def.scale(), 24f);
+
Cache.removeProperty(BitmapImageSizing.BITMAP_WIDTH);
-
- def = BitmapImageSizing.defaultBitmapImageSizing();
- assertEquals(def.height, 120);
- assertEquals(def.width, zero.width);
- assertEquals(def.scale, 24f);
+
+ // def = BitmapImageSizing.defaultBitmapImageSizing();
+ assertEquals(def.height(), 120);
+ assertEquals(def.width(), zero.width());
+ assertEquals(def.scale(), 24f);
}
}