/** * A supporting panel for the preferences dialog. This panel gives the user the option to change the * appearance of the user interface. * * @author Sai Pullabhotla, psai [at] jMethods [dot] com * @version 2.0 */ public class UIPrefsPanel extends JPanel { private static final ResourceBundle resources = ResourceLoader.getBundle("com.myjavaworld.jftp.UIPrefsPanel"); private MComboBox comboLookAndFeels = null; public UIPrefsPanel() { super(); setLayout(new GridBagLayout()); initComponents(); } private void initComponents() { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; MLabel labLookAndFeel = new MLabel(resources.getString("text.lookAndFeel")); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.weightx = 0.0; c.weighty = 0.0; c.insets = new Insets(12, 12, 12, 12); add(labLookAndFeel, c); comboLookAndFeels = new MComboBox(getInstalledLookAndFeels()); c.gridx = 1; c.gridy = 0; c.gridwidth = 2; c.weightx = 0.5; c.weighty = 0.0; c.insets = new Insets(12, 0, 12, 12); add(comboLookAndFeels, c); c.gridx = 0; c.gridy = 3; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = GridBagConstraints.REMAINDER; c.weighty = 1.0; c.fill = GridBagConstraints.BOTH; add(new MLabel(), c); populateScreen(); } public boolean validateFields() { return true; } public void populateScreen() { populateScreen(JFTP.prefs); } public void populateScreen(JFTPPreferences prefs) { comboLookAndFeels.setSelectedItem(getLookAndFeelName(prefs.getLookAndFeelClassName())); // comboThemes.setSelectedItem(prefs.getTheme()); // if (prefs.getUseJavaWindows()) { // radioJavaWindows.setSelected(true); // } // else { // radioStandardWindows.setSelected(true); // } } public void saveChanges() { String selecteLookAndFeel = (String) comboLookAndFeels.getSelectedItem(); JFTP.prefs.setLookAndFeelClassName(getLookAndFeelClassName(selecteLookAndFeel)); // JFTP.prefs.setTheme((String) comboThemes.getSelectedItem()); // JFTP.prefs.setUseJavaWindows(radioJavaWindows.isSelected()); } private String[] getInstalledLookAndFeels() { UIManager.LookAndFeelInfo[] lnfs = UIManager.getInstalledLookAndFeels(); String[] lnfNames = new String[lnfs.length]; for (int i = 0; i < lnfs.length; i++) { lnfNames[i] = lnfs[i].getName(); } return lnfNames; } private String getLookAndFeelClassName(String lookAndFeelName) { UIManager.LookAndFeelInfo[] lnfs = UIManager.getInstalledLookAndFeels(); for (int i = 0; i < lnfs.length; i++) { if (lookAndFeelName.equals(lnfs[i].getName())) { return lnfs[i].getClassName(); } } return UIManager.getSystemLookAndFeelClassName(); } private String getLookAndFeelName(String lookAndFeelClassName) { if (lookAndFeelClassName == null) { return null; } UIManager.LookAndFeelInfo[] lnfs = UIManager.getInstalledLookAndFeels(); for (int i = 0; i < lnfs.length; i++) { if (lookAndFeelClassName.equals(lnfs[i].getClassName())) { return lnfs[i].getName(); } } return null; } }
/** @author Sai Pullabhotla */ public class UploadAsDlg extends MDialog implements ActionListener { private static ResourceBundle resources = ResourceLoader.getBundle("com.myjavaworld.jftp.UploadAsDlg"); private static final String HELP_ID = "transfer.uploadAs"; private MTextField tfFileName = null; private MButton butUpload = null; private MButton butCancel = null; private MButton butHelp = null; private LocalFile localFile = null; private boolean approved = false; public UploadAsDlg(JFTP jftp, LocalFile localFile) { super(jftp); this.localFile = localFile; setTitle(resources.getString("title.dialog")); setModal(true); setResizable(false); initComponents(); pack(); } public boolean isApproved() { return approved; } public String getFileName() { if (approved) { return tfFileName.getText(); } return null; } public void actionPerformed(ActionEvent evt) { if (evt.getSource() == butUpload) { if (!validateInput()) { return; } approved = true; setVisible(false); } if (evt.getSource() == butCancel) { setVisible(false); } } @Override protected void escape() { butCancel.doClick(); } private boolean validateInput() { String error = null; Component errorComponent = null; if (tfFileName.getText().trim().length() < 1) { error = resources.getString("error.fileName.required"); errorComponent = tfFileName; } if (error != null) { GUIUtil.showError(this, error); if (errorComponent != null) { errorComponent.requestFocusInWindow(); } return false; } return true; } private void initComponents() { getContentPane().setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; MessageFormat formatter = new MessageFormat(resources.getString("text.fileName")); String label = formatter.format(new Object[] {localFile.getName()}); MLabel labFileName = new MLabel(label); tfFileName = new MTextField(30); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(12, 12, 12, 12); getContentPane().add(labFileName, c); c.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 1.0; c.weighty = 0.0; c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(12, 0, 12, 12); getContentPane().add(tfFileName, c); c.gridx = 0; c.gridy = 2; c.gridwidth = 2; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; c.fill = GridBagConstraints.NONE; c.insets = new Insets(6, 12, 12, 12); c.anchor = GridBagConstraints.SOUTHEAST; getContentPane().add(getCommandButtons(), c); } private Component getCommandButtons() { Box panel = new Box(BoxLayout.X_AXIS); butUpload = new MButton(resources.getString("text.upload")); butUpload.addActionListener(this); getRootPane().setDefaultButton(butUpload); butCancel = new MButton(CommonResources.getString("text.cancel")); butCancel.addActionListener(this); butHelp = new MButton(CommonResources.getString("text.help")); JFTPHelp2.getInstance().enableHelp(butHelp, HELP_ID); panel.add(butUpload); panel.add(Box.createRigidArea(new Dimension(5, 0))); panel.add(butCancel); panel.add(Box.createRigidArea(new Dimension(5, 0))); panel.add(butHelp); return panel; } }