bibliothek.gui.dock.util.CoreWarningDialog Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docking-frames-core Show documentation
Show all versions of docking-frames-core Show documentation
A window docking framework for Swing
The newest version!
/*
* Bibliothek - DockingFrames
* Library built on Java/Swing, allows the user to "drag and drop"
* panels containing any Swing-Component the developer likes to add.
*
* Copyright (C) 2013 Benjamin Sigg
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Benjamin Sigg
* [email protected]
* CH - Switzerland
*/
package bibliothek.gui.dock.util;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Method;
import java.net.URI;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.Timer;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import bibliothek.util.Version;
/**
* The {@link CoreWarningDialog} is an annoying little dialog informing a developer that he/she is using
* the Core API, even tough the Common API would offer much more features.
* @author Benjamin Sigg
*/
public class CoreWarningDialog extends JPanel{
public static void main( String[] args ){
showDialog();
}
/**
* Opens the dialog, the dialog is modal and will attempt to steal the focus.
*/
public static void showDialog(){
JDialog dialog = new JDialog();
dialog.setModal( true );
dialog.setTitle( "Information from DockingFrames " + Version.CURRENT );
dialog.setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
dialog.add( new CoreWarningDialog( dialog ) );
dialog.pack();
dialog.setLocationRelativeTo( null );
dialog.setVisible( true );
}
private JDialog dialog;
private JButton close;
private CoreWarningDialog( JDialog dialog ){
this.dialog = dialog;
JTextPane info = new JTextPane();
info.setContentType( "text/html" );
info.setText( createMessage() );
info.setEditable( false );
initHyperlinking( info );
close = new JButton();
setLayout( new GridBagLayout() );
add( new JScrollPane( info ), new GridBagConstraints( 0, 0, 1, 1, 10.0, 10.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 1, 1, 1, 1 ), 0, 0 ));
add( close, new GridBagConstraints( 0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets( 20, 20, 20, 20 ), 0, 0 ));
startCountdown();
}
private void initHyperlinking( JTextPane pane ){
pane.addHyperlinkListener( new HyperlinkListener(){
public void hyperlinkUpdate( HyperlinkEvent e ){
if( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED ){
try{
Class> desktopClass = Class.forName( "java.awt.Desktop" );
Object desktop = desktopClass.getMethod( "getDesktop" ).invoke( null );
Method browse = desktopClass.getMethod( "browse", URI.class );
browse.invoke( desktop, e.getURL().toURI() );
}
catch( Exception ex ){
ex.printStackTrace();
JOptionPane.showMessageDialog( dialog, "I was unable to open your browser :-(", "Cannot open link", JOptionPane.ERROR_MESSAGE );
}
}
}
});
}
private String createMessage(){
return
"" +
"Annoying warning
" +
"
" +
"Dear Developer,
" +
"You are using the Core API of DockingFrames. But you are not making use of the Common API, which " +
"would offer you a wide varity of exciting new features.
" +
"
" +
"Right now your application could have:" +
"" +
"- Buttons for minimizing Dockables.
" +
"- Drag and drop affecting entire stacks of Dockables, instead of only one Dockable at a time.
" +
"- Dockables refusing to resize (but the user can override that behavior).
" +
"- Eclipse-like distinction between 'editors' and 'tools' (called Multiple- and SingleCDockable)
" +
"- More advanced handling of location, includes tracking of closed Dockables.
" +
"- Colors, Fonts, and Icons customized for each Dockable
" +
"- An API that is easier to understand and to use than the Core API.
" +
"
" +
"
" +
"How to get all these goodies? Just include the 'docking-frames-common.jar' file into the class-path of this " +
"application. Visit http://dock.javaforge.com to download the files if you are missing them.
" +
"Then create a CControl instead of a DockController or a DockFrontend.
" +
"
" +
"You may also want to have a look at the 'docking-frames-demo-tutorial' project, it shows how to use the Common API.
" +
"And if you still have questions: visit our forum at " +
"http://forum.byte-welt.net/forumdisplay.php?f=69.
" +
"
" +
"If you really want to get rid of this dialog, just call:
" +
"DockController.disableCoreWarning();
" +
"
" +
"Regards
" +
"Benjamin Sigg" +
"";
}
private void startCountdown(){
close.setEnabled( false );
close.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent e ){
dialog.dispose();
}
});
updateClose( 4 );
final Timer timer = new Timer( 1000, null );
timer.addActionListener( new ActionListener(){
private int remaining = 4;
public void actionPerformed( ActionEvent e ){
remaining--;
updateClose( remaining );
if( remaining == 0 ){
timer.stop();
}
}
});
timer.start();
}
private void updateClose( int remaining ){
if( remaining == 0 ){
close.setEnabled( true );
close.setText( "Close" );
}
else{
close.setText( "Close (" + remaining + ")" );
}
}
}