List of usage examples for javax.swing JToggleButton isSelected
public boolean isSelected()
From source file:UndoableToggleApp3.java
public UndoableToggleEdit(JToggleButton button) { this.button = button; selected = button.isSelected(); }
From source file:net.schweerelos.parrot.CombinedParrotApp.java
@SuppressWarnings("serial") private JToggleButton setupNavigatorButton(final String name, final String accelerator, final NavigatorComponent navigator) { final Component component = navigator.asJComponent(); AbstractAction showNavigatorAction = new AbstractAction(name) { @Override/*from ww w . j av a 2 s . c o m*/ public void actionPerformed(ActionEvent e) { if (!(e.getSource() instanceof JToggleButton)) { return; } final Window window; if (component instanceof Window) { window = (Window) component; } else { window = SwingUtilities.getWindowAncestor(component); } JToggleButton button = (JToggleButton) e.getSource(); boolean show = button.isSelected(); if (show) { if (window != CombinedParrotApp.this && preferredFrameLocations.containsKey(window)) { window.setLocation(preferredFrameLocations.get(window)); } } if (navigator.tellSelectionWhenShown()) { Collection<NodeWrapper> selectedNodes = activeMainView.getSelectedNodes(); navigator.setSelectedNodes(selectedNodes); } component.setVisible(show); if (show) { window.setVisible(true); } else if (window != CombinedParrotApp.this) { window.setVisible(false); } } }; showNavigatorAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control " + accelerator)); final JToggleButton button = new JToggleButton(showNavigatorAction); button.setToolTipText("Show " + name.toLowerCase()); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button.setToolTipText((button.isSelected() ? "Hide " : "Show ") + name.toLowerCase()); } }); final Window window; if (component instanceof Window) { window = (Window) component; } else { window = SwingUtilities.getWindowAncestor(component); } if (window != null) { window.addComponentListener(new ComponentAdapter() { @Override public void componentHidden(ComponentEvent e) { button.setSelected(false); if (window != CombinedParrotApp.this) { preferredFrameLocations.put(window, window.getLocation()); } } @Override public void componentShown(ComponentEvent e) { button.setSelected(true); } }); } return button; }
From source file:de.codesourcery.eve.skills.ui.components.AbstractComponent.java
protected void linkComponentEnabledStates(final JToggleButton parent, final Component... children) { final boolean selected = parent.isSelected(); for (Component child : children) { child.setEnabled(selected);//from ww w . java 2 s .c om } parent.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { final boolean selected = e.getStateChange() == ItemEvent.SELECTED; for (Component child : children) { child.setEnabled(selected); } } }); }
From source file:es.emergya.ui.gis.HistoryMapViewer.java
private JToggleButton getResultadosButton() { final JToggleButton jToggleButton = new JToggleButton(i18n.getString("map.history.button.results"), LogicConstants.getIcon("capas_button_resultado")); jToggleButton.addActionListener(new ActionListener() { @Override//www.j ava2 s . c o m public void actionPerformed(ActionEvent e) { if (jToggleButton.isSelected()) { for (Layer l : ConsultaHistoricos.getCapas()) { l.visible = true; } } else { for (Layer l : ConsultaHistoricos.getCapas()) { l.visible = false; } } mapView.repaint(); } }); return jToggleButton; }
From source file:io.github.jeremgamer.editor.panels.MusicFrame.java
public MusicFrame(JFrame frame, final GeneralSave gs) { ArrayList<BufferedImage> icons = new ArrayList<BufferedImage>(); try {//from ww w . jav a 2 s . c o m icons.add(ImageIO.read(ImageGetter.class.getResource("icon16.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon32.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon64.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon128.png"))); } catch (IOException e1) { e1.printStackTrace(); } this.setIconImages((List<? extends Image>) icons); this.setTitle("Musique"); this.setSize(new Dimension(300, 225)); this.addWindowListener(new WindowListener() { @Override public void windowActivated(WindowEvent event) { } @Override public void windowClosed(WindowEvent event) { } @Override public void windowClosing(WindowEvent event) { try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } if (clip != null) { clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } } @Override public void windowDeactivated(WindowEvent event) { } @Override public void windowDeiconified(WindowEvent event) { } @Override public void windowIconified(WindowEvent event) { } @Override public void windowOpened(WindowEvent event) { } }); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); this.setModal(true); this.setLocationRelativeTo(frame); JPanel properties = new JPanel(); properties.setBorder(BorderFactory.createTitledBorder("Lecture")); ButtonGroup bg = new ButtonGroup(); bg.add(one); bg.add(loop); one.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JRadioButton rb = (JRadioButton) event.getSource(); if (rb.isSelected()) { gs.set("music.reading", 0); try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } if (clip != null) { if (clip.isRunning()) clip.loop(0); } } } }); loop.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JRadioButton rb = (JRadioButton) event.getSource(); if (rb.isSelected()) { gs.set("music.reading", 1); try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } if (clip != null) { if (clip.isRunning()) clip.loop(Clip.LOOP_CONTINUOUSLY); } } } }); properties.add(one); properties.add(loop); if (gs.getInt("music.reading") == 0) { one.setSelected(true); } else { loop.setSelected(true); } volume.setMaximum(100); volume.setMinimum(0); volume.setValue(30); volume.setPaintTicks(true); volume.setPaintLabels(true); volume.setMinorTickSpacing(10); volume.setMajorTickSpacing(20); volume.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { JSlider slider = (JSlider) event.getSource(); double value = slider.getValue(); gain = value / 100; dB = (float) (Math.log(gain) / Math.log(10.0) * 20.0); if (clip != null) gainControl.setValue(dB); gs.set("music.volume", (int) value); } }); volume.setValue(gs.getInt("music.volume")); properties.add(volume); properties.setPreferredSize(new Dimension(300, 125)); content.add(properties); JPanel browsePanel = new JPanel(); browsePanel.setBorder(BorderFactory.createTitledBorder("")); JButton browse = new JButton("Parcourir..."); if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) { preview.setEnabled(false); browse.setText(""); try { browse.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } } browse.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JButton button = (JButton) event.getSource(); if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) { if (clip != null) { clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } name.setText(""); preview.setEnabled(false); button.setText("Parcourir..."); button.setIcon(null); new File("projects/" + Editor.getProjectName() + "/music.wav").delete(); gs.set("music.name", ""); } else { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Audio (WAV)", "wav"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyMusic(new File(path)); button.setText(""); try { button.setIcon( new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } gs.set("music.name", new File(path).getName()); try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } name.setText(new File(path).getName()); preview.setEnabled(true); } } } }); if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) { preview.setEnabled(true); } else { preview.setEnabled(false); } preview.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JToggleButton tb = (JToggleButton) event.getSource(); if (tb.isSelected()) { try { audioStream = AudioSystem.getAudioInputStream( new File("projects/" + Editor.getProjectName() + "/music.wav")); format = audioStream.getFormat(); info = new DataLine.Info(Clip.class, format); clip = (Clip) AudioSystem.getLine(info); clip.open(audioStream); clip.start(); gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(dB); if (loop.isSelected()) { clip.loop(Clip.LOOP_CONTINUOUSLY); } else { clip.loop(0); } clip.addLineListener(new LineListener() { @Override public void update(LineEvent event) { Clip clip = (Clip) event.getSource(); if (!clip.isRunning()) { preview.setSelected(false); clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }); } catch (Exception exc) { exc.printStackTrace(); } } else { clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BorderLayout()); buttons.add(browse, BorderLayout.WEST); buttons.add(preview, BorderLayout.EAST); browsePanel.setLayout(new BorderLayout()); browsePanel.add(buttons, BorderLayout.NORTH); browsePanel.add(name, BorderLayout.SOUTH); name.setPreferredSize(new Dimension(280, 25)); name.setText(gs.getString("music.name")); content.add(browsePanel); this.setContentPane(content); this.setVisible(true); }
From source file:org.nbheaven.sqe.codedefects.history.controlcenter.panels.SQEHistoryPanel.java
/** Creates new form SQEHistoryPanel */ public SQEHistoryPanel() { historyChart = org.jfree.chart.ChartFactory.createStackedXYAreaChart(null, "Snapshot", "CodeDefects", perProjectDataSet, PlotOrientation.VERTICAL, false, true, false); historyChart.setBackgroundPaint(Color.WHITE); historyChart.getXYPlot().setRangeGridlinePaint(Color.BLACK); historyChart.getXYPlot().setDomainGridlinePaint(Color.BLACK); historyChart.getXYPlot().setBackgroundPaint(Color.WHITE); XYPlot plot = historyChart.getXYPlot(); plot.setForegroundAlpha(0.7f);//from ww w .j a v a2s .co m // plot.getRenderer(); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects"); rangeAxis.setStrictValuesFlag(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setRangeAxis(rangeAxis); StackedXYAreaRenderer2 categoryItemRenderer = new StackedXYAreaRenderer2(); //3D(); categoryItemRenderer.setSeriesPaint(0, Color.RED); categoryItemRenderer.setSeriesPaint(1, Color.ORANGE); categoryItemRenderer.setSeriesPaint(2, Color.YELLOW); plot.setRenderer(categoryItemRenderer); ChartPanel historyChartPanel = new ChartPanel(historyChart); historyChartPanel.setBorder(null); historyChartPanel.setPreferredSize(new Dimension(150, 200)); historyChartPanel.setBackground(Color.WHITE); initComponents(); historyView.setLayout(new BorderLayout()); historyView.add(historyChartPanel, BorderLayout.CENTER); JPanel selectorPanel = new JPanel(); selectorPanel.setOpaque(false); GroupLayout layout = new GroupLayout(selectorPanel); selectorPanel.setLayout(layout); // Turn on automatically adding gaps between components layout.setAutocreateGaps(true); // Turn on automatically creating gaps between components that touch // the edge of the container and the container. layout.setAutocreateContainerGaps(true); ParallelGroup horizontalParallelGroup = layout.createParallelGroup(GroupLayout.LEADING); SequentialGroup verticalSequentialGroup = layout.createSequentialGroup(); layout.setHorizontalGroup(layout.createSequentialGroup().add(horizontalParallelGroup)); layout.setVerticalGroup(verticalSequentialGroup); clearHistoryButton = new JButton(); clearHistoryButton.setEnabled(false); clearHistoryButton.setIcon(ImageUtilities .image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/codedefects/history/resources/trash.png"))); clearHistoryButton.setOpaque(false); clearHistoryButton.setFocusPainted(false); clearHistoryButton.setToolTipText( NbBundle.getBundle("org/nbheaven/sqe/codedefects/history/controlcenter/panels/Bundle") .getString("HINT_clear_button")); horizontalParallelGroup.add(clearHistoryButton); verticalSequentialGroup.add(clearHistoryButton); clearHistoryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (null != activeHistory) { activeHistory.clear(); } } }); Component createVerticalStrut = Box.createVerticalStrut(10); horizontalParallelGroup.add(createVerticalStrut); verticalSequentialGroup.add(createVerticalStrut); for (final QualityProvider provider : SQEUtilities.getProviders()) { final JToggleButton providerButton = new JToggleButton(); providerButton.setIcon(provider.getIcon()); providerButton.setOpaque(false); providerButton.setFocusPainted(false); horizontalParallelGroup.add(providerButton); verticalSequentialGroup.add(providerButton); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (providerButton.isSelected()) { addSelectedProvider(provider); } else { removeSelectedProvider(provider); } updateView(); } }; providerButton.addActionListener(listener); addSelectedProvider(provider); providerButton.setSelected(true); } historyView.add(selectorPanel, BorderLayout.EAST); }
From source file:krasa.formatter.plugin.ProjectSettingsForm.java
private void enabledBy(@NotNull JComponent[] targets, @NotNull JToggleButton... control) { boolean b = true; for (JToggleButton jToggleButton : control) { b = b && (jToggleButton.isEnabled() && jToggleButton.isSelected()); }/* w ww .j av a2 s . co m*/ for (JComponent target : targets) { target.setEnabled(b); } }
From source file:krasa.formatter.plugin.ProjectSettingsForm.java
private void enabledByAny(@NotNull JComponent[] targets, @NotNull JToggleButton... control) { boolean b = false; for (JToggleButton jToggleButton : control) { b = b || (jToggleButton.isEnabled() && jToggleButton.isSelected()); }/*from w w w . j a va 2 s . c om*/ for (JComponent target : targets) { target.setEnabled(b); } }
From source file:krasa.formatter.plugin.ProjectSettingsForm.java
private void enabledByAny(@NotNull JComponent[] targets, @NotNull JToggleButton[] negated, @NotNull JToggleButton... control) { boolean b = false; for (JToggleButton jToggleButton : control) { b = b || (jToggleButton.isEnabled() && jToggleButton.isSelected()); }// w ww. j a v a 2 s .com for (JToggleButton jToggleButton : negated) { b = b || (jToggleButton.isEnabled() && !jToggleButton.isSelected()); } for (JComponent target : targets) { target.setEnabled(b); } }
From source file:com.t3.client.ui.ExportDialog.java
public Map<String, Boolean> getExportSettings() { Map<String, Boolean> settings = new HashMap<String, Boolean>(16); FormAccessor fa = interactPanel.getFormAccessor(); Iterator<?> iter = fa.beanIterator(true); while (iter.hasNext()) { Object obj = iter.next(); if (obj instanceof JToggleButton) { JToggleButton jtb = (JToggleButton) obj; settings.put(jtb.getName(), jtb.isSelected()); }// ww w. j ava 2s. c om } return settings; }