From 9129838d208c0df7293e5b757661125545cd6df8 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 4 Mar 2009 17:31:40 +0000 Subject: flib added --- libs/FLib/TableLayout/License.txt | 123 + libs/FLib/TableLayout/README.txt | 34 + libs/FLib/TableLayout/build.xml | 120 + libs/FLib/TableLayout/doc-templates/License.html | 180 + libs/FLib/TableLayout/doc/example/Example1.java | 180 + .../TableLayout/doc/example/TableExplorer.java | 1230 +++++ libs/FLib/TableLayout/doc/examples.html | 76 + libs/FLib/TableLayout/doc/features.html | 55 + libs/FLib/TableLayout/doc/images/Logo.png | Bin 0 -> 62326 bytes libs/FLib/TableLayout/doc/images/screenshot1.png | Bin 0 -> 2523 bytes libs/FLib/TableLayout/doc/images/screenshot2.png | Bin 0 -> 3997 bytes libs/FLib/TableLayout/doc/images/tutorial1.png | Bin 0 -> 1245 bytes libs/FLib/TableLayout/doc/images/tutorial2.png | Bin 0 -> 1724 bytes libs/FLib/TableLayout/doc/images/tutorial3.png | Bin 0 -> 1797 bytes libs/FLib/TableLayout/doc/images/tutorial4.png | Bin 0 -> 1765 bytes libs/FLib/TableLayout/doc/images/tutorial5.png | Bin 0 -> 1433 bytes libs/FLib/TableLayout/doc/images/tutorial6.png | Bin 0 -> 1048 bytes libs/FLib/TableLayout/doc/images/tutorial7.png | Bin 0 -> 821 bytes libs/FLib/TableLayout/doc/images/tutorial8.png | Bin 0 -> 923 bytes libs/FLib/TableLayout/doc/index.html | 64 + libs/FLib/TableLayout/doc/resources.html | 68 + libs/FLib/TableLayout/doc/screenshots.html | 48 + libs/FLib/TableLayout/doc/stylesheet.css | 48 + libs/FLib/TableLayout/doc/tutorial.html | 338 ++ .../org/freixas/tablelayout/TableLayout.java | 2049 ++++++++ libs/FLib/TableLayout/project.dtd | 5193 ++++++++++++++++++++ 26 files changed, 9806 insertions(+) create mode 100644 libs/FLib/TableLayout/License.txt create mode 100644 libs/FLib/TableLayout/README.txt create mode 100644 libs/FLib/TableLayout/build.xml create mode 100644 libs/FLib/TableLayout/doc-templates/License.html create mode 100644 libs/FLib/TableLayout/doc/example/Example1.java create mode 100644 libs/FLib/TableLayout/doc/example/TableExplorer.java create mode 100644 libs/FLib/TableLayout/doc/examples.html create mode 100644 libs/FLib/TableLayout/doc/features.html create mode 100644 libs/FLib/TableLayout/doc/images/Logo.png create mode 100644 libs/FLib/TableLayout/doc/images/screenshot1.png create mode 100644 libs/FLib/TableLayout/doc/images/screenshot2.png create mode 100644 libs/FLib/TableLayout/doc/images/tutorial1.png create mode 100644 libs/FLib/TableLayout/doc/images/tutorial2.png create mode 100644 libs/FLib/TableLayout/doc/images/tutorial3.png create mode 100644 libs/FLib/TableLayout/doc/images/tutorial4.png create mode 100644 libs/FLib/TableLayout/doc/images/tutorial5.png create mode 100644 libs/FLib/TableLayout/doc/images/tutorial6.png create mode 100644 libs/FLib/TableLayout/doc/images/tutorial7.png create mode 100644 libs/FLib/TableLayout/doc/images/tutorial8.png create mode 100644 libs/FLib/TableLayout/doc/index.html create mode 100644 libs/FLib/TableLayout/doc/resources.html create mode 100644 libs/FLib/TableLayout/doc/screenshots.html create mode 100644 libs/FLib/TableLayout/doc/stylesheet.css create mode 100644 libs/FLib/TableLayout/doc/tutorial.html create mode 100644 libs/FLib/TableLayout/org/freixas/tablelayout/TableLayout.java create mode 100644 libs/FLib/TableLayout/project.dtd (limited to 'libs/FLib/TableLayout') diff --git a/libs/FLib/TableLayout/License.txt b/libs/FLib/TableLayout/License.txt new file mode 100644 index 0000000..be12e9d --- /dev/null +++ b/libs/FLib/TableLayout/License.txt @@ -0,0 +1,123 @@ + Artistic License + +Preamble + +The intent of this document is to state the conditions under which a +Package may be copied, such that the Copyright Holder maintains some +semblance of artistic control over the development of the package, +while giving the users of the package the right to use and distribute +the Package in a more-or-less customary fashion, plus the right to +make reasonable modifications. + +Definitions: + + * "Package" refers to the collection of files distributed by the + Copyright Holder, and derivatives of that collection of files + created through textual modification. + + * "Standard Version" refers to such a Package if it has not been + modified, or has been modified in accordance with the wishes of + the Copyright Holder. + + * "Copyright Holder" is whoever is named in the copyright or + copyrights for the package. + + * "You" is you, if you're thinking about copying or distributing + this Package. + + * "Reasonable copying fee" is whatever you can justify on the + basis of media cost, duplication charges, time of people + involved, and so on. (You will not be required to justify it to + the Copyright Holder, but only to the computing community at + large as a market that must bear the fee.) + + * "Freely Available" means that no fee is charged for the item + itself, though there may be fees involved in handling the item. + It also means that recipients of the item may redistribute it + under the same conditions they received it. + +1. You may make and give away verbatim copies of the source form of + the Standard Version of this Package without restriction, provided + that you duplicate all of the original copyright notices and + associated disclaimers. + +2. You may apply bug fixes, portability fixes and other modifications + derived from the Public Domain or from the Copyright Holder. A + Package modified in such a way shall still be considered the + Standard Version. + +3. You may otherwise modify your copy of this Package in any way, + provided that you insert a prominent notice in each changed file + stating how and when you changed that file, and provided that you + do at least ONE of the following: + + a) place your modifications in the Public Domain or otherwise make + them Freely Available, such as by posting said modifications to + Usenet or an equivalent medium, or placing the modifications on + a major archive site such as ftp.uu.net, or by allowing the + Copyright Holder to include your modifications in the Standard + Version of the Package. + + b) use the modified Package only within your corporation or + organization. + + c) rename any non-standard executables so the names do not + conflict with standard executables, which must also be + provided, and provide a separate manual page for each + non-standard executable that clearly documents how it differs + from the Standard Version. + + d) make other distribution arrangements with the Copyright Holder. + +4. You may distribute the programs of this Package in object code or + executable form, provided that you do at least ONE of the + following: + + a) distribute a Standard Version of the executables and library + files, together with instructions (in the manual page or + equivalent) on where to get the Standard Version. + + b) accompany the distribution with the machine-readable source of + the Package with your modifications. + + c) accompany any non-standard executables with their corresponding + Standard Version executables, giving the non-standard + executables non-standard names, and clearly documenting the + differences in manual pages (or equivalent), together with + instructions on where to get the Standard Version. + + d) make other distribution arrangements with the Copyright Holder. + +5. You may charge a reasonable copying fee for any distribution of + this Package. You may charge any fee you choose for support of this + Package. You may not charge a fee for this Package itself. However, + you may distribute this Package in aggregate with other (possibly + commercial) programs as part of a larger (possibly commercial) + software distribution provided that you do not advertise this + Package as a product of your own. + +6. The scripts and library files supplied as input to or produced as + output from the programs of this Package do not automatically fall + under the copyright of this Package, but belong to whomever + generated them, and may be sold commercially, and may be aggregated + with this Package. + +7. C or perl subroutines supplied by you and linked into this Package + shall not be considered part of this Package. + +8. Aggregation of this Package with a commercial distribution is + always permitted provided that the use of this Package is embedded; + that is, when no overt attempt is made to make this Package's + interfaces visible to the end user of the commercial distribution. + Such use shall not be construed as a distribution of this Package. + +9. The name of the Copyright Holder may not be used to endorse or + promote products derived from this software without specific prior + written permission. + +10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + PURPOSE. + +The End diff --git a/libs/FLib/TableLayout/README.txt b/libs/FLib/TableLayout/README.txt new file mode 100644 index 0000000..6a3ac6e --- /dev/null +++ b/libs/FLib/TableLayout/README.txt @@ -0,0 +1,34 @@ + TableLayout + +This package provides a TableLayout manager for use in Java programs. + +This program is free software; you can redistribute it and/or modify +it under the terms of the Artistic License. You should have received a +copy of the Artistic License along with this program (in file +License.txt). If not, a copy is available at + + http://opensource.org/licenses/artistic-license.php + +To build it you'll need Ant. I used version 1.6.2. Use + + ant all + +This will create build/tablelayout.jar. To create the API +documentation, use + + ant javadoc + +To view all the documentation, view doc/index.html. + +There is a tutorial in doc/tutorial.html. There is also a sample Java +program that uses the TableLayout class. You can build and run this +program with + + ant runExample1 + +In addition, there is a tool you can use to practice using the +TableLayout. It's called TableExplorer and follows the approach of a +similar tool written for the GridBagLayout. Build and run this program +with + + ant runTableExplorer diff --git a/libs/FLib/TableLayout/build.xml b/libs/FLib/TableLayout/build.xml new file mode 100644 index 0000000..99384a6 --- /dev/null +++ b/libs/FLib/TableLayout/build.xml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+
+ + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/libs/FLib/TableLayout/doc-templates/License.html b/libs/FLib/TableLayout/doc-templates/License.html new file mode 100644 index 0000000..d5fbdc1 --- /dev/null +++ b/libs/FLib/TableLayout/doc-templates/License.html @@ -0,0 +1,180 @@ + + + + + + +

