Example usage for javax.swing JPanel getComponentCount

List of usage examples for javax.swing JPanel getComponentCount

Introduction

In this page you can find the example usage for javax.swing JPanel getComponentCount.

Prototype

public int getComponentCount() 

Source Link

Document

Gets the number of components in this panel.

Usage

From source file:ffx.ui.ModelingPanel.java

private void loadCommand() {
    synchronized (this) {
        // Force Field X Command
        Element command;/*w  w w.  j  a  v  a2s  .c o m*/
        // Command Options
        NodeList options;
        Element option;
        // Option Values
        NodeList values;
        Element value;
        // Options may be Conditional based on previous Option values (not
        // always supplied)
        NodeList conditionalList;
        Element conditional;
        // JobPanel GUI Components that change based on command
        JPanel optionPanel;
        // Clear the previous components
        commandPanel.removeAll();
        optionsTabbedPane.removeAll();
        conditionals.clear();
        String currentCommand = (String) currentCommandBox.getSelectedItem();
        if (currentCommand == null) {
            commandPanel.validate();
            commandPanel.repaint();
            return;
        }
        command = null;
        for (int i = 0; i < commandList.getLength(); i++) {
            command = (Element) commandList.item(i);
            String name = command.getAttribute("name");
            if (name.equalsIgnoreCase(currentCommand)) {
                break;
            }
        }
        int div = splitPane.getDividerLocation();
        descriptTextArea.setText(currentCommand.toUpperCase() + ": " + command.getAttribute("description"));
        splitPane.setBottomComponent(descriptScrollPane);
        splitPane.setDividerLocation(div);
        // The "action" tells Force Field X what to do when the
        // command finishes
        commandActions = command.getAttribute("action").trim();
        // The "fileType" specifies what file types this command can execute
        // on
        String string = command.getAttribute("fileType").trim();
        String[] types = string.split(" +");
        commandFileTypes.clear();
        for (String type : types) {
            if (type.contains("XYZ")) {
                commandFileTypes.add(FileType.XYZ);
            }
            if (type.contains("INT")) {
                commandFileTypes.add(FileType.INT);
            }
            if (type.contains("ARC")) {
                commandFileTypes.add(FileType.ARC);
            }
            if (type.contains("PDB")) {
                commandFileTypes.add(FileType.PDB);
            }
            if (type.contains("ANY")) {
                commandFileTypes.add(FileType.ANY);
            }
        }
        // Determine what options are available for this command
        options = command.getElementsByTagName("Option");
        int length = options.getLength();
        for (int i = 0; i < length; i++) {
            // This Option will be enabled (isEnabled = true) unless a
            // Conditional disables it
            boolean isEnabled = true;
            option = (Element) options.item(i);
            conditionalList = option.getElementsByTagName("Conditional");
            /*
             * Currently, there can only be 0 or 1 Conditionals per Option
             * There are three types of Conditionals implemented. 1.)
             * Conditional on a previous Option, this option may be
             * available 2.) Conditional on input for this option, a
             * sub-option may be available 3.) Conditional on the presence
             * of keywords, this option may be available
             */
            if (conditionalList != null) {
                conditional = (Element) conditionalList.item(0);
            } else {
                conditional = null;
            }
            // Get the command line flag
            String flag = option.getAttribute("flag").trim();
            // Get the description
            String optionDescript = option.getAttribute("description");
            JTextArea optionTextArea = new JTextArea("  " + optionDescript.trim());
            optionTextArea.setEditable(false);
            optionTextArea.setLineWrap(true);
            optionTextArea.setWrapStyleWord(true);
            optionTextArea.setBorder(etchedBorder);
            // Get the default for this Option (if one exists)
            String defaultOption = option.getAttribute("default");
            // Option Panel
            optionPanel = new JPanel(new BorderLayout());
            optionPanel.add(optionTextArea, BorderLayout.NORTH);
            String swing = option.getAttribute("gui");
            JPanel optionValuesPanel = new JPanel(new FlowLayout());
            optionValuesPanel.setBorder(etchedBorder);
            ButtonGroup bg = null;
            if (swing.equalsIgnoreCase("CHECKBOXES")) {
                // CHECKBOXES allows selection of 1 or more values from a
                // predefined set (Analyze, for example)
                values = option.getElementsByTagName("Value");
                for (int j = 0; j < values.getLength(); j++) {
                    value = (Element) values.item(j);
                    JCheckBox jcb = new JCheckBox(value.getAttribute("name"));
                    jcb.addMouseListener(this);
                    jcb.setName(flag);
                    if (defaultOption != null && jcb.getActionCommand().equalsIgnoreCase(defaultOption)) {
                        jcb.setSelected(true);
                    }
                    optionValuesPanel.add(jcb);
                }
            } else if (swing.equalsIgnoreCase("TEXTFIELD")) {
                // TEXTFIELD takes an arbitrary String as input
                JTextField jtf = new JTextField(20);
                jtf.addMouseListener(this);
                jtf.setName(flag);
                if (defaultOption != null && defaultOption.equals("ATOMS")) {
                    FFXSystem sys = mainPanel.getHierarchy().getActive();
                    if (sys != null) {
                        jtf.setText("" + sys.getAtomList().size());
                    }
                } else if (defaultOption != null) {
                    jtf.setText(defaultOption);
                }
                optionValuesPanel.add(jtf);
            } else if (swing.equalsIgnoreCase("RADIOBUTTONS")) {
                // RADIOBUTTONS allows one choice from a set of predifined
                // values
                bg = new ButtonGroup();
                values = option.getElementsByTagName("Value");
                for (int j = 0; j < values.getLength(); j++) {
                    value = (Element) values.item(j);
                    JRadioButton jrb = new JRadioButton(value.getAttribute("name"));
                    jrb.addMouseListener(this);
                    jrb.setName(flag);
                    bg.add(jrb);
                    if (defaultOption != null && jrb.getActionCommand().equalsIgnoreCase(defaultOption)) {
                        jrb.setSelected(true);
                    }
                    optionValuesPanel.add(jrb);
                }
            } else if (swing.equalsIgnoreCase("PROTEIN")) {
                // Protein allows selection of amino acids for the protein
                // builder
                optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS));
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(getAminoAcidPanel());
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidComboBox.removeAllItems();
                JButton add = new JButton("Edit");
                add.setActionCommand("PROTEIN");
                add.addActionListener(this);
                add.setAlignmentX(Button.CENTER_ALIGNMENT);
                JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidTextField);
                comboPanel.add(add);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton remove = new JButton("Remove");
                add.setMinimumSize(remove.getPreferredSize());
                add.setPreferredSize(remove.getPreferredSize());
                remove.setActionCommand("PROTEIN");
                remove.addActionListener(this);
                remove.setAlignmentX(Button.CENTER_ALIGNMENT);
                comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidComboBox);
                comboPanel.add(remove);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(acidScrollPane);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton reset = new JButton("Reset");
                reset.setActionCommand("PROTEIN");
                reset.addActionListener(this);
                reset.setAlignmentX(Button.CENTER_ALIGNMENT);
                optionValuesPanel.add(reset);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidTextArea.setText("");
                acidTextField.setText("");
            } else if (swing.equalsIgnoreCase("NUCLEIC")) {
                // Nucleic allows selection of nucleic acids for the nucleic
                // acid builder
                optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS));
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(getNucleicAcidPanel());
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidComboBox.removeAllItems();
                JButton add = new JButton("Edit");
                add.setActionCommand("NUCLEIC");
                add.addActionListener(this);
                add.setAlignmentX(Button.CENTER_ALIGNMENT);
                JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidTextField);
                comboPanel.add(add);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton remove = new JButton("Remove");
                add.setMinimumSize(remove.getPreferredSize());
                add.setPreferredSize(remove.getPreferredSize());
                remove.setActionCommand("NUCLEIC");
                remove.addActionListener(this);
                remove.setAlignmentX(Button.CENTER_ALIGNMENT);
                comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidComboBox);
                comboPanel.add(remove);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(acidScrollPane);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton button = new JButton("Reset");
                button.setActionCommand("NUCLEIC");
                button.addActionListener(this);
                button.setAlignmentX(Button.CENTER_ALIGNMENT);
                optionValuesPanel.add(button);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidTextArea.setText("");
                acidTextField.setText("");
            } else if (swing.equalsIgnoreCase("SYSTEMS")) {
                // SYSTEMS allows selection of an open system
                JComboBox<FFXSystem> jcb = new JComboBox<>(mainPanel.getHierarchy().getNonActiveSystems());
                jcb.setSize(jcb.getMaximumSize());
                jcb.addActionListener(this);
                optionValuesPanel.add(jcb);
            }
            // Set up a Conditional for this Option
            if (conditional != null) {
                isEnabled = false;
                String conditionalName = conditional.getAttribute("name");
                String conditionalValues = conditional.getAttribute("value");
                String cDescription = conditional.getAttribute("description");
                String cpostProcess = conditional.getAttribute("postProcess");
                if (conditionalName.toUpperCase().startsWith("KEYWORD")) {
                    optionPanel.setName(conditionalName);
                    String keywords[] = conditionalValues.split(" +");
                    if (activeSystem != null) {
                        Hashtable<String, Keyword> systemKeywords = activeSystem.getKeywords();
                        for (String key : keywords) {
                            if (systemKeywords.containsKey(key.toUpperCase())) {
                                isEnabled = true;
                            }
                        }
                    }
                } else if (conditionalName.toUpperCase().startsWith("VALUE")) {
                    isEnabled = true;
                    // Add listeners to the values of this option so
                    // the conditional options can be disabled/enabled.
                    for (int j = 0; j < optionValuesPanel.getComponentCount(); j++) {
                        JToggleButton jtb = (JToggleButton) optionValuesPanel.getComponent(j);
                        jtb.addActionListener(this);
                        jtb.setActionCommand("Conditional");
                    }
                    JPanel condpanel = new JPanel();
                    condpanel.setBorder(etchedBorder);
                    JLabel condlabel = new JLabel(cDescription);
                    condlabel.setEnabled(false);
                    condlabel.setName(conditionalValues);
                    JTextField condtext = new JTextField(10);
                    condlabel.setLabelFor(condtext);
                    if (cpostProcess != null) {
                        condtext.setName(cpostProcess);
                    }
                    condtext.setEnabled(false);
                    condpanel.add(condlabel);
                    condpanel.add(condtext);
                    conditionals.add(condlabel);
                    optionPanel.add(condpanel, BorderLayout.SOUTH);
                } else if (conditionalName.toUpperCase().startsWith("REFLECTION")) {
                    String[] condModifiers;
                    if (conditionalValues.equalsIgnoreCase("AltLoc")) {
                        condModifiers = activeSystem.getAltLocations();
                        if (condModifiers != null && condModifiers.length > 1) {
                            isEnabled = true;
                            bg = new ButtonGroup();
                            for (int j = 0; j < condModifiers.length; j++) {
                                JRadioButton jrbmi = new JRadioButton(condModifiers[j]);
                                jrbmi.addMouseListener(this);
                                bg.add(jrbmi);
                                optionValuesPanel.add(jrbmi);
                                if (j == 0) {
                                    jrbmi.setSelected(true);
                                }
                            }
                        }
                    } else if (conditionalValues.equalsIgnoreCase("Chains")) {
                        condModifiers = activeSystem.getChainNames();
                        if (condModifiers != null && condModifiers.length > 0) {
                            isEnabled = true;
                            for (int j = 0; j < condModifiers.length; j++) {
                                JRadioButton jrbmi = new JRadioButton(condModifiers[j]);
                                jrbmi.addMouseListener(this);
                                bg.add(jrbmi);
                                optionValuesPanel.add(jrbmi, j);
                            }
                        }
                    }
                }
            }
            optionPanel.add(optionValuesPanel, BorderLayout.CENTER);
            optionPanel.setPreferredSize(optionPanel.getPreferredSize());
            optionsTabbedPane.addTab(option.getAttribute("name"), optionPanel);
            optionsTabbedPane.setEnabledAt(optionsTabbedPane.getTabCount() - 1, isEnabled);
        }
    }
    optionsTabbedPane.setPreferredSize(optionsTabbedPane.getPreferredSize());
    commandPanel.setLayout(borderLayout);
    commandPanel.add(optionsTabbedPane, BorderLayout.CENTER);
    commandPanel.validate();
    commandPanel.repaint();
    loadLogSettings();
    statusLabel.setText("  " + createCommandInput());
}

