Example usage for java.awt Component isEnabled

List of usage examples for java.awt Component isEnabled

Introduction

In this page you can find the example usage for java.awt Component isEnabled.

Prototype

public boolean isEnabled() 

Source Link

Document

Determines whether this component is enabled.

Usage

From source file:MainClass.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Insets insets = getBorderInsets(c);
    Color horizontalColor;/*from w w  w .j  a v  a  2 s .c om*/
    Color verticalColor;
    if (c.isEnabled()) {
        boolean pressed = false;
        if (c instanceof AbstractButton) {
            ButtonModel model = ((AbstractButton) c).getModel();
            pressed = model.isPressed();
        }
        if (pressed) {
            horizontalColor = Color.WHITE;
            verticalColor = Color.BLACK;
        } else {
            horizontalColor = Color.BLACK;
            verticalColor = Color.WHITE;
        }
    } else {
        horizontalColor = Color.LIGHT_GRAY;
        verticalColor = Color.LIGHT_GRAY;
    }
    g.setColor(horizontalColor);

    g.translate(x, y);

    // top
    g.fillRect(0, 0, width, insets.top);
    // bottom
    g.fillRect(0, height - insets.bottom, width, insets.bottom);

    g.setColor(verticalColor);
    // left
    g.fillRect(0, insets.top, insets.left, height - insets.top - insets.bottom);
    // right
    g.fillRect(width - insets.right, insets.top, insets.right, height - insets.top - insets.bottom);
    g.translate(-x, -y);
}

From source file:CustomIconDemo.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    int length = xPoints.length;
    int adjustedXPoints[] = new int[length];
    int adjustedYPoints[] = new int[length];

    for (int i = 0; i < length; i++) {
        adjustedXPoints[i] = xPoints[i] + x;
        adjustedYPoints[i] = yPoints[i] + y;
    }/*from   www  . j av a 2 s. c o  m*/

    if (c.isEnabled()) {
        g.setColor(Color.black);
    } else {
        g.setColor(Color.gray);
    }

    g.fillPolygon(adjustedXPoints, adjustedYPoints, length);
}

From source file:edu.ku.brc.af.ui.forms.FormViewObj.java

/**
 * @param dataObj/*from  w  ww  . java  2  s .  c  o m*/
 */
protected void processControlsForSecurity(Object dataObj) {
    boolean editable = checkEditPermission(dataObj);
    for (String id : controlsById.keySet()) {
        //In case business rules have intentionally disabled controls. (bug 10068)
        Component cmp = getControlById(id);
        cmp.setEnabled(cmp.isEnabled() && editable);

        //The old way:
        //getControlById(id).setEnabled(editable);
    }
}

From source file:edu.ku.brc.af.ui.forms.FormViewObj.java

/**
 * This will choose the first focusable UI component that doesn't have a value. 
 * BUT! It always chooses a JTextField over anything else.
 * (NOTE: We may want a non-JTextField that is required to override a JTextField that is not.)
 * // w w w .j a va 2  s .  c  om
 * @return the focusable first object.
 */
public Component getFirstFocusable() {
    int insertPos = Integer.MAX_VALUE;
    Component focusable = null;
    Component first = null;
    for (FVOFieldInfo compFI : compsList) {
        Component comp = compFI.getComp();

        if (comp.isEnabled() && comp.isFocusable() && comp instanceof GetSetValueIFace) {
            Object val = ((GetSetValueIFace) comp).getValue();
            if (val == null || (val instanceof String && StringUtils.isEmpty((String) val))) {
                if (comp instanceof ValFormattedTextFieldSingle) {
                    ValFormattedTextFieldSingle vtf = (ValFormattedTextFieldSingle) comp;
                    if (vtf.getFormatter() != null && vtf.getFormatter().isIncrementer()) {
                        continue;
                    }
                }
                boolean override = false;//focusable instanceof JTextField && !(comp instanceof JTextField);

                if (compFI.getInsertPos() < insertPos || override) {

                    if (comp instanceof UIValidatable) {

                        focusable = ((UIValidatable) comp).getValidatableUIComp();
                    } else {
                        focusable = comp;
                    }

                    if (!override) // keep the same (lower) position as the original
                    {
                        insertPos = compFI.getInsertPos();
                    }
                }
            }

            if (compFI.getInsertPos() == 0) {
                first = comp;
            }
        }
    }

    if (focusable instanceof JTextField && !(first instanceof JTextField)) {
        return focusable;
    }

    return first != null ? first : focusable;
}

