📄 prefsdialog.java
字号:
package com.prcomps.cahitarf.gui;
import com.sohlman.easylayout.EasyLayout;
import com.sohlman.easylayout.Constraint;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.HyperlinkEvent;
import java.awt.Frame;
import java.awt.HeadlessException;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.util.ResourceBundle;
import java.io.File;
import java.io.IOException;
/**
*/
public class PrefsDialog
extends JDialog
{
private ResourceBundle bundle = WizardFrame.getBundle();
private String laf;
private JEditorPane lblAbout;
private Frame owner;
public PrefsDialog( Frame owner )
throws HeadlessException
{
super( owner, WizardFrame.getBundle().getString( "wizard.prefs.title" ), true );
this.owner = owner;
JPanel container = new JPanel();
container.setLayout( new BorderLayout() );
JPanel buttonPanel = buildButtonPanel();
JPanel prefsPanel = buildPrefsPanel();
container.add( prefsPanel, BorderLayout.CENTER );
container.add( buttonPanel, BorderLayout.SOUTH );
lblAbout = new JEditorPane( "text/html", about );
lblAbout.setEditable( false);
lblAbout.setBackground( javax.swing.UIManager.getColor( "background" ) );
lblAbout.addHyperlinkListener( new HyperlinkListener()
{
public void hyperlinkUpdate( HyperlinkEvent e )
{
if ( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED )
launchURL( e.getURL().toExternalForm() );
}
}
);
container.add( lblAbout, BorderLayout.NORTH );
getContentPane().add(container);
pack();
setSize( 500, 300 );
centerDialog();
}
private void launchURL( String url )
{
try
{
if(System.getProperty("os.name").indexOf("Windows") >= 0)
CAPanel.launchW32AssocProgram( ".html", url );
else
{
FileDialog fileDialog = new FileDialog( owner );
fileDialog.setMode(0);
fileDialog.setTitle("Choose the browser to use:");
fileDialog.setVisible(true);
String resultPath = fileDialog.getDirectory();
String resultFile = fileDialog.getFile();
if(resultPath != null && resultPath.length() != 0 && resultFile != null && resultFile.length() != 0)
{
File file = new File(resultPath + resultFile);
if(file != null)
{
String browserName = file.getPath();
try
{
Runtime.getRuntime().exec(new String[] {
browserName, "http://www.ca.com"
});
}
catch(IOException exc)
{
exc.printStackTrace();
}
}
}
}
}
catch ( IOException e )
{
JOptionPane.showMessageDialog( this, url );
}
}
private JPanel buildPrefsPanel()
{
JPanel prefsPanel = new JPanel( new EasyLayout( new int[] { 60, 40 }, new int[]{100}, 6, 6 ) );
JComboBox cbLaf = new JComboBox( new String[] { "Aqua", "Modern", "BeOS", "CellShaded", "Whistler" } );
String currentLaf = WizardFrame.getCurrentLaf();
for ( int i=0; i<cbLaf.getItemCount(); i++ )
if ( cbLaf.getItemAt( i ).toString().equalsIgnoreCase( currentLaf ) )
{
cbLaf.setSelectedIndex( i );
laf = currentLaf;
break;
}
cbLaf.addItemListener( new ItemListener()
{
public void itemStateChanged( ItemEvent e )
{
laf = e.getItem().toString().toLowerCase();
}
});
JLabel lbLaf = new JLabel( bundle.getString( "wizard.prefs.laf" ) );
prefsPanel.add( lbLaf, new Constraint( 0, 0, Constraint.RIGHT, Constraint.BOTTOM, 5, 5 ) );
prefsPanel.add( cbLaf, new Constraint( 1, 0, Constraint.LEFT, Constraint.BOTTOM, 5, 5 ) );
return prefsPanel;
}
private JPanel buildButtonPanel()
{
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout ( new FlowLayout(FlowLayout.RIGHT) );
JButton cancel = new JButton("Close");
cancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
CancelPressed();
}
});
buttonPanel.add( cancel );
JButton ok = new JButton("Apply");
ok.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
OKPressed();
}
});
buttonPanel.add( ok );
getRootPane().setDefaultButton(ok);
return buttonPanel;
}
protected void centerDialog()
{
Dimension screenSize = this.getToolkit().getScreenSize();
Dimension size = this.getSize();
screenSize.height = screenSize.height/2;
screenSize.width = screenSize.width/2;
size.height = size.height/2;
size.width = size.width/2;
int y = screenSize.height - size.height;
int x = screenSize.width - size.width;
this.setLocation(x,y);
}
public void CancelPressed()
{
this.setVisible(false);
}
public void OKPressed()
{
this.setVisible(false);
((WizardFrame) getOwner()).setLookAndFeel( laf );
dispose();
}
private final String anypay = "https://secure.anypay.com/apmain?interfaceId=LinkPaymentAccept&langCode=eng&.curr=EUR&.email=ayhan@ayhanalkan.com&.description=Donation+for+Cahit+Arf%2C+a+data+extraction+tool+for+WEKA&.amount=20.00&.clearingMode=1&.quantityEdit=true&.returnUrl=http%3A%2F%2Fwww.primecomponents.com%2Fopensource%2Fcahitarf%2Fthanks.php";
private final String about = "<html><body><h3 align=center>Cahit Arf V1.0</h3><p> © 2003, " +
"<a href=\"mailto:ayhan@primecomponents.com\">Ayhan Alkan &040; PrimeComponents</a></p>" +
"<p> Visit us at <a href=\"http://www.primecomponents.com/\">http://www.primecomponents.com/"+
"<p> Commercial users, if you would like to donate, please click <a href=\"" + anypay + "\" target=\"_blank\"><img src=\""+
getClass().getClassLoader().getResource( "icons/secure_payment_88x33.gif" ).toExternalForm() + "\" align=middle></a>" +
"<br><hr></body></html>";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -