📄 sharedpanel.java
字号:
package de.uni_bremen.informatik.p2p.plugins.filesharing.gui;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import de.uni_bremen.informatik.p2p.plugins.filesharing.data.FilesharingState;
import de.uni_bremen.informatik.p2p.plugins.filesharing.data.ShareList;
import de.uni_bremen.informatik.p2p.plugins.filesharing.gui.event.SharedEventListener;
/**
* An object of the class represents the share-userinterface of the filesharing
* plugin.
*
* @author Philipp Hoheisel, Cecile Prigge, Lars Kordes
*/
public class SharedPanel
extends JPanel {
/** Table which presents a look on the list of all shares. */
private JTable table;
/**
* Classconstructor.
*
* @param actlist Buttoneventlistener of all buttons of the filesharing
* gui.
*/
public SharedPanel(SharedEventListener actlist) {
// set layout and doublebuffer for graphics
super(null, true);
// setting layout
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridbag);
JPanel panel = createInputPanel(actlist);
panel.setPreferredSize(new Dimension(1000, 20));
c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
c.gridy = 0;
c.weightx = 0;
c.weighty = 0;
gridbag.setConstraints(panel, c);
add(panel);
table = new JTable(new ShareList(FilesharingState.sharedfiles));
JScrollPane scroll = new JScrollPane(table);
scroll.setPreferredSize(new Dimension(10000,10000));
c.gridx = 0;
c.gridy = 1;
c.weightx = 1;
c.weighty = 1;
gridbag.setConstraints(scroll, c);
// add scrollpane to context
add(scroll);
}
/**
* Returns panel for userinput (e.g. panel with buttons and textfields).
*
* @param actlist Actionlistener
* @return New Panel
*/
private JPanel createInputPanel(SharedEventListener actlist) {
JPanel panel = new JPanel();
// create add-share-button (file)
JButton addfilebutton = new JButton(P42_resource_reader.getImageIcon("/addfile.gif"));
addfilebutton.setActionCommand("Add File");
// tooltip
addfilebutton.setToolTipText("Press Button to add new shared file");
// set preferred size
addfilebutton.setPreferredSize(new Dimension(32, 32));
// add actionlistener
addfilebutton.addActionListener(actlist);
panel.add(addfilebutton);
// create add-share-button (directory)
JButton adddirbutton = new JButton(P42_resource_reader.getImageIcon("/adddirectory.gif"));
adddirbutton.setActionCommand("Add Directory");
// tooltip
adddirbutton.setToolTipText("Press Button to add shared directory");
// set preferred size
adddirbutton.setPreferredSize(new Dimension(32, 32));
// add actionlistener
adddirbutton.addActionListener(actlist);
panel.add(adddirbutton);
// create remove-share-button
JButton removebutton = new JButton(P42_resource_reader.getImageIcon("/remove.gif"));
removebutton.setActionCommand("Remove");
// tooltip
removebutton.setToolTipText("Press Button to remove share");
// set preferred size
removebutton.setPreferredSize(new Dimension(32, 32));
// add actionlistener
removebutton.addActionListener(actlist);
panel.add(removebutton);
// create remove-share-button
JButton removeallbutton = new JButton(P42_resource_reader.getImageIcon("/removeall.gif"));
removeallbutton.setActionCommand("Remove All");
// tooltip
removeallbutton.setToolTipText("Press Button to remove all shares");
// set preferred size
removeallbutton.setPreferredSize(new Dimension(32, 32));
// add actionlistener
removeallbutton.addActionListener(actlist);
panel.add(removeallbutton);
return panel;
}
/**
* Method returns the table-ui which represents all shares of the
* filesharingplugin.
*
* @return Table-ui which presents all shares of the filesharingplugin.
*/
public JTable getTable() {
return table;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -