Example usage for javax.swing JCheckBox setBackground

List of usage examples for javax.swing JCheckBox setBackground

Introduction

In this page you can find the example usage for javax.swing JCheckBox setBackground.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.")
public void setBackground(Color bg) 

Source Link

Document

Sets the background color of this component.

Usage

From source file:org.forester.archaeopteryx.ControlPanel.java

void addSecondLevelJCheckBoxWithSlider(final JCheckBox jcb, final JPanel p) {
    jcb.setFocusPainted(false);/*from   ww w. j a  v  a2 s  .c o  m*/
    jcb.setFont(ControlPanel.jcb_font);
    if (!_configuration.isUseNativeUI()) {
        jcb.setBackground(ControlPanel.jcb_background_color);
        jcb.setForeground(ControlPanel.jcb_text_color);
    }
    Box box = Box.createHorizontalBox();
    p.setBackground(background_color);
    box.add(Box.createRigidArea(new Dimension(12, 0)));
    jcb.setVisible(_color_branches_cb.isSelected());
    box.add(jcb);
    buildJSlider(60, _slider_min, _slider_max);
    getColorBranchesEdplSlider().setVisible(_color_branches_cb.isSelected());
    getColorBranchesEdplSlider().setEnabled(_color_branches_edpl.isSelected());
    box.add(getColorBranchesEdplSlider());
    p.add(box, "Center");
    jcb.addActionListener(this);
}

From source file:lcmc.gui.resources.ServiceInfo.java

/** Returns existing service manu item. */
private MyMenu getExistingServiceMenuItem(final String name, final boolean enableForNew,
        final boolean testOnly) {
    final ServiceInfo thisClass = this;
    return new MyMenu(name, new AccessMode(ConfigData.AccessType.ADMIN, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
        private static final long serialVersionUID = 1L;
        private final Lock mUpdateLock = new ReentrantLock();

        @Override/*w w  w . j  a v a 2s .  c o  m*/
        public String enablePredicate() {
            if (getBrowser().clStatusFailed()) {
                return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
            } else if (getService().isRemoved()) {
                return IS_BEING_REMOVED_STRING;
            } else if (getService().isOrphaned()) {
                return IS_ORPHANED_STRING;
            } else if (!enableForNew && getService().isNew()) {
                return IS_NEW_STRING;
            }
            if (getBrowser().getExistingServiceList(thisClass).size() == 0) {
                return "<<empty;>>";
            }
            return null;
        }

        @Override
        public void update() {
            final Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    if (mUpdateLock.tryLock()) {
                        try {
                            updateThread();
                        } finally {
                            mUpdateLock.unlock();
                        }
                    }
                }
            });
            t.start();
        }

        private void updateThread() {
            final JCheckBox colocationWi = new JCheckBox("Colo", true);
            final JCheckBox orderWi = new JCheckBox("Order", true);
            colocationWi.setBackground(ClusterBrowser.STATUS_BACKGROUND);
            colocationWi.setPreferredSize(colocationWi.getMinimumSize());
            orderWi.setBackground(ClusterBrowser.STATUS_BACKGROUND);
            orderWi.setPreferredSize(orderWi.getMinimumSize());
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    setEnabled(false);
                }
            });
            Tools.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    removeAll();
                }
            });

            final MyListModel<MyMenuItem> dlm = new MyListModel<MyMenuItem>();
            final Map<MyMenuItem, ButtonCallback> callbackHash = new HashMap<MyMenuItem, ButtonCallback>();
            final MyList<MyMenuItem> list = new MyList<MyMenuItem>(dlm, getBackground());

            final List<JDialog> popups = new ArrayList<JDialog>();
            for (final ServiceInfo asi : getBrowser().getExistingServiceList(thisClass)) {
                if (asi.isConstraintPH() && isConstraintPH()) {
                    continue;
                }
                if (asi.getCloneInfo() != null || asi.getGroupInfo() != null) {
                    /* skip services that are clones or in groups. */
                    continue;
                }
                addExistingServiceMenuItem(asi.toString(), asi, dlm, callbackHash, list, colocationWi, orderWi,
                        popups, testOnly);
                asi.addExistingGroupServiceMenuItems(thisClass, dlm, callbackHash, list, colocationWi, orderWi,
                        popups, testOnly);
            }
            final JPanel colOrdPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
            colOrdPanel.setBackground(ClusterBrowser.STATUS_BACKGROUND);
            colOrdPanel.add(colocationWi);
            colOrdPanel.add(orderWi);
            final MyMenu thisM = this;
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    @Override
                    public void run() {
                        final boolean ret = Tools.getScrollingMenu(name, colOrdPanel, thisM, dlm, list,
                                thisClass, popups, callbackHash);
                        if (!ret) {
                            setEnabled(false);
                        }
                    }
                });
            } catch (final InterruptedException ix) {
                Thread.currentThread().interrupt();
            } catch (final InvocationTargetException x) {
                Tools.printStackTrace();
            }
            super.update();
        }
    };
}

