use of java.awt.FontMetrics in project vcell by virtualcell.
the class TextImage method refreshImage.
/**
* This method was created by a SmartGuide.
* @param g java.awt.Graphics
*/
private void refreshImage(Component component) {
if (image != null) {
return;
}
FontMetrics fontMetrics = component.getFontMetrics(font);
int strWidth = fontMetrics.stringWidth(text);
int strHeight = fontMetrics.getHeight();
int strAscent = fontMetrics.getMaxAscent();
width = strWidth + 4;
height = strHeight + 4;
image = component.createImage(width, height);
if (image == null) {
throw new RuntimeException("error creating horizontal image");
}
java.awt.Graphics g = image.getGraphics();
// g.setPaintMode();
g.setClip(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
g.setColor(Color.black);
int posY = 2 + strAscent;
int posX = 2;
g.setFont(font);
g.drawString(text, posX, posY);
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class ImagePlaneManagerPanel method updateInfo.
private void updateInfo(MouseEvent mouseEvent) {
if (mouseEvent == null) {
return;
}
String infoS = null;
// }else
if (mouseEvent.getID() != java.awt.event.MouseEvent.MOUSE_EXITED) {
Coordinate wc = null;
boolean bNeedsMembraneCursor = false;
if (getCurveEditorTool().getTool() == CurveEditorTool.TOOL_ZOOM || getCurveEditorTool().getTool() == CurveEditorTool.TOOL_PAN) {
infoS = getCurveEditorTool().getToolDescription(getCurveEditorTool().getTool());
setToolCursor();
} else if (mouseEvent.getID() != java.awt.event.MouseEvent.MOUSE_ENTERED) {
lastValidMouseEvent = mouseEvent;
if (getimagePaneView1().isPointOnImage(mouseEvent.getPoint())) {
java.awt.geom.Point2D unitP = getimagePaneView1().getImagePointUnitized(mouseEvent.getPoint());
wc = getImagePlaneManager().getWorldCoordinateFromUnitized2D(unitP.getX(), unitP.getY());
if (wc != null) {
if (getCurveValueProvider() != null) {
if (getSourceDataInfo() != null && getSourceDataInfo().isChombo()) {
// for chombo, can't use closest curve method, one irregular point has one curve, it can be very far
CoordinateIndex ci = getImagePlaneManager().getDataIndexFromUnitized2D(unitP.getX(), unitP.getY());
CurveSelectionInfo csiSegment = getCurveValueProvider().findChomboCurveSelectionInfoForPoint(ci);
if (csiSegment != null) {
String infoTemp = getCurveValueProvider().getCurveValue(csiSegment);
if (infoTemp != null) {
infoS = infoTemp;
bNeedsMembraneCursor = true;
}
}
} else {
CurveSelectionInfo[] curveCSIArr = getCurveRenderer().getCloseCurveSelectionInfos(wc);
if (curveCSIArr != null) {
for (int i = 0; i < curveCSIArr.length; i += 1) {
CurveSelectionInfo csiSegment = getCurveRenderer().getClosestSegmentSelectionInfo(wc, curveCSIArr[i].getCurve());
if (csiSegment != null) {
String infoTemp = getCurveValueProvider().getCurveValue(csiSegment);
if (infoTemp != null) {
infoS = infoTemp;
bNeedsMembraneCursor = true;
break;
}
}
}
}
}
}
if (infoS == null && getSourceDataInfo() != null) {
CoordinateIndex ci = getImagePlaneManager().getDataIndexFromUnitized2D(unitP.getX(), unitP.getY());
int volumeIndex = getSourceDataInfo().calculateWorldIndex(ci);
Coordinate quantizedWC = getSourceDataInfo().getWorldCoordinateFromIndex(ci);
boolean bUndefined = getSourceDataInfo().isDataNull() || (getDataInfoProvider() != null && !getDataInfoProvider().isDefined(volumeIndex));
String xCoordString = NumberUtils.formatNumber(quantizedWC.getX());
String yCoordString = NumberUtils.formatNumber(quantizedWC.getY());
String zCoordString = NumberUtils.formatNumber(quantizedWC.getZ());
infoS = "(" + xCoordString + (getSourceDataInfo().getYSize() > 1 ? "," + yCoordString : "") + (getSourceDataInfo().getZSize() > 1 ? "," + zCoordString : "") + ") " + "[" + volumeIndex + "]" + " [" + ci.x + (getSourceDataInfo().getYSize() > 1 ? "," + ci.y : "") + (getSourceDataInfo().getZSize() > 1 ? "," + ci.z : "") + "] " + (bUndefined ? "Undefined" : getSourceDataInfo().getDataValueAsString(ci.x, ci.y, ci.z));
if (getDataInfoProvider() != null) {
if (getDataInfoProvider().getPDEDataContext().getCartesianMesh().isChomboMesh()) {
if (!bUndefined) {
StructureMetricsEntry structure = ((CartesianMeshChombo) getDataInfoProvider().getPDEDataContext().getCartesianMesh()).getStructureInfo(getDataInfoProvider().getPDEDataContext().getDataIdentifier());
if (structure != null) {
infoS += " || " + structure.getDisplayLabel();
}
}
} else if (getDataInfoProvider() != null) {
infoS += " ";
try {
VolumeDataInfo volumeDataInfo = getDataInfoProvider().getVolumeDataInfo(volumeIndex);
if (volumeDataInfo.subvolumeID0 != null) {
infoS += " \"" + volumeDataInfo.volumeNamePhysiology + "\"" + " (\"" + volumeDataInfo.volumeNameGeometry + "\")";
infoS += " svID=" + volumeDataInfo.subvolumeID0;
infoS += " vrID=" + volumeDataInfo.volumeRegionID;
}
} catch (Exception e) {
// This can happen with FieldData viewer
e.printStackTrace();
}
}
}
String curveDescr = CurveRenderer.getROIDescriptions(wc, getCurveRenderer());
if (curveDescr != null) {
infoS += " " + curveDescr;
}
}
if (infoS == null) {
infoS = "Unknown";
}
}
}
if (bNeedsMembraneCursor) {
getimagePaneView1().setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
} else {
getimagePaneView1().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
setToolCursor();
}
} else {
lastValidMouseEvent = null;
}
} else {
lastValidMouseEvent = null;
}
// if(mouseEvent.getID() == java.awt.event.MouseEvent.MOUSE_DRAGGED ||
// mouseEvent.getID() == java.awt.event.MouseEvent.MOUSE_PRESSED ||
// mouseEvent.getID() == java.awt.event.MouseEvent.MOUSE_EXITED ||
// mouseEvent.getID() == java.awt.event.MouseEvent.MOUSE_ENTERED){
// getInfoJlabel().setText((infoS == null?defaultInfoString:infoS));
// }
getimagePaneView1().setToolTipText(infoS == null ? defaultInfoString : infoS);
// make sure the vertical space for the infoText is sufficient to avoid resizing
FontMetrics fontMetrics = getInfoJlabel().getGraphics().getFontMetrics();
getInfoJlabel().setMinimumSize(new Dimension(50, (fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent() + 1)));
getInfoJlabel().setText((infoS == null ? defaultInfoString : infoS));
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class Node method paint.
public void paint(Graphics g) {
int x = _bb.projection.projectX(_x, _y, _z);
int y = _bb.projection.projectY(_x, _y, _z);
if (dummy()) {
// g.setColor(Color.blue);
// g.fillOval( x-dummySize/2, y-dummySize/2, dummySize, dummySize );
_boundingHeight = dummySize;
_boundingWidth = dummySize;
} else {
g.setColor(((_picked) ? selectColor : (_fixed ? fixedColor : nodeColor)));
int depdelta = (int) (10 * _bb.projection.projectZ(_x, _y, _z) / _bb.globals.L());
FontMetrics fm = g.getFontMetrics();
int w = _boundingWidth = fm.stringWidth(_label) + xmarginSize + depdelta;
int h = _boundingHeight = fm.getHeight() + ymarginSize + depdelta;
g.fillRect(x - w / 2, y - h / 2, w, h);
g.setColor(Color.black);
g.drawRect(x - w / 2, y - h / 2, w - 1, h - 1);
if (_center) {
g.drawRect(x - w / 2 - 1, y - h / 2 - 1, w + 1, h + 1);
g.drawRect(x - w / 2 - 2, y - h / 2 - 2, w + 3, h + 3);
g.drawRect(x - w / 2 - 3, y - h / 2 - 3, w + 5, h + 5);
}
g.drawString(_label, x - (w - xmarginSize) / 2, y - (h - ymarginSize) / 2 + fm.getAscent());
}
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class ReactionRuleDiagramShape method getPreferedSizeSelf.
@Override
public Dimension getPreferedSizeSelf(Graphics2D g) {
getSpaceManager().setSizePreferred(width, height);
if (getLabel() != null && getLabel().length() > 0) {
FontMetrics fontMetrics = g.getFontMetrics();
setLabelSize(fontMetrics.stringWidth(getLabel()), fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent());
}
return getSpaceManager().getSizePreferred();
}
use of java.awt.FontMetrics in project vcell by virtualcell.
the class ReactionRuleShortDiagramShape method getPreferedSizeSelf.
@Override
public Dimension getPreferedSizeSelf(Graphics2D g) {
getSpaceManager().setSizePreferred(width, height);
if (getLabel() != null && getLabel().length() > 0) {
FontMetrics fontMetrics = g.getFontMetrics();
setLabelSize(fontMetrics.stringWidth(getLabel()), fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent());
}
return getSpaceManager().getSizePreferred();
}
Aggregations