Path: blob/master/src/demo/share/jfc/J2Ddemo/java2d/GlobalPanel.java
41154 views
/*1*2* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7*8* - Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10*11* - Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* - Neither the name of Oracle nor the names of its16* contributors may be used to endorse or promote products derived17* from this software without specific prior written permission.18*19* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS20* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,21* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR22* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR23* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,24* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,25* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR26* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF27* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING28* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS29* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/31package java2d;323334import java.awt.BorderLayout;35import java.awt.GridBagLayout;36import javax.swing.JPanel;37import javax.swing.border.BevelBorder;38import javax.swing.border.CompoundBorder;39import javax.swing.border.EmptyBorder;40import javax.swing.event.ChangeEvent;41import javax.swing.event.ChangeListener;424344/**45* Panel that holds the Demo groups, Controls and Monitors for each tab.46* It's a special "always visible" panel for the Controls, MemoryMonitor &47* PerformanceMonitor.48*/49@SuppressWarnings("serial")50public class GlobalPanel extends JPanel implements ChangeListener {51private final DemoInstVarsAccessor demoInstVars;52private JPanel p;53private int index;5455public GlobalPanel(DemoInstVarsAccessor demoInstVars) {56this.demoInstVars = demoInstVars;5758setLayout(new BorderLayout());59p = new JPanel(new GridBagLayout());60EmptyBorder eb = new EmptyBorder(5, 0, 5, 5);61BevelBorder bb = new BevelBorder(BevelBorder.LOWERED);62p.setBorder(new CompoundBorder(eb, bb));63J2Ddemo.addToGridBag(p, demoInstVars.getControls(), 0, 0, 1, 1, 0, 0);64J2Ddemo.addToGridBag(p, demoInstVars.getMemoryMonitor(), 0, 1, 1, 1, 0, 0);65J2Ddemo.addToGridBag(p, demoInstVars.getPerformanceMonitor(), 0, 2, 1, 1, 0, 0);66add(demoInstVars.getIntro());67}6869@Override70public void stateChanged(ChangeEvent e) {7172demoInstVars.getGroup()[index].shutDown(demoInstVars.getGroup()[index].getPanel());73if (demoInstVars.getTabbedPane().getSelectedIndex() == 0) {74demoInstVars.getMemoryMonitor().surf.stop();75demoInstVars.getPerformanceMonitor().surf.stop();76removeAll();77add(demoInstVars.getIntro());78demoInstVars.getIntro().start();79} else {80if (getComponentCount() == 1) {81demoInstVars.getIntro().stop();82remove(demoInstVars.getIntro());83add(p, BorderLayout.EAST);84if (demoInstVars.getMemoryCB().getState()) {85demoInstVars.getMemoryMonitor().surf.start();86}87if (demoInstVars.getPerfCB().getState()) {88demoInstVars.getPerformanceMonitor().surf.start();89}90} else {91remove(demoInstVars.getGroup()[index]);92}93index = demoInstVars.getTabbedPane().getSelectedIndex() - 1;94add(demoInstVars.getGroup()[index]);95demoInstVars.getGroup()[index].setup(false);96}97revalidate();98}99}100101102