Comment out class

osx
Hammy 3 years ago
parent 4b294542a8
commit 208701479c

@ -1,111 +1,110 @@
package me.goudham; //package me.goudham;
//
import java.awt.BorderLayout; //import java.awt.BorderLayout;
import java.awt.Dimension; //import java.awt.Dimension;
import java.awt.GridLayout; //import java.awt.GridLayout;
import java.awt.Toolkit; //import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard; //import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection; //import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent; //import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; //import java.awt.event.ActionListener;
//
import javax.swing.BorderFactory; //import javax.swing.BorderFactory;
import javax.swing.BoxLayout; //import javax.swing.BoxLayout;
import javax.swing.DefaultListModel; //import javax.swing.DefaultListModel;
import javax.swing.JButton; //import javax.swing.JButton;
import javax.swing.JFrame; //import javax.swing.JFrame;
import javax.swing.JList; //import javax.swing.JList;
import javax.swing.JPanel; //import javax.swing.JPanel;
import javax.swing.JScrollPane; //import javax.swing.JScrollPane;
import javax.swing.JSplitPane; //import javax.swing.JSplitPane;
import javax.swing.ListSelectionModel; //import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities; //import javax.swing.SwingUtilities;
//
// We are going to build the UI of our Clipboard History software //// We are going to build the UI of our Clipboard History software
// We will use Swing API //// We will use Swing API
public class ClipboardHistory extends JPanel implements ClipboardListener.EntryListener { //public class ClipboardHistory extends JPanel implements ClipboardListener.EntryListener {
//
// for the list of entries copied in clipboard // // for the list of entries copied in clipboard
private final JList<String> list; // private final JList<String> list;
private final DefaultListModel<String> listModel; // private final DefaultListModel<String> listModel;
private ListSelectionModel listSelectionModel; // private ListSelectionModel listSelectionModel;
//
public ClipboardHistory() { // public ClipboardHistory() {
super(new BorderLayout()); // super(new BorderLayout());
listModel = new DefaultListModel<>(); // listModel = new DefaultListModel<>();
list = new JList<>(listModel); // list = new JList<>(listModel);
listSelectionModel = list.getSelectionModel(); // listSelectionModel = list.getSelectionModel();
listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//
// we create a JScrollPane to embed our control pane // // we create a JScrollPane to embed our control pane
JScrollPane listPane = new JScrollPane(list); // JScrollPane listPane = new JScrollPane(list);
JPanel controlPane = new JPanel(); // JPanel controlPane = new JPanel();
//
// we add a button to let users copy old entries to the clipboard // // we add a button to let users copy old entries to the clipboard
final JButton button = new JButton("Copy"); // final JButton button = new JButton("Copy");
button.addActionListener(e -> { // button.addActionListener(e -> {
String value = list.getSelectedValue(); // String value = list.getSelectedValue();
int index = list.getSelectedIndex(); // int index = list.getSelectedIndex();
// remove selected index to avoid duplicate in our list ... // // remove selected index to avoid duplicate in our list ...
listModel.remove(index); // listModel.remove(index);
// copy to clipboard // // copy to clipboard
copyToClipboard(value); // copyToClipboard(value);
}); // });
//
// we add the button // // we add the button
controlPane.add(button); // controlPane.add(button);
//
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); // JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
add(splitPane, BorderLayout.CENTER); // add(splitPane, BorderLayout.CENTER);
//
JPanel topHalf = new JPanel(); // JPanel topHalf = new JPanel();
topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); // topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS));
JPanel listContainer = new JPanel(new GridLayout(1, 1)); // JPanel listContainer = new JPanel(new GridLayout(1, 1));
listContainer.setBorder(BorderFactory.createTitledBorder("Entries")); // listContainer.setBorder(BorderFactory.createTitledBorder("Entries"));
listContainer.add(listPane); // listContainer.add(listPane);
//
topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); // topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
topHalf.add(listContainer); // topHalf.add(listContainer);
topHalf.setMinimumSize(new Dimension(100, 50)); // topHalf.setMinimumSize(new Dimension(100, 50));
topHalf.setPreferredSize(new Dimension(100, 250)); // topHalf.setPreferredSize(new Dimension(100, 250));
splitPane.add(topHalf); // splitPane.add(topHalf);
//
JPanel bottomHalf = new JPanel(new BorderLayout()); // JPanel bottomHalf = new JPanel(new BorderLayout());
bottomHalf.add(controlPane, BorderLayout.CENTER); // bottomHalf.add(controlPane, BorderLayout.CENTER);
bottomHalf.setPreferredSize(new Dimension(450, 30)); // bottomHalf.setPreferredSize(new Dimension(450, 30));
splitPane.add(bottomHalf); // splitPane.add(bottomHalf);
} // }
//
public void copyToClipboard(String value) { // public void copyToClipboard(String value) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection data = new StringSelection(value); // StringSelection data = new StringSelection(value);
clipboard.setContents(data, data); // clipboard.setContents(data, data);
} // }
//
public void createAndShowGUI() { // public void createAndShowGUI() {
// We create a top JFrame // // We create a top JFrame
JFrame frame = new JFrame("Clipboard History"); // JFrame frame = new JFrame("Clipboard History");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//
setOpaque(true); // setOpaque(true);
frame.setContentPane(this); // frame.setContentPane(this);
frame.pack(); // frame.pack();
frame.setVisible(true); // we display on the screen // frame.setVisible(true); // we display on the screen
//
// we connect the Clipboard Listener to our UI // // we connect the Clipboard Listener to our UI
ClipboardListener listener = new ClipboardListener(); // ClipboardListener listener = new ClipboardListener(this);
listener.setEntryListener(this); // listener.start();
listener.start(); // }
} //
// @Override
@Override // public void onCopy(String data) {
public void onCopy(String data) { // // we add new entry on the top of our list
// we add new entry on the top of our list // listModel.add(0, data);
listModel.add(0, data); // }
} //
// public static void main(String[] args) {
public static void main(String[] args) { // SwingUtilities.invokeLater(() -> new ClipboardHistory().createAndShowGUI());
SwingUtilities.invokeLater(() -> new ClipboardHistory().createAndShowGUI()); // }
} //
//}
}

Loading…
Cancel
Save