Example usage for javax.swing UIManager getFont

List of usage examples for javax.swing UIManager getFont

Introduction

In this page you can find the example usage for javax.swing UIManager getFont.

Prototype

public static Font getFont(Object key) 

Source Link

Document

Returns a font from the defaults.

Usage

From source file:org.yccheok.jstock.gui.Utils.java

private static Font _getRobotoLightFont() {
    InputStream inputStream = Utils.class.getResourceAsStream("/assets/fonts/Roboto-Light.ttf");
    try {/*from  w  w w . j  a  v  a  2  s  .c o m*/
        Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
        if (font != null) {
            return font;
        }
    } catch (FontFormatException ex) {
        log.error(null, ex);
    } catch (IOException ex) {
        log.error(null, ex);
    } finally {
        org.yccheok.jstock.file.Utils.close(inputStream);
    }
    Font oldLabelFont = UIManager.getFont("Label.font");
    return oldLabelFont;
}

From source file:phex.gui.tabs.download.DownloadOverviewPanel.java

private JPanel buildInfo2Panel() {
    JPanel subPanel = new JPanel();
    CellConstraints cc = new CellConstraints();

    String systemExtraCols = "";
    if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) {
        systemExtraCols = ", 4dlu, d";
    }/* w w  w .  j av a  2  s  .co m*/
    FormLayout layout = new FormLayout("d, 4dlu, 1dlu:grow" + systemExtraCols, // columns
            "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p"); //rows
    PanelBuilder panelBuilder = new PanelBuilder(layout, subPanel);

    panelBuilder.addSeparator(Localizer.getString("DownloadOverview_Information"),
            cc.xywh(1, 1, layout.getColumnCount(), 1));

    JLabel label = new JLabel(Localizer.getString("DownloadOverview_FileName"));
    panelBuilder.add(label, cc.xy(1, 3));
    fileNameTxt = new JTextField();
    fileNameTxt.setEditable(false);
    fileNameTxt.setFont(UIManager.getFont("Label.font"));
    fileNameTxt.setForeground(UIManager.getColor("Label.foreground"));
    fileNameTxt.setBackground(UIManager.getColor("Label.background"));
    fileNameTxt.setMinimumSize(new Dimension(0, 0));
    panelBuilder.add(fileNameTxt, cc.xy(3, 3));

    label = new JLabel(Localizer.getString("DownloadOverview_IncompleteFile"));
    panelBuilder.add(label, cc.xy(1, 5));
    incompleteFileTxt = new JTextField();
    incompleteFileTxt.setEditable(false);
    incompleteFileTxt.setFont(UIManager.getFont("Label.font"));
    incompleteFileTxt.setForeground(UIManager.getColor("Label.foreground"));
    incompleteFileTxt.setBackground(UIManager.getColor("Label.background"));
    panelBuilder.add(incompleteFileTxt, cc.xy(3, 5));

    if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) {
        exploreFileBtn = new JButton();
        exploreFileBtn.setToolTipText(Localizer.getString("DownloadOverview_Explore"));
        exploreFileBtn.setMargin(GUIUtils.EMPTY_INSETS);
        exploreFileBtn.addActionListener(new ExploreActionListener());
        panelBuilder.add(exploreFileBtn, cc.xy(5, 5));
    }

    return subPanel;
}

From source file:studio.core.EntryPoint.java

public static void main(final String[] args) {
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

    if (System.getProperty("mrj.version") != null) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        //     System.setProperty("apple.awt.brushMetalLook", "true");
        System.setProperty("apple.awt.showGrowBox", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Studio for kdb+");
        System.setProperty("com.apple.mrj.application.live-resize", "true");
        System.setProperty("com.apple.macos.smallTabs", "true");
        System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
    }//ww  w . j  a  va2 s .com

    if (Config.getInstance().getLookAndFeel() != null) {
        try {
            UIManager.setLookAndFeel(Config.getInstance().getLookAndFeel());
        } catch (Exception ex) {
            // go on with default one
            ex.printStackTrace();
        }
    }
    final CommandLineParser cmdLineGnuParser = new GnuParser();
    try {
        CommandLine commandLine = cmdLineGnuParser.parse(constructGnuOptions(), args);
        if (commandLine.hasOption("servers")) {
            String fileName = commandLine.getOptionValue("servers");
            Config.getInstance().loadFromFile(fileName);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    studio.ui.I18n.setLocale(Locale.getDefault());

    //   studio.ui.I18n.setLocale(new Locale("zh", "cn"));

    if (!Config.getInstance().getAcceptedLicense()) {
        LicensePanel panel = new LicensePanel();
        Object[] options = new String[] { "Accept", "Do Not Accept" };
        int answer = JOptionPane.showOptionDialog(null, panel, "Studio for kdb+", JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, Studio.getImage(Config.imageBase + "32x32/question.png"), //do not use a custom Icon
                options, //the titles of buttons
                options[1]); //default button title

        if (answer == JOptionPane.NO_OPTION)
            System.exit(0);

        Config.getInstance().setAcceptedLicense(Lm.buildDate);
    }

    UIManager.put("Table.font", new javax.swing.plaf.FontUIResource("Monospaced", Font.PLAIN,
            UIManager.getFont("Table.font").getSize()));
    System.setProperty("awt.useSystemAAFontSettings", "on");
    System.setProperty("swing.aatext", "true");

    ThreadGroup exceptionThreadGroup = new ExceptionGroup();

    new Thread(exceptionThreadGroup, "Init thread") {
        public void run() {
            Studio.init(args);
        }
    }.start();

}

From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.GiftCloudDialogs.java

public void showMessage(final String message) throws HeadlessException {

    final JPanel messagePanel = new JPanel(new GridBagLayout());
    final JEditorPane textField = new JEditorPane();
    textField.setContentType("text/html");
    textField.setText(message);//from w  ww  .  j a  v a 2s  .  co  m
    textField.setEditable(false);
    textField.setBackground(null);
    textField.setBorder(null);
    textField.setEditable(false);
    textField.setForeground(UIManager.getColor("Label.foreground"));
    textField.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
    textField.setFont(UIManager.getFont("Label.font"));
    textField.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (IOException e1) {
                        // Ignore failure to launch URL
                    } catch (URISyntaxException e1) {
                        // Ignore failure to launch URL
                    }
                }
            }
        }
    });

    messagePanel.add(textField);
    textField.setAlignmentX(SwingConstants.CENTER);

    JOptionPane.showMessageDialog(mainFrame.getContainer(), messagePanel, applicationName,
            JOptionPane.INFORMATION_MESSAGE, icon);
}

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();/*from  www . j  ava  2 s  . c  o 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);
}