I have decided searching is pointless, there is no Dialog outside Java.
Being however in need as I am, I have decided to try and write a Java program, which would do what I want which is:
* take 2 arguments in cmd line - label text and label name (label, labelName)
* create an image with black background and white text in Dialog size 11 saying exactly what was given in label text parameter
* save an image as labelName.png
So far this is what I was able to produce:
public class Main {
/**
* Installation folder
*/
static String pmDir = "/home/dreen/Makra/patmaker/";
/**
* PATs folder
*/
static String patDir = "/home/dreen/Makra/";//matchItems/";
/**
* Font size
*/
static int fSize = 11;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// there have to be 2 arguments: label text, label name.
if (args.length < 2)
{
System.out.println("Too few arguments (2 required).");
System.exit(-1);
}
String label = args[0];
String labelName = args[1];
int imgH = fSize;
int imgW = label.length() * 10; // how to get text size before initializing the image btw?
// setup the image
BufferedImage image = new BufferedImage(imgW, imgH, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = image.createGraphics();
g2d.setColor(Color.BLACK);
g2d.drawRect(0,0,imgH,imgW);
g2d.setColor(Color.WHITE);
Font f = new Font("Dialog", Font.PLAIN, fSize);
g2d.setFont(f);
g2d.drawString(label, 0, 0);
g2d.dispose();
// save the image
File file = new File(patDir + labelName + ".png");
try
{
ImageIO.write(image,"png",file);
}
catch(IOException e)
{
handleException(e);
}
}
/**
* Handle errors
*/
public static void handleException (Exception e)
{
try
{
BufferedWriter errorLog = new BufferedWriter(new FileWriter(pmDir + "error.log"));
errorLog.write("Afollowing error occured:\n\n");
errorLog.write ("====== Exception " + e.getMessage() + " ======");
errorLog.write(e.getStackTrace().toString());
System.err.println("An error occured, log file saved.");
System.exit(-1);
} catch(IOException ioe)
{
System.err.println("IOException");
System.exit(-1);
}
}
}
This is a complete program for that purpose, which should work, but it doesn't. Can you please help me and tell me why?