From source file:edu.ku.brc.af.ui.forms.FormViewObj.java

/**
 * Increments to the next number in the series.
 *//*from  w  ww. j  a v a  2s  .  c  o m*/
public void updateAutoNumbers() {
    if (isAutoNumberOn) {
        for (FVOFieldInfo fieldInfo : controlsById.values()) {
            Component comp = fieldInfo.getComp();
            if (comp instanceof AutoNumberableIFace && comp.isEnabled()) {
                ((AutoNumberableIFace) comp).updateAutoNumbers();
            }
        }
    }
}

From source file:org.jdal.swing.form.FormFocusTransversalPolicy.java

@Override
public Component getComponentAfter(Container container, Component component) {

    // Fix awt bug looking for ComboBoxEditor instead ComboBox
    // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6205817
    if (component.getParent() instanceof JComboBox)
        component = component.getParent();

    int index = components.indexOf(component);

    if (index == -1) { // not owner
        Container childContainer = getTopmostProvider(container, component);
        if (childContainer == null)
            return getFirstComponent(container);

        FocusTraversalPolicy ftp = childContainer.getFocusTraversalPolicy();
        if (ftp != null && ftp != this) {
            Component next = ftp.getComponentAfter(childContainer, component);
            if (next != ftp.getFirstComponent(container))
                return next;

            // child cycle
            do {/* www . ja va  2 s . co m*/
                index = components.indexOf(childContainer);
                childContainer = childContainer.getParent();
            } while (index == -1 || childContainer == null);

            if (index == -1) {
                log.warn("I can't figure what is the next component");
                return getFirstComponent(container);
            }
        }
    }

    index++;

    if (index < components.size() && index >= 0) {
        Component c = getComponent(index);
        if (c.isEnabled() && c.isFocusable())
            return c;
        else
            return getComponentAfter(container, c);
    }

    return getFirstComponent(container);
}

From source file:org.jdal.swing.form.FormFocusTransversalPolicy.java

@Override
public Component getComponentBefore(Container aContainer, Component aComponent) {

    int index = components.indexOf(aComponent);
    index--;//from  w  w  w  .j a  va2 s.  c  o  m

    if (index < components.size() && index >= 0) {
        Component c = getComponent(index);
        if (c.isEnabled())
            return c;
        else
            return getComponentBefore(aContainer, c);
    }

    return getLastComponent(aContainer);
}

From source file:org.jdal.swing.form.FormFocusTransversalPolicy.java

@Override
public Component getLastComponent(Container aContainer) {
    if (!components.isEmpty()) {
        Component c = components.get(components.size() - 1);
        if (c.isEnabled())
            return c;
        else/*from  w w  w  .jav  a  2s.  c  o m*/
            return getComponentBefore(aContainer, c);
    }

    return null;
}

From source file:org.opendatakit.briefcase.ui.MainBriefcaseWindow.java

/**
 * Create the application.//from  www . j  a  va2 s.c  o m
 */
