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