Java Code Examples for javax.swing.JToggleButton

The following examples show how to use javax.swing.JToggleButton. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
private void addTool(final Tool t, JMenu menu, JToolBar toolbar, ButtonGroup menuGroup, ButtonGroup toolbarGroup) {
    final JToggleButton toggle = new JToggleButton();
    final JCheckBoxMenuItem check = new JCheckBoxMenuItem();
    Action action = new AbstractAction(t.getName()) {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (currentTool != null) {
                    currentTool.deactivate();
                }
                currentTool = t;
                toggle.setSelected(true);
                check.setSelected(true);
                currentTool.activate();
            }
        };
    toggle.setAction(action);
    check.setAction(action);
    menu.add(check);
    if (toolbar != null) {
        toolbar.add(toggle);
        toolbarGroup.add(toggle);
    }
    menuGroup.add(check);
}
 
Example 2
@Override
public void actionPerformed(ActionEvent e) {
	for (JToggleButton button : primaryButtons) {
		if (button != e.getSource() && button.isSelected()) {
			button.setSelected(false);
		} else if (button == e.getSource() && !button.isSelected()) {
			button.setSelected(true);
		}

		if (button.isSelected()) {
			button.setFont(button.getFont().deriveFont(Font.BOLD));
		} else {
			button.setFont(button.getFont().deriveFont(Font.PLAIN));
		}
	}

	if (secondaryButton != null) {
		if (secondaryButton != e.getSource() && secondaryButton.isSelected()) {
			secondaryButton.clearMenuSelection();
		}
	}
}
 
Example 3
Source Project: WorldGrower   Source File: CommunityDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void createToggleButtonPanel(SoundIdReader soundIdReader, int infoPanelWidth, CardLayout cardLayout, JPanel infoPanel) {
	JPanel toggleButtonPanel = JPanelFactory.createBorderlessPanel();
	toggleButtonPanel.setBounds(5, 5, infoPanelWidth, 40);
	toggleButtonPanel.setLayout(new FlowLayout());
	contentPanel.add(toggleButtonPanel);

	ButtonGroup buttonGroup = new ButtonGroup();
	
	JToggleButton familyButton = createToggleButton("Family", FAMILY_KEY, soundIdReader, cardLayout, infoPanel, buttonGroup, toggleButtonPanel, "Shows family members of the player character");

	createToggleButton("Acquaintances", ACQUAINTANCES_KEY, soundIdReader, cardLayout, infoPanel, buttonGroup, toggleButtonPanel, "Shows acquaintances of the player character");
	createToggleButton("Player Character Ranks", RANKS_KEY, soundIdReader, cardLayout, infoPanel, buttonGroup, toggleButtonPanel, "Shows group memberships of the player character");
	createToggleButton("Organizations", ORGANIZATIONS_KEY, soundIdReader, cardLayout, infoPanel, buttonGroup, toggleButtonPanel, "Shows an overview of all organizations and their members");
	createToggleButton("Deities", DEITIES_KEY, soundIdReader, cardLayout, infoPanel, buttonGroup, toggleButtonPanel, "Shows an overview of all deities and their happiness");
	
	buttonGroup.setSelected(familyButton.getModel(), true);
}
 
Example 4
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 5
Source Project: jaamsim   Source File: GUIFrame.java    License: 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 Project: openjdk-jdk9   Source File: Test4619792.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class[] types = {
            Component.class,
            Container.class,
            JComponent.class,
            AbstractButton.class,
            JButton.class,
            JToggleButton.class,
    };
    // Control set. "enabled" and "name" has the same pattern and can be found
    String[] names = {
            "enabled",
            "name",
            "focusable",
    };
    for (String name : names) {
        for (Class type : types) {
            BeanUtils.getPropertyDescriptor(type, name);
        }
    }
}
 