From source file:op.allowance.PnlAllowance.java

private JPanel createContentPanel4(final Resident resident) {
    JPanel pnlContent = new JPanel(new VerticalLayout());

    final JidePopup popupTX = new JidePopup();
    popupTX.setMovable(false);/* w  w w  .j av  a 2s .  com*/

    PnlTX pnlTX = getPnlTX(resident, null);

    popupTX.setContentPane(pnlTX);
    popupTX.removeExcludedComponent(pnlTX);
    popupTX.setDefaultFocusComponent(pnlTX);

    final JideButton btnNewTX = GUITools.createHyperlinkButton(SYSTools.xx("admin.residents.cash.enterTXs"),
            SYSConst.icon22add, null);
    btnNewTX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            popupTX.setOwner(btnNewTX);
            GUITools.showPopup(popupTX, SwingConstants.NORTH);
        }
    });
    btnNewTX.setBackground(getBG(resident, 9));
    btnNewTX.setOpaque(true);
    pnlContent.add(btnNewTX);

    if (!minmax.containsKey(resident)) {
        minmax.put(resident, AllowanceTools.getMinMax(resident));
    }

    if (minmax.get(resident) != null) {

        LocalDate start = SYSCalendar.bom(minmax.get(resident).getFirst());
        LocalDate end = resident.isActive() ? new LocalDate()
                : SYSCalendar.eom(minmax.get(resident).getSecond());

        CollapsiblePane cpArchive = new CollapsiblePane(SYSTools.xx("admin.residents.cash.archive"));
        try {
            cpArchive.setCollapsed(true);
        } catch (PropertyVetoException e) {
            //bah!
        }
        cpArchive.setBackground(getBG(resident, 7));
        JPanel pnlArchive = new JPanel(new VerticalLayout());
        cpArchive.setContentPane(pnlArchive);
        for (int year = end.getYear(); year >= start.getYear(); year--) {
            if (year >= new LocalDate().getYear() - 1) {
                pnlContent.add(createCP4(resident, year));
            } else if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.ARCHIVE, internalClassID)) {
                pnlArchive.add(createCP4(resident, year));
            }
        }
        if (pnlArchive.getComponentCount() > 0) {
            pnlContent.add(cpArchive);
        }
    }
    return pnlContent;
}

