Example usage for javax.swing JToggleButton JToggleButton

List of usage examples for javax.swing JToggleButton JToggleButton

Introduction

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

Prototype

public JToggleButton(Action a) 

Source Link

Document

Creates a toggle button where properties are taken from the Action supplied.

Usage

From source file:com.romraider.logger.ecu.ui.handler.graph.GraphUpdateHandler.java

public GraphUpdateHandler(final JPanel panel) {
    this.graphPanel = new JPanel(new SpringLayout());
    final JCheckBox combinedCheckbox = new JCheckBox("Combine Graphs", combinedChart);
    combinedCheckbox.addActionListener(new CombinedActionListener(combinedCheckbox));
    JToggleButton playPauseButton = new JToggleButton("Pause Graphs");
    playPauseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            paused = !paused;//from   w  w  w .  j a v a2  s  .  co  m
            if (paused) {
                pauseStartTime = System.currentTimeMillis();
            } else {
                startTime = startTime + (System.currentTimeMillis() - pauseStartTime);
            }
        }
    });
    panel.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(getKeyStroke("F12"), "toggleCombineGraphs");
    panel.getActionMap().put("toggleCombineGraphs", new AbstractAction() {
        private static final long serialVersionUID = 1540427179539775534L;

        public void actionPerformed(ActionEvent e) {
            combinedCheckbox.doClick();
        }
    });
    JPanel controlPanel = new JPanel();
    controlPanel.add(combinedCheckbox);
    controlPanel.add(playPauseButton);
    panel.add(controlPanel, NORTH);
    panel.add(this.graphPanel, CENTER);
}

From source file:net.brtly.monkeyboard.plugin.ConsolePanel.java

public ConsolePanel(PluginDelegate service) {
    super(service);
    setLayout(new MigLayout("inset 5", "[grow][:100:100][24:n:24][24:n:24]", "[::24][grow]"));

    JComboBox comboBox = new JComboBox();
    comboBox.setToolTipText("Log Level");
    comboBox.setMaximumRowCount(6);//from ww w.  j  a v a2 s.com
    comboBox.setModel(
            new DefaultComboBoxModel(new String[] { "Fatal", "Error", "Warn", "Info", "Debug", "Trace" }));
    comboBox.setSelectedIndex(5);
    add(comboBox, "cell 1 0,growx");

    JButton btnC = new JButton("");
    btnC.setToolTipText("Clear Buffer");
    btnC.setIcon(new ImageIcon(ConsolePanel.class.getResource("/img/clear-document.png")));
    btnC.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent arg0) {
            logPangrams();
        }
    });
    add(btnC, "cell 2 0,wmax 24,hmax 26");

    tglbtnV = new JToggleButton("");
    tglbtnV.setToolTipText("Auto Scroll");
    tglbtnV.setIcon(new ImageIcon(ConsolePanel.class.getResource("/img/auto-scroll.png")));
    tglbtnV.setSelected(true);
    tglbtnV.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
                _table.setAutoScroll(true);
            } else if (ev.getStateChange() == ItemEvent.DESELECTED) {
                _table.setAutoScroll(false);
            }
        }
    });

    add(tglbtnV, "cell 3 0,wmax 24,hmax 26");

    scrollPane = new JScrollPane();
    scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            // TODO figure out what to do with this event?
        }
    });

    add(scrollPane, "cell 0 1 4 1,grow");

    _table = new JLogTable("Time", "Source", "Message");

    _table.getColumnModel().getColumn(0).setMinWidth(50);
    _table.getColumnModel().getColumn(0).setPreferredWidth(50);
    _table.getColumnModel().getColumn(0).setMaxWidth(100);

    _table.getColumnModel().getColumn(1).setMinWidth(50);
    _table.getColumnModel().getColumn(1).setPreferredWidth(50);
    _table.getColumnModel().getColumn(1).setMaxWidth(100);

    _table.getColumnModel().getColumn(2).setMinWidth(50);
    _table.getColumnModel().getColumn(2).setWidth(255);

    _table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

    scrollPane.setViewportView(_table);

    _appender = new JLogTableAppender();
    _appender.setThreshold(Level.ALL);
    Logger.getRootLogger().addAppender(_appender);
}