Example 7
Source Project: runelite   Source File: TimerPanel.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
TimerPanel(ClockManager clockManager, Timer timer)
{
	super(clockManager, timer, "timer", true);

	JToggleButton loopButton = new JToggleButton(ClockTabPanel.LOOP_ICON);
	loopButton.setRolloverIcon(ClockTabPanel.LOOP_ICON_HOVER);
	loopButton.setSelectedIcon(ClockTabPanel.LOOP_SELECTED_ICON);
	loopButton.setRolloverSelectedIcon(ClockTabPanel.LOOP_SELECTED_ICON_HOVER);
	SwingUtil.removeButtonDecorations(loopButton);
	loopButton.setPreferredSize(new Dimension(16, 14));
	loopButton.setToolTipText("Loop timer");
	loopButton.addActionListener(e -> timer.setLoop(!timer.isLoop()));
	loopButton.setSelected(timer.isLoop());
	leftActions.add(loopButton);

	JButton deleteButton = new JButton(ClockTabPanel.DELETE_ICON);
	SwingUtil.removeButtonDecorations(deleteButton);
	deleteButton.setRolloverIcon(ClockTabPanel.DELETE_ICON_HOVER);
	deleteButton.setPreferredSize(new Dimension(16, 14));
	deleteButton.setToolTipText("Delete timer");
	deleteButton.addActionListener(e -> clockManager.removeTimer(timer));
	rightActions.add(deleteButton);
}
 
Example 8
private void init() {
    setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.X_AXIS));
    setFloatable(false);

    add(new javax.swing.Box.Filler(new java.awt.Dimension(10, 0),
            new java.awt.Dimension(10, 0),
            new java.awt.Dimension(10, 32767)));
    JLabel label = new JLabel("Properties");
    label.setFont(new Font("Default", Font.BOLD, 12));
    add(label);

    add(new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 32767)));

    add(Utils.createButton("Add Row", "add", "Ctrl+Plus", WebORTable.this));
    add(Utils.createButton("Delete Rows", "remove", "Ctrl+Minus", WebORTable.this));
    addSeparator();
    add(Utils.createButton("Move Rows Up", "up", "Ctrl+Up", WebORTable.this));
    add(Utils.createButton("Move Rows Down", "down", "Ctrl+Down", WebORTable.this));
    addSeparator();
    frameToggle = new JToggleButton(Utils.getIconByResourceName("/ui/resources/or/web/propViewer"));
    frameToggle.addItemListener(WebORTable.this);
    frameToggle.setToolTipText("Show/Hide Frame Property");
    frameToggle.setActionCommand("Toggle Frame");
    add(frameToggle);
}
 
Example 9
private void addButton(String title, String iconUrl,
  final Component component, JButtonBar bar, ButtonGroup group) {
  Action action = new AbstractAction(title, new ImageIcon(
    ButtonBarMain.class.getResource(iconUrl))) {
    public void actionPerformed(ActionEvent e) {
      show(component);
    }
  };

  JToggleButton button = new JToggleButton(action);
  bar.add(button);

  group.add(button);

  if (group.getSelection() == null) {
    button.setSelected(true);
    show(component);
  }
}
 
Example 10
Source Project: pumpernickel   Source File: TextSearchBar.java    License: MIT License 6 votes vote down vote up
/**
 * Sets the font for all the components in this search bar.
 */
@Override
public void setFont(Font f) {
	for (int a = 0; a < getComponentCount(); a++) {
		Component c = getComponent(a);
		if (c instanceof JButton) {
			((JButton) c).setFont(f);
		} else if (c instanceof JCheckBox) {
			// do nothing
		} else if (c instanceof JToggleButton) {
			((JToggleButton) c).setFont(f);
		} else if (c instanceof JLabel) {
			((JLabel) c).setFont(f);
		} else if (c instanceof JTextField) {
			((JTextField) c).setFont(f);
		}
	}
}
 
Example 11
Source Project: logging-log4j2   Source File: ClientGui.java    License: Apache License 2.0 6 votes vote down vote up
private JScrollPane scroll(final JTextArea text) {
    final JToggleButton toggleButton = new JToggleButton();
    toggleButton.setAction(new AbstractAction() {
        private static final long serialVersionUID = -4214143754637722322L;

        @Override
        public void actionPerformed(final ActionEvent e) {
            final boolean wrap = toggleButton.isSelected();
            text.setLineWrap(wrap);
        }
    });
    toggleButton.setToolTipText("Toggle line wrapping");
    final JScrollPane scrollStatusLog = new JScrollPane(text, //
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, //
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollStatusLog.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, toggleButton);
    return scrollStatusLog;
}
 