From source file:op.care.bhp.PnlBHP.java

private CollapsiblePane createCP4Shift(final Byte shift) {
    /***/*  w  w  w  .  j  a  v a2s  .  co  m*/
     *                          _        ____ ____  _  _
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \| || |
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | || |_
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/|__   _|
     *      \___|_|  \___|\__,_|\__\___|\____|_|      |_|
     *
     */
    String title = "<html><font size=+1><b>" + GUITools.getLocalizedMessages(BHPTools.SHIFT_TEXT)[shift]
            + "</b></font></html>";

    final CollapsiblePane prPane = new CollapsiblePane(title);
    prPane.setSlidingDirection(SwingConstants.SOUTH);
    prPane.setBackground(SYSCalendar.getBGSHIFT(shift));
    prPane.setForeground(SYSCalendar.getFGSHIFT(shift));
    prPane.setOpaque(false);

    JPanel prPanel = new JPanel();
    prPanel.setLayout(new VerticalLayout());

    if (mapShift2BHP.containsKey(shift)) {

        if (shift == BHPTools.SHIFT_EARLY) {

            final CollapsiblePane morning = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.morning.long") + "</font></html>", null);
            morning.setSlidingDirection(SwingConstants.SOUTH);
            morning.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            morning.setForeground(Color.white);
            morning.setOpaque(false);
            JPanel pnlMorning = new JPanel();
            pnlMorning.setLayout(new VerticalLayout());
            morning.setContentPane(pnlMorning);

            final CollapsiblePane noon = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.noon.long") + "</font></html>", null);
            noon.setSlidingDirection(SwingConstants.SOUTH);
            noon.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            noon.setForeground(Color.white);
            noon.setOpaque(false);
            JPanel pnlNoon = new JPanel();
            pnlNoon.setLayout(new VerticalLayout());
            noon.setContentPane(pnlNoon);

            final CollapsiblePane clock = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.Time.long") + "</font></html>", null);
            clock.setSlidingDirection(SwingConstants.SOUTH);
            clock.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            clock.setForeground(Color.white);
            clock.setOpaque(false);
            JPanel pnlClock = new JPanel();
            pnlClock.setLayout(new VerticalLayout());
            clock.setContentPane(pnlClock);

            for (BHP bhp : mapShift2BHP.get(shift)) {
                prPanel.setBackground(bhp.getBG());
                mapBHP2Pane.put(bhp, createCP4(bhp));
                if (bhp.getSollZeit() == BHPTools.BYTE_MORNING) {
                    pnlMorning.add(mapBHP2Pane.get(bhp));
                } else if (bhp.getSollZeit() == BHPTools.BYTE_NOON) {
                    pnlNoon.add(mapBHP2Pane.get(bhp));
                } else {
                    pnlClock.add(mapBHP2Pane.get(bhp));
                }
            }

            if (pnlClock.getComponentCount() > 0) {
                prPanel.add(clock);
            }
            if (pnlMorning.getComponentCount() > 0) {
                prPanel.add(morning);
            }
            if (pnlNoon.getComponentCount() > 0) {
                prPanel.add(noon);
            }

        } else if (shift == BHPTools.SHIFT_LATE) {
            final CollapsiblePane afternoon = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.afternoon.long") + "</font></html>", null);
            afternoon.setSlidingDirection(SwingConstants.SOUTH);
            afternoon.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            afternoon.setForeground(Color.white);
            afternoon.setOpaque(false);
            JPanel pnlAfternoon = new JPanel();
            pnlAfternoon.setLayout(new VerticalLayout());
            afternoon.setContentPane(pnlAfternoon);

            final CollapsiblePane evening = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.evening.long") + "</font></html>", null);
            evening.setSlidingDirection(SwingConstants.SOUTH);
            evening.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            evening.setForeground(Color.white);
            evening.setOpaque(false);
            JPanel pnlEvening = new JPanel();
            pnlEvening.setLayout(new VerticalLayout());
            evening.setContentPane(pnlEvening);

            final CollapsiblePane clock = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.Time.long") + "</font></html>", null);
            clock.setSlidingDirection(SwingConstants.SOUTH);
            clock.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            clock.setForeground(Color.white);
            clock.setOpaque(false);
            JPanel pnlClock = new JPanel();
            pnlClock.setLayout(new VerticalLayout());
            clock.setContentPane(pnlClock);

            for (BHP bhp : mapShift2BHP.get(shift)) {
                prPanel.setBackground(bhp.getBG());
                mapBHP2Pane.put(bhp, createCP4(bhp));
                if (bhp.getSollZeit() == BHPTools.BYTE_AFTERNOON) {
                    pnlAfternoon.add(mapBHP2Pane.get(bhp));
                } else if (bhp.getSollZeit() == BHPTools.BYTE_EVENING) {
                    pnlEvening.add(mapBHP2Pane.get(bhp));
                } else {
                    pnlClock.add(mapBHP2Pane.get(bhp));
                }
            }

            if (pnlClock.getComponentCount() > 0) {
                prPanel.add(clock);
            }
            if (pnlAfternoon.getComponentCount() > 0) {
                prPanel.add(afternoon);
            }
            if (pnlEvening.getComponentCount() > 0) {
                prPanel.add(evening);
            }
        } else {
            for (BHP bhp : mapShift2BHP.get(shift)) {
                prPanel.setBackground(bhp.getBG());
                mapBHP2Pane.put(bhp, createCP4(bhp));
                prPanel.add(mapBHP2Pane.get(bhp));
            }
        }
        prPane.setContentPane(prPanel);
        prPane.setCollapsible(true);
    } else {
        prPane.setContentPane(prPanel);
        prPane.setCollapsible(false);
    }

    return prPane;
}

