|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
StylePanel.java | 100% | 94.3% | 66.7% | 92.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 java.awt.*;
|
|
21 |
import javax.swing.*;
|
|
22 |
import javax.swing.text.*;
|
|
23 |
import javax.swing.text.html.*;
|
|
24 |
import java.util.*;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* Panel to set general text style attributes such as indent or alignment.
|
|
28 |
*
|
|
29 |
* @author Ulrich Hilger
|
|
30 |
* @author Light Development
|
|
31 |
* @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
|
|
32 |
* @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
|
|
33 |
* @author published under the terms and conditions of the
|
|
34 |
* GNU General Public License,
|
|
35 |
* for details see file gpl.txt in the distribution
|
|
36 |
* package of this software
|
|
37 |
*
|
|
38 |
* @version stage 11, April 27, 2003
|
|
39 |
*/
|
|
40 |
|
|
41 |
public class StylePanel extends AttributePanel { |
|
42 |
|
|
43 |
public static final int TYPE_PARAGRAPH = 1; |
|
44 |
public static final int TYPE_TABLE_CELL = 2; |
|
45 |
|
|
46 |
private AttributeComboBox ctAlgn;
|
|
47 |
private AttributeComboBox cAlgn;
|
|
48 |
|
|
49 | 3 |
public StylePanel(int type) { |
50 | 3 |
super();
|
51 |
|
|
52 | 3 |
JLabel lb; |
53 |
|
|
54 |
// have a grid bag layout ready to use
|
|
55 | 3 |
GridBagLayout g = new GridBagLayout();
|
56 | 3 |
GridBagConstraints c = new GridBagConstraints();
|
57 |
|
|
58 | 3 |
this.setLayout(g);
|
59 |
|
|
60 | 3 |
if(type == TYPE_TABLE_CELL) {
|
61 |
// background color label
|
|
62 | 1 |
lb = new JLabel(FrmMain.dynRes.getResourceString(FrmMain.resources, "tableBgColLabel")); |
63 | 1 |
Util.addGridBagComponent(this, lb, g, c, 0, 0, GridBagConstraints.EAST);
|
64 |
|
|
65 |
// background color panel
|
|
66 | 1 |
ColorPanel cp = new ColorPanel(null, Color.white, |
67 |
CSS.Attribute.BACKGROUND_COLOR); |
|
68 | 1 |
Util.addGridBagComponent(this, cp, g, c, 1, 0, GridBagConstraints.WEST);
|
69 |
} |
|
70 |
|
|
71 |
// text alignment label
|
|
72 | 3 |
lb = new JLabel(FrmMain.dynRes.getResourceString(FrmMain.resources, "alignLabel")); |
73 | 3 |
Util.addGridBagComponent(this, lb, g, c, 0, 1, GridBagConstraints.EAST);
|
74 |
|
|
75 |
// text align combo box
|
|
76 | 3 |
String[] items = new String[] {
|
77 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "alignLeft"),
|
|
78 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "alignCenter"),
|
|
79 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "alignRight") };
|
|
80 | 3 |
String[] names = new String[] {"left", "center", "right"}; |
81 | 3 |
ctAlgn = new AttributeComboBox(items, names,
|
82 |
CSS.Attribute.TEXT_ALIGN, HTML.Attribute.ALIGN); |
|
83 | 3 |
Util.addGridBagComponent(this, ctAlgn, g, c, 1, 1, GridBagConstraints.WEST);
|
84 |
|
|
85 |
// vertical alignment label
|
|
86 | 3 |
lb = new JLabel(FrmMain.dynRes.getResourceString(FrmMain.resources, "valignLabel")); |
87 | 3 |
Util.addGridBagComponent(this, lb, g, c, 0, 2, GridBagConstraints.EAST);
|
88 |
|
|
89 |
// vertical alignment combo box
|
|
90 | 3 |
items = new String[] {
|
91 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "valignTop"),
|
|
92 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "valignMiddle"),
|
|
93 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "valignBottom"),
|
|
94 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "valignBaseline")};
|
|
95 | 3 |
names = new String[] {"top", "middle", "bottom", "baseline"}; |
96 | 3 |
cAlgn = new AttributeComboBox(items, names,
|
97 |
CSS.Attribute.VERTICAL_ALIGN, HTML.Attribute.VALIGN); |
|
98 | 3 |
Util.addGridBagComponent(this, cAlgn, g, c, 1, 2, GridBagConstraints.WEST);
|
99 |
|
|
100 | 3 |
switch(type) {
|
101 | 2 |
case TYPE_PARAGRAPH:
|
102 | 2 |
addSizeSelector(FrmMain.dynRes.getResourceString( |
103 |
FrmMain.resources, "textIndentLabel"), CSS.Attribute.TEXT_INDENT, null, true, g, c); |
|
104 | 2 |
break;
|
105 | 1 |
case TYPE_TABLE_CELL:
|
106 | 1 |
addSizeSelector(FrmMain.dynRes.getResourceString( |
107 |
FrmMain.resources, "tableWidthLabel"), CSS.Attribute.WIDTH, HTML.Attribute.WIDTH, false, g, c); |
|
108 | 1 |
break;
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 | 0 |
public void reset() { |
113 | 0 |
ctAlgn.reset(); |
114 | 0 |
cAlgn.reset(); |
115 |
} |
|
116 |
|
|
117 | 3 |
private void addSizeSelector(String text, CSS.Attribute ca, HTML.Attribute ha, boolean negVals, |
118 |
GridBagLayout g, GridBagConstraints c) |
|
119 |
{ |
|
120 |
// label
|
|
121 | 3 |
JLabel lb = new JLabel(text);
|
122 | 3 |
Util.addGridBagComponent(this, lb, g, c, 0, 3, GridBagConstraints.EAST);
|
123 |
|
|
124 |
// selector
|
|
125 | 3 |
SizeSelectorPanel ssp = new SizeSelectorPanel(
|
126 |
ca, |
|
127 |
ha, |
|
128 |
negVals, |
|
129 |
SizeSelectorPanel.TYPE_COMBO); |
|
130 | 3 |
Util.addGridBagComponent(this, ssp, g, c, 1, 3, GridBagConstraints.WEST);
|
131 |
} |
|
132 |
} |
|