Example usage for com.jgoodies.forms.layout CellConstraints FILL

List of usage examples for com.jgoodies.forms.layout CellConstraints FILL

Introduction

In this page you can find the example usage for com.jgoodies.forms.layout CellConstraints FILL.

Prototype

Alignment FILL

To view the source code for com.jgoodies.forms.layout CellConstraints FILL.

Click Source Link

Document

Fill the cell either horizontally or vertically.

Usage

From source file:tvbrowser.extras.reminderplugin.ReminderFrame.java

License:Open Source License

/**
 * Creates a new instance of ReminderFrame.
 *
 * @param list//from  w ww . j  av a2 s  . c  o m
 *          The list of all reminders.
 * @param reminders
 *          The reminders to show.
 * @param autoCloseSecs
 *          The number seconds to wait before auto-closing the window. -1
 *          disables auto-closing.
 */
public ReminderFrame(final ReminderList list, final AbstractList<ReminderListItem> reminders,
        final int autoCloseSecs) {
    mGlobalReminderList = list;
    mReminderItems = reminders;

    // Check whether we have to use a frame or dialog
    // Workaround: If there is a modal dialog open a frame is not usable. All
    //             user interaction will be ignored.
    //             -> If there is a modal dialog open, we show this reminder as
    //                dialog, otherwise as frame.
    final Window parent = UiUtilities.getLastModalChildOf(MainFrame.getInstance());
    String title = mLocalizer.msg("title", "Reminder");

    // if this is a favorite, change the title to the name of the favorite
    if (reminders.size() == 1) {
        boolean found = false;
        for (Favorite favorite : FavoriteTreeModel.getInstance().getFavoriteArr()) {
            for (Program program : favorite.getPrograms()) {
                if (program.equals(reminders.get(0).getProgram())) {
                    title = favorite.getName();
                    found = true;
                    break;
                }
            }
            if (found) {
                break;
            }
        }
    }

    mDialog = new JDialog(parent, title);
    UiUtilities.registerForClosing(this);

    final JPanel jcontentPane = new JPanel(new BorderLayout(0, 10));
    jcontentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    mDialog.setContentPane(jcontentPane);

    mLayout = new FormLayout("pref:grow,3dlu,pref", "pref,3dlu");
    final PanelBuilder programsPanel = new PanelBuilder(mLayout);
    CellConstraints cc = new CellConstraints();

    final Date today = Date.getCurrentDate();
    programsPanel.add(mHeader = new JLabel(""), cc.xyw(1, 1, 3));
    programsPanel.setRow(3);
    int remainingMinutesMax = 0;

    ArrayList<ProgramPanel> panels = new ArrayList<ProgramPanel>(reminders.size());

    for (ReminderListItem reminder : reminders) {
        Program program = reminder.getProgram();
        mGlobalReminderList.blockProgram(program);
        // text label
        String msg;
        final int progMinutesAfterMidnight = program.getStartTime();
        int remainingMinutes = 0;
        if (today.compareTo(program.getDate()) >= 0
                && IOUtilities.getMinutesAfterMidnight() > progMinutesAfterMidnight) {
            msg = updateRunningTime();
        } else {
            msg = mLocalizer.msg("soonStarts", "Soon starts");
            remainingMinutes = ReminderPlugin.getTimeToProgramStart(program);
        }
        mHeader.setText(msg);
        remainingMinutesMax = Math.max(remainingMinutesMax, remainingMinutes);

        List<JComponent> componentList = new ArrayList<JComponent>();
        mComponents.put(reminder, componentList);

        final ProgramPanel panel = new ProgramPanel(program,
                new ProgramPanelSettings(
                        new PluginPictureSettings(PluginPictureSettings.ALL_PLUGINS_SETTINGS_TYPE), false,
                        ProgramPanelSettings.X_AXIS));
        componentList.add(panel);
        panels.add(panel);
        panel.setMinimumSize(new Dimension(300, 50));
        panel.setWidth(300);
        // register panel with tooltip manager
        panel.setToolTipText("");
        panel.addPluginContextMenuMouseListener(ReminderPluginProxy.getInstance());

        final JPanel channelPanel = new JPanel(new BorderLayout());
        componentList.add(channelPanel);
        if (program.getLength() > 0) {
            final JLabel endTime = new JLabel(
                    mLocalizer.msg("endTime", "until {0}", program.getEndTimeString()));
            channelPanel.add(endTime, BorderLayout.PAGE_START);
        }
        String channelName = program.getChannel().getName();
        JLabel channelLabel = new JLabel();
        channelLabel.setToolTipText(channelName);
        channelLabel.setIcon(UiUtilities.createChannelIcon(program.getChannel().getIcon()));
        channelLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
        channelPanel.add(channelLabel, BorderLayout.CENTER);
        channelLabel = new JLabel(channelName);
        channelPanel.add(channelLabel, BorderLayout.PAGE_END);

        int layoutStartRow = programsPanel.getRowCount();
        mLayout.appendRow(RowSpec.decode("pref"));
        programsPanel.add(panel, cc.xy(1, programsPanel.getRow(), CellConstraints.FILL, CellConstraints.FILL));
        programsPanel.add(channelPanel,
                cc.xy(3, programsPanel.getRow(), CellConstraints.LEFT, CellConstraints.TOP));
        programsPanel.nextRow();

        String comment = reminder.getComment();
        if (comment != null && comment.length() > 0) {
            mLayout.appendRow(RowSpec.decode("2dlu"));
            mLayout.appendRow(RowSpec.decode("pref"));
            mLayout.appendRow(RowSpec.decode("2dlu"));
            JLabel commentLabel = new JLabel(comment);
            componentList.add(commentLabel);
            programsPanel.add(commentLabel, cc.xyw(1, programsPanel.getRow() + 1, 3));
            programsPanel.nextRow(3);
        }
        int layoutEndRow = programsPanel.getRowCount();
        mPanelRange.put(reminder, new Integer[] { layoutStartRow, layoutEndRow });
    }

    // initialize close button with full text, so it can show the countdown later without size problems
    mRemainingSecs = autoCloseSecs;
    mAutoCloseAtMillis = System.currentTimeMillis() + 1000 * autoCloseSecs;
    final JPanel btnPanel = new JPanel(new BorderLayout(10, 0));
    mCloseBtText = Localizer.getLocalization(Localizer.I18N_CLOSE);
    int seconds = mRemainingSecs;
    if (ReminderPlugin.getInstance().getSettings().getProperty("showTimeCounter", "false")
            .compareTo("true") == 0) {
        seconds = 10;
    }
    mCloseBt = new JButton(getCloseButtonText(seconds));
    mDialog.getRootPane().setDefaultButton(mCloseBt);

    for (ReminderListItem reminder : reminders) {
        if (reminder.getMinutes() < remainingMinutesMax) {
            remainingMinutesMax = reminder.getMinutes();
        }
    }

    mReminderCB = new JComboBox();
    int i = 0;
    while (i < REMIND_VALUE_ARR.length && REMIND_VALUE_ARR[i] < remainingMinutesMax) {
        mReminderCB.addItem(REMIND_MSG_ARR[i]);
        i++;
    }
    // don't show reminder selection if it contains only the
    // entry "don't remind me"
    mReminderCB.setVisible(mReminderCB.getItemCount() > 1);

    btnPanel.add(mReminderCB, BorderLayout.WEST);
    btnPanel.add(mCloseBt, BorderLayout.EAST);

    final JScrollPane scrollPane = new JScrollPane(programsPanel.getPanel());
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    jcontentPane.add(scrollPane, BorderLayout.CENTER);
    jcontentPane.add(btnPanel, BorderLayout.SOUTH);

    mCloseBt.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            close();
        }
    });

    if (mRemainingSecs > 0) {
        updateCloseBtText();
        mAutoCloseTimer = new Timer(1000, new ActionListener() {
            public void actionPerformed(final ActionEvent evt) {
                handleTimerEvent();
            }
        });
        mAutoCloseTimer.start();
    }

    for (ProgramPanel programPanel : panels) {
        programPanel.setMinimumSize(new Dimension(300, 50));
    }
    mDialog.pack();

    mCloseBt.setText(mCloseBtText);
    mDialog.setAlwaysOnTop(ReminderPlugin.getInstance().getSettings().getProperty("alwaysOnTop", "true")
            .equalsIgnoreCase("true"));

    UiUtilities.centerAndShow(mDialog);
    mDialog.toFront();

    if (mDialog.isAlwaysOnTop()) {
        mDialog.addWindowFocusListener(new WindowFocusListener() {
            public void windowGainedFocus(final WindowEvent e) {
            }

            public void windowLostFocus(final WindowEvent e) {
                mDialog.setAlwaysOnTop(false);
                UiUtilities.getLastModalChildOf(MainFrame.getInstance()).toFront();
            }
        });
    }

    mDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    mDialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(final WindowEvent e) {
            close();
        }
    });

    for (ReminderListItem reminder : reminders) {
        reminder.getProgram().addChangeListener(this);
    }
}

