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