📄 profilemanager.java
字号:
/* * Copyright (C) 2003 Adam Olsen * 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; either version 1, or (at your option) * any later version. * 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., 675 Mass Ave, Cambridge, MA 02139, USA. */package com.valhalla.jbother;import java.awt.*;import java.awt.event.*;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FilenameFilter;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.util.Locale;import java.util.Properties;import java.util.ResourceBundle;import javax.swing.*;import org.jivesoftware.smack.packet.Presence;import com.valhalla.gui.Standard;import com.valhalla.misc.GnuPG;import com.valhalla.misc.MiscUtils;import com.valhalla.misc.SimpleXOR;import com.valhalla.settings.Arguments;import com.valhalla.settings.Settings;/** * Shows a graphical chooser for different JBother profiles * * @author Adam Olsen * @created Oct 28, 2004 * @version 1.0 */public class ProfileManager extends JFrame { private static ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault()); private JList profileList = new JList(); private JButton newButton = new JButton(resources.getString("newButton")); private JButton editButton = new JButton(resources.getString("editButton")); private JButton deleteButton = new JButton(resources .getString("deleteButton")); private JButton openButton = new JButton(resources.getString("openButton")); private JButton cancelButton = new JButton(resources .getString("cancelButton")); private JPanel main = null; private String defaultString = " <-"; private static File profDir = new File(JBother.settingsDir, "profiles"); private ProfileListModel model = null; private boolean exitOnClose = false; private static String currentProfile = "default"; private static boolean isShowing = false; private static Object selected = null; /** * Default constructor */ public ProfileManager() { super("JBother"); setIconImage(Standard.getImage("frameicon.png")); profileList.setCellRenderer(new ListRenderer()); loadProfileList(); main = (JPanel) getContentPane(); main.setBorder(BorderFactory.createTitledBorder(resources .getString("profileManager"))); main.setLayout(new BorderLayout(5, 5)); JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS)); newButton.setMaximumSize(new Dimension(100, 100)); editButton.setMaximumSize(new Dimension(100, 100)); deleteButton.setMaximumSize(new Dimension(100, 100)); rightPanel.add(newButton); rightPanel.add(editButton); rightPanel.add(deleteButton); rightPanel.add(Box.createVerticalGlue()); JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS)); bottomPanel.add(Box.createHorizontalGlue()); bottomPanel.add(cancelButton); bottomPanel.add(openButton); main.add(new JScrollPane(profileList), BorderLayout.CENTER); main.add(rightPanel, BorderLayout.WEST); main.add(bottomPanel, BorderLayout.SOUTH); addListeners(); pack(); setSize(350, 200); setLocationRelativeTo(null); isShowing = true; setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { cancelHandler(); } }); } class MouseClickListener extends MouseAdapter { public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 2) { openHandler(); } } } public static boolean isCurrentlyShowing() { return isShowing; } public static String getCurrentProfile() { return currentProfile; } public static void setCurrentProfile(String profile) { currentProfile = profile; } /** * @param exitOnClose * set to true to have this dialog close the app on close */ public void setExitOnClose(boolean exitOnClose) { this.exitOnClose = exitOnClose; } /** * cancels this dialog, and if exitOnClose is set, the application quits */ private void cancelHandler() { if (exitOnClose) { System.exit(0); } else { isShowing = false; dispose(); BuddyList.getInstance().getContainerFrame().setVisible(true); } } /** * Adds event listeners */ private void addListeners() { cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelHandler(); } }); editButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String string = (String) profileList.getSelectedValue(); selected = string; if (string != null && string.endsWith(defaultString)) { int index = string.indexOf(defaultString); string = string.substring(0, index); } new ProfileEditorDialog(ProfileManager.this, ProfileManager.this, string).setVisible(true); } }); newButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new ProfileEditorDialog(ProfileManager.this, ProfileManager.this, null).setVisible(true); } }); deleteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String string = (String) profileList.getSelectedValue(); if (string != null && string.endsWith(defaultString)) { int index = string.indexOf(defaultString); string = string.substring(0, index); } int result = JOptionPane.showConfirmDialog(null, resources .getString("deleteProfile"), "JBother", JOptionPane.YES_NO_OPTION); if (result == 0) { try { MiscUtils.recursivelyDeleteDirectory(profDir.getPath() + File.separatorChar + string); } catch (Exception ex) { Standard.warningMessage(ProfileManager.this, "JBother", resources.getString("errorDeletingProfile")); com.valhalla.Logger.logException(ex); return; } loadProfileList(); } } }); openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openHandler(); } }); profileList.addMouseListener(new MouseClickListener()); } public void openHandler() { String string = (String) profileList.getSelectedValue(); if (string != null && string.endsWith(defaultString)) { int index = string.indexOf(defaultString); string = string.substring(0, index); } loadProfile(string); isShowing = false; dispose();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -