Example usage for java.awt Font getFamily

List of usage examples for java.awt Font getFamily

Introduction

In this page you can find the example usage for java.awt Font getFamily.

Prototype

public String getFamily() 

Source Link

Document

Returns the family name of this Font .

Usage

From source file:org.docx4all.ui.main.WordMLEditor.java

private JEditorPane createSourceView(WordMLTextPane editorView) {
    //Create the Source View
    JEditorPane sourceView = new JEditorPane();

    MutableAttributeSet attrs = new SimpleAttributeSet();
    StyleConstants.setFontFamily(attrs, FontManager.getInstance().getSourceViewFontFamilyName());
    StyleConstants.setFontSize(attrs, FontManager.getInstance().getSourceViewFontSize());

    // TODO - only do this if the font is available.
    Font font = new Font("Arial Unicode MS", Font.PLAIN, 12);

    System.out.println(font.getFamily());
    System.out.println(font.getFontName());
    System.out.println(font.getPSName());

    sourceView.setFont(font);/*  w w  w.jav  a  2s.  c o  m*/
    //sourceView.setFont(FontManager.getInstance().getFontInAction(attrs));

    sourceView.setContentType("text/xml; charset=UTF-16");

    // Instantiate a XMLEditorKit with wrapping enabled.
    XMLEditorKit kit = new XMLEditorKit(true);
    // Set the wrapping style.
    kit.setWrapStyleWord(true);

    sourceView.setEditorKit(kit);

    WordMLDocument editorViewDoc = (WordMLDocument) editorView.getDocument();

    try {
        editorViewDoc.readLock();

        editorView.getWordMLEditorKit().saveCaretText();

        DocumentElement elem = (DocumentElement) editorViewDoc.getDefaultRootElement();
        WordprocessingMLPackage wmlPackage = ((DocumentML) elem.getElementML()).getWordprocessingMLPackage();
        String filePath = (String) editorView.getDocument().getProperty(WordMLDocument.FILE_PATH_PROPERTY);

        //Do not include the last paragraph which is an extra paragraph.
        elem = (DocumentElement) elem.getElement(elem.getElementCount() - 1);
        ElementML paraML = elem.getElementML();
        ElementML bodyML = paraML.getParent();
        paraML.delete();

        Document doc = DocUtil.read(sourceView, wmlPackage);
        doc.putProperty(WordMLDocument.FILE_PATH_PROPERTY, filePath);
        doc.putProperty(WordMLDocument.WML_PACKAGE_PROPERTY, wmlPackage);
        doc.addDocumentListener(getToolbarStates());

        //Below are the properties used by bounce.jar library
        //See http://www.edankert.com/bounce/xmleditorkit.html
        doc.putProperty(PlainDocument.tabSizeAttribute, new Integer(4));
        doc.putProperty(XMLDocument.AUTO_INDENTATION_ATTRIBUTE, Boolean.TRUE);
        doc.putProperty(XMLDocument.TAG_COMPLETION_ATTRIBUTE, Boolean.TRUE);

        //Remember to put 'paraML' as last paragraph
        bodyML.addChild(paraML);

    } finally {
        editorViewDoc.readUnlock();
    }

    kit.setStyle(XMLStyleConstants.ATTRIBUTE_NAME, new Color(255, 0, 0), Font.PLAIN);

    sourceView.addFocusListener(getToolbarStates());
    //sourceView.setDocument(doc);
    sourceView.putClientProperty(Constants.LOCAL_VIEWS_SYNCHRONIZED_FLAG, Boolean.TRUE);

    return sourceView;
}

From source file:edu.ku.brc.ui.UIRegistry.java

/**
 * Check the font against the System base font.
 * @param font the new font.// w  w  w  . j  a  v  a  2s. c  om
 * @return the original System Base font if the family name and size matches. For some OSs the actual
 * System Base Font is different than creating it.
 */
public static Font adjustPerDefaultFont(final Font font) {
    return font.getFamily().equals(instance.defaultFont.getFamily())
            && instance.defaultFont.getSize() == font.getSize() ? instance.defaultFont : font;
}

From source file:Main.Interface_Main.java

