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

The following examples show how to use javax.swing.JToggleButton#setFocusPainted() . 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: IconPanel.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nonnull
private JToggleButton makeIconButton(@Nonnull final ButtonGroup group, @Nonnull final String name) {
  final JToggleButton result = Utils.UI_COMPO_FACTORY.makeToggleButton();

  final Color panelColor = this.getBackground();

  result.setUI(new MetalToggleButtonUI() {
    @Override
    @Nullable
    protected Color getSelectColor() {
      return panelColor.brighter();
    }
  });

  result.setBackground(panelColor.darker());

  result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(3, 3, 3, 3)));
  result.setIcon(new ImageIcon(MiscIcons.findForName(name)));
  result.setName(name);
  result.setFocusPainted(false);
  result.setToolTipText(name);

  group.add(result);
  return result;
}
 
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 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 4
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 5
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addFillButton(JToolBar buttonBar, Insets margin) {
	fill = new JToggleButton(new ImageIcon(
			GUIFrame.class.getResource("/resources/images/Fill-16.png")));
	fill.setMargin(margin);
	fill.setFocusPainted(false);
	fill.setRequestFocusEnabled(false);
	fill.setToolTipText(formatToolTip("Show Fill",
			"Fills the entity with the selected colour."));
	fill.addActionListener( new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			if (!(selectedEntity instanceof FillEntity))
				return;
			FillEntity fillEnt = (FillEntity) selectedEntity;
			fillColour.setEnabled(fill.isSelected());
			if (fillEnt.isFilled() == fill.isSelected())
				return;
			KeywordIndex kw = InputAgent.formatBoolean("Filled", fill.isSelected());
			InputAgent.storeAndExecute(new KeywordCommand((Entity)fillEnt, kw));
			controlStartResume.requestFocusInWindow();
		}
	});

	buttonBar.add( fill );
}
 
Example 6
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 7
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 8
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addSnapToGridButton(JToolBar buttonBar, Insets margin) {
	snapToGrid = new JToggleButton( new ImageIcon(
			GUIFrame.class.getResource("/resources/images/Snap-16.png")) );
	snapToGrid.setMargin(margin);
	snapToGrid.setFocusPainted(false);
	snapToGrid.setRequestFocusEnabled(false);
	snapToGrid.setToolTipText(formatToolTip("Snap to Grid",
			"During repositioning, objects are forced to the nearest grid point."));
	snapToGrid.addActionListener( new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			KeywordIndex kw = InputAgent.formatBoolean("SnapToGrid", snapToGrid.isSelected());
			InputAgent.storeAndExecute(new KeywordCommand(sim.getSimulation(), kw));
			gridSpacing.setEnabled(snapToGrid.isSelected());
			controlStartResume.requestFocusInWindow();
		}
	} );

	buttonBar.add( snapToGrid );
}
 
Example 9
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 10
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addOutlineButton(JToolBar buttonBar, Insets margin) {
	outline = new JToggleButton(new ImageIcon(
			GUIFrame.class.getResource("/resources/images/Outline-16.png")));
	outline.setMargin(margin);
	outline.setFocusPainted(false);
	outline.setRequestFocusEnabled(false);
	outline.setToolTipText(formatToolTip("Show Outline", "Shows the outline."));
	outline.addActionListener( new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			if (!(selectedEntity instanceof LineEntity))
				return;
			LineEntity lineEnt = (LineEntity) selectedEntity;
			lineWidth.setEnabled(outline.isSelected());
			lineColour.setEnabled(outline.isSelected());
			if (lineEnt.isOutlined() == outline.isSelected())
				return;
			KeywordIndex kw = InputAgent.formatBoolean("Outlined", outline.isSelected());
			InputAgent.storeAndExecute(new KeywordCommand((Entity)lineEnt, kw));
			controlStartResume.requestFocusInWindow();
		}
	});

	buttonBar.add( outline );
}
 
Example 11
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 12
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 13
Source File: Compass.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
/** Creates new Compass */
public Compass() {
  super(new java.awt.GridLayout(3, 3));
  setOpaque(false);
  direction = -1;
  ActionListener lst = new ActionListener() {
    public void actionPerformed(ActionEvent ev) {
      String c = ev.getActionCommand();
      for (int i = 0; i < 9; i++) {
        if (BT_NAMES[i].equals(c)) {
          setDirection(i);
          break;
        }
      }
    }
  };
  ButtonGroup bg = new ButtonGroup();
  buttons = new JToggleButton[9];
  for (int i = 0; i < 9; i++) {
    JToggleButton btn = new JToggleButton(
        new ImageIcon(getClass().getResource("/edu/xtec/resources/icons/" + BT_NAMES[i] + ".gif")));
    btn.setPreferredSize(BT_DIMENSION);
    bg.add(btn);
    btn.setActionCommand(BT_NAMES[i]);
    btn.addActionListener(lst);
    btn.setFocusPainted(false);
    add(btn);
    buttons[i] = btn;
  }
}
 
Example 14
Source File: CSSStylesSelectionPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Property Summary section.
 *
 * @return Property Summary panel.
 */
