File: DSourceListExpansionListener.java

package info (click to toggle)
mac-widgets 0.10.0%2Bsvn416-dfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,968 kB
  • sloc: java: 9,909; makefile: 13; sh: 12
file content (84 lines) | stat: -rw-r--r-- 3,422 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.explodingpixels.macwidgets;

import com.explodingpixels.widgets.WindowUtils;

import javax.swing.*;
import java.awt.*;

public class DSourceListExpansionListener {
    private static Object[] willExpandOptions = {"Cancel Expansion", "Expand"};
    private static String willExpandText = "A branch node is about to be expanded.\n"
                                  + "Click \"Cancel Expansion\" to prevent it.";
    private static String willExpandTitle = "Tree Will Expand";

    public static void main(String[] args) {

        final SourceListExpansionListener expansionListener = new SourceListExpansionListener() {
            public void sourceListItemExpanded(SourceListItem item) {
                System.out.println("SourceListItem " +item.getText() + " was expanded.");
            }

            public void sourceListItemCollapsed(SourceListItem item) {
                System.out.println("SourceListItem " +item.getText() + " was collapsed.");
            }

            public void sourceListCategoryExpanded(SourceListCategory category) {
                System.out.println("SourceListCategory " +category.getText() + " was expanded.");
            }

            public void sourceListCategoryCollapsed(SourceListCategory category) {
                System.out.println("SourceListCategory " +category.getText() + " was collapsed.");
            }

            public boolean shouldExpandSourceListItem(SourceListItem item) {
                int n = JOptionPane.showOptionDialog(
                        null, willExpandText, willExpandTitle,
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        willExpandOptions,
                        willExpandOptions[1]);

                if (n == JOptionPane.YES_OPTION) {
                    return false;
                }

                System.out.println("SourceListItem " +item.getText() + " will be expanded.");
                return true;
            }

            public boolean shouldCollapseSourceListItem(SourceListItem item) {
                System.out.println("SourceListItem " +item.getText() + " will be collapsed.");
                return true;
            }

            public boolean shouldExpandSourceListCategory(SourceListCategory category) {
                System.out.println("SourceListCategory " +category.getText() + " will be expanded.");
                return true;
            }

            public boolean shouldToCollapseSourceListCategory(SourceListCategory category) {
                System.out.println("SourceListCategory " +category.getText() + " will be collapsed.");
                return true;
            }
        };

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {

                SourceList sourceList = DSourceListMail.createSourceList();
                sourceList.addSourceListExpansionListener(expansionListener);

                JFrame frame = new JFrame();
                WindowUtils.createAndInstallRepaintWindowFocusListener(frame);
                frame.add(sourceList.getComponent(), BorderLayout.CENTER);
                frame.setSize(225, 250);
                frame.setLocationRelativeTo(null);
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.setVisible(true);

            }
        });

    }
}