Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012-2014 Erwin Müller <erwin.mueller@deventm.org>
   *
   * This file is part of prefdialog-core.
   *
   * prefdialog-core is free software: you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as published by the
   * Free Software Foundation, either version 3 of the License, or (at your
   * option) any later version.
  *
  * prefdialog-core is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  * details.
  *
  * You should have received a copy of the GNU Lesser General Public License
  * along with prefdialog-core. If not, see <http://www.gnu.org/licenses/>.
  */
 package com.anrisoftware.prefdialog.core;
 
 import static info.clearthought.layout.TableLayoutConstants.FILL;
 import static info.clearthought.layout.TableLayoutConstants.PREFERRED;
 import static java.lang.String.format;
 import static org.apache.commons.lang3.StringUtils.isEmpty;
 
 
 
Sets a title label on top of the field. The title can show the icon if the correct text position is set.

Author(s):
Erwin Mueller, erwin.mueller@deventm.org
Since:
1.0
See also:
AbstractContainerField
 
 @SuppressWarnings("serial")
 public abstract class AbstractTitleField<ComponentType extends Component>
         extends AbstractContainerField<ComponentType> {

    
Suffix for the title label for the field. The name of the title label will be <name>-title, <name> is the name of the field.
 
     public static final String TITLE_NAME = "title";
 
     private final JLabel titleLabel;
 
     private final TableLayout layout;

    
 
     protected AbstractTitleField(ComponentType componentObject parentObject,
             String fieldName) {
         super(componentparentObjectfieldName);
         this. = new JLabel("(title):");
         this. = createLayout();
         setup();
     }
 
     private void setup() {
         setupContainer();
         setupTitleLabel();
     }
 
     private void setupContainer() {
         Container container = getContainer();
         container.removeAll();
         container.setLayout();
         container.add("0, 0");
         container.add(getComponent(), "0, 1");
     }
 
     private TableLayout createLayout() {
         double[] col = {  };
         double[] row = {  };
         return new TableLayout(colrow);
     }
 
     private void setupTitleLabel() {
         .setLabelFor(getComponent());
     }

    
Sets the name of the title label to <name>- TITLE_NAME, with <name> being the name of the component.
    @Override
    public void setName(String name) {
        super.setName(name);
        .setName(format("%s-%s"name));
    }
    @Override
    public void setMnemonic(int mnemonic) {
        super.setMnemonic(mnemonic);
        .setDisplayedMnemonic(mnemonic);
    }
    @Override
    public void setMnemonicIndex(int index) {
        super.setMnemonicIndex(index);
        if (.getText() != null) {
            .setDisplayedMnemonicIndex(index);
        }
    }

    
Enabled or disables the title label with the component.
    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        .setEnabled(enabled);
    }
    @Override
    public void setTitlePosition(TextPosition position) {
        super.setTitlePosition(position);
        switch (position) {
        case :
            .setText(null);
            break;
        case :
            updateTitleResource();
            updateIconResource();
            break;
        case :
            updateTitleResource();
            .setIcon(null);
            break;
        case :
            updateIconResource();
            updateTitleResource();
            break;
        default:
            break;
        }
    }
    @Override
    public void setIconSize(IconSize size) {
        super.setIconSize(size);
        updateIconResource();
    }
    @Override
    public void setLocale(Locale locale) {
        super.setLocale(locale);
        updateTextsResources();
        updateIconResource();
    }
    @Override
    public void setImages(Images images) {
        super.setImages(images);
        updateIconResource();
    }
    private void updateIconResource() {
        .setIcon(getIcon());
    }
    @Override
    public void setTexts(Texts texts) {
        super.setTexts(texts);
        updateTextsResources();
    }
    private void updateTextsResources() {
        updateTitleResource();
    }
    private void updateTitleResource() {
        if (isShowTitle()) {
            .setText(getTitleLabelText());
            updateMnemonic();
        } else {
            .setText(null);
        }
    }
    private void updateMnemonic() {
        Integer mnemonic = getMnemonic();
        if (mnemonic != null) {
            .setDisplayedMnemonic(mnemonic);
        }
        int index = getMnemonicIndex();
        if (index != -1) {
            .setDisplayedMnemonicIndex(index);
        }
    }
    public String getTitleLabelText() {
        return appendColumn(getTitle());
    }
    private String appendColumn(String text) {
        if (!isEmpty(text) && !text.endsWith(":")) {
            text = text + ":";
        }
        return text;
    }

    
Returns the title label for styling.

Returns:
the javax.swing.JLabel title label.
    public JLabel getTitleLabel() {
        return ;
    }
    @Override
    public void setContainer(JPanel container) {
        super.setContainer(container);
        setupContainer();
    }
    @Override
    public void setComponent(ComponentType component) {
        super.setComponent(component);
        setupContainer();
    }
New to GrepCode? Check out our FAQ X