Search in sources :

Example 1 with AlignmentStrategy

use of com.github.weisj.darklaf.components.alignment.AlignmentStrategy in project darklaf by weisJ.

the class ToolTipDemo method createComponent.

@Override
public JComponent createComponent() {
    JButton button = new JButton("Demo Button", DemoResources.FOLDER_ICON);
    DemoPanel panel = new DemoPanel(button);
    ToolTipContext context = new ToolTipContext(button).setAlignment(Alignment.CENTER).setCenterAlignment(Alignment.SOUTH);
    ToolTipContext.setDefaultContext(context);
    button.setToolTipText(StringUtil.toHtml("<p style=\"color:red;\">This is the ToolTip demo text!\n" + "<p style=\"color:blue;\">This is the ToolTip demo text!\n" + "<p style=\"color:green;\">This is the ToolTip demo text!\n"));
    button.putClientProperty(DarkToolTipUI.KEY_STYLE, DarkToolTipUI.VARIANT_BALLOON);
    button.putClientProperty(DarkToolTipUI.KEY_CONTEXT, context);
    JPanel controlPanel = panel.addControls(3);
    controlPanel.add(new JCheckBox("Align inside") {

        {
            setSelected(context.isAlignInside());
            addActionListener(e -> context.setAlignInside(isSelected()));
        }
    });
    controlPanel.add(new JCheckBox("Ignore Border") {

        {
            setSelected(context.isIgnoreBorder());
            addActionListener(e -> context.setIgnoreBorder(isSelected()));
        }
    });
    controlPanel.add(new JCheckBox("Use best fit") {

        {
            setSelected(context.isBestFit());
            addActionListener(e -> context.setUseBestFit(isSelected()));
        }
    });
    controlPanel = panel.addControls();
    controlPanel.add(new JLabel("Tooltip Style:", JLabel.RIGHT));
    controlPanel.add(new JComboBox<ToolTipStyle>(ToolTipStyle.values()) {

        {
            setSelectedItem(ToolTipStyle.BALLOON);
            addItemListener(e -> button.putClientProperty(DarkToolTipUI.KEY_STYLE, e.getItem()));
        }
    }, "sgx");
    controlPanel.add(new JLabel("Alignment:", JLabel.RIGHT));
    controlPanel.add(new JComboBox<Alignment>(Alignment.values()) {

        {
            setSelectedItem(context.getAlignment());
            addItemListener(e -> context.setAlignment((Alignment) e.getItem()));
        }
    }, "sgx");
    controlPanel.add(new JLabel("Center Alignment:", JLabel.RIGHT));
    controlPanel.add(new JComboBox<Alignment>(Alignment.values()) {

        {
            setSelectedItem(context.getCenterAlignment());
            addItemListener(e -> context.setCenterAlignment((Alignment) e.getItem()));
        }
    }, "sgx");
    controlPanel.add(new JLabel("Alignment Strategy:", JLabel.RIGHT));
    controlPanel.add(new JComboBox<AlignmentStrategy>(AlignmentStrategy.values()) {

        {
            setSelectedItem(context.getAlignmentStrategy());
            addItemListener(e -> context.setAlignmentStrategy((AlignmentStrategy) e.getItem()));
        }
    }, "sgx");
    return panel;
}
Also used : DemoExecutor(com.github.weisj.darklaf.ui.demo.DemoExecutor) BaseComponentDemo(com.github.weisj.darklaf.ui.demo.BaseComponentDemo) Alignment(com.github.weisj.darklaf.util.Alignment) AlignmentStrategy(com.github.weisj.darklaf.components.alignment.AlignmentStrategy) ToolTipContext(com.github.weisj.darklaf.components.tooltip.ToolTipContext) ToolTipStyle(com.github.weisj.darklaf.components.tooltip.ToolTipStyle) DemoPanel(com.github.weisj.darklaf.ui.DemoPanel) StringUtil(com.github.weisj.darklaf.util.StringUtil) DemoResources(com.github.weisj.darklaf.ui.DemoResources) javax.swing(javax.swing) DarkToolTipUI(com.github.weisj.darklaf.ui.tooltip.DarkToolTipUI) DemoPanel(com.github.weisj.darklaf.ui.DemoPanel) ToolTipStyle(com.github.weisj.darklaf.components.tooltip.ToolTipStyle) Alignment(com.github.weisj.darklaf.util.Alignment) ToolTipContext(com.github.weisj.darklaf.components.tooltip.ToolTipContext) AlignmentStrategy(com.github.weisj.darklaf.components.alignment.AlignmentStrategy)

Aggregations

AlignmentStrategy (com.github.weisj.darklaf.components.alignment.AlignmentStrategy)1 ToolTipContext (com.github.weisj.darklaf.components.tooltip.ToolTipContext)1 ToolTipStyle (com.github.weisj.darklaf.components.tooltip.ToolTipStyle)1 DemoPanel (com.github.weisj.darklaf.ui.DemoPanel)1 DemoResources (com.github.weisj.darklaf.ui.DemoResources)1 BaseComponentDemo (com.github.weisj.darklaf.ui.demo.BaseComponentDemo)1 DemoExecutor (com.github.weisj.darklaf.ui.demo.DemoExecutor)1 DarkToolTipUI (com.github.weisj.darklaf.ui.tooltip.DarkToolTipUI)1 Alignment (com.github.weisj.darklaf.util.Alignment)1 StringUtil (com.github.weisj.darklaf.util.StringUtil)1 javax.swing (javax.swing)1