From source file:uk.ac.ebi.metingear.preference.PreferencePanel.java

License:Open Source License

public PreferencePanel(final Window window) {

    setLayout(new FormLayout("p, p:grow", "p:grow, p, p:grow"));

    DefaultListModel model = new DefaultListModel();
    final JList category = new JList(model);

    CellConstraints cc = new CellConstraints();

    // off white/*from w w w .  j a  v  a  2s. c om*/
    setBackground(new Color(240, 240, 240));

    category.setBackground(new Color(234, 237, 243));
    category.setPreferredSize(new Dimension(200, 150));
    category.setFixedCellHeight(40);
    category.setCellRenderer(new MyListRenderer());

    model.addElement("Resources");
    model.addElement("General");
    model.addElement("Rendering");
    model.addElement("Tools");

    category.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            CardLayout layout = (CardLayout) options.getLayout();
            layout.show(options, (String) category.getSelectedValue());
        }
    });

    JPanel topfill = new JPanel();
    JPanel bottomfill = new JPanel();
    topfill.setBackground(new Color(234, 237, 243));
    bottomfill.setBackground(new Color(234, 237, 243));

    add(topfill, cc.xy(1, 1, CellConstraints.FILL, CellConstraints.FILL));
    add(category, cc.xy(1, 2, CellConstraints.FILL, CellConstraints.FILL));
    add(bottomfill, cc.xy(1, 3, CellConstraints.FILL, CellConstraints.FILL));

    category.setMaximumSize(new Dimension(50, 2000));

    options.setLayout(new CardLayout());
    options.setBackground(Color.WHITE);

    Multimap<String, Preference> map = ComponentPreferences.getInstance().getCategoryMap();

    options.add(new CenteringPanel(new GeneralPanel()), "General");
    options.add(new CenteringPanel(PreferencePanelFactory.getPreferencePanel(map.get("Rendering"))),
            "Rendering");
    options.add(new CenteringPanel(new ResourceLoading(window)), "Resources");
    options.add(new CenteringPanel(new Tools()), "Tools");

    add(new JScrollPane(options), cc.xywh(2, 1, 1, 3));

    category.setSelectedValue("Resources", true);

}