private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed

    // for copying style
    JLabel label = new JLabel();
    Font font = label.getFont();

    // create some css from the label's font
    StringBuffer style = new StringBuffer("font-family:" + font.getFamily() + ";");
    style.append("font-weight:" + (font.isBold() ? "bold" : "normal") + ";");
    style.append("font-size:" + font.getSize() + "pt;");

    // html content
    JEditorPane ep = new JEditorPane("text/html", "<html><body style=\"" + style + "\">" //
            + "This application was designed by <A HREF=http://www.friedcircuits.us>FriedCircuits</A> for the USB Tester." //
            + "<br><br><center>App Version: " + appVersion + "<br>FW Version: " + FW_VERSION
            + "</center><br><br>*Connect once to get FW version.</body></html>");

    // handle link events
    ep.addHyperlinkListener(new HyperlinkListener() {
        @Override/*from  ww w. j a va2  s.  co m*/
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

                URI uri;
                try {
                    uri = new java.net.URI("www.friedcircuits.us");
                    if (desktop.isSupported(Desktop.Action.BROWSE)) {
                        try {
                            desktop.browse(uri);
                        } catch (IOException ex) {
                            Logger.getLogger(Interface_Main.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                } catch (URISyntaxException ex) {
                    Logger.getLogger(Interface_Main.class.getName()).log(Level.SEVERE, null, ex);
                }

            } // roll your own link launcher or use Desktop if J6+
        }
    });
    Color bgColor = label.getBackground();
    UIDefaults defaults = new UIDefaults();
    defaults.put("EditorPane[Enabled].backgroundPainter", bgColor);
    ep.putClientProperty("Nimbus.Overrides", defaults);
    ep.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
    ep.setEditable(false);
    ep.setBackground(bgColor);

    // show
    ImageIcon myCustomIcon = new ImageIcon(getClass().getResource("/faviconbot2edit.png"));
    JOptionPane.showMessageDialog(plCurrent, ep, "About", JOptionPane.INFORMATION_MESSAGE, myCustomIcon);
}

From source file:org.mwc.cmap.xyplot.views.XYPlotView.java

private void storeFont(final IMemento memento, final String entryHeader, final Font theFont) {
    // write elements
    memento.putInteger(entryHeader + "_SIZE", theFont.getSize());
    memento.putString(entryHeader + "_FAMILY", theFont.getFamily());
    memento.putInteger(entryHeader + "_STYLE", theFont.getStyle());
}

From source file:net.ontopia.topicmaps.viz.VizTopicMapConfigurationManager.java

private String serializeFont(Font font) {
    // Fonts are serialized to the form:
    // "<family name>-<style>-<size>"

    StringBuilder buffer = new StringBuilder();
    buffer.append(font.getFamily());
    buffer.append("-");
    buffer.append(font.getStyle());/*  w w w. j  av  a  2s  .c  o  m*/
    buffer.append("-");
    buffer.append(font.getSize());

    String result = buffer.toString();

    fontCache.put(result, font);

    return result;
}

From source file:co.foldingmap.mapImportExport.SvgExporter.java

