Update GUI

main
sgoudham 3 years ago
parent f621a2d156
commit 5c8d99b0f4
No known key found for this signature in database
GPG Key ID: EF51A29A50FB754C

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="me.goudham.view.ClipboardView"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="me.goudham.view.ClipboardView">
<grid id="27dc6" binding="Clipboard" layout-manager="GridBagLayout"> <grid id="27dc6" binding="clipboard" layout-manager="GridBagLayout">
<constraints> <constraints>
<xy x="20" y="20" width="641" height="499"/> <xy x="20" y="20" width="641" height="794"/>
</constraints> </constraints>
<properties> <properties>
<background color="-16710887"/> <background color="-16710887"/>
@ -60,7 +60,7 @@
<margin top="0" left="10" bottom="0" right="10"/> <margin top="0" left="10" bottom="0" right="10"/>
<constraints> <constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag top="5" left="0" bottom="0" right="0" weightx="0.0" weighty="0.0"/> <gridbag top="5" left="0" bottom="0" right="0" weightx="1.0" weighty="0.0"/>
</constraints> </constraints>
<properties> <properties>
<background color="-16710887"/> <background color="-16710887"/>
@ -101,31 +101,10 @@
</component> </component>
</children> </children>
</grid> </grid>
<grid id="eb90f" binding="imagePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="5" bottom="0" right="5"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<background color="-16710887"/>
</properties>
<border type="none"/>
<children>
<component id="d4095" class="javax.swing.JLabel" binding="imageIconLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
<component id="f6be9" class="javax.swing.JLabel"> <component id="f6be9" class="javax.swing.JLabel">
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
<gridbag top="5" left="0" bottom="5" right="0" weightx="0.0" weighty="0.0"/> <gridbag top="5" left="0" bottom="5" right="0" weightx="1.0" weighty="0.0"/>
</constraints> </constraints>
<properties> <properties>
<font name="Berlin Sans FB Demi" size="24" style="1"/> <font name="Berlin Sans FB Demi" size="24" style="1"/>
@ -136,7 +115,7 @@
<component id="12b73" class="javax.swing.JLabel" binding="textClipboardLabel"> <component id="12b73" class="javax.swing.JLabel" binding="textClipboardLabel">
<constraints> <constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/> <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
<gridbag top="5" left="0" bottom="5" right="0" weightx="0.0" weighty="0.0"/> <gridbag top="5" left="0" bottom="5" right="0" weightx="1.0" weighty="0.0"/>
</constraints> </constraints>
<properties> <properties>
<font name="Berlin Sans FB Demi" size="24" style="1"/> <font name="Berlin Sans FB Demi" size="24" style="1"/>
@ -144,11 +123,11 @@
<text value="Text History"/> <text value="Text History"/>
</properties> </properties>
</component> </component>
<grid id="865e3" binding="imageButtonPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="865e3" binding="imageButtonPanel" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="10" bottom="10" right="10"/> <margin top="0" left="10" bottom="10" right="10"/>
<constraints> <constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/> <gridbag weightx="1.0" weighty="0.0"/>
</constraints> </constraints>
<properties> <properties>
<background color="-16710887"/> <background color="-16710887"/>
@ -165,14 +144,47 @@
</component> </component>
<component id="b16b7" class="javax.swing.JButton" binding="removeImageBelowButton" default-binding="true"> <component id="b16b7" class="javax.swing.JButton" binding="removeImageBelowButton" default-binding="true">
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<text value="Remove Image Below"/> <text value="Remove Image Below"/>
</properties> </properties>
</component> </component>
<component id="6b15e" class="javax.swing.JButton" binding="toggleImageButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Toggle Image"/>
</properties>
</component>
</children> </children>
</grid> </grid>
<scrollpane id="6714a" binding="anotherImagePanel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag top="5" left="5" bottom="5" right="5" weightx="1.0" weighty="1.0"/>
</constraints>
<properties>
<background color="-16710887"/>
<foreground color="-16710887"/>
<opaque value="false"/>
</properties>
<border type="none"/>
<children>
<component id="d4095" class="javax.swing.JLabel" binding="imageIconLabel">
<constraints/>
<properties>
<autoscrolls value="true"/>
<background color="-16710887"/>
<horizontalAlignment value="0"/>
<horizontalTextPosition value="0"/>
<opaque value="true"/>
<text value=""/>
</properties>
</component>
</children>
</scrollpane>
</children> </children>
</grid> </grid>
</form> </form>