From source file:uk.ac.ebi.mnb.core.ExpandableComponentGroup.java

License:Open Source License

public ExpandableComponentGroup(String name, JComponent component, JDialog root) {
    setLayout(new FormLayout("p:grow", "min, 2dlu, p:grow"));
    excomp = new ExpandComponent(component, root);
    button = new ExpandButton(excomp);

    Box controller = Box.createHorizontalBox();

    button.setSelected(false);//  w w  w.j  ava2 s  .  c o m

    JLabel label = LabelFactory.newLabel(name);
    label.setVerticalAlignment(JLabel.CENTER);

    CellConstraints cc = new CellConstraints();

    controller.add(button);
    controller.add(Box.createRigidArea(new Dimension(16, 16)));
    controller.add(label);
    controller.add(Box.createGlue());

    JSeparator separator = new JSeparator();

    controller.add(separator);

    add(controller, cc.xy(1, 1));
    add(component, cc.xy(1, 3, CellConstraints.FILL, CellConstraints.FILL));

    component.setVisible(false);

}

From source file:uk.ac.ebi.mnb.dialog.tools.DownloadStructuresDialog.java

License:Open Source License

public JPanel getForm() {
    JPanel panel = super.getForm();
    CellConstraints cc = new CellConstraints();

    panel.setLayout(new FormLayout("right:p, 4dlu,    left:p:grow", "p, 4dlu, p, 4dlu, top:p:grow"));

    panel.add(allowWebServiceLabel, cc.xy(1, 1));
    panel.add(ws, cc.xy(3, 1));//from   w w  w .ja  va 2  s.  c  o  m
    panel.add(fetchAllLabel, cc.xy(1, 3));
    panel.add(fetchAll, cc.xy(3, 3));

    panel.add(LabelFactory.newFormLabel("Resource Priority:"), cc.xy(1, 5));
    panel.add(new MutableJListController(resourceSelection).getListWithController(),
            cc.xy(3, 5, CellConstraints.FILL, CellConstraints.FILL));

    return panel;
}

