|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TableDialog.java | 100% | 98.5% | 90% | 97.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.JDialog;
|
|
21 |
import java.awt.event.ActionListener;
|
|
22 |
import java.awt.AWTEvent;
|
|
23 |
import java.awt.event.WindowEvent;
|
|
24 |
import java.awt.event.ActionEvent;
|
|
25 |
import javax.swing.JDialog;
|
|
26 |
import javax.swing.JButton;
|
|
27 |
import javax.swing.JPanel;
|
|
28 |
import java.awt.Frame;
|
|
29 |
import java.awt.BorderLayout;
|
|
30 |
import java.awt.FlowLayout;
|
|
31 |
import java.awt.Container;
|
|
32 |
import javax.swing.text.AttributeSet;
|
|
33 |
import javax.swing.border.TitledBorder;
|
|
34 |
import javax.swing.border.EtchedBorder;
|
|
35 |
import javax.swing.text.html.CSS;
|
|
36 |
import javax.swing.text.SimpleAttributeSet;
|
|
37 |
import java.awt.GridLayout;
|
|
38 |
import java.awt.GridBagLayout;
|
|
39 |
import java.awt.GridBagConstraints;
|
|
40 |
import java.util.Vector;
|
|
41 |
import javax.swing.JComboBox;
|
|
42 |
import javax.swing.JLabel;
|
|
43 |
import java.awt.Color;
|
|
44 |
import javax.swing.JComponent;
|
|
45 |
import javax.swing.text.html.HTML;
|
|
46 |
import java.util.Enumeration;
|
|
47 |
import javax.swing.JTabbedPane;
|
|
48 |
import java.awt.Dimension;
|
|
49 |
import java.awt.Rectangle;
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Dialog to manipulate HTML table attributes.
|
|
53 |
*
|
|
54 |
* @author Ulrich Hilger
|
|
55 |
* @author Light Development
|
|
56 |
* @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
|
|
57 |
* @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
|
|
58 |
* @author published under the terms and conditions of the
|
|
59 |
* GNU General Public License,
|
|
60 |
* for details see file gpl.txt in the distribution
|
|
61 |
* package of this software
|
|
62 |
*
|
|
63 |
* @version stage 11, April 27, 2003
|
|
64 |
*/
|
|
65 |
public class TableDialog extends DialogShell { |
|
66 |
|
|
67 |
/** collection of all components with table related attributes */
|
|
68 |
Vector tableComponents = new Vector();
|
|
69 |
|
|
70 |
/** collection of all components with cell related attributes */
|
|
71 |
Vector cellComponents = new Vector();
|
|
72 |
|
|
73 |
/** selector for cell range to apply cell attributes to */
|
|
74 |
JComboBox cellRange; |
|
75 |
|
|
76 |
/**
|
|
77 |
* constructor
|
|
78 |
*
|
|
79 |
* @param parent the main frame having the ResourceBundle
|
|
80 |
* @param title the title for this dialog
|
|
81 |
* @param a the set of attributes to show and manipulate
|
|
82 |
*/
|
|
83 | 1 |
public TableDialog(Frame parent, String title) {
|
84 | 1 |
super(parent, title);
|
85 |
|
|
86 |
// add to content pane of DialogShell
|
|
87 | 1 |
Container contentPane = super.getContentPane();
|
88 | 1 |
contentPane.add(buildTablePanel(), BorderLayout.NORTH); |
89 | 1 |
contentPane.add(buildCellPanel(), BorderLayout.CENTER); |
90 |
|
|
91 |
// cause optimal placement of all elements
|
|
92 | 1 |
pack(); |
93 |
} |
|
94 |
|
|
95 | 1 |
public void setTableAttributes(AttributeSet a) { |
96 | 1 |
setComponentAttributes(tableComponents, a); |
97 |
} |
|
98 |
|
|
99 | 1 |
public void setCellAttributes(AttributeSet a) { |
100 | 1 |
setComponentAttributes(cellComponents, a); |
101 |
} |
|
102 |
|
|
103 | 2 |
public void setComponentAttributes(Vector v, AttributeSet a) { |
104 | 2 |
Enumeration components = v.elements(); |
105 | 2 |
AttributeComponent ac; |
106 | 2 |
while(components.hasMoreElements()) {
|
107 | 6 |
ac = (AttributeComponent) components.nextElement(); |
108 | 6 |
ac.setValue(a); |
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
/**
|
|
113 |
* get the set of attributes resulting from the settings on
|
|
114 |
* this TableDialog.
|
|
115 |
*
|
|
116 |
* @return the set of attributes set in this TableDialog
|
|
117 |
*/
|
|
118 | 1 |
public AttributeSet getTableAttributes() {
|
119 | 1 |
return getComponentAttributes(tableComponents);
|
120 |
} |
|
121 |
|
|
122 | 1 |
public AttributeSet getCellAttributes() {
|
123 |
//System.out.println("TableDialog getCellattributes=" + getComponentAttributes(cellComponents));
|
|
124 | 1 |
return getComponentAttributes(cellComponents);
|
125 |
} |
|
126 |
|
|
127 | 2 |
private AttributeSet getComponentAttributes(Vector v) {
|
128 | 2 |
SimpleAttributeSet attributes = new SimpleAttributeSet();
|
129 | 2 |
Enumeration components = v.elements(); |
130 | 2 |
AttributeComponent ac; |
131 | 2 |
while(components.hasMoreElements()) {
|
132 | 6 |
ac = (AttributeComponent) components.nextElement(); |
133 |
//System.out.println(ac.getValue());
|
|
134 | 6 |
attributes.addAttributes(ac.getValue()); |
135 |
} |
|
136 | 2 |
return attributes;
|
137 |
} |
|
138 |
|
|
139 |
/**
|
|
140 |
* build the contents of the cell panel
|
|
141 |
*
|
|
142 |
* this is moved to a separate method to make the code more
|
|
143 |
* legible.
|
|
144 |
*/
|
|
145 | 1 |
private JPanel buildCellPanel() {
|
146 |
|
|
147 |
// have a grid bag layout ready to use
|
|
148 | 1 |
GridBagLayout g = new GridBagLayout();
|
149 | 1 |
GridBagConstraints c = new GridBagConstraints();
|
150 |
|
|
151 |
// construct cell format panel
|
|
152 | 1 |
JPanel cellPanel = new JPanel(new BorderLayout()); |
153 | 1 |
cellPanel.setBorder(new TitledBorder(new EtchedBorder( |
154 |
EtchedBorder.LOWERED), |
|
155 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "cellPanelTitle")));
|
|
156 |
|
|
157 |
// construct tabbed pane for various cell settings
|
|
158 | 1 |
JTabbedPane tp = new JTabbedPane();
|
159 | 1 |
tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); |
160 |
|
|
161 |
// add general panel to tabbed pane
|
|
162 | 1 |
StylePanel sp = new StylePanel(StylePanel.TYPE_TABLE_CELL);
|
163 | 1 |
cellComponents.add(sp); |
164 | 1 |
tp.add(FrmMain.dynRes.getResourceString(FrmMain.resources, "cellGenTabLabel"), sp);
|
165 |
|
|
166 |
// add padding panel to cell components and tabbed pane
|
|
167 | 1 |
MarginPanel mp = new MarginPanel();
|
168 | 1 |
cellComponents.add(mp); |
169 | 1 |
tp.add(FrmMain.dynRes.getResourceString(FrmMain.resources, "cellMarginTabLabel"),mp);
|
170 |
|
|
171 |
// construct border panel
|
|
172 | 1 |
BorderPanel bPanel = new BorderPanel();
|
173 |
|
|
174 |
// add border width panel and border color panel to cell components
|
|
175 | 1 |
cellComponents.add(bPanel); |
176 |
|
|
177 |
// add border panel to tabbed pane
|
|
178 | 1 |
tp.add(FrmMain.dynRes.getResourceString(FrmMain.resources, "cellBorderTabLabel"), bPanel);
|
179 |
|
|
180 |
// create cell range panel
|
|
181 | 1 |
JPanel crPanel = new JPanel();
|
182 | 1 |
String[] cellRangeSelection = new String[] {
|
183 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "thisCellRangeLabel"),
|
|
184 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "thisColRangeLabel"),
|
|
185 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "thisRowRangeLabel"),
|
|
186 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "allCellsRangeLabel")};
|
|
187 | 1 |
crPanel.add(new JLabel(FrmMain.dynRes.getResourceString(FrmMain.resources, "applyCellAttrLabel"))); |
188 | 1 |
cellRange = new JComboBox(cellRangeSelection);
|
189 | 1 |
crPanel.add(cellRange); |
190 |
|
|
191 |
// get the preferred size of the tabbed pane
|
|
192 |
/*
|
|
193 |
int lastTabIndex = tp.getTabCount() - 1;
|
|
194 |
Rectangle tabRect = tp.getBoundsAt(lastTabIndex);
|
|
195 |
int prefWidth = tabRect.x + tabRect.width + 30;
|
|
196 |
tp.setPreferredSize(new Dimension(prefWidth, 300));
|
|
197 |
*/
|
|
198 |
|
|
199 |
// add tabbed pane and range selector to cell panel
|
|
200 | 1 |
cellPanel.add(tp, BorderLayout.CENTER); |
201 | 1 |
cellPanel.add(crPanel, BorderLayout.SOUTH); |
202 |
|
|
203 | 1 |
return cellPanel;
|
204 |
} |
|
205 |
|
|
206 |
/**
|
|
207 |
* get the range of cells to apply cell attributes to
|
|
208 |
*/
|
|
209 | 0 |
public int getCellRange() { |
210 | 0 |
return cellRange.getSelectedIndex();
|
211 |
} |
|
212 |
|
|
213 |
/**
|
|
214 |
* build the contents of the table panel
|
|
215 |
*
|
|
216 |
* this is moved to a separate method to make the code more
|
|
217 |
* legible.
|
|
218 |
*/
|
|
219 | 1 |
private JPanel buildTablePanel() {
|
220 |
|
|
221 |
// layout and constraints to use
|
|
222 | 1 |
GridBagLayout g = new GridBagLayout();
|
223 | 1 |
GridBagConstraints c = new GridBagConstraints();
|
224 |
|
|
225 |
// table panel
|
|
226 | 1 |
JPanel tablePanel = new JPanel(g);
|
227 | 1 |
tablePanel.setBorder(new TitledBorder(new EtchedBorder( |
228 |
EtchedBorder.LOWERED), |
|
229 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "tablePanelTitle")));
|
|
230 |
|
|
231 |
// table width label
|
|
232 | 1 |
JLabel lb = new JLabel(FrmMain.dynRes.getResourceString(FrmMain.resources, "tableWidthLabel")); |
233 | 1 |
Util.addGridBagComponent(tablePanel, lb, g, c, 0, 0, GridBagConstraints.EAST); |
234 |
|
|
235 |
// table width combo box
|
|
236 | 1 |
SizeSelectorPanel ssp = new SizeSelectorPanel(
|
237 |
CSS.Attribute.WIDTH, |
|
238 |
HTML.Attribute.WIDTH, |
|
239 |
false,
|
|
240 |
SizeSelectorPanel.TYPE_COMBO); |
|
241 | 1 |
Util.addGridBagComponent(tablePanel, ssp, g, c, 1, 0, GridBagConstraints.WEST); |
242 | 1 |
tableComponents.addElement(ssp); |
243 |
|
|
244 |
// table background color label
|
|
245 | 1 |
lb = new JLabel(FrmMain.dynRes.getResourceString(FrmMain.resources, "tableBgColLabel")); |
246 | 1 |
Util.addGridBagComponent(tablePanel, lb, g, c, 0, 1, GridBagConstraints.EAST); |
247 |
|
|
248 |
// table background color panel
|
|
249 | 1 |
ColorPanel cp = new ColorPanel(null, Color.white, |
250 |
CSS.Attribute.BACKGROUND_COLOR); |
|
251 | 1 |
Util.addGridBagComponent(tablePanel, cp, g, c, 1, 1, GridBagConstraints.WEST); |
252 | 1 |
tableComponents.addElement(cp); |
253 |
|
|
254 |
// table alignment label
|
|
255 | 1 |
lb = new JLabel(FrmMain.dynRes.getResourceString(FrmMain.resources, "alignLabel")); |
256 | 1 |
Util.addGridBagComponent(tablePanel, lb, g, c, 0, 2, GridBagConstraints.EAST); |
257 |
|
|
258 |
// table alignment combo box
|
|
259 | 1 |
String[] items = new String[] {
|
260 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "alignLeft"),
|
|
261 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "alignCenter"),
|
|
262 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "alignRight") };
|
|
263 | 1 |
String[] names = new String[] {"left", "center", "right"}; |
264 | 1 |
AttributeComboBox tAlgn = new AttributeComboBox(items, names,
|
265 |
CSS.Attribute.TEXT_ALIGN, HTML.Attribute.ALIGN); |
|
266 | 1 |
Util.addGridBagComponent(tablePanel, tAlgn, g, c, 1, 2, GridBagConstraints.WEST); |
267 | 1 |
tableComponents.addElement(tAlgn); |
268 |
|
|
269 | 1 |
return tablePanel;
|
270 |
} |
|
271 |
} |
|