From 36c53d91df7169f2e1c1c05fb13a14d95a068c3a Mon Sep 17 00:00:00 2001 From: sgoudham Date: Wed, 21 Jul 2021 01:42:28 +0100 Subject: [PATCH] Override onCopyString() & onCopyImage() and display to GUI --- .../java/me/goudham/view/ClipboardView.java | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/main/java/me/goudham/view/ClipboardView.java b/src/main/java/me/goudham/view/ClipboardView.java index 3756d81..2fce84f 100644 --- a/src/main/java/me/goudham/view/ClipboardView.java +++ b/src/main/java/me/goudham/view/ClipboardView.java @@ -1,38 +1,38 @@ package me.goudham.view; -import me.goudham.ClipboardListener; -import me.goudham.listener.ClipboardEvent; -import me.goudham.model.MyClipboardContent; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; +import java.awt.Dimension; +import java.awt.Image; +import java.awt.image.BufferedImage; import javax.swing.BorderFactory; import javax.swing.DefaultListModel; -import javax.swing.InputMap; +import javax.swing.ImageIcon; 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 javax.swing.KeyStroke; -import java.awt.Dimension; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; +import me.goudham.ClipboardListener; +import me.goudham.listener.ClipboardEvent; public class ClipboardView implements ClipboardEvent { private JPanel Clipboard; - private JButton copyButton; + private JButton copySelectedTextButton; private JList clipboardContentList; private final DefaultListModel listModel; private JLabel title; private JScrollPane scrollPane; private JPanel buttonPane; - private JButton clearButton; + private JButton clearAllHistoryButton; private JButton removeButton; + private JLabel imageIconLabel; + private JLabel textClipboardLabel; + private JButton copyImageBelowButton; + private JButton removeImageBelowButton; + private JPanel imageButtonPanel; + private JPanel imagePanel; + + private boolean resize = false; public ClipboardView() { scrollPane.setBorder(BorderFactory.createEmptyBorder()); @@ -90,15 +90,23 @@ public class ClipboardView implements ClipboardEvent { jFrame.setVisible(true); jFrame.setAlwaysOnTop(true); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - jFrame.setPreferredSize(new Dimension(1000, 680)); - jFrame.setMaximumSize(new Dimension(1000, 680)); + jFrame.setPreferredSize(new Dimension(1200, 900)); jFrame.setResizable(true); jFrame.pack(); jFrame.setLocationRelativeTo(null); } @Override - public void onCopy(MyClipboardContent copiedContent) { - listModel.add(0, copiedContent.getContent().toString()); + public void onCopyString(String stringContent) { + listModel.add(0, stringContent); + } + + @Override + public void onCopyImage(BufferedImage imageContent) { + if (imageContent.getWidth() > 1000 || imageContent.getHeight() > 500) { + imageIconLabel.setIcon(new ImageIcon(new ImageIcon(imageContent).getImage().getScaledInstance(1000, 300, Image.SCALE_SMOOTH))); + } else { + imageIconLabel.setIcon(new ImageIcon(imageContent)); + } } }