Refactor ClipboardView to copy images and strings (wip)

osx
Hammy 3 years ago
parent 27841266ed
commit 6c679c8ef2

@ -1,27 +1,33 @@
package me.goudham.view; package me.goudham.view;
import me.goudham.ClipboardListener; import me.goudham.ClipboardListener;
import me.goudham.controller.MyClipboardContent; import me.goudham.listener.ClipboardEvent;
import me.goudham.model.TransferableImage; import me.goudham.model.MyClipboardContent;
import javax.swing.*; import javax.swing.BorderFactory;
import java.awt.Color; import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.datatransfer.*;
import java.io.IOException;
public class ClipboardView implements ClipboardListener.EntryListener { public class ClipboardView implements ClipboardEvent {
private JPanel Clipboard; private JPanel Clipboard;
private JButton copyButton; private JButton copyButton;
private JList<String> clipboardContentList; private JList<String> clipboardContentList;
private final DefaultListModel<String> listModel; private final DefaultListModel<String> listModel;
private JLabel title; private JLabel title;
private JScrollPane scrollPane; private JScrollPane scrollPane;
private JPanel buttonPane;
private JButton clearButton;
private JButton removeButton;
public ClipboardView() { public ClipboardView() {
scrollPane.setBorder(BorderFactory.createEmptyBorder()); scrollPane.setBorder(BorderFactory.createEmptyBorder());
buttonPane.setBorder(BorderFactory.createEmptyBorder());
listModel = new DefaultListModel<>(); listModel = new DefaultListModel<>();
clipboardContentList.setModel(listModel); clipboardContentList.setModel(listModel);
@ -66,18 +72,8 @@ public class ClipboardView implements ClipboardListener.EntryListener {
// }); // });
} }
public JPanel getClipboard() { public void createAndShowGUI() {
return Clipboard; new ClipboardListener(this).start();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new ClipboardView().createAndShowGUI());
}
private void createAndShowGUI() {
ClipboardListener listener = new ClipboardListener();
listener.setEntryListener(this);
listener.start();
JFrame jFrame = new JFrame(); JFrame jFrame = new JFrame();
jFrame.setTitle("My Clipboard History"); jFrame.setTitle("My Clipboard History");
@ -85,16 +81,15 @@ public class ClipboardView implements ClipboardListener.EntryListener {
jFrame.setVisible(true); jFrame.setVisible(true);
jFrame.setAlwaysOnTop(true); jFrame.setAlwaysOnTop(true);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.getContentPane().setBackground(new Color(1, 3, 25));
jFrame.setPreferredSize(new Dimension(1000, 680)); jFrame.setPreferredSize(new Dimension(1000, 680));
jFrame.setMaximumSize(new Dimension(1000, 680)); jFrame.setMaximumSize(new Dimension(1000, 680));
jFrame.setResizable(false); jFrame.setResizable(true);
jFrame.pack(); jFrame.pack();
jFrame.setLocationRelativeTo(null); jFrame.setLocationRelativeTo(null);
} }
@Override @Override
public void onCopy(String data) { public <T> void onCopy(MyClipboardContent<T> copiedContent) {
listModel.add(0, data); listModel.add(0, copiedContent.getContent().toString());
} }
} }

Loading…
Cancel
Save