Example 12
Source Project: ghidra   Source File: AbstractDockingTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Finds the toggle button with the given name inside of the given container and then
 * ensures that the selected state of the button matches <code>selected</code>.
 * <p>
 * Note: this works for any instanceof {@link JToggleButton}, such as:
 * <ul>
 * 	<li>{@link JCheckBox}</li>
 *  <li>{@link JRadioButton}</li>
 * </ul>
 * as well as {@link EmptyBorderToggleButton}s.
 *
 * @param container a container that has the desired button as a descendant
 * @param buttonName the name of the button (you must set this on the button when it is
 *                   constructed; if there is no button with the given name found, then this
 *                   method will search for a button with the given text
 * @param selected true to toggle the button to selected; false for de-selected
 */
public static void setToggleButtonSelected(Container container, String buttonName,
		boolean selected) {

	AbstractButton button = findAbstractButtonByName(container, buttonName);
	if (button == null) {
		button = findAbstractButtonByText(container, buttonName);
	}
	if (button == null) {
		throw new AssertionError("Could not find button by name or text '" + buttonName + "'");
	}

	boolean isToggle =
		(button instanceof JToggleButton) || (button instanceof EmptyBorderToggleButton);
	if (!isToggle) {
		throw new AssertionError(
			"Found a button, but it is not a toggle button.  Text: '" + buttonName + "'");
	}

	setToggleButtonSelected(button, selected);
}
 
Example 13
Source Project: jaamsim   Source File: GUIFrame.java    License: 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 14
Source Project: TencentKona-8   Source File: Test4619792.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class[] types = {
            Component.class,
            Container.class,
            JComponent.class,
            AbstractButton.class,
            JButton.class,
            JToggleButton.class,
    };
    // Control set. "enabled" and "name" has the same pattern and can be found
    String[] names = {
            "enabled",
            "name",
            "focusable",
    };
    for (String name : names) {
        for (Class type : types) {
            BeanUtils.getPropertyDescriptor(type, name);
        }
    }
}
 
Example 15
Source Project: jaamsim   Source File: GUIFrame.java    License: 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 16
public OptComponentBinding(Bindings bindings, String property, Class<? extends IValidatable> clazz,
							JToggleButton button, boolean enabledByDefault) {
	if (property == null || clazz == null || button == null) {
		throw new NullPointerException();
	}

	if (property.equals("")) {
		throw new IllegalArgumentException();
	}

	if (!Arrays.asList(clazz.getInterfaces()).contains(IValidatable.class)) {
		throw new IllegalArgumentException(
				Messages.getString("OptComponentBinding.must.implement")
				+ IValidatable.class);
	}

	_bindings = bindings;
	_property = property;
	_clazz = clazz;
	_button = button;
	_button.addActionListener(this);
	_enabledByDefault = enabledByDefault;
}
 
Example 17
Source Project: pcgen   Source File: TableUtils.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private static JScrollPane createToggleButtonSelectionPane(JTable table, JTable rowheaderTable,
	JToggleButton button)
{
	rowheaderTable.setAutoCreateColumnsFromModel(false);
	// force the tables to share models
	rowheaderTable.setModel(table.getModel());
	rowheaderTable.setSelectionModel(table.getSelectionModel());
	rowheaderTable.setRowHeight(table.getRowHeight());
	rowheaderTable.setIntercellSpacing(table.getIntercellSpacing());
	rowheaderTable.setShowGrid(false);
	rowheaderTable.setFocusable(false);

	TableColumn column = new TableColumn(-1);
	column.setHeaderValue(new Object());
	column.setCellRenderer(new TableCellUtilities.ToggleButtonRenderer(button));
	rowheaderTable.addColumn(column);
	rowheaderTable.setPreferredScrollableViewportSize(new Dimension(20, 0));

	JScrollPane scrollPane = new JScrollPane();
	scrollPane.setViewportView(table);
	scrollPane.setRowHeaderView(rowheaderTable);
	return scrollPane;
}
 
Example 18
public OptComponentBinding(Bindings bindings, String property, Class<? extends IValidatable> clazz,
							JToggleButton button, boolean enabledByDefault) {
	if (property == null || clazz == null || button == null) {
		throw new NullPointerException();
	}

	if (property.equals("")) {
		throw new IllegalArgumentException();
	}

	if (!Arrays.asList(clazz.getInterfaces()).contains(IValidatable.class)) {
		throw new IllegalArgumentException(
				Messages.getString("OptComponentBinding.must.implement")
				+ IValidatable.class);
	}

	_bindings = bindings;
	_property = property;
	_clazz = clazz;
	_button = button;
	_button.addActionListener(this);
	_enabledByDefault = enabledByDefault;
}
 