Artistic License

+ +

Preamble

+ +

The intent of this document is to state the conditions under which a + Package may be copied, such that the Copyright Holder maintains some + semblance of artistic control over the development of the package, + while giving the users of the package the right to use and distribute + the Package in a more-or-less customary fashion, plus the right to + make reasonable modifications.

+ +

Definitions:

+ + + +
+ +
    + +
  1. You may make and give away verbatim copies of the source form of + the Standard Version of this Package without restriction, provided + that you duplicate all of the original copyright notices and + associated disclaimers.
  2. + +
  3. You may apply bug fixes, portability fixes and other modifications + derived from the Public Domain or from the Copyright Holder. A Package + modified in such a way shall still be considered the Standard + Version.
  4. + +
  5. You may otherwise modify your copy of this Package in any way, + provided that you insert a prominent notice in each changed file + stating how and when you changed that file, and provided that you do + at least ONE of the following: + +
      + +
    1. place your modifications in the Public Domain or otherwise make + them Freely Available, such as by posting said modifications to Usenet + or an equivalent medium, or placing the modifications on a major + archive site such as ftp.uu.net, or by allowing the Copyright Holder + to include your modifications in the Standard Version of the Package.
    2. + +
    3. use the modified Package only within your corporation or + organization.
    4. + +
    5. rename any non-standard executables so the names do not conflict + with standard executables, which must also be provided, and provide a + separate manual page for each non-standard executable that clearly + documents how it differs from the Standard Version.
    6. + +
    7. make other distribution arrangements with the Copyright + Holder.
    8. + +
    +
  6. + +
  7. You may distribute the programs of this Package in object code or + executable form, provided that you do at least ONE of the following: + +
      + +
    1. distribute a Standard Version of the executables and library + files, together with instructions (in the manual page or equivalent) + on where to get the Standard Version.
    2. + +
    3. accompany the distribution with the machine-readable source of the + Package with your modifications.
    4. + +
    5. accompany any non-standard executables with their corresponding + Standard Version executables, giving the non-standard executables + non-standard names, and clearly documenting the differences in manual + pages (or equivalent), together with instructions on where to get the + Standard Version.
    6. + +
    7. make other distribution arrangements with the Copyright + Holder.
    8. + +
    +
  8. + +
  9. You may charge a reasonable copying fee for any distribution of + this Package. You may charge any fee you choose for support of this + Package. You may not charge a fee for this Package itself. However, + you may distribute this Package in aggregate with other (possibly + commercial) programs as part of a larger (possibly commercial) + software distribution provided that you do not advertise this Package + as a product of your own.
  10. + +
  11. The scripts and library files supplied as input to or produced as + output from the programs of this Package do not automatically fall + under the copyright of this Package, but belong to whomever generated + them, and may be sold commercially, and may be aggregatedwith this + Package.
  12. + +
  13. r perl subroutines supplied by you and linked into this Package + shall not be considered part of this Package.
  14. + +
  15. Aggregation of this Package with a commercial distribution is + always permitted provided that the use of this Package is embedded; + that is, when no overt attempt is made to make this Package's + interfaces visible to the end user of the commercial distribution. + Such use shall not be construed as a distribution of this Package.
  16. + +
  17. The name of the Copyright Holder may not be used to endorse or + promote products derived from this software without specific prior + written permission.
  18. + +
  19. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + PURPOSE.
  20. + +
