1/*
2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 6348456
27 * @summary Tests model changing
28 * @author Sergey Malenkov
29 * @run applet/manual=yesno Test6348456.html
30 */
31
32import java.awt.BorderLayout;
33import java.awt.Color;
34import java.awt.event.ActionEvent;
35import java.awt.event.ActionListener;
36import javax.swing.JApplet;
37import javax.swing.JButton;
38import javax.swing.JColorChooser;
39import javax.swing.colorchooser.DefaultColorSelectionModel;
40
41public final class Test6348456 extends JApplet implements ActionListener {
42
43    private static final DefaultColorSelectionModel WHITE = new DefaultColorSelectionModel(Color.WHITE);
44    private static final DefaultColorSelectionModel BLACK = new DefaultColorSelectionModel(Color.BLACK);
45
46    private JColorChooser chooser;
47
48    @Override
49    public void init() {
50        JButton button = new JButton("Swap models");
51        button.addActionListener(this);
52
53        this.chooser = new JColorChooser(Color.RED);
54        this.chooser.setSelectionModel(WHITE);
55
56        add(BorderLayout.NORTH, button);
57        add(BorderLayout.CENTER, this.chooser);
58    }
59
60    public void actionPerformed(ActionEvent event){
61        this.chooser.setSelectionModel(this.chooser.getSelectionModel() == BLACK ? WHITE : BLACK);
62    }
63}
64