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

The following examples show how to use javax.swing.JToggleButton#setMargin() . 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: 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 2
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addEntityFinderButton(JToolBar buttonBar, Insets margin) {
	find = new JToggleButton(new ImageIcon(GUIFrame.class.getResource("/resources/images/Find-16.png")));
	find.setToolTipText(formatToolTip("Entity Finder (Ctrl+F)",
			"Searches for an entity with a given name."));
	find.setMargin(margin);
	find.setFocusPainted(false);
	find.setRequestFocusEnabled(false);
	find.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed( ActionEvent event ) {
			if (find.isSelected()) {
				FindBox.getInstance().showDialog();
			}
			else {
				FindBox.getInstance().setVisible(false);
			}
			controlStartResume.requestFocusInWindow();
		}
	});
	buttonBar.add( find );
}
 
Example 3
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addReverseButton(JToolBar buttonBar, Insets margin) {
	reverseButton = new JToggleButton(new ImageIcon(GUIFrame.class.getResource("/resources/images/Reverse-16.png")));
	reverseButton.setToolTipText(formatToolTip("Reverse Direction",
			"When enabled, the link arrows are shown for entities travelling in the reverse "
			+ "direction, and the Next and Previous buttons select the next/previous links "
			+ "for that direction."));
	reverseButton.setMargin(margin);
	reverseButton.setFocusPainted(false);
	reverseButton.setRequestFocusEnabled(false);
	reverseButton.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed( ActionEvent event ) {
			if (createLinks.isSelected())
				createLinks.doClick();
			boolean bool = (((JToggleButton)event.getSource()).isSelected());
			if (RenderManager.isGood()) {
				RenderManager.inst().setLinkDirection(!bool);
				RenderManager.redraw();
			}
			updateUI();
		}
	});
	// Reverse button is not needed in the open source JaamSim
	//buttonBar.add( reverseButton );
}
 
Example 4
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 5
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addShowSubModelsButton(JToolBar buttonBar, Insets margin) {
	showSubModels = new JToggleButton( new ImageIcon(
			GUIFrame.class.getResource("/resources/images/ShowSubModels-16.png")) );
	showSubModels.setMargin(margin);
	showSubModels.setFocusPainted(false);
	showSubModels.setRequestFocusEnabled(false);
	showSubModels.setToolTipText(formatToolTip("Show SubModels",
			"Displays the components of each sub-model."));
	showSubModels.addActionListener( new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			boolean bool = showSubModels.isSelected();
			KeywordIndex kw = InputAgent.formatBoolean("ShowSubModels", bool);
			InputAgent.storeAndExecute(new KeywordCommand(sim.getSimulation(), kw));
			setShowSubModels(bool);
			controlStartResume.requestFocusInWindow();
		}
	} );
	buttonBar.add( showSubModels );
}
 
Example 6
Source File: ControlsFrame.java    From training with MIT License 6 votes vote down vote up
private JToggleButton makeToggle(String ideLabel, boolean initial, Consumer<Boolean> action) {
	JToggleButton button = new JToggleButton(createImageIcon("/"+ideLabel+"18.png", ideLabel));
	button.setSelected(initial);
	button.addChangeListener(new ChangeListener() {
		boolean oldState = initial;
		public void stateChanged(ChangeEvent e) {
			if (button.isSelected() != oldState) {
				action.accept(button.isSelected());
				oldState = !oldState;
			}
		}
	}
	); 
	button.setMargin(new Insets(0, 0, 0, 0));
	return button;
}
 
Example 7
Source File: DrawingViewPlacardPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a button to toggle the grid in the drawing.
 *
 * @param view The DrawingView the button will belong to.
 * @return The created button.
 */
private JToggleButton toggleConstrainerButton(final OpenTCSDrawingView drawingView) {
  final JToggleButton toggleButton = new JToggleButton();

  toggleButton.setToolTipText(
      labels.getString("drawingViewPlacardPanel.button_toggleGrid.tooltipText")
  );

  toggleButton.setIcon(ImageDirectory.getImageIcon("/menu/view-split.png"));

  toggleButton.setMargin(new Insets(0, 0, 0, 0));
  toggleButton.setFocusable(false);

  toggleButton.addItemListener(
      (ItemEvent event) -> drawingView.setConstrainerVisible(toggleButton.isSelected())
  );

  return toggleButton;
}
 
Example 8
Source File: JTSTestBuilderToolBar.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
private JToggleButton createToggleButton(String toolTipText, 
    ImageIcon icon, 
    java.awt.event.ActionListener actionListener)
{
  JToggleButton btn = new JToggleButton();
  btn.setMargin(new Insets(0, 0, 0, 0));
  btn.setPreferredSize(new Dimension(30, 30));
  btn.setIcon(icon);
  btn.setMinimumSize(new Dimension(30, 30));
  btn.setVerticalTextPosition(SwingConstants.BOTTOM);
  btn.setSelected(false);
  btn.setToolTipText(toolTipText);
  btn.setHorizontalTextPosition(SwingConstants.CENTER);
  btn.setFont(new java.awt.Font("SansSerif", 0, 10));
  btn.setMaximumSize(new Dimension(30, 30));
  btn.addActionListener(actionListener);
  return btn;
}
 
