|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AttributePanel.java | 57.1% | 62.5% | 66.7% | 61.5% |
|
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 |
|
|
22 |
import java.awt.*;
|
|
23 |
import javax.swing.*;
|
|
24 |
import javax.swing.text.*;
|
|
25 |
import javax.swing.text.html.*;
|
|
26 |
import java.util.*;
|
|
27 |
import java.awt.event.*;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* Panel set a group of attributes.
|
|
31 |
*
|
|
32 |
* <p>Abstract base class for other panels such as margin or style panel.</p>
|
|
33 |
*
|
|
34 |
* @author Ulrich Hilger
|
|
35 |
* @author Light Development
|
|
36 |
* @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
|
|
37 |
* @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
|
|
38 |
* @author published under the terms and conditions of the
|
|
39 |
* GNU General Public License,
|
|
40 |
* for details see file gpl.txt in the distribution
|
|
41 |
* package of this software
|
|
42 |
*
|
|
43 |
* @version stage 11, April 27, 2003
|
|
44 |
*/
|
|
45 |
|
|
46 |
public abstract class AttributePanel extends JPanel |
|
47 |
implements AttributeComponent, ContainerListener
|
|
48 |
{ |
|
49 |
|
|
50 |
/** container for all AttributeComponents shown on this AttributePanel */
|
|
51 |
private Vector components = new Vector(); |
|
52 |
|
|
53 |
/**
|
|
54 |
* construct a new AttributePanel
|
|
55 |
*/
|
|
56 | 6 |
public AttributePanel() {
|
57 | 6 |
super();
|
58 | 6 |
this.addContainerListener(this); |
59 |
} |
|
60 |
|
|
61 |
/**
|
|
62 |
* set the value of this <code>AttributeComponent</code>
|
|
63 |
*
|
|
64 |
* @param a the set of attributes possibly having an
|
|
65 |
* attribute this component can display
|
|
66 |
*
|
|
67 |
* @return true, if the set of attributes had a matching attribute,
|
|
68 |
* false if not
|
|
69 |
*/
|
|
70 | 6 |
public boolean setValue(AttributeSet a) { |
71 |
/*
|
|
72 |
System.out.println("AttributePanel setValue");
|
|
73 |
de.calcom.cclib.html.HTMLDiag hd = new de.calcom.cclib.html.HTMLDiag();
|
|
74 |
hd.listAttributes(a, 4);
|
|
75 |
System.out.println("\r\n");
|
|
76 |
*/
|
|
77 | 6 |
boolean result = true; |
78 | 6 |
Enumeration elements = components.elements(); |
79 | 6 |
AttributeComponent ac; |
80 | 6 |
while(elements.hasMoreElements()) {
|
81 | 16 |
ac = (AttributeComponent) elements.nextElement(); |
82 | 16 |
if(!ac.setValue(a)) {
|
83 | 7 |
result = false;
|
84 |
} |
|
85 |
} |
|
86 | 6 |
return result;
|
87 |
} |
|
88 |
|
|
89 |
/**
|
|
90 |
* get the value of this <code>AttributeComponent</code>
|
|
91 |
*
|
|
92 |
* @return the value selected from this component
|
|
93 |
*/
|
|
94 | 4 |
public AttributeSet getValue() {
|
95 | 4 |
SimpleAttributeSet attributes = new SimpleAttributeSet();
|
96 | 4 |
Enumeration elements = components.elements(); |
97 | 4 |
AttributeComponent ac; |
98 | 4 |
while(elements.hasMoreElements()) {
|
99 | 11 |
ac = (AttributeComponent) elements.nextElement(); |
100 | 11 |
attributes.addAttributes(ac.getValue()); |
101 |
} |
|
102 | 4 |
return attributes;
|
103 |
} |
|
104 |
|
|
105 | 0 |
public AttributeSet getValue(boolean includeUnchanged) { |
106 | 0 |
if(includeUnchanged) {
|
107 | 0 |
SimpleAttributeSet attributes = new SimpleAttributeSet();
|
108 | 0 |
Enumeration elements = components.elements(); |
109 | 0 |
AttributeComponent ac; |
110 | 0 |
while(elements.hasMoreElements()) {
|
111 | 0 |
ac = (AttributeComponent) elements.nextElement(); |
112 | 0 |
attributes.addAttributes(ac.getValue(includeUnchanged)); |
113 |
} |
|
114 | 0 |
return attributes;
|
115 |
} |
|
116 |
else {
|
|
117 | 0 |
return getValue();
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 | 26 |
public void componentAdded(ContainerEvent e) { |
122 | 26 |
Object component = e.getChild(); |
123 | 26 |
if(component instanceof AttributeComponent) { |
124 | 16 |
components.add(component); |
125 |
} |
|
126 |
} |
|
127 |
|
|
128 | 0 |
public void componentRemoved(ContainerEvent e) { |
129 | 0 |
Object component = e.getChild(); |
130 | 0 |
if(component instanceof AttributeComponent) { |
131 | 0 |
components.remove(component); |
132 |
} |
|
133 |
} |
|
134 |
} |
|