use of org.apache.pivot.wtk.NumberRuler in project pivot by apache.
the class NumberRulerSkin method setShowMajorNumbers.
/**
* Sets the flag to say whether to show numbers at each major division
* (only for horizontal orientation).
*
* @param showMajorNumbers Whether numbers should be shown for major divisions.
*/
public final void setShowMajorNumbers(boolean showMajorNumbers) {
this.showMajorNumbers = showMajorNumbers;
NumberRuler ruler = (NumberRuler) getComponent();
if (ruler.getOrientation() == Orientation.HORIZONTAL) {
invalidateComponent();
}
}
use of org.apache.pivot.wtk.NumberRuler in project pivot by apache.
the class NumberRulerSkin method setShowMinorNumbers.
/**
* Sets the flag to say whether to show numbers at each minor division
* (for horizontal orientation only).
*
* @param showMinorNumbers Whether numbers should be shown for minor divisions.
*/
public final void setShowMinorNumbers(boolean showMinorNumbers) {
this.showMinorNumbers = showMinorNumbers;
NumberRuler ruler = (NumberRuler) getComponent();
if (ruler.getOrientation() == Orientation.HORIZONTAL) {
invalidateComponent();
}
}
use of org.apache.pivot.wtk.NumberRuler in project pivot by apache.
the class NumberRulerSkin method install.
@Override
public void install(Component component) {
super.install(component);
Theme theme = Theme.getTheme();
setFont(theme.getFont());
setColor(0);
setBackgroundColor(19);
markerSpacing = 5;
markerInsets = new Insets(0);
rowPadding = new Insets(0);
// Note: these aren't settable
majorDivision = 10;
minorDivision = 5;
// But these are
showMajorNumbers = true;
showMinorNumbers = false;
NumberRuler ruler = (NumberRuler) component;
ruler.getRulerListeners().add(this);
}
use of org.apache.pivot.wtk.NumberRuler in project pivot by apache.
the class NumberRulerSkin method paint.
@Override
public void paint(Graphics2D graphics) {
int width = getWidth();
int height = getHeight();
int bottom = height - markerInsets.bottom;
Rectangle clipRect = graphics.getClipBounds();
NumberRuler ruler = (NumberRuler) getComponent();
int textSize = ruler.getTextSize();
graphics.setColor(backgroundColor);
graphics.fillRect(0, 0, width, height);
graphics.setColor(color);
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
graphics.setFont(font);
Orientation orientation = ruler.getOrientation();
Rectangle fullRect = new Rectangle(width, height);
Rectangle clippedRect = fullRect.intersection(clipRect);
switch(orientation) {
case HORIZONTAL:
{
int start = bottom - 1;
int end2 = start - (MAJOR_SIZE - 1);
int end3 = start - (MINOR_SIZE - 1);
int end4 = start - (REGULAR_SIZE - 1);
Rectangle lineRect = new Rectangle(0, height - 1, width - 1, 0);
Rectangle clippedLineRect = lineRect.intersection(clipRect);
graphics.drawLine(clippedLineRect.x, clippedLineRect.y, clippedLineRect.x + clippedLineRect.width, clippedLineRect.y);
for (int i = 0, n = width / markerSpacing + 1; i < n; i++) {
int x = i * markerSpacing + markerInsets.left;
if (majorDivision != 0 && i % majorDivision == 0) {
graphics.drawLine(x, start, x, end2);
// Don't show any numbers at 0 -- make a style for this?
if (showMajorNumbers && i > 0) {
showNumber(graphics, fontRenderContext, i, x, end2);
}
} else if (minorDivision != 0 && i % minorDivision == 0) {
graphics.drawLine(x, start, x, end3);
if (showMinorNumbers && i > 0) {
// Show the minor numbers at the same y point as the major
showNumber(graphics, fontRenderContext, i, x, end2);
}
} else {
graphics.drawLine(x, start, x, end4);
}
}
break;
}
case VERTICAL:
{
Rectangle lineRect = new Rectangle(width - 1, 0, 0, height - 1);
Rectangle clippedLineRect = lineRect.intersection(clipRect);
graphics.drawLine(clippedLineRect.x, clippedLineRect.y, clippedLineRect.x, clippedLineRect.y + clippedLineRect.height);
// Optimize drawing by only starting just above the current clip bounds
// down to the bottom (plus one) of the end of the clip bounds.
// This is a 100x speed improvement for 500,000 lines.
int linesAbove = clipRect.y / lineHeight;
int linesBelow = (height - (clipRect.y + clipRect.height)) / lineHeight;
int totalLines = height / lineHeight + 1;
for (int num = 1 + linesAbove, n = totalLines - (linesBelow - 1); num < n; num++) {
String numberString = Integer.toString(num);
StringCharacterIterator line = new StringCharacterIterator(numberString);
int lineY = (num - 1) * lineHeight + markerInsets.top;
Graphics2D lineGraphics = (Graphics2D) graphics.create(0, lineY, width, lineHeight);
float y = (float) (lineHeight - rowPadding.bottom) - descent;
GlyphVector glyphVector = font.createGlyphVector(fontRenderContext, line);
Rectangle2D textBounds = glyphVector.getLogicalBounds();
float lineWidth = (float) textBounds.getWidth();
float x = (float) width - (lineWidth + (float) padding);
lineGraphics.drawGlyphVector(glyphVector, x, y);
}
break;
}
default:
{
break;
}
}
}
use of org.apache.pivot.wtk.NumberRuler in project pivot by apache.
the class NumberRulerSkin method getPreferredHeight.
@Override
public int getPreferredHeight(int width) {
NumberRuler ruler = (NumberRuler) getComponent();
Orientation orientation = ruler.getOrientation();
// Give a little extra height if showing numbers
return (orientation == Orientation.HORIZONTAL) ? ((showMajorNumbers || showMinorNumbers) ? ((int) Math.ceil(charHeight) + MAJOR_SIZE + 5) : MAJOR_SIZE * 2) : 0;
}
Aggregations