public MainBriefcaseWindow() {
    frame = new JFrame();
    frame.setBounds(100, 100, 680, 595);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.addWindowListener(new WindowListener() {
        @Override
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosing(WindowEvent e) {
        }

        @Override
        public void windowClosed(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }
    });

    JLabel lblBriefcaseDirectory = new JLabel(MessageStrings.BRIEFCASE_STORAGE_LOCATION);

    txtBriefcaseDir = new JTextField();
    txtBriefcaseDir.setFocusable(false);
    txtBriefcaseDir.setEditable(false);
    txtBriefcaseDir.setColumns(10);

    btnChoose = new JButton("Change...");
    btnChoose.addActionListener(new FolderActionListener());

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
    groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
            .createSequentialGroup().addContainerGap()
            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addComponent(tabbedPane, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 628,
                            Short.MAX_VALUE)
                    .addGroup(groupLayout.createSequentialGroup().addComponent(lblBriefcaseDirectory).addGap(18)
                            .addComponent(txtBriefcaseDir, GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
                            .addGap(18).addComponent(btnChoose)))
            .addContainerGap()));
    groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(groupLayout.createSequentialGroup().addContainerGap()
                    .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                            .addComponent(txtBriefcaseDir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnChoose).addComponent(lblBriefcaseDirectory))
                    .addGap(33).addComponent(tabbedPane, GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
                    .addContainerGap()));

    gatherPanel = new PullTransferPanel(transferTerminationFuture);
    tabbedPane.addTab(PullTransferPanel.TAB_NAME, null, gatherPanel, null);
    PullTransferPanel.TAB_POSITION = 0;

    uploadPanel = new PushTransferPanel(transferTerminationFuture);
    tabbedPane.addTab(PushTransferPanel.TAB_NAME, null, uploadPanel, null);
    PushTransferPanel.TAB_POSITION = 1;

    exportPanel = new ExportPanel(exportTerminationFuture);
    tabbedPane.addTab(ExportPanel.TAB_NAME, null, exportPanel, null);
    frame.getContentPane().setLayout(groupLayout);
    ExportPanel.TAB_POSITION = 2;

    frame.addWindowListener(this);
    setFullUIEnabled(false);

    frame.setFocusTraversalPolicy(new FocusTraversalPolicy() {

        @Override
        public Component getComponentAfter(Container arg0, Component arg1) {
            ArrayList<Component> componentOrdering = new ArrayList<Component>();
            for (;;) {
                int nextPanel = PullTransferPanel.TAB_POSITION;
                componentOrdering.clear();
                componentOrdering.add(txtBriefcaseDir);
                componentOrdering.add(btnChoose);
                componentOrdering.add(tabbedPane);
                int idx = tabbedPane.getSelectedIndex();
                if (idx == PullTransferPanel.TAB_POSITION) {
                    componentOrdering.addAll(gatherPanel.getTraversalOrdering());
                    nextPanel = PushTransferPanel.TAB_POSITION;
                } else if (idx == PushTransferPanel.TAB_POSITION) {
                    componentOrdering.addAll(uploadPanel.getTraversalOrdering());
                    nextPanel = ExportPanel.TAB_POSITION;
                } else if (idx == ExportPanel.TAB_POSITION) {
                    componentOrdering.addAll(exportPanel.getTraversalOrdering());
                    nextPanel = PullTransferPanel.TAB_POSITION;
                }
                componentOrdering.add(btnChoose);
                boolean found = false;
                for (int i = 0; i < componentOrdering.size() - 1; ++i) {
                    if (found || arg1 == componentOrdering.get(i)) {
                        found = true;
                        Component comp = componentOrdering.get(i + 1);
                        if (comp == tabbedPane) {
                            return comp;
                        }
                        if (comp.isVisible() && comp.isEnabled()
                                && (!(comp instanceof JTextField) || ((JTextField) comp).isEditable())) {
                            return comp;
                        }
                    }
                }
                if (!found) {
                    return componentOrdering.get(0);
                }
                tabbedPane.setSelectedIndex(nextPanel);
            }
        }

        @Override
        public Component getComponentBefore(Container arg0, Component arg1) {
            ArrayList<Component> componentOrdering = new ArrayList<Component>();
            for (;;) {
                int nextPanel = PullTransferPanel.TAB_POSITION;
                componentOrdering.clear();
                componentOrdering.add(txtBriefcaseDir);
                componentOrdering.add(btnChoose);
                componentOrdering.add(tabbedPane);
                int idx = tabbedPane.getSelectedIndex();
                if (idx == PullTransferPanel.TAB_POSITION) {
                    componentOrdering.addAll(gatherPanel.getTraversalOrdering());
                    nextPanel = ExportPanel.TAB_POSITION;
                } else if (idx == PushTransferPanel.TAB_POSITION) {
                    componentOrdering.addAll(uploadPanel.getTraversalOrdering());
                    nextPanel = PullTransferPanel.TAB_POSITION;
                } else if (idx == ExportPanel.TAB_POSITION) {
                    componentOrdering.addAll(exportPanel.getTraversalOrdering());
                    nextPanel = PushTransferPanel.TAB_POSITION;
                }
                componentOrdering.add(btnChoose);
                boolean found = false;
                for (int i = componentOrdering.size() - 1; i > 0; --i) {
                    if (found || arg1 == componentOrdering.get(i)) {
                        found = true;
                        Component comp = componentOrdering.get(i - 1);
                        if (comp == tabbedPane) {
                            return comp;
                        }
                        if (comp.isVisible() && comp.isEnabled()
                                && (!(comp instanceof JTextField) || ((JTextField) comp).isEditable())) {
                            return comp;
                        }
                    }
                }
                if (!found) {
                    return componentOrdering.get(componentOrdering.size() - 1);
                }
                tabbedPane.setSelectedIndex(nextPanel);
            }
        }

        @Override
        public Component getDefaultComponent(Container arg0) {
            return btnChoose;
        }

        @Override
        public Component getFirstComponent(Container arg0) {
            return btnChoose;
        }

        @Override
        public Component getLastComponent(Container arg0) {
            return tabbedPane;
        }
    });
}

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