Example 9
Source File: VariablesViewButtons.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static JToggleButton createToggleButton (final String id, String iconName, String tooltip) {
    Icon icon = loadIcon(iconName);
    boolean isSelected = isButtonSelected(id);
    final JToggleButton toggleButton = new JToggleButton(icon, isSelected);
    // ensure small size, just for the icon
    Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
    toggleButton.setPreferredSize(size);
    toggleButton.setMargin(new Insets(1, 1, 1, 1));
    if (!"Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N
        // We do not want an ugly border with the exception of Mac, where it paints the toggle state!
        toggleButton.setBorder(new EmptyBorder(toggleButton.getBorder().getBorderInsets(toggleButton)));
    }
    toggleButton.setToolTipText(tooltip);
    toggleButton.setFocusable(false);
    return toggleButton;
}
 
Example 10
Source File: VariablesViewButtons.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static JToggleButton createToggleButton (final String id, String iconName, String tooltip) {
    Icon icon = loadIcon(iconName);
    boolean isSelected = isButtonSelected(id);
    final JToggleButton toggleButton = new JToggleButton(icon, isSelected);
    // ensure small size, just for the icon
    Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
    toggleButton.setPreferredSize(size);
    toggleButton.setMargin(new Insets(1, 1, 1, 1));
    if (!"Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N
        // We do not want an ugly border with the exception of Mac, where it paints the toggle state!
        toggleButton.setBorder(new EmptyBorder(toggleButton.getBorder().getBorderInsets(toggleButton)));
    }
    toggleButton.setToolTipText(tooltip);
    toggleButton.setFocusable(false);
    return toggleButton;
}
 
Example 11
Source File: VariablesViewButtons.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static JToggleButton createToggleButton (final String id, String iconPath, String tooltip) {
    Icon icon = ImageUtilities.loadImageIcon(iconPath, false);
    boolean isSelected = isButtonSelected(id);
    final JToggleButton toggleButton = new JToggleButton(icon, isSelected);
    // ensure small size, just for the icon
    Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
    toggleButton.setPreferredSize(size);
    toggleButton.setMargin(new Insets(1, 1, 1, 1));
    if (!"Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N
        // We do not want an ugly border with the exception of Mac, where it paints the toggle state!
        toggleButton.setBorder(new EmptyBorder(toggleButton.getBorder().getBorderInsets(toggleButton)));
    }
    toggleButton.setToolTipText(tooltip);
    toggleButton.setFocusable(false);
    return toggleButton;
}
 
Example 12
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 13
Source File: DrawingViewPlacardPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a button to toglle the labels.
 *
 * @param view The DrawingView the button will belong to.
 * @return The created button.
 */
private JToggleButton toggleLabelsButton(final OpenTCSDrawingView drawingView) {
  final JToggleButton toggleButton = new JToggleButton();

  toggleButton.setToolTipText(
      labels.getString("drawingViewPlacardPanel.button_toggleLabels.tooltipText")
  );

  toggleButton.setIcon(ImageDirectory.getImageIcon("/menu/comment-add.16.png"));

  toggleButton.setMargin(new Insets(0, 0, 0, 0));
  toggleButton.setFocusable(false);

  toggleButton.addItemListener(
      (ItemEvent event) -> drawingView.setLabelsVisible(toggleButton.isSelected())
  );

  return toggleButton;
}
 
Example 14
Source File: FiltersManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JToggleButton createToggle (Map<String,Boolean> fStates, int index) {
    boolean isSelected = filtersDesc.isSelected(index);
    Icon icon = filtersDesc.getSelectedIcon(index);
    // ensure small size, just for the icon
    JToggleButton result = new JToggleButton(icon, isSelected);
    Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 4);
    result.setPreferredSize(size);
    result.setMargin(new Insets(2,3,2,3));
    result.setToolTipText(filtersDesc.getTooltip(index));
    
    fStates.put(filtersDesc.getName(index), Boolean.valueOf(isSelected));
    
    return result;
}
 
Example 15
Source File: FiltersManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JToggleButton createToggle (Map<String,Boolean> fStates, int index) {
    boolean isSelected = getPreferences().getBoolean( filtersDesc.getName(index), filtersDesc.isSelected(index) );
    Icon icon = filtersDesc.getSelectedIcon(index);
    // ensure small size, just for the icon
    JToggleButton result = new JToggleButton(icon, isSelected);
    Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 4);
    result.setPreferredSize(size);
    result.setMargin(new Insets(2,3,2,3));
    result.setToolTipText(filtersDesc.getTooltip(index));
    result.setFocusable(false);
    
    fStates.put(filtersDesc.getName(index), Boolean.valueOf(isSelected));
    
    return result;
}
 
