* Will be used to avoid sovrapposition of nodes on the graph before placement.
* @param className name of the *Cell that will be instantiated
* @return predicted dimensions of Node
*/
public Dimension predictCellSize(String className) {
JmodelStationDefinition sd = mediator.getStationDefinition();
String path = "jmt.gui.jmodel.JGraphMod.";
ImageIcon icon = null;
// Using reflection to access to public ICON field on given class
try {
String iconName = (String) (Class.forName(path + className)).getField("ICON").get(null);
icon = JMTImageLoader.loadImage(iconName);
} catch (IllegalAccessException e) {
System.out.println("Error: A security manager has blocked reflection...");
e.printStackTrace();
return null;
} catch (NoSuchFieldException e) {
System.out.println("Error: Field 'ICON' was not found in '" + className + "'. This is needed for reflection.");
e.printStackTrace();
return null;
} catch (ClassNotFoundException e) {
System.out.println("Error: Trying to get size fron a Cell class that does not exist");
e.printStackTrace();
return null;
}
String name = sd.previewStationName(getComponentType(className));
Dimension cellDimension = new Dimension(icon.getIconWidth(), icon.getIconHeight());
// Gets the graph font
Font font = mediator.getGraph().getFont();
// Gets the graphical context