PreferencesDialog.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.xnap.gui |
![]() |
![]() |
XNap 3 |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* XNap - A P2P framework and client.
*
* See the file AUTHORS for copyright information.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.xnap.gui;
import java.awt.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.help.CSH;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import org.xnap.XNap;
import org.xnap.gui.event.DialogSupport;
import org.xnap.gui.prefs.AdvancedTransferPrefsPanel;
import org.xnap.gui.prefs.ApplicationPrefsPanel;
import org.xnap.gui.prefs.ChatAppearancePrefsPanel;
import org.xnap.gui.prefs.ChatPrefsPanel;
import org.xnap.gui.prefs.ConfirmPrefsPanel;
import org.xnap.gui.prefs.ConsoleAppearancePrefsPanel;
import org.xnap.gui.prefs.FilePrefsPanel;
import org.xnap.gui.prefs.LookAndFeelPrefsPanel;
import org.xnap.gui.prefs.NetworkPrefsPanel;
import org.xnap.gui.prefs.PackagePrefsPanel;
import org.xnap.gui.prefs.PersonalPrefsPanel;
import org.xnap.gui.prefs.ProgramPrefsPanel;
import org.xnap.gui.prefs.ProxyPrefsPanel;
import org.xnap.gui.prefs.SearchPrefsPanel;
import org.xnap.gui.prefs.ShortcutPrefsPanel;
import org.xnap.gui.prefs.TransferPrefsPanel;
import org.xnap.gui.util.*;
import org.xnap.util.Preferences;
/**
* Provides the global preferences dialog.
*/
public class PreferencesDialog extends AbstractPreferencesDialog
implements PropertyChangeListener {
//--- Data field(s) ---
/**
* Used to store dialog listeners.
*/
private static DialogSupport listeners = new DialogSupport();
private static PreferencesDialog me = null;
private Preferences prefs = Preferences.getInstance();
private boolean canClose;
private boolean needToRestartXNap = false;
//--- Constructor(s) ---
private PreferencesDialog()
{
super(XNap.tr("XNap - Settings"));
// icon panel
initializePanels();
listeners.fireDialogWillBecomeVisible(this);
setSize(prefs.getPrefsWindowWidth(), prefs.getPrefsWindowHeight());
}
// --- Methods ---
private void initializePanels()
{
JTabbedPane jtpGeneral = new JTabbedPane();
addPanel(jtpGeneral, XNap.tr("General"), "gohome.png",
XNap.tr("Personal settings configuration."));
CSH.setHelpIDString(jtpGeneral, "general");
addTab(jtpGeneral, new PersonalPrefsPanel());
addTab(jtpGeneral, new ConfirmPrefsPanel());
addTab(jtpGeneral, new ShortcutPrefsPanel());
JTabbedPane jtpAppearance = new JTabbedPane();
addPanel(jtpAppearance, XNap.tr("Appearance"), "list.png",
XNap.tr("Program behaviour and look and feel configuration."));
CSH.setHelpIDString(jtpAppearance, "appearance");
addTab(jtpAppearance, new ApplicationPrefsPanel());
addTab(jtpAppearance, new LookAndFeelPrefsPanel());
addTab(jtpAppearance, new ChatAppearancePrefsPanel());
addTab(jtpAppearance, new ConsoleAppearancePrefsPanel());
JTabbedPane jtpFiles = new JTabbedPane();
addPanel(jtpFiles, XNap.tr("Files"), "folder.png",
XNap.tr("Folder and program configuration."));
CSH.setHelpIDString(jtpFiles, "files");
addTab(jtpFiles, new FilePrefsPanel());
addTab(jtpFiles, new ProgramPrefsPanel());
JTabbedPane jtpNetwork = new JTabbedPane();
addPanel(jtpNetwork, XNap.tr("Network"), "world.png",
XNap.tr("Firewall and proxy configuration."));
CSH.setHelpIDString(jtpNetwork, "network");
addTab(jtpNetwork, new NetworkPrefsPanel());
addTab(jtpNetwork, new ProxyPrefsPanel());
// search
SearchPrefsPanel spp = new SearchPrefsPanel();
CSH.setHelpIDString(spp, "search");
addPanel(spp, "find.png");
// transfer
JTabbedPane jtpTransfer = new JTabbedPane();
addPanel(jtpTransfer, XNap.tr("Transfer"), "connect_established.png",
XNap.tr("Throttle and transfer limit configuration."));
CSH.setHelpIDString(jtpTransfer, "transfer");
addTab(jtpTransfer, new TransferPrefsPanel());
addTab(jtpTransfer, new AdvancedTransferPrefsPanel());
// chat
addPanel(new ChatPrefsPanel(), "mail_generic.png");
// packages
addPanel(new PackagePrefsPanel(), "package.png");
HelpManager.enableHelpKeys(getRootPane(), "configuring-XNap", null);
}
public boolean apply()
{
// initialize
canClose = true;
// register for restart notification
prefs.addPropertyChangeListener(this);
canClose &= super.apply();
prefs.removePropertyChangeListener(this);
return canClose;
}
public void close()
{
// save dialog prefs
prefs.setPrefsWindowWidth(getBounds().getSize().width);
prefs.setPrefsWindowHeight(getBounds().getSize().height);
// save the preferences to file
if (isOkay() && !prefs.write()) {
String msg = XNap.tr("Could not write {0}.", prefs.getFilename());
JOptionPane.showMessageDialog
(this, msg, XNap.tr("Preferences"),
JOptionPane.ERROR_MESSAGE);
return;
}
if (needToRestartXNap) {
Dialogs.showRestartNotification(this);
}
listeners.fireDialogWillBecomeInvisible(this);
dispose();
me = null;
}
public void propertyChange(PropertyChangeEvent e)
{
String p = e.getPropertyName();
if (p.equals("lookAndFeel") || p.equals("showTextIcons")
|| p.equals("theme") || p.equals("language")
|| p.equals("iconTheme")) {
needToRestartXNap = true;
}
}
/**
* Removes <code>jp</code> from the list.
*/
public static void removePanel(JPanel jp)
{
if (me != null) {
me.remove(jp);
}
}
/**
* Removes <code>tab</code> from the list of {@link SettingsPanel}
* objects. After this method has been invoked, <code>tab.apply()</code>
* is not called when the dialog is closed.
*/
public static void removePanel(SettingsPanel tab)
{
if (me != null) {
me.remove(tab);
}
}
public static void showDialog(Component c)
{
if (me == null) {
me = new PreferencesDialog();
}
me.show(c);
}
}
The table below shows all metrics for PreferencesDialog.java.