+ +

The End

+ + diff --git a/libs/FLib/TableLayout/doc/example/Example1.java b/libs/FLib/TableLayout/doc/example/Example1.java new file mode 100644 index 0000000..797d1e7 --- /dev/null +++ b/libs/FLib/TableLayout/doc/example/Example1.java @@ -0,0 +1,180 @@ +//********************************************************************** +// Package +//********************************************************************** + +package doc.example; + +//********************************************************************** +// Import list +//********************************************************************** + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import org.freixas.tablelayout.*; + +/** + * This example compares the GridBagLayout to the TableLayout. The + * same layout is created using each layout manager. The layouts are + * displayed in their own window. + * + * @author Antonio Freixas + */ + +// Copyright © 2004 Antonio Freixas +// All Rights Reserved. + +public class Example1 +{ + +//********************************************************************** +// Public Constants +//********************************************************************** + +//********************************************************************** +// Private Constants +//********************************************************************** + +//********************************************************************** +// Private Members +//********************************************************************** + +//********************************************************************** +// main +//********************************************************************** + +public static void +main( + String[] args) +{ + new Example1(); +} + +//********************************************************************** +// Constructors +//********************************************************************** + +/** + * 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); +} + +//********************************************************************** +// 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; +} + +} diff --git a/libs/FLib/TableLayout/doc/example/TableExplorer.java b/libs/FLib/TableLayout/doc/example/TableExplorer.java new file mode 100644 index 0000000..d66c497 --- /dev/null +++ b/libs/FLib/TableLayout/doc/example/TableExplorer.java @@ -0,0 +1,1230 @@ +//********************************************************************** +// Package +//********************************************************************** + +package doc.example; + +//********************************************************************** +// Import list +//********************************************************************** + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import org.freixas.tablelayout.*; + +/** + * This class allows a user to dynamically alter a set of components + * using the TableLayout class to explore the layout's abilities. + * + * @author Antonio Freixas + */ + +public class TableExplorer + 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[] tableFillList = { + "Default", "tfh", "tfv", "tf" +}; + +static final String[] positionList = { + "Default", + "n", "ne", "nw", + "s", "se", "sw", + "e", "w", "c" +}; + +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; + +//********************************************************************** +// Main +//********************************************************************** + +static public void +main( + String[] args) +{ + new TableExplorer(); +} + +//********************************************************************** +// Constructors +//********************************************************************** + +/** + * Create the TableExplorer JFrame. + */ + +TableExplorer() +{ + super("TableExplorer"); + + // Table with three columns + // Row 1: Buttons for managing component list + // Row 2: Component list + // Row 3: Attribute settings + + setJMenuBar(createJMenuBar()); + + 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"); + + pack(); + setVisible(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(); + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + compEntryField.grabFocus(); + + 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(); + } + } + + 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, + "" + + "

