Use JSplitPane for showing text & images dynamically

main
sgoudham 3 years ago
parent d7afe6b44f
commit 7e1c62de83
No known key found for this signature in database
GPG Key ID: EF51A29A50FB754C

@ -2,7 +2,7 @@
<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">
<constraints>
<xy x="20" y="20" width="641" height="794"/>
<xy x="20" y="20" width="710" height="682"/>
</constraints>
<properties>
<background color="-16710887"/>
@ -12,241 +12,185 @@
</clientProperties>
<border type="none"/>
<children>
<component id="ccd73" class="javax.swing.JLabel" binding="title">
<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"/>
<gridbag weightx="1.0" weighty="0.0"/>
</constraints>
<properties>
<font name="Berlin Sans FB Demi" size="48" style="1"/>
<foreground color="-7401958"/>
<text value="My Clipboard History"/>
<verticalTextPosition value="1"/>
</properties>
</component>
<scrollpane id="1de68" binding="scrollPane">
<splitpane id="a64a3">
<constraints>
<grid row="7" column="0" row-span="2" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag top="10" left="10" bottom="10" right="10" weightx="1.0" weighty="1.0"/>
<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">
<preferred-size width="200" height="200"/>
</grid>
<gridbag weightx="1.0" weighty="1.0"/>
</constraints>
<properties>
<autoscrolls value="true"/>
<background color="-16710887"/>
<continuousLayout value="true"/>
<foreground color="-16710887"/>
<oneTouchExpandable value="true"/>
<opaque value="true"/>
<orientation value="0"/>
<preferredSize width="300" height="250"/>
</properties>
<border type="none"/>
<children>
<component id="d2b04" class="javax.swing.JList" binding="clipboardContentList">
<constraints/>
<scrollpane id="681c6" binding="imageScrollPane">
<constraints>
<splitpane position="right"/>
</constraints>
<properties>
<alignmentX value="0.5"/>
<alignmentY value="0.5"/>
<autoscrolls value="false"/>
<background color="-16710887"/>
<dragEnabled value="false"/>
<fixedCellHeight value="-1"/>
<fixedCellWidth value="-1"/>
<focusable value="true"/>
<font name="Berlin Sans FB Demi" size="18" style="1"/>
<foreground color="-263169"/>
<inheritsPopupMenu value="false"/>
<layoutOrientation value="0"/>
<model/>
<foreground color="-16710887"/>
<maximumSize width="300" height="300"/>
<minimumSize width="0" height="0"/>
<opaque value="false"/>
<preferredSize width="300" height="300"/>
</properties>
<clientProperties>
<List.isFileList class="java.lang.Boolean" value="false"/>
</clientProperties>
</component>
<border type="none"/>
<children>
<component id="a0714" class="javax.swing.JLabel" binding="imageLabel">
<constraints/>
<properties>
<autoscrolls value="true"/>
<background color="-16710887"/>
<horizontalAlignment value="0"/>
<horizontalTextPosition value="0"/>
<opaque value="true"/>
<text value=""/>
</properties>
</component>
</children>
</scrollpane>
<scrollpane id="cebe0" binding="clipboardContentScrollPane">
<constraints>
<splitpane position="left"/>
</constraints>
<properties>
<minimumSize width="0" height="0"/>
</properties>
<border type="none"/>
<children>
<component id="d2b04" class="javax.swing.JList" binding="clipboardContentList">
<constraints/>
<properties>
<alignmentX value="0.5"/>
<alignmentY value="0.5"/>
<background color="-16710887"/>
<dragEnabled value="false"/>
<fixedCellHeight value="-1"/>
<fixedCellWidth value="-1"/>
<focusable value="true"/>
<font name="Berlin Sans FB Demi" size="18" style="1"/>
<foreground color="-263169"/>
<inheritsPopupMenu value="false"/>
<layoutOrientation value="0"/>
<model/>
</properties>
<clientProperties>
<List.isFileList class="java.lang.Boolean" value="false"/>
</clientProperties>
</component>
</children>
</scrollpane>
</children>
</scrollpane>
<grid id="a7b09" binding="buttonPane" 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="0" right="10"/>
</splitpane>
<grid id="865e3" binding="imageButtonPanel" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="6" 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"/>
<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 top="5" left="5" bottom="5" right="5" weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<background color="-16710887"/>
<minimumSize width="367" height="30"/>
<preferredSize width="367" height="30"/>
</properties>
<border type="none"/>
<children>
<component id="17bdb" class="javax.swing.JButton" binding="copySelectedTextButton" default-binding="true">
<component id="b16b7" class="javax.swing.JButton" binding="removeImageBelowButton" default-binding="true">
<constraints>
<grid row="0" column="0" 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>
<properties>
<borderPainted value="true"/>
<doubleBuffered value="true"/>
<text value="Copy Selected Text"/>
<text value="Remove Image Below"/>
</properties>
<clientProperties>
<hideActionText class="java.lang.Boolean" value="false"/>
</clientProperties>
</component>
<component id="c36b1" class="javax.swing.JButton" binding="clearAllHistoryButton" default-binding="true">
<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>
<borderPainted value="true"/>
<doubleBuffered value="true"/>
<text value="Clear All History"/>
<text value="Toggle Image"/>
</properties>
</component>
<component id="b7183" class="javax.swing.JButton" binding="removeButton">
<component id="cbf3c" class="javax.swing.JButton" binding="copyImageBelowButton" default-binding="true">
<constraints>
<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"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<actionCommand value="Button"/>
<text value="Remove Selected Text"/>
<horizontalTextPosition value="11"/>
<preferredSize width="126" height="30"/>
<text value="Copy Image Below"/>
</properties>
</component>
</children>
</grid>
<component id="f6be9" class="javax.swing.JLabel">
<grid id="a7b09" binding="textButtonPanel" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" 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"/>
</constraints>
<properties>
<font name="Berlin Sans FB Demi" size="24" style="1"/>
<foreground color="-263169"/>
<text value="Last Copied Image"/>
</properties>
</component>
<component id="12b73" class="javax.swing.JLabel" binding="textClipboardLabel">
<constraints>
<grid row="5" 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"/>
</constraints>
<properties>
<font name="Berlin Sans FB Demi" size="24" style="1"/>
<foreground color="-263169"/>
<text value="Text History"/>
</properties>
</component>
<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"/>
<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"/>
<grid row="1" 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="5" bottom="5" right="5" weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<background color="-16710887"/>
<preferredSize width="389" height="30"/>
</properties>
<border type="none"/>
<children>
<component id="cbf3c" class="javax.swing.JButton" binding="copyImageBelowButton" default-binding="true">
<component id="17bdb" class="javax.swing.JButton" binding="copySelectedTextButton" default-binding="true">
<constraints>
<grid row="0" column="0" 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="Copy Image Below"/>
<borderPainted value="true"/>
<doubleBuffered value="true"/>
<text value="Copy Selected Text"/>
</properties>
<clientProperties>
<hideActionText class="java.lang.Boolean" value="false"/>
</clientProperties>
</component>
<component id="b16b7" class="javax.swing.JButton" binding="removeImageBelowButton" default-binding="true">
<component id="c36b1" class="javax.swing.JButton" binding="clearAllHistoryButton" default-binding="true">
<constraints>
<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"/>
<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="Remove Image Below"/>
<borderPainted value="true"/>
<doubleBuffered value="true"/>
<text value="Clear All History"/>
</properties>
</component>
<component id="6b15e" class="javax.swing.JButton" binding="toggleImageButton" default-binding="true">
<component id="b7183" class="javax.swing.JButton" binding="removeButton">
<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>
<properties>
<text value="Toggle Image"/>
<actionCommand value="Button"/>
<text value="Remove Selected Text"/>
</properties>
</component>
</children>
</grid>
<scrollpane id="6714a" binding="anotherImagePanel">
<constraints>
<grid row="4" 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="0.0" weighty="0.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>
<splitpane id="a64a3">
<component id="ccd73" class="javax.swing.JLabel" binding="title">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
</grid>
<gridbag weightx="0.0" weighty="0.0"/>
<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"/>
<gridbag weightx="1.0" weighty="0.0"/>
</constraints>
<properties>
<autoscrolls value="true"/>
<background color="-16710887"/>
<continuousLayout value="true"/>
<foreground color="-16710887"/>
<oneTouchExpandable value="true"/>
<opaque value="true"/>
<orientation value="0"/>
<preferredSize width="300" height="300"/>
<font name="Berlin Sans FB Demi" size="48" style="1"/>
<foreground color="-7401958"/>
<text value="My Clipboard History"/>
<verticalTextPosition value="1"/>
</properties>
<border type="none"/>
<children>
<component id="fc284" class="javax.swing.JList" binding="list1" default-binding="true">
<constraints>
<splitpane position="left"/>
</constraints>
<properties>
<background color="-16710887"/>
<font name="JetBrains Mono" size="18" style="1"/>
<foreground color="-1"/>
<minimumSize width="0" height="0"/>
<model/>
<opaque value="false"/>
<requestFocusEnabled value="false"/>
</properties>
</component>
<scrollpane id="681c6">
<constraints>
<splitpane position="right"/>
</constraints>
<properties>
<background color="-16710887"/>
<foreground color="-16710887"/>
<opaque value="false"/>
</properties>
<border type="none"/>
<children>
<component id="a0714" class="javax.swing.JLabel" binding="yetAnotherImageIcon">
<constraints/>
<properties>
<autoscrolls value="true"/>
<background color="-16710887"/>
<horizontalAlignment value="0"/>
<horizontalTextPosition value="0"/>
<maximumSize width="0" height="0"/>
<minimumSize width="0" height="0"/>
<opaque value="true"/>
<preferredSize width="0" height="0"/>
<text value=""/>
</properties>
</component>
</children>
</scrollpane>
</children>
</splitpane>
</component>
</children>
</grid>
</form>

