package org.leumasjaffe.charsheet.view.level; import java.util.function.Consumer; import java.util.stream.IntStream; import javax.swing.JPanel; import org.jdesktop.swingx.VerticalLayout; import org.leumasjaffe.charsheet.view.skills.SkillLevelUpPanel; import org.leumasjaffe.function.VoidVoidFunction; import org.leumasjaffe.observer.Observable; import org.leumasjaffe.observer.ObservableListener; import org.leumasjaffe.observer.ObserverDispatch; import lombok.AccessLevel; import lombok.experimental.FieldDefaults; import java.awt.GridBagLayout; import javax.swing.JTabbedPane; import java.awt.GridBagConstraints; import java.awt.Insets; import java.awt.Component; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JLabel; @SuppressWarnings("serial") @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true) class UpdateClassWithLevelPanel extends JPanel { @FieldDefaults(level=AccessLevel.PUBLIC, makeFinal=true) public class BoolArray extends Observable { boolean data[] = new boolean[] {false}; } BoolArray readyCount = new BoolArray(); ObservableListener, BoolArray> listener; public UpdateClassWithLevelPanel(LevelUpClassInfo info, VoidVoidFunction back, Consumer setReady) { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{0, 0}; gridBagLayout.rowHeights = new int[]{0, 0, 0}; gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{1.0, 0.0, Double.MIN_VALUE}; setLayout(gridBagLayout); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); GridBagConstraints gbc_tabbedPane = new GridBagConstraints(); gbc_tabbedPane.insets = new Insets(0, 0, 5, 0); gbc_tabbedPane.fill = GridBagConstraints.BOTH; gbc_tabbedPane.gridx = 0; gbc_tabbedPane.gridy = 0; add(tabbedPane, gbc_tabbedPane); JPanel features = new JPanel(new VerticalLayout(2)); info.ddClass.getBase().getFeatures(info.toLevel).forEach(prop -> { features.add(new JLabel(prop.getName())); }); tabbedPane.addTab("Features", null, features, null); JPanel skills = new SkillLevelUpPanel(info.ddCharacter, info.ddClass) { @Override public void setIsReady(boolean b) { readyCount.data[0] = b; ObserverDispatch.notifySubscribers(readyCount, null); } }; tabbedPane.addTab("Skills", null, skills, null); JPanel panel = new JPanel(); GridBagConstraints gbc_panel = new GridBagConstraints(); gbc_panel.fill = GridBagConstraints.BOTH; gbc_panel.gridx = 0; gbc_panel.gridy = 1; add(panel, gbc_panel); GridBagLayout gbl_panel = new GridBagLayout(); gbl_panel.columnWidths = new int[]{0, 0, 0}; gbl_panel.rowHeights = new int[]{0, 0}; gbl_panel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE}; panel.setLayout(gbl_panel); JButton btnBack = new JButton("Back"); GridBagConstraints gbc_btnBack = new GridBagConstraints(); gbc_btnBack.insets = new Insets(0, 0, 0, 5); gbc_btnBack.gridx = 0; gbc_btnBack.gridy = 0; panel.add(btnBack, gbc_btnBack); btnBack.addActionListener(e -> back.apply()); Component horizontalGlue = Box.createHorizontalGlue(); GridBagConstraints gbc_horizontalGlue = new GridBagConstraints(); gbc_horizontalGlue.gridx = 1; gbc_horizontalGlue.gridy = 0; panel.add(horizontalGlue, gbc_horizontalGlue); listener = new ObservableListener<>(setReady, (c, v) -> { c.accept(IntStream.range(0, v.data.length) .mapToObj(i -> v.data[i]).allMatch(b -> b)); }); listener.setObserved(readyCount); } }