本文整理汇总了Java中java.awt.Font.deriveFont方法的典型用法代码示例。如果您正苦于以下问题:Java Font.deriveFont方法的具体用法?Java Font.deriveFont怎么用?Java Font.deriveFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Font
的用法示例。
在下文中一共展示了Font.deriveFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSizeForString
import java.awt.Font; //导入方法依赖的package包/类
/**
* Returns an <mxRectangle> with the size (width and height in pixels) of the given string.
*
* @param text String whose size should be returned.
* @param font Font to be used for the computation.
*/
public static mxRectangle getSizeForString(String text, Font font, double scale) {
FontRenderContext frc = new FontRenderContext(null, false, false);
font = font.deriveFont((float) (font.getSize2D() * scale));
FontMetrics metrics = null;
if (fontGraphics != null) {
metrics = fontGraphics.getFontMetrics(font);
}
double lineHeight = mxConstants.LINESPACING;
if (metrics != null) {
lineHeight += metrics.getHeight();
} else {
lineHeight += font.getSize2D() * 1.27;
}
String[] lines = text.split("\n");
Rectangle2D boundingBox = null;
if (lines.length == 0) {
boundingBox = font.getStringBounds("", frc);
} else {
for (int i = 0; i < lines.length; i++) {
Rectangle2D bounds = font.getStringBounds(lines[i], frc);
if (boundingBox == null) {
boundingBox = bounds;
} else {
boundingBox.setFrame(0, 0, Math.max(boundingBox.getWidth(), bounds.getWidth()),
boundingBox.getHeight() + lineHeight);
}
}
}
return new mxRectangle(boundingBox);
}
示例2: getFontForState
import java.awt.Font; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* Overridden to cause this style to populate itself with data from
* UIDefaults, if necessary. If a value named "font" is not found in
* UIDefaults, then the "defaultFont" font in UIDefaults will be returned
* instead.
*/
@Override protected Font getFontForState(SynthContext ctx) {
Font f = (Font)get(ctx, "font");
if (f == null) f = UIManager.getFont("defaultFont");
// Account for scale
// The key "JComponent.sizeVariant" is used to match Apple's LAF
String scaleKey = (String)ctx.getComponent().getClientProperty(
"JComponent.sizeVariant");
if (scaleKey != null){
if (LARGE_KEY.equals(scaleKey)){
f = f.deriveFont(Math.round(f.getSize2D()*LARGE_SCALE));
} else if (SMALL_KEY.equals(scaleKey)){
f = f.deriveFont(Math.round(f.getSize2D()*SMALL_SCALE));
} else if (MINI_KEY.equals(scaleKey)){
f = f.deriveFont(Math.round(f.getSize2D()*MINI_SCALE));
}
}
return f;
}
示例3: FontPanel
import java.awt.Font; //导入方法依赖的package包/类
public FontPanel( Font2DTest demo, JFrame f ) {
f2dt = demo;
parent = f;
verticalBar = new JScrollBar ( JScrollBar.VERTICAL );
fc = new FontCanvas();
this.setLayout( new BorderLayout() );
this.add( "Center", fc );
this.add( "East", verticalBar );
verticalBar.addAdjustmentListener( this );
this.addComponentListener( new ComponentAdapter() {
public void componentResized( ComponentEvent e ) {
updateBackBuffer = true;
updateFontMetrics = true;
}
});
/// Initialize font and its infos
testFont = new Font(fontName, fontStyle, (int)fontSize);
if ((float)((int)fontSize) != fontSize) {
testFont = testFont.deriveFont(fontSize);
}
updateFontInfo();
}
示例4: createCompatibleFont
import java.awt.Font; //导入方法依赖的package包/类
/**
* Create a scaled {@code Font} which can display all characters
* inside the given text string.
* This is mostly necessary for the header font. Thats because the currently
* used ShadowedBlack is missing support for CJK and others. Even some
* special glyphs for European languages like the triple-dot are missing.
*
* @param string The text to find a compatible font for.
* @param fontType How the font should look like.
* @param fontSize Its relative size.
* @param style The font style for choosing plain, bold or italic.
* @param scaleFactor The applied scale factor.
* @return The created Font.
*/
public static Font createCompatibleFont(String string, FontType fontType,
FontSize fontSize,
int style, float scaleFactor) {
// TODO: Consider testing the normal font for compatibility and try
// some or all other available fonts for complete/longest match:
// header/simple->main->normal->simple/header->emergency
float scaledSize = calcScaledSize(fontSize, scaleFactor);
String fontKey = getFontKey(fontType);
Font font = null;
if(fontType != FontType.NORMAL) {
font = ResourceManager.getFont(fontKey);
if(font.canDisplayUpTo(string) != -1)
font = null;
}
if(font == null) {
fontKey = getFontKey(FontType.NORMAL);
font = (fontKey == null)
? mainFont
: ResourceManager.getFont(fontKey);
}
font = font.deriveFont(style, scaledSize);
return font;
}
示例5: actionPerformedImpl
import java.awt.Font; //导入方法依赖的package包/类
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
Font font = textArea.getFont();
float oldSize = font.getSize2D();
float newSize = oldSize - decreaseAmount;
if (newSize>=MINIMUM_SIZE) {
// Shrink by decreaseAmount.
font = font.deriveFont(newSize);
textArea.setFont(font);
}
else if (oldSize>MINIMUM_SIZE) {
// Can't shrink by full decreaseAmount, but can shrink a
// little bit.
font = font.deriveFont(MINIMUM_SIZE);
textArea.setFont(font);
}
else {
// Our font size must be at or below MINIMUM_SIZE.
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
}
textArea.requestFocusInWindow();
}
示例6: getPlotter
import java.awt.Font; //导入方法依赖的package包/类
@Override
public JComponent getPlotter() {
DataTable table = getDataTable();
if (table != null && table.getNumberOfRows() > MAX_NUMBER_OF_ROWS) {
LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.mathplot.SurfacePlot2D.too_many_examples",
new Object[] { table.getNumberOfRows(), MAX_NUMBER_OF_ROWS });
// Display Label with error message because Plot3DPanel can not handle such a lot of
// data points
JLabel label = new JLabel(I18N.getGUILabel("surface3DPlot.too_many_examples", MAX_NUMBER_OF_ROWS));
label.setHorizontalAlignment(SwingConstants.CENTER);
Font originalFont = label.getFont();
label.setFont(originalFont.deriveFont((float) (originalFont.getSize() * 1.25)));
originalFont.deriveFont(new AffineTransform());
return label;
} else {
return super.getPlotter();
}
}
示例7: createSubGroupPanel
import java.awt.Font; //导入方法依赖的package包/类
/**
* Creates a panel with a heading.
*
* @param labelText
* The text for the heading
*
* @return The panel
*/
private JPanel createSubGroupPanel(String labelText) {
JLabel subGroupLabel = new JLabel();
Font font = subGroupLabel.getFont();
font = font.deriveFont(Font.BOLD, 14f);
subGroupLabel.setFont(font);
subGroupLabel.setForeground(SettingsTabs.COLOR_SUBGROUP);
subGroupLabel.setText(labelText);
int top = SUBGROUP_TOP_MARGIN;
if (isFirstSubGroup) {
isFirstSubGroup = false;
top = FIRST_SUBGROUP_TOP_MARGIN;
}
subGroupLabel.setBorder(BorderFactory.createEmptyBorder(top, 0, 7, 0));
JPanel subGroupPanel = new JPanel();
subGroupPanel.setLayout(new BoxLayout(subGroupPanel, BoxLayout.LINE_AXIS));
subGroupPanel.add(subGroupLabel);
subGroupPanel.add(Box.createHorizontalGlue());
return subGroupPanel;
}
示例8: writeImage
import java.awt.Font; //导入方法依赖的package包/类
public static void writeImage(File fontFile, File outputFile, String value) throws Exception {
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, image.getWidth(), image.getHeight());
g.setColor(Color.BLACK);
Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
font = font.deriveFont(Font.PLAIN, 72f);
FontRenderContext frc = new FontRenderContext(null, false, false);
GlyphVector gv = font.createGlyphVector(frc, value);
g.drawGlyphVector(gv, 10, 80);
g.fill(gv.getOutline(10, 180));
ImageIO.write(image, "png", outputFile);
}
示例9: resetAllDayLabels
import java.awt.Font; //导入方法依赖的package包/类
/**
* Reset all day labels back to plain font.
*/
private void resetAllDayLabels() {
JLabel[] labels = {jLabel9, jLabel10, jLabel11, jLabel12, jLabel13, jLabel14, jLabel5, jLabel6};
for (JLabel label : labels) {
final Font oldFont = label.getFont();
// Reset BOLD attribute.
final Font font = oldFont.deriveFont(oldFont.getStyle() & ~Font.BOLD);
label.setFont(font);
}
}
示例10: paintComponent
import java.awt.Font; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void paintComponent(Graphics g) {
updateSizes();
Graphics2D g2d = (Graphics2D) g;
chatDisplay.removeOldMessages();
Dimension size = getSize();
if (freeColClient.isMapEditor()) {
if (hasMap()) {
mapViewer.displayMap(g2d);
} else {
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, size.width, size.height);
}
} else if (freeColClient.isInGame() && hasMap()) {
mapViewer.displayMap(g2d);
// Grey out the map if it is not my turn (and a multiplayer game).
if (!freeColClient.currentPlayerIsMyPlayer()) {
if (greyLayer == null) {
greyLayer = new GrayLayer(freeColClient);
}
if (greyLayer.getParent() == null) {
add(greyLayer, JLayeredPane.DRAG_LAYER);
}
greyLayer.setBounds(0, 0, size.width, size.height);
greyLayer.setPlayer(freeColClient.getGame().getCurrentPlayer());
} else {
if (greyLayer != null && greyLayer.getParent() != null) {
removeFromCanvas(greyLayer);
}
}
// paint chat display
chatDisplay.display(g2d, mapViewer.getImageLibrary(), size);
} else {
/* main menu */
// TODO: Check if its right to sometimes have an unfocused map
// ingame and end up here after clicking outside map.
final String bgImageKey = "image.flavor.Canvas.map";
if (ResourceManager.hasImageResource(bgImageKey)) {
// Get the background without scaling, to avoid wasting
// memory needlessly keeping an unbounded number of rescaled
// versions of the largest image in FreeCol, forever.
final Image bgImage = ResourceManager.getImage(bgImageKey);
// Draw background image with scaling.
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(bgImage, 0, 0, size.width, size.height, this);
String versionStr = "v. " + FreeCol.getVersion();
Font oldFont = g2d.getFont();
Color oldColor = g2d.getColor();
Font newFont = oldFont.deriveFont(Font.BOLD);
TextLayout layout = new TextLayout(versionStr, newFont,
g2d.getFontRenderContext());
Rectangle2D bounds = layout.getBounds();
float x = size.width - (float) bounds.getWidth() - 5;
float y = size.height - (float) bounds.getHeight();
g2d.setColor(Color.white);
layout.draw(g2d, x, y);
g2d.setFont(oldFont);
g2d.setColor(oldColor);
} else {
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, size.width, size.height);
}
}
}
示例11: init
import java.awt.Font; //导入方法依赖的package包/类
public void init(TestEnvironment env, Result result) {
// graphics
graphics = env.getGraphics();
// text
String sname = (String)env.getModifier(tscriptList);
int slen = env.getIntValue(tlengthList);
text = getString(sname, slen);
// chars
chars = text.toCharArray();
// font
String fname = (String)env.getModifier(fnameList);
if ("Physical".equals(fname)) {
fname = physicalFontNameFor(sname, slen, text);
}
int fstyle = env.getIntValue(fstyleList);
float fsize = ((Float)env.getModifier(fsizeList)).floatValue();
AffineTransform ftx = (AffineTransform)env.getModifier(ftxList);
font = new Font(fname, fstyle, (int)fsize);
if (hasGraphics2D) {
if (fsize != Math.floor(fsize)) {
font = font.deriveFont(fsize);
}
if (!ftx.isIdentity()) {
font = font.deriveFont(ftx);
}
}
// graphics
if (hasGraphics2D) {
Graphics2D g2d = (Graphics2D)graphics;
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
env.getModifier(taaList));
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
env.isEnabled(tfmTog)
? RenderingHints.VALUE_FRACTIONALMETRICS_ON
: RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
env.isEnabled(gaaTog)
? RenderingHints.VALUE_ANTIALIAS_ON
: RenderingHints.VALUE_ANTIALIAS_OFF);
g2d.transform((AffineTransform)env.getModifier(gtxList));
}
// set result
result.setUnits(text.length());
result.setUnitName("char");
}
示例12: doRender
import java.awt.Font; //导入方法依赖的package包/类
/**
* Run the render method of the given component.
*
* @param comp
*/
private void doRender(Component comp) {
if (rendered.contains(System.identityHashCode(comp))) {
return;
}
rendered.add(System.identityHashCode(comp));
if (comp instanceof Container) {
Container cont = (Container) comp;
for (Component comp2 : cont.getComponents()) {
doRender(comp2);
}
}
float[] scale = getScalef();
Component originalComponent = null;
try {
originalComponent = deserializeObject(JComponent.class, originalComps.get(System.identityHashCode(comp)));
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
if (originalComponent != null) {
// Bounds
if (isWindowOptionEnabled(WindowOptions.SCALE_COMPONENTS)) {
Rectangle original = originalComponent.getBounds();
int newX = (int) (original.getX() * scale[0]);
int newY = (int) (original.getY() * scale[1]);
int newW = (int) (original.getWidth() * scale[0]);
int newH = (int) (original.getHeight() * scale[1]);
comp.setBounds(newX, newY, newW, newH);
}
// Fonts
if (isWindowOptionEnabled(WindowOptions.SCALE_FONTS)) {
if (comp.getFont() != null && originalComponent.getFont() != null) {
Font font = comp.getFont();
Font newFont = font.deriveFont(font.getStyle(),
getSuggestedFontSize(originalComponent.getFont().getSize()));
comp.setFont(newFont);
}
}
// Images
if (isWindowOptionEnabled(WindowOptions.SCALE_IMAGES)) {
if (comp instanceof JLabel) {
JLabel label = (JLabel) comp;
JLabel orig = (JLabel) originalComponent;
label.setIcon(getScaledImageIcon(orig));
}
}
}
}
示例13: SelectionBar
import java.awt.Font; //导入方法依赖的package包/类
public SelectionBar()
{
super(new MigLayout("fill, ins 3", "fill"));
Messenger.register(MT.SERIES_CHANGED, this);
Messenger.register(MT.RUNGROUP_CHANGED, this);
Messenger.register(MT.ENTRANTS_CHANGED, this);
setBorder(new BevelBorder(0));
Font f = new Font(Font.DIALOG, Font.BOLD, 14);
Font fn = f.deriveFont(Font.PLAIN);
resultsButton = new JButton("Print Current Group Results");
resultsButton.addActionListener(this);
resultsButton.setActionCommand("resultsPrint");
refreshButton = new JButton("Refresh");
refreshButton.addActionListener(e -> Messenger.sendEvent(MT.RUNGROUP_CHANGED, null));
seriesLabel = new CurrentSeriesLabel();
seriesLabel.setFont(fn);
entrantCountLabel = new JLabel("0");
entrantCountLabel.setFont(fn);
courseSelect = createCombo("courseChange");
groupSelect = createCombo("groupChange");
eventSelect = createCombo("eventChange");
groupSelect.setModel(new DefaultComboBoxModel<Integer>(new Integer[] { 1, 2, 3, 4, 5, 6 }));
add(createLabel("Series:", f), "gapleft 10");
add(seriesLabel, "gapright 20");
add(createLabel("Event:", f), "");
add(eventSelect, "gapright 20");
add(createLabel("Course:", f));
add(courseSelect, "gapright 10");
add(createLabel("RunGroup:", f));
add(groupSelect, "gapright 10");
add(createLabel("Count:", f));
add(entrantCountLabel, "");
add(new JLabel(""), "growx 100, pushx 100");
add(refreshButton, "");
add(resultsButton, "gapright 20");
}
示例14: configureTextField
import java.awt.Font; //导入方法依赖的package包/类
public void configureTextField(EditableLabelField field, double zoom) {
Font f = font;
if (zoom != 1.0) {
f = f.deriveFont(AffineTransform.getScaleInstance(zoom, zoom));
}
field.setFont(f);
Dimension dim = field.getPreferredSize();
int w;
int border = EditableLabelField.FIELD_BORDER;
if (dimsKnown) {
w = width + 1 + 2 * border;
} else {
FontMetrics fm = field.getFontMetrics(font);
ascent = fm.getAscent();
descent = fm.getDescent();
w = 0;
}
int x0 = x;
int y0 = getBaseY() - ascent;
if (zoom != 1.0) {
x0 = (int) Math.round(x0 * zoom);
y0 = (int) Math.round(y0 * zoom);
w = (int) Math.round(w * zoom);
}
w = Math.max(w, dim.width);
int h = dim.height;
switch (horzAlign) {
case LEFT:
x0 = x0 - border;
break;
case CENTER:
x0 = x0 - (w / 2) + 1;
break;
case RIGHT:
x0 = x0 - w + border + 1;
break;
default:
x0 = x0 - border;
}
y0 = y0 - border;
field.setHorizontalAlignment(horzAlign);
field.setForeground(color);
field.setBounds(x0, y0, w, h);
}
示例15: getFont
import java.awt.Font; //导入方法依赖的package包/类
/**
* Return a Font from a given font index with properties
* from attributes. The font index, which should have been produced
* by getFontIndex(), determines a font family. The size and style
* of the Font reflect the properties in attributes. Any Font or
* font family specifications in attributes are ignored, on the
* assumption that clients have already handled them.
* @param index an index from getFontIndex() which determines the
* font family
* @param attributes a Map from which the size and style of the Font
* are determined. The default size is 12 and the default style
* is Font.PLAIN
* @see #getFontIndex
*/
public Font getFont(int index, Map attributes) {
Font font = defaultFont;
if (index >= 2) {
font = allFonts[index-2];
}
return font.deriveFont(attributes);
}