Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/JFrameWrapper.java
41161 views
/*1* Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.ui;2526import java.awt.*;27import java.awt.event.*;28import javax.swing.*;2930public class JFrameWrapper implements FrameWrapper {31private JFrame frame;32private boolean hasWindowListener;33private ActionListener closingActionListener;34private ActionListener activatedActionListener;3536public JFrameWrapper(JFrame frame) {37this.frame = frame;38}3940public Component getComponent() { return frame; }41public Container getContentPane() { return frame.getContentPane(); }42public void setVisible(boolean visible) { frame.setVisible(visible); }43public void setSize(int x, int y) { frame.setSize(x, y); }44public void pack() { frame.pack(); }45public void show() { frame.setVisible(true); }46public void dispose() { frame.dispose(); }47public void setBackground(Color color) { frame.setBackground(color); }48public void setResizable(boolean resizable) { frame.setResizable(resizable); }4950public void setClosable(boolean closable) {51if (closable) {52frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);53} else {54frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);55}56}5758public void setClosingActionListener(ActionListener l) {59closingActionListener = l;60maybeInstallWindowListener();61}6263public void setActivatedActionListener(ActionListener l) {64activatedActionListener = l;65maybeInstallWindowListener();66}6768public void toFront() {69frame.toFront();70frame.requestFocus();71}7273//----------------------------------------------------------------------74// Internals only below this point75//7677private void maybeInstallWindowListener() {78if (!hasWindowListener) {79frame.addWindowListener(new WindowAdapter() {80public void windowClosing(WindowEvent e) {81if (closingActionListener != null) {82closingActionListener.actionPerformed(null);83}84}8586public void windowActivated(WindowEvent e) {87if (activatedActionListener != null) {88activatedActionListener.actionPerformed(null);89}90}91});92hasWindowListener = true;93}94}95}969798