From source file:lcmc.gui.resources.ServiceInfo.java

/** Adds new Service and dependence. */
private MyMenu getAddServiceMenuItem(final boolean testOnly, final String name) {
    final ServiceInfo thisClass = this;
    return new MyMenu(name, new AccessMode(ConfigData.AccessType.ADMIN, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
        private static final long serialVersionUID = 1L;
        private final Lock mUpdateLock = new ReentrantLock();

        @Override/*from w w  w. ja v a 2 s .co m*/
        public String enablePredicate() {
            if (getBrowser().clStatusFailed()) {
                return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
            } else if (getService().isRemoved()) {
                return IS_BEING_REMOVED_STRING;
            } else if (getService().isOrphaned()) {
                return IS_ORPHANED_STRING;
            } else if (getService().isNew()) {
                return IS_NEW_STRING;
            }
            return null;
        }

        @Override
        public void update() {
            final Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    if (mUpdateLock.tryLock()) {
                        try {
                            updateThread();
                        } finally {
                            mUpdateLock.unlock();
                        }
                    }
                }
            });
            t.start();
        }

        private void updateThread() {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    setEnabled(false);
                }
            });
            Tools.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    removeAll();
                }
            });
            final Point2D pos = getPos();
            final CRMXML crmXML = getBrowser().getCRMXML();
            final ResourceAgent fsService = crmXML.getResourceAgent("Filesystem",
                    ResourceAgent.HEARTBEAT_PROVIDER, ResourceAgent.OCF_CLASS);
            final MyMenu thisMenu = this;
            if (crmXML.isLinbitDrbdPresent()) { /* just skip it, if it
                                                   is not */
                final ResourceAgent linbitDrbdService = crmXML.getHbLinbitDrbd();
                /* Linbit:DRBD */
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {
                        @Override
                        public void run() {
                            addDrbdLinbitMenu(thisMenu, crmXML, pos, fsService, testOnly);
                        }
                    });
                } catch (final InterruptedException ix) {
                    Thread.currentThread().interrupt();
                } catch (final InvocationTargetException x) {
                    Tools.printStackTrace();
                }

            }
            if (crmXML.isDrbddiskPresent()) { /* just skip it,
                                                 if it is not */
                /* drbddisk */
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {
                        @Override
                        public void run() {
                            addDrbddiskMenu(thisMenu, crmXML, pos, fsService, testOnly);
                        }
                    });
                } catch (final InterruptedException ix) {
                    Thread.currentThread().interrupt();
                } catch (final InvocationTargetException x) {
                    Tools.printStackTrace();
                }
            }
            final ResourceAgent ipService = crmXML.getResourceAgent("IPaddr2", ResourceAgent.HEARTBEAT_PROVIDER,
                    ResourceAgent.OCF_CLASS);
            if (ipService != null) { /* just skip it, if it is not*/
                /* ipaddr */
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {
                        @Override
                        public void run() {
                            addIpMenu(thisMenu, pos, ipService, testOnly);
                        }
                    });
                } catch (final InterruptedException ix) {
                    Thread.currentThread().interrupt();
                } catch (final InvocationTargetException x) {
                    Tools.printStackTrace();
                }
            }
            if (fsService != null) { /* just skip it, if it is not*/
                /* Filesystem */
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {
                        @Override
                        public void run() {
                            addFilesystemMenu(thisMenu, pos, fsService, testOnly);
                        }
                    });
                } catch (final InterruptedException ix) {
                    Thread.currentThread().interrupt();
                } catch (final InvocationTargetException x) {
                    Tools.printStackTrace();
                }
            }
            final List<JDialog> popups = new ArrayList<JDialog>();
            for (final String cl : ClusterBrowser.HB_CLASSES) {
                final List<ResourceAgent> services = getAddServiceList(cl);
                if (services.size() == 0) {
                    /* no services, don't show */
                    continue;
                }
                final JCheckBox colocationWi = new JCheckBox("Colo", true);
                final JCheckBox orderWi = new JCheckBox("Order", true);
                colocationWi.setBackground(ClusterBrowser.STATUS_BACKGROUND);
                colocationWi.setPreferredSize(colocationWi.getMinimumSize());
                orderWi.setBackground(ClusterBrowser.STATUS_BACKGROUND);
                orderWi.setPreferredSize(orderWi.getMinimumSize());
                final JPanel colOrdPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
                colOrdPanel.setBackground(ClusterBrowser.STATUS_BACKGROUND);
                colOrdPanel.add(colocationWi);
                colOrdPanel.add(orderWi);
                boolean mode = !AccessMode.ADVANCED;
                if (ResourceAgent.UPSTART_CLASS.equals(cl) || ResourceAgent.SYSTEMD_CLASS.equals(cl)) {
                    mode = AccessMode.ADVANCED;
                }
                if (ResourceAgent.LSB_CLASS.equals(cl)
                        && !getAddServiceList(ResourceAgent.SERVICE_CLASS).isEmpty()) {
                    mode = AccessMode.ADVANCED;
                }
                final MyMenu classItem = new MyMenu(ClusterBrowser.getClassMenu(cl),
                        new AccessMode(ConfigData.AccessType.ADMIN, mode),
                        new AccessMode(ConfigData.AccessType.OP, mode));
                final MyListModel<MyMenuItem> dlm = new MyListModel<MyMenuItem>();
                for (final ResourceAgent ra : services) {
                    try {
                        SwingUtilities.invokeAndWait(new Runnable() {
                            @Override
                            public void run() {
                                addResourceAgentMenu(ra, dlm, pos, popups, colocationWi, orderWi, testOnly);
                            }
                        });
                    } catch (final InterruptedException ix) {
                        Thread.currentThread().interrupt();
                    } catch (final InvocationTargetException x) {
                        Tools.printStackTrace();
                    }
                }
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {
                        @Override
                        public void run() {
                            final boolean ret = Tools.getScrollingMenu(ClusterBrowser.getClassMenu(cl),
                                    colOrdPanel, classItem, dlm, new MyList<MyMenuItem>(dlm, getBackground()),
                                    thisClass, popups, null);
                            if (!ret) {
                                classItem.setEnabled(false);
                            }
                            thisMenu.add(classItem);
                        }
                    });
                } catch (final InterruptedException ix) {
                    Thread.currentThread().interrupt();
                } catch (final InvocationTargetException x) {
                    Tools.printStackTrace();
                }
            }
            super.update();
        }
    };
}