Table Explorer V1.0

" + + "Written by Antonio Freixas
" + + "tonyf@freixas.org", + "About Table Explorer
", + 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); + + exitItem = new JMenuItem("Exit"); + exitItem.addActionListener(this); + fileMenu.add(exitItem); + + previewItem = new JMenuItem("Show Preview Window"); + previewItem.addActionListener(this); + windowMenu.add(previewItem); + + packItem = new JMenuItem("Pack Preview Window"); + packItem.addActionListener(this); + windowMenu.add(packItem); + + windowMenu.add(new JSeparator()); + + codeItem = new JMenuItem("Show Code Window"); + codeItem.addActionListener(this); + windowMenu.add(codeItem); + + generateItem = new JMenuItem("Generate Code"); + generateItem.addActionListener(this); + windowMenu.add(generateItem); + + aboutItem = new JMenuItem("About TableExplorer..."); + aboutItem.addActionListener(this); + helpMenu.add(aboutItem); + + return menuBar; +} + +Component +createButtonPane() +{ + JPanel topLevel = new JPanel(new TableLayout("cols=1")); + + upButton = new JButton("Up"); + upButton.setEnabled(false); + upButton.addActionListener(this); + + downButton = new JButton("Down"); + downButton.setEnabled(false); + downButton.addActionListener(this); + + removeButton = new JButton("Remove"); + removeButton.setEnabled(false); + removeButton.addActionListener(this); + + addButton = new JButton("Add"); + addButton.addActionListener(this); + + topLevel.add(upButton); + topLevel.add(downButton, "rweight=1 n fh"); + topLevel.add(removeButton, "rweight=1 s fh "); + topLevel.add(addButton); + + return topLevel; +} + +Component +createListPane() +{ + JPanel topLevel = new JPanel(new TableLayout("cols=1 rgap=2")); + + compListModel = new DefaultListModel(); + compList = new JList(compListModel); + compList.setVisibleRowCount(20); + compList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + compList.addListSelectionListener(this); + + compEntryField = new JTextField("Start Here!"); + compEntryField.selectAll(); + compEntryField.setColumns(20); + compEntryField.addCaretListener(this); + compEntryField.addActionListener(this); + + topLevel.add(compList, "rweight=1"); + topLevel.add(compEntryField); + + return topLevel; +} + +Component +createAttributePane() +{ + JPanel topLevel = new JPanel(new TableLayout("cols=3 rgap=2 cgap=5")); + + // Table Attributes + + topLevel.add(new JLabel("Table Attributes"), "cspan=3"); + + 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("Table insets"), "col=1"); + topLevel.add(createInsetsPane(tableInsetFields)); + + 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); + + 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; +} + +Component +createInsetsPane( + JTextField[] insetFields) +{ + JPanel topLevel = new JPanel(new TableLayout("cols=3")); + + for (int i = 0; i < 4; i++) { + insetFields[i] = new JTextField(2); + insetFields[i].addActionListener(this); + insetFields[i].addFocusListener(this); + } + + topLevel.add(insetFields[0], "col=1"); + topLevel.add(insetFields[1], "col=0"); + topLevel.add(insetFields[2], "col=2"); + topLevel.add(insetFields[3], "col=1"); + + return topLevel; +} + +JPanel +createCodePane() +{ + JPanel topLevel = new JPanel(new TableLayout("cols=2 rgap=2 cgap=5")); + + codeTextArea = new JTextArea(15, 30); + codeTextScroll = new JScrollPane(codeTextArea); + topLevel.add(codeTextScroll, "cspan=2 rweight=1"); + + return topLevel; +} + +void +addToLayout( + Component c) +{ + try { + layoutPane.add(c); + } + catch (IllegalArgumentException e) { + JOptionPane.showMessageDialog( + this, e.toString(), "Attribute Error", JOptionPane.ERROR_MESSAGE); + } + layoutPane.revalidate(); +} + +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(); +} + +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 +} + +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); + } + 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)); + + 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; +} + +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; +} + +String +getString( + JComboBox box) +{ + return (String)box.getSelectedItem(); +} + +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); + } +} + +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 +//********************************************************************** + +//********************************************************************** +// Private +//********************************************************************** + +//********************************************************************** +// Inner Classes +//********************************************************************** + +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"; + +// 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(); + + 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); +} + +} + +//********************************************************************** +// End Inner Classes +//********************************************************************** + +} diff --git a/libs/FLib/TableLayout/doc/examples.html b/libs/FLib/TableLayout/doc/examples.html new file mode 100644 index 0000000..7f8217f --- /dev/null +++ b/libs/FLib/TableLayout/doc/examples.html @@ -0,0 +1,76 @@ + + + + + +TableLayout - Examples + + + + + + + + +

+ + + +
+

Examples

+

There are two example programs provided for TableLayout.

+

The Example1 program compares TableLayout + with GridBagLayout. It uses the code found on the API page for GridBagLayout + and then adds code to create + the equivalent layout using TableLayout.

+

I hope the TableLayout version is much easier to understand. It's definitely + a lot shorter!

+

The second program is called + TableExplorer. While you are + free to examine the code, it is really a tool you run to learn how to + use the TableLayout.

+

If you download the FLib source, you can use Ant to build and run + the example programs:

+
cd TableLayout
+ant runExample1
+ant runTableExplorer
+

The Example1 class will display two windows, one created using GridBagLayout + and the other using TableLayout. You can resize the windows to verify + that + the behavior + is + identical.

+

When you run the TableExplorer program, it will display a text field + at the bottom with the words "Start Here!" and an Add button + next to it. You create JButton components by entering the component name + (which + also + becomes its label) and pressing the Add button. Each component added + shows up in the list above the text field.

+

Selecting Window / Show Preview Window from the menu will bring up a + window containing the JButtons. You can then set the table attributes +