[3952] | 1 | /* |
---|
| 2 | * SimplyHTML, a word processor based on Java, HTML and CSS |
---|
| 3 | * Copyright (C) 2002 Ulrich Hilger |
---|
| 4 | * |
---|
| 5 | * This program is free software; you can redistribute it and/or |
---|
| 6 | * modify it under the terms of the GNU General Public License |
---|
| 7 | * as published by the Free Software Foundation; either version 2 |
---|
| 8 | * of the License, or (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with this program; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | package nu.fw.jeti.plugins.xhtml.fontchooser; |
---|
| 21 | |
---|
| 22 | import java.awt.Font; |
---|
| 23 | import java.awt.GridLayout; |
---|
| 24 | |
---|
| 25 | import javax.swing.ButtonGroup; |
---|
| 26 | import javax.swing.JPanel; |
---|
| 27 | import javax.swing.JRadioButton; |
---|
| 28 | import javax.swing.UIManager; |
---|
| 29 | import javax.swing.border.EtchedBorder; |
---|
| 30 | import javax.swing.border.TitledBorder; |
---|
| 31 | import javax.swing.text.AttributeSet; |
---|
| 32 | import javax.swing.text.SimpleAttributeSet; |
---|
| 33 | import javax.swing.text.StyleConstants; |
---|
| 34 | |
---|
| 35 | /** |
---|
| 36 | * a panel to display and change line attributes |
---|
| 37 | * |
---|
| 38 | * @author Ulrich Hilger |
---|
| 39 | * @author Light Development |
---|
| 40 | * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a> |
---|
| 41 | * @author <a href="mailto:info@lightdev.com">info@lightdev.com</a> |
---|
| 42 | * @author published under the terms and conditions of the |
---|
| 43 | * GNU General Public License, |
---|
| 44 | * for details see file gpl.txt in the distribution |
---|
| 45 | * package of this software |
---|
| 46 | * |
---|
| 47 | * @version stage 9, release 4, January 12, 2003 |
---|
| 48 | */ |
---|
| 49 | public class EffectPanel extends JPanel implements AttributeComponent { |
---|
| 50 | |
---|
| 51 | /** a radio button for the underline attribute */ |
---|
| 52 | JRadioButton uLine; |
---|
| 53 | |
---|
| 54 | /** a radio button for the strike through attribute */ |
---|
| 55 | JRadioButton strike; |
---|
| 56 | |
---|
| 57 | /** a radio button if no line effect is set */ |
---|
| 58 | JRadioButton noLine; |
---|
| 59 | |
---|
| 60 | private Object originalValue; |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | String selection = "Util.CSS_ATTRIBUTE_NONE"; |
---|
| 64 | |
---|
| 65 | public EffectPanel() { |
---|
| 66 | super(new GridLayout(3,1,3,3)); |
---|
| 67 | |
---|
| 68 | /** initialize the line effects button group */ |
---|
| 69 | noLine = new JRadioButton("noLine"); |
---|
| 70 | uLine = new JRadioButton("underLine"); |
---|
| 71 | strike = new JRadioButton("striketrough"); |
---|
| 72 | ButtonGroup effectGroup = new ButtonGroup(); |
---|
| 73 | effectGroup.add(noLine); |
---|
| 74 | effectGroup.add(uLine); |
---|
| 75 | effectGroup.add(strike); |
---|
| 76 | |
---|
| 77 | //JPanel linePanel = new JPanel(new GridLayout(3,1,3,3)); |
---|
| 78 | setBorder(new TitledBorder(new EtchedBorder( |
---|
| 79 | EtchedBorder.LOWERED),"effect")); |
---|
| 80 | Font font = UIManager.getFont("TextField.font"); |
---|
| 81 | uLine.setFont(font); |
---|
| 82 | strike.setFont(font); |
---|
| 83 | noLine.setFont(font); |
---|
| 84 | add(noLine); |
---|
| 85 | add(uLine); |
---|
| 86 | add(strike); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | public AttributeSet getValue(boolean includeUnchanged) { |
---|
| 90 | if(includeUnchanged) { |
---|
| 91 | return getAttributes(); |
---|
| 92 | } |
---|
| 93 | else { |
---|
| 94 | return getValue(); |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | private AttributeSet getAttributes() { |
---|
| 99 | SimpleAttributeSet set = new SimpleAttributeSet(); |
---|
| 100 | if(uLine.isSelected()) { |
---|
| 101 | StyleConstants.setUnderline(set, true); |
---|
| 102 | selection="sdf"; |
---|
| 103 | } |
---|
| 104 | else if(strike.isSelected()) { |
---|
| 105 | StyleConstants.setStrikeThrough(set, true); |
---|
| 106 | selection="sdf"; |
---|
| 107 | } |
---|
| 108 | return set; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | public AttributeSet getValue() { |
---|
| 112 | if(((originalValue == null)) || |
---|
| 113 | ((originalValue != null) && (!originalValue.toString().equalsIgnoreCase(selection)))) |
---|
| 114 | { |
---|
| 115 | return getAttributes(); |
---|
| 116 | } |
---|
| 117 | else { |
---|
| 118 | return getAttributes(); |
---|
| 119 | //return new SimpleAttributeSet(); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | public boolean setValue(AttributeSet a) { |
---|
| 124 | // boolean success = false; |
---|
| 125 | // if(a.isDefined(CSS.Attribute.TEXT_DECORATION)) { |
---|
| 126 | // String value = a.getAttribute(CSS.Attribute.TEXT_DECORATION).toString(); |
---|
| 127 | // if(value.equalsIgnoreCase(Util.CSS_ATTRIBUTE_UNDERLINE)) { |
---|
| 128 | // uLine.setSelected(true); |
---|
| 129 | // if(++setValCount < 2) { |
---|
| 130 | // originalValue = Util.CSS_ATTRIBUTE_UNDERLINE; |
---|
| 131 | // } |
---|
| 132 | // success = true; |
---|
| 133 | // } |
---|
| 134 | // else if(value.equalsIgnoreCase(Util.CSS_ATTRIBUTE_LINE_THROUGH)) { |
---|
| 135 | // strike.setSelected(true); |
---|
| 136 | // if(++setValCount < 2) { |
---|
| 137 | // originalValue = Util.CSS_ATTRIBUTE_LINE_THROUGH; |
---|
| 138 | // } |
---|
| 139 | // success = true; |
---|
| 140 | // } |
---|
| 141 | // else { |
---|
| 142 | // noLine.setSelected(true); |
---|
| 143 | // } |
---|
| 144 | // } |
---|
| 145 | // else { |
---|
| 146 | // noLine.setSelected(true); |
---|
| 147 | // } |
---|
| 148 | // return success; |
---|
| 149 | // } |
---|
| 150 | return true; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | /* |
---|
| 154 | * Overrides for emacs |
---|
| 155 | * Local variables: |
---|
| 156 | * tab-width: 4 |
---|
| 157 | * End: |
---|
| 158 | */ |
---|