From source file:org.ecoinformatics.seek.ecogrid.CheckBoxTableCellRenderer.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    jTable = table;//from w  w w. j a  va  2 s .c  o m

    JPanel cellPanel = new JPanel();
    cellPanel.setBorder(new LineBorder(Color.lightGray, 1));
    cellPanel.setBackground(Color.WHITE);
    cellPanel.setPreferredSize(
            new Dimension(ServicesDisplayPanel.CELLPREFERREDWIDTH, ServicesDisplayPanel.HEIGHT));

    SelectableDocumentType selectedDocumentType = null;
    boolean isChecked = false;
    boolean isEnable = true;
    String text = null;
    if (value != null && value instanceof SelectableObjectInterface) {
        SelectableObjectInterface selectedObj = (SelectableObjectInterface) value;
        text = selectedObj.getSelectableObjectLabel();
        isChecked = selectedObj.getIsSelected();
        isEnable = selectedObj.getEnabled();
    }

    /*
     * label = (JLabel)renderer.getTableCellRendererComponent(table, text,
     * isSelected, hasFocus, row, column);
     */
    JLabel label = new JLabel(text);
    label.setFont(new Font(FONTNAME, Font.PLAIN, FONTSIZE));
    label.setPreferredSize(new Dimension(ServicesDisplayPanel.LABELPREFERWIDTH, ServicesDisplayPanel.HEIGHT));
    // set a check box name
    String checkBoxName = "" + topRowNum + SEPERATOR + row;
    JCheckBox checkBox = new JCheckBox();
    checkBox.setName(checkBoxName);
    checkBox.setBackground(Color.WHITE);
    checkBox.setSelected(isChecked);
    CheckBoxListener listener = new CheckBoxListener();
    checkBox.addItemListener(listener);
    // checkBox.setEnabled(false);

    /*
     * if (topRowNum != DEFAUTTOPROW ) { // for sub table we need to set up
     * check box enable status checkBox.setEnabled(isEnable); }//if
     */

    // add the label and checkbox to jpanel which has a border layout
    // manager
    BorderLayout layoutManager = new BorderLayout();
    cellPanel.setLayout(layoutManager);
    cellPanel.add(label, BorderLayout.CENTER);
    cellPanel.add(checkBox, BorderLayout.WEST);
    return cellPanel;
}

