📄 display.java
字号:
* so is disabled by default.
* @param on true to enable anti-aliased rendering, false to disable it
*/
public void setHighQuality(boolean on) {
if ( m_highQuality != on )
damageReport();
m_highQuality = on;
}
/**
* Indicates if the Display is using high quality (return value true) or
* regular quality (return value false) rendering.
* @return true if high quality rendering is enabled, false otherwise
*/
public boolean isHighQuality() {
return m_highQuality;
}
/**
* Returns the Visualization backing this Display.
* @return this Display's {@link Visualization}
*/
public Visualization getVisualization() {
return m_vis;
}
/**
* Set the Visualiztion associated with this Display. This Display
* will render the items contained in the provided visualization. If this
* Display is already associated with a different Visualization, the
* Display unregisters itself with the previous one.
* @param vis the backing {@link Visualization} to use.
*/
public void setVisualization(Visualization vis) {
// TODO: synchronization?
if ( m_vis == vis ) {
// nothing need be done
return;
} else if ( m_vis != null ) {
// remove this display from it's previous registry
m_vis.removeDisplay(this);
}
m_vis = vis;
if ( m_vis != null )
m_vis.addDisplay(this);
}
/**
* Returns the filtering Predicate used to control what items are drawn
* by this display.
* @return the filtering {@link prefuse.data.expression.Predicate}
*/
public Predicate getPredicate() {
if ( m_predicate.size() == 1 ) {
return BooleanLiteral.TRUE;
} else {
return m_predicate.get(0);
}
}
/**
* Sets the filtering Predicate used to control what items are drawn by
* this Display.
* @param expr the filtering predicate to use. The predicate string will be
* parsed by the {@link prefuse.data.expression.parser.ExpressionParser}.
* If the parse fails or does not result in a
* {@link prefuse.data.expression.Predicate} instance, an exception will
* be thrown.
*/
public void setPredicate(String expr) {
Predicate p = (Predicate)ExpressionParser.parse(expr, true);
setPredicate(p);
}
/**
* Sets the filtering Predicate used to control what items are drawn by
* this Display.
* @param p the filtering {@link prefuse.data.expression.Predicate} to use
*/
public synchronized void setPredicate(Predicate p) {
if ( p == null ) {
m_predicate.set(VisiblePredicate.TRUE);
} else {
m_predicate.set(new Predicate[] {p, VisiblePredicate.TRUE});
}
}
/**
* Returns the number of visible items processed by this Display. This
* includes items not currently visible on screen due to the current
* panning or zooming state.
* @return the count of visible items
*/
public int getVisibleItemCount() {
return m_visibleCount;
}
/**
* Get the ItemSorter that determines the rendering order of the
* VisualItems. Items are drawn in ascending order of the scores provided
* by the ItemSorter.
* @return this Display's {@link prefuse.visual.sort.ItemSorter}
*/
public ItemSorter getItemSorter() {
return m_queue.sort;
}
/**
* Set the ItemSorter that determines the rendering order of the
* VisualItems. Items are drawn in ascending order of the scores provided
* by the ItemSorter.
* @return the {@link prefuse.visual.sort.ItemSorter} to use
*/
public synchronized void setItemSorter(ItemSorter cmp) {
damageReport();
m_queue.sort = cmp;
}
/**
* Set a background image for this display.
* @param image the background Image. If a null value is provided,
* than no background image will be shown.
* @param fixed true if the background image should stay in a fixed
* position, invariant to panning, zooming, or rotation; false if
* the image should be subject to view transforms
* @param tileImage true to tile the image across the visible background,
* false to only include the image once
*/
public synchronized void setBackgroundImage(Image image,
boolean fixed, boolean tileImage)
{
BackgroundPainter bg = null;
if ( image != null )
bg = new BackgroundPainter(image, fixed, tileImage);
setBackgroundPainter(bg);
}
/**
* Set a background image for this display.
* @param location a location String of where to retrieve the
* image file from. Uses
* {@link prefuse.util.io.IOLib#urlFromString(String)} to resolve
* the String. If a null value is provided, than no background
* image will be shown.
* @param fixed true if the background image should stay in a fixed
* position, invariant to panning, zooming, or rotation; false if
* the image should be subject to view transforms
* @param tileImage true to tile the image across the visible background,
* false to only include the image once
*/
public synchronized void setBackgroundImage(String location,
boolean fixed, boolean tileImage)
{
BackgroundPainter bg = null;
if ( location != null )
bg = new BackgroundPainter(location, fixed, tileImage);
setBackgroundPainter(bg);
}
private void setBackgroundPainter(BackgroundPainter bg) {
if ( m_bgpainter != null )
removePaintListener(m_bgpainter);
m_bgpainter = bg;
if ( bg != null )
addPaintListener(bg);
}
// ------------------------------------------------------------------------
// ToolTips
/**
* Returns the tooltip instance to use for this Display. By default, uses
* the normal Swing tooltips, returning the result of this same method
* invoked on the JComponent super-class. If a custom tooltip has been
* set, that is returned instead.
* @see #setCustomToolTip(JToolTip)
* @see javax.swing.JComponent#createToolTip()
*/
public JToolTip createToolTip() {
if ( m_customToolTip == null ) {
return super.createToolTip();
} else {
return m_customToolTip;
}
}
/**
* Set a custom tooltip to use for this Display. To trigger tooltip
* display, you must still use the <code>setToolTipText</code> method
* as usual. The actual text will no longer have any effect, other
* than that a null text value will result in no tooltip display
* while a non-null text value will result in a tooltip being
* shown. Clients are responsible for setting the tool tip
* text to enable/disable tooltips as well as updating the content
* of their own custom tooltip instance.
* @param tooltip the tooltip component to use
* @see prefuse.util.ui.JCustomTooltip
*/
public void setCustomToolTip(JToolTip tooltip) {
m_customToolTip = tooltip;
}
/**
* Get the custom tooltip used by this Display. Returns null if normal
* tooltips are being used.
* @return the custom tooltip used by this Display, or null if none
*/
public JToolTip getCustomToolTip() {
return m_customToolTip;
}
// ------------------------------------------------------------------------
// Clip / Bounds Management
/**
* Indicates if damage/redraw rendering is enabled. If enabled, the display
* will only redraw within the bounding box of all areas that have changed
* since the last rendering operation. For small changes, such as a single
* item being dragged, this can result in a significant performance
* increase. By default, the damage/redraw optimization is enabled. It can
* be disabled, however, if rendering artifacts are appearing in your
* visualization. Be careful though, as this may not be the best solution.
* Rendering artifacts may result because the item bounds returned by
* {@link prefuse.visual.VisualItem#getBounds()} are not accurate and the
* item's {@link prefuse.render.Renderer} is drawing outside of the
* reported bounds. In this case, there is usually a bug in the Renderer.
* One reported problem arises from Java itself, however, which
* inaccurately redraws images outside of their reported bounds. If you
* have a visulization with a number of images and are seeing rendering
* artifacts, try disabling damage/redraw.
* @return true if damage/redraw optimizations are enabled, false
* otherwise (in which case the entire Display is redrawn upon a repaint)
*/
public synchronized boolean isDamageRedraw() {
return m_damageRedraw;
}
/**
* Sets if damage/redraw rendering is enabled. If enabled, the display
* will only redraw within the bounding box of all areas that have changed
* since the last rendering operation. For small changes, such as a single
* item being dragged, this can result in a significant performance
* increase. By default, the damage/redraw optimization is enabled. It can
* be disabled, however, if rendering artifacts are appearing in your
* visualization. Be careful though, as this may not be the best solution.
* Rendering artifacts may result because the item bounds returned by
* {@link prefuse.visual.VisualItem#getBounds()} are not accurate and the
* item's {@link prefuse.render.Renderer} is drawing outside of the
* reported bounds. In this case, there is usually a bug in the Renderer.
* One reported problem arises from Java itself, however, which
* inaccurately redraws images outside of their reported bounds. If you
* have a visulization with a number of images and are seeing rendering
* artifacts, try disabling damage/redraw.
* @param b true to enable damage/redraw optimizations, false otherwise
* (in which case the entire Display will be redrawn upon a repaint)
*/
public synchronized void setDamageRedraw(boolean b) {
m_damageRedraw = b;
m_clip.invalidate();
}
/**
* Reports damage to the Display within in the specified region.
* @param region the damaged region, in absolute coordinates
*/
public synchronized void damageReport(Rectangle2D region) {
if ( m_damageRedraw )
m_clip.union(region);
}
/**
* Reports damage to the entire Display.
*/
public synchronized void damageReport() {
m_clip.invalidate();
}
/**
* Clears any reports of damaged regions, causing the Display to believe
* that the display contents are up-to-date. If used incorrectly this
* can cause inaccurate rendering. <strong>Call this method only
* if you know what you are doing.</strong>
*/
public synchronized void clearDamage() {
if ( m_damageRedraw )
m_clip.reset();
}
/**
* Returns the bounds, in absolute (item-space) coordinates, of the total
* bounds occupied by all currently visible VisualItems. This method
* allocates a new Rectangle2D instance for the result.
* @return the bounding box of all visibile VisualItems
* @see #getItemBounds(Rectangle2D)
*/
public synchronized Rectangle2D getItemBounds() {
return getItemBounds(new Rectangle2D.Double());
}
/**
* Returns the bounds, in absolute (item-space) coordinates, of the total
* bounds occupied by all currently visible VisualItems.
* @param b the Rectangle2D to use to store the return value
* @return the bounding box of all visibile VisualItems
*/
public synchronized Rectangle2D getItemBounds(Rectangle2D b) {
b.setFrameFromDiagonal(m_bounds.getMinX(), m_bounds.getMinY(),
m_bounds.getMaxX(), m_bounds.getMaxY());
return b;
}
// ------------------------------------------------------------------------
// Rendering
/**
* Returns the offscreen buffer used for double buffering.
* @return the offscreen buffer
*/
public BufferedImage getOffscreenBuffer() {
return m_offscreen;
}
/**
* Creates a new buffered image to use as an offscreen buffer.
*/
protected BufferedImage getNewOffscreenBuffer(int width, int height) {
BufferedImage img = null;
if ( !GraphicsEnvironment.isHeadless() ) {
try {
img = (BufferedImage)createImage(width, height);
} catch ( Exception e ) {
img = null;
}
}
if ( img == null ) {
return new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
}
return img;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -