本文整理汇总了Java中prefuse.util.FontLib类的典型用法代码示例。如果您正苦于以下问题:Java FontLib类的具体用法?Java FontLib怎么用?Java FontLib使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FontLib类属于prefuse.util包,在下文中一共展示了FontLib类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeTextDimensions
import prefuse.util.FontLib; //导入依赖的package包/类
private String computeTextDimensions(
VisualItem item, String text,
double size )
{
// put item font in temp member variable
m_font = item.getFont();
// scale the font as needed
if ( size != 1 ) {
m_font = FontLib.getFont(
m_font.getName(), m_font.getStyle(),
size * m_font.getSize()
);
}
FontMetrics fm = DEFAULT_GRAPHICS.getFontMetrics( m_font );
StringBuffer str = null;
// compute the number of lines and the maximum width
int nlines = 1, w = 0, start = 0, end = text.indexOf( m_delim );
m_textDim.width = 0;
String line;
for ( ; end >= 0; ++nlines ) {
w = fm.stringWidth( line = text.substring( start, end ) );
// abbreviate line as needed
if ( m_maxTextWidth > -1 && w > m_maxTextWidth ) {
if ( str == null )
str = new StringBuffer( text.substring( 0, start ) );
str.append( StringLib.abbreviate( line, fm, m_maxTextWidth ) );
str.append( m_delim );
w = m_maxTextWidth;
}
else if ( str != null ) {
str.append( line ).append( m_delim );
}
// update maximum width and substring indices
m_textDim.width = Math.max( m_textDim.width, w );
start = end + 1;
end = text.indexOf( m_delim, start );
}
w = fm.stringWidth( line = text.substring( start ) );
// abbreviate line as needed
if ( m_maxTextWidth > -1 && w > m_maxTextWidth ) {
if ( str == null )
str = new StringBuffer( text.substring( 0, start ) );
str.append( StringLib.abbreviate( line, fm, m_maxTextWidth ) );
w = m_maxTextWidth;
}
else if ( str != null ) {
str.append( line );
}
// update maximum width
m_textDim.width = Math.max( m_textDim.width, w );
// compute the text height
m_textDim.height = fm.getHeight() * nlines;
return str == null ? text : str.toString();
}
示例2: computeTextDimensions
import prefuse.util.FontLib; //导入依赖的package包/类
private String computeTextDimensions(VisualItem item, String text,
double size)
{
// put item font in temp member variable
m_font = item.getFont();
// scale the font as needed
if ( size != 1 ) {
m_font = FontLib.getFont(m_font.getName(), m_font.getStyle(),
size*m_font.getSize());
}
m_font2 = FontLib.getFont(m_font.getName(), m_font.getStyle(),
size*m_font.getSize() * 0.8);
m_font_nic = FontLib.getFont(m_font.getName(), m_font.getStyle() | Font.ITALIC,
size*m_font.getSize());
FontMetrics fm = DEFAULT_GRAPHICS.getFontMetrics(m_font);
FontMetrics fm2 = DEFAULT_GRAPHICS.getFontMetrics(m_font2);
StringBuffer str = null;
// compute the number of lines and the maximum width
int nlines = 1, w = 0, start = 0, end = text.indexOf(m_delim);
if (text.endsWith("\n")) {
--nlines;
}
m_textDim.width = 0;
m_headerDim.width = 0;
String line;
boolean f = true;
for ( ; end >= 0; ++nlines ) {
w = (f? fm : fm2).stringWidth(line=text.substring(start,end));
f = false;
// abbreviate line as needed
if ( m_maxTextWidth > -1 && w > m_maxTextWidth ) {
if ( str == null )
str = new StringBuffer(text.substring(0,start));
str.append(StringLib.abbreviate(line, fm, m_maxTextWidth));
str.append(m_delim);
w = m_maxTextWidth;
} else if ( str != null ) {
str.append(line).append(m_delim);
}
// update maximum width and substring indices
m_textDim.width = Math.max(m_textDim.width, w);
start = end+1;
end = text.indexOf(m_delim, start);
}
w = (f? fm : fm2).stringWidth(line=text.substring(start));
// abbreviate line as needed
if ( m_maxTextWidth > -1 && w > m_maxTextWidth ) {
if ( str == null )
str = new StringBuffer(text.substring(0,start));
str.append(StringLib.abbreviate(line, fm, m_maxTextWidth));
w = m_maxTextWidth;
} else if ( str != null ) {
str.append(line);
}
// update maximum width
m_textDim.width = Math.max(m_textDim.width, w);
// compute the text height
m_textDim.height = fm.getHeight() + fm2.getHeight() * (nlines - 1);
m_headerDim.width = m_textDim.width;
m_headerDim.height = fm.getHeight();
return str==null ? text : str.toString();
}
示例3: AggregateDecoratorDemo
import prefuse.util.FontLib; //导入依赖的package包/类
public AggregateDecoratorDemo() {
// initialize display and data
super(new Visualization());
initDataGroups();
// set up the renderers
// draw the nodes as basic shapes
Renderer nodeR = new ShapeRenderer(20);
// draw aggregates as polygons with curved edges
Renderer polyR = new PolygonRenderer(Constants.POLY_TYPE_CURVE);
((PolygonRenderer)polyR).setCurveSlack(0.15f);
DefaultRendererFactory drf = new DefaultRendererFactory();
drf.setDefaultRenderer(nodeR);
drf.add("ingroup('aggregates')", polyR);
drf.add(new InGroupPredicate(EDGE_DECORATORS), new LabelRenderer(VisualItem.LABEL));
drf.add(new InGroupPredicate(NODE_DECORATORS), new LabelRenderer(VisualItem.LABEL));
drf.add(new InGroupPredicate(AGGR_DECORATORS), new LabelRenderer("id"));
m_vis.setRendererFactory(drf);
// adding decorators, one group for the nodes, one for the edges and one
// for the aggregates
DECORATOR_SCHEMA.setDefault(VisualItem.TEXTCOLOR, ColorLib.gray(0));
m_vis.addDecorators(EDGE_DECORATORS, EDGES, DECORATOR_SCHEMA);
DECORATOR_SCHEMA.setDefault(VisualItem.TEXTCOLOR, ColorLib.gray(128));
m_vis.addDecorators(NODE_DECORATORS, NODES, DECORATOR_SCHEMA);
// the HoverPredicate makes this group of decorators to appear only on mouseOver
DECORATOR_SCHEMA.setDefault(VisualItem.TEXTCOLOR, ColorLib.gray(255, 128));
DECORATOR_SCHEMA.setDefault(VisualItem.FONT, FontLib.getFont("Tahoma", Font.BOLD, 48));
m_vis.addDecorators(AGGR_DECORATORS, AGGR, new HoverPredicate(), DECORATOR_SCHEMA);
// set up the visual operators
// first set up all the color actions
ColorAction nStroke = new ColorAction(NODES, VisualItem.STROKECOLOR);
nStroke.setDefaultColor(ColorLib.gray(100));
nStroke.add("_hover", ColorLib.gray(50));
ColorAction nFill = new ColorAction(NODES, VisualItem.FILLCOLOR);
nFill.setDefaultColor(ColorLib.gray(255));
nFill.add("_hover", ColorLib.gray(200));
ColorAction nEdges = new ColorAction(EDGES, VisualItem.STROKECOLOR);
nEdges.setDefaultColor(ColorLib.gray(100));
ColorAction aStroke = new ColorAction(AGGR, VisualItem.STROKECOLOR);
aStroke.setDefaultColor(ColorLib.gray(200));
aStroke.add("_hover", ColorLib.rgb(255,100,100));
int[] palette = new int[] {
ColorLib.rgba(255,200,200,150),
ColorLib.rgba(200,255,200,150),
ColorLib.rgba(200,200,255,150)
};
ColorAction aFill = new DataColorAction(AGGR, "id",
Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
// bundle the color actions
ActionList colors = new ActionList();
colors.add(nStroke);
colors.add(nFill);
colors.add(nEdges);
colors.add(aStroke);
colors.add(aFill);
// now create the main layout routine
ActionList layout = new ActionList(Activity.INFINITY);
layout.add(colors);
layout.add(new ForceDirectedLayout(GRAPH, true));
layout.add(new AggregateLayout2(AGGR));
layout.add(new LabelLayout2(EDGE_DECORATORS));
layout.add(new LabelLayout2(NODE_DECORATORS));
layout.add(new LabelLayout2(AGGR_DECORATORS));
layout.add(new RepaintAction());
m_vis.putAction("layout", layout);
// set up the display
setSize(500,500);
pan(250, 250);
setHighQuality(true);
addControlListener(new AggregateDragControl2());
addControlListener(new ZoomControl());
addControlListener(new PanControl());
// set things running
m_vis.run("layout");
}
示例4: computeTextDimensions
import prefuse.util.FontLib; //导入依赖的package包/类
private String computeTextDimensions(VisualItem item, String text,
double size)
{
// put item font in temp member variable
m_font = item.getFont();
// scale the font as needed
if ( size != 1 ) {
m_font = FontLib.getFont(m_font.getName(), m_font.getStyle(),
size*m_font.getSize());
}
AwtFontMetrics fm = new AwtFontMetrics(m_font);
StringBuffer str = null;
// compute the number of lines and the maximum width
int nlines = 1, w = 0, start = 0, end = text.indexOf(m_delim);
m_textDim.width = 0;
String line;
for ( ; end >= 0; ++nlines ) {
w = fm.stringWidth(line=text.substring(start,end));
// abbreviate line as needed
if ( m_maxTextWidth > -1 && w > m_maxTextWidth ) {
if ( str == null )
str = new StringBuffer(text.substring(0,start));
str.append(StringLib.abbreviate(line, fm, m_maxTextWidth));
str.append(m_delim);
w = m_maxTextWidth;
} else if ( str != null ) {
str.append(line).append(m_delim);
}
// update maximum width and substring indices
m_textDim.width = Math.max(m_textDim.width, w);
start = end+1;
end = text.indexOf(m_delim, start);
}
w = fm.stringWidth(line=text.substring(start));
// abbreviate line as needed
if ( m_maxTextWidth > -1 && w > m_maxTextWidth ) {
if ( str == null )
str = new StringBuffer(text.substring(0,start));
str.append(StringLib.abbreviate(line, fm, m_maxTextWidth));
w = m_maxTextWidth;
} else if ( str != null ) {
str.append(line);
}
// update maximum width
m_textDim.width = Math.max(m_textDim.width, w);
// compute the text height
m_textDim.height = fm.getHeight() * nlines;
return str==null ? text : str.toString();
}
示例5: process
import prefuse.util.FontLib; //导入依赖的package包/类
/**
* @see prefuse.action.ItemAction#process(prefuse.visual.VisualItem, double)
*/
public void process(VisualItem item, double frac) {
Font f1 = item.getStartFont(), f2 = item.getEndFont();
item.setFont(FontLib.getIntermediateFont(f1,f2,frac));
}
示例6: AggregateDecoratorDemo
import prefuse.util.FontLib; //导入依赖的package包/类
public AggregateDecoratorDemo() {
// initialize display and data
super(new Visualization());
initDataGroups();
// set up the renderers
// draw the nodes as basic shapes
Renderer nodeR = new ShapeRenderer(20);
// draw aggregates as polygons with curved edges
Renderer polyR = new PolygonRenderer(Constants.POLY_TYPE_CURVE);
((PolygonRenderer)polyR).setCurveSlack(0.15f);
DefaultRendererFactory drf = new DefaultRendererFactory();
drf.setDefaultRenderer(nodeR);
drf.add("ingroup('aggregates')", polyR);
drf.add(new InGroupPredicate(EDGE_DECORATORS), new LabelRenderer(VisualItem.LABEL));
drf.add(new InGroupPredicate(NODE_DECORATORS), new LabelRenderer(VisualItem.LABEL));
drf.add(new InGroupPredicate(AGGR_DECORATORS), new LabelRenderer("id"));
m_vis.setRendererFactory(drf);
// adding decorators, one group for the nodes, one for the edges and one
// for the aggregates
DECORATOR_SCHEMA.setDefault(VisualItem.TEXTCOLOR, ColorLib.gray(0));
m_vis.addDecorators(EDGE_DECORATORS, EDGES, DECORATOR_SCHEMA);
DECORATOR_SCHEMA.setDefault(VisualItem.TEXTCOLOR, ColorLib.gray(128));
m_vis.addDecorators(NODE_DECORATORS, NODES, DECORATOR_SCHEMA);
// the HoverPredicate makes this group of decorators to appear only on mouseOver
DECORATOR_SCHEMA.setDefault(VisualItem.TEXTCOLOR, ColorLib.gray(255, 128));
DECORATOR_SCHEMA.setDefault(VisualItem.FONT, FontLib.getFont("Tahoma", Font.BOLD, 48));
m_vis.addDecorators(AGGR_DECORATORS, AGGR, new HoverPredicate(), DECORATOR_SCHEMA);
// set up the visual operators
// first set up all the color actions
ColorAction nStroke = new ColorAction(NODES, VisualItem.STROKECOLOR);
nStroke.setDefaultColor(ColorLib.gray(100));
nStroke.add("_hover", ColorLib.gray(50));
ColorAction nFill = new ColorAction(NODES, VisualItem.FILLCOLOR);
nFill.setDefaultColor(ColorLib.gray(255));
nFill.add("_hover", ColorLib.gray(200));
ColorAction nEdges = new ColorAction(EDGES, VisualItem.STROKECOLOR);
nEdges.setDefaultColor(ColorLib.gray(100));
ColorAction aStroke = new ColorAction(AGGR, VisualItem.STROKECOLOR);
aStroke.setDefaultColor(ColorLib.gray(200));
aStroke.add("_hover", ColorLib.rgb(255,100,100));
int[] palette = new int[] {
ColorLib.rgba(255,200,200,150),
ColorLib.rgba(200,255,200,150),
ColorLib.rgba(200,200,255,150)
};
ColorAction aFill = new DataColorAction(AGGR, "id",
Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
// bundle the color actions
ActionList colors = new ActionList();
colors.add(nStroke);
colors.add(nFill);
colors.add(nEdges);
colors.add(aStroke);
colors.add(aFill);
// now create the main layout routine
ActionList layout = new ActionList(Activity.INFINITY);
layout.add(colors);
layout.add(new ForceDirectedLayout(GRAPH, true));
layout.add(new AggregateLayout(AGGR));
layout.add(new LabelLayout2(EDGE_DECORATORS));
layout.add(new LabelLayout2(NODE_DECORATORS));
layout.add(new LabelLayout2(AGGR_DECORATORS));
layout.add(new RepaintAction());
m_vis.putAction("layout", layout);
// set up the display
setSize(500,500);
pan(250, 250);
setHighQuality(true);
addControlListener(new AggregateDragControl());
addControlListener(new ZoomControl());
addControlListener(new PanControl());
// set things running
m_vis.run("layout");
}
示例7: getFont
import prefuse.util.FontLib; //导入依赖的package包/类
@Override
public Font getFont(VisualItem item) {
return FontLib.getFont(this.name, item.getDouble(fontSizeFieldName));
}
示例8: addGraph
import prefuse.util.FontLib; //导入依赖的package包/类
/**
* Adds a Graph, refreshes search items and removes aggregates.
*
* @param graph
*/
protected void addGraph(Graph graph){
if(graph == null) return;
// stop visualization
m_vis.cancel(Actions.DRAW.name()).setEnabled(false);
m_vis.cancel(Actions.AGGR.name()).setEnabled(false);
// wait till layout calculations finished.
while(m_aggregateLayout.runs);
// remove all rows
m_aTable.clear();
// remove old groups
m_vis.removeGroup(AGGR_DECORATORS);
m_vis.removeGroup(Visualization.SEARCH_ITEMS);
m_vis.removeGroup(GRAPH);
// add new graph
VisualGraph vg = m_vis.addGraph(GRAPH, graph);
// set focus group
VisualItem f = (VisualItem)vg.getNode(0);
m_vis.getGroup(Visualization.FOCUS_ITEMS).setTuple(f);
//f.setFixed(true);
m_vis.setValue(EDGES, null, VisualItem.INTERACTIVE, Boolean.FALSE);
// refresh search group
SearchTupleSet searchTup = new KeywordSearchTupleSet();
m_vis.addFocusGroup(Visualization.SEARCH_ITEMS, searchTup);
searchTup.addTupleSetListener(new TupleSetListener() {
@Override
public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
m_vis.run(Actions.DRAW.name() );
}
});
//
SearchQueryBinding sq = new SearchQueryBinding( vg.getNodeTable(), NODE_NAME,
(SearchTupleSet)m_vis.getGroup(Visualization.SEARCH_ITEMS));
// refresh search gui
search = sq.createSearchPanel();
search.setShowResultCount(true);
search.setBorder(BorderFactory.createEmptyBorder(5,5,4,0));
search.setFont(FontLib.getFont("Tahoma", Font.PLAIN, 11));
// refresh box
m_searchBox.removeAll();
m_searchBox.add(Box.createHorizontalStrut(10));
m_searchBox.add(m_searchLabel);
m_searchBox.add(Box.createHorizontalGlue());
m_searchBox.add(search);
m_searchBox.add(Box.createHorizontalStrut(3));
// run
m_vis.run(Actions.DRAW.name()).setEnabled(true);
m_vis.run(Actions.DRAW.name());
//
revalidate();
repaint();
}