private JPanel initPropertyPane() {
    propertyPane = new PropertyPaneView();
    String valueTitle =  NbBundle.getMessage(CSSStylesSelectionPanel.class, "CSSStylesSelectionPanel.value"); // NOI18N
    propertyPane.setProperties(new Node.Property[] {
        new PropertySupport.ReadOnly<String>(MatchedPropertyNode.PROPERTY_VALUE, String.class, valueTitle, null) {
            @Override
            public String getValue() throws IllegalAccessException, InvocationTargetException {
                return null;
            }
        }
    });
    ExplorerManagerProviderPanel propertyPanePanel = new ExplorerManagerProviderPanel();
    propertyPanePanel.setLayout(new BorderLayout());
    propertyPanePanel.add(propertyPane, BorderLayout.CENTER);
    JPanel headerPanel = new JPanel();
    headerPanel.setLayout(new BorderLayout());
    JPanel titlePanel = new JPanel();
    titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.X_AXIS));
    propertySummaryLabel = new JLabel();
    propertySummaryLabel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
    propertySummaryLabel.setMinimumSize(new Dimension(0,0));
    titlePanel.add(propertySummaryLabel);
    titlePanel.add(Box.createHorizontalGlue());
    JToggleButton pseudoClassToggle = new JToggleButton();
    pseudoClassToggle.setFocusPainted(false);
    pseudoClassToggle.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/web/inspect/resources/elementStates.png", true)); // NOI18N
    pseudoClassToggle.setToolTipText(NbBundle.getMessage(CSSStylesSelectionPanel.class, "CSSStylesSelectionPanel.pseudoClasses")); // NOI18N
    CustomToolbar toolBar = new CustomToolbar();
    toolBar.addButton(pseudoClassToggle);
    titlePanel.add(toolBar);
    headerPanel.add(titlePanel, BorderLayout.PAGE_START);
    headerPanel.add(createPseudoClassPanel(pseudoClassToggle), BorderLayout.CENTER);
    propertyPanePanel.add(headerPanel, BorderLayout.PAGE_START);
    propertyPaneManager = propertyPanePanel.getExplorerManager();
    propertyPanePanel.setMinimumSize(new Dimension(0,0)); // allow shrinking in JSplitPane
    return propertyPanePanel;
}
 
Example 15
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 );
}
 
Example 16
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void addShowGridButton(JToolBar buttonBar, Insets margin) {
	grid = new JToggleButton( new ImageIcon(
			GUIFrame.class.getResource("/resources/images/Grid-16.png")) );
	grid.setMargin(margin);
	grid.setFocusPainted(false);
	grid.setRequestFocusEnabled(false);
	grid.setToolTipText(formatToolTip("Show Grid",
			"Shows the coordinate grid on the x-y plane."));
	grid.addActionListener( new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			DisplayEntity ent = (DisplayEntity) sim.getNamedEntity("XY-Grid");
			if (ent == null && sim.getNamedEntity("Grid100x100") != null) {
				InputAgent.storeAndExecute(new DefineCommand(sim, DisplayEntity.class, "XY-Grid"));
				ent = (DisplayEntity) sim.getNamedEntity("XY-Grid");
				KeywordIndex dmKw = InputAgent.formatArgs("DisplayModel", "Grid100x100");
				KeywordIndex sizeKw = InputAgent.formatArgs("Size", "100", "100", "0", "m");
				InputAgent.storeAndExecute(new KeywordCommand(ent, dmKw, sizeKw));
				grid.setSelected(true);
			}
			if (ent != null) {
				KeywordIndex kw = InputAgent.formatBoolean("Show", grid.isSelected());
				InputAgent.storeAndExecute(new KeywordCommand(ent, kw));
			}
			controlStartResume.requestFocusInWindow();
		}
	} );
	buttonBar.add( grid );
}
 
Example 17
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 18
Source File: CssStylesPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void updateToolbar(FileObject file, Collection<CssStylesPanelProvider> activeProviders) {

        toolBar.removeAll();
        if (activeProviders.size() <= 1) {
            //remove the whole toolbar, if there's one or zero providers
            removeToolbar();
        } else {
            addToolbar();
        }

        // Button group for document and source buttons
        ButtonGroup buttonGroup = new ButtonGroup();

        boolean first = true;

        CssStylesPanelProvider selected = (file == null) ? null : selectedTabs.get(file.getMIMEType());

        //do the active providers contain the pre-selected provider for this mimetype?
        boolean containsPreselected = selected == null ? false : activeProviders.contains(selected);

        for (CssStylesPanelProvider provider : activeProviders) {
            JToggleButton button = new JToggleButton();
            button.setText(provider.getPanelDisplayName());
            button.setActionCommand(provider.getPanelID());
            button.addActionListener(toolbarListener);

            button.setFocusable(true);
            button.setFocusPainted(false);
            button.setRolloverEnabled(true);

            //copied from org.netbeans.core.multiview.TabsComponent.createButton to make the look 
            //similar to the editor tabs
            Border b = (getButtonBorder());
            if (b != null) {
                button.setBorder(b);
            }
            if (AQUA) {
                button.putClientProperty("JButton.buttonType", "square"); //NOI18N
                button.putClientProperty("JComponent.sizeVariant", "small"); //NOI18N
            }

            buttonGroup.add(button);
            toolBar.add(button);

            if (containsPreselected) {
                //one of the active providers is already pre-selected by user
                if (provider == selected) {
                    //the selected one - activate it
                    button.setSelected(true);
                    setActiveProvider(provider);
                } else {
                    button.setSelected(false);
                }
            } else {
                //no provider has been explicitly selected by the user yet
                button.setSelected(first);
                if (first) {
                    setActiveProvider(provider);
                    first = false;
                }
            }
        }

        revalidate();
        repaint();
    }