From source file:Main.java

/**
 * //from  ww  w.  j  a v  a 2  s.com
 * TODO
 * @param action
 * @return
 */
public static AbstractButton createToolbarItem(Action action) {
    final AbstractButton button;
    if (action == null) {
        throw new NullPointerException("Action cannot be null!");
    } else if (action.getValue(Action.SELECTED_KEY) != null) {
        button = new JToggleButton(action);
    } else {
        button = new JButton(action);
    }

    button.setOpaque(false);
    // hide text if icon is available
    if (action != null
            && (action.getValue(Action.SMALL_ICON) != null || action.getValue(Action.LARGE_ICON_KEY) != null)) {
        button.setHideActionText(true);
    }
    button.setHorizontalTextPosition(JButton.CENTER);
    button.setVerticalTextPosition(JButton.BOTTOM);
    return button;
}

From source file:ScribbleDragAndDrop.java

/**
 * The main method. Creates a simple application using this class. Note the
 * buttons for switching between draw mode and drag mode.
 *//* w ww .  j a va  2  s  . c  o m*/
public static void main(String[] args) {
    // Create a frame and put a scribble pane in it
    JFrame frame = new JFrame("ScribbleDragAndDrop");
    final ScribbleDragAndDrop scribblePane = new ScribbleDragAndDrop();
    frame.getContentPane().add(scribblePane, BorderLayout.CENTER);

    // Create two buttons for switching modes
    JToolBar toolbar = new JToolBar();
    ButtonGroup group = new ButtonGroup();
    JToggleButton draw = new JToggleButton("Draw");
    JToggleButton drag = new JToggleButton("Drag");
    draw.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scribblePane.setDragMode(false);
        }
    });
    drag.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scribblePane.setDragMode(true);
        }
    });
    group.add(draw);
    group.add(drag);
    toolbar.add(draw);
    toolbar.add(drag);
    frame.getContentPane().add(toolbar, BorderLayout.NORTH);

    // Start off in drawing mode
    draw.setSelected(true);
    scribblePane.setDragMode(false);

    // Pop up the window
    frame.setSize(400, 400);
    frame.setVisible(true);
}

From source file:be.nbb.demetra.dfm.DfmExecViewTopComponent.java

@Override
public JComponent getToolbarRepresentation() {
    JToolBar toolBar = NbComponents.newInnerToolbar();
    toolBar.addSeparator();//from  ww  w .  j  a  va 2s .  co m
    toolBar.add(Box.createRigidArea(new Dimension(5, 0)));

    JToggleButton startStop = (JToggleButton) toolBar
            .add(new JToggleButton(StartStopCommand.INSTANCE.toAction(this)));
    startStop.setIcon(DemetraUiIcon.COMPILE_16);
    startStop.setDisabledIcon(createDisabledIcon(startStop.getIcon()));
    startStop.setToolTipText("Start/Stop");

    JButton edit = toolBar.add(EditSpecCommand.INSTANCE.toAction(this));
    edit.setIcon(DemetraUiIcon.PREFERENCES);
    edit.setDisabledIcon(createDisabledIcon(edit.getIcon()));
    edit.setToolTipText("Specification");

    JButton clear = toolBar.add(ClearCommand.INSTANCE.toAction(this));
    clear.setIcon(DemetraUiIcon.EDIT_CLEAR_16);
    clear.setDisabledIcon(createDisabledIcon(clear.getIcon()));
    clear.setToolTipText("Clear");

    SwingColorSchemeSupport colorSchemeSupport = SwingColorSchemeSupport
            .from(DemetraUI.getInstance().getColorScheme());
    sparkline = (ChartPanel) toolBar
            .add(Charts.avoidScaling(new ChartPanel(Charts.createSparkLineChart(null))));
    sparkline.setPreferredSize(new Dimension(150, 16));
    sparkline.setMaximumSize(new Dimension(150, 16));
    sparkline.getChart().getXYPlot().setDataset(dataset);
    sparkline.getChart().getXYPlot().getRenderer()
            .setBasePaint(colorSchemeSupport.getLineColor(ColorScheme.KnownColor.GREEN));
    sparkline.setBackground(colorSchemeSupport.getPlotColor());
    sparkline.setBorder(BorderFactory.createLineBorder(colorSchemeSupport.getGridColor()));
    sparkline.setToolTipText("loglikelihood");

    return toolBar;
}