@ -1,7 +1,6 @@
package me.goudham.view; package me.goudham.view;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Image;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
@ -12,11 +11,13 @@ import javax.swing.JLabel;
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 me.goudham.ClipboardListener;
import me.goudham.listener.ClipboardEvent; import me.goudham.listener.ClipboardEvent;
import me.goudham.listener.MacClipboardListener;
import me.goudham.listener.WindowsOrUnixClipboardListener;
import org.apache.commons.lang3.SystemUtils;
public class ClipboardView implements ClipboardEvent { public class ClipboardView implements ClipboardEvent {
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;
@ -30,15 +31,36 @@ public class ClipboardView implements ClipboardEvent {
private JButton copyImageBelowButton; private JButton copyImageBelowButton;
private JButton removeImageBelowButton; private JButton removeImageBelowButton;
private JPanel imageButtonPanel; private JPanel imageButtonPanel;
private JPanel imagePanel; private JButton toggleImageButton;
private JScrollPane anotherImagePanel;
private boolean toggle = true;
private BufferedImage storedImageContent;
public ClipboardView() { public ClipboardView() {
scrollPane.setBorder(BorderFactory.createEmptyBorder()); scrollPane.setBorder(BorderFactory.createEmptyBorder());
anotherImagePanel.setBorder(BorderFactory.createEmptyBorder());
buttonPane.setBorder(BorderFactory.createEmptyBorder()); buttonPane.setBorder(BorderFactory.createEmptyBorder());
listModel = new DefaultListModel<>(); listModel = new DefaultListModel<>();
clipboardContentList.setModel(listModel); clipboardContentList.setModel(listModel);
// final java.awt.datatransfer.Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); toggleImageButton.addActionListener(actionEvent -> {
if (toggle) {
imageIconLabel.setIcon(null);
// anotherImagePanel.setPreferredSize(new Dimension(0, 0));
// anotherImagePanel.setVisible(false);
// imageIconLabel.setMaximumSize(new Dimension(0, 0));
// anotherImagePanel.setPreferredSize(new Dimension(0, 0));
toggle = false;
} else {
// anotherImagePanel.setPreferredSize(new Dimension(300, 300));
imageIconLabel.setIcon(new ImageIcon(storedImageContent));
// anotherImagePanel.setVisible(true);
toggle = true;
}
});
// final java.awt.datatransfer.clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
// final MyClipboardContent<?> previousContent = new MyClipboardContent<>(""); // final MyClipboardContent<?> previousContent = new MyClipboardContent<>("");
// final int[] count = {0}; // final int[] count = {0};
// //
@ -80,11 +102,17 @@ public class ClipboardView implements ClipboardEvent {
} }
public void createAndShowGUI() { public void createAndShowGUI() {
new ClipboardListener(this).start(); me.goudham.listener.ClipboardListener clipboardListener = null;
if (isMac()) {
clipboardListener = new MacClipboardListener(this);
} else if (isUnix() || isWindows()) {
clipboardListener = new WindowsOrUnixClipboardListener(this);
}
clipboardListener.execute();
JFrame jFrame = new JFrame(); JFrame jFrame = new JFrame();
jFrame.setTitle("My Clipboard History"); jFrame.setTitle("My Clipboard History");
jFrame.setContentPane(Clipboard); jFrame.setContentPane(clipboard);
jFrame.setVisible(true); jFrame.setVisible(true);
jFrame.setAlwaysOnTop(true); jFrame.setAlwaysOnTop(true);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -101,10 +129,26 @@ public class ClipboardView implements ClipboardEvent {
@Override @Override
public void onCopyImage(BufferedImage imageContent) { public void onCopyImage(BufferedImage imageContent) {
if (imageContent.getWidth() > 1000 || imageContent.getHeight() > 500) { storedImageContent = imageContent;
imageIconLabel.setIcon(new ImageIcon(new ImageIcon(imageContent).getImage().getScaledInstance(1000, 300, Image.SCALE_SMOOTH))); imageIconLabel.setIcon(new ImageIcon(imageContent));
} else { toggle = true;
imageIconLabel.setIcon(new ImageIcon(imageContent)); //
} // if (imageContent.getWidth() > 1000 || imageContent.getHeight() > 1000) {
// imageIconLabel.setIcon(new ImageIcon(new ImageIcon(imageContent).getImage().getScaledInstance(1000, 600, Image.SCALE_SMOOTH)));
// } else {
// imageIconLabel.setIcon(new ImageIcon(imageContent));
// }
}
private boolean isMac() {
return SystemUtils.IS_OS_MAC;
}
private boolean isUnix() {
return SystemUtils.IS_OS_UNIX || SystemUtils.IS_OS_LINUX;
}
private boolean isWindows() {
return SystemUtils.IS_OS_WINDOWS;
} }
} }

Loading…
Cancel
Save