Example 19
Source Project: openjdk-jdk8u   Source File: Test4619792.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class[] types = {
            Component.class,
            Container.class,
            JComponent.class,
            AbstractButton.class,
            JButton.class,
            JToggleButton.class,
    };
    // Control set. "enabled" and "name" has the same pattern and can be found
    String[] names = {
            "enabled",
            "name",
            "focusable",
    };
    for (String name : names) {
        for (Class type : types) {
            BeanUtils.getPropertyDescriptor(type, name);
        }
    }
}
 
Example 20
Source Project: netbeans   Source File: BreakpointsViewButtons.java    License: 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 21
Source Project: visualvm   Source File: ButtonBuilders.java    License: GNU General Public License v2.0 6 votes vote down vote up
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
    if (DetailsUtils.isSubclassOf(instance, JButton.class.getName())) {
        return new JButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JCheckBox.class.getName())) {
        return new JCheckBoxBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JRadioButton.class.getName())) {
        return new JRadioButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JToggleButton.class.getName())) {
        return new JToggleButtonBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JCheckBoxMenuItem.class.getName())) {
        return new JCheckBoxMenuItemBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JRadioButtonMenuItem.class.getName())) {
        return new JRadioButtonMenuItemBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenu.class.getName())) {
        return new JMenuBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenuBar.class.getName())) {
        return new JMenuBarBuilder(instance, heap);
    } else if (DetailsUtils.isSubclassOf(instance, JMenuItem.class.getName())) {
        return new JMenuItemBuilder(instance, heap);
    }
    return null;
}
 
Example 22
Source Project: brModelo   Source File: Controler.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void PopuleBarra(JComponent obj) {
    ButtonGroup buttons = new ButtonGroup();
    Barra = obj;

    Acao ac = new Acao(editor, "?", "Controler.interface.BarraLateral.Nothing.img", "Controler.interface.BarraLateral.Nothing.Texto", null);
    JToggleButton btn = arrume(new JToggleButton(ac));
    buttons.add(btn);
    obj.add(btn);
    btn.setSelected(true);
    ac.IDX = -1;
    this.BtnNothing = btn;
    int i = 0;
    for (ConfigAcao ca : Lista) {
        if (ca.tipo == TipoConfigAcao.tpBotoes || ca.tipo == TipoConfigAcao.tpAny) {
            ac = new Acao(editor, ca.texto, ca.ico, ca.descricao, ca.command);
            ac.IDX = i++;
            btn = arrume(new JToggleButton(ac));
            buttons.add(btn);
            //obj.add(btn);
            listaBotoes.put(ca.command, btn);
        }
    }
    menuComandos c = menuComandos.cmdDel;
    String str = "Controler.comandos." + c.toString().substring(3).toLowerCase();
    ac = new Acao(editor, Editor.fromConfiguracao.getValor(str + ".descricao"), str + ".img", str + ".descricao", c.toString());
    ListaDeAcoesEditaveis.add(ac);
    ac.normal = false;
    JButton btn2 = new JButton(ac);
    btn2.setHideActionText(true);
    btn2.setFocusable(false);
    btn2.setPreferredSize(new Dimension(40, 40));
    obj.add(btn2);

    LayoutManager la = obj.getLayout();
    if (la instanceof GridLayout) {
        ((GridLayout) la).setRows(i + 2);
    }
}
 
Example 23
Source Project: magarena   Source File: TabSelector.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void setOrSwitchZone(MagicPlayerZone aZone) {
    int switchPlayer = aZone != getZone()
        ? getPlayerIndex()
        : getPlayerIndex() == 0 ? 1 : 0;
    for (JToggleButton btn : buttons) {
        if (aZone.equals(getZone(btn)) && switchPlayer == getPlayerIndex(btn)) {
            setSelectedTab(getTabIndex(aZone, switchPlayer));
        }
    }
}
 
Example 24
Source Project: groovy   Source File: LexerFrame.java    License: 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 25
Source Project: magarena   Source File: ToggleButtonsPanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
private JToggleButton getToggleButton(String text, AbstractAction action) {
    final JToggleButton btn = new ViewToggleButton(text);
    if (action != null) {
        btn.addActionListener(action);
    }
    toggleGroup.add(btn);
    return btn;
}
 
