Search in sources :

Example 1 with WrapLayout

use of com.pixbits.lib.ui.WrapLayout in project rom-manager by Jakz.

the class ClonesEnumPanel method update.

public void update(final Game game) {
    Runnable updater = () -> {
        inner.removeAll();
        // inner.setLayout(mode == Mode.COMPACT ? new FlowLayout() : new BoxLayout(inner, BoxLayout.PAGE_AXIS));
        inner.setLayout(new WrapLayout());
        this.game = game;
        if (game != null) {
            GameClone clones = game.getClone();
            if (clones != null) {
                this.clones = clones.stream().toArray(i -> new Game[i]);
                // title.setText("Clones: "+this.clones.length);
                inner.add(new JLabel("" + this.clones.length + " clones:"));
                for (final Game clone : this.clones) {
                    JButton label = new JButton();
                    label.setFocusPainted(false);
                    label.setContentAreaFilled(false);
                    label.setOpaque(false);
                    Icon icon = clone.getLocation().getIcon();
                    label.setIcon(icon != null ? icon.getIcon() : null);
                    label.setText(mode == Mode.COMPACT ? clone.getVersion().toString() : clone.getCorrectName());
                    // if (game == clone)
                    // label.setFont(label.getFont().deriveFont(Font.BOLD));
                    label.setForeground(clone.getStatus().color);
                    if (game == clone)
                        label.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 2), BorderFactory.createEmptyBorder(4, 4, 4, 4)));
                    else
                        label.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.GRAY), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
                    label.setToolTipText(clone.getCorrectName());
                    label.addActionListener(e -> {
                        if (game != clone)
                            mediator.selectGameIfVisible(clone);
                    });
                    inner.add(label);
                }
                revalidate();
                repaint();
                return;
            }
        }
        title.setText("");
        revalidate();
        repaint();
        return;
    };
    if (SwingUtilities.isEventDispatchThread())
        updater.run();
    else
        SwingUtilities.invokeLater(updater);
}
Also used : Color(java.awt.Color) JComponent(javax.swing.JComponent) FlowLayout(java.awt.FlowLayout) Insets(java.awt.Insets) Icon(com.github.jakz.romlib.ui.Icon) JButton(javax.swing.JButton) Font(java.awt.Font) WrapLayout(com.pixbits.lib.ui.WrapLayout) Game(com.github.jakz.romlib.data.game.Game) BorderFactory(javax.swing.BorderFactory) MouseEvent(java.awt.event.MouseEvent) GameSet(com.github.jakz.romlib.data.set.GameSet) Dimension(java.awt.Dimension) SwingUtilities(javax.swing.SwingUtilities) JLabel(javax.swing.JLabel) MouseAdapter(java.awt.event.MouseAdapter) GameClone(com.github.jakz.romlib.data.game.GameClone) BorderLayout(java.awt.BorderLayout) JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) Mediator(jack.rm.gui.Mediator) Game(com.github.jakz.romlib.data.game.Game) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) GameClone(com.github.jakz.romlib.data.game.GameClone) Icon(com.github.jakz.romlib.ui.Icon) WrapLayout(com.pixbits.lib.ui.WrapLayout)

Aggregations

Game (com.github.jakz.romlib.data.game.Game)1 GameClone (com.github.jakz.romlib.data.game.GameClone)1 GameSet (com.github.jakz.romlib.data.set.GameSet)1 Icon (com.github.jakz.romlib.ui.Icon)1 WrapLayout (com.pixbits.lib.ui.WrapLayout)1 Mediator (jack.rm.gui.Mediator)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 Font (java.awt.Font)1 Insets (java.awt.Insets)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 BorderFactory (javax.swing.BorderFactory)1 BoxLayout (javax.swing.BoxLayout)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1