From source file:uk.ac.ebi.mnb.importer.xls.wizzard.ReactionColumnChooser.java

License:Open Source License

public ReactionColumnChooser(ExcelHelper helper, ExcelModelProperties properties) {
    super();/*ww  w .  java 2  s. co m*/

    this.helper = helper;
    this.properties = properties;

    columns.add("-"); // no selection
    for (char c = 'A'; c <= 'Z'; ++c) {
        columns.add(Character.toString(c));
    }

    start = new JSpinner(new SpinnerNumberModel(1, 1, 4000, 1));
    end = new JSpinner(new SpinnerNumberModel(1, 1, 4000, 1));

    abbreviation = ComboBoxFactory.newComboBox(columns);
    description = ComboBoxFactory.newComboBox(columns);

    equation = ComboBoxFactory.newComboBox(columns);
    classification = ComboBoxFactory.newComboBox(columns);

    subsystem = ComboBoxFactory.newComboBox(columns);
    source = ComboBoxFactory.newComboBox(columns);

    locus = ComboBoxFactory.newComboBox(columns);

    FormLayout layout = new FormLayout("right:p:grow, 4dlu, min, 4dlu, right:p:grow, 4dlu, min", "p");

    // content panel
    setLayout(layout);

    removeAll();

    add(LabelFactory.newFormLabel("Start Row"), cc.xy(1, layout.getRowCount()));
    add(start, cc.xy(3, layout.getRowCount()));
    add(LabelFactory.newFormLabel("End Row"), cc.xy(5, layout.getRowCount()));
    add(end, cc.xy(7, layout.getRowCount()));

    layout.appendRow(new RowSpec(Sizes.DLUY2));
    layout.appendRow(new RowSpec(Sizes.PREFERRED));

    add(new JSeparator(), cc.xyw(1, layout.getRowCount(), 7));

    layout.appendRow(new RowSpec(Sizes.DLUY2));
    layout.appendRow(new RowSpec(Sizes.PREFERRED));

    add(LabelFactory.newFormLabel("Identifier/Abbreviation"), cc.xy(1, layout.getRowCount()));
    add(abbreviation, cc.xy(3, layout.getRowCount()));
    add(LabelFactory.newFormLabel("Name/Description"), cc.xy(5, layout.getRowCount()));
    add(description, cc.xy(7, layout.getRowCount()));

    layout.appendRow(new RowSpec(Sizes.DLUY2));
    layout.appendRow(new RowSpec(Sizes.PREFERRED));

    add(LabelFactory.newFormLabel("Reaction Equation"), cc.xy(1, layout.getRowCount()));
    add(equation, cc.xy(3, layout.getRowCount()));
    add(LabelFactory.newFormLabel("Classification (EC/TC Number)"), cc.xy(5, layout.getRowCount()));
    add(classification, cc.xy(7, layout.getRowCount()));

    layout.appendRow(new RowSpec(Sizes.DLUY2));
    layout.appendRow(new RowSpec(Sizes.PREFERRED));

    add(LabelFactory.newFormLabel("Subsystem/Reaction type"), cc.xy(1, layout.getRowCount()));
    add(subsystem, cc.xy(3, layout.getRowCount()));
    add(LabelFactory.newFormLabel("Source/Reference:"), cc.xy(5, layout.getRowCount()));
    add(source, cc.xy(7, layout.getRowCount()));

    layout.appendRow(new RowSpec(Sizes.DLUY2));
    layout.appendRow(new RowSpec(Sizes.PREFERRED));

    add(LabelFactory.newFormLabel("Locus"), cc.xy(1, layout.getRowCount()));
    add(locus, cc.xy(3, layout.getRowCount()));

    layout.appendRow(new RowSpec(Sizes.DLUY2));
    layout.appendRow(new RowSpec(Sizes.PREFERRED));

    JPanel extra = PanelFactory.createDialogPanel("right:p:grow, 4dlu, min, 4dlu, right:p:grow, 4dlu, min",
            "p, 2dlu, p, 2dlu, p");

    deltaG = ComboBoxFactory.newComboBox(columns);
    deltaGError = ComboBoxFactory.newComboBox(columns);
    minFlux = ComboBoxFactory.newComboBox(columns);
    maxFlux = ComboBoxFactory.newComboBox(columns);
    direction = ComboBoxFactory.newComboBox(columns);

    extra.add(LabelFactory.newFormLabel("Free energy / G"), cc.xy(1, 1));
    extra.add(deltaG, cc.xy(3, 1));
    extra.add(LabelFactory.newFormLabel("Free energy / G (error)"), cc.xy(5, 1));
    extra.add(deltaGError, cc.xy(7, 1));

    extra.add(LabelFactory.newFormLabel("Lower Bound Flux"), cc.xy(1, 3));
    extra.add(minFlux, cc.xy(3, 3));
    extra.add(LabelFactory.newFormLabel("Upper Bound Flux"), cc.xy(5, 3));
    extra.add(maxFlux, cc.xy(7, 3));

    extra.add(LabelFactory.newFormLabel("Direction"), cc.xy(1, 5));
    extra.add(direction, cc.xy(3, 5));

    add(new ExpandableComponentGroup("Extra Columns", extra),
            cc.xyw(1, layout.getRowCount(), 7, CellConstraints.FILL, CellConstraints.FILL));

    layout.appendRow(new RowSpec(Sizes.DLUY2));
    layout.appendRow(new RowSpec(Sizes.PREFERRED));

    add(new JSeparator(), cc.xyw(1, layout.getRowCount(), 7));

    layout.appendRow(new RowSpec(Sizes.DLUY2));
    layout.appendRow(new RowSpec(Sizes.PREFERRED));

    table = new SelectionTable(helper);

    JScrollPane pane = new BorderlessScrollPane(table, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    RowNumberTable rnt = new RowNumberTable(table);
    pane.setRowHeaderView(rnt);
    pane.setCorner(JScrollPane.UPPER_LEFT_CORNER, rnt.getTableHeader());
    pane.setPreferredSize(new Dimension(800, table.getRowHeight() * 10));
    add(pane, cc.xyw(1, layout.getRowCount(), 7));

    // set previous selections
    Preferences pref = Preferences.userNodeForPackage(ReactionColumnChooser.class);
    start.setValue(pref.getInt(properties.getPreferenceKey("rxn.start"), 1));
    end.setValue(pref.getInt(properties.getPreferenceKey("rxn.end"), 10));
    abbreviation.setSelectedIndex(pref.getInt(properties.getPreferenceKey(ABBREVIATION), 0));
    description.setSelectedIndex(pref.getInt(properties.getPreferenceKey(DESCRIPTION), 0));
    equation.setSelectedIndex(pref.getInt(properties.getPreferenceKey(EQUATION), 0));
    classification.setSelectedIndex(pref.getInt(properties.getPreferenceKey(CLASSIFICATION), 0));
    subsystem.setSelectedIndex(pref.getInt(properties.getPreferenceKey(SUBSYSTEM), 0));
    source.setSelectedIndex(pref.getInt(properties.getPreferenceKey(SOURCE), 0));
    locus.setSelectedIndex(pref.getInt(properties.getPreferenceKey(LOCUS), 0));
    minFlux.setSelectedIndex(pref.getInt(properties.getPreferenceKey(MIN_FLUX), 0));
    maxFlux.setSelectedIndex(pref.getInt(properties.getPreferenceKey(MAX_FLUX), 0));
    deltaG.setSelectedIndex(pref.getInt(properties.getPreferenceKey(FREE_ENERGY), 0));
    deltaGError.setSelectedIndex(pref.getInt(properties.getPreferenceKey(FREE_ENERGY_ERROR), 0));
    direction.setSelectedIndex(pref.getInt(properties.getPreferenceKey(DIRECTION), 0));

    // listeners to change table header name
    abbreviation.addActionListener(new TableHeaderChanger(abbreviation, "Abbreviation"));
    description.addActionListener(new TableHeaderChanger(description, "Description"));
    equation.addActionListener(new TableHeaderChanger(equation, "Equation"));
    classification.addActionListener(new TableHeaderChanger(classification, "Classification"));
    source.addActionListener(new TableHeaderChanger(source, "Source"));
    subsystem.addActionListener(new TableHeaderChanger(subsystem, "Subsystem"));

    // Spinner listeners for shading the table
    start.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent ce) {
            table.setStart((Integer) start.getValue());
            repaint();
        }
    });
    end.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent ce) {
            table.setEnd((Integer) end.getValue());
            repaint();
        }
    });

}