summaryrefslogtreecommitdiff
path: root/libs/FLib/TableLayout
diff options
context:
space:
mode:
Diffstat (limited to 'libs/FLib/TableLayout')
-rw-r--r--libs/FLib/TableLayout/doc/example/Example1.java242
-rw-r--r--libs/FLib/TableLayout/doc/example/TableExplorer.java2118
-rw-r--r--libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java3114
3 files changed, 2738 insertions, 2736 deletions
diff --git a/libs/FLib/TableLayout/doc/example/Example1.java b/libs/FLib/TableLayout/doc/example/Example1.java
index 797d1e7..5791d1a 100644
--- a/libs/FLib/TableLayout/doc/example/Example1.java
+++ b/libs/FLib/TableLayout/doc/example/Example1.java
@@ -44,137 +44,137 @@ public class Example1
// main
//**********************************************************************
-public static void
-main(
- String[] args)
-{
- new Example1();
-}
+ public static void
+ main(
+ String[] args)
+ {
+ new Example1();
+ }
//**********************************************************************
// Constructors
//**********************************************************************
-/**
- * Create the two windows and display them.
- */
+ /**
+ * Create the two windows and display them.
+ */
-public
-Example1()
-{
- JFrame frame1 = createGridBagLayout();
- JFrame frame2 = createTableLayout();
- frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- frame1.pack();
- frame2.pack();
- frame1.setLocation(10, 100);
- frame2.setLocation(400, 100);
- frame1.setVisible(true);
- frame2.setVisible(true);
-}
+ public
+ Example1()
+ {
+ JFrame frame1 = createGridBagLayout();
+ JFrame frame2 = createTableLayout();
+ frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ frame1.pack();
+ frame2.pack();
+ frame1.setLocation(10, 100);
+ frame2.setLocation(400, 100);
+ frame1.setVisible(true);
+ frame2.setVisible(true);
+ }
//**********************************************************************
// Private
//**********************************************************************
-/**
- * Create the layout using GridBagLayout. This code comes from the API
- * page for GridBagLayout.
- *
- * @return The JFrame containing the layout.
- */
-
-public JFrame
-createGridBagLayout()
-{
- JFrame frame = new JFrame("GridBagLayout");
-
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints c = new GridBagConstraints();
-
- JPanel panel = new JPanel(gridbag);
- frame.getContentPane().add(panel);
-
- c.fill = GridBagConstraints.BOTH;
- c.weightx = 1.0;
- makebutton(panel, "Button1", gridbag, c);
- makebutton(panel, "Button2", gridbag, c);
- makebutton(panel, "Button3", gridbag, c);
-
- c.gridwidth = GridBagConstraints.REMAINDER; //end row
- makebutton(panel, "Button4", gridbag, c);
-
- c.weightx = 0.0; //reset to the default
- makebutton(panel, "Button5", gridbag, c); //another row
-
- c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
- makebutton(panel, "Button6", gridbag, c);
-
- c.gridwidth = GridBagConstraints.REMAINDER; //end row
- makebutton(panel, "Button7", gridbag, c);
-
- c.gridwidth = 1; //reset to the default
- c.gridheight = 2;
- c.weighty = 1.0;
- makebutton(panel, "Button8", gridbag, c);
-
- c.weighty = 0.0; //reset to the default
- c.gridwidth = GridBagConstraints.REMAINDER; //end row
- c.gridheight = 1; //reset to the default
- makebutton(panel, "Button9", gridbag, c);
- makebutton(panel, "Button10", gridbag, c);
-
- return frame;
-}
-
-/**
- * Helper method for createGridBagLayout().
- *
- * @param panel The panel to add the button to.
- * @param name The button's label.
- * @param gridbag The GridBagLayout to use.
- * @param c The constraints to use.
- */
-
-private void
-makebutton(
- JPanel panel,
- String name,
- GridBagLayout gridbag,
- GridBagConstraints c)
-{
- JButton button = new JButton(name);
- gridbag.setConstraints(button, c);
- panel.add(button);
-}
-
-/**
- * Create the layout using TableLayout.
- *
- * @return The JFrame containing the layout.
- */
-
-public JFrame
-createTableLayout()
-{
- JFrame frame = new JFrame("TableLayout");
-
- JPanel panel = new JPanel(new TableLayout("cols=4"));
- frame.getContentPane().add(panel);
-
- panel.add(new JButton("Button1"));
- panel.add(new JButton("Button2"));
- panel.add(new JButton("Button3"));
- panel.add(new JButton("Button4"));
- panel.add(new JButton("Button5"), "cspan=4");
- panel.add(new JButton("Button6"), "cspan=3");
- panel.add(new JButton("Button7"));
- panel.add(new JButton("Button8"), "rspan=2");
- panel.add(new JButton("Button9"), "cspan=3");
- panel.add(new JButton("Button10"), "cspan=3 rweight=1");
-
- return frame;
-}
+ /**
+ * Create the layout using GridBagLayout. This code comes from the API
+ * page for GridBagLayout.
+ *
+ * @return The JFrame containing the layout.
+ */
+
+ public JFrame
+ createGridBagLayout()
+ {
+ JFrame frame = new JFrame("GridBagLayout");
+
+ GridBagLayout gridbag = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+
+ JPanel panel = new JPanel(gridbag);
+ frame.getContentPane().add(panel);
+
+ c.fill = GridBagConstraints.BOTH;
+ c.weightx = 1.0;
+ makebutton(panel, "Button1", gridbag, c);
+ makebutton(panel, "Button2", gridbag, c);
+ makebutton(panel, "Button3", gridbag, c);
+
+ c.gridwidth = GridBagConstraints.REMAINDER; //end row
+ makebutton(panel, "Button4", gridbag, c);
+
+ c.weightx = 0.0; //reset to the default
+ makebutton(panel, "Button5", gridbag, c); //another row
+
+ c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
+ makebutton(panel, "Button6", gridbag, c);
+
+ c.gridwidth = GridBagConstraints.REMAINDER; //end row
+ makebutton(panel, "Button7", gridbag, c);
+
+ c.gridwidth = 1; //reset to the default
+ c.gridheight = 2;
+ c.weighty = 1.0;
+ makebutton(panel, "Button8", gridbag, c);
+
+ c.weighty = 0.0; //reset to the default
+ c.gridwidth = GridBagConstraints.REMAINDER; //end row
+ c.gridheight = 1; //reset to the default
+ makebutton(panel, "Button9", gridbag, c);
+ makebutton(panel, "Button10", gridbag, c);
+
+ return frame;
+ }
+
+ /**
+ * Helper method for createGridBagLayout().
+ *
+ * @param panel The panel to add the button to.
+ * @param name The button's label.
+ * @param gridbag The GridBagLayout to use.
+ * @param c The constraints to use.
+ */
+
+ private void
+ makebutton(
+ JPanel panel,
+ String name,
+ GridBagLayout gridbag,
+ GridBagConstraints c)
+ {
+ JButton button = new JButton(name);
+ gridbag.setConstraints(button, c);
+ panel.add(button);
+ }
+
+ /**
+ * Create the layout using TableLayout.
+ *
+ * @return The JFrame containing the layout.
+ */
+
+ public JFrame
+ createTableLayout()
+ {
+ JFrame frame = new JFrame("TableLayout");
+
+ JPanel panel = new JPanel(new TableLayout("cols=4"));
+ frame.getContentPane().add(panel);
+
+ panel.add(new JButton("Button1"));
+ panel.add(new JButton("Button2"));
+ panel.add(new JButton("Button3"));
+ panel.add(new JButton("Button4"));
+ panel.add(new JButton("Button5"), "cspan=4");
+ panel.add(new JButton("Button6"), "cspan=3");
+ panel.add(new JButton("Button7"));
+ panel.add(new JButton("Button8"), "rspan=2");
+ panel.add(new JButton("Button9"), "cspan=3");
+ panel.add(new JButton("Button10"), "cspan=3 rweight=1");
+
+ return frame;
+ }
}
diff --git a/libs/FLib/TableLayout/doc/example/TableExplorer.java b/libs/FLib/TableLayout/doc/example/TableExplorer.java
index d66c497..90c3a5e 100644
--- a/libs/FLib/TableLayout/doc/example/TableExplorer.java
+++ b/libs/FLib/TableLayout/doc/example/TableExplorer.java
@@ -24,1039 +24,1039 @@ import org.freixas.tablelayout.*;
*/
public class TableExplorer
- extends JFrame
- implements CaretListener, ActionListener, ListSelectionListener,
- FocusListener, MenuListener
+ extends JFrame
+ implements CaretListener, ActionListener, ListSelectionListener,
+ FocusListener, MenuListener
{
//**********************************************************************
// Constants
//**********************************************************************
-static final String[] tablePositionList = {
- "Default",
- "tn", "tne", "tnw",
- "ts", "tse", "tsw",
- "te", "tw", "tc"
-};
+ static final String[] tablePositionList = {
+ "Default",
+ "tn", "tne", "tnw",
+ "ts", "tse", "tsw",
+ "te", "tw", "tc"
+ };
-static final String[] tableFillList = {
- "Default", "tfh", "tfv", "tf"
-};
+ static final String[] tableFillList = {
+ "Default", "tfh", "tfv", "tf"
+ };
-static final String[] positionList = {
- "Default",
- "n", "ne", "nw",
- "s", "se", "sw",
- "e", "w", "c"
-};
+ static final String[] positionList = {
+ "Default",
+ "n", "ne", "nw",
+ "s", "se", "sw",
+ "e", "w", "c"
+ };
-static final String[] fillList = {
- "Default", "fh", "fv", "f"
-};
+ static final String[] fillList = {
+ "Default", "fh", "fv", "f"
+ };
//**********************************************************************
// Fields
//**********************************************************************
-JFrame layout;
-JPanel layoutPane;
-JFrame code;
-JPanel codePane;
-
-HashMap compHash = new HashMap();
-HashMap attrHash = new HashMap();
-
-JMenu fileMenu;
-JMenu windowMenu;
-JMenu helpMenu;
-
-JMenuItem exitItem;
-JMenuItem previewItem;
-JMenuItem packItem;
-JMenuItem codeItem;
-JMenuItem generateItem;
-JMenuItem aboutItem;
-
-JButton upButton;
-JButton downButton;
-JButton removeButton;
-JButton addButton;
-
-JList compList;
-DefaultListModel compListModel;
-JTextField compEntryField;
-
-JTextField columnsField;
-JTextField[] tableInsetFields = new JTextField[4];
-JTextField rowGapField;
-JTextField colGapField;
-JComboBox tablePositionBox;
-JComboBox tableFillBox;
-
-JTextField[] tableCellInsetFields = new JTextField[4];
-JComboBox tableCellPositionBox;
-JComboBox tableCellFillBox;
-JTextField tableRowWeightField;
-JTextField tableColWeightField;
-
-JTextField tableAttributesField;
-
-JTextField[] insetFields = new JTextField[4];
-JComboBox positionBox;
-JComboBox fillBox;
-JTextField rowWeightField;
-JTextField colWeightField;
-JTextField colPositionField;
-JTextField skipCellsField;
-JTextField rowSpanField;
-JTextField colSpanField;
-
-JTextField cellAttributesField;
-
-JTextArea codeTextArea;
-JScrollPane codeTextScroll;
-
-String textWhenFocusGained = null;
-boolean ignoreEvents = false;
-
-TableAttributes tableAttributes = null;
+ JFrame layout;
+ JPanel layoutPane;
+ JFrame code;
+ JPanel codePane;
+
+ HashMap compHash = new HashMap();
+ HashMap attrHash = new HashMap();
+
+ JMenu fileMenu;
+ JMenu windowMenu;
+ JMenu helpMenu;
+
+ JMenuItem exitItem;
+ JMenuItem previewItem;
+ JMenuItem packItem;
+ JMenuItem codeItem;
+ JMenuItem generateItem;
+ JMenuItem aboutItem;
+
+ JButton upButton;
+ JButton downButton;
+ JButton removeButton;
+ JButton addButton;
+
+ JList compList;
+ DefaultListModel compListModel;
+ JTextField compEntryField;
+
+ JTextField columnsField;
+ JTextField[] tableInsetFields = new JTextField[4];
+ JTextField rowGapField;
+ JTextField colGapField;
+ JComboBox tablePositionBox;
+ JComboBox tableFillBox;
+
+ JTextField[] tableCellInsetFields = new JTextField[4];
+ JComboBox tableCellPositionBox;
+ JComboBox tableCellFillBox;
+ JTextField tableRowWeightField;
+ JTextField tableColWeightField;
+
+ JTextField tableAttributesField;
+
+ JTextField[] insetFields = new JTextField[4];
+ JComboBox positionBox;
+ JComboBox fillBox;
+ JTextField rowWeightField;
+ JTextField colWeightField;
+ JTextField colPositionField;
+ JTextField skipCellsField;
+ JTextField rowSpanField;
+ JTextField colSpanField;
+
+ JTextField cellAttributesField;
+
+ JTextArea codeTextArea;
+ JScrollPane codeTextScroll;
+
+ String textWhenFocusGained = null;
+ boolean ignoreEvents = false;
+
+ TableAttributes tableAttributes = null;
//**********************************************************************
// Main
//**********************************************************************
-static public void
-main(
- String[] args)
-{
- new TableExplorer();
-}
+ static public void
+ main(
+ String[] args)
+ {
+ new TableExplorer();
+ }
//**********************************************************************
// Constructors
//**********************************************************************
-/**
- * Create the TableExplorer JFrame.
- */
+ /**
+ * Create the TableExplorer JFrame.
+ */
-TableExplorer()
-{
- super("TableExplorer");
+ TableExplorer()
+ {
+ super("TableExplorer");
- // Table with three columns
- // Row 1: Buttons for managing component list
- // Row 2: Component list
- // Row 3: Attribute settings
+ // Table with three columns
+ // Row 1: Buttons for managing component list
+ // Row 2: Component list
+ // Row 3: Attribute settings
- setJMenuBar(createJMenuBar());
+ setJMenuBar(createJMenuBar());
- getContentPane().setLayout(
- new TableLayout("cols=3 cgap=5 " +
- "titop=2 tibottom=2 tileft=2 tiright=2"));
+ getContentPane().setLayout(
+ new TableLayout("cols=3 cgap=5 " +
+ "titop=2 tibottom=2 tileft=2 tiright=2"));
- getContentPane().add(createButtonPane());
- getContentPane().add(createListPane(), "cweight=1");
- getContentPane().add(createAttributePane(), "n fh");
+ getContentPane().add(createButtonPane());
+ getContentPane().add(createListPane(), "cweight=1");
+ getContentPane().add(createAttributePane(), "n fh");
- pack();
- setVisible(true);
+ pack();
+ setVisible(true);
- layout = new JFrame("Table Layout Preview");
- layoutPane = (JPanel)layout.getContentPane();
- layoutPane.setName("DEBUG");
- layoutPane.setLayout(new TableLayout());
- layoutPane.setOpaque(true);
+ layout = new JFrame("Table Layout Preview");
+ layoutPane = (JPanel)layout.getContentPane();
+ layoutPane.setName("DEBUG");
+ layoutPane.setLayout(new TableLayout());
+ layoutPane.setOpaque(true);
- code = new JFrame("Table Layout Code");
- codePane = createCodePane();
- code.setContentPane(codePane);
- code.pack();
+ code = new JFrame("Table Layout Code");
+ codePane = createCodePane();
+ code.setContentPane(codePane);
+ code.pack();
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- compEntryField.grabFocus();
+ compEntryField.grabFocus();
- layout.setSize(300, 300);
-}
+ layout.setSize(300, 300);
+ }
//**********************************************************************
// Public
//**********************************************************************
-public void
-caretUpdate(
- CaretEvent e)
-{
- if (e.getSource() == compEntryField) {
- String text = compEntryField.getText();
- addButton.setEnabled(text.length() > 0);
- }
-}
-
-public void
-actionPerformed(
- ActionEvent e)
-{
- if (ignoreEvents) return;
-
- if (e.getSource() == addButton ||
- e.getSource() == compEntryField) {
-
- String name = compEntryField.getText();
-
- JButton button = new JButton(name);
- addToLayout(button);
- compHash.put(name, button);
- attrHash.put(name, new Attributes());
- compListModel.addElement(name);
- compEntryField.setText("");
- addButton.setEnabled(false);
- }
-
- else if (e.getSource() == removeButton) {
- String name = (String)compList.getSelectedValue();
- if (name != null) {
- Component c = (Component)compHash.get(name);
- layoutPane.remove(c);
- compHash.remove(name);
- attrHash.remove(name);
- compListModel.removeElement(name);
- removeButton.setEnabled(false);
- layoutPane.revalidate();
- }
- }
-
- else if (e.getSource() == upButton) {
- int index = compList.getSelectedIndex();
- if (index > 0) {
- String name = (String)compListModel.elementAt(index);
- compListModel.removeElementAt(index);
- compListModel.insertElementAt(name, index - 1);
- compList.setSelectedIndex(index - 1);
-
- Component c = (Component)compHash.get(name);
- Attributes a = (Attributes)attrHash.get(name);
- layoutPane.remove(index);
- layoutPane.add(c, a.toString(), index - 1);
- layoutPane.revalidate();
- }
- }
-
- else if (e.getSource() == downButton) {
- int index = compList.getSelectedIndex();
- if (index > -1 && index < compListModel.getSize() - 1) {
- String name = (String)compListModel.elementAt(index);
- compListModel.removeElementAt(index);
- compListModel.insertElementAt(name, index + 1);
- compList.setSelectedIndex(index + 1);
-
- Component c = (Component)compHash.get(name);
- Attributes a = (Attributes)attrHash.get(name);
- layoutPane.remove(index);
- layoutPane.add(c, a.toString(), index + 1);
- layoutPane.revalidate();
- }
+ public void
+ caretUpdate(
+ CaretEvent e)
+ {
+ if (e.getSource() == compEntryField) {
+ String text = compEntryField.getText();
+ addButton.setEnabled(text.length() > 0);
+ }
}
- else if (e.getSource() == insetFields[0] ||
- e.getSource() == insetFields[1] ||
- e.getSource() == insetFields[2] ||
- e.getSource() == insetFields[3] ||
- e.getSource() == positionBox ||
- e.getSource() == fillBox ||
- e.getSource() == rowWeightField ||
- e.getSource() == colWeightField ||
- e.getSource() == colPositionField ||
- e.getSource() == skipCellsField ||
- e.getSource() == rowSpanField ||
- e.getSource() == colSpanField) {
- String name = (String)compList.getSelectedValue();
- changeLayout(name);
+ public void
+ actionPerformed(
+ ActionEvent e)
+ {
+ if (ignoreEvents) return;
+
+ if (e.getSource() == addButton ||
+ e.getSource() == compEntryField) {
+
+ String name = compEntryField.getText();
+
+ JButton button = new JButton(name);
+ addToLayout(button);
+ compHash.put(name, button);
+ attrHash.put(name, new Attributes());
+ compListModel.addElement(name);
+ compEntryField.setText("");
+ addButton.setEnabled(false);
+ }
+
+ else if (e.getSource() == removeButton) {
+ String name = (String)compList.getSelectedValue();
+ if (name != null) {
+ Component c = (Component)compHash.get(name);
+ layoutPane.remove(c);
+ compHash.remove(name);
+ attrHash.remove(name);
+ compListModel.removeElement(name);
+ removeButton.setEnabled(false);
+ layoutPane.revalidate();
+ }
+ }
+
+ else if (e.getSource() == upButton) {
+ int index = compList.getSelectedIndex();
+ if (index > 0) {
+ String name = (String)compListModel.elementAt(index);
+ compListModel.removeElementAt(index);
+ compListModel.insertElementAt(name, index - 1);
+ compList.setSelectedIndex(index - 1);
+
+ Component c = (Component)compHash.get(name);
+ Attributes a = (Attributes)attrHash.get(name);
+ layoutPane.remove(index);
+ layoutPane.add(c, a.toString(), index - 1);
+ layoutPane.revalidate();
+ }
+ }
+
+ else if (e.getSource() == downButton) {
+ int index = compList.getSelectedIndex();
+ if (index > -1 && index < compListModel.getSize() - 1) {
+ String name = (String)compListModel.elementAt(index);
+ compListModel.removeElementAt(index);
+ compListModel.insertElementAt(name, index + 1);
+ compList.setSelectedIndex(index + 1);
+
+ Component c = (Component)compHash.get(name);
+ Attributes a = (Attributes)attrHash.get(name);
+ layoutPane.remove(index);
+ layoutPane.add(c, a.toString(), index + 1);
+ layoutPane.revalidate();
+ }
+ }
+
+ else if (e.getSource() == insetFields[0] ||
+ e.getSource() == insetFields[1] ||
+ e.getSource() == insetFields[2] ||
+ e.getSource() == insetFields[3] ||
+ e.getSource() == positionBox ||
+ e.getSource() == fillBox ||
+ e.getSource() == rowWeightField ||
+ e.getSource() == colWeightField ||
+ e.getSource() == colPositionField ||
+ e.getSource() == skipCellsField ||
+ e.getSource() == rowSpanField ||
+ e.getSource() == colSpanField) {
+ String name = (String)compList.getSelectedValue();
+ changeLayout(name);
+ }
+
+ else if (e.getSource() == columnsField ||
+ e.getSource() == tableInsetFields[0] ||
+ e.getSource() == tableInsetFields[1] ||
+ e.getSource() == tableInsetFields[2] ||
+ e.getSource() == tableInsetFields[3] ||
+ e.getSource() == rowGapField ||
+ e.getSource() == colGapField ||
+ e.getSource() == tablePositionBox ||
+ e.getSource() == tableFillBox ||
+ e.getSource() == tableCellInsetFields[0] ||
+ e.getSource() == tableCellInsetFields[1] ||
+ e.getSource() == tableCellInsetFields[2] ||
+ e.getSource() == tableCellInsetFields[3] ||
+ e.getSource() == tableCellPositionBox ||
+ e.getSource() == tableCellFillBox ||
+ e.getSource() == tableRowWeightField ||
+ e.getSource() == tableColWeightField) {
+ changeTableLayout();
+ }
+
+ else if (e.getSource() == exitItem) {
+ System.exit(0);
+ }
+
+ else if (e.getSource() == previewItem) {
+ if (layout.isVisible()) {
+ layout.setVisible(false);
+ }
+ else {
+ layout.setVisible(true);
+ }
+ }
+
+ else if (e.getSource() == packItem) {
+ layout.pack();
+ }
+
+ else if (e.getSource() == codeItem) {
+ if (code.isVisible()) {
+ code.setVisible(false);
+ }
+ else {
+ generateCode();
+ code.setVisible(true);
+ }
+ }
+
+ else if (e.getSource() == generateItem) {
+ generateCode();
+ }
+
+ else if (e.getSource() == aboutItem) {
+ JOptionPane.showMessageDialog(this,
+ "<html>" +
+ "<h1><font face=Dialog>Table Explorer V1.0</font></h1>" +
+ "<font face=Dialog>Written by Antonio Freixas<br>" +
+ "<a src=\"mailto:tony@freixas.org\">tonyf@freixas.org</a>",
+ "About Table Explorer</font>",
+ JOptionPane.INFORMATION_MESSAGE);
+ }
}
- else if (e.getSource() == columnsField ||
- e.getSource() == tableInsetFields[0] ||
- e.getSource() == tableInsetFields[1] ||
- e.getSource() == tableInsetFields[2] ||
- e.getSource() == tableInsetFields[3] ||
- e.getSource() == rowGapField ||
- e.getSource() == colGapField ||
- e.getSource() == tablePositionBox ||
- e.getSource() == tableFillBox ||
- e.getSource() == tableCellInsetFields[0] ||
- e.getSource() == tableCellInsetFields[1] ||
- e.getSource() == tableCellInsetFields[2] ||
- e.getSource() == tableCellInsetFields[3] ||
- e.getSource() == tableCellPositionBox ||
- e.getSource() == tableCellFillBox ||
- e.getSource() == tableRowWeightField ||
- e.getSource() == tableColWeightField) {
- changeTableLayout();
+ public void
+ valueChanged(
+ ListSelectionEvent e)
+ {
+ if (ignoreEvents) return;
+
+ if (e.getSource() == compList) {
+ String name = (String)compList.getSelectedValue();
+ int index = compList.getSelectedIndex();
+
+ boolean hasObject = name != null;
+
+ removeButton.setEnabled(hasObject);
+ upButton.setEnabled(hasObject && index != 0);
+ downButton.setEnabled(hasObject &&
+ index != compListModel.getSize() - 1);
+ enableAttributes(hasObject);
+
+ if (hasObject) {
+ Attributes attributes = (Attributes)attrHash.get(name);
+ setAttributes(attributes);
+ }
+ }
}
- else if (e.getSource() == exitItem) {
- System.exit(0);
+ public void
+ focusGained(
+ FocusEvent e)
+ {
+ if (e.getSource() == insetFields[0] ||
+ e.getSource() == insetFields[1] ||
+ e.getSource() == insetFields[2] ||
+ e.getSource() == insetFields[3] ||
+ e.getSource() == rowWeightField ||
+ e.getSource() == colWeightField ||
+ e.getSource() == colPositionField ||
+ e.getSource() == skipCellsField ||
+ e.getSource() == rowSpanField ||
+ e.getSource() == colSpanField||
+ e.getSource() == columnsField ||
+ e.getSource() == tableInsetFields[0] ||
+ e.getSource() == tableInsetFields[1] ||
+ e.getSource() == tableInsetFields[2] ||
+ e.getSource() == tableInsetFields[3] ||
+ e.getSource() == rowGapField ||
+ e.getSource() == colGapField ||
+ e.getSource() == tableCellInsetFields[0] ||
+ e.getSource() == tableCellInsetFields[1] ||
+ e.getSource() == tableCellInsetFields[2] ||
+ e.getSource() == tableCellInsetFields[3] ||
+ e.getSource() == tableRowWeightField ||
+ e.getSource() == tableColWeightField) {
+
+ JTextField field = (JTextField)e.getSource();
+ textWhenFocusGained = field.getText();
+ }
+ else if (e.getSource() == positionBox ||
+ e.getSource() == fillBox ||
+ e.getSource() == tablePositionBox ||
+ e.getSource() == tableFillBox ||
+ e.getSource() == tableCellPositionBox ||
+ e.getSource() == tableCellFillBox) {
+
+ JComboBox box = (JComboBox)e.getSource();
+ textWhenFocusGained = (String)box.getSelectedItem();
+ }
+ else {
+ textWhenFocusGained = null;
+ }
}
- else if (e.getSource() == previewItem) {
- if (layout.isVisible()) {
- layout.setVisible(false);
- }
- else {
- layout.setVisible(true);
- }
+ public void
+ focusLost(
+ FocusEvent e)
+ {
+ if (textWhenFocusGained != null) {
+ if (e.getSource() == insetFields[0] ||
+ e.getSource() == insetFields[1] ||
+ e.getSource() == insetFields[2] ||
+ e.getSource() == insetFields[3] ||
+ e.getSource() == rowWeightField ||
+ e.getSource() == colWeightField ||
+ e.getSource() == colPositionField ||
+ e.getSource() == skipCellsField ||
+ e.getSource() == rowSpanField ||
+ e.getSource() == colSpanField) {
+
+ JTextField field = (JTextField)e.getSource();
+ if (!textWhenFocusGained.equals(field.getText())) {
+ changeLayout();
+ }
+ }
+ else if (e.getSource() == positionBox ||
+ e.getSource() == fillBox) {
+ JComboBox box = (JComboBox)e.getSource();
+ if (!textWhenFocusGained.equals(box.getSelectedItem())) {
+ changeLayout();
+ }
+ }
+ else if (e.getSource() == columnsField ||
+ e.getSource() == tableInsetFields[0] ||
+ e.getSource() == tableInsetFields[1] ||
+ e.getSource() == tableInsetFields[2] ||
+ e.getSource() == tableInsetFields[3] ||
+ e.getSource() == rowGapField ||
+ e.getSource() == colGapField ||
+ e.getSource() == tableCellInsetFields[0] ||
+ e.getSource() == tableCellInsetFields[1] ||
+ e.getSource() == tableCellInsetFields[2] ||
+ e.getSource() == tableCellInsetFields[3] ||
+ e.getSource() == tableRowWeightField ||
+ e.getSource() == tableColWeightField) {
+
+ JTextField field = (JTextField)e.getSource();
+ if (!textWhenFocusGained.equals(field.getText())) {
+ changeTableLayout();
+ }
+ }
+
+ else if (e.getSource() == tablePositionBox ||
+ e.getSource() == tableFillBox ||
+ e.getSource() == tableCellPositionBox ||
+ e.getSource() == tableCellFillBox) {
+
+ JComboBox box = (JComboBox)e.getSource();
+ if (!textWhenFocusGained.equals(box.getSelectedItem())) {
+ changeTableLayout();
+ }
+ }
+ }
+
+ textWhenFocusGained = null;
}
- else if (e.getSource() == packItem) {
- layout.pack();
+ public void
+ menuCanceled(
+ MenuEvent e)
+ {
}
- else if (e.getSource() == codeItem) {
- if (code.isVisible()) {
- code.setVisible(false);
- }
- else {
- generateCode();
- code.setVisible(true);
- }
+ public void
+ menuDeselected(
+ MenuEvent e)
+ {
}
- else if (e.getSource() == generateItem) {
- generateCode();
+ public void
+ menuSelected(
+ MenuEvent e)
+ {
+ if (e.getSource() == windowMenu) {
+ if (layout.isVisible()) {
+ previewItem.setText("Hide Preview Window");
+ }
+ else {
+ previewItem.setText("Show Preview Window");
+ }
+ if (code.isVisible()) {
+ codeItem.setText("Hide Code Window");
+ }
+ else {
+ codeItem.setText("Show Code Window");
+ }
+ }
}
- else if (e.getSource() == aboutItem) {
- JOptionPane.showMessageDialog(this,
- "<html>" +
- "<h1><font face=Dialog>Table Explorer V1.0</font></h1>" +
- "<font face=Dialog>Written by Antonio Freixas<br>" +
- "<a src=\"mailto:tony@freixas.org\">tonyf@freixas.org</a>",
- "About Table Explorer</font>",
- JOptionPane.INFORMATION_MESSAGE);
- }
-}
-
-public void
-valueChanged(
- ListSelectionEvent e)
-{
- if (ignoreEvents) return;
-
- if (e.getSource() == compList) {
- String name = (String)compList.getSelectedValue();
- int index = compList.getSelectedIndex();
-
- boolean hasObject = name != null;
-
- removeButton.setEnabled(hasObject);
- upButton.setEnabled(hasObject && index != 0);
- downButton.setEnabled(hasObject &&
- index != compListModel.getSize() - 1);
- enableAttributes(hasObject);
-
- if (hasObject) {
- Attributes attributes = (Attributes)attrHash.get(name);
- setAttributes(attributes);
- }
- }
-}
-
-public void
-focusGained(
- FocusEvent e)
-{
- if (e.getSource() == insetFields[0] ||
- e.getSource() == insetFields[1] ||
- e.getSource() == insetFields[2] ||
- e.getSource() == insetFields[3] ||
- e.getSource() == rowWeightField ||
- e.getSource() == colWeightField ||
- e.getSource() == colPositionField ||
- e.getSource() == skipCellsField ||
- e.getSource() == rowSpanField ||
- e.getSource() == colSpanField||
- e.getSource() == columnsField ||
- e.getSource() == tableInsetFields[0] ||
- e.getSource() == tableInsetFields[1] ||
- e.getSource() == tableInsetFields[2] ||
- e.getSource() == tableInsetFields[3] ||
- e.getSource() == rowGapField ||
- e.getSource() == colGapField ||
- e.getSource() == tableCellInsetFields[0] ||
- e.getSource() == tableCellInsetFields[1] ||
- e.getSource() == tableCellInsetFields[2] ||
- e.getSource() == tableCellInsetFields[3] ||
- e.getSource() == tableRowWeightField ||
- e.getSource() == tableColWeightField) {
-
- JTextField field = (JTextField)e.getSource();
- textWhenFocusGained = field.getText();
- }
- else if (e.getSource() == positionBox ||
- e.getSource() == fillBox ||
- e.getSource() == tablePositionBox ||
- e.getSource() == tableFillBox ||
- e.getSource() == tableCellPositionBox ||
- e.getSource() == tableCellFillBox) {
-
- JComboBox box = (JComboBox)e.getSource();
- textWhenFocusGained = (String)box.getSelectedItem();
- }
- else {
- textWhenFocusGained = null;
- }
-}
-
-public void
-focusLost(
- FocusEvent e)
-{
- if (textWhenFocusGained != null) {
- if (e.getSource() == insetFields[0] ||
- e.getSource() == insetFields[1] ||
- e.getSource() == insetFields[2] ||
- e.getSource() == insetFields[3] ||
- e.getSource() == rowWeightField ||
- e.getSource() == colWeightField ||
- e.getSource() == colPositionField ||
- e.getSource() == skipCellsField ||
- e.getSource() == rowSpanField ||
- e.getSource() == colSpanField) {
-
- JTextField field = (JTextField)e.getSource();
- if (!textWhenFocusGained.equals(field.getText())) {
- changeLayout();
- }
- }
- else if (e.getSource() == positionBox ||
- e.getSource() == fillBox) {
- JComboBox box = (JComboBox)e.getSource();
- if (!textWhenFocusGained.equals(box.getSelectedItem())) {
- changeLayout();
- }
- }
- else if (e.getSource() == columnsField ||
- e.getSource() == tableInsetFields[0] ||
- e.getSource() == tableInsetFields[1] ||
- e.getSource() == tableInsetFields[2] ||
- e.getSource() == tableInsetFields[3] ||
- e.getSource() == rowGapField ||
- e.getSource() == colGapField ||
- e.getSource() == tableCellInsetFields[0] ||
- e.getSource() == tableCellInsetFields[1] ||
- e.getSource() == tableCellInsetFields[2] ||
- e.getSource() == tableCellInsetFields[3] ||
- e.getSource() == tableRowWeightField ||
- e.getSource() == tableColWeightField) {
-
- JTextField field = (JTextField)e.getSource();
- if (!textWhenFocusGained.equals(field.getText())) {
- changeTableLayout();
- }
- }
-
- else if (e.getSource() == tablePositionBox ||
- e.getSource() == tableFillBox ||
- e.getSource() == tableCellPositionBox ||
- e.getSource() == tableCellFillBox) {
-
- JComboBox box = (JComboBox)e.getSource();
- if (!textWhenFocusGained.equals(box.getSelectedItem())) {
- changeTableLayout();
- }
- }
- }
-
- textWhenFocusGained = null;
-}
-
-public void
-menuCanceled(
- MenuEvent e)
-{
-}
-
-public void
-menuDeselected(
- MenuEvent e)
-{
-}
-
-public void
-menuSelected(
- MenuEvent e)
-{
- if (e.getSource() == windowMenu) {
- if (layout.isVisible()) {
- previewItem.setText("Hide Preview Window");
- }
- else {
- previewItem.setText("Show Preview Window");
- }
- if (code.isVisible()) {
- codeItem.setText("Hide Code Window");
- }
- else {
- codeItem.setText("Show Code Window");
- }
- }
-}
-
//**********************************************************************
// Package Public
//**********************************************************************
-JMenuBar
-createJMenuBar()
-{
- JMenuBar menuBar = new JMenuBar();
-
- fileMenu = new JMenu("File");
- menuBar.add(fileMenu);
- windowMenu = new JMenu("Window");
- windowMenu.addMenuListener(this);
- menuBar.add(windowMenu);
- helpMenu = new JMenu("Help");
- menuBar.add(helpMenu);
+ JMenuBar
+ createJMenuBar()
+ {
+ JMenuBar menuBar = new JMenuBar();
- exitItem = new JMenuItem("Exit");
- exitItem.addActionListener(this);
- fileMenu.add(exitItem);
+ fileMenu = new JMenu("File");
+ menuBar.add(fileMenu);
+ windowMenu = new JMenu("Window");
+ windowMenu.addMenuListener(this);
+ menuBar.add(windowMenu);
+ helpMenu = new JMenu("Help");
+ menuBar.add(helpMenu);
- previewItem = new JMenuItem("Show Preview Window");
- previewItem.addActionListener(this);
- windowMenu.add(previewItem);
+ exitItem = new JMenuItem("Exit");
+ exitItem.addActionListener(this);
+ fileMenu.add(exitItem);
- packItem = new JMenuItem("Pack Preview Window");
- packItem.addActionListener(this);
- windowMenu.add(packItem);
+ previewItem = new JMenuItem("Show Preview Window");
+ previewItem.addActionListener(this);
+ windowMenu.add(previewItem);
- windowMenu.add(new JSeparator());
+ packItem = new JMenuItem("Pack Preview Window");
+ packItem.addActionListener(this);
+ windowMenu.add(packItem);
- codeItem = new JMenuItem("Show Code Window");
- codeItem.addActionListener(this);
- windowMenu.add(codeItem);
+ windowMenu.add(new JSeparator());
- generateItem = new JMenuItem("Generate Code");
- generateItem.addActionListener(this);
- windowMenu.add(generateItem);
+ codeItem = new JMenuItem("Show Code Window");
+ codeItem.addActionListener(this);
+ windowMenu.add(codeItem);
- aboutItem = new JMenuItem("About TableExplorer...");
- aboutItem.addActionListener(this);
- helpMenu.add(aboutItem);
+ generateItem = new JMenuItem("Generate Code");
+ generateItem.addActionListener(this);
+ windowMenu.add(generateItem);
- return menuBar;
-}
-
-Component
-createButtonPane()
-{
- JPanel topLevel = new JPanel(new TableLayout("cols=1"));
+ aboutItem = new JMenuItem("About TableExplorer...");
+ aboutItem.addActionListener(this);
+ helpMenu.add(aboutItem);
- upButton = new JButton("Up");
- upButton.setEnabled(false);
- upButton.addActionListener(this);
+ return menuBar;
+ }
- downButton = new JButton("Down");
- downButton.setEnabled(false);
- downButton.addActionListener(this);
+ Component
+ createButtonPane()
+ {
+ JPanel topLevel = new JPanel(new TableLayout("cols=1"));
- removeButton = new JButton("Remove");
- removeButton.setEnabled(false);
- removeButton.addActionListener(this);
+ upButton = new JButton("Up");
+ upButton.setEnabled(false);
+ upButton.addActionListener(this);
- addButton = new JButton("Add");
- addButton.addActionListener(this);
+ downButton = new JButton("Down");
+ downButton.setEnabled(false);
+ downButton.addActionListener(this);
- topLevel.add(upButton);
- topLevel.add(downButton, "rweight=1 n fh");
- topLevel.add(removeButton, "rweight=1 s fh ");
- topLevel.add(addButton);
+ removeButton = new JButton("Remove");
+ removeButton.setEnabled(false);
+ removeButton.addActionListener(this);
- return topLevel;
-}
+ addButton = new JButton("Add");
+ addButton.addActionListener(this);
-Component
-createListPane()
-{
- JPanel topLevel = new JPanel(new TableLayout("cols=1 rgap=2"));
+ topLevel.add(upButton);
+ topLevel.add(downButton, "rweight=1 n fh");
+ topLevel.add(removeButton, "rweight=1 s fh ");
+ topLevel.add(addButton);
- compListModel = new DefaultListModel();
- compList = new JList(compListModel);
- compList.setVisibleRowCount(20);
- compList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- compList.addListSelectionListener(this);
+ return topLevel;
+ }
- compEntryField = new JTextField("Start Here!");
- compEntryField.selectAll();
- compEntryField.setColumns(20);
- compEntryField.addCaretListener(this);
- compEntryField.addActionListener(this);
+ Component
+ createListPane()
+ {
+ JPanel topLevel = new JPanel(new TableLayout("cols=1 rgap=2"));
- topLevel.add(compList, "rweight=1");
- topLevel.add(compEntryField);
+ compListModel = new DefaultListModel();
+ compList = new JList(compListModel);
+ compList.setVisibleRowCount(20);
+ compList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ compList.addListSelectionListener(this);
- return topLevel;
-}
+ compEntryField = new JTextField("Start Here!");
+ compEntryField.selectAll();
+ compEntryField.setColumns(20);
+ compEntryField.addCaretListener(this);
+ compEntryField.addActionListener(this);
-Component
-createAttributePane()
-{
- JPanel topLevel = new JPanel(new TableLayout("cols=3 rgap=2 cgap=5"));
+ topLevel.add(compList, "rweight=1");
+ topLevel.add(compEntryField);
- // Table Attributes
+ return topLevel;
+ }
- topLevel.add(new JLabel("Table Attributes"), "cspan=3");
+ Component
+ createAttributePane()
+ {
+ JPanel topLevel = new JPanel(new TableLayout("cols=3 rgap=2 cgap=5"));
- JPanel spacer1= new JPanel();
- spacer1.setSize(20, 1);
- topLevel.add(spacer1);
- topLevel.add(new JLabel("Columns"));
- columnsField = new JTextField(10);
- columnsField.addActionListener(this);
- columnsField.addFocusListener(this);
- topLevel.add(columnsField);
+ // Table Attributes
- topLevel.add(new JLabel("Table insets"), "col=1");
- topLevel.add(createInsetsPane(tableInsetFields));
+ topLevel.add(new JLabel("Table Attributes"), "cspan=3");
- topLevel.add(new JLabel("Row gap"), "col=1");
- rowGapField = new JTextField(10);
- rowGapField.addActionListener(this);
- rowGapField.addFocusListener(this);
- topLevel.add(rowGapField);
-
- topLevel.add(new JLabel("Column gap"), "col=1");
- colGapField = new JTextField(10);
- colGapField.addActionListener(this);
- colGapField.addFocusListener(this);
- topLevel.add(colGapField);
-
- topLevel.add(new JLabel("Table position"), "col=1");
- tablePositionBox = new JComboBox(tablePositionList);
- tablePositionBox.addActionListener(this);
- topLevel.add(tablePositionBox);
-
- topLevel.add(new JLabel("Table fill"), "col=1");
- tableFillBox = new JComboBox(tableFillList);
- tableFillBox.addActionListener(this);
- topLevel.add(tableFillBox);
-
- // Table Cell Defaults
-
- topLevel.add(new JLabel("Table Cell Defaults"), "cspan=3 itop=20");
-
- topLevel.add(new JLabel("Cell insets"), "col=1");
- topLevel.add(createInsetsPane(tableCellInsetFields));
-
- topLevel.add(new JLabel("Cell position"), "col=1");
- tableCellPositionBox = new JComboBox(positionList);
- tableCellPositionBox.addActionListener(this);
- topLevel.add(tableCellPositionBox);
-
- topLevel.add(new JLabel("Cell fill"), "col=1");
- tableCellFillBox = new JComboBox(fillList);
- tableCellFillBox.addActionListener(this);
- topLevel.add(tableCellFillBox);
-
- topLevel.add(new JLabel("Row weight"), "col=1");
- tableRowWeightField = new JTextField(10);
- tableRowWeightField.addActionListener(this);
- tableRowWeightField.addFocusListener(this);
- topLevel.add(tableRowWeightField);
-
- topLevel.add(new JLabel("Column weight"), "col=1");
- tableColWeightField = new JTextField(10);
- tableColWeightField.addActionListener(this);
-
- tableColWeightField.addFocusListener(this);
- topLevel.add(tableColWeightField);
-
- topLevel.add(new JLabel("Attributes"), "itop=5 col=0 cspan=2");
- tableAttributesField = new JTextField();
- tableAttributesField.setEditable(false);
- topLevel.add(tableAttributesField, "itop=5");
-
- // Make sure components are initialized as per the default table
- // attributes
-
- tableAttributes = new TableAttributes();
- setTableAttributes(tableAttributes);
-
- // Cell Attributes
-
- topLevel.add(new JSeparator(), "cspan=3 itop=20 ibottom=5");
-
- topLevel.add(new JLabel("Cell Attributes"), "cspan=3");
-
- topLevel.add(new JLabel("Cell insets"), "col=1");
- topLevel.add(createInsetsPane(insetFields));
-
- topLevel.add(new JLabel("Cell position"), "col=1");
- positionBox = new JComboBox(positionList);
- positionBox.addActionListener(this);
- topLevel.add(positionBox);
-
- topLevel.add(new JLabel("Cell fill"), "col=1");
- fillBox = new JComboBox(fillList);
- fillBox.addActionListener(this);
- topLevel.add(fillBox);
-
- topLevel.add(new JLabel("Row weight"), "col=1");
- rowWeightField = new JTextField(10);
- rowWeightField.addActionListener(this);
- rowWeightField.addFocusListener(this);
- topLevel.add(rowWeightField);
-
- topLevel.add(new JLabel("Column weight"), "col=1");
- colWeightField = new JTextField(10);
- colWeightField.addActionListener(this);
- colWeightField.addFocusListener(this);
- topLevel.add(colWeightField);
-
- topLevel.add(new JLabel("Column position"), "col=1");
- colPositionField = new JTextField(10);
- colPositionField.addActionListener(this);
- colPositionField.addFocusListener(this);
- topLevel.add(colPositionField);
-
- topLevel.add(new JLabel("Skip cells"), "col=1");
- skipCellsField = new JTextField(10);
- skipCellsField.addActionListener(this);
- skipCellsField.addFocusListener(this);
- topLevel.add(skipCellsField);
-
- topLevel.add(new JLabel("Row span"), "col=1");
- rowSpanField = new JTextField(10);
- rowSpanField.addActionListener(this);
- rowSpanField.addFocusListener(this);
- topLevel.add(rowSpanField);
+ JPanel spacer1= new JPanel();
+ spacer1.setSize(20, 1);
+ topLevel.add(spacer1);
+ topLevel.add(new JLabel("Columns"));
+ columnsField = new JTextField(10);
+ columnsField.addActionListener(this);
+ columnsField.addFocusListener(this);
+ topLevel.add(columnsField);
- topLevel.add(new JLabel("Column span"), "col=1");
- colSpanField = new JTextField(10);
- colSpanField.addActionListener(this);
- colSpanField.addFocusListener(this);
- topLevel.add(colSpanField);
-
- topLevel.add(new JLabel("Attributes"), "itop=5 col=0 cspan=2");
- cellAttributesField = new JTextField();
- cellAttributesField.setEditable(false);
- topLevel.add(cellAttributesField, "itop=5");
-
- enableAttributes(false);
-
- return topLevel;
-}
+ topLevel.add(new JLabel("Table insets"), "col=1");
+ topLevel.add(createInsetsPane(tableInsetFields));
-Component
-createInsetsPane(
- JTextField[] insetFields)
-{
- JPanel topLevel = new JPanel(new TableLayout("cols=3"));
+ topLevel.add(new JLabel("Row gap"), "col=1");
+ rowGapField = new JTextField(10);
+ rowGapField.addActionListener(this);
+ rowGapField.addFocusListener(this);
+ topLevel.add(rowGapField);
+
+ topLevel.add(new JLabel("Column gap"), "col=1");
+ colGapField = new JTextField(10);
+ colGapField.addActionListener(this);
+ colGapField.addFocusListener(this);
+ topLevel.add(colGapField);
+
+ topLevel.add(new JLabel("Table position"), "col=1");
+ tablePositionBox = new JComboBox(tablePositionList);
+ tablePositionBox.addActionListener(this);
+ topLevel.add(tablePositionBox);
+
+ topLevel.add(new JLabel("Table fill"), "col=1");
+ tableFillBox = new JComboBox(tableFillList);
+ tableFillBox.addActionListener(this);
+ topLevel.add(tableFillBox);
+
+ // Table Cell Defaults
+
+ topLevel.add(new JLabel("Table Cell Defaults"), "cspan=3 itop=20");
+
+ topLevel.add(new JLabel("Cell insets"), "col=1");
+ topLevel.add(createInsetsPane(tableCellInsetFields));
+
+ topLevel.add(new JLabel("Cell position"), "col=1");
+ tableCellPositionBox = new JComboBox(positionList);
+ tableCellPositionBox.addActionListener(this);
+ topLevel.add(tableCellPositionBox);
+
+ topLevel.add(new JLabel("Cell fill"), "col=1");
+ tableCellFillBox = new JComboBox(fillList);
+ tableCellFillBox.addActionListener(this);
+ topLevel.add(tableCellFillBox);
+
+ topLevel.add(new JLabel("Row weight"), "col=1");
+ tableRowWeightField = new JTextField(10);
+ tableRowWeightField.addActionListener(this);
+ tableRowWeightField.addFocusListener(this);
+ topLevel.add(tableRowWeightField);
+
+ topLevel.add(new JLabel("Column weight"), "col=1");
+ tableColWeightField = new JTextField(10);
+ tableColWeightField.addActionListener(this);
+
+ tableColWeightField.addFocusListener(this);
+ topLevel.add(tableColWeightField);
+
+ topLevel.add(new JLabel("Attributes"), "itop=5 col=0 cspan=2");
+ tableAttributesField = new JTextField();
+ tableAttributesField.setEditable(false);
+ topLevel.add(tableAttributesField, "itop=5");
+
+ // Make sure components are initialized as per the default table
+ // attributes
+
+ tableAttributes = new TableAttributes();
+ setTableAttributes(tableAttributes);
+
+ // Cell Attributes
+
+ topLevel.add(new JSeparator(), "cspan=3 itop=20 ibottom=5");
+
+ topLevel.add(new JLabel("Cell Attributes"), "cspan=3");
+
+ topLevel.add(new JLabel("Cell insets"), "col=1");
+ topLevel.add(createInsetsPane(insetFields));
+
+ topLevel.add(new JLabel("Cell position"), "col=1");
+ positionBox = new JComboBox(positionList);
+ positionBox.addActionListener(this);
+ topLevel.add(positionBox);
+
+ topLevel.add(new JLabel("Cell fill"), "col=1");
+ fillBox = new JComboBox(fillList);
+ fillBox.addActionListener(this);
+ topLevel.add(fillBox);
+
+ topLevel.add(new JLabel("Row weight"), "col=1");
+ rowWeightField = new JTextField(10);
+ rowWeightField.addActionListener(this);
+ rowWeightField.addFocusListener(this);
+ topLevel.add(rowWeightField);
+
+ topLevel.add(new JLabel("Column weight"), "col=1");
+ colWeightField = new JTextField(10);
+ colWeightField.addActionListener(this);
+ colWeightField.addFocusListener(this);
+ topLevel.add(colWeightField);
+
+ topLevel.add(new JLabel("Column position"), "col=1");
+ colPositionField = new JTextField(10);
+ colPositionField.addActionListener(this);
+ colPositionField.addFocusListener(this);
+ topLevel.add(colPositionField);
+
+ topLevel.add(new JLabel("Skip cells"), "col=1");
+ skipCellsField = new JTextField(10);
+ skipCellsField.addActionListener(this);
+ skipCellsField.addFocusListener(this);
+ topLevel.add(skipCellsField);
+
+ topLevel.add(new JLabel("Row span"), "col=1");
+ rowSpanField = new JTextField(10);
+ rowSpanField.addActionListener(this);
+ rowSpanField.addFocusListener(this);
+ topLevel.add(rowSpanField);
- for (int i = 0; i < 4; i++) {
- insetFields[i] = new JTextField(2);
- insetFields[i].addActionListener(this);
- insetFields[i].addFocusListener(this);
+ topLevel.add(new JLabel("Column span"), "col=1");
+ colSpanField = new JTextField(10);
+ colSpanField.addActionListener(this);
+ colSpanField.addFocusListener(this);
+ topLevel.add(colSpanField);
+
+ topLevel.add(new JLabel("Attributes"), "itop=5 col=0 cspan=2");
+ cellAttributesField = new JTextField();
+ cellAttributesField.setEditable(false);
+ topLevel.add(cellAttributesField, "itop=5");
+
+ enableAttributes(false);
+
+ return topLevel;
}
- topLevel.add(insetFields[0], "col=1");
- topLevel.add(insetFields[1], "col=0");
- topLevel.add(insetFields[2], "col=2");
- topLevel.add(insetFields[3], "col=1");
+ Component
+ createInsetsPane(
+ JTextField[] insetFields)
+ {
+ JPanel topLevel = new JPanel(new TableLayout("cols=3"));
- return topLevel;
-}
+ for (int i = 0; i < 4; i++) {
+ insetFields[i] = new JTextField(2);
+ insetFields[i].addActionListener(this);
+ insetFields[i].addFocusListener(this);
+ }
-JPanel
-createCodePane()
-{
- JPanel topLevel = new JPanel(new TableLayout("cols=2 rgap=2 cgap=5"));
+ topLevel.add(insetFields[0], "col=1");
+ topLevel.add(insetFields[1], "col=0");
+ topLevel.add(insetFields[2], "col=2");
+ topLevel.add(insetFields[3], "col=1");
- codeTextArea = new JTextArea(15, 30);
- codeTextScroll = new JScrollPane(codeTextArea);
- topLevel.add(codeTextScroll, "cspan=2 rweight=1");
+ return topLevel;
+ }
- return topLevel;
-}
+ JPanel
+ createCodePane()
+ {
+ JPanel topLevel = new JPanel(new TableLayout("cols=2 rgap=2 cgap=5"));
-void
-addToLayout(
- Component c)
-{
- try {
- layoutPane.add(c);
- }
- catch (IllegalArgumentException e) {
- JOptionPane.showMessageDialog(
- this, e.toString(), "Attribute Error", JOptionPane.ERROR_MESSAGE);
- }
- layoutPane.revalidate();
-}
+ codeTextArea = new JTextArea(15, 30);
+ codeTextScroll = new JScrollPane(codeTextArea);
+ topLevel.add(codeTextScroll, "cspan=2 rweight=1");
-void
-addToLayout(
- Component c,
- String a,
- int index)
-{
- try {
- layoutPane.add(c, a, index);
- }
- catch (IllegalArgumentException e) {
- JOptionPane.showMessageDialog(
- this, e.toString(), "Attribute Error", JOptionPane.ERROR_MESSAGE);
+ return topLevel;
}
- layoutPane.revalidate();
-}
-void
-changeTableLayout()
-{
- tableAttributes = getTableAttributes();
- try {
- ((TableLayout)layoutPane.getLayout()).setTableAttributes(
- tableAttributes.toString());
+ void
+ addToLayout(
+ Component c)
+ {
+ try {
+ layoutPane.add(c);
+ }
+ catch (IllegalArgumentException e) {
+ JOptionPane.showMessageDialog(
+ this, e.toString(), "Attribute Error", JOptionPane.ERROR_MESSAGE);
+ }
+ layoutPane.revalidate();
}
- catch (IllegalArgumentException e) {
- JOptionPane.showMessageDialog(
- this, e.toString(), "Attribute Error", JOptionPane.ERROR_MESSAGE);
- }
- layoutPane.revalidate();
- setTableAttributes(tableAttributes); // Normalize appearance
-}
-
-void
-changeLayout()
-{
- String name = (String)compList.getSelectedValue();
- changeLayout(name);
-}
-void
-changeLayout(
- String name)
-{
- if (name == null) return;
-
- Component c = (Component)compHash.get(name);
- Attributes attributes = getAttributes();
- try {
- ((TableLayout)layoutPane.getLayout()).setAttributes(
- c, attributes.toString());
- }
- catch (IllegalArgumentException e) {
- JOptionPane.showMessageDialog(
- this, e.toString(), "Attribute Error", JOptionPane.ERROR_MESSAGE);
+ void
+ addToLayout(
+ Component c,
+ String a,
+ int index)
+ {
+ try {
+ layoutPane.add(c, a, index);
+ }
+ catch (IllegalArgumentException e) {
+ JOptionPane.showMessageDialog(
+ this, e.toString(), "Attribute Error", JOptionPane.ERROR_MESSAGE);
+ }
+ layoutPane.revalidate();
}
- layoutPane.revalidate();
- setAttributes(attributes); // Normalize appearance
- attrHash.put(name, attributes);
-}
-TableAttributes
-getTableAttributes()
-{
- TableAttributes attributes = new TableAttributes();
-
- attributes.columns = getNumber(attributes.columns, columnsField);
- attributes.rGap = getNumber(attributes.rGap, rowGapField);
- attributes.cGap = getNumber(attributes.cGap, colGapField);
-
- attributes.tableInsets.top =
- getNumber(attributes.tableInsets.top, tableInsetFields[0]);
- attributes.tableInsets.left =
- getNumber(attributes.tableInsets.left, tableInsetFields[1]);
- attributes.tableInsets.right =
- getNumber(attributes.tableInsets.right, tableInsetFields[2]);
- attributes.tableInsets.bottom =
- getNumber(attributes.tableInsets.bottom, tableInsetFields[3]);
-
- attributes.tablePosition = getString(tablePositionBox);
- attributes.tableFill = getString(tableFillBox);
-
- attributes.insets.top =
- getNumber(attributes.insets.top, tableCellInsetFields[0]);
- attributes.insets.left =
- getNumber(attributes.insets.left, tableCellInsetFields[1]);
- attributes.insets.right =
- getNumber(attributes.insets.right, tableCellInsetFields[2]);
- attributes.insets.bottom =
- getNumber(attributes.insets.bottom, tableCellInsetFields[3]);
-
- attributes.position = getString(tableCellPositionBox);
- attributes.fill = getString(tableCellFillBox);
- attributes.rWeight = getNumber(attributes.rWeight, tableRowWeightField);
- attributes.cWeight = getNumber(attributes.cWeight, tableColWeightField);
-
- return attributes;
-}
-
-void
-setTableAttributes(
- TableAttributes attributes)
-{
- ignoreEvents = true;
-
- columnsField.setText(Integer.toString(attributes.columns));
- rowGapField.setText(Integer.toString(attributes.rGap));
- colGapField.setText(Integer.toString(attributes.cGap));
-
- tableInsetFields[0].setText(
- Integer.toString(attributes.tableInsets.top));
- tableInsetFields[1].setText(
- Integer.toString(attributes.tableInsets.left));
- tableInsetFields[2].setText(
- Integer.toString(attributes.tableInsets.right));
- tableInsetFields[3].setText(
- Integer.toString(attributes.tableInsets.bottom));
-
- tablePositionBox.setSelectedItem(attributes.tablePosition);
- tableFillBox.setSelectedItem(attributes.tableFill);
-
- tableCellInsetFields[0].setText(
- Integer.toString(attributes.insets.top));
- tableCellInsetFields[1].setText(
- Integer.toString(attributes.insets.left));
- tableCellInsetFields[2].setText(
- Integer.toString(attributes.insets.right));
- tableCellInsetFields[3].setText(
- Integer.toString(attributes.insets.bottom));
-
- tableCellPositionBox.setSelectedItem(attributes.position);
- tableCellFillBox.setSelectedItem(attributes.fill);
- tableRowWeightField.setText(Integer.toString(attributes.rWeight));
- tableColWeightField.setText(Integer.toString(attributes.cWeight));
-
- tableAttributesField.setText(attributes.toString());
-
- ignoreEvents = false;
-}
-
-Attributes
-getAttributes()
-{
- Attributes attributes = new Attributes();
-
- attributes.insets.top =
- getNumber(attributes.insets.top, insetFields[0]);
- attributes.insets.left =
- getNumber(attributes.insets.left, insetFields[1]);
- attributes.insets.right =
- getNumber(attributes.insets.right, insetFields[2]);
- attributes.insets.bottom =
- getNumber(attributes.insets.bottom, insetFields[3]);
-
- attributes.position = getString(positionBox);
- attributes.fill = getString(fillBox);
- attributes.rWeight = getNumber(attributes.rWeight, rowWeightField);
- attributes.cWeight = getNumber(attributes.cWeight, colWeightField);
- attributes.column = getNumber(attributes.column, colPositionField);
- attributes.skip = getNumber(attributes.skip, skipCellsField);
- attributes.rSpan = getNumber(attributes.rSpan, rowSpanField);
- attributes.cSpan = getNumber(attributes.cSpan, colSpanField);
-
- return attributes;
-}
-
-void
-setAttributes(
- Attributes attributes)
-{
- ignoreEvents = true;
-
- insetFields[0].setText(Integer.toString(attributes.insets.top));
- insetFields[1].setText(Integer.toString(attributes.insets.left));
- insetFields[2].setText(Integer.toString(attributes.insets.right));
- insetFields[3].setText(Integer.toString(attributes.insets.bottom));
+ void
+ changeTableLayout()
+ {
+ tableAttributes = getTableAttributes();
+ try {
+ ((TableLayout)layoutPane.getLayout()).setTableAttributes(
+ tableAttributes.toString());
+ }
+ catch (IllegalArgumentException e) {
+ JOptionPane.showMessageDialog(
+ this, e.toString(), "Attribute Error", JOptionPane.ERROR_MESSAGE);
+ }
+ layoutPane.revalidate();
+ setTableAttributes(tableAttributes); // Normalize appearance
+ }
- positionBox.setSelectedItem(attributes.position);
- fillBox.setSelectedItem(attributes.fill);
- rowWeightField.setText(Integer.toString(attributes.rWeight));
- colWeightField.setText(Integer.toString(attributes.cWeight));
- colPositionField.setText(Integer.toString(attributes.column));
- skipCellsField.setText(Integer.toString(attributes.skip));
- rowSpanField.setText(Integer.toString(attributes.rSpan));
- colSpanField.setText(Integer.toString(attributes.cSpan));
+ void
+ changeLayout()
+ {
+ String name = (String)compList.getSelectedValue();
+ changeLayout(name);
+ }
- cellAttributesField.setText(attributes.toString());
+ void
+ changeLayout(
+ String name)
+ {
+ if (name == null) return;
+
+ Component c = (Component)compHash.get(name);
+ Attributes attributes = getAttributes();
+ try {
+ ((TableLayout)layoutPane.getLayout()).setAttributes(
+ c, attributes.toString());
+ }
+ catch (IllegalArgumentException e) {
+ JOptionPane.showMessageDialog(
+ this, e.toString(), "Attribute Error", JOptionPane.ERROR_MESSAGE);
+ }
+ layoutPane.revalidate();
+ setAttributes(attributes); // Normalize appearance
+ attrHash.put(name, attributes);
+ }
- ignoreEvents = false;
-}
+ TableAttributes
+ getTableAttributes()
+ {
+ TableAttributes attributes = new TableAttributes();
+
+ attributes.columns = getNumber(attributes.columns, columnsField);
+ attributes.rGap = getNumber(attributes.rGap, rowGapField);
+ attributes.cGap = getNumber(attributes.cGap, colGapField);
+
+ attributes.tableInsets.top =
+ getNumber(attributes.tableInsets.top, tableInsetFields[0]);
+ attributes.tableInsets.left =
+ getNumber(attributes.tableInsets.left, tableInsetFields[1]);
+ attributes.tableInsets.right =
+ getNumber(attributes.tableInsets.right, tableInsetFields[2]);
+ attributes.tableInsets.bottom =
+ getNumber(attributes.tableInsets.bottom, tableInsetFields[3]);
+
+ attributes.tablePosition = getString(tablePositionBox);
+ attributes.tableFill = getString(tableFillBox);
+
+ attributes.insets.top =
+ getNumber(attributes.insets.top, tableCellInsetFields[0]);
+ attributes.insets.left =
+ getNumber(attributes.insets.left, tableCellInsetFields[1]);
+ attributes.insets.right =
+ getNumber(attributes.insets.right, tableCellInsetFields[2]);
+ attributes.insets.bottom =
+ getNumber(attributes.insets.bottom, tableCellInsetFields[3]);
+
+ attributes.position = getString(tableCellPositionBox);
+ attributes.fill = getString(tableCellFillBox);
+ attributes.rWeight = getNumber(attributes.rWeight, tableRowWeightField);
+ attributes.cWeight = getNumber(attributes.cWeight, tableColWeightField);
+
+ return attributes;
+ }
-int
-getNumber(
- int defaultValue,
- JTextField field)
-{
- String text = field.getText().trim();
- if (text.length() == 0) return defaultValue;
+ void
+ setTableAttributes(
+ TableAttributes attributes)
+ {
+ ignoreEvents = true;
+
+ columnsField.setText(Integer.toString(attributes.columns));
+ rowGapField.setText(Integer.toString(attributes.rGap));
+ colGapField.setText(Integer.toString(attributes.cGap));
+
+ tableInsetFields[0].setText(
+ Integer.toString(attributes.tableInsets.top));
+ tableInsetFields[1].setText(
+ Integer.toString(attributes.tableInsets.left));
+ tableInsetFields[2].setText(
+ Integer.toString(attributes.tableInsets.right));
+ tableInsetFields[3].setText(
+ Integer.toString(attributes.tableInsets.bottom));
+
+ tablePositionBox.setSelectedItem(attributes.tablePosition);
+ tableFillBox.setSelectedItem(attributes.tableFill);
+
+ tableCellInsetFields[0].setText(
+ Integer.toString(attributes.insets.top));
+ tableCellInsetFields[1].setText(
+ Integer.toString(attributes.insets.left));
+ tableCellInsetFields[2].setText(
+ Integer.toString(attributes.insets.right));
+ tableCellInsetFields[3].setText(
+ Integer.toString(attributes.insets.bottom));
+
+ tableCellPositionBox.setSelectedItem(attributes.position);
+ tableCellFillBox.setSelectedItem(attributes.fill);
+ tableRowWeightField.setText(Integer.toString(attributes.rWeight));
+ tableColWeightField.setText(Integer.toString(attributes.cWeight));
+
+ tableAttributesField.setText(attributes.toString());
+
+ ignoreEvents = false;
+ }
- int value = 0;
- try {
- value = Integer.parseInt(text);
+ Attributes
+ getAttributes()
+ {
+ Attributes attributes = new Attributes();
+
+ attributes.insets.top =
+ getNumber(attributes.insets.top, insetFields[0]);
+ attributes.insets.left =
+ getNumber(attributes.insets.left, insetFields[1]);
+ attributes.insets.right =
+ getNumber(attributes.insets.right, insetFields[2]);
+ attributes.insets.bottom =
+ getNumber(attributes.insets.bottom, insetFields[3]);
+
+ attributes.position = getString(positionBox);
+ attributes.fill = getString(fillBox);
+ attributes.rWeight = getNumber(attributes.rWeight, rowWeightField);
+ attributes.cWeight = getNumber(attributes.cWeight, colWeightField);
+ attributes.column = getNumber(attributes.column, colPositionField);
+ attributes.skip = getNumber(attributes.skip, skipCellsField);
+ attributes.rSpan = getNumber(attributes.rSpan, rowSpanField);
+ attributes.cSpan = getNumber(attributes.cSpan, colSpanField);
+
+ return attributes;
}
- catch (NumberFormatException e) {}
- return value;
-}
+ void
+ setAttributes(
+ Attributes attributes)
+ {
+ ignoreEvents = true;
+
+ insetFields[0].setText(Integer.toString(attributes.insets.top));
+ insetFields[1].setText(Integer.toString(attributes.insets.left));
+ insetFields[2].setText(Integer.toString(attributes.insets.right));
+ insetFields[3].setText(Integer.toString(attributes.insets.bottom));
+
+ positionBox.setSelectedItem(attributes.position);
+ fillBox.setSelectedItem(attributes.fill);
+ rowWeightField.setText(Integer.toString(attributes.rWeight));
+ colWeightField.setText(Integer.toString(attributes.cWeight));
+ colPositionField.setText(Integer.toString(attributes.column));
+ skipCellsField.setText(Integer.toString(attributes.skip));
+ rowSpanField.setText(Integer.toString(attributes.rSpan));
+ colSpanField.setText(Integer.toString(attributes.cSpan));
+
+ cellAttributesField.setText(attributes.toString());
+
+ ignoreEvents = false;
+ }
-String
-getString(
- JComboBox box)
-{
- return (String)box.getSelectedItem();
-}
+ int
+ getNumber(
+ int defaultValue,
+ JTextField field)
+ {
+ String text = field.getText().trim();
+ if (text.length() == 0) return defaultValue;
+
+ int value = 0;
+ try {
+ value = Integer.parseInt(text);
+ }
+ catch (NumberFormatException e) {}
+
+ return value;
+ }
-void
-enableAttributes(
- boolean enable)
-{
- positionBox.setEnabled(enable);
- fillBox.setEnabled(enable);
- rowWeightField.setEnabled(enable);
- colWeightField.setEnabled(enable);
- colPositionField.setEnabled(enable);
- skipCellsField.setEnabled(enable);
- rowSpanField.setEnabled(enable);
- colSpanField.setEnabled(enable);
-
- for (int i = 0; i < 4; i++) {
- insetFields[i].setEnabled(enable);
+ String
+ getString(
+ JComboBox box)
+ {
+ return (String)box.getSelectedItem();
}
-}
-void
-generateCode()
-{
- tableAttributes = getTableAttributes();
-
- String indent = "";
- String containerName = "";
-
- StringBuffer code = new StringBuffer(
- indent + "// Code generated by Table Explorer V1.0\n" +
- indent +
- "// Copyright © 2004, Antonio Freixas\n" +
- indent + "// All Rights Reserved.\n" +
- indent + "// tony@freixas.org\n\n" +
- indent + "// Define the table layout\n\n" +
- indent + "JPanel panel = new JPanel(new TableLayout(" +
- "\"" + tableAttributes.toString().trim() + "\"));\n\n");
-
- for (int i = 0; i < compListModel.size(); i++) {
- String name = (String)compListModel.elementAt(i);
- Attributes attr = (Attributes)attrHash.get(name);
- String sAttr = attr.toString().trim();
- code.append(
- indent + "panel.add(new JButton(\"" + name + "\"" +
- (sAttr.length() > 0 ? ", \"" + sAttr + "\"" : "") + "));\n");
+ void
+ enableAttributes(
+ boolean enable)
+ {
+ positionBox.setEnabled(enable);
+ fillBox.setEnabled(enable);
+ rowWeightField.setEnabled(enable);
+ colWeightField.setEnabled(enable);
+ colPositionField.setEnabled(enable);
+ skipCellsField.setEnabled(enable);
+ rowSpanField.setEnabled(enable);
+ colSpanField.setEnabled(enable);
+
+ for (int i = 0; i < 4; i++) {
+ insetFields[i].setEnabled(enable);
+ }
}
- codeTextArea.setText(code.toString());
-}
+ void
+ generateCode()
+ {
+ tableAttributes = getTableAttributes();
+
+ String indent = "";
+ String containerName = "";
+
+ StringBuffer code = new StringBuffer(
+ indent + "// Code generated by Table Explorer V1.0\n" +
+ indent +
+ "// Copyright © 2004, Antonio Freixas\n" +
+ indent + "// All Rights Reserved.\n" +
+ indent + "// tony@freixas.org\n\n" +
+ indent + "// Define the table layout\n\n" +
+ indent + "JPanel panel = new JPanel(new TableLayout(" +
+ "\"" + tableAttributes.toString().trim() + "\"));\n\n");
+
+ for (int i = 0; i < compListModel.size(); i++) {
+ String name = (String)compListModel.elementAt(i);
+ Attributes attr = (Attributes)attrHash.get(name);
+ String sAttr = attr.toString().trim();
+ code.append(
+ indent + "panel.add(new JButton(\"" + name + "\"" +
+ (sAttr.length() > 0 ? ", \"" + sAttr + "\"" : "") + "));\n");
+ }
+
+ codeTextArea.setText(code.toString());
+ }
//**********************************************************************
// Protected
@@ -1070,158 +1070,158 @@ generateCode()
// Inner Classes
//**********************************************************************
-class TableAttributes
-{
+ class TableAttributes
+ {
// Table-only options
-int columns = 1;
-int rGap = 0;
-int cGap = 0;
-Insets tableInsets = new Insets(0, 0, 0, 0);
-String tablePosition = "Default";
-String tableFill = "Default";
+ int columns = 1;
+ int rGap = 0;
+ int cGap = 0;
+ Insets tableInsets = new Insets(0, 0, 0, 0);
+ String tablePosition = "Default";
+ String tableFill = "Default";
// Table/cell options
-Insets insets = new Insets(0, 0, 0, 0);
-String position = "Default";
-String fill = "Default";
-int rWeight = 0;
-int cWeight = 0;
-
-public String
-toString()
-{
- StringBuffer b = new StringBuffer();
-
- if (columns != 1) {
- b.append("cols=" + columns + " ");
- }
-
- if (rGap != 0) {
- b.append("rgap=" + rGap + " ");
- }
- if (cGap != 0) {
- b.append("cgap=" + cGap + " ");
- }
-
- if (tableInsets.top != 0) {
- b.append("titop=" + tableInsets.top + " ");
- }
- if (tableInsets.bottom != 0) {
- b.append("tibottom=" + tableInsets.bottom + " ");
- }
- if (tableInsets.left != 0) {
- b.append("tileft=" + tableInsets.left + " ");
- }
- if (tableInsets.right != 0) {
- b.append("tiright=" + tableInsets.right + " ");
- }
-
- if (!"Default".equals(tablePosition)) {
- b.append(tablePosition + " ");
- }
- if (!"Default".equals(tableFill)) {
- b.append(tableFill + " ");
- }
-
- if (insets.top != 0) {
- b.append("itop=" + insets.top + " ");
- }
- if (insets.bottom != 0) {
- b.append("ibottom=" + insets.bottom + " ");
- }
- if (insets.left != 0) {
- b.append("ileft=" + insets.left + " ");
- }
- if (insets.right != 0) {
- b.append("iright=" + insets.right + " ");
- }
-
- if (!"Default".equals(position)) {
- b.append(position + " ");
- }
- if (!"Default".equals(fill)) {
- b.append(fill + " ");
- }
-
- if (rWeight != 0) {
- b.append("rweight=" + rWeight + " ");
- }
- if (cWeight != 0) {
- b.append("cweight=" + cWeight + " ");
- }
-
- return new String(b);
-}
-
-}
-
-class Attributes
-{
-
-Insets insets = new Insets(0, 0, 0, 0);
-String position = "Default";
-String fill = "Default";
-int rWeight = 0;
-int cWeight = 0;
-int column = -1;
-int skip = 0;
-int rSpan = 1;
-int cSpan = 1;
-
-public String
-toString()
-{
- StringBuffer b = new StringBuffer();
+ Insets insets = new Insets(0, 0, 0, 0);
+ String position = "Default";
+ String fill = "Default";
+ int rWeight = 0;
+ int cWeight = 0;
+
+ public String
+ toString()
+ {
+ StringBuffer b = new StringBuffer();
+
+ if (columns != 1) {
+ b.append("cols=" + columns + " ");
+ }
+
+ if (rGap != 0) {
+ b.append("rgap=" + rGap + " ");
+ }
+ if (cGap != 0) {
+ b.append("cgap=" + cGap + " ");
+ }
+
+ if (tableInsets.top != 0) {
+ b.append("titop=" + tableInsets.top + " ");
+ }
+ if (tableInsets.bottom != 0) {
+ b.append("tibottom=" + tableInsets.bottom + " ");
+ }
+ if (tableInsets.left != 0) {
+ b.append("tileft=" + tableInsets.left + " ");
+ }
+ if (tableInsets.right != 0) {
+ b.append("tiright=" + tableInsets.right + " ");
+ }
+
+ if (!"Default".equals(tablePosition)) {
+ b.append(tablePosition + " ");
+ }
+ if (!"Default".equals(tableFill)) {
+ b.append(tableFill + " ");
+ }
+
+ if (insets.top != 0) {
+ b.append("itop=" + insets.top + " ");
+ }
+ if (insets.bottom != 0) {
+ b.append("ibottom=" + insets.bottom + " ");
+ }
+ if (insets.left != 0) {
+ b.append("ileft=" + insets.left + " ");
+ }
+ if (insets.right != 0) {
+ b.append("iright=" + insets.right + " ");
+ }
+
+ if (!"Default".equals(position)) {
+ b.append(position + " ");
+ }
+ if (!"Default".equals(fill)) {
+ b.append(fill + " ");
+ }
+
+ if (rWeight != 0) {
+ b.append("rweight=" + rWeight + " ");
+ }
+ if (cWeight != 0) {
+ b.append("cweight=" + cWeight + " ");
+ }
+
+ return new String(b);
+ }
- if (insets.top != tableAttributes.insets.top) {
- b.append("itop=" + insets.top + " ");
- }
- if (insets.bottom != tableAttributes.insets.bottom) {
- b.append("ibottom=" + insets.bottom + " ");
- }
- if (insets.left != tableAttributes.insets.left) {
- b.append("ileft=" + insets.left + " ");
- }
- if (insets.right != tableAttributes.insets.right) {
- b.append("iright=" + insets.right + " ");
}
- if (!"Default".equals(position)) {
- b.append(position + " ");
- }
- if (!"Default".equals(fill)) {
- b.append(fill + " ");
- }
+ class Attributes
+ {
+
+ Insets insets = new Insets(0, 0, 0, 0);
+ String position = "Default";
+ String fill = "Default";
+ int rWeight = 0;
+ int cWeight = 0;
+ int column = -1;
+ int skip = 0;
+ int rSpan = 1;
+ int cSpan = 1;
+
+ public String
+ toString()
+ {
+ StringBuffer b = new StringBuffer();
+
+ if (insets.top != tableAttributes.insets.top) {
+ b.append("itop=" + insets.top + " ");
+ }
+ if (insets.bottom != tableAttributes.insets.bottom) {
+ b.append("ibottom=" + insets.bottom + " ");
+ }
+ if (insets.left != tableAttributes.insets.left) {
+ b.append("ileft=" + insets.left + " ");
+ }
+ if (insets.right != tableAttributes.insets.right) {
+ b.append("iright=" + insets.right + " ");
+ }
+
+ if (!"Default".equals(position)) {
+ b.append(position + " ");
+ }
+ if (!"Default".equals(fill)) {
+ b.append(fill + " ");
+ }
+
+ if (rWeight != tableAttributes.rWeight) {
+ b.append("rweight=" + rWeight + " ");
+ }
+ if (cWeight != tableAttributes.cWeight) {
+ b.append("cweight=" + cWeight + " ");
+ }
+
+ if (column != -1) {
+ b.append("col=" + column + " ");
+ }
+
+ if (skip != 0) {
+ b.append("skip=" + skip + " ");
+ }
+
+ if (rSpan != 1) {
+ b.append("rspan=" + rSpan + " ");
+ }
+ if (cSpan != 1) {
+ b.append("cspan=" + cSpan + " ");
+ }
+
+ return new String(b);
+ }
- if (rWeight != tableAttributes.rWeight) {
- b.append("rweight=" + rWeight + " ");
}
- if (cWeight != tableAttributes.cWeight) {
- b.append("cweight=" + cWeight + " ");
- }
-
- if (column != -1) {
- b.append("col=" + column + " ");
- }
-
- if (skip != 0) {
- b.append("skip=" + skip + " ");
- }
-
- if (rSpan != 1) {
- b.append("rspan=" + rSpan + " ");
- }
- if (cSpan != 1) {
- b.append("cspan=" + cSpan + " ");
- }
-
- return new String(b);
-}
-
-}
//**********************************************************************
// End Inner Classes
diff --git a/libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java b/libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java
index 870115d..75d42f3 100644
--- a/libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java
+++ b/libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java
@@ -263,7 +263,7 @@ import java.util.Iterator;
// All Rights Reserved.
public class TableLayout
- implements LayoutManager2
+ implements LayoutManager2
{
//**********************************************************************
@@ -273,554 +273,554 @@ public class TableLayout
// This is the set of attributes applied to the table. Some attributes
// are used as cell defaults. Cell-only attributes are ignored
-private Attributes tableAttributes;
+ private Attributes tableAttributes;
// Attributes for each component can be found in these hash tables
-private HashMap compAttributes = new HashMap();
+ private HashMap compAttributes = new HashMap();
// These variables store information about the row/col arrangement of
// the components. These are set by placeComponents()
-private int nRows = 0;
-private int nCols = 0;
-private Component[][] components = null;
+ private int nRows = 0;
+ private int nCols = 0;
+ private Component[][] components = null;
// We cache measureComponents() information so that it is recalculated
// after invalidateLayout() is called
-private boolean useCacheMeasureResults = false;
+ private boolean useCacheMeasureResults = false;
// These variables store sizing information set by measureComponents()
-private int[] minWidth;
-private int[] prefWidth;
-private int[] maxWidth;
-private int[] adjWidth;
-private int[] colWeight;
+ private int[] minWidth;
+ private int[] prefWidth;
+ private int[] maxWidth;
+ private int[] adjWidth;
+ private int[] colWeight;
-private int[] minHeight;
-private int[] prefHeight;
-private int[] maxHeight;
-private int[] adjHeight;
-private int[] rowWeight;
+ private int[] minHeight;
+ private int[] prefHeight;
+ private int[] maxHeight;
+ private int[] adjHeight;
+ private int[] rowWeight;
// These sizes are the minimum width for the table, not including
// either the container's insets or the table's insets
-private int MinWidth = 0;
-private int MinHeight = 0;
-private int PrefWidth = 0;
-private int PrefHeight = 0;
-private int MaxWidth = 0;
-private int MaxHeight = 0;
-private int ColWeight = 0;
-private int RowWeight = 0;
+ private int MinWidth = 0;
+ private int MinHeight = 0;
+ private int PrefWidth = 0;
+ private int PrefHeight = 0;
+ private int MaxWidth = 0;
+ private int MaxHeight = 0;
+ private int ColWeight = 0;
+ private int RowWeight = 0;
-static private int classCount = 0;
-private int instanceCount = classCount++;
+ static private int classCount = 0;
+ private int instanceCount = classCount++;
//**********************************************************************
// Constructors
//**********************************************************************
-/**
- * Construct a new TableLayout.
- */
-
-public
-TableLayout()
-{
- this(null);
-}
+ /**
+ * Construct a new TableLayout.
+ */
-/**
- * Construct a new TableLayout with the given attributes.
- *
- * @param attributes A list of attributes for the table. The list is
- * described in the class documentation above. Cell-only
- * attributes are ignored.
- */
+ public
+ TableLayout()
+ {
+ this(null);
+ }
-public
-TableLayout(
- String attributes)
-{
- tableAttributes = new Attributes(attributes);
-}
+ /**
+ * Construct a new TableLayout with the given attributes.
+ *
+ * @param attributes A list of attributes for the table. The list is
+ * described in the class documentation above. Cell-only
+ * attributes are ignored.
+ */
+
+ public
+ TableLayout(
+ String attributes)
+ {
+ tableAttributes = new Attributes(attributes);
+ }
//**********************************************************************
// Public
//**********************************************************************
-/**
- * Reset the table attributes for the layout.
- *
- * @param attributes The new table attributes.
- */
-
-public void
-setTableAttributes(
- String attributes)
-{
- // Set the attributes for the table
-
- tableAttributes = new Attributes(attributes);
-
- // Since the component attributes "inherit" from the table
- // attributes, any change to the table attributes causes us to
- // reprocess all existing component attributes
-
- Iterator iter = compAttributes.keySet().iterator();
- while (iter.hasNext()) {
- Component comp = (Component)iter.next();
- Attributes a = (Attributes)compAttributes.get(comp);
- a.parse(); // Re-parse
+ /**
+ * Reset the table attributes for the layout.
+ *
+ * @param attributes The new table attributes.
+ */
+
+ public void
+ setTableAttributes(
+ String attributes)
+ {
+ // Set the attributes for the table
+
+ tableAttributes = new Attributes(attributes);
+
+ // Since the component attributes "inherit" from the table
+ // attributes, any change to the table attributes causes us to
+ // reprocess all existing component attributes
+
+ Iterator iter = compAttributes.keySet().iterator();
+ while (iter.hasNext()) {
+ Component comp = (Component)iter.next();
+ Attributes a = (Attributes)compAttributes.get(comp);
+ a.parse(); // Re-parse
+ }
+
+ components = null;
+ useCacheMeasureResults = false;
}
- components = null;
- useCacheMeasureResults = false;
-}
-
-/**
- * Reset the attributes for a component in the layout. The component
- * must already have been added to the container or else this call has
- * no effect.
- *
- * @param comp The component to alter.
- * @param attributes The new attributes for the component.
- */
-
-public void
-setAttributes(
- Component comp,
- String attributes)
-{
- if (compAttributes.get(comp) != null) {
- Attributes a = new Attributes(attributes, false);
- compAttributes.put(comp, a);
-
- components = null;
- useCacheMeasureResults = false;
+ /**
+ * Reset the attributes for a component in the layout. The component
+ * must already have been added to the container or else this call has
+ * no effect.
+ *
+ * @param comp The component to alter.
+ * @param attributes The new attributes for the component.
+ */
+
+ public void
+ setAttributes(
+ Component comp,
+ String attributes)
+ {
+ if (compAttributes.get(comp) != null) {
+ Attributes a = new Attributes(attributes, false);
+ compAttributes.put(comp, a);
+
+ components = null;
+ useCacheMeasureResults = false;
+ }
}
-}
-/**
- * Adds the component with the specified attributes to the layout.
- *
- * @param attributes A list of attributes for the component. The list
- * is described in the class documentation above. Table-only
- * attributes are ignored.
- * @param comp The component to be added.
- */
+ /**
+ * Adds the component with the specified attributes to the layout.
+ *
+ * @param attributes A list of attributes for the component. The list
+ * is described in the class documentation above. Table-only
+ * attributes are ignored.
+ * @param comp The component to be added.
+ */
-public void
-addLayoutComponent(
- String attributes,
- Component comp)
-{
- Attributes a = new Attributes(attributes, false);
- compAttributes.put(comp, a);
+ public void
+ addLayoutComponent(
+ String attributes,
+ Component comp)
+ {
+ Attributes a = new Attributes(attributes, false);
+ compAttributes.put(comp, a);
- components = null;
- useCacheMeasureResults = false;
+ components = null;
+ useCacheMeasureResults = false;
- // DEBUG
+ // DEBUG
// if ("DEBUG".equals(comp.getName())) {
// System.out.println(
// "Adding comp " + comp.getClass().getName() + " " + a);
// }
-}
-
-/**
- * Adds the specified component to the layout, using the specified
- * constraint object (which we expect to be a String of attributes).
- *
- * @param comp The component to be added.
- * @param constraints A list of attributes for the component. The list
- * is described in the class documentation above. Table-only
- * attributes are ignored.
- */
-
-public void
-addLayoutComponent(
- Component comp,
- Object constraints)
-{
- String attributes = "";
- if (constraints instanceof String) {
- attributes = (String)constraints;
}
- addLayoutComponent(attributes, comp);
-}
-/**
- * Removes the specified component from the layout.
-
- * @param comp The component to be removed.
- */
-
-public void
-removeLayoutComponent(
- Component comp)
-{
- compAttributes.remove(comp);
- components = null;
-}
-
-/**
- * Calculates the minimum size dimensions for the layout given the
- * components in the a parent container.
- *
- * @param parent The container to be laid out.
- * @return The minimum layout size.
- * @see #preferredLayoutSize(Container)
- * @see #maximumLayoutSize(Container)
- */
-
-public Dimension
-minimumLayoutSize(
- Container parent)
-{
- Insets insets = parent.getInsets();
- measureComponents(parent);
- int w =
- insets.left + insets.right +
- tableAttributes.tableInsets.left +
- tableAttributes.tableInsets.right +
- MinWidth;
- int h =
- insets.top + insets.bottom +
- tableAttributes.tableInsets.top +
- tableAttributes.tableInsets.bottom +
- MinHeight;
- if (w > Short.MAX_VALUE) w = Short.MAX_VALUE;
- if (h > Short.MAX_VALUE) h = Short.MAX_VALUE;
-
- return new Dimension(w, h);
-}
-
-/**
- * Calculates the preferred size dimensions for the layout given the
- * components in a parent container.
- *
- * @param parent The container to be laid out.
- * @return The preferred layout size.
- * @see #minimumLayoutSize(Container)
- * @see #maximumLayoutSize(Container)
- */
+ /**
+ * Adds the specified component to the layout, using the specified
+ * constraint object (which we expect to be a String of attributes).
+ *
+ * @param comp The component to be added.
+ * @param constraints A list of attributes for the component. The list
+ * is described in the class documentation above. Table-only
+ * attributes are ignored.
+ */
+
+ public void
+ addLayoutComponent(
+ Component comp,
+ Object constraints)
+ {
+ String attributes = "";
+ if (constraints instanceof String) {
+ attributes = (String)constraints;
+ }
+ addLayoutComponent(attributes, comp);
+ }
-public Dimension
-preferredLayoutSize(
- Container parent)
-{
- Insets insets = parent.getInsets();
- measureComponents(parent);
- int w =
- insets.left + insets.right +
- tableAttributes.tableInsets.left +
- tableAttributes.tableInsets.right +
- PrefWidth;
- int h =
- insets.top + insets.bottom +
- tableAttributes.tableInsets.top +
- tableAttributes.tableInsets.bottom +
- PrefHeight;
- if (w > Short.MAX_VALUE) w = Short.MAX_VALUE;
- if (h > Short.MAX_VALUE) h = Short.MAX_VALUE;
-
- return new Dimension(w, h);
-}
+ /**
+ * Removes the specified component from the layout.
-/**
- * Calculates the maximum size dimensions for the layout given the
- * components in a parent container.
- *
- * @param parent The container parent.
- * @return The maximum layout size.
- * @see #minimumLayoutSize(Container)
- * @see #preferredLayoutSize(Container)
- */
+ * @param comp The component to be removed.
+ */
-public Dimension
-maximumLayoutSize(
- Container parent)
-{
- Insets insets = parent.getInsets();
- measureComponents(parent);
-
- // Note that the maximum size of the container is not the maximum
- // size of the table if the fill options are not used
-
- int w = Short.MAX_VALUE;
- if (tableAttributes.tableHorizontal != Attributes.FILL) {
- w = insets.left + insets.right +
- tableAttributes.tableInsets.left +
- tableAttributes.tableInsets.right +
- MaxWidth;
- if (w > Short.MAX_VALUE) w = Short.MAX_VALUE;
+ public void
+ removeLayoutComponent(
+ Component comp)
+ {
+ compAttributes.remove(comp);
+ components = null;
}
- int h = Short.MAX_VALUE;
- if (tableAttributes.tableVertical != Attributes.FILL) {
- h = insets.top + insets.bottom +
- tableAttributes.tableInsets.top +
- tableAttributes.tableInsets.bottom +
- MaxHeight;
- if (h > Short.MAX_VALUE) h = Short.MAX_VALUE;
+ /**
+ * Calculates the minimum size dimensions for the layout given the
+ * components in the a parent container.
+ *
+ * @param parent The container to be laid out.
+ * @return The minimum layout size.
+ * @see #preferredLayoutSize(Container)
+ * @see #maximumLayoutSize(Container)
+ */
+
+ public Dimension
+ minimumLayoutSize(
+ Container parent)
+ {
+ Insets insets = parent.getInsets();
+ measureComponents(parent);
+ int w =
+ insets.left + insets.right +
+ tableAttributes.tableInsets.left +
+ tableAttributes.tableInsets.right +
+ MinWidth;
+ int h =
+ insets.top + insets.bottom +
+ tableAttributes.tableInsets.top +
+ tableAttributes.tableInsets.bottom +
+ MinHeight;
+ if (w > Short.MAX_VALUE) w = Short.MAX_VALUE;
+ if (h > Short.MAX_VALUE) h = Short.MAX_VALUE;
+
+ return new Dimension(w, h);
}
- return new Dimension(w, h);
-}
-
-/**
- * Returns the alignment along the x axis. This always returns 0.5.
- *
- * @param parent The container whose alignment we want.
- * @return The alignment along the x axis.
- */
-
-public float
-getLayoutAlignmentX(
- Container parent)
-{
- return 0.5f;
-}
-
-/**
- * Returns the alignment along the y axis. This always returns 0.5.
- *
- * @param parent The container whose alignment we want.
- * @return The alignment along the y axis.
- */
-
-public float
-getLayoutAlignmentY(
- Container parent)
-{
- return 0.5f;
-}
-
-/**
- * Invalidates the layout. Cached information will be discarded.
- *
- * @param parent The container whose alignment we want.
- */
-
-public void
-invalidateLayout(
- Container parent)
-{
- useCacheMeasureResults = false;
-}
-
-/**
- * Lays out the components in the given container.
- *
- * @param parent The container which needs to be laid out.
- */
-
-public void
-layoutContainer(
- Container parent)
-{
- // Get the row and column measurements
-
- measureComponents(parent);
-
- // Get the parent insets and determine the full amount of space we
- // have available
-
- Insets insets = parent.getInsets();
- int fullWidth =
- parent.getSize().width -
- (insets.left + insets.right) -
- (tableAttributes.tableInsets.left +
- tableAttributes.tableInsets.right);
- int fullHeight = parent.getSize().height -
- (insets.top + insets.bottom) -
- (tableAttributes.tableInsets.top +
- tableAttributes.tableInsets.bottom);
-
- // We normally draw each row and column in its preferred size. If
- // we have more space, we grow the cells. If less, we shrink the
- // cells
-
- boolean shrinkWidth = fullWidth < PrefWidth;
- boolean shrinkHeight = fullHeight < PrefHeight;
-
- // Get the position and size of the table. There are three
- // possibilities for the table size:
- //
- // * The available space equals or exceeds the preferred size
- // and the table is filled - use the full space available. We
- // will expand the cells in a later step.
- //
- // * The available space equals or exceeds the preferred size
- // and the table is not filled - use the preferred size.
- //
- // * The available space is less than the preferred size - use
- // the available space. We will shrink the cells in a later
- // step.
-
- int tableX = insets.left + tableAttributes.tableInsets.left;
- int tableY = insets.top + tableAttributes.tableInsets.top;
-
- int tableWidth = PrefWidth;
- if (shrinkWidth ||
- tableAttributes.tableHorizontal == Attributes.FILL) {
- tableWidth = fullWidth;
- }
- int tableHeight = PrefHeight;
- if (shrinkHeight ||
- tableAttributes.tableVertical == Attributes.FILL) {
- tableHeight = fullHeight;
+ /**
+ * Calculates the preferred size dimensions for the layout given the
+ * components in a parent container.
+ *
+ * @param parent The container to be laid out.
+ * @return The preferred layout size.
+ * @see #minimumLayoutSize(Container)
+ * @see #maximumLayoutSize(Container)
+ */
+
+ public Dimension
+ preferredLayoutSize(
+ Container parent)
+ {
+ Insets insets = parent.getInsets();
+ measureComponents(parent);
+ int w =
+ insets.left + insets.right +
+ tableAttributes.tableInsets.left +
+ tableAttributes.tableInsets.right +
+ PrefWidth;
+ int h =
+ insets.top + insets.bottom +
+ tableAttributes.tableInsets.top +
+ tableAttributes.tableInsets.bottom +
+ PrefHeight;
+ if (w > Short.MAX_VALUE) w = Short.MAX_VALUE;
+ if (h > Short.MAX_VALUE) h = Short.MAX_VALUE;
+
+ return new Dimension(w, h);
}
- if (tableAttributes.tableHorizontal == Attributes.CENTER ||
- tableAttributes.tableHorizontal == Attributes.FILL) {
- tableX += (fullWidth - tableWidth) / 2;
- }
- else if (tableAttributes.tableHorizontal == Attributes.RIGHT) {
- tableX += fullWidth - tableWidth;
+ /**
+ * Calculates the maximum size dimensions for the layout given the
+ * components in a parent container.
+ *
+ * @param parent The container parent.
+ * @return The maximum layout size.
+ * @see #minimumLayoutSize(Container)
+ * @see #preferredLayoutSize(Container)
+ */
+
+ public Dimension
+ maximumLayoutSize(
+ Container parent)
+ {
+ Insets insets = parent.getInsets();
+ measureComponents(parent);
+
+ // Note that the maximum size of the container is not the maximum
+ // size of the table if the fill options are not used
+
+ int w = Short.MAX_VALUE;
+ if (tableAttributes.tableHorizontal != Attributes.FILL) {
+ w = insets.left + insets.right +
+ tableAttributes.tableInsets.left +
+ tableAttributes.tableInsets.right +
+ MaxWidth;
+ if (w > Short.MAX_VALUE) w = Short.MAX_VALUE;
+ }
+
+ int h = Short.MAX_VALUE;
+ if (tableAttributes.tableVertical != Attributes.FILL) {
+ h = insets.top + insets.bottom +
+ tableAttributes.tableInsets.top +
+ tableAttributes.tableInsets.bottom +
+ MaxHeight;
+ if (h > Short.MAX_VALUE) h = Short.MAX_VALUE;
+ }
+
+ return new Dimension(w, h);
}
- if (tableAttributes.tableVertical == Attributes.CENTER ||
- tableAttributes.tableVertical == Attributes.FILL) {
- tableY += (fullHeight - tableHeight) / 2;
- }
- else if (tableAttributes.tableVertical == Attributes.BOTTOM) {
- tableY += fullHeight - tableHeight;
+ /**
+ * Returns the alignment along the x axis. This always returns 0.5.
+ *
+ * @param parent The container whose alignment we want.
+ * @return The alignment along the x axis.
+ */
+
+ public float
+ getLayoutAlignmentX(
+ Container parent)
+ {
+ return 0.5f;
}
- // Now adjust the column and row cell sizes
+ /**
+ * Returns the alignment along the y axis. This always returns 0.5.
+ *
+ * @param parent The container whose alignment we want.
+ * @return The alignment along the y axis.
+ */
+
+ public float
+ getLayoutAlignmentY(
+ Container parent)
+ {
+ return 0.5f;
+ }
- adjustCellSizes(
- nCols,
- (tableAttributes.tableHorizontal == Attributes.FILL),
- shrinkWidth,
- minWidth,
- PrefWidth, prefWidth,
- fullWidth,
- ColWeight, colWeight,
- adjWidth,
- parent);
+ /**
+ * Invalidates the layout. Cached information will be discarded.
+ *
+ * @param parent The container whose alignment we want.
+ */
+
+ public void
+ invalidateLayout(
+ Container parent)
+ {
+ useCacheMeasureResults = false;
+ }
- adjustCellSizes(
- nRows,
- (tableAttributes.tableVertical == Attributes.FILL),
- shrinkHeight,
- minHeight,
- PrefHeight, prefHeight,
- fullHeight,
- RowWeight, rowWeight,
- adjHeight,
- parent);
-
- // Begin the component layout loop
-
- for (int r = 0; r < nRows; r++) {
- for (int c = 0; c < nCols; c++) {
- Component comp = components[r][c];
- if (comp == null) continue;
-
- Attributes attributes = (Attributes)compAttributes.get(comp);
-
- Dimension compMinSize = comp.getMinimumSize();
- Dimension compPrefSize = comp.getPreferredSize();
- Dimension compMaxSize = comp.getMaximumSize();
-
- // Base position
-
- int compX =
- tableX +
- (tableAttributes.cGap * c) +
- attributes.cellInsets.left;
- for (int i = 0; i < c; i++) compX += adjWidth[i];
-
- int compY =
- tableY +
- (tableAttributes.rGap * r) +
- attributes.cellInsets.top;
- for (int i = 0; i < r; i++) compY += adjHeight[i];
-
- // Get the cell size. This has to take into account row
- // and column spanning
-
- int cellWidth = adjWidth[c];
- for (int i = 1; i < attributes.cSpan; i++) {
- cellWidth += tableAttributes.cGap + adjWidth[c + i];
- }
-
- int cellHeight = adjHeight[r];
- for (int i = 1; i < attributes.rSpan; i++) {
- cellHeight += tableAttributes.rGap + adjHeight[r + i];
- }
-
- int insetCellWidth =
- cellWidth -
- attributes.cellInsets.left - attributes.cellInsets.right;
- int insetCellHeight =
- cellHeight -
- attributes.cellInsets.top - attributes.cellInsets.bottom;
-
- // Get the component size. Use the preferred size, if
- // possible. If not use the cell size minus insets
-
- int compWidth = compPrefSize.width;
- int compHeight = compPrefSize.height;
- if (compWidth > insetCellWidth) compWidth = insetCellWidth;
- if (compHeight > insetCellHeight) compHeight = insetCellHeight;
-
- // Adjust for fill
-
- if (attributes.horizontal == Attributes.FILL) {
- compWidth = insetCellWidth;
- compWidth = Math.max(compWidth, compMinSize.width);
- // Some components (like JButton) can exceed their max size
- // compWidth = Math.min(compWidth, compMaxSize.width);
- }
- if (attributes.vertical == Attributes.FILL) {
- compHeight = insetCellHeight;
- compHeight = Math.max(compHeight, compMinSize.height);
- // Some components (like JButton) can exceed their max size
- // compHeight = Math.min(compHeight, compMaxSize.height);
- }
-
- // Position properly. We treat FILL like CENTER since
- // the min/max limits may have prevented us from really
- // filling
-
- if (attributes.horizontal == Attributes.CENTER ||
- attributes.horizontal == Attributes.FILL) {
- compX += (cellWidth -
- (attributes.cellInsets.left +
- attributes.cellInsets.right) - compWidth) / 2;
- }
- else if (attributes.horizontal == Attributes.RIGHT) {
- compX += (cellWidth -
- (attributes.cellInsets.left +
- attributes.cellInsets.right) - compWidth);
- }
-
- if (attributes.vertical == Attributes.CENTER ||
- attributes.vertical == Attributes.FILL) {
- compY += (cellHeight -
- (attributes.cellInsets.top +
- attributes.cellInsets.bottom) - compHeight) / 2;
- }
- else if (attributes.vertical == Attributes.BOTTOM) {
- compY += (cellHeight -
- (attributes.cellInsets.top +
- attributes.cellInsets.bottom) - compHeight);
- }
-
- // Place the component
-
- comp.setBounds(compX, compY, compWidth, compHeight);
-
- // DEBUG
+ /**
+ * Lays out the components in the given container.
+ *
+ * @param parent The container which needs to be laid out.
+ */
+
+ public void
+ layoutContainer(
+ Container parent)
+ {
+ // Get the row and column measurements
+
+ measureComponents(parent);
+
+ // Get the parent insets and determine the full amount of space we
+ // have available
+
+ Insets insets = parent.getInsets();
+ int fullWidth =
+ parent.getSize().width -
+ (insets.left + insets.right) -
+ (tableAttributes.tableInsets.left +
+ tableAttributes.tableInsets.right);
+ int fullHeight = parent.getSize().height -
+ (insets.top + insets.bottom) -
+ (tableAttributes.tableInsets.top +
+ tableAttributes.tableInsets.bottom);
+
+ // We normally draw each row and column in its preferred size. If
+ // we have more space, we grow the cells. If less, we shrink the
+ // cells
+
+ boolean shrinkWidth = fullWidth < PrefWidth;
+ boolean shrinkHeight = fullHeight < PrefHeight;
+
+ // Get the position and size of the table. There are three
+ // possibilities for the table size:
+ //
+ // * The available space equals or exceeds the preferred size
+ // and the table is filled - use the full space available. We
+ // will expand the cells in a later step.
+ //
+ // * The available space equals or exceeds the preferred size
+ // and the table is not filled - use the preferred size.
+ //
+ // * The available space is less than the preferred size - use
+ // the available space. We will shrink the cells in a later
+ // step.
+
+ int tableX = insets.left + tableAttributes.tableInsets.left;
+ int tableY = insets.top + tableAttributes.tableInsets.top;
+
+ int tableWidth = PrefWidth;
+ if (shrinkWidth ||
+ tableAttributes.tableHorizontal == Attributes.FILL) {
+ tableWidth = fullWidth;
+ }
+ int tableHeight = PrefHeight;
+ if (shrinkHeight ||
+ tableAttributes.tableVertical == Attributes.FILL) {
+ tableHeight = fullHeight;
+ }
+
+ if (tableAttributes.tableHorizontal == Attributes.CENTER ||
+ tableAttributes.tableHorizontal == Attributes.FILL) {
+ tableX += (fullWidth - tableWidth) / 2;
+ }
+ else if (tableAttributes.tableHorizontal == Attributes.RIGHT) {
+ tableX += fullWidth - tableWidth;
+ }
+
+ if (tableAttributes.tableVertical == Attributes.CENTER ||
+ tableAttributes.tableVertical == Attributes.FILL) {
+ tableY += (fullHeight - tableHeight) / 2;
+ }
+ else if (tableAttributes.tableVertical == Attributes.BOTTOM) {
+ tableY += fullHeight - tableHeight;
+ }
+
+ // Now adjust the column and row cell sizes
+
+ adjustCellSizes(
+ nCols,
+ (tableAttributes.tableHorizontal == Attributes.FILL),
+ shrinkWidth,
+ minWidth,
+ PrefWidth, prefWidth,
+ fullWidth,
+ ColWeight, colWeight,
+ adjWidth,
+ parent);
+
+ adjustCellSizes(
+ nRows,
+ (tableAttributes.tableVertical == Attributes.FILL),
+ shrinkHeight,
+ minHeight,
+ PrefHeight, prefHeight,
+ fullHeight,
+ RowWeight, rowWeight,
+ adjHeight,
+ parent);
+
+ // Begin the component layout loop
+
+ for (int r = 0; r < nRows; r++) {
+ for (int c = 0; c < nCols; c++) {
+ Component comp = components[r][c];
+ if (comp == null) continue;
+
+ Attributes attributes = (Attributes)compAttributes.get(comp);
+
+ Dimension compMinSize = comp.getMinimumSize();
+ Dimension compPrefSize = comp.getPreferredSize();
+ Dimension compMaxSize = comp.getMaximumSize();
+
+ // Base position
+
+ int compX =
+ tableX +
+ (tableAttributes.cGap * c) +
+ attributes.cellInsets.left;
+ for (int i = 0; i < c; i++) compX += adjWidth[i];
+
+ int compY =
+ tableY +
+ (tableAttributes.rGap * r) +
+ attributes.cellInsets.top;
+ for (int i = 0; i < r; i++) compY += adjHeight[i];
+
+ // Get the cell size. This has to take into account row
+ // and column spanning
+
+ int cellWidth = adjWidth[c];
+ for (int i = 1; i < attributes.cSpan; i++) {
+ cellWidth += tableAttributes.cGap + adjWidth[c + i];
+ }
+
+ int cellHeight = adjHeight[r];
+ for (int i = 1; i < attributes.rSpan; i++) {
+ cellHeight += tableAttributes.rGap + adjHeight[r + i];
+ }
+
+ int insetCellWidth =
+ cellWidth -
+ attributes.cellInsets.left - attributes.cellInsets.right;
+ int insetCellHeight =
+ cellHeight -
+ attributes.cellInsets.top - attributes.cellInsets.bottom;
+
+ // Get the component size. Use the preferred size, if
+ // possible. If not use the cell size minus insets
+
+ int compWidth = compPrefSize.width;
+ int compHeight = compPrefSize.height;
+ if (compWidth > insetCellWidth) compWidth = insetCellWidth;
+ if (compHeight > insetCellHeight) compHeight = insetCellHeight;
+
+ // Adjust for fill
+
+ if (attributes.horizontal == Attributes.FILL) {
+ compWidth = insetCellWidth;
+ compWidth = Math.max(compWidth, compMinSize.width);
+ // Some components (like JButton) can exceed their max size
+ // compWidth = Math.min(compWidth, compMaxSize.width);
+ }
+ if (attributes.vertical == Attributes.FILL) {
+ compHeight = insetCellHeight;
+ compHeight = Math.max(compHeight, compMinSize.height);
+ // Some components (like JButton) can exceed their max size
+ // compHeight = Math.min(compHeight, compMaxSize.height);
+ }
+
+ // Position properly. We treat FILL like CENTER since
+ // the min/max limits may have prevented us from really
+ // filling
+
+ if (attributes.horizontal == Attributes.CENTER ||
+ attributes.horizontal == Attributes.FILL) {
+ compX += (cellWidth -
+ (attributes.cellInsets.left +
+ attributes.cellInsets.right) - compWidth) / 2;
+ }
+ else if (attributes.horizontal == Attributes.RIGHT) {
+ compX += (cellWidth -
+ (attributes.cellInsets.left +
+ attributes.cellInsets.right) - compWidth);
+ }
+
+ if (attributes.vertical == Attributes.CENTER ||
+ attributes.vertical == Attributes.FILL) {
+ compY += (cellHeight -
+ (attributes.cellInsets.top +
+ attributes.cellInsets.bottom) - compHeight) / 2;
+ }
+ else if (attributes.vertical == Attributes.BOTTOM) {
+ compY += (cellHeight -
+ (attributes.cellInsets.top +
+ attributes.cellInsets.bottom) - compHeight);
+ }
+
+ // Place the component
+
+ comp.setBounds(compX, compY, compWidth, compHeight);
+
+ // DEBUG
// if ("DEBUG".equals(parent.getName())) {
// System.out.println("Placing component " +
@@ -828,9 +828,9 @@ layoutContainer(
// " (" + compX + ", " + compY + ") " +
// compWidth + " x " + compHeight);
// }
- }
+ }
+ }
}
-}
// The inherited toString() method is acceptable.
@@ -838,160 +838,162 @@ layoutContainer(
// Private
//**********************************************************************
-/**
- * The row or column sizes need to be adjusted. We may want to grow
- * or shrink the sizes, based on whether the available space is larger
- * or smaller than the preferred size.
- * <p>
- * If we grow the table, we pay attention to the user's weighting
- * factors. If we shrink the table, we assign all cells a weight
- * factor of 1.
- *
- * @param nCells The number of cells in the row or column.
- * @param fill True if the table rows or columns should fill the
- * available space.
- * @param shrink True if the available size is less than the preferred
- * size.
- * @param minSize The minimum sizes of each row or column.
- * @param PrefSize The sum of the preferred sizes of all cells in the
- * row or column plus any cell gaps.
- * @param prefSize The preferred sizes of each row or column.
- * @param CellWeight The sum of all cell weights in the row or column.
- * @param cellWeight The weight of each row or column.
- * @param adjSize The adjusted size of each row or column. The
- * contents of this array are set and returned.
- */
-
-private void
-adjustCellSizes(
- int nCells,
- boolean fill,
- boolean shrink,
- int[] minSize,
- int PrefSize,
- int[] prefSize,
- int fullSize,
- int CellWeight,
- int[] cellWeight,
- int[] adjSize,
- Container parent)
-
-{
- // The sum of the weights (CellWeight) determines how many units
- // any excess (or reduced) space should be divided into. The
- // unitOfSpace variable is the size of each unit.
- //
- // We use weighting under two conditions:
- //
- // * We are shrinking the table.
- //
- // * We have more space than we need and the user asked us to
- // fill the available space
- //
- // When we have more than enough space for the preferred row and
- // column sizes, we follow the user's weighting. There is a
- // special case if all weights are 0: the weights are treated as
- // thought they were all 1.
- //
- // When do not have enough space, we weight everything the same.
-
- double unitOfSpace = 0.0;
- if (shrink || fill) {
- unitOfSpace =
- (double)(fullSize - PrefSize) /
- (double)((shrink || CellWeight == 0) ? nCells : CellWeight);
- }
- else {
- // No adjustment needed: use the preferred sizes
-
- for (int i = 0; i < nCells; i++) {
- adjSize[i] = prefSize[i];
- }
- return;
- }
-
- double extraSpace; int iExtraSpace;
- double error = 0.0; int iError = -999999;
-
- int adjWeight;
-
- for (int i = 0; i < nCells; i++) {
-
- // Initialize the adjusted size to the preferred size
-
- adjSize[i] = prefSize[i];
-
- // Get the cell weight based on various conditions
-
- adjWeight = (shrink || CellWeight == 0) ? 1 : cellWeight[i];
-
- // Determine how much extra space to give each cell. The space
- // is the weight (number of units) times the unit size. We can
- // only assign an integer number of pixels, which creates a
- // fractional error
-
- extraSpace = unitOfSpace * adjWeight;
- iExtraSpace = (int)extraSpace;
- adjSize[i] += iExtraSpace;
-
- error += extraSpace - iExtraSpace;
- iError = (int)error;
-
- // Increment/decrement this cell by the accumulated integer
- // error, if it's not 0
-
- if (shrink) {
- if (iError < 0) {
- adjSize[i] += iError;
- }
- }
- else {
- if (iError > 0) {
- adjSize[i] += iError;
- }
- }
- error -= iError;
-
- // If we're shrinking, we need to prevent any cell from
- // shrinking below its minimum size. The error is adjusted to
- // include the space added to the cell
-
- if (shrink && (adjSize[i] < minSize[i])) {
- error -= minSize[i] - adjSize[i];
- adjSize[i] = minSize[i];
- }
-
- iError = (int)error;
- }
-
- // If we are growing, the error should be less than 1 pixel. If we
- // are shrinking, we limit each cell to its minimum size, so we
- // can accumulate larger errors as cells refuse to shrink. So we
- // distribute the error to cells that can still shrink. We repeat
- // this until we've reduced the error to 0 or we're unable to
- // shrink the error anymore.
- //
- // Remember that iError is a negative number
-
- if (shrink || iError < 0) {
- int lastIError;
-
- do {
- lastIError = iError;
- for (int i = 0; i < nCells; i++) {
-
- // If the cell is already at its minimum size, skip it
-
- if (adjSize[i] > minSize[i]) {
- adjSize[i]--;
- iError++;
- }
- }
- }
- while (iError < 0 && iError > lastIError);
- }
-
- // DEBUG
+ /**
+ * The row or column sizes need to be adjusted. We may want to grow
+ * or shrink the sizes, based on whether the available space is larger
+ * or smaller than the preferred size.
+ * <p>
+ * If we grow the table, we pay attention to the user's weighting
+ * factors. If we shrink the table, we assign all cells a weight
+ * factor of 1.
+ *
+ * @param nCells The number of cells in the row or column.
+ * @param fill True if the table rows or columns should fill the
+ * available space.
+ * @param shrink True if the available size is less than the preferred
+ * size.
+ * @param minSize The minimum sizes of each row or column.
+ * @param PrefSize The sum of the preferred sizes of all cells in the
+ * row or column plus any cell gaps.
+ * @param prefSize The preferred sizes of each row or column.
+ * @param CellWeight The sum of all cell weights in the row or column.
+ * @param cellWeight The weight of each row or column.
+ * @param adjSize The adjusted size of each row or column. The
+ * contents of this array are set and returned.
+ */
+
+ private void
+ adjustCellSizes(
+ int nCells,
+ boolean fill,
+ boolean shrink,
+ int[] minSize,
+ int PrefSize,
+ int[] prefSize,
+ int fullSize,
+ int CellWeight,
+ int[] cellWeight,
+ int[] adjSize,
+ Container parent)
+
+ {
+ // The sum of the weights (CellWeight) determines how many units
+ // any excess (or reduced) space should be divided into. The
+ // unitOfSpace variable is the size of each unit.
+ //
+ // We use weighting under two conditions:
+ //
+ // * We are shrinking the table.
+ //
+ // * We have more space than we need and the user asked us to
+ // fill the available space
+ //
+ // When we have more than enough space for the preferred row and
+ // column sizes, we follow the user's weighting. There is a
+ // special case if all weights are 0: the weights are treated as
+ // thought they were all 1.
+ //
+ // When do not have enough space, we weight everything the same.
+
+ double unitOfSpace = 0.0;
+ if (shrink || fill) {
+ unitOfSpace =
+ (double)(fullSize - PrefSize) /
+ (double)((shrink || CellWeight == 0) ? nCells : CellWeight);
+ }
+ else {
+ // No adjustment needed: use the preferred sizes
+
+ for (int i = 0; i < nCells; i++) {
+ adjSize[i] = prefSize[i];
+ }
+ return;
+ }
+
+ double extraSpace;
+ int iExtraSpace;
+ double error = 0.0;
+ int iError = -999999;
+
+ int adjWeight;
+
+ for (int i = 0; i < nCells; i++) {
+
+ // Initialize the adjusted size to the preferred size
+
+ adjSize[i] = prefSize[i];
+
+ // Get the cell weight based on various conditions
+
+ adjWeight = (shrink || CellWeight == 0) ? 1 : cellWeight[i];
+
+ // Determine how much extra space to give each cell. The space
+ // is the weight (number of units) times the unit size. We can
+ // only assign an integer number of pixels, which creates a
+ // fractional error
+
+ extraSpace = unitOfSpace * adjWeight;
+ iExtraSpace = (int)extraSpace;
+ adjSize[i] += iExtraSpace;
+
+ error += extraSpace - iExtraSpace;
+ iError = (int)error;
+
+ // Increment/decrement this cell by the accumulated integer
+ // error, if it's not 0
+
+ if (shrink) {
+ if (iError < 0) {
+ adjSize[i] += iError;
+ }
+ }
+ else {
+ if (iError > 0) {
+ adjSize[i] += iError;
+ }
+ }
+ error -= iError;
+
+ // If we're shrinking, we need to prevent any cell from
+ // shrinking below its minimum size. The error is adjusted to
+ // include the space added to the cell
+
+ if (shrink && (adjSize[i] < minSize[i])) {
+ error -= minSize[i] - adjSize[i];
+ adjSize[i] = minSize[i];
+ }
+
+ iError = (int)error;
+ }
+
+ // If we are growing, the error should be less than 1 pixel. If we
+ // are shrinking, we limit each cell to its minimum size, so we
+ // can accumulate larger errors as cells refuse to shrink. So we
+ // distribute the error to cells that can still shrink. We repeat
+ // this until we've reduced the error to 0 or we're unable to
+ // shrink the error anymore.
+ //
+ // Remember that iError is a negative number
+
+ if (shrink || iError < 0) {
+ int lastIError;
+
+ do {
+ lastIError = iError;
+ for (int i = 0; i < nCells; i++) {
+
+ // If the cell is already at its minimum size, skip it
+
+ if (adjSize[i] > minSize[i]) {
+ adjSize[i]--;
+ iError++;
+ }
+ }
+ }
+ while (iError < 0 && iError > lastIError);
+ }
+
+ // DEBUG
// if ("DEBUG".equals(parent.getName())) {
// System.out.println(" iError " + iError);
@@ -999,130 +1001,130 @@ adjustCellSizes(
// System.out.println(" " + i + ") Adjusted size = " + adjSize[i]);
// }
// }
-}
+ }
-/**
- * For each component, determine its row/col position and place it in
- * an array for easy access later. Elements spanning multiple rows
- * and/or columns are placed in the NW row/col slot in the array.
- * Results are placed in class fields.
- *
- * @param parent The parent container.
- */
+ /**
+ * For each component, determine its row/col position and place it in
+ * an array for easy access later. Elements spanning multiple rows
+ * and/or columns are placed in the NW row/col slot in the array.
+ * Results are placed in class fields.
+ *
+ * @param parent The parent container.
+ */
-private void
-placeComponents(
- Container parent)
-{
- // If we haven't added or removed a component since the last time
- // placeComponents() was called, we assume the current results are
- // OK
+ private void
+ placeComponents(
+ Container parent)
+ {
+ // If we haven't added or removed a component since the last time
+ // placeComponents() was called, we assume the current results are
+ // OK
- if (components != null) return;
+ if (components != null) return;
+
+ int compCount = parent.getComponentCount();
- int compCount = parent.getComponentCount();
+ // Get the number of columns specified by the user
- // Get the number of columns specified by the user
+ nCols = tableAttributes.columns;
- nCols = tableAttributes.columns;
+ // Create the array of components
- // Create the array of components
+ CompArray compArray = new CompArray(tableAttributes.columns, compCount);
- CompArray compArray = new CompArray(tableAttributes.columns, compCount);
+ // Fill the array with components, taking row/column spanning
+ // into account
- // Fill the array with components, taking row/column spanning
- // into account
+ int row = 0;
+ int col = 0;
- int row = 0;
- int col = 0;
+ for (int i = 0; i < compCount; i++) {
- for (int i = 0; i < compCount; i++) {
+ // Get the next component and its options
- // Get the next component and its options
+ Component comp = parent.getComponent(i);
+ Attributes attributes = (Attributes)compAttributes.get(comp);
- Component comp = parent.getComponent(i);
- Attributes attributes = (Attributes)compAttributes.get(comp);
+ // If the column span is greater than the column size,
+ // truncate it to the column size
- // If the column span is greater than the column size,
- // truncate it to the column size
+ attributes.cSpan = attributes.originalCSpan;
+ if (attributes.cSpan > tableAttributes.columns) {
+ attributes.cSpan = tableAttributes.columns;
- attributes.cSpan = attributes.originalCSpan;
- if (attributes.cSpan > tableAttributes.columns) {
- attributes.cSpan = tableAttributes.columns;
+ }
+ // Handle options to force us to column 0 or to skip columns
- }
- // Handle options to force us to column 0 or to skip columns
+ if (attributes.column != Attributes.NEXT_COLUMN) {
+ if (col > attributes.column) row++;
+ col = attributes.column;
+ }
+ col += attributes.skip;
+ if (col >= nCols) {
+ row++;
+ col = 0;
+ }
- if (attributes.column != Attributes.NEXT_COLUMN) {
- if (col > attributes.column) row++;
- col = attributes.column;
- }
- col += attributes.skip;
- if (col >= nCols) {
- row++;
- col = 0;
- }
+ // Skip over any cells that are already occupied
- // Skip over any cells that are already occupied
+ while (compArray.get(row, col) != null) {
+ col++;
+ if (col >= nCols) {
+ row++;
+ col = 0;
+ }
+ }
- while (compArray.get(row, col) != null) {
- col++;
- if (col >= nCols) {
- row++;
- col = 0;
- }
- }
+ // If spanning multiple columns, will we fit on this row?
- // If spanning multiple columns, will we fit on this row?
+ if (col + attributes.cSpan > nCols) {
+ row++;
+ col = 0;
+ }
- if (col + attributes.cSpan > nCols) {
- row++;
- col = 0;
- }
+ // For now, fill all the cells that are occupied by this
+ // component
- // For now, fill all the cells that are occupied by this
- // component
+ for (int c = 0; c < attributes.cSpan; c++) {
+ for (int r = 0; r < attributes.rSpan; r++) {
+ compArray.set(row + r, col + c, comp);
+ }
+ }
- for (int c = 0; c < attributes.cSpan; c++) {
- for (int r = 0; r < attributes.rSpan; r++) {
- compArray.set(row + r, col + c, comp);
- }
- }
+ // Advance to the next cell, ready for the next component
- // Advance to the next cell, ready for the next component
+ col += attributes.cSpan;
+ if (col >= nCols) {
+ row++;
+ col = 0;
+ }
+ }
- col += attributes.cSpan;
- if (col >= nCols) {
- row++;
- col = 0;
- }
- }
+ // Now we know how many rows there are. We can use a normal,
+ // properly sized array from now on. The array returned includes
+ // the maximum row into which anything was entered, including any
+ // row spans
- // Now we know how many rows there are. We can use a normal,
- // properly sized array from now on. The array returned includes
- // the maximum row into which anything was entered, including any
- // row spans
-
- components = compArray.getArray();
- nRows = components.length;
-
- // Now we've positioned our components we can thin out the cells so
- // we only remember the top left corner of each component
-
- for (row = 0; row < nRows; row++) {
- for (col = 0; col < nCols; col++) {
- Component comp = components[row][col];
- for (int r = row; r < nRows && components[r][col] == comp; r++) {
- for (int c = col; c < nCols && components[r][c] == comp; c++) {
- if (r > row || c > col) {
- components[r][c] = null;
- }
- }
- }
- }
- }
+ components = compArray.getArray();
+ nRows = components.length;
+
+ // Now we've positioned our components we can thin out the cells so
+ // we only remember the top left corner of each component
+
+ for (row = 0; row < nRows; row++) {
+ for (col = 0; col < nCols; col++) {
+ Component comp = components[row][col];
+ for (int r = row; r < nRows && components[r][col] == comp; r++) {
+ for (int c = col; c < nCols && components[r][c] == comp; c++) {
+ if (r > row || c > col) {
+ components[r][c] = null;
+ }
+ }
+ }
+ }
+ }
- // DEBUG
+ // DEBUG
// if ("DEBUG".equals(parent.getName())) {
// System.out.println("placeComponents finished: rows = " +
@@ -1137,246 +1139,246 @@ placeComponents(
// }
// }
// }
-}
-
-/**
- * In this method, we will determine the minimum, preferred and
- * maximum sizes of the components as layed out by the table layout
- * manager
- *
- * @param parent The parent container.
- */
-
-private void
-measureComponents(
- Container parent)
-{
- if (useCacheMeasureResults) return;
-
- // Determine the row/col positions for the components
-
- placeComponents(parent);
-
- // Allocate new arrays to store row and column preferred and min
- // sizes, but only if the old arrays aren't big enough
-
- if (minWidth == null || minWidth.length < nCols) {
- minWidth = new int[nCols];
- prefWidth = new int[nCols];
- maxWidth = new int[nCols];
- adjWidth = new int[nCols];
- colWeight = new int[nCols];
- }
- if (minHeight == null || minHeight.length < nRows) {
- minHeight = new int[nRows];
- prefHeight = new int[nRows];
- maxHeight = new int[nRows];
- adjHeight = new int[nRows];
- rowWeight = new int[nRows];
- }
-
- for (int i = 0; i < nCols; i++) {
- minWidth[i] = 0;
- prefWidth[i] = 0;
- maxWidth[i] = 0;
- colWeight[i] = 0;
- }
- for (int i = 0; i < nRows; i++) {
- minHeight[i] = 0;
- prefHeight[i] = 0;
- maxHeight[i] = 0;
- rowWeight[i] = 0;
- }
-
- // Measure the minimum and preferred size of each row and column
-
- for (int row = 0; row < nRows; row++) {
- for (int col = 0; col < nCols; col++) {
- Component comp = components[row][col];
- if (comp != null) {
- Attributes attributes = (Attributes)compAttributes.get(comp);
-
- Dimension minSize = new Dimension(comp.getMinimumSize());
- Dimension prefSize = new Dimension(comp.getPreferredSize());
- Dimension maxSize = new Dimension(comp.getMaximumSize());
-
- // Add the cell insets
-
- minSize.width +=
- attributes.cellInsets.left + attributes.cellInsets.right;
- minSize.height +=
- attributes.cellInsets.top + attributes.cellInsets.bottom;
- prefSize.width +=
- attributes.cellInsets.left + attributes.cellInsets.right;
- prefSize.height +=
- attributes.cellInsets.top + attributes.cellInsets.bottom;
- maxSize.width +=
- attributes.cellInsets.left + attributes.cellInsets.right;
- maxSize.height +=
- attributes.cellInsets.right + attributes.cellInsets.bottom;
-
- // Make sure that 0 <= minSize <= prefSize <= maxSize
-
- limitDimension(minSize, new Dimension(0, 0));
- limitDimension(prefSize, minSize);
- limitDimension(maxSize, prefSize);
-
- // First pass, we determine the sizes while ignoring
- // components which span columns or rows
-
- if (attributes.cSpan == 1) {
- minWidth[col] =
- Math.max(minSize.width, minWidth[col]);
- prefWidth[col] =
- Math.max(prefSize.width, prefWidth[col]);
- maxWidth[col] =
- Math.max(maxSize.width, maxWidth[col]);
- }
-
- if (attributes.rSpan == 1) {
- minHeight[row] =
- Math.max(minSize.height, minHeight[row]);
- prefHeight[row] =
- Math.max(prefSize.height, prefHeight[row]);
- maxHeight[row] =
- Math.max(maxSize.height, maxHeight[row]);
- }
-
- // Get the row and column weights. The weight is the
- // maximum value for the row or column
-
- if (attributes.cWeight > colWeight[col]) {
- colWeight[col] = attributes.cWeight;
- }
- if (attributes.rWeight > rowWeight[row]) {
- rowWeight[row] = attributes.rWeight;
- }
- }
- }
- }
-
- // Do it again, but just for components which span multiple cells.
- //
-
- for (int row = 0; row < nRows; row++) {
- for (int col = 0; col < nCols; col++) {
- Component comp = components[row][col];
- if (comp != null) {
- Attributes attributes = (Attributes)compAttributes.get(comp);
-
- if (attributes.rSpan == 1 && attributes.cSpan == 1) continue;
-
- Dimension minSize = new Dimension(comp.getMinimumSize());
- Dimension prefSize = new Dimension(comp.getPreferredSize());
- Dimension maxSize = new Dimension(comp.getMaximumSize());
-
- // Add the cell insets
-
- minSize.width +=
- attributes.cellInsets.top + attributes.cellInsets.bottom;
- minSize.height +=
- attributes.cellInsets.left + attributes.cellInsets.right;
- prefSize.width +=
- attributes.cellInsets.top + attributes.cellInsets.bottom;
- prefSize.height +=
- attributes.cellInsets.left + attributes.cellInsets.right;
- maxSize.width +=
- attributes.cellInsets.top + attributes.cellInsets.bottom;
- maxSize.height +=
- attributes.cellInsets.left + attributes.cellInsets.right;
-
- // Make sure that 0 <= minSize <= prefSize <= maxSize
-
- limitDimension(minSize, new Dimension(0, 0));
- limitDimension(prefSize, minSize);
- limitDimension(maxSize, prefSize);
-
- if (attributes.cSpan > 1) {
- adjustForSpans(col,
- minSize.width,
- minWidth,
- colWeight,
- attributes.cSpan,
- tableAttributes.cGap);
- adjustForSpans(col,
- prefSize.width,
- prefWidth,
- colWeight,
- attributes.cSpan,
- tableAttributes.cGap);
- adjustForSpans(col,
- maxSize.width,
- maxWidth,
- colWeight,
- attributes.cSpan,
- tableAttributes.cGap);
- }
-
- if (attributes.rSpan > 1) {
- adjustForSpans(row,
- minSize.height,
- minHeight,
- rowWeight,
- attributes.rSpan,
- tableAttributes.rGap);
- adjustForSpans(row,
- prefSize.height,
- prefHeight,
- rowWeight,
- attributes.rSpan,
- tableAttributes.rGap);
- adjustForSpans(row,
- maxSize.height,
- maxHeight,
- rowWeight,
- attributes.rSpan,
- tableAttributes.rGap);
- }
- }
- }
- }
-
- // Add up all the individual values
-
- MinWidth = 0;
- MinHeight = 0;
- PrefWidth = 0;
- PrefHeight = 0;
- MaxWidth = 0;
- MaxHeight = 0;
- ColWeight = 0;
- RowWeight = 0;
-
- // Sum up everything
-
- for (int i = 0; i < nCols; i++) {
- MinWidth += minWidth[i];
- PrefWidth += prefWidth[i];
- MaxWidth += maxWidth[i];
- ColWeight += colWeight[i];
- }
-
- for (int i = 0; i < nRows; i++) {
- MinHeight += minHeight[i];
- PrefHeight += prefHeight[i];
- MaxHeight += maxHeight[i];
- RowWeight += rowWeight[i];
}
- // Add in the table gaps
-
- int cExtra = tableAttributes.cGap * (nCols - 1);
- int rExtra = tableAttributes.rGap * (nRows - 1);
-
- MinWidth += cExtra;
- PrefWidth += cExtra;
- MaxWidth += cExtra;
-
- MinHeight += rExtra;
- PrefHeight += rExtra;
- MaxHeight += rExtra;
-
- // DEBUG
+ /**
+ * In this method, we will determine the minimum, preferred and
+ * maximum sizes of the components as layed out by the table layout
+ * manager
+ *
+ * @param parent The parent container.
+ */
+
+ private void
+ measureComponents(
+ Container parent)
+ {
+ if (useCacheMeasureResults) return;
+
+ // Determine the row/col positions for the components
+
+ placeComponents(parent);
+
+ // Allocate new arrays to store row and column preferred and min
+ // sizes, but only if the old arrays aren't big enough
+
+ if (minWidth == null || minWidth.length < nCols) {
+ minWidth = new int[nCols];
+ prefWidth = new int[nCols];
+ maxWidth = new int[nCols];
+ adjWidth = new int[nCols];
+ colWeight = new int[nCols];
+ }
+ if (minHeight == null || minHeight.length < nRows) {
+ minHeight = new int[nRows];
+ prefHeight = new int[nRows];
+ maxHeight = new int[nRows];
+ adjHeight = new int[nRows];
+ rowWeight = new int[nRows];
+ }
+
+ for (int i = 0; i < nCols; i++) {
+ minWidth[i] = 0;
+ prefWidth[i] = 0;
+ maxWidth[i] = 0;
+ colWeight[i] = 0;
+ }
+ for (int i = 0; i < nRows; i++) {
+ minHeight[i] = 0;
+ prefHeight[i] = 0;
+ maxHeight[i] = 0;
+ rowWeight[i] = 0;
+ }
+
+ // Measure the minimum and preferred size of each row and column
+
+ for (int row = 0; row < nRows; row++) {
+ for (int col = 0; col < nCols; col++) {
+ Component comp = components[row][col];
+ if (comp != null) {
+ Attributes attributes = (Attributes)compAttributes.get(comp);
+
+ Dimension minSize = new Dimension(comp.getMinimumSize());
+ Dimension prefSize = new Dimension(comp.getPreferredSize());
+ Dimension maxSize = new Dimension(comp.getMaximumSize());
+
+ // Add the cell insets
+
+ minSize.width +=
+ attributes.cellInsets.left + attributes.cellInsets.right;
+ minSize.height +=
+ attributes.cellInsets.top + attributes.cellInsets.bottom;
+ prefSize.width +=
+ attributes.cellInsets.left + attributes.cellInsets.right;
+ prefSize.height +=
+ attributes.cellInsets.top + attributes.cellInsets.bottom;
+ maxSize.width +=
+ attributes.cellInsets.left + attributes.cellInsets.right;
+ maxSize.height +=
+ attributes.cellInsets.right + attributes.cellInsets.bottom;
+
+ // Make sure that 0 <= minSize <= prefSize <= maxSize
+
+ limitDimension(minSize, new Dimension(0, 0));
+ limitDimension(prefSize, minSize);
+ limitDimension(maxSize, prefSize);
+
+ // First pass, we determine the sizes while ignoring
+ // components which span columns or rows
+
+ if (attributes.cSpan == 1) {
+ minWidth[col] =
+ Math.max(minSize.width, minWidth[col]);
+ prefWidth[col] =
+ Math.max(prefSize.width, prefWidth[col]);
+ maxWidth[col] =
+ Math.max(maxSize.width, maxWidth[col]);
+ }
+
+ if (attributes.rSpan == 1) {
+ minHeight[row] =
+ Math.max(minSize.height, minHeight[row]);
+ prefHeight[row] =
+ Math.max(prefSize.height, prefHeight[row]);
+ maxHeight[row] =
+ Math.max(maxSize.height, maxHeight[row]);
+ }
+
+ // Get the row and column weights. The weight is the
+ // maximum value for the row or column
+
+ if (attributes.cWeight > colWeight[col]) {
+ colWeight[col] = attributes.cWeight;
+ }
+ if (attributes.rWeight > rowWeight[row]) {
+ rowWeight[row] = attributes.rWeight;
+ }
+ }
+ }
+ }
+
+ // Do it again, but just for components which span multiple cells.
+ //
+
+ for (int row = 0; row < nRows; row++) {
+ for (int col = 0; col < nCols; col++) {
+ Component comp = components[row][col];
+ if (comp != null) {
+ Attributes attributes = (Attributes)compAttributes.get(comp);
+
+ if (attributes.rSpan == 1 && attributes.cSpan == 1) continue;
+
+ Dimension minSize = new Dimension(comp.getMinimumSize());
+ Dimension prefSize = new Dimension(comp.getPreferredSize());
+ Dimension maxSize = new Dimension(comp.getMaximumSize());
+
+ // Add the cell insets
+
+ minSize.width +=
+ attributes.cellInsets.top + attributes.cellInsets.bottom;
+ minSize.height +=
+ attributes.cellInsets.left + attributes.cellInsets.right;
+ prefSize.width +=
+ attributes.cellInsets.top + attributes.cellInsets.bottom;
+ prefSize.height +=
+ attributes.cellInsets.left + attributes.cellInsets.right;
+ maxSize.width +=
+ attributes.cellInsets.top + attributes.cellInsets.bottom;
+ maxSize.height +=
+ attributes.cellInsets.left + attributes.cellInsets.right;
+
+ // Make sure that 0 <= minSize <= prefSize <= maxSize
+
+ limitDimension(minSize, new Dimension(0, 0));
+ limitDimension(prefSize, minSize);
+ limitDimension(maxSize, prefSize);
+
+ if (attributes.cSpan > 1) {
+ adjustForSpans(col,
+ minSize.width,
+ minWidth,
+ colWeight,
+ attributes.cSpan,
+ tableAttributes.cGap);
+ adjustForSpans(col,
+ prefSize.width,
+ prefWidth,
+ colWeight,
+ attributes.cSpan,
+ tableAttributes.cGap);
+ adjustForSpans(col,
+ maxSize.width,
+ maxWidth,
+ colWeight,
+ attributes.cSpan,
+ tableAttributes.cGap);
+ }
+
+ if (attributes.rSpan > 1) {
+ adjustForSpans(row,
+ minSize.height,
+ minHeight,
+ rowWeight,
+ attributes.rSpan,
+ tableAttributes.rGap);
+ adjustForSpans(row,
+ prefSize.height,
+ prefHeight,
+ rowWeight,
+ attributes.rSpan,
+ tableAttributes.rGap);
+ adjustForSpans(row,
+ maxSize.height,
+ maxHeight,
+ rowWeight,
+ attributes.rSpan,
+ tableAttributes.rGap);
+ }
+ }
+ }
+ }
+
+ // Add up all the individual values
+
+ MinWidth = 0;
+ MinHeight = 0;
+ PrefWidth = 0;
+ PrefHeight = 0;
+ MaxWidth = 0;
+ MaxHeight = 0;
+ ColWeight = 0;
+ RowWeight = 0;
+
+ // Sum up everything
+
+ for (int i = 0; i < nCols; i++) {
+ MinWidth += minWidth[i];
+ PrefWidth += prefWidth[i];
+ MaxWidth += maxWidth[i];
+ ColWeight += colWeight[i];
+ }
+
+ for (int i = 0; i < nRows; i++) {
+ MinHeight += minHeight[i];
+ PrefHeight += prefHeight[i];
+ MaxHeight += maxHeight[i];
+ RowWeight += rowWeight[i];
+ }
+
+ // Add in the table gaps
+
+ int cExtra = tableAttributes.cGap * (nCols - 1);
+ int rExtra = tableAttributes.rGap * (nRows - 1);
+
+ MinWidth += cExtra;
+ PrefWidth += cExtra;
+ MaxWidth += cExtra;
+
+ MinHeight += rExtra;
+ PrefHeight += rExtra;
+ MaxHeight += rExtra;
+
+ // DEBUG
// if ("DEBUG".equals(parent.getName())) {
// System.out.println("MeasureComponents:");
@@ -1401,87 +1403,87 @@ measureComponents(
// }
// }
- // We keep using these results until the layout is invalidated
+ // We keep using these results until the layout is invalidated
- useCacheMeasureResults = true;
-}
-
-/**
- * Make sure the first dimension is greater than or equal to the
- * second. Also make sure the first dimension is less than an absolute
- * maximum.
- *
- * @param d1 The first dimension (may be modified).
- * @param d2 The second dimension (will not be modified).
- */
-
-private void
-limitDimension(
- Dimension d1,
- Dimension d2)
-{
- if (d1.width < d2.width) d1.width = d2.width;
- if (d1.height < d2.height) d1.height = d2.height;
- if (d1.width > Short.MAX_VALUE) d1.width = Short.MAX_VALUE;
- if (d1.height > Short.MAX_VALUE) d1.height = Short.MAX_VALUE;
-}
-
-/**
- * If a component spans multiple rows or columns, we need to
- * distribute portions of its size to the individual rows and columns.
- *
- * @param pos Row or column position where the span component starts.
- * @param compSize The height or width of the component
- * @param sizes The array of widths or heights to adjust.
- * @param span The number of cells spanned by the component.
- * @param gap The row or column gap.
- */
-
-private void
-adjustForSpans(
- int pos,
- int compSize,
- int[] sizes,
- int[] weight,
- int span,
- int gap)
-{
- // The total size is the size of the rows or columns plus all the
- // space in between
+ useCacheMeasureResults = true;
+ }
- int totalSize = 0;
- for (int i = 0; i < span; i++) {
- totalSize += sizes[pos + i];
+ /**
+ * Make sure the first dimension is greater than or equal to the
+ * second. Also make sure the first dimension is less than an absolute
+ * maximum.
+ *
+ * @param d1 The first dimension (may be modified).
+ * @param d2 The second dimension (will not be modified).
+ */
+
+ private void
+ limitDimension(
+ Dimension d1,
+ Dimension d2)
+ {
+ if (d1.width < d2.width) d1.width = d2.width;
+ if (d1.height < d2.height) d1.height = d2.height;
+ if (d1.width > Short.MAX_VALUE) d1.width = Short.MAX_VALUE;
+ if (d1.height > Short.MAX_VALUE) d1.height = Short.MAX_VALUE;
}
- totalSize += gap * (span - 1);
-
- // If the spanned component is bigger than the the rows or columns
- // it spans, we divide the extra space based on the weights of the
- // spanned rows or columns
-
- if (compSize > totalSize) {
- int extra = compSize - totalSize;
- int totalWeight = 0;
- for (int i = 0; i < span; i++) {
- totalWeight += weight[pos + i];
- }
- if (totalWeight == 0) totalWeight = span;
-
- int remainder = extra;
- for (int i = 0; i < span; i++) {
- int portion = (extra * weight[pos + i]) / totalWeight;
- sizes[pos + i] += portion;
- remainder -= portion;
- }
-
- // Because of truncation, we may have a little left over which
- // we give to the last row or column
-
- if (remainder > 0) {
- sizes[pos + span - 1] += remainder;
- }
+
+ /**
+ * If a component spans multiple rows or columns, we need to
+ * distribute portions of its size to the individual rows and columns.
+ *
+ * @param pos Row or column position where the span component starts.
+ * @param compSize The height or width of the component
+ * @param sizes The array of widths or heights to adjust.
+ * @param span The number of cells spanned by the component.
+ * @param gap The row or column gap.
+ */
+
+ private void
+ adjustForSpans(
+ int pos,
+ int compSize,
+ int[] sizes,
+ int[] weight,
+ int span,
+ int gap)
+ {
+ // The total size is the size of the rows or columns plus all the
+ // space in between
+
+ int totalSize = 0;
+ for (int i = 0; i < span; i++) {
+ totalSize += sizes[pos + i];
+ }
+ totalSize += gap * (span - 1);
+
+ // If the spanned component is bigger than the the rows or columns
+ // it spans, we divide the extra space based on the weights of the
+ // spanned rows or columns
+
+ if (compSize > totalSize) {
+ int extra = compSize - totalSize;
+ int totalWeight = 0;
+ for (int i = 0; i < span; i++) {
+ totalWeight += weight[pos + i];
+ }
+ if (totalWeight == 0) totalWeight = span;
+
+ int remainder = extra;
+ for (int i = 0; i < span; i++) {
+ int portion = (extra * weight[pos + i]) / totalWeight;
+ sizes[pos + i] += portion;
+ remainder -= portion;
+ }
+
+ // Because of truncation, we may have a little left over which
+ // we give to the last row or column
+
+ if (remainder > 0) {
+ sizes[pos + span - 1] += remainder;
+ }
+ }
}
-}
//**********************************************************************
// Inner Classes
@@ -1497,451 +1499,451 @@ adjustForSpans(
// Attributes not needing assigment
-static String[] attr = {
- "tn", "tne", "tnw",
- "ts", "tse", "tsw",
- "te", "tw", "tc",
- "tfh", "tfv", "tf",
- "n", "ne", "nw",
- "s", "se", "sw",
- "e", "w", "c",
- "fh", "fv", "f",
-};
+ static String[] attr = {
+ "tn", "tne", "tnw",
+ "ts", "tse", "tsw",
+ "te", "tw", "tc",
+ "tfh", "tfv", "tf",
+ "n", "ne", "nw",
+ "s", "se", "sw",
+ "e", "w", "c",
+ "fh", "fv", "f",
+ };
// Attributes needing assigment
-static String[] assgn = {
- "cols",
- "rgap",
- "cgap",
- "titop",
- "tibottom",
- "tileft",
- "tiright",
- "itop",
- "ibottom",
- "ileft",
- "iright",
- "rweight",
- "cweight",
- "rspan",
- "cspan",
- "col",
- "skip"
-};
-
-private class Attributes
-{
+ static String[] assgn = {
+ "cols",
+ "rgap",
+ "cgap",
+ "titop",
+ "tibottom",
+ "tileft",
+ "tiright",
+ "itop",
+ "ibottom",
+ "ileft",
+ "iright",
+ "rweight",
+ "cweight",
+ "rspan",
+ "cspan",
+ "col",
+ "skip"
+ };
+
+ private class Attributes
+ {
// Constants used for fill and placement operations
-static final int CENTER = 0;
-static final int LEFT = 1;
-static final int RIGHT = 2;
-static final int TOP = 3;
-static final int BOTTOM = 4;
-static final int FILL = 5;
+ static final int CENTER = 0;
+ static final int LEFT = 1;
+ static final int RIGHT = 2;
+ static final int TOP = 3;
+ static final int BOTTOM = 4;
+ static final int FILL = 5;
// Constants for column placement
-static final int NEXT_COLUMN = -1;
+ static final int NEXT_COLUMN = -1;
// The attributes in their original string form
-String attrString;
+ String attrString;
// Table-only options
-int columns = 1;
-int tableHorizontal = FILL;
-int tableVertical = FILL;
-int rGap = 0;
-int cGap = 0;
-Insets tableInsets = new Insets(0, 0, 0, 0);
+ int columns = 1;
+ int tableHorizontal = FILL;
+ int tableVertical = FILL;
+ int rGap = 0;
+ int cGap = 0;
+ Insets tableInsets = new Insets(0, 0, 0, 0);
// Table/cell options
-int horizontal = FILL;
-int vertical = FILL;
-Insets cellInsets = new Insets(0, 0, 0, 0);
-int rWeight = 0;
-int cWeight = 0;
+ int horizontal = FILL;
+ int vertical = FILL;
+ Insets cellInsets = new Insets(0, 0, 0, 0);
+ int rWeight = 0;
+ int cWeight = 0;
// Cell-only options
-int rSpan = 1;
-int cSpan = 1;
-int originalCSpan = cSpan;
-int column = NEXT_COLUMN;
-int skip = 0;
-
-int tkPos = 0;
-boolean isTableAttributes = false;
-
-Attributes(
- String attrString)
-{
- this(attrString, true);
-}
-
-Attributes(
- String attrString,
- boolean isTableAttributes)
-{
- // Save the string for later access
-
- this.attrString = attrString;
-
- this.isTableAttributes = isTableAttributes;
-
- parse();
-}
-
-public String
-toString()
-{
- String sep = System.getProperty("line.separator");
- return "TableLayout Attributes:" + sep +
- "isTableAttributes = " + isTableAttributes + sep +
- "columns = " + columns + sep +
- "tableHorizontal = " + tableHorizontal + " " +
- "tableVertical = " + tableVertical + sep +
- "rGap = " + rGap + " " +
- "cGap = " + cGap + sep +
- "tableInsets = " + tableInsets + sep +
- "horizontal = " + horizontal + " " +
- "vertical = " + vertical + sep +
- "cellInsets = " + cellInsets + sep +
- "rWeight = " + rWeight + " " +
- "cWeight = " + cWeight + sep +
- "rSpan = " + rSpan + " " +
- "cSpan = " + cSpan + sep +
- "originalCSpan = " + originalCSpan + sep +
- "column = " + column + sep +
- "skip = " + skip;
-}
+ int rSpan = 1;
+ int cSpan = 1;
+ int originalCSpan = cSpan;
+ int column = NEXT_COLUMN;
+ int skip = 0;
+
+ int tkPos = 0;
+ boolean isTableAttributes = false;
+
+ Attributes(
+ String attrString)
+ {
+ this(attrString, true);
+ }
+
+ Attributes(
+ String attrString,
+ boolean isTableAttributes)
+ {
+ // Save the string for later access
+
+ this.attrString = attrString;
+
+ this.isTableAttributes = isTableAttributes;
+
+ parse();
+ }
+
+ public String
+ toString()
+ {
+ String sep = System.getProperty("line.separator");
+ return "TableLayout Attributes:" + sep +
+ "isTableAttributes = " + isTableAttributes + sep +
+ "columns = " + columns + sep +
+ "tableHorizontal = " + tableHorizontal + " " +
+ "tableVertical = " + tableVertical + sep +
+ "rGap = " + rGap + " " +
+ "cGap = " + cGap + sep +
+ "tableInsets = " + tableInsets + sep +
+ "horizontal = " + horizontal + " " +
+ "vertical = " + vertical + sep +
+ "cellInsets = " + cellInsets + sep +
+ "rWeight = " + rWeight + " " +
+ "cWeight = " + cWeight + sep +
+ "rSpan = " + rSpan + " " +
+ "cSpan = " + cSpan + sep +
+ "originalCSpan = " + originalCSpan + sep +
+ "column = " + column + sep +
+ "skip = " + skip;
+ }
+
+ String
+ getStringAttributes()
+ {
+ return attrString;
+ }
+
+ private char
+ getTokenChar()
+ {
+ if (tkPos >= attrString.length()) return 0;
+ return Character.toLowerCase(attrString.charAt(tkPos++));
+ }
+
+
+ private String
+ getToken()
+ {
+ StringBuffer token = new StringBuffer();
+
+ char c = getTokenChar();
+
+ // Skip whitespace
+
+ if (Character.isWhitespace(c)) {
+ do {
+ c = getTokenChar();
+ }
+ while (Character.isWhitespace(c));
+ }
+
+ // Attributes
+
+ if (Character.isLetter(c)) {
+ do {
+ token.append(c);
+ c = getTokenChar();
+ }
+ while (Character.isLetter(c));
+ if (c != 0) tkPos--;
+ }
+
+ // Integers
+
+ else if (Character.isDigit(c)) {
+ do {
+ token.append(c);
+ c = getTokenChar();
+ }
+ while (Character.isDigit(c));
+ if (c != 0) tkPos--;
+ }
+
+ // End of string
+
+ else if (c == 0) {
+ return null;
+ }
+
+ // Everything else is a single-character token
+
+ else {
+ token.append(c);
+ }
+
+ return new String(token);
+ }
+
+ void
+ parse()
+ {
+ // Initialize this set of attributes so it starts out as a copy of
+ // the given default, at least for those options where the cell
+ // can override a table default
+
+ if (!isTableAttributes) {
+ horizontal = tableAttributes.horizontal;
+ vertical = tableAttributes.vertical;
+ cellInsets = (Insets)tableAttributes.cellInsets.clone();
+ rWeight = tableAttributes.rWeight;
+ cWeight = tableAttributes.cWeight;
+ }
+
+ if (attrString == null) return;
+ tkPos = 0;
+
+ while (tkPos < attrString.length()) {
+ parseOption();
+ }
+
+ // We have checked the syntax, now check the semantics
+
+ if (isTableAttributes) {
+ if (columns == 0) {
+ reportSemanticError("cols=0");
+ }
+ }
+ else {
+ if (rSpan == 0) {
+ reportSemanticError("rspan=0");
+ }
+ if (cSpan == 0) {
+ reportSemanticError("cspan=0");
+ }
+ if (column >= tableAttributes.columns) {
+ reportSemanticError("col=" + column +
+ " (max is " +
+ (tableAttributes.columns - 1) + ")");
+ }
+ }
+ }
+
+ private void
+ parseOption()
+ {
+ // Get the next token
+
+ String token = getToken();
+ if (token == null) return;
+
+ boolean attributeFound = false;
+ for (int i = 0; i < attr.length; i++) {
+ if (token.equals(attr[i])) {
+ parseAttribute(token);
+ return;
+ }
+ }
+
+ for (int i = 0; i < assgn.length; i++) {
+ if (token.equals(assgn[i])) {
+ parseAssignment(token);
+ return;
+ }
+ }
+
+ reportError(token, "Unrecognized attribute");
+ }
+
+ private void
+ parseAttribute(
+ String token)
+ {
+ // Table placement and fill
+
+ if ("tnw".equals(token) ||
+ "tw".equals(token) ||
+ "tsw".equals(token)) {
+ tableHorizontal = LEFT;
+ }
+
+ if ("tne".equals(token) ||
+ "te".equals(token) ||
+ "tse".equals(token)) {
+ tableHorizontal = RIGHT;
+ }
+
+ if ("tn".equals(token) ||
+ "tc".equals(token) ||
+ "ts".equals(token)) {
+ tableHorizontal = CENTER;
+ }
+
+ if ("tf".equals(token) ||
+ "tfh".equals(token)) {
+ tableHorizontal = FILL;
+ }
+
+ if ("tn".equals(token) ||
+ "tnw".equals(token) ||
+ "tne".equals(token)) {
+ tableVertical = TOP;
+ }
+
+ if ("ts".equals(token) ||
+ "tsw".equals(token) ||
+ "tse".equals(token)) {
+ tableVertical = BOTTOM;
+ }
+
+ if ("tw".equals(token) ||
+ "tc".equals(token) ||
+ "te".equals(token)) {
+ tableVertical = CENTER;
+ }
+
+ if ("tf".equals(token) ||
+ "tfv".equals(token)) {
+ tableVertical = FILL;
+ }
+
+ // Cell placement and fill
+
+ if ("nw".equals(token) ||
+ "w".equals(token) ||
+ "sw".equals(token)) {
+ horizontal = LEFT;
+ }
+
+ if ("ne".equals(token) ||
+ "e".equals(token) ||
+ "se".equals(token)) {
+ horizontal = RIGHT;
+ }
+
+ if ("n".equals(token) ||
+ "c".equals(token) ||
+ "s".equals(token)) {
+ horizontal = CENTER;
+ }
+
+ if ("f".equals(token) ||
+ "fh".equals(token)) {
+ horizontal = FILL;
+ }
+
+ if ("n".equals(token) ||
+ "nw".equals(token) ||
+ "ne".equals(token)) {
+ vertical = TOP;
+ }
+
+ if ("s".equals(token) ||
+ "sw".equals(token) ||
+ "se".equals(token)) {
+ vertical = BOTTOM;
+ }
+
+ if ("w".equals(token) ||
+ "c".equals(token) ||
+ "e".equals(token)) {
+ vertical = CENTER;
+ }
+
+ if ("f".equals(token) ||
+ "fv".equals(token)) {
+ vertical = FILL;
+ }
+ }
+
+ private void
+ parseAssignment(
+ String token)
+ {
+ String attr = token;
+
+ token = getToken();
+ if (token != null) {
+ if ("=".equals(token)) {
+ token = getToken();
+ if (token != null) {
+ int value = 0;
+ try {
+ value = Integer.parseInt(token);
+ }
+ catch (NumberFormatException e) {
+ reportError(token, "Expected an integer");
+ }
+
+ if ("cols".equals(attr))
+ columns = value;
+ else if ("rgap".equals(attr))
+ rGap = value;
+ else if ("cgap".equals(attr))
+ cGap = value;
+ else if ("titop".equals(attr))
+ tableInsets.top = value;
+ else if ("tibottom".equals(attr))
+ tableInsets.bottom = value;
+ else if ("tileft".equals(attr))
+ tableInsets.left = value;
+ else if ("tiright".equals(attr))
+ tableInsets.right = value;
+ else if ("itop".equals(attr))
+ cellInsets.top = value;
+ else if ("ibottom".equals(attr))
+ cellInsets.bottom = value;
+ else if ("ileft".equals(attr))
+ cellInsets.left = value;
+ else if ("iright".equals(attr))
+ cellInsets.right = value;
+ else if ("rweight".equals(attr))
+ rWeight = value;
+ else if ("cweight".equals(attr))
+ cWeight = value;
+ else if ("rspan".equals(attr))
+ rSpan = value;
+ else if ("cspan".equals(attr))
+ originalCSpan = cSpan = value;
+ else if ("col".equals(attr))
+ column = value;
+ else if ("skip".equals(attr))
+ skip = value;
+
+ return;
+ }
+ }
+ reportError(token, "Expected an '='");
+ }
+ reportError(token, "Expected an '='");
+ }
+
+ private void
+ reportError(
+ String token,
+ String message)
+ {
+ throw new IllegalArgumentException(
+ "TableLayout: " + message + "; near '" + token +
+ "' at position " + tkPos + " in '" +
+ attrString + "'");
+ }
+
+ private void
+ reportSemanticError(
+ String message)
+ {
+ throw new IllegalArgumentException(
+ "TableLayout: Invalid value: " + message);
+ }
-String
-getStringAttributes()
-{
- return attrString;
-}
-
-private char
-getTokenChar()
-{
- if (tkPos >= attrString.length()) return 0;
- return Character.toLowerCase(attrString.charAt(tkPos++));
-}
-
-
-private String
-getToken()
-{
- StringBuffer token = new StringBuffer();
-
- char c = getTokenChar();
-
- // Skip whitespace
-
- if (Character.isWhitespace(c)) {
- do {
- c = getTokenChar();
- }
- while (Character.isWhitespace(c));
- }
-
- // Attributes
-
- if (Character.isLetter(c)) {
- do {
- token.append(c);
- c = getTokenChar();
- }
- while (Character.isLetter(c));
- if (c != 0) tkPos--;
- }
-
- // Integers
-
- else if (Character.isDigit(c)) {
- do {
- token.append(c);
- c = getTokenChar();
- }
- while (Character.isDigit(c));
- if (c != 0) tkPos--;
- }
-
- // End of string
-
- else if (c == 0) {
- return null;
}
- // Everything else is a single-character token
-
- else {
- token.append(c);
- }
-
- return new String(token);
-}
-
-void
-parse()
-{
- // Initialize this set of attributes so it starts out as a copy of
- // the given default, at least for those options where the cell
- // can override a table default
-
- if (!isTableAttributes) {
- horizontal = tableAttributes.horizontal;
- vertical = tableAttributes.vertical;
- cellInsets = (Insets)tableAttributes.cellInsets.clone();
- rWeight = tableAttributes.rWeight;
- cWeight = tableAttributes.cWeight;
- }
-
- if (attrString == null) return;
- tkPos = 0;
-
- while (tkPos < attrString.length()) {
- parseOption();
- }
-
- // We have checked the syntax, now check the semantics
-
- if (isTableAttributes) {
- if (columns == 0) {
- reportSemanticError("cols=0");
- }
- }
- else {
- if (rSpan == 0) {
- reportSemanticError("rspan=0");
- }
- if (cSpan == 0) {
- reportSemanticError("cspan=0");
- }
- if (column >= tableAttributes.columns) {
- reportSemanticError("col=" + column +
- " (max is " +
- (tableAttributes.columns - 1) + ")");
- }
- }
-}
-
-private void
-parseOption()
-{
- // Get the next token
-
- String token = getToken();
- if (token == null) return;
-
- boolean attributeFound = false;
- for (int i = 0; i < attr.length; i++) {
- if (token.equals(attr[i])) {
- parseAttribute(token);
- return;
- }
- }
-
- for (int i = 0; i < assgn.length; i++) {
- if (token.equals(assgn[i])) {
- parseAssignment(token);
- return;
- }
- }
-
- reportError(token, "Unrecognized attribute");
-}
-
-private void
-parseAttribute(
- String token)
-{
- // Table placement and fill
-
- if ("tnw".equals(token) ||
- "tw".equals(token) ||
- "tsw".equals(token)) {
- tableHorizontal = LEFT;
- }
-
- if ("tne".equals(token) ||
- "te".equals(token) ||
- "tse".equals(token)) {
- tableHorizontal = RIGHT;
- }
-
- if ("tn".equals(token) ||
- "tc".equals(token) ||
- "ts".equals(token)) {
- tableHorizontal = CENTER;
- }
-
- if ("tf".equals(token) ||
- "tfh".equals(token)) {
- tableHorizontal = FILL;
- }
-
- if ("tn".equals(token) ||
- "tnw".equals(token) ||
- "tne".equals(token)) {
- tableVertical = TOP;
- }
-
- if ("ts".equals(token) ||
- "tsw".equals(token) ||
- "tse".equals(token)) {
- tableVertical = BOTTOM;
- }
-
- if ("tw".equals(token) ||
- "tc".equals(token) ||
- "te".equals(token)) {
- tableVertical = CENTER;
- }
-
- if ("tf".equals(token) ||
- "tfv".equals(token)) {
- tableVertical = FILL;
- }
-
- // Cell placement and fill
-
- if ("nw".equals(token) ||
- "w".equals(token) ||
- "sw".equals(token)) {
- horizontal = LEFT;
- }
-
- if ("ne".equals(token) ||
- "e".equals(token) ||
- "se".equals(token)) {
- horizontal = RIGHT;
- }
-
- if ("n".equals(token) ||
- "c".equals(token) ||
- "s".equals(token)) {
- horizontal = CENTER;
- }
-
- if ("f".equals(token) ||
- "fh".equals(token)) {
- horizontal = FILL;
- }
-
- if ("n".equals(token) ||
- "nw".equals(token) ||
- "ne".equals(token)) {
- vertical = TOP;
- }
-
- if ("s".equals(token) ||
- "sw".equals(token) ||
- "se".equals(token)) {
- vertical = BOTTOM;
- }
-
- if ("w".equals(token) ||
- "c".equals(token) ||
- "e".equals(token)) {
- vertical = CENTER;
- }
-
- if ("f".equals(token) ||
- "fv".equals(token)) {
- vertical = FILL;
- }
-}
-
-private void
-parseAssignment(
- String token)
-{
- String attr = token;
-
- token = getToken();
- if (token != null) {
- if ("=".equals(token)) {
- token = getToken();
- if (token != null) {
- int value = 0;
- try {
- value = Integer.parseInt(token);
- }
- catch (NumberFormatException e) {
- reportError(token, "Expected an integer");
- }
-
- if ("cols".equals(attr))
- columns = value;
- else if ("rgap".equals(attr))
- rGap = value;
- else if ("cgap".equals(attr))
- cGap = value;
- else if ("titop".equals(attr))
- tableInsets.top = value;
- else if ("tibottom".equals(attr))
- tableInsets.bottom = value;
- else if ("tileft".equals(attr))
- tableInsets.left = value;
- else if ("tiright".equals(attr))
- tableInsets.right = value;
- else if ("itop".equals(attr))
- cellInsets.top = value;
- else if ("ibottom".equals(attr))
- cellInsets.bottom = value;
- else if ("ileft".equals(attr))
- cellInsets.left = value;
- else if ("iright".equals(attr))
- cellInsets.right = value;
- else if ("rweight".equals(attr))
- rWeight = value;
- else if ("cweight".equals(attr))
- cWeight = value;
- else if ("rspan".equals(attr))
- rSpan = value;
- else if ("cspan".equals(attr))
- originalCSpan = cSpan = value;
- else if ("col".equals(attr))
- column = value;
- else if ("skip".equals(attr))
- skip = value;
-
- return;
- }
- }
- reportError(token, "Expected an '='");
- }
- reportError(token, "Expected an '='");
-}
-
-private void
-reportError(
- String token,
- String message)
-{
- throw new IllegalArgumentException(
- "TableLayout: " + message + "; near '" + token +
- "' at position " + tkPos + " in '" +
- attrString + "'");
-}
-
-private void
-reportSemanticError(
- String message)
-{
- throw new IllegalArgumentException(
- "TableLayout: Invalid value: " + message);
-}
-
-}
-
//**********************************************************************
//
// CompArray
@@ -1960,88 +1962,88 @@ reportSemanticError(
//
//**********************************************************************
-private class CompArray
-{
-
-private int nCols;
-private int nRows;
-private int maxRow = 0;
-Component[][] compArray = null;
-
-CompArray(
- int nCols,
- int compCount)
-{
- this.nRows = (compCount + (nCols - 1)) / nCols;
- this.nRows = Math.max(this.nRows, 1);
- this.nCols = nCols;
-
- compArray = new Component[nRows][];
- for (int i = 0; i < nRows; i++) {
- compArray[i] = new Component[nCols];
- Arrays.fill(compArray[i], null);
- }
-}
-
-Component
-get(
- int row,
- int col)
-{
- if (row >= nRows) resize(row + 1);
- return compArray[row][col];
-}
-
-void
-set(
- int row,
- int col,
- Component comp)
-{
- if (row >= nRows) resize(row + 1);
- compArray[row][col] = comp;
- maxRow = Math.max(row, maxRow);
-}
-
-Component[][]
-getArray()
-{
- int maxRows = maxRow + 1;
- Component[][] array = new Component[maxRows][];
- for (int r = 0; r < maxRows; r++) {
- array[r] = new Component[nCols];
- System.arraycopy(compArray[r], 0, array[r], 0, nCols);
- }
-
- return array;
-}
+ private class CompArray
+ {
+
+ private int nCols;
+ private int nRows;
+ private int maxRow = 0;
+ Component[][] compArray = null;
+
+ CompArray(
+ int nCols,
+ int compCount)
+ {
+ this.nRows = (compCount + (nCols - 1)) / nCols;
+ this.nRows = Math.max(this.nRows, 1);
+ this.nCols = nCols;
+
+ compArray = new Component[nRows][];
+ for (int i = 0; i < nRows; i++) {
+ compArray[i] = new Component[nCols];
+ Arrays.fill(compArray[i], null);
+ }
+ }
+
+ Component
+ get(
+ int row,
+ int col)
+ {
+ if (row >= nRows) resize(row + 1);
+ return compArray[row][col];
+ }
+
+ void
+ set(
+ int row,
+ int col,
+ Component comp)
+ {
+ if (row >= nRows) resize(row + 1);
+ compArray[row][col] = comp;
+ maxRow = Math.max(row, maxRow);
+ }
+
+ Component[][]
+ getArray()
+ {
+ int maxRows = maxRow + 1;
+ Component[][] array = new Component[maxRows][];
+ for (int r = 0; r < maxRows; r++) {
+ array[r] = new Component[nCols];
+ System.arraycopy(compArray[r], 0, array[r], 0, nCols);
+ }
+
+ return array;
+ }
+
+ private void
+ resize(
+ int newRows)
+ {
+ // When we exceed a threshold, bump up the size by at least 10
+
+ if (newRows - nRows < 10) newRows = nRows + 10;
+
+ // Create the new row array and copy the old one into it
+
+ Component[][] newArray = new Component[newRows][];
+ System.arraycopy(compArray, 0, newArray, 0, nRows);
+
+ // Initialize each new row to nulls
+
+ for (int i = nRows; i < newRows; i++) {
+ newArray[i] = new Component[nCols];
+ Arrays.fill(newArray[i], null);
+ }
+
+ compArray = newArray;
+ nRows = newRows;
+ }
-private void
-resize(
- int newRows)
-{
- // When we exceed a threshold, bump up the size by at least 10
-
- if (newRows - nRows < 10) newRows = nRows + 10;
-
- // Create the new row array and copy the old one into it
-
- Component[][] newArray = new Component[newRows][];
- System.arraycopy(compArray, 0, newArray, 0, nRows);
-
- // Initialize each new row to nulls
-
- for (int i = nRows; i < newRows; i++) {
- newArray[i] = new Component[nCols];
- Arrays.fill(newArray[i], null);
}
- compArray = newArray;
- nRows = newRows;
-}
-
-}
-
//**********************************************************************
// End Inner Classes
//**********************************************************************