001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.modules.profiler.ui.stp;
042:
043: import java.awt.Container;
044: import java.awt.Dimension;
045: import java.awt.Rectangle;
046: import java.awt.event.ActionEvent;
047: import java.awt.event.ActionListener;
048: import java.util.Vector;
049: import javax.swing.JPanel;
050: import javax.swing.JViewport;
051: import javax.swing.Scrollable;
052: import javax.swing.event.ChangeEvent;
053: import javax.swing.event.ChangeListener;
054:
055: /**
056: *
057: * @author Jiri Sedlacek
058: */
059: public class DefaultSettingsPanel extends JPanel implements Scrollable {
060: //~ Inner Classes ------------------------------------------------------------------------------------------------------------
061:
062: private class SettingsChangeListener implements ActionListener,
063: ChangeListener /*, DocumentListener*/{
064: //~ Methods --------------------------------------------------------------------------------------------------------------
065:
066: public void actionPerformed(ActionEvent e) {
067: fireSettingsChanged();
068: }
069:
070: public void stateChanged(ChangeEvent e) {
071: fireSettingsChanged();
072: }
073:
074: // public void insertUpdate(DocumentEvent e) { fireSettingsChanged(); }
075: // public void removeUpdate(DocumentEvent e) { fireSettingsChanged(); }
076: // public void changedUpdate(DocumentEvent e) { fireSettingsChanged(); }
077: }
078:
079: //~ Instance fields ----------------------------------------------------------------------------------------------------------
080:
081: private SettingsChangeListener settingsChangeListener;
082: private Vector<ChangeListener> changeListeners;
083:
084: //~ Constructors -------------------------------------------------------------------------------------------------------------
085:
086: public DefaultSettingsPanel() {
087: setOpaque(true);
088: setBackground(SelectProfilingTask.BACKGROUND_COLOR);
089:
090: changeListeners = new Vector();
091: settingsChangeListener = new SettingsChangeListener();
092: }
093:
094: //~ Methods ------------------------------------------------------------------------------------------------------------------
095:
096: public Dimension getPreferredScrollableViewportSize() {
097: return null;
098: }
099:
100: public int getScrollableBlockIncrement(Rectangle visibleRect,
101: int orientation, int direction) {
102: // Scroll almost one screen
103: Container parent = getParent();
104:
105: if ((parent == null) || !(parent instanceof JViewport)) {
106: return 50;
107: }
108:
109: return (int) (((JViewport) parent).getHeight() * 0.95f);
110: }
111:
112: public boolean getScrollableTracksViewportHeight() {
113: // Allow dynamic vertical enlarging of the panel but request the vertical scrollbar when needed
114: Container parent = getParent();
115:
116: if ((parent == null) || !(parent instanceof JViewport)) {
117: return false;
118: }
119:
120: return getPreferredSize().height < ((JViewport) parent)
121: .getHeight();
122: }
123:
124: public boolean getScrollableTracksViewportWidth() {
125: return true;
126: }
127:
128: public int getScrollableUnitIncrement(Rectangle visibleRect,
129: int orientation, int direction) {
130: return 20;
131: }
132:
133: public void addChangeListener(ChangeListener listener) {
134: if (!changeListeners.contains(listener)) {
135: changeListeners.add(listener);
136: }
137: }
138:
139: public void removeChangeListener(ChangeListener listener) {
140: changeListeners.remove(listener);
141: }
142:
143: SettingsChangeListener getSettingsChangeListener() {
144: return settingsChangeListener;
145: }
146:
147: private void fireSettingsChanged() {
148: for (ChangeListener listener : changeListeners) {
149: listener.stateChanged(new ChangeEvent(this));
150: }
151: }
152: }
|