/* * Copyright (C) 2002 Devon Jones * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * PreferencesNetworkingPanel.java * * Created on August 29, 2002, 2:41 PM */ package plugin.network.gui; import pcgen.core.SettingsHandler; import pcgen.system.LanguageBundle; import plugin.network.NetworkModel; import plugin.network.NetworkPlugin; import javax.swing.*; import javax.swing.border.TitledBorder; import java.awt.BorderLayout; import java.awt.FlowLayout; /** * Dialog for editing preferences. * *@author devon *@since April 7, 2003 */ public class PreferencesNetworkingPanel extends gmgen.gui.PreferencesPanel { private NetworkModel model; private JPanel serverPanel; private JPanel clientPanel; private JTextField serverPort; private JTextField userName; /** Creates new form PreferencesTrackingPanel * @param model */ public PreferencesNetworkingPanel(NetworkModel model) { initComponents(); this.model = model; initPreferences(); } public void setPortNumber(int port) { serverPort.setText(Integer.toString(port)); } public int getPortNumber() { int port = 80; try { port = Integer.parseInt(serverPort.getText()); } catch (Exception e) { // Handle this? } return port; } public void setUserName(String username) { userName.setText(username); } public String getUserName() { return userName.getText(); } @Override public void applyPreferences() { SettingsHandler.setGMGenOption(NetworkPlugin.LOG_NAME + ".port", getPortNumber()); SettingsHandler.setGMGenOption(NetworkPlugin.LOG_NAME + ".username", getUserName()); model.applyPrefs(); } @Override public void initPreferences() { setPortNumber(SettingsHandler.getGMGenOption(NetworkPlugin.LOG_NAME + ".port", 80)); setUserName(SettingsHandler.getGMGenOption(NetworkPlugin.LOG_NAME + ".username", LanguageBundle.getString("in_player"))); //$NON-NLS-2$ } @Override public String toString() { return LanguageBundle.getString("in_plugin_network"); //$NON-NLS-1$ } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ private void initComponents() { setLayout(new BorderLayout()); serverPort = new JTextField(4); userName = new JTextField(10); JPanel borderPanel = new JPanel(); borderPanel.setLayout(new BorderLayout()); JPanel topPanel = new JPanel(); topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS)); serverPanel = new JPanel(); serverPanel.setLayout(new BoxLayout(serverPanel, BoxLayout.Y_AXIS)); serverPanel.setBorder(new TitledBorder(LanguageBundle.getString("in_plugin_network_server"))); //$NON-NLS-1$ JLabel portLabel = new JLabel(); portLabel.setText(LanguageBundle.getString("in_plugin_network_port")); //$NON-NLS-1$ JPanel line1 = new JPanel(); line1.setLayout(new FlowLayout(FlowLayout.LEFT)); line1.add(portLabel); line1.add(serverPort); serverPanel.add(line1); topPanel.add(serverPanel); clientPanel = new JPanel(); clientPanel.setLayout(new BoxLayout(clientPanel, BoxLayout.Y_AXIS)); clientPanel.setBorder(new TitledBorder(LanguageBundle.getString("in_plugin_network_client"))); //$NON-NLS-1$ JLabel userLabel = new JLabel(); userLabel.setText(LanguageBundle.getString("in_plugin_network_username")); //$NON-NLS-1$ JPanel line2 = new JPanel(); line2.setLayout(new FlowLayout(FlowLayout.LEFT)); line2.add(userLabel); line2.add(userName); clientPanel.add(line2); topPanel.add(clientPanel); borderPanel.add(topPanel, BorderLayout.NORTH); JScrollPane jScrollPane1 = new JScrollPane(); jScrollPane1.setViewportView(borderPanel); add(jScrollPane1, BorderLayout.CENTER); } }