|
|
@@ -0,0 +1,69 @@
|
|
|
+package org.leumasjaffe.graphics;
|
|
|
+
|
|
|
+import java.awt.Component;
|
|
|
+import java.awt.Dimension;
|
|
|
+import java.awt.Font;
|
|
|
+import java.awt.GridBagConstraints;
|
|
|
+import java.awt.GridBagLayout;
|
|
|
+import java.awt.Insets;
|
|
|
+
|
|
|
+import javax.swing.JButton;
|
|
|
+import javax.swing.JLabel;
|
|
|
+import javax.swing.JPanel;
|
|
|
+
|
|
|
+import lombok.AccessLevel;
|
|
|
+import lombok.experimental.FieldDefaults;
|
|
|
+
|
|
|
+@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
+public class RowCollapsingPanel extends JPanel {
|
|
|
+ static String DOWN = "\u25BC";
|
|
|
+ static String RIGHT = "\u25B6";
|
|
|
+
|
|
|
+ public RowCollapsingPanel(GridBagLayout parentLayout, int myRow, String title, Component component) {
|
|
|
+ GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
+ gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
|
|
+ gridBagLayout.rowHeights = new int[]{0, 0};
|
|
|
+ gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
|
+ gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
|
+ setLayout(gridBagLayout);
|
|
|
+
|
|
|
+ JButton btnReveal = new JButton(DOWN);
|
|
|
+ btnReveal.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
|
+ btnReveal.setFont(new Font("Courier New", Font.PLAIN, 10));
|
|
|
+ btnReveal.setPreferredSize(new Dimension(15, 15));
|
|
|
+ btnReveal.setMaximumSize(new Dimension(15, 15));
|
|
|
+ btnReveal.setMinimumSize(new Dimension(15, 15));
|
|
|
+ btnReveal.setMargin(new Insets(0, 0, 0, 0));
|
|
|
+ GridBagConstraints gbc_btnReveal = new GridBagConstraints();
|
|
|
+ gbc_btnReveal.anchor = GridBagConstraints.NORTH;
|
|
|
+ gbc_btnReveal.insets = new Insets(0, 0, 0, 5);
|
|
|
+ gbc_btnReveal.gridx = 0;
|
|
|
+ gbc_btnReveal.gridy = 0;
|
|
|
+ add(btnReveal, gbc_btnReveal);
|
|
|
+
|
|
|
+ GridBagConstraints gbc_component = new GridBagConstraints();
|
|
|
+ gbc_component.fill = GridBagConstraints.BOTH;
|
|
|
+ gbc_component.gridx = 1;
|
|
|
+ gbc_component.gridy = 0;
|
|
|
+ add(component, gbc_component);
|
|
|
+
|
|
|
+ JLabel label = new JLabel(title);
|
|
|
+
|
|
|
+ btnReveal.addActionListener(e -> {
|
|
|
+ if (btnReveal.getText().equals(DOWN)) {
|
|
|
+ remove(component);
|
|
|
+ add(label, gbc_component);
|
|
|
+ btnReveal.setText(RIGHT);
|
|
|
+ btnReveal.setFont(new Font("Courier New", Font.PLAIN, 8));
|
|
|
+ parentLayout.rowWeights[myRow] = 0.0;
|
|
|
+ } else {
|
|
|
+ remove(label);
|
|
|
+ add(component, gbc_component);
|
|
|
+ btnReveal.setText(DOWN);
|
|
|
+ btnReveal.setFont(new Font("Courier New", Font.PLAIN, 10));
|
|
|
+ parentLayout.rowWeights[myRow] = 1.0;
|
|
|
+ }
|
|
|
+ validate();
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|