Basic functionality

This commit is contained in:
Ash 2017-04-11 18:49:18 +10:00
parent 8bc119d715
commit a33c5b5720

View File

@ -22,33 +22,104 @@
package net.ash.HIDToVPADNetworkClient.gui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import lombok.extern.java.Log;
@Log
public class GuiOptionsWindow extends JPanel {
private static final long serialVersionUID = 1L;
private static GuiOptionsWindow instance = new GuiOptionsWindow();
private static final GuiOptionsWindow instance = new GuiOptionsWindow();
private final List<Tab> tabs = new ArrayList<Tab>();
public static void showWindow() {
JFrame window = new JFrame("Options");
//TODO: close behaviour
instance.setOpaque(true);
for (Tab t : instance.tabs) {
t.updateTab();
}
JFrame window = new JFrame("Options");
//TODO: close window behaviour
window.setContentPane(instance);
window.pack();
window.setVisible(true);
}
private GuiOptionsWindow() {
super(new BorderLayout());
super(new GridLayout(1, 1));
log.info("Hello from the Options window!");
setPreferredSize(new Dimension(200, 100));
JTabbedPane tabPane = new JTabbedPane();
tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
Tab infoTab = new InfoTab();
tabs.add(infoTab);
tabPane.addTab("Info", null, infoTab, "desc");
add(tabPane);
}
private class InfoTab extends Tab {
private static final long serialVersionUID = 1L;
private final JTextArea infoText;
private InfoTab() {
super();
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
infoText = new JTextArea();
infoText.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
add(infoText);
JButton copyButton = new JButton("Copy");
copyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
StringSelection data = new StringSelection(infoText.getText());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(data, data);
}
});
copyButton.setAlignmentX(Component.CENTER_ALIGNMENT);
add(copyButton);
}
@Override
public void updateTab() {
//TODO update info text
}
}
private abstract class Tab extends JPanel {
private static final long serialVersionUID = 1L;
public abstract void updateTab();
public Tab(LayoutManager l) {
super(l);
}
public Tab() {
super();
}
}
}