private void exportMapLabel(BufferedWriter outputStream, MapLabel label) {

    Color outlineColor, fillColor;
    float x, y;//w w w .ja  v a 2  s .  c  o m
    Font labelFont;
    String style, fontStyle;

    try {
        labelFont = label.getFont();

        //construct style
        if (label.getFillColor() != null) {
            fillColor = label.getFillColor();
        } else {
            fillColor = Color.BLACK;
        }

        if (label.getOutlineColor() != null) {
            outlineColor = label.getOutlineColor();
        } else {
            outlineColor = Color.WHITE;
        }

        if (labelFont.getStyle() == Font.BOLD) {
            fontStyle = "font-weight=\"bold\"";
        } else if (labelFont.getStyle() == Font.PLAIN) {
            fontStyle = "font-style=\"normal\"";
        } else if (labelFont.getStyle() == Font.ITALIC) {
            fontStyle = "font-style=\"italic\"";
        } else {
            fontStyle = "";
        }

        style = "font-family=\"" + labelFont.getFamily() + "\" font-size=\"" + labelFont.getSize() + "\" "
                + fontStyle + " ";

        outputStream.write(getIndent());
        outputStream.write("<g " + style + ">\n");
        addIndent();

        style = "fill:#" + getHexColor(fillColor) + ";stroke:#" + getHexColor(outlineColor);

        if (label instanceof PointLabel) {
            PointLabel pointLabel = (PointLabel) label;

            x = pointLabel.getLine1StartPoint().x;
            y = pointLabel.getLine1StartPoint().y;

            outputStream.write(getIndent());
            outputStream.write("<text x=\"");
            outputStream.write(Float.toString(x));
            outputStream.write("\" y=\"");
            outputStream.write(Float.toString(y));
            outputStream.write("\" style=\"");
            outputStream.write(style);
            outputStream.write("\">\n");

            addIndent();
            outputStream.write(getIndent());
            outputStream.write("<tspan x=\"");
            outputStream.write(Float.toString(x));
            outputStream.write("\" y=\"");
            outputStream.write(Float.toString(y));
            outputStream.write("\">");
            outputStream.write(pointLabel.getLine1Text());
            outputStream.write("</tspan>\n");

            if (pointLabel.getLine2Text() != null && pointLabel.getLine2Text().length() > 0) {
                x = pointLabel.getLine2StartPoint().x;
                y = pointLabel.getLine2StartPoint().y;

                if (x != 0 && y != 0) {
                    outputStream.write(getIndent());
                    outputStream.write("<tspan x=\"");
                    outputStream.write(Float.toString(x));
                    outputStream.write("\" y=\"");
                    outputStream.write(Float.toString(y));
                    outputStream.write("\">");
                    outputStream.write(pointLabel.getLine2Text());
                    outputStream.write("</tspan>\n");
                }
            }

            removeIndent();
            outputStream.write(getIndent());
            outputStream.write("</text>\n");

            removeIndent();
            outputStream.write(getIndent());
            outputStream.write("</g>\n");
        } else if (label instanceof LineStringLabel) {
            LineStringLabel lineLabel = (LineStringLabel) label;

        } else if (label instanceof PolygonLabel) {
            PolygonLabel polyLabel = (PolygonLabel) label;

        }

    } catch (Exception e) {
        Logger.log(Logger.ERR, "Error in SvgExporter.exportMapLabel(BufferedWriter, MapLabel) - " + e);
    }
}

From source file:edu.ku.brc.ui.UIRegistry.java

/**
 * Creates the initial font mapping from the base font size to the other sizes.
 * @param clazz the class of the component
 * @param baseFontArg the base font size
 *//*from   w  ww  . j  a  v  a2  s .co m*/
protected static void adjustAllFonts(final Font oldBaseFont, final Font baseFontArg) {
    if (oldBaseFont != null && baseFontArg != null) {
        int fontSize = baseFontArg.getSize();
        int oldFontSize = oldBaseFont.getSize();
        String family = baseFontArg.getFamily();

        UIDefaults uiDefaults = UIManager.getDefaults();
        Enumeration<Object> e = uiDefaults.keys();
        while (e.hasMoreElements()) {
            Object key = e.nextElement();
            if (key.toString().endsWith(".font")) {
                FontUIResource fontUIRes = (FontUIResource) uiDefaults.get(key);
                if (fontSize != fontUIRes.getSize() || !family.equals(fontUIRes.getFamily())) {
                    UIManager.put(key, new FontUIResource(new Font(family, fontUIRes.getStyle(),
                            fontSize + (fontUIRes.getSize() - oldFontSize))));
                }
            }
        }
    }
}

From source file:ro.nextreports.engine.exporter.ResultExporter.java

private void buildCellFont(Map<String, Object> format, Font font) {
    format.put(StyleFormatConstants.FONT_FAMILY_KEY, font.getFamily());
    format.put(StyleFormatConstants.FONT_NAME_KEY, font.getName());
    format.put(StyleFormatConstants.FONT_SIZE, new Float(font.getSize()));
    if (Font.PLAIN == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_NORMAL);
    }//from   w  ww .  j a va2s . co m
    if (Font.BOLD == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_BOLD);
    }
    if (Font.ITALIC == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_ITALIC);
    }
    if ((Font.BOLD | Font.ITALIC) == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_BOLDITALIC);
    }
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