From source file:org.formic.wizard.step.gui.FeatureListStep.java

/**
 * {@inheritDoc}//from   w  w w.  ja v  a2s . c  om
 * @see org.formic.wizard.step.GuiStep#init()
 */
public Component init() {
    featureInfo = new JEditorPane("text/html", StringUtils.EMPTY);
    featureInfo.setEditable(false);
    featureInfo.addHyperlinkListener(new HyperlinkListener());

    Feature[] features = provider.getFeatures();
    JTable table = new JTable(features.length, 1) {
        private static final long serialVersionUID = 1L;

        public Class getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }

        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    table.setBackground(new javax.swing.JList().getBackground());

    GuiForm form = createForm();

    for (int ii = 0; ii < features.length; ii++) {
        final Feature feature = (Feature) features[ii];
        final JCheckBox box = new JCheckBox();

        String name = getName() + '.' + feature.getKey();
        form.bind(name, box);

        box.putClientProperty("feature", feature);
        featureMap.put(feature.getKey(), box);

        if (feature.getInfo() == null) {
            feature.setInfo(Installer.getString(getName() + "." + feature.getKey() + ".html"));
        }
        feature.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
                if (Feature.ENABLED_PROPERTY.equals(event.getPropertyName())) {
                    if (box.isSelected() != feature.isEnabled()) {
                        box.setSelected(feature.isEnabled());
                    }
                }
            }
        });

        box.setText(Installer.getString(name));
        box.setBackground(table.getBackground());
        if (!feature.isAvailable()) {
            box.setSelected(false);
            box.setEnabled(false);
        }
        table.setValueAt(box, ii, 0);
    }

    FeatureListMouseListener mouseListener = new FeatureListMouseListener();
    for (int ii = 0; ii < features.length; ii++) {
        Feature feature = (Feature) features[ii];
        if (feature.isEnabled() && feature.isAvailable()) {
            JCheckBox box = (JCheckBox) featureMap.get(feature.getKey());
            box.setSelected(true);
            mouseListener.processDependencies(feature);
            mouseListener.processExclusives(feature);
        }
    }

    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);
    table.setDefaultRenderer(JCheckBox.class, new ComponentTableCellRenderer());

    table.addKeyListener(new FeatureListKeyListener());
    table.addMouseListener(mouseListener);
    table.getSelectionModel().addListSelectionListener(new FeatureListSelectionListener(table));

    table.setRowSelectionInterval(0, 0);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    JPanel container = new JPanel(new BorderLayout());
    container.add(table, BorderLayout.CENTER);
    panel.add(new JScrollPane(container), BorderLayout.CENTER);
    JScrollPane infoScroll = new JScrollPane(featureInfo);
    infoScroll.setMinimumSize(new Dimension(0, 50));
    infoScroll.setMaximumSize(new Dimension(0, 50));
    infoScroll.setPreferredSize(new Dimension(0, 50));
    panel.add(infoScroll, BorderLayout.SOUTH);

    return panel;
}

From source file:org.openmicroscopy.shoola.agents.dataBrowser.view.SearchPanel.java

/**
 * Builds and lays out the component displaying the various options.
 * //w  w w .  j  av  a2 s .co m
 * @return See above.
 */
