preferencepanel.java

来自「peeranha42是jxta的 p2p程序核心」· Java 代码 · 共 58 行

JAVA
58
字号
package de.uni_bremen.informatik.p2p.plugins.filesharing.gui;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

import de.uni_bremen.informatik.p2p.peeranha42.core.plugin.gui.P42_application_pane;
import de.uni_bremen.informatik.p2p.plugins.filesharing.control.UserInputManager;
import de.uni_bremen.informatik.p2p.plugins.filesharing.data.FilesharingState;

/**
 * @author Lars Kordes
 */
//public class PreferencePanel extends P42_preferences_pane implements ActionListener {
public class PreferencePanel extends P42_application_pane implements ActionListener {
	private JLabel lab;
	private final static String PANEL_NAME = "Preferences";
	
	public PreferencePanel() {
		super(PANEL_NAME, P42_application_pane.ATTACHED, FilesharingState.pluginid);
		
		setLayout(new FlowLayout());
		
		lab = new JLabel("Download directory: " + FilesharingState.config.getValue("download_directory"));
		add(lab);
		
		JButton directorybutton = new JButton("Choose");
        // tooltip
        directorybutton.setToolTipText("Press Button to choose download directory");
        // set size
        directorybutton.setPreferredSize(new Dimension(100, 20));
        // add actionlistener
        directorybutton.addActionListener(this);
        add(directorybutton);
	}

	public String getName() {
		return PANEL_NAME;
	}
	
	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getActionCommand().equals("Choose")) UserInputManager.chooseDownloadDirectory();

		Runnable update = new Runnable() {
            public void run() {
            	lab.setText("Download directory: " + FilesharingState.config.getValue("download_directory"));
            }
        };
        
        SwingUtilities.invokeLater(update);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?