public void setSelectedFont(Font selectedFont) {
    this.selectedFont = selectedFont;

    fontNameTextLabel.setText(selectedFont.getFamily());
    fontSizeTextLabel.setText("" + selectedFont.getSize());
    setFontStyleText(selectedFont.getStyle());

    invalidate();/*from   w  w w.  ja  va2  s .co  m*/
    validate();
    repaint();
}

From source file:VASSAL.launch.ModuleManagerWindow.java

public ModuleManagerWindow() {
    setTitle("VASSAL");
    setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));

    ApplicationIcons.setFor(this);

    final AbstractAction shutDownAction = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            if (!AbstractLaunchAction.shutDown())
                return;

            final Prefs gl = Prefs.getGlobalPrefs();
            try {
                gl.write();/* w ww . j ava2 s.co m*/
                gl.close();
            } catch (IOException ex) {
                WriteErrorDialog.error(ex, gl.getFile());
            } finally {
                IOUtils.closeQuietly(gl);
            }

            logger.info("Exiting");
            System.exit(0);
        }
    };
    shutDownAction.putValue(Action.NAME, Resources.getString(Resources.QUIT));

    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            shutDownAction.actionPerformed(null);
        }
    });

    // setup menubar and actions
    final MenuManager mm = MenuManager.getInstance();
    final MenuBarProxy mb = mm.getMenuBarProxyFor(this);

    // file menu
    final MenuProxy fileMenu = new MenuProxy(Resources.getString("General.file"));
    fileMenu.setMnemonic(Resources.getString("General.file.shortcut").charAt(0));

    fileMenu.add(mm.addKey("Main.play_module"));
    fileMenu.add(mm.addKey("Main.edit_module"));
    fileMenu.add(mm.addKey("Main.new_module"));
    fileMenu.add(mm.addKey("Main.import_module"));
    fileMenu.addSeparator();

    if (!SystemUtils.IS_OS_MAC_OSX) {
        fileMenu.add(mm.addKey("Prefs.edit_preferences"));
        fileMenu.addSeparator();
        fileMenu.add(mm.addKey("General.quit"));
    }

    // tools menu
    final MenuProxy toolsMenu = new MenuProxy(Resources.getString("General.tools"));

    // Initialize Global Preferences
    Prefs.getGlobalPrefs().getEditor().initDialog(this);
    Prefs.initSharedGlobalPrefs();

    final BooleanConfigurer serverStatusConfig = new BooleanConfigurer(SHOW_STATUS_KEY, null, Boolean.FALSE);
    Prefs.getGlobalPrefs().addOption(null, serverStatusConfig);

    dividerLocationConfig = new IntConfigurer(DIVIDER_LOCATION_KEY, null, -10);
    Prefs.getGlobalPrefs().addOption(null, dividerLocationConfig);

    toolsMenu.add(new CheckBoxMenuItemProxy(new AbstractAction(Resources.getString("Chat.server_status")) {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            serverStatusView.toggleVisibility();
            serverStatusConfig.setValue(serverStatusConfig.booleanValue() ? Boolean.FALSE : Boolean.TRUE);
            if (serverStatusView.isVisible()) {
                setDividerLocation(getPreferredDividerLocation());
            }
        }
    }, serverStatusConfig.booleanValue()));

    // help menu
    final MenuProxy helpMenu = new MenuProxy(Resources.getString("General.help"));
    helpMenu.setMnemonic(Resources.getString("General.help.shortcut").charAt(0));

    helpMenu.add(mm.addKey("General.help"));
    helpMenu.add(mm.addKey("Main.tour"));
    helpMenu.addSeparator();
    helpMenu.add(mm.addKey("UpdateCheckAction.update_check"));
    helpMenu.add(mm.addKey("Help.error_log"));

    if (!SystemUtils.IS_OS_MAC_OSX) {
        helpMenu.addSeparator();
        helpMenu.add(mm.addKey("AboutScreen.about_vassal"));
    }

    mb.add(fileMenu);
    mb.add(toolsMenu);
    mb.add(helpMenu);

    // add actions
    mm.addAction("Main.play_module", new Player.PromptLaunchAction(this));
    mm.addAction("Main.edit_module", new Editor.PromptLaunchAction(this));
    mm.addAction("Main.new_module", new Editor.NewModuleLaunchAction(this));
    mm.addAction("Main.import_module", new Editor.PromptImportLaunchAction(this));
    mm.addAction("Prefs.edit_preferences", Prefs.getGlobalPrefs().getEditor().getEditAction());
    mm.addAction("General.quit", shutDownAction);

    URL url = null;
    try {
        url = new File(Documentation.getDocumentationBaseDir(), "README.html").toURI().toURL();
    } catch (MalformedURLException e) {
        ErrorDialog.bug(e);
    }
    mm.addAction("General.help", new ShowHelpAction(url, null));

    mm.addAction("Main.tour", new LaunchTourAction(this));
    mm.addAction("AboutScreen.about_vassal", new AboutVASSALAction(this));
    mm.addAction("UpdateCheckAction.update_check", new UpdateCheckAction(this));
    mm.addAction("Help.error_log", new ShowErrorLogAction(this));

    setJMenuBar(mm.getMenuBarFor(this));

    // Load Icons
    moduleIcon = new ImageIcon(getClass().getResource("/images/mm-module.png"));
    activeExtensionIcon = new ImageIcon(getClass().getResource("/images/mm-extension-active.png"));
    inactiveExtensionIcon = new ImageIcon(getClass().getResource("/images/mm-extension-inactive.png"));
    openGameFolderIcon = new ImageIcon(getClass().getResource("/images/mm-gamefolder-open.png"));
    closedGameFolderIcon = new ImageIcon(getClass().getResource("/images/mm-gamefolder-closed.png"));
    fileIcon = new ImageIcon(getClass().getResource("/images/mm-file.png"));

    // build module controls
    final JPanel moduleControls = new JPanel(new BorderLayout());
    modulePanelLayout = new CardLayout();
    moduleView = new JPanel(modulePanelLayout);
    buildTree();
    final JScrollPane scroll = new JScrollPane(tree);
    moduleView.add(scroll, "modules");

    final JEditorPane l = new JEditorPane("text/html", Resources.getString("ModuleManager.quickstart"));
    l.setEditable(false);

    // Try to get background color and font from LookAndFeel;
    // otherwise, use dummy JLabel to get color and font.
    Color bg = UIManager.getColor("control");
    Font font = UIManager.getFont("Label.font");

    if (bg == null || font == null) {
        final JLabel dummy = new JLabel();
        if (bg == null)
            bg = dummy.getBackground();
        if (font == null)
            font = dummy.getFont();
    }

    l.setBackground(bg);
    ((HTMLEditorKit) l.getEditorKit()).getStyleSheet()
            .addRule("body { font: " + font.getFamily() + " " + font.getSize() + "pt }");

    l.addHyperlinkListener(BrowserSupport.getListener());

    // FIXME: use MigLayout for this!
    // this is necessary to get proper vertical alignment
    final JPanel p = new JPanel(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    p.add(l, c);

    moduleView.add(p, "quickStart");
    modulePanelLayout.show(moduleView, getModuleCount() == 0 ? "quickStart" : "modules");
    moduleControls.add(moduleView, BorderLayout.CENTER);
    moduleControls.setBorder(new TitledBorder(Resources.getString("ModuleManager.recent_modules")));

    add(moduleControls);

    // build server status controls
    final ServerStatusView serverStatusControls = new ServerStatusView(new CgiServerStatus());
    serverStatusControls.setBorder(new TitledBorder(Resources.getString("Chat.server_status")));

    serverStatusView = new ComponentSplitter().splitRight(moduleControls, serverStatusControls, false);
    serverStatusView.revalidate();

    // show the server status controls according to the prefs
    if (serverStatusConfig.booleanValue()) {
        serverStatusView.showComponent();
    }

    setDividerLocation(getPreferredDividerLocation());
    serverStatusView.addPropertyChangeListener("dividerLocation", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            setPreferredDividerLocation((Integer) e.getNewValue());
        }
    });

    final Rectangle r = Info.getScreenBounds(this);
    serverStatusControls.setPreferredSize(new Dimension((int) (r.width / 3.5), 0));

    setSize(3 * r.width / 4, 3 * r.height / 4);

    // Save/load the window position and size in prefs
    final PositionOption option = new PositionOption(PositionOption.key + "ModuleManager", this);
    Prefs.getGlobalPrefs().addOption(option);
}