From source file:op.care.dfn.PnlDFN.java

private CollapsiblePane createCP4Shift(Byte shift) {
    String title = "<html><font size=+1><b>" + GUITools.getLocalizedMessages(DFNTools.SHIFT_TEXT)[shift]
            + "</b></font></html>";
    final CollapsiblePane mainPane = new CollapsiblePane(title);
    mainPane.setSlidingDirection(SwingConstants.SOUTH);
    mainPane.setBackground(SYSCalendar.getBGSHIFT(shift));
    mainPane.setForeground(SYSCalendar.getFGSHIFT(shift));
    mainPane.setOpaque(false);//from  w w w  . jav a  2s . co  m

    JPanel npPanel = new JPanel();
    npPanel.setLayout(new VerticalLayout());

    boolean containsKey = false;
    synchronized (mapShift2DFN) {
        containsKey = mapShift2DFN.containsKey(shift);
    }

    if (containsKey) {
        if (shift == DFNTools.SHIFT_EARLY) {

            final CollapsiblePane morning = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.morning.long") + "</font></html>", null);
            morning.setSlidingDirection(SwingConstants.SOUTH);
            morning.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            morning.setForeground(Color.white);
            morning.setOpaque(false);
            JPanel pnlMorning = new JPanel();
            pnlMorning.setLayout(new VerticalLayout());
            morning.setContentPane(pnlMorning);

            final CollapsiblePane noon = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.noon.long") + "</font></html>", null);
            noon.setSlidingDirection(SwingConstants.SOUTH);
            noon.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            noon.setForeground(Color.white);
            noon.setOpaque(false);
            JPanel pnlNoon = new JPanel();
            pnlNoon.setLayout(new VerticalLayout());
            noon.setContentPane(pnlNoon);

            final CollapsiblePane clock = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.Time.long") + "</font></html>", null);
            clock.setSlidingDirection(SwingConstants.SOUTH);
            clock.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            clock.setForeground(Color.white);
            clock.setOpaque(false);
            JPanel pnlClock = new JPanel();
            pnlClock.setLayout(new VerticalLayout());
            clock.setContentPane(pnlClock);

            ArrayList<DFN> listDFN = null;
            synchronized (mapShift2DFN) {
                listDFN = mapShift2DFN.get(shift);
            }

            for (DFN dfn : listDFN) {
                npPanel.setBackground(dfn.getBG());
                CollapsiblePane cp1 = createCP4(dfn);
                synchronized (mapDFN2Pane) {
                    mapDFN2Pane.put(dfn, cp1);
                    if (dfn.getSollZeit() == DFNTools.BYTE_MORNING) {
                        pnlMorning.add(mapDFN2Pane.get(dfn));
                    } else if (dfn.getSollZeit() == DFNTools.BYTE_NOON) {
                        pnlNoon.add(mapDFN2Pane.get(dfn));
                    } else {
                        pnlClock.add(mapDFN2Pane.get(dfn));
                    }
                }
            }

            if (pnlClock.getComponentCount() > 0) {
                npPanel.add(clock);
            }
            if (pnlMorning.getComponentCount() > 0) {
                npPanel.add(morning);
            }
            if (pnlNoon.getComponentCount() > 0) {
                npPanel.add(noon);
            }

        } else if (shift == DFNTools.SHIFT_LATE) {
            final CollapsiblePane afternoon = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.afternoon.long") + "</font></html>", null);
            afternoon.setSlidingDirection(SwingConstants.SOUTH);
            afternoon.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            afternoon.setForeground(Color.white);
            afternoon.setOpaque(false);
            JPanel pnlAfternoon = new JPanel();
            pnlAfternoon.setLayout(new VerticalLayout());
            afternoon.setContentPane(pnlAfternoon);

            final CollapsiblePane evening = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.evening.long") + "</font></html>", null);
            evening.setSlidingDirection(SwingConstants.SOUTH);
            evening.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            evening.setForeground(Color.white);
            evening.setOpaque(false);
            JPanel pnlEvening = new JPanel();
            pnlEvening.setLayout(new VerticalLayout());
            evening.setContentPane(pnlEvening);

            final CollapsiblePane clock = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.Time.long") + "</font></html>", null);
            clock.setSlidingDirection(SwingConstants.SOUTH);
            clock.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            clock.setForeground(Color.white);
            clock.setOpaque(false);
            JPanel pnlClock = new JPanel();
            pnlClock.setLayout(new VerticalLayout());
            clock.setContentPane(pnlClock);

            ArrayList<DFN> listDFN = null;
            synchronized (mapShift2DFN) {
                listDFN = mapShift2DFN.get(shift);
            }

            for (DFN dfn : listDFN) {
                npPanel.setBackground(dfn.getBG());
                CollapsiblePane cp1 = createCP4(dfn);
                synchronized (mapDFN2Pane) {
                    mapDFN2Pane.put(dfn, cp1);
                    if (dfn.getSollZeit() == DFNTools.BYTE_AFTERNOON) {
                        pnlAfternoon.add(mapDFN2Pane.get(dfn));
                    } else if (dfn.getSollZeit() == DFNTools.BYTE_EVENING) {
                        pnlEvening.add(mapDFN2Pane.get(dfn));
                    } else {
                        pnlClock.add(mapDFN2Pane.get(dfn));
                    }
                }
            }

            if (pnlClock.getComponentCount() > 0) {
                npPanel.add(clock);
            }
            if (pnlAfternoon.getComponentCount() > 0) {
                npPanel.add(afternoon);
            }
            if (pnlEvening.getComponentCount() > 0) {
                npPanel.add(evening);
            }

        } else {
            ArrayList<DFN> listDFN = null;
            synchronized (mapShift2DFN) {
                listDFN = mapShift2DFN.get(shift);
            }
            for (DFN dfn : listDFN) {
                npPanel.setBackground(dfn.getBG());
                CollapsiblePane cp1 = createCP4(dfn);
                synchronized (mapDFN2Pane) {
                    mapDFN2Pane.put(dfn, cp1);
                    npPanel.add(mapDFN2Pane.get(dfn));
                }
            }
        }
        mainPane.setContentPane(npPanel);
        mainPane.setCollapsible(true);
    } else {
        mainPane.setContentPane(npPanel);
        mainPane.setCollapsible(false);
    }

    return mainPane;
}

From source file:op.tools.SYSTools.java

