Java Code Examples for javax.swing.JToggleButton#addActionListener()

The following examples show how to use javax.swing.JToggleButton#addActionListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAccessSelectorPanel.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
private WebButtonPopup generatePopupMenu() {
  WebButtonPopup pm = new WebButtonPopup(this, PopupWay.downCenter);
  JPanel list = new JPanel(new GridLayout(7, 1));
  for (Entry<String, Integer> acc : otherTypes.entrySet()) {
    JToggleButton jtb = new JToggleButton(
        acc.getKey().substring(0, 1).toUpperCase() + acc.getKey().substring(1, Math.min(acc.getKey().length(), 7)));
    jtb.setSelected((visibility & acc.getValue()) != 0);
    jtb.addActionListener(e -> {
      if ((visibility & acc.getValue()) != 0) {
        visibility -= acc.getValue();
      } else {
        visibility |= acc.getValue();
      }
    });
    jtb.setFont(new Font(jtb.getFont().getName(), Font.PLAIN, 10));
    list.add(jtb);
  }
  pm.setContent(list);
  return pm;
}
 
Example 2
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addRealTimeButton(JToolBar mainToolBar, Insets margin) {
	controlRealTime = new JToggleButton( " Real Time " );
	controlRealTime.setToolTipText(formatToolTip("Real Time Mode",
			"When selected, the simulation runs at a fixed multiple of wall clock time."));
	controlRealTime.setMargin(margin);
	controlRealTime.setFocusPainted(false);
	controlRealTime.setRequestFocusEnabled(false);
	controlRealTime.addActionListener(new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			boolean bool = ((JToggleButton)event.getSource()).isSelected();
			KeywordIndex kw = InputAgent.formatBoolean("RealTime", bool);
			InputAgent.storeAndExecute(new KeywordCommand(sim.getSimulation(), kw));
			controlStartResume.requestFocusInWindow();
		}
	});
	mainToolBar.add( controlRealTime );
}
 
Example 3
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addShowAxesButton(JToolBar buttonBar, Insets margin) {
	xyzAxis = new JToggleButton( new ImageIcon(
			GUIFrame.class.getResource("/resources/images/Axes-16.png")) );
	xyzAxis.setMargin(margin);
	xyzAxis.setFocusPainted(false);
	xyzAxis.setRequestFocusEnabled(false);
	xyzAxis.setToolTipText(formatToolTip("Show Axes",
			"Shows the unit vectors for the x, y, and z axes."));
	xyzAxis.addActionListener( new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			DisplayEntity ent = (DisplayEntity) sim.getNamedEntity("XYZ-Axis");
			if (ent != null) {
				KeywordIndex kw = InputAgent.formatBoolean("Show", xyzAxis.isSelected());
				InputAgent.storeAndExecute(new KeywordCommand(ent, kw));
			}
			controlStartResume.requestFocusInWindow();
		}
	} );
	buttonBar.add( xyzAxis );
}
 
Example 4
Source File: HorizontalList.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void refresh() {
    if(blockRefeshWhileLoading) {
        return;
    }
    for(java.awt.Component cmp : getComponents()) {
        remove(cmp);
        group.remove((JToggleButton)cmp);
    }
    String[] entries = getEntries();
    Arrays.sort(entries, String.CASE_INSENSITIVE_ORDER);
    initLayout(entries.length);
    for(String current : entries) {
        JToggleButton button = createButton(current);
        add(button);
        String selection = view.getSelectedResource();
        if(selection != null && selection.equals(current)) {
            button.setSelected(true);
        }
        button.addActionListener(listener);
        group.add(button);
    }
    revalidate();
    repaint();
}
 
Example 5
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addShowLinksButton(JToolBar buttonBar, Insets margin) {
	showLinks = new JToggleButton(new ImageIcon(GUIFrame.class.getResource("/resources/images/ShowLinks-16.png")));
	showLinks.setToolTipText(formatToolTip("Show Entity Flow",
			"When selected, arrows are shown between objects to indicate the flow of entities."));
	showLinks.setMargin(margin);
	showLinks.setFocusPainted(false);
	showLinks.setRequestFocusEnabled(false);
	showLinks.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed( ActionEvent event ) {
			boolean bShow = (((JToggleButton)event.getSource()).isSelected());
			if (RenderManager.isGood()) {
				RenderManager.inst().setShowLinks(bShow);
				RenderManager.redraw();
			}
			controlStartResume.requestFocusInWindow();
		}

	});
	buttonBar.add( showLinks );
}
 
