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.Color;
020
021import javax.swing.JColorChooser;
022import javax.swing.colorchooser.DefaultColorSelectionModel;
023
024import org.nuxeo.shell.Command;
025import org.nuxeo.shell.Context;
026import org.nuxeo.shell.Shell;
027import org.nuxeo.shell.ShellException;
028import org.nuxeo.shell.swing.Console;
029import org.nuxeo.shell.swing.Theme;
030
031/**
032 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
033 */
034@Command(name = "background", help = "Modify the background color used by the shell. This command is available only in UI mode.")
035public class BgColorCommand implements Runnable {
036
037    @Context
038    protected Shell shell;
039
040    @Context
041    protected Console console;
042
043    public void run() {
044        try {
045            DefaultColorSelectionModel model = new DefaultColorSelectionModel(console.getBackground());
046            JColorChooser cc = new JColorChooser();
047            cc.setSelectionModel(model);
048            Color color = JColorChooser.showDialog(console, "Select the background color", console.getBackground());
049            if (color != null) {
050                Theme theme = console.getTheme();
051                theme.setName("Custom");
052                theme.setBgColor(color);
053                shell.setSetting("theme.Custom", theme.toString());
054                console.setTheme(theme);
055            }
056        } catch (Exception e) {
057            throw new ShellException(e);
058        }
059    }
060
061}