private JPanel buildFields() {
    List<SearchObject> nodes = model.getNodes();
    SearchObject n;
    int m = nodes.size();
    JCheckBox box;
    JPanel p = new JPanel();
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 1.0;
    c.gridy = 1;
    List<Integer> ctxNodes = null;
    SearchContext ctx = model.getSearchContext();
    if (ctx != null)
        ctxNodes = ctx.getContext();
    if (ctxNodes == null) {
        for (int i = 0; i < m; i++) {
            n = nodes.get(i);
            box = new JCheckBox(n.getDescription());
            box.setBackground(UIUtilities.BACKGROUND_COLOR);

            if (i % 2 == 0) {
                c.gridy++;
            }

            p.add(box, c);
            scopes.put(n.getIndex(), box);
        }
    } else {
        for (int i = 0; i < m; i++) {
            n = nodes.get(i);
            box = new JCheckBox(n.getDescription());
            box.setBackground(UIUtilities.BACKGROUND_COLOR);
            box.setSelected(ctxNodes.contains(n.getIndex()));

            if (i % 2 == 0)
                c.gridy++;

            p.add(box, c);
            scopes.put(n.getIndex(), box);
        }
    }
    c.gridy++;
    UIUtilities.setBoldTitledBorder("Restrict by Field", p);
    return p;
}

From source file:org.openmicroscopy.shoola.agents.dataBrowser.view.SearchPanel.java

/**
 * Builds and lays out the component displaying the various types.
 * /*from w  w  w.j  av a2 s. c o m*/
 * @return See above.
 */
private JPanel buildType() {
    JPanel p = new JPanel();
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.setLayout(new GridBagLayout());
    // p.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(3, 3, 3, 3);
    List<SearchObject> nodes = model.getTypes();
    List<Integer> ctxNodes = null;
    SearchContext ctx = model.getSearchContext();
    if (ctx != null)
        ctxNodes = ctx.getType();

    SearchObject n;
    int m = nodes.size();
    JCheckBox box;
    c.weightx = 1.0;

    if (ctxNodes == null) {
        for (int i = 0; i < m; i++) {
            n = nodes.get(i);
            box = new JCheckBox(n.getDescription());
            box.setBackground(UIUtilities.BACKGROUND_COLOR);
            box.setSelected(true);
            p.add(box, c);
            if (i % 2 == 0)
                c.gridy++;
            types.put(n.getIndex(), box);
        }
    } else {
        for (int i = 0; i < m; i++) {
            n = nodes.get(i);
            box = new JCheckBox(n.getDescription());
            box.setBackground(UIUtilities.BACKGROUND_COLOR);
            box.setSelected(ctxNodes.contains(n.getIndex()));
            p.add(box, c);
            if (i % 2 == 0)
                c.gridy++;
            types.put(n.getIndex(), box);
        }
    }

    UIUtilities.setBoldTitledBorder(TYPE_TITLE, p);
    return p;
}

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

/**
  * Builds the panel hosting the information
  * /*from  w  ww  . ja  v  a2s .  c  om*/
  * @param details The information to display.
  * @param image     The image of reference.
  * @return See above.
  */
