aboutsummaryrefslogtreecommitdiff
path: root/libjava/javax/swing/plaf/basic/BasicOptionPaneUI.java
blob: bfb6cbadfdc6ad05e853ca44f2ad344618817019 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package javax.swing.plaf.basic;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.accessibility.*;

public class BasicOptionPaneUI extends OptionPaneUI
{
    JOptionPane pane;

    BasicOptionPaneUI()
    {
    }

    public static ComponentUI createUI(JComponent x) 
    {
        return new BasicOptionPaneUI();
    }

    public void installUI(JComponent c)
    {
	super.installUI(c);
	pane = (JOptionPane)c;

	System.out.println("     -------------: " + pane);

	JLabel  message   = pane.msg != null ? new JLabel((String)pane.msg) : null;
	JButton ok_button = new JButton("Ok");	

	ok_button.addActionListener(new ActionListener()
	    {
		public void actionPerformed(ActionEvent a)
		{
		    System.out.println("ACTION ---> " + a);
		    //		    pane.dialog.dispose();

		    if (pane.dialog.isModal())
			{
			    System.out.println("modal dialog !!");
			    pane.dialog.setModal(false);
			}
		    pane.dialog.setVisible(false);
		}
	    });

	if (pane.args != null)
	    {
		for (int i=0; i<pane.args.length; i++)
		    {
			Object o = pane.args[i];
			if (o != null)
			    {
				if (o instanceof String)
				    {
					String s = (String) o;
					JLabel m = new JLabel(s);
					pane.add(m);
				    }
				else if (o instanceof Component)
				    {
					Component com = (Component) o;
					pane.add(com);
				    }
				else
				    {
					System.out.println("UNRECOGNIZED ARG: " + o);
				    }
			    }
		    }
	    }

	pane.add(message);
	pane.add(ok_button);
    }

    Dimension getMinimumOptionPaneSize()
    {
	return new Dimension(300,100);
    }

    public Dimension getPreferredSize(JComponent c)
    {
	if (c == null)
	    return getMinimumOptionPaneSize();

	if (c != pane)
	    return null;

	LayoutManager l  = c.getLayout();
	if (l == null)
	    return getMinimumOptionPaneSize();

	Dimension d1 = l.preferredLayoutSize(c);
	Dimension d2 = getMinimumOptionPaneSize();
	
	d1.width = Math.max(d1.width, d2.width);
	d1.height = Math.max(d1.height, d2.height);

	return d2;
    }
}