|
Java example source code file (Figure.java)
The Figure.java Java example source code/* * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ package com.sun.hotspot.igv.graph; import com.sun.hotspot.igv.layout.Cluster; import com.sun.hotspot.igv.layout.Vertex; import com.sun.hotspot.igv.data.Properties; import java.awt.Color; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Point; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; /** * * @author Thomas Wuerthinger */ public class Figure extends Properties.Entity implements Source.Provider, Vertex { public static final int INSET = 6; public static final int SLOT_WIDTH = 10; public static final int SLOT_START = 3; public static final boolean VERTICAL_LAYOUT = true; protected List<InputSlot> inputSlots; protected List<OutputSlot> outputSlots; private Source source; private Diagram diagram; private Point position; private List<Figure> predecessors; private List<Figure> successors; private Color color; private int id; private String idString; private String[] lines; private int heightCash = -1; private int widthCash = -1; public int getHeight() { if (heightCash == -1) { BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setFont(diagram.getFont()); FontMetrics metrics = g.getFontMetrics(); String nodeText = diagram.getNodeText(); heightCash = nodeText.split("\n").length * metrics.getHeight() + INSET; } return heightCash; } public int getWidth() { if (widthCash == -1) { int max = 0; BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setFont(diagram.getFont()); FontMetrics metrics = g.getFontMetrics(); for (String s : lines) { int cur = metrics.stringWidth(s); if (cur > max) { max = cur; } } widthCash = max + INSET; } return widthCash; } protected Figure(Diagram diagram, int id) { this.diagram = diagram; this.source = new Source(); inputSlots = new ArrayList<InputSlot>(5); outputSlots = new ArrayList<OutputSlot>(1); predecessors = new ArrayList<Figure>(6); successors = new ArrayList<Figure>(6); this.id = id; idString = Integer.toString(id); this.position = new Point(0, 0); this.color = Color.WHITE; } public int getId() { return id; } public void setColor(Color color) { this.color = color; } public Color getColor() { return color; } public List<Figure> getPredecessors() { return Collections.unmodifiableList(predecessors); } public Set<Figure> getPredecessorSet() { Set<Figure> result = new HashSet Other Java examples (source code examples)Here is a short list of links related to this Java Figure.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.