@ -22,34 +22,30 @@ public class ClipboardView implements ClipboardEvent {
private JList<String> clipboardContentList;
private final DefaultListModel<String> listModel;
private JLabel title;
private JScrollPane scrollPane;
private JPanel buttonPane;
private JPanel textButtonPanel;
private JButton clearAllHistoryButton;
private JButton removeButton;
private JLabel imageIconLabel;
private JLabel textClipboardLabel;
private JButton copyImageBelowButton;
private JButton removeImageBelowButton;
private JPanel imageButtonPanel;
private JButton toggleImageButton;
private JScrollPane anotherImagePanel;
private JList<String> list1;
private JLabel yetAnotherImageIcon;
private JLabel imageLabel;
private JScrollPane imageScrollPane;
private JScrollPane clipboardContentScrollPane;
private boolean toggle = true;
private BufferedImage storedImageContent;
public ClipboardView() {
scrollPane.setBorder(BorderFactory.createEmptyBorder());
anotherImagePanel.setBorder(BorderFactory.createEmptyBorder());
buttonPane.setBorder(BorderFactory.createEmptyBorder());
imageScrollPane.setBorder(BorderFactory.createEmptyBorder());
clipboardContentScrollPane.setBorder(BorderFactory.createEmptyBorder());
textButtonPanel.setBorder(BorderFactory.createEmptyBorder());
listModel = new DefaultListModel<>();
clipboardContentList.setModel(listModel);
list1.setModel(listModel);
toggleImageButton.addActionListener(actionEvent -> {
if (toggle) {
yetAnotherImageIcon.setIcon(null);
imageLabel.setIcon(null);
// anotherImagePanel.setPreferredSize(null);
// anotherImagePanel.setVisible(false);
// imageIconLabel.setMaximumSize(new Dimension(0, 0));
@ -58,7 +54,7 @@ public class ClipboardView implements ClipboardEvent {
} else {
// anotherImagePanel.setPreferredSize(new Dimension(300, 300));
// anotherImagePanel.setVisible(true);
yetAnotherImageIcon.setIcon(new ImageIcon(storedImageContent));
imageLabel.setIcon(new ImageIcon(storedImageContent));
toggle = true;
}
// anotherImagePanel.revalidate();
@ -135,7 +131,7 @@ public class ClipboardView implements ClipboardEvent {
public void onCopyImage(BufferedImage imageContent) {
storedImageContent = imageContent;
// anotherImagePanel.setMinimumSize(new Dimension(300, 300));
yetAnotherImageIcon.setIcon(new ImageIcon(imageContent));
imageLabel.setIcon(new ImageIcon(imageContent));
toggle = true;
//
// if (imageContent.getWidth() > 1000 || imageContent.getHeight() > 1000) {

Loading…
Cancel
Save