|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ListPanel.java | 0% | 0% | 0% | 0% |
|
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 |
import javax.swing.JPanel;
|
|
21 |
import java.awt.GridBagLayout;
|
|
22 |
import java.awt.BorderLayout;
|
|
23 |
import java.awt.GridBagConstraints;
|
|
24 |
import javax.swing.JComboBox;
|
|
25 |
import javax.swing.JLabel;
|
|
26 |
import javax.swing.text.AttributeSet;
|
|
27 |
import javax.swing.text.SimpleAttributeSet;
|
|
28 |
import javax.swing.text.html.CSS;
|
|
29 |
import javax.swing.text.html.HTML;
|
|
30 |
import javax.swing.border.TitledBorder;
|
|
31 |
import javax.swing.border.EtchedBorder;
|
|
32 |
import java.util.Hashtable;
|
|
33 |
import javax.swing.text.StyleConstants;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* A panel for showing and manipulating list format.
|
|
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 11, April 27, 2003
|
|
48 |
*/
|
|
49 |
|
|
50 |
public class ListPanel extends JPanel implements AttributeComponent { |
|
51 |
|
|
52 |
/** selector for list type */
|
|
53 |
private AttributeComboBox listType;
|
|
54 |
|
|
55 |
/** selector for list position */
|
|
56 |
private AttributeComboBox listPosition;
|
|
57 |
|
|
58 |
/** list indent selector */
|
|
59 |
private BoundariesPanel bndPanel;
|
|
60 |
|
|
61 |
/** list tag from setValue/getValue (UL or OL) */
|
|
62 |
private String listTag;
|
|
63 |
|
|
64 |
/**
|
|
65 |
* construct a new ListPanel
|
|
66 |
*/
|
|
67 | 0 |
public ListPanel() {
|
68 |
|
|
69 | 0 |
setLayout(new BorderLayout());
|
70 |
|
|
71 |
// have a grid bag layout ready to use
|
|
72 | 0 |
GridBagLayout g = new GridBagLayout();
|
73 | 0 |
GridBagConstraints c = new GridBagConstraints();
|
74 |
|
|
75 |
// build list format panel
|
|
76 | 0 |
JPanel formatPanel = new JPanel(g);
|
77 |
|
|
78 |
// add label for list type
|
|
79 | 0 |
Util.addGridBagComponent(formatPanel, new JLabel(
|
80 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listTypeLabel")),
|
|
81 |
g, c, 0, 0, GridBagConstraints.EAST); |
|
82 |
|
|
83 |
// add combo box for list type selection
|
|
84 | 0 |
String[] items = new String[] {
|
85 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listTypeNone"),
|
|
86 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listTypeDecimal"),
|
|
87 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listTypeLowerRoman"),
|
|
88 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listTypeUpperRoman"),
|
|
89 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listTypeLowerAlpha"),
|
|
90 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listTypeUpperAlpha"),
|
|
91 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listTypeDisc"),
|
|
92 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listTypeCircle"),
|
|
93 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listTypeSquare")};
|
|
94 | 0 |
String[] names = new String[] {"none", "decimal", "lower-roman", "upper-roman", |
95 |
"lower-alpha", "upper-alpha", "disc", "circle", "square"}; |
|
96 | 0 |
listType = new AttributeComboBox(items, names,
|
97 |
CSS.Attribute.LIST_STYLE_TYPE, null);
|
|
98 | 0 |
Util.addGridBagComponent(formatPanel, listType, g, c, 1, 0, |
99 |
GridBagConstraints.WEST); |
|
100 |
|
|
101 |
// add label for list position
|
|
102 | 0 |
Util.addGridBagComponent(formatPanel, new JLabel(
|
103 |
FrmMain.dynRes.getResourceString( |
|
104 |
FrmMain.resources, "listPositionLabel")),
|
|
105 |
g, c, 0, 1, GridBagConstraints.EAST); |
|
106 |
|
|
107 |
// add combo box for list postion selection
|
|
108 | 0 |
items = new String[] {
|
109 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listPosInside"),
|
|
110 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "listPosOutside")};
|
|
111 | 0 |
names = new String[] {"inside", "outside"}; |
112 | 0 |
listPosition = new AttributeComboBox(items, names,
|
113 |
CSS.Attribute.LIST_STYLE_POSITION, null);
|
|
114 | 0 |
Util.addGridBagComponent(formatPanel, listPosition, g, c, 1, 1, |
115 |
GridBagConstraints.WEST); |
|
116 |
|
|
117 |
// create list boundaries panel
|
|
118 | 0 |
bndPanel = new BoundariesPanel(CSS.Attribute.MARGIN);
|
119 | 0 |
bndPanel.setBorder(new TitledBorder(new EtchedBorder( |
120 |
EtchedBorder.LOWERED), |
|
121 |
FrmMain.dynRes.getResourceString( |
|
122 |
FrmMain.resources, "listIndentTitle")));
|
|
123 |
|
|
124 |
// add components to this ListPanel
|
|
125 | 0 |
add(formatPanel, BorderLayout.CENTER); |
126 | 0 |
add(bndPanel, BorderLayout.SOUTH); |
127 |
} |
|
128 |
|
|
129 |
/**
|
|
130 |
* get the list tag currently selected in this <code>ListPanel</code>
|
|
131 |
*
|
|
132 |
* @return the list tag currently selected or null, if no list is selected
|
|
133 |
*/
|
|
134 | 0 |
public String getListTag() {
|
135 | 0 |
return listTag;
|
136 |
} |
|
137 |
|
|
138 |
/**
|
|
139 |
* translate list types as per CSS attribute list-style-type into list
|
|
140 |
* tag (UL or OL).
|
|
141 |
*/
|
|
142 | 0 |
private void setTagFromType() { |
143 | 0 |
int index = listType.getSelectedIndex();
|
144 | 0 |
if(index > 5) {
|
145 | 0 |
listTag = HTML.Tag.UL.toString(); |
146 |
} |
|
147 | 0 |
else if(index > 0) { |
148 | 0 |
listTag = HTML.Tag.OL.toString(); |
149 |
} |
|
150 |
else {
|
|
151 | 0 |
listTag = null;
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
/**
|
|
156 |
* set the value of this <code>AttributeComponent</code>
|
|
157 |
*
|
|
158 |
* @param a the set of attributes possibly having an
|
|
159 |
* attribute this component can display
|
|
160 |
*
|
|
161 |
* @return true, if the set of attributes had a matching attribute,
|
|
162 |
* false if not
|
|
163 |
*/
|
|
164 | 0 |
public boolean setValue(AttributeSet a) { |
165 | 0 |
Object name = a.getAttribute(javax.swing.text.StyleConstants.NameAttribute); |
166 | 0 |
if(name != null) { |
167 | 0 |
listTag = name.toString(); |
168 |
} |
|
169 | 0 |
listType.setValue(a); |
170 | 0 |
listPosition.setValue(a); |
171 | 0 |
bndPanel.setValue(a); |
172 | 0 |
return true; |
173 |
} |
|
174 |
|
|
175 |
/**
|
|
176 |
* get the value of this <code>AttributeComponent</code>
|
|
177 |
*
|
|
178 |
* @return the value selected from this component
|
|
179 |
*/
|
|
180 | 0 |
public AttributeSet getValue() {
|
181 | 0 |
setTagFromType(); |
182 | 0 |
SimpleAttributeSet set = new SimpleAttributeSet();
|
183 | 0 |
set.addAttributes(listType.getValue()); |
184 | 0 |
set.addAttributes(listPosition.getValue()); |
185 | 0 |
set.addAttributes(bndPanel.getValue()); |
186 | 0 |
return set;
|
187 |
} |
|
188 |
|
|
189 | 0 |
public AttributeSet getValue(boolean includeUnchanged) { |
190 | 0 |
if(includeUnchanged) {
|
191 | 0 |
setTagFromType(); |
192 | 0 |
SimpleAttributeSet set = new SimpleAttributeSet();
|
193 | 0 |
set.addAttributes(listType.getValue(includeUnchanged)); |
194 | 0 |
set.addAttributes(listPosition.getValue(includeUnchanged)); |
195 | 0 |
set.addAttributes(bndPanel.getValue(includeUnchanged)); |
196 | 0 |
return set;
|
197 |
} |
|
198 |
else {
|
|
199 | 0 |
return getValue();
|
200 |
} |
|
201 |
} |
|
202 |
} |
|