public static void removeSearchPanels(JPanel panelSearch, int positionToAddPanels) {
    if (panelSearch.getComponentCount() > positionToAddPanels) {
        int count = panelSearch.getComponentCount();
        for (int i = count - 1; i >= positionToAddPanels; i--) {
            panelSearch.remove(positionToAddPanels);
        }//  w ww .ja v a  2 s  . com
    }
}

From source file:org.broad.igv.hic.MainWindow.java

private void initComponents() {
    JPanel mainPanel = new JPanel();
    JPanel toolbarPanel = new JPanel();

    //======== this ========

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    mainPanel.setLayout(new BorderLayout());

    toolbarPanel.setBorder(null);/*from ww w  .  j ava  2  s .c  om*/
    toolbarPanel.setLayout(new GridLayout());

    JPanel chrSelectionPanel = new JPanel();
    chrSelectionPanel.setBorder(LineBorder.createGrayLineBorder());
    chrSelectionPanel.setMinimumSize(new Dimension(130, 57));
    chrSelectionPanel.setPreferredSize(new Dimension(130, 57));
    chrSelectionPanel.setLayout(new BorderLayout());

    JPanel panel10 = new JPanel();
    panel10.setBackground(new Color(204, 204, 204));
    panel10.setLayout(new BorderLayout());

    JLabel label3 = new JLabel();
    label3.setText("Chromosomes");
    label3.setHorizontalAlignment(SwingConstants.CENTER);
    panel10.add(label3, BorderLayout.CENTER);

    chrSelectionPanel.add(panel10, BorderLayout.PAGE_START);

    JPanel panel9 = new JPanel();
    panel9.setBackground(new Color(238, 238, 238));
    panel9.setLayout(new BoxLayout(panel9, BoxLayout.X_AXIS));

    //---- chrBox1 ----
    chrBox1 = new JComboBox();
    chrBox1.setModel(new DefaultComboBoxModel(new String[] { "All" }));
    chrBox1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            chrBox1ActionPerformed(e);
        }
    });
    panel9.add(chrBox1);

    //---- chrBox2 ----
    chrBox2 = new JComboBox();
    chrBox2.setModel(new DefaultComboBoxModel(new String[] { "All" }));
    chrBox2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            chrBox2ActionPerformed(e);
        }
    });
    panel9.add(chrBox2);

    //---- refreshButton ----
    JideButton refreshButton = new JideButton();
    refreshButton
            .setIcon(new ImageIcon(getClass().getResource("/toolbarButtonGraphics/general/Refresh24.gif")));
    refreshButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            refreshButtonActionPerformed(e);
        }
    });
    panel9.add(refreshButton);

    chrSelectionPanel.add(panel9, BorderLayout.CENTER);

    toolbarPanel.add(chrSelectionPanel);

    //======== displayOptionPanel ========
    JPanel displayOptionPanel = new JPanel();
    JPanel panel1 = new JPanel();
    displayOptionComboBox = new JComboBox();

    displayOptionPanel.setBackground(new Color(238, 238, 238));
    displayOptionPanel.setBorder(LineBorder.createGrayLineBorder());
    displayOptionPanel.setLayout(new BorderLayout());

    //======== panel14 ========

    JPanel panel14 = new JPanel();
    panel14.setBackground(new Color(204, 204, 204));
    panel14.setLayout(new BorderLayout());

    //---- label4 ----
    JLabel label4 = new JLabel();
    label4.setText("Show");
    label4.setHorizontalAlignment(SwingConstants.CENTER);
    panel14.add(label4, BorderLayout.CENTER);

    displayOptionPanel.add(panel14, BorderLayout.PAGE_START);

    //======== panel1 ========

    panel1.setBorder(new EmptyBorder(0, 10, 0, 10));
    panel1.setLayout(new GridLayout(1, 0, 20, 0));

    //---- comboBox1 ----
    displayOptionComboBox
            .setModel(new DefaultComboBoxModel(new String[] { DisplayOption.OBSERVED.toString() }));
    displayOptionComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            displayOptionComboBoxActionPerformed(e);
        }
    });
    panel1.add(displayOptionComboBox);

    displayOptionPanel.add(panel1, BorderLayout.CENTER);

    toolbarPanel.add(displayOptionPanel);

    //======== colorRangePanel ========

    JPanel colorRangePanel = new JPanel();
    JLabel colorRangeLabel = new JLabel();
    colorRangeSlider = new RangeSlider();
    colorRangePanel.setBorder(LineBorder.createGrayLineBorder());
    colorRangePanel.setMinimumSize(new Dimension(96, 70));
    colorRangePanel.setPreferredSize(new Dimension(202, 70));
    colorRangePanel.setMaximumSize(new Dimension(32769, 70));
    colorRangePanel.setLayout(new BorderLayout());

    //======== panel11 ========

    JPanel colorLabelPanel = new JPanel();
    colorLabelPanel.setBackground(new Color(204, 204, 204));
    colorLabelPanel.setLayout(new BorderLayout());

    //---- colorRangeLabel ----
    colorRangeLabel.setText("Color Range");
    colorRangeLabel.setHorizontalAlignment(SwingConstants.CENTER);
    colorRangeLabel.setToolTipText("Range of color scale in counts per mega-base squared.");
    colorRangeLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    colorRangeLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                ColorRangeDialog rangeDialog = new ColorRangeDialog(MainWindow.this, colorRangeSlider);
                rangeDialog.setVisible(true);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            ColorRangeDialog rangeDialog = new ColorRangeDialog(MainWindow.this, colorRangeSlider);
            rangeDialog.setVisible(true);
        }
    });
    colorLabelPanel.add(colorRangeLabel, BorderLayout.CENTER);

    colorRangePanel.add(colorLabelPanel, BorderLayout.PAGE_START);

    //---- colorRangeSlider ----
    colorRangeSlider.setPaintTicks(true);
    colorRangeSlider.setPaintLabels(true);
    colorRangeSlider.setLowerValue(0);
    colorRangeSlider.setMajorTickSpacing(500);
    colorRangeSlider.setMaximumSize(new Dimension(32767, 52));
    colorRangeSlider.setPreferredSize(new Dimension(200, 52));
    colorRangeSlider.setMinimumSize(new Dimension(36, 52));
    colorRangeSlider.setMaximum(2000);
    colorRangeSlider.setUpperValue(500);
    colorRangeSlider.setMinorTickSpacing(100);
    colorRangeSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            colorRangeSliderStateChanged(e);
        }
    });
    colorRangePanel.add(colorRangeSlider, BorderLayout.PAGE_END);

    //        JPanel colorRangeTextPanel = new JPanel();
    //        colorRangeTextPanel.setLayout(new FlowLayout());
    //        JTextField minField = new JTextField();
    //        minField.setPreferredSize(new Dimension(50, 15));
    //        colorRangeTextPanel.add(minField);
    //        colorRangeTextPanel.add(new JLabel(" - "));
    //        JTextField maxField = new JTextField();
    //        maxField.setPreferredSize(new Dimension(50, 15));
    //        colorRangeTextPanel.add(maxField);
    //        colorRangeTextPanel.setPreferredSize(new Dimension(200, 52));
    //        colorRangePanel.add(colorRangeTextPanel, BorderLayout.PAGE_END);

    toolbarPanel.add(colorRangePanel);

    //======== resolutionPanel ========

    JLabel resolutionLabel = new JLabel();
    JPanel resolutionPanel = new JPanel();

    resolutionPanel.setBorder(LineBorder.createGrayLineBorder());
    resolutionPanel.setLayout(new BorderLayout());

    //======== panel12 ========

    JPanel panel12 = new JPanel();
    panel12.setBackground(new Color(204, 204, 204));
    panel12.setLayout(new BorderLayout());

    //---- resolutionLabel ----
    resolutionLabel.setText("Resolution");
    resolutionLabel.setHorizontalAlignment(SwingConstants.CENTER);
    resolutionLabel.setBackground(new Color(204, 204, 204));
    panel12.add(resolutionLabel, BorderLayout.CENTER);

    resolutionPanel.add(panel12, BorderLayout.PAGE_START);

    //======== panel2 ========

    JPanel panel2 = new JPanel();
    panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS));

    //---- resolutionSlider ----
    resolutionSlider = new JSlider();
    resolutionSlider.setMaximum(8);
    resolutionSlider.setMajorTickSpacing(1);
    resolutionSlider.setPaintTicks(true);
    resolutionSlider.setSnapToTicks(true);
    resolutionSlider.setPaintLabels(true);
    resolutionSlider.setMinorTickSpacing(1);

    Dictionary<Integer, JLabel> resolutionLabels = new Hashtable<Integer, JLabel>();
    Font f = FontManager.getFont(8);
    for (int i = 0; i < HiCGlobals.zoomLabels.length; i++) {
        if ((i + 1) % 2 == 0) {
            final JLabel tickLabel = new JLabel(HiCGlobals.zoomLabels[i]);
            tickLabel.setFont(f);
            resolutionLabels.put(i, tickLabel);
        }
    }
    resolutionSlider.setLabelTable(resolutionLabels);
    // Setting the zoom should always be done by calling resolutionSlider.setValue() so work isn't done twice.
    resolutionSlider.addChangeListener(new ChangeListener() {
        // Change zoom level while staying centered on current location.
        // Centering is relative to the bounds of the data, which might not be the bounds of the window

        public void stateChanged(ChangeEvent e) {
            if (!resolutionSlider.getValueIsAdjusting()) {
                int idx = resolutionSlider.getValue();
                idx = Math.max(0, Math.min(idx, MAX_ZOOM));

                if (hic.zd != null && idx == hic.zd.getZoom()) {
                    // Nothing to do
                    return;
                }

                if (hic.xContext != null) {
                    int centerLocationX = (int) hic.xContext
                            .getChromosomePosition(getHeatmapPanel().getWidth() / 2);
                    int centerLocationY = (int) hic.yContext
                            .getChromosomePosition(getHeatmapPanel().getHeight() / 2);
                    hic.setZoom(idx, centerLocationX, centerLocationY, false);
                }
                //zoomInButton.setEnabled(newZoom < MAX_ZOOM);
                //zoomOutButton.setEnabled(newZoom > 0);
            }
        }
    });
    panel2.add(resolutionSlider);

    resolutionPanel.add(panel2, BorderLayout.CENTER);

    toolbarPanel.add(resolutionPanel);

    mainPanel.add(toolbarPanel, BorderLayout.NORTH);

    //======== hiCPanel ========

    final JPanel hiCPanel = new JPanel();
    hiCPanel.setLayout(new HiCLayout());

    //---- rulerPanel2 ----
    rulerPanel2 = new HiCRulerPanel(hic);
    rulerPanel2.setMaximumSize(new Dimension(4000, 50));
    rulerPanel2.setMinimumSize(new Dimension(1, 50));
    rulerPanel2.setPreferredSize(new Dimension(1, 50));
    rulerPanel2.setBorder(null);

    JPanel panel2_5 = new JPanel();
    panel2_5.setLayout(new BorderLayout());
    panel2_5.add(rulerPanel2, BorderLayout.SOUTH);

    trackPanel = new TrackPanel(hic);
    trackPanel.setMaximumSize(new Dimension(4000, 50));
    trackPanel.setPreferredSize(new Dimension(1, 50));
    trackPanel.setMinimumSize(new Dimension(1, 50));
    trackPanel.setBorder(null);

    //        trackPanelScrollpane = new JScrollPane();
    //        trackPanelScrollpane.getViewport().add(trackPanel);
    //        trackPanelScrollpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    //        trackPanelScrollpane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    //        trackPanelScrollpane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102)));
    //        trackPanelScrollpane.setBackground(new java.awt.Color(237, 237, 237));
    //        trackPanelScrollpane.setVisible(false);
    //        panel2_5.add(trackPanelScrollpane, BorderLayout.NORTH);
    //
    trackPanel.setVisible(false);
    panel2_5.add(trackPanel, BorderLayout.NORTH);

    hiCPanel.add(panel2_5, BorderLayout.NORTH);

    //---- rulerPanel1 ----
    rulerPanel1 = new HiCRulerPanel(hic);
    rulerPanel1.setMaximumSize(new Dimension(50, 4000));
    rulerPanel1.setPreferredSize(new Dimension(50, 500));
    rulerPanel1.setBorder(null);
    rulerPanel1.setMinimumSize(new Dimension(50, 1));
    hiCPanel.add(rulerPanel1, BorderLayout.WEST);

    //---- heatmapPanel ----
    heatmapPanel = new HeatmapPanel(this, hic);
    heatmapPanel.setBorder(LineBorder.createBlackLineBorder());
    heatmapPanel.setMaximumSize(new Dimension(500, 500));
    heatmapPanel.setMinimumSize(new Dimension(500, 500));
    heatmapPanel.setPreferredSize(new Dimension(500, 500));
    heatmapPanel.setBackground(new Color(238, 238, 238));
    hiCPanel.add(heatmapPanel, BorderLayout.CENTER);

    //======== panel8 ========

    JPanel rightSidePanel = new JPanel();
    rightSidePanel.setMaximumSize(new Dimension(120, 100));
    rightSidePanel.setBorder(new EmptyBorder(0, 10, 0, 0));
    rightSidePanel.setLayout(null);

    //---- thumbnailPanel ----
    thumbnailPanel = new ThumbnailPanel(this, hic);
    thumbnailPanel.setMaximumSize(new Dimension(100, 100));
    thumbnailPanel.setMinimumSize(new Dimension(100, 100));
    thumbnailPanel.setPreferredSize(new Dimension(100, 100));
    thumbnailPanel.setBorder(LineBorder.createBlackLineBorder());
    thumbnailPanel.setPreferredSize(new Dimension(100, 100));
    thumbnailPanel.setBounds(new Rectangle(new Point(20, 0), thumbnailPanel.getPreferredSize()));
    rightSidePanel.add(thumbnailPanel);

    //======== xPlotPanel ========

    xPlotPanel = new JPanel();
    xPlotPanel.setPreferredSize(new Dimension(250, 100));
    xPlotPanel.setLayout(null);

    rightSidePanel.add(xPlotPanel);
    xPlotPanel.setBounds(10, 100, xPlotPanel.getPreferredSize().width, 228);

    //======== yPlotPanel ========

    yPlotPanel = new JPanel();
    yPlotPanel.setPreferredSize(new Dimension(250, 100));
    yPlotPanel.setLayout(null);

    rightSidePanel.add(yPlotPanel);
    yPlotPanel.setBounds(10, 328, yPlotPanel.getPreferredSize().width, 228);

    // compute preferred size
    Dimension preferredSize = new Dimension();
    for (int i = 0; i < rightSidePanel.getComponentCount(); i++) {
        Rectangle bounds = rightSidePanel.getComponent(i).getBounds();
        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
    }
    Insets insets = rightSidePanel.getInsets();
    preferredSize.width += insets.right;
    preferredSize.height += insets.bottom;
    rightSidePanel.setMinimumSize(preferredSize);
    rightSidePanel.setPreferredSize(preferredSize);

    hiCPanel.add(rightSidePanel, BorderLayout.EAST);

    mainPanel.add(hiCPanel, BorderLayout.CENTER);

    contentPane.add(mainPanel, BorderLayout.CENTER);

    JMenuBar menuBar = createMenuBar(hiCPanel);
    contentPane.add(menuBar, BorderLayout.NORTH);

    // setup the glass pane to display a wait cursor when visible, and to grab all mouse events
    rootPane.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    rootPane.getGlassPane().addMouseListener(new MouseAdapter() {
    });

}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.ImportDialog.java

