Initial revision
[old-projects.git] / ekit / com / hexidec / ekit / action / StylesAction.java
CommitLineData
c2da4d40
JL
1/*\r
2GNU Lesser General Public License\r
3\r
4StylesAction\r
5Copyright (C) 2000-2003 Howard Kistler\r
6\r
7This library is free software; you can redistribute it and/or\r
8modify it under the terms of the GNU Lesser General Public\r
9License as published by the Free Software Foundation; either\r
10version 2.1 of the License, or (at your option) any later version.\r
11\r
12This library is distributed in the hope that it will be useful,\r
13but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
15Lesser General Public License for more details.\r
16\r
17You should have received a copy of the GNU Lesser General Public\r
18License along with this library; if not, write to the Free Software\r
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
20*/\r
21\r
22package com.hexidec.ekit.action;\r
23\r
24import java.awt.event.ActionEvent;\r
25import javax.swing.JComboBox;\r
26import javax.swing.JEditorPane;\r
27import javax.swing.text.MutableAttributeSet;\r
28import javax.swing.text.SimpleAttributeSet;\r
29import javax.swing.text.StyledEditorKit;\r
30import javax.swing.text.html.HTML;\r
31import javax.swing.text.html.HTMLEditorKit;\r
32\r
33import com.hexidec.util.Translatrix;\r
34\r
35/** Class for handling CSS style events\r
36 */\r
37public 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