From source file:TreeLayoutDemo.java

public TreeLayoutDemo() {

    // create a simple graph for the demo
    graph = new DelegateForest<String, Integer>();

    createTree();//from  w  w  w  . ja  v a  2  s . c o m

    treeLayout = new TreeLayout<String, Integer>(graph);
    radialLayout = new RadialTreeLayout<String, Integer>(graph);
    radialLayout.setSize(new Dimension(600, 600));
    vv = new VisualizationViewer<String, Integer>(treeLayout, new Dimension(600, 600));
    vv.setBackground(Color.white);
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller());
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    rings = new Rings();

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);

    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    vv.setGraphMouse(graphMouse);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(graphMouse.getModeListener());
    graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JToggleButton radial = new JToggleButton("Radial");
    radial.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {

                LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, treeLayout,
                        radialLayout);
                Animator animator = new Animator(lt);
                animator.start();
                vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.addPreRenderPaintable(rings);
            } else {
                LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, radialLayout,
                        treeLayout);
                Animator animator = new Animator(lt);
                animator.start();
                vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.removePreRenderPaintable(rings);
            }
            vv.repaint();
        }
    });

    JPanel scaleGrid = new JPanel(new GridLayout(1, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));

    JPanel controls = new JPanel();
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(radial);
    controls.add(scaleGrid);
    controls.add(modeBox);

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

From source file:net.daboross.outputtablesclient.gui.OutputInterface.java

private void createTable(String tableKey) {
    String displayName = application.getOutput().getNameTable().get(tableKey);
    if (displayName == null) {
        Output.logError("Warning! No known display name for table %s", tableKey);
        displayName = tableKey;/*from www.ja v  a 2  s.  c om*/
    }
    JPanel tablePanel = new JPanel(new WrapLayout());
    Border lineBorder = new LineBorder(new Color(0, 0, 0));
    TitledBorder titleBorder = new TitledBorder(lineBorder, displayName);
    tableKeyToTableTitledBoarder.put(tableKey, titleBorder);
    Border spaceBorder = new EmptyBorder(5, 5, 5, 5);
    Border compoundBorder = new CompoundBorder(titleBorder, spaceBorder);
    tablePanel.setBorder(compoundBorder);
    tableKeyToTablePanel.put(tableKey, tablePanel);

    JToggleButton toggleButton = new JToggleButton(displayName);
    TableToggleListener listener = new TableToggleListener(toggleButton, tableKey);
    toggleButton.addItemListener(listener);
    listener.initialAdd();
    tableKeyToTableButton.put(tableKey, toggleButton);
    toggleButtonPanel.removeAll();
    for (JToggleButton button : tableKeyToTableButton.values()) {
        toggleButtonPanel.add(button, toggleButtonConstraints);
    }

    tableKeyAndKeyToValuePanel.put(tableKey, new HashMap<>());
    tableKeyAndKeyToValueLabel.put(tableKey, new HashMap<>());
}

