Commit | Line | Data |
---|---|---|
c2da4d40 JL |
1 | /*\r |
2 | GNU Lesser General Public License\r | |
3 | \r | |
4 | StylesAction\r | |
5 | Copyright (C) 2000-2003 Howard Kistler\r | |
6 | \r | |
7 | This library is free software; you can redistribute it and/or\r | |
8 | modify it under the terms of the GNU Lesser General Public\r | |
9 | License as published by the Free Software Foundation; either\r | |
10 | version 2.1 of the License, or (at your option) any later version.\r | |
11 | \r | |
12 | This library is distributed in the hope that it will be useful,\r | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of\r | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r | |
15 | Lesser General Public License for more details.\r | |
16 | \r | |
17 | You should have received a copy of the GNU Lesser General Public\r | |
18 | License along with this library; if not, write to the Free Software\r | |
19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r | |
20 | */\r | |
21 | \r | |
22 | package com.hexidec.ekit.action;\r | |
23 | \r | |
24 | import java.awt.event.ActionEvent;\r | |
25 | import javax.swing.JComboBox;\r | |
26 | import javax.swing.JEditorPane;\r | |
27 | import javax.swing.text.MutableAttributeSet;\r | |
28 | import javax.swing.text.SimpleAttributeSet;\r | |
29 | import javax.swing.text.StyledEditorKit;\r | |
30 | import javax.swing.text.html.HTML;\r | |
31 | import javax.swing.text.html.HTMLEditorKit;\r | |
32 | \r | |
33 | import com.hexidec.util.Translatrix;\r | |
34 | \r | |
35 | /** Class for handling CSS style events\r | |
36 | */\r | |
37 | public class StylesAction extends StyledEditorKit.StyledTextAction\r | |
38 | {\r | |
39 | \r | |
40 | JComboBox parent;\r | |
41 | \r | |
42 | public StylesAction(JComboBox myParent)\r | |
43 | {\r | |
44 | super("css-style");\r | |
45 | parent = myParent;\r | |
46 | }\r | |
47 | \r | |
48 | public void actionPerformed(ActionEvent e)\r | |
49 | {\r | |
50 | if(!(this.isEnabled()))\r | |
51 | {\r | |
52 | return;\r | |
53 | }\r | |
54 | JEditorPane editor = getEditor(e);\r | |
55 | if(editor != null)\r | |
56 | {\r | |
57 | String stylename = (String)(parent.getSelectedItem());\r | |
58 | if(stylename == null)\r | |
59 | {\r | |
60 | return;\r | |
61 | }\r | |
62 | else if(stylename.equals(Translatrix.getTranslationString("NoCSSStyle")))\r | |
63 | {\r | |
64 | return;\r | |
65 | }\r | |
66 | boolean replace = false;\r | |
67 | MutableAttributeSet attr = null;\r | |
68 | SimpleAttributeSet cls = new SimpleAttributeSet();\r | |
69 | cls.addAttribute(HTML.Attribute.CLASS, stylename);\r | |
70 | attr = new SimpleAttributeSet();\r | |
71 | attr.addAttribute(HTML.Tag.FONT, cls);\r | |
72 | MutableAttributeSet inattr = ((HTMLEditorKit)(editor.getEditorKitForContentType("text/html"))).getInputAttributes();\r | |
73 | inattr.addAttributes(attr);\r | |
74 | setCharacterAttributes(editor, attr, replace);\r | |
75 | }\r | |
76 | }\r | |
77 | }\r |