001/* 002 * Copyright (c) 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved. 003 * 004 * Redistribution and use in source and binary forms, with or without 005 * modification, are permitted provided that the following conditions are met: 006 * 007 * o Redistributions of source code must retain the above copyright notice, 008 * this list of conditions and the following disclaimer. 009 * 010 * o Redistributions in binary form must reproduce the above copyright notice, 011 * this list of conditions and the following disclaimer in the documentation 012 * and/or other materials provided with the distribution. 013 * 014 * o Neither the name of JGoodies Karsten Lentzsch nor the names of 015 * its contributors may be used to endorse or promote products derived 016 * from this software without specific prior written permission. 017 * 018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 020 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 021 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 022 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 024 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 025 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 026 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 027 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 028 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030 031package com.jgoodies.forms.factories; 032 033import javax.swing.JComponent; 034import javax.swing.JLabel; 035 036/** 037 * An interface that defines the factory methods as used by the 038 * {@link com.jgoodies.forms.builder.PanelBuilder} and its subclasses. 039 * 040 * <p>The String arguments passed to the methods <code>#createLabel(String)</code>, 041 * <code>#createTitle(String)</code>, and 042 * <code>#createSeparator(String, int)</code> can contain an optional 043 * mnemonic marker. The mnemonic and mnemonic index are indicated 044 * by a single ampersand (<tt>&</tt>). For example 045 * <tt>"&Save"</tt>, or <tt>"Save &as"</tt>. 046 * To use the ampersand itself duplicate it, for example 047 * <tt>"Look&&Feel"</tt>.</p> 048 * 049 * @author Karsten Lentzsch 050 * @version $Revision$ 051 * 052 * @see DefaultComponentFactory 053 * @see com.jgoodies.forms.builder.PanelBuilder 054 */ 055 056public interface ComponentFactory { 057 058 /** 059 * Creates and returns a label with an optional mnemonic. 060 * 061 * <pre> 062 * createLabel("Name"); // No mnemonic 063 * createLabel("N&ame"); // Mnemonic is 'a' 064 * createLabel("Save &as"); // Mnemonic is the second 'a' 065 * createLabel("Look&&Feel"); // No mnemonic, text is Look&Feel 066 * </pre> 067 * 068 * @param textWithMnemonic the label's text - 069 * may contain an ampersand (<tt>&</tt>) to mark a mnemonic 070 * @return an label with optional mnemonic 071 */ 072 public JLabel createLabel(String textWithMnemonic); 073 074 /** 075 * Creates and returns a title label that uses the foreground color 076 * and font of a <code>TitledBorder</code>. 077 * 078 * <pre> 079 * createTitle("Name"); // No mnemonic 080 * createTitle("N&ame"); // Mnemonic is 'a' 081 * createTitle("Save &as"); // Mnemonic is the second 'a' 082 * createTitle("Look&&Feel"); // No mnemonic, text is Look&Feel 083 * </pre> 084 * 085 * @param textWithMnemonic the label's text - 086 * may contain an ampersand (<tt>&</tt>) to mark a mnemonic 087 * @return an emphasized title label 088 */ 089 public JLabel createTitle(String textWithMnemonic); 090 091 /** 092 * Creates and returns a labeled separator. Useful to separate 093 * paragraphs in a panel, which is often a better choice than a 094 * <code>TitledBorder</code>. 095 * 096 * <pre> 097 * final int LEFT = SwingConstants.LEFT; 098 * createSeparator("Name", LEFT); // No mnemonic 099 * createSeparator("N&ame", LEFT); // Mnemonic is 'a' 100 * createSeparator("Save &as", LEFT); // Mnemonic is the second 'a' 101 * createSeparator("Look&&Feel", LEFT); // No mnemonic, text is Look&Feel 102 * </pre> 103 * 104 * @param textWithMnemonic the label's text - 105 * may contain an ampersand (<tt>&</tt>) to mark a mnemonic 106 * @param alignment text alignment, one of <code>SwingConstants.LEFT</code>, 107 * <code>SwingConstants.CENTER</code>, <code>SwingConstants.RIGHT</code> 108 * @return a title label with separator on the side 109 */ 110 public JComponent createSeparator(String textWithMnemonic, int alignment); 111 112}