private JPanel buildContentPanel(Map details, ImageData image) {
    JPanel content = new JPanel();
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    content.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    content.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 2, 2, 0);
    c.gridy = 0;
    c.gridx = 0;
    JLabel l = new JLabel();
    Font font = l.getFont();
    int size = font.getSize() - 2;
    JLabel label = UIUtilities.setTextFont(EditorUtil.ARCHIVED, Font.BOLD, size);
    JCheckBox box = new JCheckBox();
    box.setEnabled(false);
    box.setBackground(UIUtilities.BACKGROUND);
    box.setSelected(model.isArchived());
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(box, c);
    c.gridy++;
    c.gridx = 0;
    label = UIUtilities.setTextFont(EditorUtil.ACQUISITION_DATE, Font.BOLD, size);
    JLabel value = UIUtilities.createComponent(null);
    String v = model.formatDate(image);
    value.setText(v);
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);
    c.gridy++;
    c.gridx = 0;
    try { //just to be on the save side
        label = UIUtilities.setTextFont(EditorUtil.IMPORTED_DATE, Font.BOLD, size);
        value = UIUtilities.createComponent(null);
        v = UIUtilities.formatShortDateTime(image.getInserted());
        value.setText(v);
        content.add(label, c);
        c.gridx = c.gridx + 2;
        content.add(value, c);
        c.gridy++;
    } catch (Exception e) {

    }
    label = UIUtilities.setTextFont(EditorUtil.XY_DIMENSION, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    v = (String) details.get(EditorUtil.SIZE_X);
    v += " x ";
    v += (String) details.get(EditorUtil.SIZE_Y);
    value.setText(v);
    c.gridx = 0;
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);
    c.gridy++;
    label = UIUtilities.setTextFont(EditorUtil.PIXEL_TYPE, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setText((String) details.get(EditorUtil.PIXEL_TYPE));
    c.gridx = 0;
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);

    value = UIUtilities.createComponent(null);
    String s = formatPixelsSize(details, value);
    if (s != null) {
        c.gridy++;
        label = UIUtilities.setTextFont(s, Font.BOLD, size);
        c.gridx = 0;
        content.add(label, c);
        c.gridx = c.gridx + 2;
        content.add(value, c);
    }
    //parse modulo T.
    Map<Integer, ModuloInfo> modulo = model.getModulo();
    ModuloInfo moduloT = modulo.get(ModuloInfo.T);
    c.gridy++;
    label = UIUtilities.setTextFont(EditorUtil.Z_T_FIELDS, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    v = (String) details.get(EditorUtil.SECTIONS);
    v += " x ";
    if (moduloT != null) {
        String time = (String) details.get(EditorUtil.TIMEPOINTS);
        int t = Integer.parseInt(time);
        v += "" + (t / moduloT.getSize());
    } else {
        v += (String) details.get(EditorUtil.TIMEPOINTS);
    }
    value.setText(v);
    c.gridx = 0;
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);
    c.gridy++;
    if (moduloT != null) {
        label = UIUtilities.setTextFont(EditorUtil.SMALL_T_VARIABLE, Font.BOLD, size);
        value = UIUtilities.createComponent(null);
        value.setText("" + moduloT.getSize());
        c.gridx = 0;
        content.add(label, c);
        c.gridx = c.gridx + 2;
        content.add(value, c);
        c.gridy++;
    }
    if (!model.isNumerousChannel() && model.getRefObjectID() > 0) {
        label = UIUtilities.setTextFont(EditorUtil.CHANNELS, Font.BOLD, size);
        c.gridx = 0;
        c.anchor = GridBagConstraints.NORTHEAST;
        content.add(label, c);
        c.anchor = GridBagConstraints.CENTER;
        c.gridx++;
        content.add(editChannel, c);
        c.gridx++;
        content.add(channelsPane, c);
    }
    JPanel p = UIUtilities.buildComponentPanel(content);
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    return p;
}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

private TableCellRenderer getCellRenderer(final SwingTreeCol col) {

    return new DefaultTableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {

            ColumnType colType = col.getColumnType();
            if (colType == ColumnType.DYNAMIC) {
                colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column));
            }//w w  w .j av a 2 s.  c o  m

            final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column);
            switch (colType) {
            case CHECKBOX:
                JCheckBox checkbox = new JCheckBox();
                if (value instanceof String) {
                    checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$
                } else if (value instanceof Boolean) {
                    checkbox.setSelected((Boolean) value);
                } else if (value == null) {
                    checkbox.setSelected(false);
                }
                if (isSelected) {
                    checkbox.setBackground(Color.LIGHT_GRAY);
                }
                checkbox.setEnabled(!cell.isDisabled());
                return checkbox;
            case COMBOBOX:
            case EDITABLECOMBOBOX:
                Vector data;

                final JComboBox comboBox = new JComboBox();
                if (cell == null) {
                } else {
                    data = (cell.getValue() != null) ? (Vector) cell.getValue() : new Vector();

                    if (data == null) {
                        logger.debug("SwingTreeCell combobox data is null, passed in value: " + value); //$NON-NLS-1$
                        if (value instanceof Vector) {
                            data = (Vector) value;
                        }
                    }
                    if (data != null) {
                        comboBox.setModel(new DefaultComboBoxModel(data));
                        try {
                            comboBox.setSelectedIndex(cell.getSelectedIndex());
                        } catch (Exception e) {
                            logger.error("error setting selected index on the combobox editor"); //$NON-NLS-1$
                        }
                    }
                }

                if (colType == ColumnType.EDITABLECOMBOBOX) {
                    comboBox.setEditable(true);
                    ((JTextComponent) comboBox.getEditor().getEditorComponent()).setText(cell.getLabel());
                }

                if (isSelected) {
                    comboBox.setBackground(Color.LIGHT_GRAY);
                }
                comboBox.setEnabled(!cell.isDisabled());
                return comboBox;
            case CUSTOM:
                return new CustomCellEditorWrapper(cell, customEditors.get(col.getType()));
            default:
                JLabel label = new JLabel((String) value);

                if (isSelected) {
                    label.setOpaque(true);
                    label.setBackground(Color.LIGHT_GRAY);
                }
                return label;
            }

        }
    };

}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