/**
 * Handles the selection of tags.//from w w  w. j  a va 2s. c o  m
 * 
 * @param tags
 *            The selected tags.
 */
private void handleTagsSelection(Collection<TagAnnotationData> tags) {
    Collection<TagAnnotationData> set = tagsMap.values();
    Map<String, TagAnnotationData> newTags = new HashMap<String, TagAnnotationData>();
    TagAnnotationData tag;
    Iterator<TagAnnotationData> i = set.iterator();
    while (i.hasNext()) {
        tag = i.next();
        if (tag.getId() < 0)
            newTags.put(tag.getTagValue(), tag);
    }
    List<TagAnnotationData> toKeep = new ArrayList<TagAnnotationData>();
    i = tags.iterator();
    while (i.hasNext()) {
        tag = i.next();
        if (tag.getId() < 0) {
            if (!newTags.containsKey(tag.getTagValue())) {
                toKeep.add(tag);
            }
        } else
            toKeep.add(tag);
    }
    toKeep.addAll(newTags.values());

    // layout the tags
    tagsMap.clear();
    tagsPane.removeAll();
    i = toKeep.iterator();
    IconManager icons = IconManager.getInstance();
    JPanel entry;
    JPanel p = initRow();
    int width = 0;
    while (i.hasNext()) {
        tag = i.next();
        entry = buildTagEntryPanel(tag, icons.getIcon(IconManager.MINUS_11));
        if (width + entry.getPreferredSize().width >= COLUMN_WIDTH) {
            tagsPane.add(p);
            p = initRow();
            width = 0;
        } else {
            width += entry.getPreferredSize().width;
            width += 2;
        }
        p.add(entry);
    }
    if (p.getComponentCount() > 0)
        tagsPane.add(p);
    tagsPane.validate();
    tagsPane.repaint();
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.AnnotationDataUI.java

/**
 * Lays out the tags./*from w w w.  j  a v  a  2 s  .  c  o m*/
 * 
 * @param list The collection of tags to layout.
 */
private void layoutTags(Collection list) {
    tagsPane.removeAll();
    tagsDocList.clear();
    DocComponent doc;
    if (list != null && list.size() > 0) {
        Iterator i = list.iterator();
        int width = 0;
        JPanel p = initRow();
        DataObject data;
        switch (filter) {
        case SHOW_ALL:
            while (i.hasNext()) {
                doc = new DocComponent(i.next(), model);
                doc.addPropertyChangeListener(controller);
                tagsDocList.add(doc);
                if (width + doc.getPreferredSize().width >= COLUMN_WIDTH) {
                    tagsPane.add(p);
                    p = initRow();
                    width = 0;
                } else {
                    width += doc.getPreferredSize().width;
                    width += 2;
                }
                p.add(doc);
            }
            break;
        case ADDED_BY_ME:
            while (i.hasNext()) {
                data = (DataObject) i.next();
                doc = new DocComponent(data, model);
                doc.addPropertyChangeListener(controller);
                tagsDocList.add(doc);
                if (model.isLinkOwner(data)) {
                    if (width + doc.getPreferredSize().width >= COLUMN_WIDTH) {
                        tagsPane.add(p);
                        p = initRow();
                        width = 0;
                    } else {
                        width += doc.getPreferredSize().width;
                        width += 2;
                    }
                    p.add(doc);
                }
            }
            break;
        case ADDED_BY_OTHERS:
            while (i.hasNext()) {
                data = (DataObject) i.next();
                doc = new DocComponent(data, model);
                doc.addPropertyChangeListener(controller);
                tagsDocList.add(doc);
                if (model.isAnnotatedByOther(data)) {
                    if (width + doc.getPreferredSize().width >= COLUMN_WIDTH) {
                        tagsPane.add(p);
                        p = initRow();
                        width = 0;
                    } else {
                        width += doc.getPreferredSize().width;
                        width += 2;
                    }
                    p.add(doc);
                }
            }
        }
        if (p.getComponentCount() == 0) {
            switch (filter) {
            case ADDED_BY_OTHERS:
            case ADDED_BY_ME:
                doc = new DocComponent(null, model);
                tagsDocList.add(doc);
                tagsPane.add(doc);
            }
        } else
            tagsPane.add(p);
    }
    if (tagsDocList.size() == 0) {
        doc = new DocComponent(null, model);
        tagsDocList.add(doc);
        tagsPane.add(doc);
    }
    tagsPane.revalidate();
    tagsPane.repaint();
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java

/**
 * Creates the menu hosting the users belonging to the specified group.
 * Returns <code>true</code> if the group is selected, <code>false</code>
 * otherwise./*from  ww  w .j  av a 2 s. c o m*/
 * 
 * @param groupItem The item hosting the group.
 * @param size The number of groups.
 * @return See above.
 */
private boolean createGroupMenu(GroupItem groupItem, int size) {
    long loggedUserID = model.getUserDetails().getId();
    GroupData group = groupItem.getGroup();
    //Determine the user already added to the display
    Browser browser = model.getBrowser(Browser.PROJECTS_EXPLORER);
    TreeImageDisplay refNode = null;
    List<TreeImageDisplay> nodes;
    ExperimenterVisitor visitor;
    List<Long> users = new ArrayList<Long>();
    //Find the group already displayed
    if (group != null && size > 0) {
        visitor = new ExperimenterVisitor(browser, group.getId());
        browser.accept(visitor);
        nodes = visitor.getNodes();
        if (nodes.size() == 1) {
            refNode = nodes.get(0);
        }
        visitor = new ExperimenterVisitor(browser, -1, -1);
        if (refNode != null)
            refNode.accept(visitor);
        else if (size == 1)
            browser.accept(visitor);
        nodes = visitor.getNodes();

        TreeImageDisplay n;
        if (CollectionUtils.isNotEmpty(nodes)) {
            Iterator<TreeImageDisplay> j = nodes.iterator();
            while (j.hasNext()) {
                n = j.next();
                if (n.getUserObject() instanceof ExperimenterData) {
                    users.add(((ExperimenterData) n.getUserObject()).getId());
                }
            }
            if (size == 1) {
                groupItem.setMenuSelected(true, false);
            }
        }
    }

    //now add the users
    List<DataMenuItem> items = new ArrayList<DataMenuItem>();
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    List l = null;
    if (group != null)
        l = sorter.sort(group.getLeaders());
    Iterator i;
    ExperimenterData exp;

    DataMenuItem item, allUser;
    JPanel list;

    boolean view = true;
    if (group != null) {
        int level = group.getPermissions().getPermissionsLevel();
        if (level == GroupData.PERMISSIONS_PRIVATE) {
            view = model.isAdministrator() || model.isGroupOwner(group);
        }
    }

    list = new JPanel();
    list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
    allUser = new DataMenuItem(DataMenuItem.ALL_USERS_TEXT, true);
    items.add(allUser);
    if (view)
        list.add(allUser);
    p.add(UIUtilities.buildComponentPanel(list));
    int count = 0;
    int total = 0;
    if (CollectionUtils.isNotEmpty(l)) {
        total += l.size();
        i = l.iterator();
        list = new JPanel();
        list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
        while (i.hasNext()) {
            exp = (ExperimenterData) i.next();
            if (view || exp.getId() == loggedUserID) {
                item = new DataMenuItem(exp, true);
                item.setSelected(users.contains(exp.getId()));
                if (item.isSelected())
                    count++;
                item.addPropertyChangeListener(groupItem);
                items.add(item);
                list.add(item);
            }
        }
        if (list.getComponentCount() > 0) {
            p.add(formatHeader("Group owners"));
            p.add(UIUtilities.buildComponentPanel(list));
        }
    }

    if (group != null)
        l = sorter.sort(group.getMembersOnly());
    if (CollectionUtils.isNotEmpty(l)) {
        total += l.size();
        i = l.iterator();
        list = new JPanel();
        list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
        while (i.hasNext()) {
            exp = (ExperimenterData) i.next();
            if (view || exp.getId() == loggedUserID) {
                item = new DataMenuItem(exp, true);
                item.setSelected(users.contains(exp.getId()));
                if (item.isSelected())
                    count++;
                item.addPropertyChangeListener(groupItem);
                items.add(item);
                list.add(item);
            }
        }
        if (list.getComponentCount() > 0) {
            p.add(formatHeader("Members"));
            p.add(UIUtilities.buildComponentPanel(list));
        }
    }
    allUser.setSelected(total != 0 && total == count);
    allUser.addPropertyChangeListener(groupItem);
    JScrollPane pane = new JScrollPane(p);
    Dimension d = p.getPreferredSize();
    int max = 500;
    if (d.height > max) {
        Insets insets = pane.getInsets();
        pane.setPreferredSize(new Dimension(d.width + insets.left + insets.right + 20, max));
    }

    groupItem.add(pane);
    groupItem.setUsersItem(items);
    groupItem.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (GroupItem.USER_SELECTION_PROPERTY.equals(name))
                handleSelection();
            else if (GroupItem.ALL_GROUPS_SELECTION_PROPERTY.equals(name))
                handleAllGroupsSelection(true);
            else if (GroupItem.ALL_GROUPS_DESELECTION_PROPERTY.equals(name))
                handleAllGroupsSelection(false);
            else if (GroupItem.ALL_USERS_SELECTION_PROPERTY.equals(name))
                handleAllUsersSelection((Boolean) evt.getNewValue());
        }
    });
    return groupItem.isMenuSelected();
}