/**
 * Creates the menu displaying the groups and users.
 * //from   w  ww  .  j  ava 2 s  .  com
 * @param source The invoker.
 * @param p The location of the mouse clicked.
 */
private void createGroupsAndUsersMenu(Component source, Point p) {
    if (!source.isEnabled())
        return;
    Collection groups = model.getGroups();
    if (CollectionUtils.isEmpty(groups))
        return;
    popupMenu.removeAll();
    GroupData group;
    List sortedGroups = sorter.sort(groups);

    //Determine the group already displayed.
    Browser browser = model.getBrowser(Browser.PROJECTS_EXPLORER);
    List<TreeImageDisplay> nodes;
    ExperimenterVisitor visitor;
    //Find the user already added to the selected group.
    visitor = new ExperimenterVisitor(browser, -1);
    browser.accept(visitor);
    nodes = visitor.getNodes();
    Iterator<TreeImageDisplay> k = nodes.iterator();
    List<Long> groupIds = new ArrayList<Long>();
    long id;
    while (k.hasNext()) {
        id = k.next().getUserObjectId();
        if (id >= 0)
            groupIds.add(id);
    }

    //Create the group menu.
    Iterator i = sortedGroups.iterator();
    int size = sortedGroups.size();
    long userID = model.getExperimenter().getId();

    //First add item to toggle between users and group display
    DataMenuItem data = new DataMenuItem(DataMenuItem.USERS_TEXT, null);
    data.setSelected(model.getDisplayMode() == LookupNames.EXPERIMENTER_DISPLAY);
    data.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (DataMenuItem.ITEM_SELECTED_PROPERTY.equals(name)) {
                DataMenuItem data = (DataMenuItem) evt.getNewValue();
                handleSelectionDisplay(data.isSelected());
            }
        }
    });
    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    panel.setBorder(null);
    IconManager icons = IconManager.getInstance();
    panel.add(new JLabel(icons.getIcon(IconManager.TRANSPARENT)));
    panel.add(data);
    popupMenu.add(panel);
    popupMenu.add(new JSeparator());
    GroupItem item;
    GroupItem allGroup = null;
    //First add option to add all the groups.
    if (size > 1) {
        item = new GroupItem(false);
        item.setUserID(userID);
        createGroupMenu(item, 0);
        popupMenu.add(item);
        popupMenu.add(new JSeparator());
        allGroup = item;
    }

    boolean selected;
    int count = 0;
    while (i.hasNext()) {
        group = (GroupData) i.next();
        boolean b = groupIds.contains(group.getId());
        item = new GroupItem(group, b, size > 1);
        item.setUserID(userID);
        selected = createGroupMenu(item, size);
        popupMenu.add(item);
        if (selected)
            count++;
    }
    if (allGroup != null) {
        allGroup.setMenuSelected(count == sortedGroups.size(), false);
    }
    popupMenu.show(source, p.x, p.y);
}