private TableCellEditor getCellEditor(final SwingTreeCol col) {
    return new DefaultCellEditor(new JComboBox()) {

        JComponent control;// ww w  . ja  v a2s .c  o  m

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
                final int row, final int column) {
            Component comp;
            ColumnType colType = col.getColumnType();
            if (colType == ColumnType.DYNAMIC) {
                colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column));
            }

            final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column);
            switch (colType) {
            case CHECKBOX:
                final JCheckBox checkbox = new JCheckBox();
                final JTable tbl = table;
                checkbox.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        SwingTree.this.table.setValueAt(checkbox.isSelected(), row, column);
                        tbl.getCellEditor().stopCellEditing();
                    }
                });

                control = checkbox;
                if (value instanceof String) {
                    checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$
                } else if (value instanceof Boolean) {
                    checkbox.setSelected((Boolean) value);
                } else if (value == null) {
                    checkbox.setSelected(false);
                }
                if (isSelected) {
                    checkbox.setBackground(Color.LIGHT_GRAY);
                }
                comp = checkbox;
                checkbox.setEnabled(!cell.isDisabled());
                break;
            case EDITABLECOMBOBOX:
            case COMBOBOX:
                Vector val = (value != null && value instanceof Vector) ? (Vector) value : new Vector();
                final JComboBox comboBox = new JComboBox(val);

                if (isSelected) {
                    comboBox.setBackground(Color.LIGHT_GRAY);
                }

                if (colType == ColumnType.EDITABLECOMBOBOX) {

                    comboBox.setEditable(true);
                    final JTextComponent textComp = (JTextComponent) comboBox.getEditor().getEditorComponent();

                    textComp.addKeyListener(new KeyListener() {
                        private String oldValue = ""; //$NON-NLS-1$

                        public void keyPressed(KeyEvent e) {
                            oldValue = textComp.getText();
                        }

                        public void keyReleased(KeyEvent e) {
                            if (oldValue != null && !oldValue.equals(textComp.getText())) {
                                SwingTree.this.table.setValueAt(textComp.getText(), row, column);

                                oldValue = textComp.getText();
                            } else if (oldValue == null) {
                                // AWT error where sometimes the keyReleased is fired before keyPressed.
                                oldValue = textComp.getText();
                            } else {
                                logger.debug("Special key pressed, ignoring"); //$NON-NLS-1$
                            }
                        }

                        public void keyTyped(KeyEvent e) {
                        }
                    });

                    comboBox.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent event) {
                            // if(textComp.hasFocus() == false && comboBox.hasFocus()){
                            SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$
                                    + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$

                            SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column);
                            // }
                        }
                    });
                } else {
                    comboBox.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent event) {

                            SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$
                                    + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$

                            SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column);
                        }
                    });
                }

                control = comboBox;
                comboBox.setEnabled(!cell.isDisabled());
                comp = comboBox;
                break;
            case LABEL:
                JLabel lbl = new JLabel(cell.getLabel());
                comp = lbl;
                control = lbl;
                break;
            case CUSTOM:
                return new CustomCellEditorWrapper(cell, customEditors.get(col.getType()));
            default:
                final JTextField label = new JTextField((String) value);

                label.getDocument().addDocumentListener(new DocumentListener() {

                    public void changedUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                    public void insertUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                    public void removeUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                });
                if (isSelected) {
                    label.setOpaque(true);
                    // label.setBackground(Color.LIGHT_GRAY);
                }

                control = label;
                comp = label;
                label.setEnabled(!cell.isDisabled());
                label.setDisabledTextColor(Color.DARK_GRAY);
                break;
            }

            return comp;
        }

        @Override
        public Object getCellEditorValue() {
            if (control instanceof JCheckBox) {
                return ((JCheckBox) control).isSelected();
            } else if (control instanceof JComboBox) {
                JComboBox box = (JComboBox) control;
                if (box.isEditable()) {
                    return ((JTextComponent) box.getEditor().getEditorComponent()).getText();
                } else {
                    return box.getSelectedIndex();
                }
            } else if (control instanceof JTextField) {
                return ((JTextField) control).getText();
            } else {
                return ((JLabel) control).getText();
            }
        }

    };

}