From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java

/** 
 * Builds and lays out the details of the script e.g.
 * authors, contact, version.//  www. j  a va  2s .  c  o m
 * 
 * @return See above.
 */
private JPanel buildScriptDetails() {
    String[] authors = script.getAuthors();
    String contact = script.getContact();
    String version = script.getVersion();
    if (authors == null && contact == null && version == null)
        return null;
    JPanel p = new JPanel();
    p.setBackground(BG_COLOR);
    double[] columns = { TableLayout.PREFERRED, 5, TableLayout.FILL };
    TableLayout layout = new TableLayout();
    layout.setColumn(columns);
    p.setLayout(layout);
    int row = 0;
    JLabel l;
    if (authors != null && authors.length > 0) {
        l = UIUtilities.setTextFont("Authors:");
        StringBuffer buffer = new StringBuffer();
        int n = authors.length - 1;
        for (int i = 0; i < authors.length; i++) {
            buffer.append(authors[i]);
            if (i < n)
                buffer.append(", ");
        }
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(l, "0," + row);
        l = new JLabel();
        l.setText(buffer.toString());
        p.add(l, "2," + row);
        row++;
    }
    if (StringUtils.isNotBlank(contact)) {
        l = UIUtilities.setTextFont("Contact:");
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(l, "0," + row);
        l = new JLabel();
        l.setText(contact);
        p.add(l, "2," + row);
        row++;
    }
    if (StringUtils.isNotBlank(version)) {
        l = UIUtilities.setTextFont("Version:");
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(l, "0," + row);
        l = new JLabel();
        l.setText(version);
        p.add(l, "2," + row);
    }
    if (p.getComponentCount() == 0)
        return null;
    return p;
}