Example usage for javax.swing JRadioButton getModel

List of usage examples for javax.swing JRadioButton getModel

Introduction

In this page you can find the example usage for javax.swing JRadioButton getModel.

Prototype

public ButtonModel getModel() 

Source Link

Document

Returns the model that this button represents.

Usage

From source file:org.nuclos.client.ui.OptionGroup.java

private void addRadioButton(String sLabel, String sMnemonic, String sValue) {
    final JRadioButton radiobtn = new JRadioButton(sLabel);
    if (sMnemonic != null && sMnemonic.length() > 0) {
        radiobtn.setMnemonic(sMnemonic.charAt(0));
    }//from  w  ww. j a  v  a2s.  c om
    radiobtn.getModel().setActionCommand(sValue);
    radiobtn.getModel().setGroup(bg);
    radiobtn.addActionListener(actionListener);
    radiobtn.setEnabled(this.isEnabled());
    MouseListener[] mls = getMouseListeners();
    for (int i = 0; i < mls.length; i++) {
        radiobtn.addMouseListener(mls[i]);
    }
    bg.add(radiobtn);
    this.add(radiobtn);
}

From source file:org.nuclos.client.ui.OptionGroup.java

/**
 * @param sValue//from  ww w .  j a v  a 2  s.  c  o m
 */
public void setValue(String sValue) {
    final Enumeration<AbstractButton> enumElements = bg.getElements();
    while (enumElements.hasMoreElements()) {
        final JRadioButton radiobtn = (JRadioButton) enumElements.nextElement();
        if (sValue == null) {
            // unselect all buttons:
            radiobtn.setSelected(false);
            bg.clearSelection();
        } else {
            // select matching button, if any:
            if (radiobtn.getModel().getActionCommand().equals(sValue)) {
                radiobtn.setSelected(true);
                break;
            }
        }
    }
}

From source file:org.nuclos.client.ui.OptionGroup.java

/**
 * @todo What does this mean? - Compare to setValue()!
 * @param sDefaultOption/*from  w ww . j  a  va2  s  .  co  m*/
 */
public void setDefaultOption(String sDefaultOption) {
    final Enumeration<AbstractButton> enumeration = bg.getElements();
    while (enumeration.hasMoreElements()) {
        final JRadioButton radiobtn = (JRadioButton) enumeration.nextElement();
        if (radiobtn.getModel().getActionCommand().equals(sDefaultOption)) {
            radiobtn.getModel().setSelected(true);
            break;
        }
    }
}

From source file:org.nuclos.client.ui.OptionGroup.java

/**
 *
 *///w  w w .  ja v  a 2s  .  c om
public ActionListener getActionListener() {
    return new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            final Enumeration<AbstractButton> enumeration = bg.getElements();
            while (enumeration.hasMoreElements()) {
                final JRadioButton radiobtn = (JRadioButton) enumeration.nextElement();
                if (radiobtn.getModel().getActionCommand().equals(ev.getActionCommand())) {
                    radiobtn.setSelected(true);
                    break;
                }
            }
        }
    };
}

From source file:renderer.DependencyGrapher.java

/**
 * create an instance of a simple graph in two views with controls to
 * demo the features.//w w w .  j ava  2  s.c  o  m
 * 
 */
