📄 wizardframe.java
字号:
/*
* WizardFrame.java
*
* Created on 11 September 2003, 21:32
*/
package com.prcomps.cahitarf.gui;
import com.l2fprod.gui.plaf.skin.SkinLookAndFeel;
import com.prcomps.cahitarf.Db2Arff;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.JTabbedPane;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import java.util.Properties;
import java.util.Set;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.Iterator;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.net.URL;
import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.text.MessageFormat;
/**
*
* @author ayhan
*/
public class WizardFrame
extends JFrame
implements ActionListener,
ChangeListener
{
public static final String CMD_CANCEL = "cancel";
public static final String CMD_NEXT = "next";
public static final String CMD_PREV = "prev";
public static final String CMD_PREFS = "prefs";
public static final String CMD_FINISH = "finish";
public static final String FORM_START = "1start";
public static final String FORM_TABS = "2tabs";
public static final String FORM_DB = "3database";
public static final String FORM_SELECT= "4select";
public static final String FORM_ATTRS = "5attrs";
public static final String FORM_RUN = "6run";
private static ResourceBundle bundle = ResourceBundle.getBundle("messages");
public static Properties properties = new Properties();
public static Set prefsJdbcUrls;
public static Set prefsJdbcDrivers;
public static List prefsFiles;
private static String currentLaf;
private JPanel forms = new JPanel();
private Navigator navigator = new Navigator();;
private JTabbedPane tabForms = new JTabbedPane( JTabbedPane.TOP );
private FormStart formStart;
private FormDb formDb;
private FormSelect formSelect;
private FormAttrs formAttrs;
private FormRun formRun;
private IWizardPanel currentForm;
private boolean inNavAction = false;
public WizardFrame()
{
loadPrefs();
formStart = new FormStart();
formDb = new FormDb();
formSelect = new FormSelect();
formAttrs = new FormAttrs();
formRun = new FormRun();
currentForm = formStart;
initComponents();
}
private void initComponents()
{
setTitle( bundle.getString("wizard.title") );
setName( "WizardFrame" );
URL url = getClass().getClassLoader().getResource( "icons/Icon.png" );
setIconImage( new ImageIcon( url ).getImage() );
addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent evt)
{
savePrefs();
System.exit( 0 );
}
});
tabForms.add( bundle.getString("wizard.db.title"), formDb );
tabForms.add( bundle.getString("wizard.select.title"), formSelect );
tabForms.add( bundle.getString("wizard.attrs.title"), formAttrs );
tabForms.add( bundle.getString("wizard.run.title"), formRun );
tabForms.addChangeListener( this );
forms.setLayout( new CardLayout() );
forms.add( formStart, FORM_START );
forms.add( tabForms, FORM_TABS );
navigator.setActionListener( this );
getContentPane().add( navigator, BorderLayout.SOUTH );
getContentPane().add( forms, BorderLayout.CENTER );
pack();
setSize( 650, 450 );
setLookAndFeel( currentLaf );
}
/**
* @param args the command line arguments
*/
public static void main(String args[])
{
new WizardFrame().show();
}
public void setLookAndFeel( String laf )
{
String lookAndFeel = "themes/" + laf + "/skinlf-themepack.xml";
URL lfURL = getClass().getClassLoader().getResource( lookAndFeel );
if ( lfURL != null )
try
{
SkinLookAndFeel.setSkin(SkinLookAndFeel.loadThemePackDefinition( lfURL ));
SkinLookAndFeel.enable();
SwingUtilities.updateComponentTreeUI( this );
currentLaf = laf;
}
catch ( Exception ex )
{
JOptionPane.showMessageDialog( this,
MessageFormat.format( bundle.getString("wizard.laf.n.a"), new String[]{ laf } ),
bundle.getString( "wizard.msgbox.title.error"), JOptionPane.ERROR_MESSAGE );
}
}
public void actionPerformed( ActionEvent e )
{
String cmd = e.getActionCommand();
inNavAction = true;
if ( cmd.equals( CMD_CANCEL ) )
{
savePrefs();
System.exit( 0 );
}
else if ( cmd.equals( CMD_PREFS ) )
{
PrefsDialog dlgPrefs = new PrefsDialog( this );
dlgPrefs.show();
}
else if ( cmd.equals( CMD_NEXT ) )
try
{
String next = currentForm.getNext();
showForm( next );
}
catch ( NotReadyException ex )
{
JOptionPane.showMessageDialog( this, ex.getMessage(),
bundle.getString( "wizard.msgbox.title.noproceed" ), JOptionPane.ERROR_MESSAGE );
}
else if ( cmd.equals( CMD_PREV ) )
try
{
String prev = currentForm.getPrev();
showForm( prev );
}
catch ( NotReadyException ex )
{
JOptionPane.showMessageDialog( this, ex.getMessage(),
bundle.getString( "wizard.msgbox.title.noback" ), JOptionPane.ERROR_MESSAGE );
}
inNavAction = false;
}
private void showForm( String form )
{
if ( form == null )
return;
CardLayout layout = (CardLayout) forms.getLayout();
if ( form.equals( FORM_START ) )
{
layout.show( this, form );
currentForm = formStart;
}
else
{
layout.show( forms, FORM_TABS );
tabForms.setSelectedIndex( form.charAt(0) - '0' - 3 );
currentForm = (IWizardPanel) tabForms.getSelectedComponent();
}
currentForm.checkStatus();
}
public void stateChanged( ChangeEvent ce )
{
if ( inNavAction )
return;
int cur = currentForm.getName().charAt(0) - '0' - 3;
int sel = tabForms.getSelectedIndex();
if ( cur < sel )
{
int i;
for ( i=cur; i<sel; i++ )
try
{
((IWizardPanel) tabForms.getComponentAt( i ) ).getNext();
}
catch ( NotReadyException e )
{
if ( e.getMessage() != null && e.getMessage().length() > 0 )
JOptionPane.showMessageDialog( this, e.getMessage(),
bundle.getString( "wizard.msgbox.title.noproceed" ), JOptionPane.ERROR_MESSAGE );
break;
}
tabForms.setSelectedIndex( i );
}
currentForm = (IWizardPanel) tabForms.getSelectedComponent();
currentForm.checkStatus();
}
private void loadPrefs()
{
String path = new Db2Arff().getAppPath() + "/cahitarf.properties";
File file = new File( path );
String strFiles = null;
String strDrivers = null;
String strUrls = null;
if ( file.exists() )
{
try
{
InputStream in = new FileInputStream( file );
Properties tmp = new Properties();
tmp.load( in );
strFiles = tmp.getProperty( "files" );
strDrivers = tmp.getProperty( "jdbc.drivers" );
strUrls = tmp.getProperty( "jdbc.urls" );
currentLaf = tmp.getProperty( "laf", "modern" );
if ( "modern beos aqua cellshaded whistler".indexOf( currentLaf ) < 0 )
currentLaf = "cellshaded";
}
catch ( IOException e )
{
System.err.println( "Property file '" + path + "' not found." );
// Do nothing
}
}
prefsFiles = new LinkedList();
str2Set( strFiles, prefsFiles );
prefsJdbcDrivers = new HashSet();
str2Set( strDrivers, prefsJdbcDrivers );
prefsJdbcUrls = new HashSet();
str2Set( strUrls, prefsJdbcUrls );
}
private void savePrefs()
{
String path = new Db2Arff().getAppPath() + "/cahitarf.properties";
PrintStream out = null;
try
{
out = new PrintStream( new FileOutputStream( path ) );
out.println( "files=" + set2Str( prefsFiles ) );
out.println( "laf=" + currentLaf );
out.println( "jdbc.drivers=" + set2Str( prefsJdbcDrivers ) );
out.println( "jdbc.urls=" + set2Str( prefsJdbcUrls ) );
}
catch ( FileNotFoundException e )
{
System.err.println( "Could not write preferences to " + path );
}
}
private void str2Set( String str, Collection set )
{
if ( str != null && str.length() > 0 )
for ( StringTokenizer st = new StringTokenizer( str, "|" ); st.hasMoreTokens(); )
set.add( st.nextToken() );
}
private String set2Str( Collection set )
{
StringBuffer str = new StringBuffer();
for ( Iterator i = set.iterator(); i.hasNext(); )
{
str.append( i.next() );
if ( i.hasNext() )
str.append("|\\\n\t");
}
return str.toString();
}
public static String getCurrentLaf() { return currentLaf; }
public static ResourceBundle getBundle() { return bundle; }
public static Properties getProperties() { return properties; }
public static void setProperties( Properties properties ) { WizardFrame.properties = properties; }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -