Example usage for javax.swing JTabbedPane getPreferredSize

List of usage examples for javax.swing JTabbedPane getPreferredSize

Introduction

In this page you can find the example usage for javax.swing JTabbedPane getPreferredSize.

Prototype

@Transient
public Dimension getPreferredSize() 

Source Link

Document

If the preferredSize has been set to a non-null value just returns it.

Usage

From source file:edu.ku.brc.specify.plugins.latlon.LatLonUI.java

/**
 * Creates the UI.//  w  ww . jav  a2s.c o m
 * @param localityCEP the locality object (can be null)
 */
protected void createEditUI() {
    loadAndPushResourceBundle("specify_plugins");

    PanelBuilder builder = new PanelBuilder(new FormLayout("p", "p, 2px, p"), this);

    Color bgColor = getBackground();
    bgColor = new Color(Math.min(bgColor.getRed() + 20, 255), Math.min(bgColor.getGreen() + 20, 255),
            Math.min(bgColor.getBlue() + 20, 255));
    //System.out.println(bgColor);
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(bgColor),
            BorderFactory.createEmptyBorder(4, 4, 4, 4)));

    for (int i = 0; i < types.length; i++) {
        typeMapper.put(types[i], typeStrs[i]);
    }

    currentType = LatLonUIIFace.LatLonType.LLPoint;

    pointImages = new ImageIcon[pointNames.length];
    for (int i = 0; i < pointNames.length; i++) {
        pointImages[i] = IconManager.getIcon(pointNames[i], IconManager.IconSize.Std16);
    }

    String[] formatLabels = new String[formats.length];
    for (int i = 0; i < formats.length; i++) {
        formatLabels[i] = getResourceString(formats[i]);
    }
    cardPanel = new JPanel(cardLayout);
    formatSelector = createComboBox(formatLabels);
    latLonPanes = new JComponent[formatLabels.length];

    formatSelector.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            swapForm(formatSelector.getSelectedIndex(), currentType);

            cardLayout.show(cardPanel, ((JComboBox) ae.getSource()).getSelectedItem().toString());

            //stateChanged(null);
        }
    });

    Dimension preferredSize = new Dimension(0, 0);
    cardSubPanes = new JPanel[formats.length * 2];
    panels = new DDDDPanel[formats.length * 2];
    int paneInx = 0;
    for (int i = 0; i < formats.length; i++) {
        cardSubPanes[i] = new JPanel(new BorderLayout());
        try {
            String packageName = "edu.ku.brc.specify.plugins.latlon.";
            DDDDPanel latLon1 = Class.forName(packageName + formatClass[i]).asSubclass(DDDDPanel.class)
                    .newInstance();
            latLon1.setIsRequired(isRequired);
            latLon1.setViewMode(isViewMode);
            latLon1.init();
            latLon1.setChangeListener(this);

            JPanel panel1 = latLon1;
            panel1.setBorder(panelBorder);
            panels[paneInx++] = latLon1;
            latLonPanes[i] = panel1;

            DDDDPanel latlon2 = Class.forName(packageName + formatClass[i]).asSubclass(DDDDPanel.class)
                    .newInstance();
            latlon2.setIsRequired(isRequired);
            latlon2.setViewMode(isViewMode);
            latlon2.init();
            latlon2.setChangeListener(this);

            panels[paneInx++] = latlon2;

            JTabbedPane tabbedPane = new JTabbedPane(
                    UIHelper.getOSType() == UIHelper.OSTYPE.MacOSX ? SwingConstants.BOTTOM
                            : SwingConstants.RIGHT);
            tabbedPane.addTab(null, pointImages[0], panels[paneInx - 2]);
            tabbedPane.addTab(null, pointImages[0], panels[paneInx - 1]);
            latLonPanes[i] = tabbedPane;

            Dimension size = tabbedPane.getPreferredSize();
            preferredSize.width = Math.max(preferredSize.width, size.width);
            preferredSize.height = Math.max(preferredSize.height, size.height);

            tabbedPane.removeAll();
            cardSubPanes[i].add(panel1, BorderLayout.CENTER);
            cardPanel.add(formatLabels[i], cardSubPanes[i]);

            /*if (locality != null)
            {
            latLon1.set(locality.getLatitude1(), locality.getLongitude1(), locality.getLat1text(), locality.getLong1text());
            latlon2.set(locality.getLatitude2(), locality.getLongitude2(), locality.getLat2text(), locality.getLong2text());
            }*/

        } catch (Exception e) {
            e.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(LatLonUI.class, e);
        }
    }

    // Makes they are all the same size
    for (int i = 0; i < formats.length; i++) {
        cardSubPanes[i].setPreferredSize(preferredSize);
    }

    //final LatLonPanel thisPanel = this;

    PanelBuilder botBtnBar = new PanelBuilder(new FormLayout("p:g,p,10px,p,10px,p,p:g", "p"));

    ButtonGroup btnGroup = new ButtonGroup();
    botBtns = new JToggleButton[typeNames.length];

    if (UIHelper.isMacOS()) {
        /*for (int i=0;i<botBtns.length;i++)
        {
        ImageIcon selIcon   = IconManager.getIcon(typeNames[i]+"Sel", IconManager.IconSize.Std16);
        ImageIcon unselIcon = IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16);
                
        MacIconRadioButton rb = new MacIconRadioButton(selIcon, unselIcon);
        botBtns[i] = rb;
        rb.setBorder(new MacBtnBorder());
                
        Dimension size = rb.getPreferredSize();
        int max = Math.max(size.width, size.height);
        size.setSize(max, max);
        rb.setPreferredSize(size);
        }*/

        BorderedRadioButton.setSelectedBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
        BorderedRadioButton.setUnselectedBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        for (int i = 0; i < botBtns.length; i++) {
            BorderedRadioButton rb = new BorderedRadioButton(
                    IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16));
            botBtns[i] = rb;
            rb.makeSquare();
            rb.setBorder(new MacBtnBorder());
        }
    } else {
        BorderedRadioButton.setSelectedBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
        BorderedRadioButton.setUnselectedBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        for (int i = 0; i < botBtns.length; i++) {
            BorderedRadioButton rb = new BorderedRadioButton(
                    IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16));
            botBtns[i] = rb;
            rb.makeSquare();
        }
    }

    for (int i = 0; i < botBtns.length; i++) {
        botBtns[i].setToolTipText(typeToolTips[i]);
        botBtnBar.add(botBtns[i], cc.xy((i * 2) + 2, 1));
        btnGroup.add(botBtns[i]);
        selectedTypeHash.put(botBtns[i], types[i]);

        botBtns[i].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ce) {
                stateChanged(null);
                currentType = selectedTypeHash.get(ce.getSource());
                swapForm(formatSelector.getSelectedIndex(), currentType);
            }
        });
    }
    botBtns[0].setSelected(true);

    if (isViewMode) {
        typeLabel = createLabel(" ");
    }

    ActionListener infoAL = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doPrefs();
        }
    };

    JButton infoBtn = UIHelper.createIconBtn("Preferences", IconManager.IconSize.Std16,
            getResourceString("PREFERENCES"), true, infoAL);
    infoBtn.setEnabled(true);

    PanelBuilder topPane = new PanelBuilder(
            new FormLayout("l:p, c:p:g" + (isViewMode ? "" : ",4px,p,8px"), "p"));
    topPane.add(formatSelector, cc.xy(1, 1));
    topPane.add(isViewMode ? typeLabel : botBtnBar.getPanel(), cc.xy(2, 1));
    if (!isViewMode)
        topPane.add(infoBtn, cc.xy(4, 1));

    builder.add(topPane.getPanel(), cc.xy(1, 1));
    builder.add(cardPanel, cc.xy(1, 3));

    prefsPanel = new PrefsPanel(false);
    prefsPanel.add(getResourceString("LatLonUI.LL_SEP"));
    prefsPanel.add(CompType.eCheckbox, getResourceString("LatLonUI.LATDEF_DIR"), LAT_PREF, Boolean.class, true);
    prefsPanel.add(CompType.eCheckbox, getResourceString("LatLonUI.LONDEF_DIR"), LON_PREF, Boolean.class, true);
    prefsPanel.add(CompType.eComboBox, getResourceString("LatLonUI.DEF_TYP"), TYP_PREF, Integer.class,
            typeNamesLabels, 0);
    prefsPanel.add(CompType.eComboBox, getResourceString("LatLonUI.DEF_FMT"), FMT_PREF, Integer.class,
            formatLabels, 0);
    prefsPanel.createForm(null, null);

    popResourceBundle();
}