public DependencyGrapher() {

    // create a simple graph for the demo
    final DependencyDirectedSparceMultiGraph<String, Number> graph = createGraph(); //TestGraphs.getOneComponentGraph();

    // the preferred sizes for the two views

    // create one layout for the graph
    final FRLayout2<String, Number> layout = new FRLayout2<String, Number>(graph);
    layout.setMaxIterations(500);

    VisualizationModel<String, Number> vm = new DefaultVisualizationModel<String, Number>(layout,
            preferredSize1);

    Transformer<Number, String> stringer = new Transformer<Number, String>() {
        public String transform(Number e) {
            if (graph.getEdgeAttributes(e) != null) {
                return graph.getEdgeAttributes(e).toString();
            }
            return null;
        }
    };
    // create 2 views that share the same model
    final VisualizationViewer<String, Number> vv = new VisualizationViewer<String, Number>(vm, preferredSize1);
    vv.setBackground(Color.white);
    vv.getRenderContext().setEdgeLabelTransformer(stringer);
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<String, Number>(vv.getPickedEdgeState(), Color.black, Color.cyan));
    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(vv.getPickedVertexState(), Color.red, Color.yellow));
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);

    // add default listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());

    //      ToolTipManager.sharedInstance().setDismissDelay(10000);

    Container content = getContentPane();
    Container panel = new JPanel(new BorderLayout());

    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    panel.add(gzsp);

    helpDialog = new JDialog();
    helpDialog.getContentPane().add(new JLabel(instructions));

    RenderContext<String, Number> rc = vv.getRenderContext();
    AnnotatingGraphMousePlugin annotatingPlugin = new AnnotatingGraphMousePlugin(rc);
    // create a GraphMouse for the main view
    // 
    final AnnotatingModalGraphMouse graphMouse = new AnnotatingModalGraphMouse(rc, annotatingPlugin);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton filterReset = new JButton("Reset");
    filterReset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getModel().setGraphLayout(layout);
        }
    });
    JButton filterFilter = new JButton("Filter");
    filterReset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getModel().setGraphLayout(layout);
        }
    });
    JRadioButton filterDirectionInOut = new JRadioButton("In/Out");
    filterDirectionInOut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Dependency Direction: " + EdgeType.IN_OUT);
            _filterEdgeDirection = EdgeType.IN_OUT;
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }

    });
    JRadioButton filterDirectionIn = new JRadioButton("In");
    filterDirectionIn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Dependency Direction: " + EdgeType.IN);
            _filterEdgeDirection = EdgeType.IN;
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }

    });
    JRadioButton filterDirectionOut = new JRadioButton("Out");
    filterDirectionOut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Dependency Direction: " + EdgeType.OUT);
            _filterEdgeDirection = EdgeType.OUT;
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }

    });
    ButtonGroup filterRadios = new ButtonGroup();
    filterRadios.add(filterDirectionInOut);
    filterRadios.add(filterDirectionIn);
    filterRadios.add(filterDirectionOut);
    filterRadios.setSelected(filterDirectionInOut.getModel(), true);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.setSelectedItem(ModalGraphMouse.Mode.PICKING);

    final JComboBox filterBox = new JComboBox(graph.getVertices().toArray());
    filterBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            _filterChoice = filterBox.getSelectedItem().toString();
            System.out.println(_filterChoice);
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }
    });

    JButton help = new JButton("Help");
    help.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            helpDialog.pack();
            helpDialog.setVisible(true);
        }
    });

    JPanel controls = new JPanel();

    JPanel modeControls = new JPanel();
    modeControls.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modeControls.add(graphMouse.getModeComboBox());
    controls.add(modeControls);

    JPanel annotationControlPanel = new JPanel();
    annotationControlPanel.setBorder(BorderFactory.createTitledBorder("Annotation Controls"));

    AnnotationControls annotationControls = new AnnotationControls(annotatingPlugin);

    annotationControlPanel.add(annotationControls.getAnnotationsToolBar());
    controls.add(annotationControlPanel);

    JPanel helpControls = new JPanel();
    helpControls.setBorder(BorderFactory.createTitledBorder("Help"));
    helpControls.add(help);
    controls.add(helpControls);

    JPanel filterControls = new JPanel();
    filterControls.setBorder(BorderFactory.createTitledBorder("Filter"));
    filterControls.add(filterBox);
    filterControls.add(filterDirectionInOut);
    filterControls.add(filterDirectionIn);
    filterControls.add(filterDirectionOut);
    filterControls.add(filterReset);
    controls.add(filterControls);

    content.add(panel);
    content.add(controls, BorderLayout.SOUTH);

}

From source file:uk.nhs.cfh.dsp.yasb.searchpanel.SearchPanel.java

/**
 * Creates the button panel.// w  w  w .j  a va 2 s  . c o m
 */
private void createButtonPanel() {

    buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.PAGE_AXIS));

    JPanel fieldsPanel = new JPanel();
    fieldsPanel.add(new JLabel("Search using "));
    fieldsPanel.add(Box.createHorizontalStrut(5));
    fieldsPanel.setLayout(new BoxLayout(fieldsPanel, BoxLayout.LINE_AXIS));
    // create button group for term selection
    JRadioButton allRadioButton = new JRadioButton(new AbstractAction("Term") {

        public void actionPerformed(ActionEvent event) {
            // set search on term
            searchConceptId = false;
            doSearch();
        }
    });

    JRadioButton idRadioButton = new JRadioButton(new AbstractAction("ID") {

        public void actionPerformed(ActionEvent event) {
            // set search on id
            searchConceptId = true;
            doSearch();
        }
    });

    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(allRadioButton);
    buttonGroup.add(idRadioButton);
    buttonGroup.setSelected(allRadioButton.getModel(), true);

    // add search field terms to fields panel
    fieldsPanel.add(allRadioButton);
    fieldsPanel.add(idRadioButton);
    fieldsPanel.add(Box.createHorizontalGlue());

    // create panel that contains button that toggles display of controlsPane
    JideButton controlsButton = new JideButton(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (controlsPane.isCollapsed()) {
                controlsPane.setCollapsed(false);
            } else {
                controlsPane.setCollapsed(true);
            }
        }
    });
    controlsButton.setIcon(new ImageIcon(SearchPanel.class.getResource("resources/configure.png")));
    controlsButton.setToolTipText("Click to display or hide configuration panel");
    JPanel panel4 = new JPanel();
    panel4.setLayout(new BoxLayout(panel4, BoxLayout.LINE_AXIS));
    panel4.add(Box.createHorizontalGlue());
    panel4.add(new JLabel("Change search and display preferences "));
    panel4.add(controlsButton);

    // add panels to button panel
    buttonsPanel.add(fieldsPanel);
    buttonsPanel.add(panel4);
}