Example 6
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void add2dButton(JToolBar buttonBar, Insets margin) {
	lockViewXYPlane = new JToggleButton( "2D" );
	lockViewXYPlane.setMargin(margin);
	lockViewXYPlane.setFocusPainted(false);
	lockViewXYPlane.setRequestFocusEnabled(false);
	lockViewXYPlane.setToolTipText(formatToolTip("2D View",
			"Sets the camera position to show a bird's eye view of the 3D scene."));
	lockViewXYPlane.addActionListener( new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			boolean bLock2D = (((JToggleButton)event.getSource()).isSelected());

			if (RenderManager.isGood()) {
				View currentView = RenderManager.inst().getActiveView();
				if (currentView != null) {
					currentView.setLock2D(bLock2D);
				}
			}
			controlStartResume.requestFocusInWindow();
		}
	} );
	buttonBar.add( lockViewXYPlane );
}
 
Example 7
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addShowLabelsButton(JToolBar buttonBar, Insets margin) {
	showLabels = new JToggleButton( new ImageIcon(
			GUIFrame.class.getResource("/resources/images/ShowLabels-16.png")) );
	showLabels.setMargin(margin);
	showLabels.setFocusPainted(false);
	showLabels.setRequestFocusEnabled(false);
	showLabels.setToolTipText(formatToolTip("Show Labels",
			"Displays the label for every entity in the model."));
	showLabels.addActionListener( new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			boolean bool = showLabels.isSelected();
			KeywordIndex kw = InputAgent.formatBoolean("ShowLabels", bool);
			InputAgent.storeAndExecute(new KeywordCommand(sim.getSimulation(), kw));
			setShowLabels(bool);
			controlStartResume.requestFocusInWindow();
		}
	} );
	buttonBar.add( showLabels );
}
 
Example 8
Source File: ReportEditorView.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
protected JToggleButton createOpenViewButton(ButtonGroup group,
                                             final SubView view) {
    JToggleButton button = new JToggleButton(view.getTitle());
    group.add(button);
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            actionsRemoved(activeView.getActions());
            beforeSubviewActivated(view);
            content.removeAll();
            content.add(view, BorderLayout.CENTER);
            content.revalidate();
            content.repaint();
            activeView = view;
            actionsAdded(view.getActions());
        }
    });

    return button;
}
 
Example 9
Source File: BreakpointsViewButtons.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({"CTL_DeactivateAllBreakpoints=Deactivate all breakpoints in current session",
                    "CTL_ActivateAllBreakpoints=Activate all breakpoints in current session",
                    "CTL_NoDeactivation=The current session does not allow to deactivate breakpoints",
                    "CTL_NoSession=No debugger session"})
public static AbstractButton createActivateBreakpointsActionButton() {
    ImageIcon icon = ImageUtilities.loadImageIcon(DEACTIVATED_LINE_BREAKPOINT, false);
    final JToggleButton button = new JToggleButton(icon);
    // ensure small size, just for the icon
    Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
    button.setPreferredSize(size);
    button.setMargin(new Insets(1, 1, 1, 1));
    button.setBorder(new EmptyBorder(button.getBorder().getBorderInsets(button)));
    button.setToolTipText(Bundle.CTL_DeactivateAllBreakpoints());
    button.setFocusable(false);
    final BreakpointsActivator ba = new BreakpointsActivator(button);
    button.addActionListener(ba);
    DebuggerManager.getDebuggerManager().addDebuggerListener(DebuggerManager.PROP_CURRENT_ENGINE, new DebuggerManagerAdapter() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            DebuggerEngine de = (DebuggerEngine) evt.getNewValue();
            ba.setCurrentEngine(de);
        }
    });
    ba.setCurrentEngine(DebuggerManager.getDebuggerManager().getCurrentEngine());
    return button;
}
 
Example 10
Source File: VariablesViewButtons.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static JToggleButton createShowWatchesButton() {
    JToggleButton button = createToggleButton(
            SHOW_WATCHES,
            "org/netbeans/modules/debugger/resources/localsView/show_watches_16.png",
            NbBundle.getMessage (VariablesViewButtons.class, "Hint_Show_Watches")
        );
    button.addActionListener(new ShowWatchesActionListener(button));
    return button;
}
 
Example 11
Source File: BoardEditor.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets up JToggleButtons
 */