Example 16
Source File: FiltersManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JToggleButton createToggle (Map fStates, int index) {
    boolean isSelected = filtersDesc.isSelected(index);
    Icon icon = filtersDesc.getSelectedIcon(index);
    // ensure small size, just for the icon
    JToggleButton result = new JToggleButton(icon, isSelected);
    Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 4);
    result.setPreferredSize(size);
    result.setMargin(new Insets(2,3,2,3));
    result.setToolTipText(filtersDesc.getTooltip(index));
    
    fStates.put(filtersDesc.getName(index), Boolean.valueOf(isSelected));
    
    return result;
}
 
Example 17
Source File: JChoice.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * (Re)constructs the UI. This can be called many times, whenever a 
 * significant value (such as {@link #maximumFastChoices}, or the model)
 * has changed.
 */
private void buildGui(){
  removeAll();
  if(model != null && model.getSize() > 0){
    if(model.getSize() > maximumFastChoices){
      //use combobox
      add(combo);
    }else{
      //use buttons
      //first clear the old buttons, if any exist
      if(buttonToValueMap.size() > 0){
        for(AbstractButton aBtn : buttonToValueMap.keySet()){
          aBtn.removeItemListener(sharedItemListener);
        }
      }
      //now create the new buttons
      buttonToValueMap.clear();
      for(int i = 0; i < model.getSize(); i++){
        Object aValue = model.getElementAt(i);
        JToggleButton aButton = new JToggleButton(aValue.toString());
        if(defaultButtonMargin != null) aButton.setMargin(defaultButtonMargin);
        aButton.addItemListener(sharedItemListener);
        buttonToValueMap.put(aButton, aValue);
        add(aButton);
      }
    }
  }
  revalidate();
}
 
Example 18
Source File: ToolBar.java    From Dayon with GNU General Public License v3.0 5 votes vote down vote up
public void addToggleAction(Action action) {
	final JToggleButton button = new JToggleButton();

	button.setMargin(zeroInsets);
	button.setHideActionText(true);
	button.setAction(action);

	if (action.getValue(Action.SMALL_ICON) == null) {
		button.setText((String) action.getValue("DISPLAY_NAME"));
	}

	button.setFocusable(false);

	add(button);
}
 
Example 19
Source File: LexerFrame.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void scanScript(final StringReader reader) throws Exception {
    scriptPane.read(reader, null);
    reader.reset();

    // create lexer
    final GroovyLangLexer lexer = new GroovyLangLexer(reader);

    tokenPane.setEditable(true);
    tokenPane.setText("");

    int line = 1;
    final ButtonGroup bg = new ButtonGroup();
    Token token;

    while (true) {
        token = lexer.nextToken();
        JToggleButton tokenButton = new JToggleButton(tokens.get(token.getType()));
        bg.add(tokenButton);
        tokenButton.addActionListener(this);
        tokenButton.setToolTipText(token.getText());
        tokenButton.putClientProperty("token", token);
        tokenButton.setMargin(new Insets(0, 1, 0, 1));
        tokenButton.setFocusPainted(false);
        if (token.getLine() > line) {
            tokenPane.getDocument().insertString(tokenPane.getDocument().getLength(), "\n", null);
            line = token.getLine();
        }
        insertComponent(tokenButton);
        if (eof().equals(token.getType())) {
            break;
        }
    }

    tokenPane.setEditable(false);
    tokenPane.setCaretPosition(0);
    reader.close();
}
 
Example 20
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void addCreateLinksButton(JToolBar buttonBar, Insets margin) {
	createLinks = new JToggleButton(new ImageIcon(GUIFrame.class.getResource("/resources/images/MakeLinks-16.png")));
	createLinks.setToolTipText(formatToolTip("Create Entity Links",
			"When this is enabled, entities are linked when selection is changed."));
	createLinks.setMargin(margin);
	createLinks.setFocusPainted(false);
	createLinks.setRequestFocusEnabled(false);
	createLinks.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed( ActionEvent event ) {

			boolean bCreate = (((JToggleButton)event.getSource()).isSelected());
			if (RenderManager.isGood()) {
				if (bCreate) {
					FrameBox.setSelectedEntity(null, false);
					showLinks.setSelected(true);
					RenderManager.inst().setShowLinks(true);
				}
				RenderManager.inst().setCreateLinks(bCreate);
				RenderManager.redraw();
			}
			controlStartResume.requestFocusInWindow();
		}

	});
	buttonBar.add( createLinks );
}