1 | package nu.fw.jeti.plugins.xhtml; |
---|
2 | |
---|
3 | import java.awt.Color; |
---|
4 | import java.awt.GridBagConstraints; |
---|
5 | import java.awt.GridBagLayout; |
---|
6 | import java.awt.Insets; |
---|
7 | |
---|
8 | import javax.swing.Box; |
---|
9 | import javax.swing.JLabel; |
---|
10 | import javax.swing.text.AttributeSet; |
---|
11 | import javax.swing.text.MutableAttributeSet; |
---|
12 | import javax.swing.text.SimpleAttributeSet; |
---|
13 | import javax.swing.text.StyleConstants; |
---|
14 | import javax.swing.text.html.StyleSheet; |
---|
15 | |
---|
16 | import nu.fw.jeti.jabber.Backend; |
---|
17 | import nu.fw.jeti.plugins.PreferencesPanel; |
---|
18 | import nu.fw.jeti.plugins.xhtml.fontchooser.FontPanel; |
---|
19 | import nu.fw.jeti.util.I18N; |
---|
20 | import nu.fw.jeti.util.Preferences; |
---|
21 | |
---|
22 | |
---|
23 | /** |
---|
24 | * <p>Title: J2M</p> |
---|
25 | * <p>Description: </p> |
---|
26 | * <p>Copyright: Copyright (c) 2002</p> |
---|
27 | * <p>Company: </p> |
---|
28 | * @author E.S. de Boer |
---|
29 | * @version 1.0 |
---|
30 | */ |
---|
31 | |
---|
32 | public class PrefPanel extends PreferencesPanel |
---|
33 | { |
---|
34 | private FontPanel fontPanel = new FontPanel(); |
---|
35 | private StyleSheet styleSheet = new StyleSheet(); |
---|
36 | |
---|
37 | public PrefPanel(Backend backend) |
---|
38 | { |
---|
39 | setLayout(new GridBagLayout()); |
---|
40 | GridBagConstraints c = new GridBagConstraints(); |
---|
41 | c.anchor = GridBagConstraints.LINE_START; |
---|
42 | c.insets = new Insets(3, 5, 0, 3); |
---|
43 | c.gridwidth = GridBagConstraints.REMAINDER; |
---|
44 | |
---|
45 | //this.backend = backend; |
---|
46 | MutableAttributeSet set = new SimpleAttributeSet(); |
---|
47 | int i = Preferences.getInteger("xhtml", "foreground", 0); |
---|
48 | if (i != 0) |
---|
49 | { |
---|
50 | StyleConstants.setForeground(set, new Color(i)); |
---|
51 | } |
---|
52 | i = Preferences.getInteger("xhtml", "background", 0); |
---|
53 | if (i != 0) |
---|
54 | { |
---|
55 | StyleConstants.setBackground(set, new Color(i)); |
---|
56 | } |
---|
57 | i = Preferences.getInteger("xhtml", "font-size", 0); |
---|
58 | if (i != 0) |
---|
59 | { |
---|
60 | StyleConstants.setFontSize(set, i); |
---|
61 | } |
---|
62 | StyleConstants.setBold(set,Preferences.getBoolean("xhtml","bold",false)); |
---|
63 | StyleConstants.setItalic(set,Preferences.getBoolean("xhtml","italic",false)); |
---|
64 | StyleConstants.setFontFamily(set, Preferences.getString("xhtml", "font-family", "Arial")); |
---|
65 | fontPanel.setAttributes(set); |
---|
66 | |
---|
67 | add(new JLabel(I18N.gettext("xhtml.The_font_used_when_sending_messages")), c); |
---|
68 | add(fontPanel, c); |
---|
69 | |
---|
70 | c.weighty = 1.0; |
---|
71 | c.weightx = 1.0; |
---|
72 | add(Box.createVerticalGlue(), c); |
---|
73 | } |
---|
74 | |
---|
75 | public void savePreferences() |
---|
76 | { |
---|
77 | AttributeSet set = fontPanel.getAttributes(); |
---|
78 | Color c; |
---|
79 | if (set.isDefined(StyleConstants.Foreground)) |
---|
80 | { |
---|
81 | c = (Color) set.getAttribute(StyleConstants.Foreground); |
---|
82 | Preferences.putInteger("xhtml", "foreground", c.getRGB()); |
---|
83 | } |
---|
84 | if (set.isDefined(StyleConstants.Background)) |
---|
85 | { |
---|
86 | c = (Color) set.getAttribute(StyleConstants.Background); |
---|
87 | Preferences.putInteger("xhtml", "background", c.getRGB()); |
---|
88 | } |
---|
89 | if (set.isDefined(StyleConstants.FontFamily)) |
---|
90 | { |
---|
91 | Preferences.putString("xhtml", "font-family", StyleConstants.getFontFamily(set)); |
---|
92 | } |
---|
93 | if (set.isDefined(StyleConstants.FontSize)) |
---|
94 | { |
---|
95 | Preferences.putInteger("xhtml", "font-size", StyleConstants.getFontSize(set)); |
---|
96 | } |
---|
97 | Preferences.putBoolean("xhtml","bold",StyleConstants.isBold(set)); |
---|
98 | Preferences.putBoolean("xhtml","italic",StyleConstants.isItalic(set)); |
---|
99 | } |
---|
100 | |
---|
101 | } |
---|
102 | /* |
---|
103 | * Overrides for emacs |
---|
104 | * Local variables: |
---|
105 | * tab-width: 4 |
---|
106 | * End: |
---|
107 | */ |
---|