List of usage examples for java.awt Graphics getFont
public abstract Font getFont();
From source file:ro.nextreports.designer.ui.sqleditor.syntax.SyntaxView.java
@Override protected int drawUnselectedText(Graphics graphics, int x, int y, int p0, int p1) { Font saveFont = graphics.getFont(); Color saveColor = graphics.getColor(); SyntaxDocument doc = (SyntaxDocument) getDocument(); Segment segment = getLineBuffer(); try {/*from w ww. jav a 2 s. c om*/ // Colour the parts Iterator<Token> tokens = doc.getTokens(p0, p1); int start = p0; while (tokens.hasNext()) { Token t = tokens.next(); // if there is a gap between the next token start and where we // should be starting (spaces not returned in tokens), then draw // it in the default type if (start < t.start) { SyntaxStyles.getInstance().setGraphicsStyle(graphics, TokenType.DEFAULT); doc.getText(start, t.start - start, segment); x = Utilities.drawTabbedText(segment, x, y, graphics, this, start); } // t and s are the actual start and length of what we should // put on the screen. assume these are the whole token.... int l = t.length; int s = t.start; // ... unless the token starts before p0: if (s < p0) { // token is before what is requested. adgust the length and s l -= (p0 - s); s = p0; } // if token end (s + l is still the token end pos) is greater // than p1, then just put up to p1 if (s + l > p1) { l = p1 - s; } doc.getText(s, l, segment); x = SyntaxStyles.getInstance().drawText(segment, x, y, graphics, this, t); start = t.start + t.length; } // now for any remaining text not tokenized: if (start < p1) { SyntaxStyles.getInstance().setGraphicsStyle(graphics, TokenType.DEFAULT); doc.getText(start, p1 - start, segment); x = Utilities.drawTabbedText(segment, x, y, graphics, this, start); } } catch (BadLocationException e) { System.err.println("Requested: " + e.offsetRequested()); LOG.error(e.getMessage(), e); } finally { graphics.setFont(saveFont); graphics.setColor(saveColor); } return x; }
From source file:uk.co.modularaudio.mads.base.oscilloscope.ui.OscilloscopeDisplayUiJComponent.java
private void paintIntoImage(final Graphics g, final OscilloscopeWriteableScopeData scopeData) { // Graphics2D g2d = (Graphics2D)g; // Rectangle clipBounds = g.getClipBounds(); final Font f = g.getFont(); final Font newFont = f.deriveFont(12); g.setFont(newFont);/*from w w w .ja v a2 s.c o m*/ final int x = 0; final int y = 0; newMaxMag0 = 0.5f; newMaxMag1 = 0.5f; final int width = getWidth(); final int height = getHeight(); final int plotWidth = width - (SCALE_WIDTH * 2); final int plotStart = SCALE_WIDTH; final int plotHeight = getHeight(); // g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g.setColor(Color.BLACK); g.fillRect(x, y, width, height); if (scopeData != null) { final int numSamplesInBuffer = scopeData.desiredDataLength; final float[] float0Data = scopeData.floatBuffer0; final FloatType float0Type = scopeData.floatBuffer0Type; switch (float0Type) { case AUDIO: maxMag0 = 1.0f; break; case CV: break; } final boolean displayFloat0 = scopeData.float0Written; final float[] float1Data = scopeData.floatBuffer1; final FloatType float1Type = scopeData.floatBuffer1Type; switch (float1Type) { case AUDIO: maxMag1 = 1.0f; break; case CV: break; } final boolean displayFloat1 = scopeData.float1Written; if (displayFloat0) { // Float data draw g.setColor(Color.RED); drawScale(g, height, maxMag0, 0); plotAllDataValues(g, plotWidth, plotStart, plotHeight, numSamplesInBuffer, float0Data, true); } if (displayFloat1) { // CV data draw g.setColor(Color.YELLOW); drawScale(g, height, maxMag1, plotStart + plotWidth); plotAllDataValues(g, plotWidth, plotStart, plotHeight, numSamplesInBuffer, float1Data, false); } maxMag0 = newMaxMag0; maxMag1 = newMaxMag1; } }