From source file:edu.uci.ics.jung.samples.TreeLayoutDemo.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public TreeLayoutDemo() {

    // create a simple graph for the demo
    graph = new DelegateForest<String, Integer>();

    createTree();/*from w w w  .  ja va  2s  . c om*/

    treeLayout = new TreeLayout<String, Integer>(graph);
    radialLayout = new RadialTreeLayout<String, Integer>(graph);
    radialLayout.setSize(new Dimension(600, 600));
    vv = new VisualizationViewer<String, Integer>(treeLayout, new Dimension(600, 600));
    vv.setBackground(Color.white);
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller());
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    rings = new Rings();

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);

    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    vv.setGraphMouse(graphMouse);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(graphMouse.getModeListener());
    graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JToggleButton radial = new JToggleButton("Radial");
    radial.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {

                LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, treeLayout,
                        radialLayout);
                Animator animator = new Animator(lt);
                animator.start();
                vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.addPreRenderPaintable(rings);
            } else {
                LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, radialLayout,
                        treeLayout);
                Animator animator = new Animator(lt);
                animator.start();
                vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.removePreRenderPaintable(rings);
            }
            vv.repaint();
        }
    });

    JPanel scaleGrid = new JPanel(new GridLayout(1, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));

    JPanel controls = new JPanel();
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(radial);
    controls.add(scaleGrid);
    controls.add(modeBox);

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

From source file:WSRTreeVisualizer.java

public WSRTreeVisualizer() {

    // create a simple graph for the demo
    graph = new DelegateForest<String, Integer>();

    createTree();/*  w  ww .  ja v  a  2s .  c o m*/

    treeLayout = new TreeLayout<String, Integer>(graph);
    radialLayout = new RadialTreeLayout<String, Integer>(graph);
    radialLayout.setSize(new Dimension(600, 600));
    vv = new VisualizationViewer<String, Integer>(treeLayout, new Dimension(600, 600));
    vv.setBackground(Color.white);
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller());
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    rings = new Rings();

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);

    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    vv.setGraphMouse(graphMouse);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(graphMouse.getModeListener());
    graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JToggleButton radial = new JToggleButton("Radial");
    radial.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {

                LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, treeLayout,
                        radialLayout);
                Animator animator = new Animator(lt);
                animator.start();
                vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.addPreRenderPaintable(rings);
            } else {
                LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, radialLayout,
                        treeLayout);
                Animator animator = new Animator(lt);
                animator.start();
                vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.removePreRenderPaintable(rings);
            }
            vv.repaint();
        }
    });

    JPanel scaleGrid = new JPanel(new GridLayout(1, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));

    JPanel controls = new JPanel();
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(radial);
    controls.add(scaleGrid);
    controls.add(modeBox);

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

From source file:bigdata.explorer.nutch.grapview.tests.WebGraphTreeLayout.java

public WebGraphTreeLayout() throws IOException {

    // create a simple graph for the demo
    graph = new DelegateForest<String, Number>();

    createTree();//from   ww  w.  jav  a 2 s. com

    treeLayout = new TreeLayout<String, Number>(graph);
    radialLayout = new RadialTreeLayout<String, Number>(graph);
    radialLayout.setSize(new Dimension(600, 600));
    vv = new VisualizationViewer<String, Number>(treeLayout, new Dimension(600, 600));
    vv.setBackground(Color.white);
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller());
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    rings = new Rings();

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);

    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    vv.setGraphMouse(graphMouse);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(graphMouse.getModeListener());
    graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JToggleButton radial = new JToggleButton("Radial");
    radial.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {

                LayoutTransition<String, Number> lt = new LayoutTransition<String, Number>(vv, treeLayout,
                        radialLayout);
                Animator animator = new Animator(lt);
                animator.start();
                vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.addPreRenderPaintable(rings);
            } else {
                LayoutTransition<String, Number> lt = new LayoutTransition<String, Number>(vv, radialLayout,
                        treeLayout);
                Animator animator = new Animator(lt);
                animator.start();
                vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.removePreRenderPaintable(rings);
            }
            vv.repaint();
        }
    });

    JPanel scaleGrid = new JPanel(new GridLayout(1, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));

    JPanel controls = new JPanel();
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(radial);
    controls.add(scaleGrid);
    controls.add(modeBox);

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