|
|
@ -12,15 +12,16 @@ import javax.swing.JList;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.JScrollPane;
|
|
|
|
import javax.swing.JScrollPane;
|
|
|
|
import me.goudham.listener.ClipboardEvent;
|
|
|
|
import me.goudham.listener.ClipboardEvent;
|
|
|
|
|
|
|
|
import me.goudham.listener.ClipboardListener;
|
|
|
|
import me.goudham.listener.MacClipboardListener;
|
|
|
|
import me.goudham.listener.MacClipboardListener;
|
|
|
|
import me.goudham.listener.WindowsOrUnixClipboardListener;
|
|
|
|
import me.goudham.listener.WindowsOrUnixClipboardListener;
|
|
|
|
import org.apache.commons.lang3.SystemUtils;
|
|
|
|
import org.apache.commons.lang3.SystemUtils;
|
|
|
|
|
|
|
|
|
|
|
|
public class ClipboardView implements ClipboardEvent {
|
|
|
|
public class ClipboardView {
|
|
|
|
private JPanel clipboard;
|
|
|
|
private JPanel clipboard;
|
|
|
|
private JButton copySelectedTextButton;
|
|
|
|
private JButton copySelectedTextButton;
|
|
|
|
private JList<String> clipboardContentList;
|
|
|
|
private JList<String> clipboardContentList;
|
|
|
|
private final DefaultListModel<String> listModel;
|
|
|
|
private final DefaultListModel<String> listModel = new DefaultListModel<>();
|
|
|
|
private JLabel title;
|
|
|
|
private JLabel title;
|
|
|
|
private JPanel textButtonPanel;
|
|
|
|
private JPanel textButtonPanel;
|
|
|
|
private JButton clearAllHistoryButton;
|
|
|
|
private JButton clearAllHistoryButton;
|
|
|
@ -35,29 +36,28 @@ public class ClipboardView implements ClipboardEvent {
|
|
|
|
|
|
|
|
|
|
|
|
private boolean toggle = true;
|
|
|
|
private boolean toggle = true;
|
|
|
|
private BufferedImage storedImageContent;
|
|
|
|
private BufferedImage storedImageContent;
|
|
|
|
|
|
|
|
private ClipboardListener clipboardListener;
|
|
|
|
|
|
|
|
|
|
|
|
public ClipboardView() {
|
|
|
|
public ClipboardView() {
|
|
|
|
imageScrollPane.setBorder(BorderFactory.createEmptyBorder());
|
|
|
|
|
|
|
|
clipboardContentScrollPane.setBorder(BorderFactory.createEmptyBorder());
|
|
|
|
clipboardContentScrollPane.setBorder(BorderFactory.createEmptyBorder());
|
|
|
|
textButtonPanel.setBorder(BorderFactory.createEmptyBorder());
|
|
|
|
imageScrollPane.getVerticalScrollBar().setUnitIncrement(35);
|
|
|
|
listModel = new DefaultListModel<>();
|
|
|
|
imageScrollPane.getHorizontalScrollBar().setUnitIncrement(35);
|
|
|
|
|
|
|
|
clipboardContentScrollPane.getVerticalScrollBar().setUnitIncrement(200);
|
|
|
|
|
|
|
|
clipboardContentScrollPane.getHorizontalScrollBar().setUnitIncrement(200);
|
|
|
|
clipboardContentList.setModel(listModel);
|
|
|
|
clipboardContentList.setModel(listModel);
|
|
|
|
|
|
|
|
|
|
|
|
toggleImageButton.addActionListener(actionEvent -> {
|
|
|
|
toggleImageButton.addActionListener(actionEvent -> {
|
|
|
|
|
|
|
|
if (storedImageContent != null) {
|
|
|
|
if (toggle) {
|
|
|
|
if (toggle) {
|
|
|
|
|
|
|
|
toggleImageButton.setText("Show Image");
|
|
|
|
imageLabel.setIcon(null);
|
|
|
|
imageLabel.setIcon(null);
|
|
|
|
// anotherImagePanel.setPreferredSize(null);
|
|
|
|
|
|
|
|
// anotherImagePanel.setVisible(false);
|
|
|
|
|
|
|
|
// imageIconLabel.setMaximumSize(new Dimension(0, 0));
|
|
|
|
|
|
|
|
// anotherImagePanel.setPreferredSize(new Dimension(0, 0));
|
|
|
|
|
|
|
|
toggle = false;
|
|
|
|
toggle = false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// anotherImagePanel.setPreferredSize(new Dimension(300, 300));
|
|
|
|
|
|
|
|
// anotherImagePanel.setVisible(true);
|
|
|
|
|
|
|
|
imageLabel.setIcon(new ImageIcon(storedImageContent));
|
|
|
|
imageLabel.setIcon(new ImageIcon(storedImageContent));
|
|
|
|
|
|
|
|
toggleImageButton.setText("Hide Image");
|
|
|
|
toggle = true;
|
|
|
|
toggle = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// anotherImagePanel.revalidate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// final java.awt.datatransfer.clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
|
|
|
// final java.awt.datatransfer.clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
|
|
@ -102,26 +102,14 @@ public class ClipboardView implements ClipboardEvent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void createAndShowGUI() {
|
|
|
|
public void createAndShowGUI() {
|
|
|
|
me.goudham.listener.ClipboardListener clipboardListener = null;
|
|
|
|
|
|
|
|
if (isMac()) {
|
|
|
|
if (isMac()) {
|
|
|
|
clipboardListener = new MacClipboardListener(this);
|
|
|
|
clipboardListener = new MacClipboardListener();
|
|
|
|
} else if (isUnix() || isWindows()) {
|
|
|
|
} else if (isUnix() || isWindows()) {
|
|
|
|
clipboardListener = new WindowsOrUnixClipboardListener(this);
|
|
|
|
clipboardListener = new WindowsOrUnixClipboardListener();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clipboardListener.execute();
|
|
|
|
clipboardListener.execute();
|
|
|
|
|
|
|
|
|
|
|
|
JFrame jFrame = new JFrame();
|
|
|
|
clipboardListener.addEventListener(new ClipboardEvent() {
|
|
|
|
jFrame.setTitle("My Clipboard History");
|
|
|
|
|
|
|
|
jFrame.setContentPane(clipboard);
|
|
|
|
|
|
|
|
jFrame.setVisible(true);
|
|
|
|
|
|
|
|
jFrame.setAlwaysOnTop(true);
|
|
|
|
|
|
|
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
|
|
jFrame.setPreferredSize(new Dimension(1200, 900));
|
|
|
|
|
|
|
|
jFrame.setResizable(true);
|
|
|
|
|
|
|
|
jFrame.pack();
|
|
|
|
|
|
|
|
jFrame.setLocationRelativeTo(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onCopyString(String stringContent) {
|
|
|
|
public void onCopyString(String stringContent) {
|
|
|
|
listModel.add(0, stringContent);
|
|
|
|
listModel.add(0, stringContent);
|
|
|
@ -130,15 +118,22 @@ public class ClipboardView implements ClipboardEvent {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onCopyImage(BufferedImage imageContent) {
|
|
|
|
public void onCopyImage(BufferedImage imageContent) {
|
|
|
|
storedImageContent = imageContent;
|
|
|
|
storedImageContent = imageContent;
|
|
|
|
// anotherImagePanel.setMinimumSize(new Dimension(300, 300));
|
|
|
|
|
|
|
|
imageLabel.setIcon(new ImageIcon(imageContent));
|
|
|
|
imageLabel.setIcon(new ImageIcon(imageContent));
|
|
|
|
|
|
|
|
toggleImageButton.setText("Hide Image");
|
|
|
|
toggle = true;
|
|
|
|
toggle = true;
|
|
|
|
//
|
|
|
|
}
|
|
|
|
// if (imageContent.getWidth() > 1000 || imageContent.getHeight() > 1000) {
|
|
|
|
});
|
|
|
|
// imageIconLabel.setIcon(new ImageIcon(new ImageIcon(imageContent).getImage().getScaledInstance(1000, 600, Image.SCALE_SMOOTH)));
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
JFrame jFrame = new JFrame();
|
|
|
|
// imageIconLabel.setIcon(new ImageIcon(imageContent));
|
|
|
|
jFrame.setTitle("My Clipboard History");
|
|
|
|
// }
|
|
|
|
jFrame.setContentPane(clipboard);
|
|
|
|
|
|
|
|
jFrame.setVisible(true);
|
|
|
|
|
|
|
|
jFrame.setAlwaysOnTop(true);
|
|
|
|
|
|
|
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
|
|
jFrame.setPreferredSize(new Dimension(1200, 900));
|
|
|
|
|
|
|
|
jFrame.setResizable(true);
|
|
|
|
|
|
|
|
jFrame.pack();
|
|
|
|
|
|
|
|
jFrame.setLocationRelativeTo(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isMac() {
|
|
|
|
private boolean isMac() {
|
|
|
|