001/*
002 * (C) Copyright 2006-2010 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bstefanescu
016 */
017package org.nuxeo.shell.swing.cmds;
018
019import java.awt.Font;
020
021import org.nuxeo.shell.Command;
022import org.nuxeo.shell.Context;
023import org.nuxeo.shell.Shell;
024import org.nuxeo.shell.ShellException;
025import org.nuxeo.shell.swing.Console;
026import org.nuxeo.shell.swing.Theme;
027import org.nuxeo.shell.swing.widgets.JFontChooser;
028
029/**
030 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
031 */
032@Command(name = "font", help = "Modify the font used by the shell. This command is available only in UI mode.")
033public class FontCommand implements Runnable {
034
035    @Context
036    protected Shell shell;
037
038    @Context
039    protected Console console;
040
041    public void run() {
042        try {
043            JFontChooser fc = new JFontChooser();
044            fc.setSelectedFont(console.getFont());
045            int result = fc.showDialog(console);
046            if (result == JFontChooser.OK_OPTION) {
047                Font font = fc.getSelectedFont();
048                Theme theme = console.getTheme();
049                theme.setName("Custom");
050                theme.setFont(font);
051                shell.setSetting("theme.Custom", theme.toString());
052                console.setTheme(theme);
053            }
054        } catch (Exception e) {
055            throw new ShellException(e);
056        }
057    }
058
059}