From f263dd53d355be86e5845b53d09b037bbcdc72cd Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 9 Jul 2002 17:48:23 +0000 Subject: [PATCH] moved in from other realms git-svn-id: https://samskivert.googlecode.com/svn/trunk@791 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/swing/JInternalDialog.java | 84 +++++++++++++++++++ .../com/samskivert/swing/SafeScrollPane.java | 27 ++++++ 2 files changed, 111 insertions(+) create mode 100644 projects/samskivert/src/java/com/samskivert/swing/JInternalDialog.java create mode 100644 projects/samskivert/src/java/com/samskivert/swing/SafeScrollPane.java diff --git a/projects/samskivert/src/java/com/samskivert/swing/JInternalDialog.java b/projects/samskivert/src/java/com/samskivert/swing/JInternalDialog.java new file mode 100644 index 00000000..88f1aa6d --- /dev/null +++ b/projects/samskivert/src/java/com/samskivert/swing/JInternalDialog.java @@ -0,0 +1,84 @@ +// +// $Id: JInternalDialog.java,v 1.1 2002/07/09 17:48:23 ray Exp $ + +package com.samskivert.swing; + +import java.awt.Component; + +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.JLayeredPane; + +/** + * Used for displaying dialogs internally. Be sure to use {@link + * #showDialog} and {@link #dismissDialog} to show and hide these dialogs + * because they need to do some extra fiddling that the regular show and + * hide wouldn't do. + */ +public class JInternalDialog extends JInternalFrame +{ + /** + * Creates a dialog that will display itself in the layered pane of + * the frame that contains the supplied component. + */ + public JInternalDialog (JComponent friend) + { + this(JLayeredPane.getLayeredPaneAbove(friend)); + } + + /** + * Creates a dialog that will display itself in the layered pane of + * the supplied frame. + */ + public JInternalDialog (JFrame frame) + { + this(frame.getLayeredPane()); + } + + /** + * Creates a dialog that will display itself in the specified layered + * pane. + */ + public JInternalDialog (JLayeredPane parent) + { + _parent = parent; + } + + /** + * Adds this dialog to its parent and shows it. + */ + public void showDialog () + { + _parent.add(this, JLayeredPane.PALETTE_LAYER); + setVisible(true); + } + + /** + * Hides this dialog and removes it from its parent. + */ + public void dismissDialog () + { + setVisible(false); + _parent.remove(this); + } + + /** + * Scans up the interface hierarchy looking for the {@link + * JInternalDialog} that contains the supplied child component and + * dismisses it. + */ + public static void dismissDialog (Component child) + { + if (child == null) { + return; + } else if (child instanceof JInternalDialog) { + ((JInternalDialog)child).dismissDialog(); + } else { + dismissDialog(child.getParent()); + } + } + + /** Our parent. */ + protected JLayeredPane _parent; +} diff --git a/projects/samskivert/src/java/com/samskivert/swing/SafeScrollPane.java b/projects/samskivert/src/java/com/samskivert/swing/SafeScrollPane.java new file mode 100644 index 00000000..2c3606ba --- /dev/null +++ b/projects/samskivert/src/java/com/samskivert/swing/SafeScrollPane.java @@ -0,0 +1,27 @@ +// +// $Id: SafeScrollPane.java,v 1.1 2002/07/09 17:48:23 ray Exp $ + +package com.samskivert.swing; + +import java.awt.Component; + +import javax.swing.JScrollPane; +import javax.swing.JViewport; + +/** + * A scroll pane that is safe to use in frame managed views. + */ +public class SafeScrollPane extends JScrollPane +{ + public SafeScrollPane (Component view) + { + super(view); + } + + protected JViewport createViewport () + { + JViewport vp = new JViewport(); + vp.setScrollMode(JViewport.SIMPLE_SCROLL_MODE); + return vp; + } +}