Initial revision
[old-projects.git] / ekit / com / hexidec / ekit / action / StylesAction.java
diff --git a/ekit/com/hexidec/ekit/action/StylesAction.java b/ekit/com/hexidec/ekit/action/StylesAction.java
new file mode 100644 (file)
index 0000000..1f6657b
--- /dev/null
@@ -0,0 +1,77 @@
+/*\r
+GNU Lesser General Public License\r
+\r
+StylesAction\r
+Copyright (C) 2000-2003 Howard Kistler\r
+\r
+This library is free software; you can redistribute it and/or\r
+modify it under the terms of the GNU Lesser General Public\r
+License as published by the Free Software Foundation; either\r
+version 2.1 of the License, or (at your option) any later version.\r
+\r
+This library is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+Lesser General Public License for more details.\r
+\r
+You should have received a copy of the GNU Lesser General Public\r
+License along with this library; if not, write to the Free Software\r
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+*/\r
+\r
+package com.hexidec.ekit.action;\r
+\r
+import java.awt.event.ActionEvent;\r
+import javax.swing.JComboBox;\r
+import javax.swing.JEditorPane;\r
+import javax.swing.text.MutableAttributeSet;\r
+import javax.swing.text.SimpleAttributeSet;\r
+import javax.swing.text.StyledEditorKit;\r
+import javax.swing.text.html.HTML;\r
+import javax.swing.text.html.HTMLEditorKit;\r
+\r
+import com.hexidec.util.Translatrix;\r
+\r
+/** Class for handling CSS style events\r
+  */\r
+public class StylesAction extends StyledEditorKit.StyledTextAction\r
+{\r
+\r
+       JComboBox parent;\r
+\r
+       public StylesAction(JComboBox myParent)\r
+       {\r
+               super("css-style");\r
+               parent = myParent;\r
+       }\r
+\r
+       public void actionPerformed(ActionEvent e)\r
+       {\r
+               if(!(this.isEnabled()))\r
+               {\r
+                       return;\r
+               }\r
+               JEditorPane editor = getEditor(e);\r
+               if(editor != null)\r
+               {\r
+                       String stylename = (String)(parent.getSelectedItem());\r
+                       if(stylename == null)\r
+                       {\r
+                               return;\r
+                       }\r
+                       else if(stylename.equals(Translatrix.getTranslationString("NoCSSStyle")))\r
+                       {\r
+                               return;\r
+                       }\r
+                       boolean replace = false;\r
+                       MutableAttributeSet     attr = null;\r
+                       SimpleAttributeSet cls = new SimpleAttributeSet();\r
+                       cls.addAttribute(HTML.Attribute.CLASS, stylename);\r
+                       attr = new SimpleAttributeSet();\r
+                       attr.addAttribute(HTML.Tag.FONT, cls);\r
+                       MutableAttributeSet inattr = ((HTMLEditorKit)(editor.getEditorKitForContentType("text/html"))).getInputAttributes();\r
+                       inattr.addAttributes(attr);\r
+                       setCharacterAttributes(editor, attr, replace);\r
+               }\r
+       }\r
+}\r