use of java.awt.FontMetrics in project n2a by frothga.
the class ChangeAnnotation method apply.
public static void apply(List<String> path, String nameBefore, String nameAfter, String valueAfter, String blockName, NodeFactory factory) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeBase nodeBefore = parent.child(nameBefore);
if (nodeBefore == null)
throw new CannotRedoException();
PanelEquationTree pet = PanelModel.instance.panelEquations;
JTree tree = pet.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = nodeBefore.getFontMetrics(tree);
NodeBase nodeAfter;
if (nameBefore.equals(nameAfter)) {
nodeAfter = nodeBefore;
nodeAfter.source.set(valueAfter);
} else {
// Update database
MPart mparent;
if (parent instanceof NodeVariable)
mparent = (MPart) parent.source.child(blockName);
else
mparent = parent.source;
// should directly change destinationNode if it exists
MPart newPart = (MPart) mparent.set(nameAfter, valueAfter);
mparent.clear(nameBefore);
MPart oldPart = (MPart) mparent.child(nameBefore);
// Update GUI
nodeAfter = parent.child(nameAfter);
if (oldPart == null) {
if (nodeAfter == null) {
nodeAfter = nodeBefore;
nodeAfter.source = newPart;
} else {
model.removeNodeFromParent(nodeBefore);
}
} else {
if (nodeAfter == null) {
int index = parent.getIndex(nodeBefore);
nodeAfter = factory.create(newPart);
model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
}
}
}
nodeAfter.updateColumnWidths(fm);
parent.updateTabStops(fm);
parent.allNodesChanged(model);
TreeNode[] nodePath = nodeAfter.getPath();
pet.updateOrder(nodePath);
pet.updateVisibility(nodePath);
// Only an inherited lock node can be touched by editing. It is possible to activate (make local) if the user assigns a specific value to it.
if (path.size() == 2 && path.get(1).equals("$metadata") && (nameBefore.equals("lock") || nameAfter.equals("lock")))
pet.updateLock();
}
use of java.awt.FontMetrics in project n2a by frothga.
the class ChangeEquation method apply.
public static void apply(List<String> path, String nameBefore, String nameAfter, String combinerAfter, String valueAfter) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeBase nodeBefore = parent.child(nameBefore);
if (nodeBefore == null)
throw new CannotRedoException();
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = nodeBefore.getFontMetrics(tree);
NodeBase nodeAfter;
if (nameBefore.equals(nameAfter)) {
nodeAfter = nodeBefore;
nodeAfter.source.set(valueAfter);
} else {
// Update the database
MPart mparent = parent.source;
MPart newPart = (MPart) mparent.set(nameAfter, valueAfter);
mparent.clear(nameBefore);
MPart oldPart = (MPart) mparent.child(nameBefore);
// Update GUI
nodeAfter = parent.child(nameAfter);
if (oldPart == null) {
if (nodeAfter == null) {
nodeAfter = nodeBefore;
nodeAfter.source = newPart;
} else {
model.removeNodeFromParent(nodeBefore);
}
} else {
if (nodeAfter == null) {
int index = parent.getIndex(nodeBefore);
nodeAfter = new NodeEquation(newPart);
model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
}
if (nodeBefore.visible(model.filterLevel))
model.nodeChanged(nodeBefore);
else
parent.hide(nodeBefore, model, true);
}
}
if (parent.getChildCount() > 0) {
NodeBase firstChild = (NodeBase) parent.getChildAt(0);
if (firstChild.needsInitTabs())
firstChild.initTabs(fm);
}
if (!parent.source.get().equals(combinerAfter)) {
parent.source.set(combinerAfter);
parent.updateColumnWidths(fm);
NodeBase grandparent = (NodeBase) parent.getParent();
grandparent.updateTabStops(fm);
grandparent.allNodesChanged(model);
}
nodeAfter.updateColumnWidths(fm);
parent.updateTabStops(fm);
parent.allNodesChanged(model);
mep.panelEquations.updateVisibility(nodeAfter.getPath());
}
use of java.awt.FontMetrics in project n2a by frothga.
the class Move method apply.
public static void apply(List<String> path, int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
model.removeNodeFromParent(moveNode);
NodeBase metadataNode = parent.child("$metadata");
if (createOrder) {
if (metadataNode == null) {
metadataNode = new NodeAnnotations((MPart) parent.source.set("$metadata", ""));
model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
}
NodeBase orderNode = new NodeAnnotation((MPart) metadataNode.source.set("gui.order", ""));
model.insertNodeIntoUnfiltered(orderNode, metadataNode, metadataNode.getChildCount());
}
if (destroyOrder) {
NodeBase orderNode = metadataNode.child("gui.order");
FontMetrics fm = orderNode.getFontMetrics(tree);
metadataNode.source.clear("gui.order");
model.removeNodeFromParent(metadataNode.child("gui.order"));
if (metadataNode.getChildCount() == 0) {
parent.source.clear("$metadata");
model.removeNodeFromParent(metadataNode);
} else {
metadataNode.updateTabStops(fm);
metadataNode.allNodesChanged(model);
}
}
model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
TreeNode[] movePath = moveNode.getPath();
if (!destroyOrder)
mep.panelEquations.updateOrder(movePath);
mep.panelEquations.updateVisibility(movePath);
}
use of java.awt.FontMetrics in project vft-capture by videofirst.
the class DefaultDisplayService method drawText.
private void drawText(Graphics g) {
DisplayText displayText = displayUpdate.getText();
final Font font = getFont().deriveFont(displayText.getFontSize());
g.setFont(font);
g.setColor(displayText.getColor());
final String message = // FIXME improve
status != null ? ("Status : " + status.getState().toString()) : "";
FontMetrics metrics = g.getFontMetrics();
g.drawString(message, displayText.getX(), displayText.getY() + metrics.getHeight());
}
use of java.awt.FontMetrics in project cayenne by apache.
the class LineNumberedBorder method paintBorder.
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
java.awt.Rectangle clip = g.getClipBounds();
FontMetrics fm = g.getFontMetrics();
int fontHeight = fm.getHeight();
int ybaseline = y + fm.getAscent();
int startingLineNumber = (clip.y / fontHeight) + 1;
if (ybaseline < clip.y) {
ybaseline = y + startingLineNumber * fontHeight - (fontHeight - fm.getAscent());
}
int yend = ybaseline + height;
if (yend > (y + height)) {
yend = y + height;
}
int lnxstart = x;
int widhtBorder = getLineNumberWidth() - 2;
g.setColor(new Color(255, 255, 224));
g.fillRect(lnxstart, 0, lnxstart + widhtBorder, yend);
g.setColor(new Color(214, 214, 214));
g.drawRect(lnxstart - 1, -1, lnxstart + widhtBorder, yend + 1);
int end = pane.getEndPositionInDocument();
Document doc = pane.getDocument();
int endline = doc.getDefaultRootElement().getElementIndex(end) + 1;
while (startingLineNumber <= endline) {
g.setColor(Color.gray);
g.drawString(startingLineNumber + " ", lnxstart + 1, ybaseline);
ybaseline += fontHeight;
startingLineNumber++;
}
setEtalon(startingLineNumber - 1);
}
Aggregations