private JToggleButton addTerrainTButton(String iconName, String buttonName, ArrayList<JToggleButton> bList) {
    JToggleButton button = new JToggleButton(buttonName);
    button.addActionListener(this);
    
    // Get the normal icon
    File file = new MegaMekFile(Configuration.widgetsDir(), "/MapEditor/"+iconName+".png").getFile(); //$NON-NLS-1$ //$NON-NLS-2$
    Image imageButton = ImageUtil.loadImageFromFile(file.getAbsolutePath());
    if (imageButton != null) {
        button.setIcon(new ImageIcon(imageButton));
        // When there is an icon, then the text can be removed
        button.setText("");
    }
    
    // Get the hover icon
    file = new MegaMekFile(Configuration.widgetsDir(), "/MapEditor/"+iconName+"_H.png").getFile(); //$NON-NLS-1$ //$NON-NLS-2$
    imageButton = ImageUtil.loadImageFromFile(file.getAbsolutePath());
    if (imageButton != null)
        button.setRolloverIcon(new ImageIcon(imageButton));
    
    // Get the selected icon
    file = new MegaMekFile(Configuration.widgetsDir(), "/MapEditor/"+iconName+"_S.png").getFile(); //$NON-NLS-1$ //$NON-NLS-2$
    imageButton = ImageUtil.loadImageFromFile(file.getAbsolutePath());
    if (imageButton != null)
        button.setSelectedIcon(new ImageIcon(imageButton));
    
    button.setToolTipText(Messages.getString("BoardEditor."+iconName+"TT")); //$NON-NLS-1$ //$NON-NLS-2$
    if (bList != null) bList.add(button);
    return button;
}
 
Example 12
Source File: ToggleButtonGroup.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new button group from the given Actions (requires at least two actions).
 *
 * @param preferredSize
 *            the preferredSize of the nested {@link CompositeToggleButton}s or {@code null}
 * @param actions
 *            the action
 */
public ToggleButtonGroup(Dimension preferredSize, Action... actions) {
	if (actions.length < 2) {
		throw new IllegalArgumentException("At least two primary actions must be specified.");
	}

	this.setOpaque(false);
	this.preferredSize = preferredSize;

	primaryButtons = new CompositeToggleButton[actions.length];
	for (int i = 0; i < actions.length; i++) {
		int position;
		if (i == 0) {
			position = SwingConstants.LEFT;
		} else if (i < actions.length - 1) {
			position = SwingConstants.CENTER;
		} else {
			position = SwingConstants.RIGHT;
		}
		primaryButtons[i] = new CompositeToggleButton(actions[i], position);
	}

	// align buttons left to right with no padding
	GridBagLayout layout = new GridBagLayout();
	setLayout(layout);

	GridBagConstraints gbc = new GridBagConstraints();
	gbc.insets = new Insets(0, 0, 0, 0);
	gbc.fill = GridBagConstraints.VERTICAL;
	gbc.weighty = 1;

	for (JToggleButton button : primaryButtons) {
		button.addActionListener(buttonChooser);
		if (preferredSize != null) {
			button.setMinimumSize(preferredSize);
			button.setPreferredSize(preferredSize);
		}
		add(button, gbc);
	}
}
 
Example 13
Source File: OptJTextAreaBinding.java    From jmkvpropedit with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public OptJTextAreaBinding(String property, String stateProperty, 
		JToggleButton button, JTextArea textArea) {
	if (property == null || button == null || textArea == null) {
		throw new NullPointerException();
	}
	if (property.equals("")) {
		throw new IllegalArgumentException();
	}
	_property = property;
	_stateProperty = stateProperty;
	_button = button;
	_textArea = textArea;
	_validColor = _textArea.getBackground();
	button.addActionListener(this);
}
 
Example 14
Source File: VariablesViewButtons.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static JToggleButton createShowResultButton() {
    JToggleButton button = createToggleButton(
            SHOW_EVALUTOR_RESULT,
            "org/netbeans/modules/debugger/resources/localsView/show_evaluator_result_16.png",
            NbBundle.getMessage (VariablesViewButtons.class, "Hint_Show_Result")
        );
    button.addActionListener(new ShowResultActionListener(button));
    return button;
}
 
Example 15
Source File: Toolbar.java    From android-classyshark with Apache License 2.0 5 votes vote down vote up
private JToggleButton buildLeftPanelToggleButton() {
    final ImageIcon toggleIcon = theme.getToggleIcon();
    final JToggleButton jToggleButton = new JToggleButton(toggleIcon, true);
    jToggleButton.setToolTipText("Show/hide navigation tree");
    jToggleButton.setBorderPainted(false);
    jToggleButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            toolbarController.onChangeLeftPaneVisibility(jToggleButton.isSelected());
        }
    });
    return jToggleButton;
}
 
Example 16
Source File: TabSelector.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
public void addTab(MagicPlayerZone zone, int player) {
    final JToggleButton button = new JToggleButton();
    button.setToolTipText(null);
    button.setBackground(this.backgroundColor);
    button.setFocusable(false);
    button.setPreferredSize(buttonDimension);
    button.setActionCommand(zone.name() + DELIM + player + DELIM + buttons.size());
    button.addActionListener(this);
    buttons.add(button);
    buttonPanel.add(button);

    if (buttons.size() == 1) {
        showTab(button);
    }
}
 