Example 26
Source Project: netbeans   Source File: FiltersManager.java    License: Apache License 2.0 5 votes vote down vote up
/** Reactions to toggle button click,  */
public void actionPerformed(ActionEvent e) {
    // copy changed state first
    JToggleButton toggle = (JToggleButton)e.getSource();
    int index = toggles.indexOf(e.getSource());
    synchronized (STATES_LOCK) {
        filterStates.put(filtersDesc.getName(index),
                        Boolean.valueOf(toggle.isSelected()));
    }
    // notify
    fireChange();
}
 
Example 27
/**
 * Called when a waypoint is added. This implementation adds a waypoint button.
 * @param graphic the waypoint graphic, whose ID may or may not be populated.
 * @param graphicUid the waypoint graphic's ID.
 * @see RouteListener#waypointAdded(com.esri.core.map.Graphic, int)
 */
public void waypointAdded(Graphic graphic, int graphicUid) {
    final JToggleButton button = new JToggleButton((String) graphic.getAttributeValue("name"));
    waypointButtonToGraphicId.put(button, graphicUid);
    graphicIdToWaypointButton.put(graphicUid, button);
    Font font = new Font("Arial", Font.PLAIN, 18);
    button.setFont(font);
    button.setFocusable(false);
    button.setSelected(false);
    button.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (button == selectedWaypointButton) {
                //Unselect
                buttonGroup_waypoints.remove(button);
                button.setSelected(false);
                buttonGroup_waypoints.add(button);
                selectedWaypointButton = null;

                routeController.setSelectedWaypoint(null);
            } else {
                selectedWaypointButton = button;

                routeController.setSelectedWaypoint(waypointButtonToGraphicId.get(button));
            }
        }
    });
    button.setMaximumSize(new Dimension(Integer.MAX_VALUE, 60));
    button.setMinimumSize(new Dimension(0, 60));
    jPanel_waypointsList.add(button);
    buttonGroup_waypoints.add(button);
}
 
Example 28
Source Project: netbeans   Source File: CSSStylesSelectionPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a panel that allows forcing of pseudo-classes.
 * 
 * @param pseudoClassToggle toggle-button used to show the panel.
 * @return panel that allows forcing of pseudo-classes.
 */
private JPanel createPseudoClassPanel(JToggleButton pseudoClassToggle) {
    final JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2,2));
    ResourceBundle bundle = NbBundle.getBundle(CSSStylesSelectionPanel.class);
    panel.add(createPseudoCheckBox(
            CSS.PseudoClass.ACTIVE,
            bundle.getString("CSSStylesSelectionPanel.pseudoClass.active"))); // NOI18N
    panel.add(createPseudoCheckBox(
            CSS.PseudoClass.HOVER,
            bundle.getString("CSSStylesSelectionPanel.pseudoClass.hover"))); // NOI18N
    panel.add(createPseudoCheckBox(
            CSS.PseudoClass.FOCUS,
            bundle.getString("CSSStylesSelectionPanel.pseudoClass.focus"))); // NOI18N
    panel.add(createPseudoCheckBox(
            CSS.PseudoClass.VISITED,
            bundle.getString("CSSStylesSelectionPanel.pseudoClass.visited"))); // NOI18N
    panel.setVisible(false);
    pseudoClassToggle.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            JToggleButton source = (JToggleButton)e.getSource();
            panel.setVisible(source.isSelected());
        }
    });
    return panel;
}
 
Example 29
Source Project: settlers-remake   Source File: ShapeSelectionPanel.java    License: MIT License 5 votes vote down vote up
/**
 * Constructor
 */
public ShapeSelectionPanel() {
	super(BoxLayout.Y_AXIS);
	JToolBar tb = new JToolBar();
	tb.setFloatable(false);

	ButtonGroup group = new ButtonGroup();

	for (EShapeType type : EShapeType.values()) {
		JToggleButton bt = new JToggleButton(type.getIcon());
		bt.setDisabledIcon(type.getIcon().createDisabledIcon());
		bt.setSelectedIcon(type.getIcon().createSelectedIcon());
		bt.setToolTipText(type.getShape().getName());
		bt.addActionListener(new ShapeActionListener(type.getShape()));
		bt.setEnabled(false);
		tb.add(bt);
		group.add(bt);
		buttons.put(type, bt);
	}

	add(tb);

	for (EShapeProperty p : EShapeProperty.values()) {
		StrokenSlider slider = new StrokenSlider(p);
		properties.put(p, slider);

		add(slider);
	}

	updateStrokeProperties();
}
 
Example 30
Source Project: netbeans   Source File: VariablesViewButtons.java    License: 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;
}