@Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub Object source = e.getSource(); if (source == ok) { response = APPLY_OPTION; this.setVisible(false); } else if (source == cancel) { response = CANCEL_OPTION; this.setVisible(false); } else if (source == sizeCombo) { // get the number from the source JComboBox number = (JComboBox) source; String numberItem = (String) number.getSelectedItem(); Font temp = example.getFont(); // then set the font int newSize = Integer.parseInt(numberItem); example.setFont(new Font(temp.getFamily(), temp.getStyle(), newSize)); } else if (source == fontCombo) { JComboBox font = (JComboBox) source; String s = (String) font.getSelectedItem(); Font tmp = example.getFont(); example.setFont(new Font(s, tmp.getStyle(), tmp.getSize())); } else if (source == foreground) { Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground()); MenuBar.shapeLBG.setBackground(tmp); if (tmp != null) example.setForeground(tmp); } }
public void drawString(String str, int x, int y) { if (str == null || str.equals("")) return; Font excelFont = font; if (font.getName().equals("SansSerif")) { excelFont = new Font("Arial", font.getStyle(), (int) (font.getSize() / verticalPixelsPerPoint)); } else { excelFont = new Font( font.getName(), font.getStyle(), (int) (font.getSize() / verticalPixelsPerPoint)); } FontDetails d = StaticFontMetrics.getFontDetails(excelFont); int width = (int) ((d.getStringWidth(str) * 8) + 12); int height = (int) ((font.getSize() / verticalPixelsPerPoint) + 6) * 2; y -= (font.getSize() / verticalPixelsPerPoint) + 2 * verticalPixelsPerPoint; // we want to draw the shape from the top-left HSSFTextbox textbox = escherGroup.createTextbox(new HSSFChildAnchor(x, y, x + width, y + height)); textbox.setNoFill(true); textbox.setLineStyle(HSSFShape.LINESTYLE_NONE); HSSFRichTextString s = new HSSFRichTextString(str); HSSFFont hssfFont = matchFont(excelFont); s.applyFont(hssfFont); textbox.setString(s); }
private void _applyFontStyleForSelection(Font font) { StyledDocument doc = mTextEditor.getStyledDocument(); MutableAttributeSet attrs = mTextEditor.getInputAttributes(); StyleConstants.setFontFamily(attrs, font.getFamily()); StyleConstants.setFontSize(attrs, font.getSize()); StyleConstants.setBold(attrs, ((font.getStyle() & Font.BOLD) != 0)); StyleConstants.setItalic(attrs, ((font.getStyle() & Font.ITALIC) != 0)); StyleConstants.setUnderline(attrs, ((font.getStyle() & Font.CENTER_BASELINE) != 0)); int start = mTextEditor.getSelectionStart(); int end = mTextEditor.getSelectionEnd(); doc.setCharacterAttributes(start, (end - start), attrs, false); }
public RollResultView() { this.setOpaque(true); this.setLayout(new BorderLayout()); this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH)); // add the title label to the panel titleLabel = new JLabel("Roll Results"); Font titleLabelFont = titleLabel.getFont(); titleLabelFont = titleLabelFont.deriveFont(titleLabelFont.getStyle(), TITLE_TEXT_SIZE); titleLabel.setFont(titleLabelFont); this.add(titleLabel, BorderLayout.NORTH); // add the button to the panel okayButton = new JButton("Okay"); okayButton.addActionListener(actionListener); Font okayButtonFont = okayButton.getFont(); okayButtonFont = okayButtonFont.deriveFont(okayButtonFont.getStyle(), BUTTON_TEXT_SIZE); okayButton.setFont(okayButtonFont); this.add(okayButton, BorderLayout.SOUTH); // create the rollLabel rollLabel = new JLabel( "ERROR: YOU FORGOT TO SET THE ROLL VALUE BEFORE DISPLAYING THIS WINDOW... NAUGHTY, NAUGHTY"); Font rollLabelFont = rollLabel.getFont(); rollLabelFont = rollLabelFont.deriveFont(rollLabelFont.getStyle(), LABEL_TEXT_SIZE); rollLabel.setFont(rollLabelFont); rollLabel.setHorizontalAlignment(SwingConstants.CENTER); rollLabel.setBorder(BorderFactory.createEmptyBorder(25, 0, 25, 0)); // create the picture picture = new ImageIcon( ImageUtils.loadImage("images/resources/resources.png") .getScaledInstance(250, 250, Image.SCALE_SMOOTH)); pictureLabel = new JLabel(); pictureLabel.setIcon(picture); // create the center label centerPanel = new JPanel(); centerPanel.setLayout(new BorderLayout()); centerPanel.add(pictureLabel, BorderLayout.NORTH); centerPanel.add(Box.createRigidArea(new Dimension(25, 25))); centerPanel.add(rollLabel, BorderLayout.SOUTH); this.add(centerPanel, BorderLayout.CENTER); // add some spacing this.add(Box.createRigidArea(new Dimension(50, 50)), BorderLayout.EAST); this.add(Box.createRigidArea(new Dimension(50, 50)), BorderLayout.WEST); }
public void setGameLabellingSize(int sizeShift) { Font font = currentHometeamL.getFont(); Font newFont = new Font(font.getName(), font.getStyle(), font.getSize() + sizeShift); currentHometeamL.setFont(newFont); currentAwayteamL.setFont(newFont); Font tableHeaderFont = showTableP.getTable().getTableHeader().getFont(); Font newTableHeaderFont = new Font( tableHeaderFont.getName(), tableHeaderFont.getStyle(), tableHeaderFont.getSize() + sizeShift); showTableP.getTable().getTableHeader().setFont(newTableHeaderFont); }
public void setSelectedFont(Font font) { selectedFont = font; family = font.getFamily(); style = font.getStyle(); size = font.getSize(); preview.setFont(font); }
private int computeTextWidth(@NotNull Font font, final boolean mainTextOnly) { int result = 0; int baseSize = font.getSize(); boolean wasSmaller = false; for (int i = 0; i < myAttributes.size(); i++) { SimpleTextAttributes attributes = myAttributes.get(i); boolean isSmaller = attributes.isSmaller(); if (font.getStyle() != attributes.getFontStyle() || isSmaller != wasSmaller) { // derive font only if it is necessary font = font.deriveFont( attributes.getFontStyle(), isSmaller ? UIUtil.getFontSize(UIUtil.FontSize.SMALL) : baseSize); } wasSmaller = isSmaller; result += computeStringWidth(i, font); final int fixedWidth = myFragmentPadding.get(i); if (fixedWidth > 0 && result < fixedWidth) { result = fixedWidth; } if (mainTextOnly && myMainTextLastIndex >= 0 && i == myMainTextLastIndex) break; } return result; }
/** * Gets a special kind of Phrase that changes some characters into corresponding symbols. * * @param leading * @param string * @param font * @return a newly constructed Phrase */ public static final Phrase getInstance(int leading, String string, Font font) { Phrase p = new Phrase(true); p.setLeading(leading); p.font = font; if (font.getFamily() != Font.SYMBOL && font.getFamily() != Font.ZAPFDINGBATS && font.getBaseFont() == null) { int index; while ((index = SpecialSymbol.index(string)) > -1) { if (index > 0) { String firstPart = string.substring(0, index); ((ArrayList) p).add(new Chunk(firstPart, font)); string = string.substring(index); } Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor()); StringBuffer buf = new StringBuffer(); buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0))); string = string.substring(1); while (SpecialSymbol.index(string) == 0) { buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0))); string = string.substring(1); } ((ArrayList) p).add(new Chunk(buf.toString(), symbol)); } } if (string != null && string.length() != 0) { ((ArrayList) p).add(new Chunk(string, font)); } return p; }
/** * Set the Font to use with the class * * @param f Font */ public void setFont(Font f) { font = f; fontname = f.getName(); fontstyle = f.getStyle(); fontsize = f.getSize(); parse = true; }
private static File findFileForFont(Font font, final boolean matchStyle) { final String normalizedFamilyName = font.getFamily().toLowerCase(Locale.getDefault()).replace(" ", ""); final int fontStyle = font.getStyle(); File[] files = new File(System.getProperty("user.home"), "Library/Fonts") .listFiles( new FilenameFilter() { @Override public boolean accept(File file, String name) { String normalizedName = name.toLowerCase(Locale.getDefault()); return normalizedName.startsWith(normalizedFamilyName) && (normalizedName.endsWith(".otf") || normalizedName.endsWith(".ttf")) && (!matchStyle || fontStyle == ComplementaryFontsRegistry.getFontStyle(name)); } }); if (files == null || files.length == 0) return null; // to make sure results are predictable we return first file in alphabetical order return Collections.min( Arrays.asList(files), new Comparator<File>() { @Override public int compare(File file1, File file2) { return file1.getName().compareTo(file2.getName()); } }); }
/** * Paints the graphic component * * @param g Graphic component */ public void paint(Graphics g) { if (environment != null) { Sudoku env = (Sudoku) environment; Board board = env.getBoard(); int n = SudokuLanguage.DIGITS; int sqrt_n = (int) (Math.sqrt(n) + 0.1); g.setColor(Color.lightGray); Font font = g.getFont(); g.setFont(new Font(font.getName(), font.getStyle(), 20)); for (int i = 0; i < n; i++) { int ci = getCanvasValue(i); if (i % sqrt_n == 0) { g.drawLine(ci, DRAW_AREA_SIZE + MARGIN, ci, MARGIN); g.drawLine(DRAW_AREA_SIZE + MARGIN, ci, MARGIN, ci); } for (int j = 0; j < n; j++) { int cj = getCanvasValue(j); int value = board.get(i, j); if (value > 0) { g.setColor(Color.black); g.drawString("" + value, cj + CELL_SIZE / 5, ci + CELL_SIZE); g.setColor(Color.lightGray); } } } g.drawLine(DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, MARGIN); g.drawLine(DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, MARGIN, DRAW_AREA_SIZE + MARGIN); } }
public static void bumpUpFontSize(Component widget, int bumps) { if (!UserPreferences.readLocalePref() .equals("ko")) { // HACK!!! refector with variable localeSupportsBold Font f = widget.getFont(); widget.setFont(new Font(f.getFamily(), f.getStyle(), f.getSize() + bumps)); } }
/** * Set current font. Default to Plain Courier 11 if null. * * @param font new font. */ public void setFont(Font font) { if (font != null) { m_localGraphicsState.setFont(font); if (font.getName().equals(m_psGraphicsState.getFont().getName()) && (m_psGraphicsState.getFont().getStyle() == font.getStyle()) && (m_psGraphicsState.getFont().getSize() == yScale(font.getSize()))) return; m_psGraphicsState.setFont( new Font(font.getName(), font.getStyle(), yScale(getFont().getSize()))); } else { m_localGraphicsState.setFont(new Font("Courier", Font.PLAIN, 11)); m_psGraphicsState.setFont(getFont()); } m_printstream.println("/(" + replacePSFont(getFont().getPSName()) + ")" + " findfont"); m_printstream.println(yScale(getFont().getSize()) + " scalefont setfont"); }
/** * Adjust shape's font size to show specified message. * * @param message template message. */ public void adjustFontSize(String message) { Dimension size = getSize(); Font font = getFont(); int l = 5; int r = 1000; while (l < r) { int m = (l + r + 1) / 2; FontMetrics metrics = getFontMetrics(new Font(font.getName(), font.getStyle(), m)); Dimension minSize = new Dimension(metrics.stringWidth(message) + 1, metrics.getHeight() + 1); if (size.width < minSize.width || size.height < minSize.height) { r = m - 1; } else { l = m; } } setFont(new Font(font.getName(), font.getStyle(), l)); }
/** * Instantiate the class * * @param s String to parse. * @param f Font to use. */ public TextLine(String s, Font f) { this(s); font = f; if (font == null) return; fontname = f.getName(); fontstyle = f.getStyle(); fontsize = f.getSize(); }
/** * Gets the BDFontMetrics object for the supplied font. This method caches font metrics to ensure * native fonts are not loaded twice for the same font. */ static synchronized BDFontMetrics getFontMetrics(Font font) { /* See if metrics has been stored in font already. */ BDFontMetrics fm = null; // BDFontMetrics fm = (BDFontMetrics)font.metrics; // if (fm == null) { /* See if a font metrics of the same native name and size has already been loaded. If it has then we use that one. */ String nativeName = (String) fontNameMap.get(font.getName().toLowerCase() + "." + font.getStyle()); if (nativeName == null) nativeName = (String) fontNameMap.get("default." + font.getStyle()); String key = nativeName + "." + font.getSize(); fm = (BDFontMetrics) fontMetricsMap.get(key); if (fm == null) fontMetricsMap.put(key, fm = new BDFontMetrics(font, nativeName)); // font.metrics = fm; // } return fm; }
/** * Gets a chunk with a symbol character. * * @param c a character that has to be changed into a symbol * @param font Font if there is no SYMBOL character corresponding with c * @return a SYMBOL version of a character */ public static Chunk get(char c, Font font) { char greek = SpecialSymbol.getCorrespondingSymbol(c); if (greek == ' ') { return new Chunk(String.valueOf(c), font); } Font symbol = new Font(FontFamily.SYMBOL, font.getSize(), font.getStyle(), font.getColor()); String s = String.valueOf(greek); return new Chunk(s, symbol); }
@Override public Font getFont(EditorFontType key) { if (UISettings.getInstance().PRESENTATION_MODE) { final Font font = myFonts.get(key); return new Font( font.getName(), font.getStyle(), UISettings.getInstance().PRESENTATION_MODE_FONT_SIZE); } return myFonts.get(key); }
/** * Instantiate the class * * @param f Font to use. * @param c Color to use * @param j Justification */ public TextLine(Font f, Color c, int j) { font = f; color = c; justification = j; if (font == null) return; fontname = f.getName(); fontstyle = f.getStyle(); fontsize = f.getSize(); }
private HSSFFont matchFont(Font font) { HSSFColor hssfColor = workbook .getCustomPalette() .findColor( (byte) foreground.getRed(), (byte) foreground.getGreen(), (byte) foreground.getBlue()); if (hssfColor == null) hssfColor = workbook .getCustomPalette() .findSimilarColor( (byte) foreground.getRed(), (byte) foreground.getGreen(), (byte) foreground.getBlue()); boolean bold = (font.getStyle() & Font.BOLD) != 0; boolean italic = (font.getStyle() & Font.ITALIC) != 0; HSSFFont hssfFont = workbook.findFont( bold ? HSSFFont.BOLDWEIGHT_BOLD : 0, hssfColor.getIndex(), (short) (font.getSize() * 20), font.getName(), italic, false, (short) 0, (byte) 0); if (hssfFont == null) { hssfFont = workbook.createFont(); hssfFont.setBoldweight(bold ? HSSFFont.BOLDWEIGHT_BOLD : 0); hssfFont.setColor(hssfColor.getIndex()); hssfFont.setFontHeight((short) (font.getSize() * 20)); hssfFont.setFontName(font.getName()); hssfFont.setItalic(italic); hssfFont.setStrikeout(false); hssfFont.setTypeOffset((short) 0); hssfFont.setUnderline((byte) 0); } return hssfFont; }
@NotNull private static Font getFontWithLigaturesEnabled(Font font) { if (SystemInfo.isMac) { // Ligatures don't work on Mac for fonts loaded natively, so we need to locate and load font // manually File fontFile = findFileForFont(font, true); if (fontFile == null && font.getStyle() != Font.PLAIN) fontFile = findFileForFont(font.deriveFont(Font.PLAIN), true); if (fontFile == null) fontFile = findFileForFont(font, false); if (fontFile == null) return font; try { font = Font.createFont(Font.TRUETYPE_FONT, fontFile) .deriveFont(font.getStyle(), font.getSize()); } catch (Exception e) { return font; } } return font.deriveFont( Collections.singletonMap(TextAttribute.LIGATURES, TextAttribute.LIGATURES_ON)); }
@Override public UIDefaults getDefaults() { try { final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults"); superMethod.setAccessible(true); final UIDefaults metalDefaults = (UIDefaults) superMethod.invoke(new MetalLookAndFeel()); final UIDefaults defaults = (UIDefaults) superMethod.invoke(base); if (SystemInfo.isLinux) { if (!Registry.is("darcula.use.native.fonts.on.linux")) { Font font = findFont("DejaVu Sans"); if (font != null) { for (Object key : defaults.keySet()) { if (key instanceof String && ((String) key).endsWith(".font")) { defaults.put(key, new FontUIResource(font.deriveFont(13f))); } } } } else if (Arrays.asList("CN", "JP", "KR", "TW") .contains(Locale.getDefault().getCountry())) { for (Object key : defaults.keySet()) { if (key instanceof String && ((String) key).endsWith(".font")) { final Font font = defaults.getFont(key); if (font != null) { defaults.put(key, new FontUIResource("Dialog", font.getStyle(), font.getSize())); } } } } } LafManagerImpl.initInputMapDefaults(defaults); initIdeaDefaults(defaults); patchStyledEditorKit(defaults); patchComboBox(metalDefaults, defaults); defaults.remove("Spinner.arrowButtonBorder"); defaults.put("Spinner.arrowButtonSize", JBUI.size(16, 5).asUIResource()); MetalLookAndFeel.setCurrentTheme(createMetalTheme()); if (SystemInfo.isWindows && Registry.is("ide.win.frame.decoration")) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); } if (SystemInfo.isLinux && JBUI.isHiDPI()) { applySystemFonts(defaults); } defaults.put("EditorPane.font", defaults.getFont("TextField.font")); return defaults; } catch (Exception e) { log(e); } return super.getDefaults(); }
public MaritimeTradeView() { this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); Font font = new JButton().getFont(); Font newFont = font.deriveFont(font.getStyle(), 20); button = new JButton("Maritime Trade"); button.setFont(newFont); button.addActionListener(buttonListener); this.add(button); }
@Override public String toString(TextStyle ts) { StringBuilder obj = new StringBuilder(); // Store font info Font f = ts.getFont(); if (f != null) { obj.append(f.getFontName(Locale.ROOT)); if (f.getStyle() != Font.PLAIN) { obj.append('-'); if ((f.getStyle() & Font.BOLD) == Font.BOLD) { obj.append("bold"); } if ((f.getStyle() & Font.ITALIC) == Font.ITALIC) { obj.append("italic"); } } obj.append('-'); obj.append(f.getSize()); } obj.append(';'); // Store foreground Color fg = ts.getForeground(); if (fg != null) { obj.append(fg.getRGB()); } obj.append(';'); // Store background Color bg = ts.getBackground(); if (bg != null) { obj.append(bg.getRGB()); } return obj.toString(); }
/** * Copy the state of the parsed Textline into the existing object. * * @param t The TextLine to get the state information from. */ public void copyState(TextLine t) { if (t == null) return; font = t.getFont(); color = t.getColor(); justification = t.getJustification(); if (font == null) return; fontname = font.getName(); fontstyle = font.getStyle(); fontsize = font.getSize(); parse = true; }
@Override protected JComponent getRowPresentation( ParameterTableModelItemBase<ParameterInfoImpl> item, boolean selected, final boolean focused) { final JPanel panel = new JPanel(new BorderLayout()); final String typeText = item.typeCodeFragment.getText(); final String separator = StringUtil.repeatSymbol(' ', getTypesMaxLength() - typeText.length() + 1); String text = typeText + separator + item.parameter.getName(); final String defaultValue = item.defaultValueCodeFragment.getText(); String tail = ""; if (StringUtil.isNotEmpty(defaultValue)) { tail += " default value = " + defaultValue; } if (item.parameter.isUseAnySingleVariable()) { if (StringUtil.isNotEmpty(defaultValue)) { tail += ";"; } tail += " Use any var."; } if (!StringUtil.isEmpty(tail)) { text += " //" + tail; } final EditorTextField field = new EditorTextField(" " + text, getProject(), getFileType()) { @Override protected boolean shouldHaveBorder() { return false; } }; Font font = EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN); font = new Font(font.getFontName(), font.getStyle(), 12); field.setFont(font); if (selected && focused) { panel.setBackground(UIUtil.getTableSelectionBackground()); field.setAsRendererWithSelection( UIUtil.getTableSelectionBackground(), UIUtil.getTableSelectionForeground()); } else { panel.setBackground(UIUtil.getTableBackground()); if (selected && !focused) { panel.setBorder(new DottedBorder(UIUtil.getTableForeground())); } } panel.add(field, BorderLayout.WEST); return panel; }
public void setFont(Font f) { if (f != null) { String str = f.getName(); int style = f.getStyle(); String size = "" + f.getSize(); for (int i = 0; i < fontList.getModel().getSize(); i++) { String listStr = ((String) fontList.getModel().getElementAt(i)).toLowerCase(); if (listStr.equals(str.toLowerCase())) { Object value = fontList.getModel().getElementAt(i); fontList.setSelectedValue(value, true); fontBox.setText((String) value); break; } } switch (style) { case Font.PLAIN: styleList.setSelectedIndex(0); break; case Font.ITALIC: styleList.setSelectedIndex(2); break; case Font.BOLD: styleList.setSelectedIndex(1); break; case Font.BOLD | Font.ITALIC: styleList.setSelectedIndex(3); break; } boolean found = false; for (int i = 0; i < sizeList.getModel().getSize(); i++) { String listStr = ((String) sizeList.getModel().getElementAt(i)).toLowerCase(); if (listStr.equals(size.toLowerCase())) { Object value = sizeList.getModel().getElementAt(i); sizeList.setSelectedValue(value, true); sizeBox.setText((String) value); found = true; break; } } if (!found) { sizeBox.setText(size); } } }
public void startDrop(PieceType pieceType, CatanColor pieceColor, boolean isCancelAllowed) { this.setOpaque(false); this.setLayout(new BorderLayout()); this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH)); label = new JLabel(getLabelText(pieceType), JLabel.CENTER); label.setOpaque(true); label.setBackground(Color.white); Font labelFont = label.getFont(); labelFont = labelFont.deriveFont(labelFont.getStyle(), LABEL_TEXT_SIZE); label.setFont(labelFont); map = mainMap.copy(); map.setController(getController()); int prefWidth = (int) (mainMap.getScale() * mainMap.getPreferredSize().getWidth()); int prefHeight = (int) (mainMap.getScale() * mainMap.getPreferredSize().getHeight()); Dimension prefSize = new Dimension(prefWidth, prefHeight); map.setPreferredSize(prefSize); this.add(label, BorderLayout.NORTH); this.add(map, BorderLayout.CENTER); if (isCancelAllowed) { cancelButton = new JButton("Cancel"); Font buttonFont = cancelButton.getFont(); buttonFont = buttonFont.deriveFont(buttonFont.getStyle(), BUTTON_TEXT_SIZE); cancelButton.setFont(buttonFont); cancelButton.addActionListener(cancelButtonListener); this.add(cancelButton, BorderLayout.SOUTH); } map.startDrop(pieceType, pieceColor); }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (!(value instanceof Delimiter)) { return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } else { JLabel label = new JLabel(value.toString()); Font f = label.getFont(); label.setFont(f.deriveFont(f.getStyle() | Font.BOLD | Font.ITALIC)); Dimension size = label.getPreferredSize(); size.height += 5; label.setPreferredSize(size); return label; } }
/** * @param f Font * @return The script font version of the parsed font using the script_fraction variable. */ public Font getScriptFont(Font f) { int size; if (f == null) return f; size = f.getSize(); if (size <= MINIMUM_SIZE) return f; size = (int) ((double) (f.getSize()) * script_fraction + 0.5); if (size <= MINIMUM_SIZE) return f; return new Font(f.getName(), f.getStyle(), size); }