Example 17
Source File: MediaContentEditor.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
private void post_init() {
  textFields = new JTextField[] { fileTxt, externalTxt, fromTxt, toTxt, xTxt, yTxt };
  for (int i = 0; i < textFields.length; i++)
    textFields[i].getDocument().addDocumentListener(this);

  Enumeration en = mediaTypes.getElements();
  while (en.hasMoreElements()) {
    JToggleButton rb = (JToggleButton) en.nextElement();
    rb.addActionListener(this);
  }
}
 
Example 18
Source File: VariablesViewButtons.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static JToggleButton createShowWatchesButton() {
    JToggleButton button = createToggleButton(
            SHOW_WATCHES,
            "org/netbeans/modules/debugger/resources/localsView/show_watches_16.png",
            NbBundle.getMessage (VariablesViewButtons.class, "Hint_Show_Watches")
        );
    button.addActionListener(new ShowWatchesActionListener(button));
    return button;
}
 
Example 19
Source File: OptJTextAreaBinding.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
public OptJTextAreaBinding(String property, String stateProperty, 
		JToggleButton button, JTextArea textArea) {
	if (property == null || button == null || textArea == null) {
		throw new NullPointerException();
	}
	if (property.equals("")) {
		throw new IllegalArgumentException();
	}
	_property = property;
	_stateProperty = stateProperty;
	_button = button;
	_textArea = textArea;
	_validColor = _textArea.getBackground();
	button.addActionListener(this);
}
 
Example 20
Source File: JAccessSelectorPanel.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
private WebButtonPopup generatePopupMenu() {
  WebButtonPopup pm = new WebButtonPopup(this, PopupWay.downCenter);
  JToggleButton abs = new JToggleButton(TreeCellRenderer.abs);
  abs.setToolTipText("abstract");
  abs.setSelected(AccessHelper.isAbstract(visibility));
  JToggleButton fin = new JToggleButton(TreeCellRenderer.fin);
  fin.setToolTipText("final");
  fin.setSelected(AccessHelper.isFinal(visibility));
  JToggleButton nat = new JToggleButton(TreeCellRenderer.nat);
  nat.setToolTipText("native");
  nat.setSelected(AccessHelper.isNative(visibility));
  JToggleButton stat = new JToggleButton(TreeCellRenderer.stat);
  stat.setToolTipText("static");
  stat.setSelected(AccessHelper.isStatic(visibility));
  JToggleButton syn = new JToggleButton(TreeCellRenderer.syn);
  syn.setToolTipText("synthetic");
  syn.setSelected(AccessHelper.isSynthetic(visibility));
  abs.addActionListener(e -> {
    if (AccessHelper.isAbstract(visibility)) {
      visibility -= ACC_ABSTRACT;
    } else {
      visibility |= ACC_ABSTRACT;
      if (fin.isSelected())
        fin.doClick();
      if (nat.isSelected())
        nat.doClick();
      if (stat.isSelected())
        stat.doClick();
      if (syn.isSelected())
        syn.doClick();
    }
    updateVisibility(visibility);
  });
  fin.addActionListener(e -> {
    if (AccessHelper.isFinal(visibility)) {
      visibility -= ACC_FINAL;
    } else {
      visibility |= ACC_FINAL;
      if (nat.isSelected())
        nat.doClick();
      if (abs.isSelected())
        abs.doClick();
    }
    updateVisibility(visibility);
  });
  nat.addActionListener(e -> {
    if (AccessHelper.isNative(visibility)) {
      visibility -= ACC_NATIVE;
    } else {
      visibility |= ACC_NATIVE;
      if (fin.isSelected())
        fin.doClick();
      if (abs.isSelected())
        abs.doClick();
    }
    updateVisibility(visibility);
  });
  stat.addActionListener(e -> {
    if (AccessHelper.isStatic(visibility)) {
      visibility -= ACC_STATIC;
    } else {
      visibility |= ACC_STATIC;
      if (abs.isSelected())
        abs.doClick();
    }
    updateVisibility(visibility);
  });
  syn.addActionListener(e -> {
    if (AccessHelper.isSynthetic(visibility)) {
      visibility -= ACC_SYNTHETIC;
    } else {
      visibility |= ACC_SYNTHETIC;
      if (abs.isSelected())
        abs.doClick();
    }
    updateVisibility(visibility);
  });
  JPanel list = new JPanel(new GridLayout(4, 1));
  list.add(fin);
  list.add(nat);
  list.add(stat);
  list.add(syn);
  list.add(abs);
  pm.setContent(list);
  return pm;
}