List of usage examples for javax.swing AbstractButton getText
public String getText()
From source file:Main.java
public Main(JFrame frame) { analyzer = new MyDialog(frame); analyzer.pack();/* w w w . j ava 2 s .c o m*/ analyzer.setLocationRelativeTo(frame); Point location = analyzer.getLocation(); location = new Point(location.x - LOC_SHIFT, location.y - LOC_SHIFT); analyzer.setLocation(location); analyzer.setVisible(true); add(new JButton(new AbstractAction(DISABLE_DIALOG_COMPONENTS) { @Override public void actionPerformed(ActionEvent evt) { AbstractButton btn = (AbstractButton) evt.getSource(); if (btn.getText().equals(DISABLE_DIALOG_COMPONENTS)) { btn.setText(ENABLE_DIALOG_COMPONENTS); analyzer.setComponentEnabled(false); } else { btn.setText(DISABLE_DIALOG_COMPONENTS); analyzer.setComponentEnabled(true); } } })); add(new JButton(new AbstractAction(DISABLE_DIALOG) { @Override public void actionPerformed(ActionEvent evt) { AbstractButton btn = (AbstractButton) evt.getSource(); if (btn.getText().equals(DISABLE_DIALOG)) { btn.setText(ENABLE_DIALOG); analyzer.setEnabled(false); } else { btn.setText(DISABLE_DIALOG); analyzer.setEnabled(true); } } })); }
From source file:MyButtonUI.java
public void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; Dimension d = b.getSize();//from w ww .j ava 2 s .co m g.setFont(c.getFont()); FontMetrics fm = g.getFontMetrics(); g.setColor(b.getForeground()); String caption = b.getText(); int x = (d.width - fm.stringWidth(caption)) / 2; int y = (d.height + fm.getAscent()) / 2; g.drawString(caption, x, y); }
From source file:ventanas.intervalosLenguaje.java
private int getIntervalos() { for (Enumeration<AbstractButton> buttons = cantidadIntervalos.getElements(); buttons.hasMoreElements();) { AbstractButton button = buttons.nextElement(); if (button.isSelected()) { String T = button.getText(); return Integer.parseInt(T); }//from w ww .j a va 2s .c o m } return 0; }
From source file:org.pentaho.ui.xul.swing.tags.SwingButton.java
@Override public void layout() { // check type to see if it's a toggleButton if (type == Type.CHECKBOX || type == Type.RADIO) { final AbstractButton oldButton = getButton(); final AbstractButton button = new JToggleButton(); button.setText(oldButton.getText()); button.setIcon(oldButton.getIcon()); button.setEnabled(oldButton.isEnabled()); button.setSelected(this.selected); setButton(button);// w w w. ja v a 2s . c o m if (this.getOnclick() != null) { this.setOnclick(this.getOnclick()); } } final AbstractButton button = getButton(); // adjust orientation of label and icon if (this.orientation == Orient.VERTICAL) { button.setHorizontalTextPosition(JButton.CENTER); if (this.dir == Direction.FORWARD) { button.setVerticalTextPosition(JButton.BOTTOM); } else { button.setVerticalTextPosition(JButton.TOP); } } else { button.setVerticalTextPosition(JButton.CENTER); if (this.dir == Direction.FORWARD) { button.setHorizontalTextPosition(JButton.RIGHT); } else { button.setHorizontalTextPosition(JButton.LEFT); } } // Square button patch. if no label and icon is square, set min/max to square up button final Icon icon = button.getIcon(); if ("".equals(button.getText()) && icon != null && icon.getIconHeight() == icon.getIconWidth()) { Dimension dim = button.getPreferredSize(); button.setMinimumSize(new Dimension(dim.height, dim.height)); button.setPreferredSize(new Dimension(dim.height, dim.height)); } button.setToolTipText(this.getTooltiptext()); super.layout(); }
From source file:lab4.YouQuiz.java
public String getSelectedButtonText(ButtonGroup buttonGroup) { for (Enumeration<AbstractButton> buttons = buttonGroup.getElements(); buttons.hasMoreElements();) { AbstractButton button = buttons.nextElement(); if (button.isSelected()) { return button.getText(); }// w w w . ja va2 s. c o m } return null; }
From source file:org.datacleaner.windows.ResultWindow.java
/** * * @param configuration/*from w w w .j av a2 s .c om*/ * @param job * either this or result must be available * @param result * either this or job must be available * @param jobFilename * @param windowContext * @param userPreferences * @param rendererFactory */ @Inject protected ResultWindow(DataCleanerConfiguration configuration, @Nullable AnalysisJob job, @Nullable AnalysisResult result, @Nullable @JobFile FileObject jobFilename, WindowContext windowContext, UserPreferences userPreferences, RendererFactory rendererFactory) { super(windowContext); final boolean running = (result == null); _resultPanels = new IdentityHashMap<>(); _configuration = configuration; _job = job; _jobFilename = jobFilename; _userPreferences = userPreferences; _rendererFactory = rendererFactory; final Ref<AnalysisResult> resultRef = new Ref<AnalysisResult>() { @Override public AnalysisResult get() { return getResult(); } }; Border buttonBorder = new CompoundBorder(WidgetUtils.BORDER_LIST_ITEM_SUBTLE, new EmptyBorder(10, 4, 10, 4)); _cancelButton = WidgetFactory.createDefaultButton("Cancel job", IconUtils.ACTION_STOP); _cancelButton.setHorizontalAlignment(SwingConstants.LEFT); _cancelButton.setBorder(buttonBorder); _saveResultsPopupButton = WidgetFactory.createDefaultPopupButton("Save results", IconUtils.ACTION_SAVE_DARK); _saveResultsPopupButton.setHorizontalAlignment(SwingConstants.LEFT); _saveResultsPopupButton.setBorder(buttonBorder); _saveResultsPopupButton.setMenuPosition(MenuPosition.TOP); _saveResultsPopupButton.getMenu().setBorder(new MatteBorder(1, 0, 0, 1, WidgetUtils.BG_COLOR_MEDIUM)); JMenuItem saveAsFileItem = WidgetFactory.createMenuItem("Save as result file", IconUtils.ACTION_SAVE_DARK); saveAsFileItem.addActionListener(new SaveAnalysisResultActionListener(resultRef, _userPreferences)); saveAsFileItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(saveAsFileItem); JMenuItem exportToHtmlItem = WidgetFactory.createMenuItem("Export to HTML", IconUtils.WEBSITE); exportToHtmlItem.addActionListener( new ExportResultToHtmlActionListener(resultRef, _configuration, _userPreferences)); exportToHtmlItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(exportToHtmlItem); JMenuItem publishToServerItem = WidgetFactory.createMenuItem("Publish to server", IconUtils.MENU_DQ_MONITOR); publishToServerItem.addActionListener(new PublishResultToMonitorActionListener(getWindowContext(), _userPreferences, resultRef, _jobFilename)); publishToServerItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(publishToServerItem); _tabbedPane = new VerticalTabbedPane() { private static final long serialVersionUID = 1L; @Override protected JComponent wrapInCollapsiblePane(final JComponent originalPanel) { DCPanel buttonPanel = new DCPanel(); buttonPanel.setLayout(new VerticalLayout()); buttonPanel.setBorder(new MatteBorder(1, 0, 0, 0, WidgetUtils.BG_COLOR_MEDIUM)); buttonPanel.add(_saveResultsPopupButton); buttonPanel.add(_cancelButton); DCPanel wrappedPanel = new DCPanel(); wrappedPanel.setLayout(new BorderLayout()); wrappedPanel.add(originalPanel, BorderLayout.CENTER); wrappedPanel.add(buttonPanel, BorderLayout.SOUTH); return super.wrapInCollapsiblePane(wrappedPanel); } }; final Dimension size = getDefaultWindowSize(); _windowSizePreference = new WindowSizePreferences(_userPreferences, getClass(), size.width, size.height); _progressInformationPanel = new ProgressInformationPanel(running); _tabbedPane.addTab("Progress information", imageManager.getImageIcon("images/model/progress_information.png", IconUtils.ICON_SIZE_TAB), _progressInformationPanel); for (Func<ResultWindow, JComponent> pluggableComponent : PLUGGABLE_BANNER_COMPONENTS) { JComponent component = pluggableComponent.eval(this); if (component != null) { if (component instanceof AbstractButton) { AbstractButton button = (AbstractButton) component; JMenuItem menuItem = WidgetFactory.createMenuItem(button.getText(), button.getIcon()); for (ActionListener listener : button.getActionListeners()) { menuItem.addActionListener(listener); } menuItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(menuItem); } else if (component instanceof JMenuItem) { // TODO: Not possible. JMenuItem is a subclass of AbstractButton. Reorder or remove? JMenuItem menuItem = (JMenuItem) component; menuItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(menuItem); } } } if (running) { // run the job in a swing worker _result = null; _worker = new AnalysisRunnerSwingWorker(_configuration, _job, this); _cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { _worker.cancelIfRunning(); } }); } else { // don't add the progress information, simply render the job asap _result = result; _worker = null; final Map<ComponentJob, AnalyzerResult> map = result.getResultMap(); for (Entry<ComponentJob, AnalyzerResult> entry : map.entrySet()) { final ComponentJob componentJob = entry.getKey(); final AnalyzerResult analyzerResult = entry.getValue(); addResult(componentJob, analyzerResult); } _progressInformationPanel.onSuccess(); WidgetUtils.invokeSwingAction(new Runnable() { @Override public void run() { if (_tabbedPane.getTabCount() > 1) { // switch to the first available result panel _tabbedPane.setSelectedIndex(1); } } }); } updateButtonVisibility(running); }
From source file:com.codejumble.opentube.Main.java
/** * Returns the version selected by the user for the output file * * @return desired format/*www . j ava 2 s.co m*/ */ private String getSelectedFormatOption() { String format = "mp4"; for (Enumeration<AbstractButton> buttons = mediaFormatButtonGroup.getElements(); buttons .hasMoreElements();) { AbstractButton button = buttons.nextElement(); if (button.isSelected()) { format = button.getText(); } } return format; }
From source file:org.drugis.addis.gui.WelcomeDialog.java
private void initComps() { final ButtonGroup examples = new ButtonGroup(); examples.add(new JRadioButton(Main.Examples.DEPRESSION.name, true)); examples.add(new JRadioButton(Main.Examples.HYPERTENSION.name)); final AbstractAction exampleAction = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { d_main.loadExampleDomain(Main.Examples.findFileName(getSelection(examples).getText())); closeWelcome();/*from w w w .j av a2 s. c o m*/ } }; final AbstractAction loadAction = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { if (d_main.fileLoadActions() == JFileChooser.APPROVE_OPTION) { closeWelcome(); } } }; final AbstractAction newAction = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { d_main.newFileActions(); closeWelcome(); } }; FormLayout layout = new FormLayout("left:pref, " + SPACING + "px, left:pref", "p, 3dlu, p, " + SPACING + "px, p, " + SPACING + "px, p, 3dlu, p"); PanelBuilder builder = new PanelBuilder(layout); final CellConstraints cc = new CellConstraints(); builder.add(createImageLabel(FileNames.IMAGE_HEADER), cc.xyw(1, 1, 3)); builder.add(createButton("Load example", FileNames.ICON_TIP, exampleAction), cc.xy(1, 3)); final PanelBuilder radios = new PanelBuilder(new FormLayout("p, fill:pref:grow, right:pref", "p, 3dlu, p")); final ArrayList<AbstractButton> buttons = Collections.list(examples.getElements()); forAllDo(buttons, new Closure<AbstractButton>() { public void execute(final AbstractButton exampleOption) { int row = buttons.indexOf(exampleOption) == 0 ? 1 : buttons.indexOf(exampleOption) + 2; exampleOption.setOpaque(false); radios.add(exampleOption, cc.xy(1, row)); radios.add(createHelpButton(exampleOption), cc.xy(3, row)); } private JButton createHelpButton(final AbstractButton exampleOption) { JButton help = GUIFactory.createIconButton(org.drugis.mtc.gui.FileNames.ICON_ABOUT, "Information about this example"); removeBackground(help); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Examples example = Examples.findByName(exampleOption.getText()); String helpText = s_help.getHelpText(example.name().toLowerCase()); showExampleInfo(helpText); } }); return help; } }); JPanel radiosPanel = radios.getPanel(); setBorder(radiosPanel); builder.add(radiosPanel, cc.xy(3, 3)); builder.add(createButton("Open file", FileNames.ICON_OPENFILE, loadAction), cc.xy(1, 5)); JTextPane load = createLabel("Load an existing ADDIS data file stored on your computer."); builder.add(load, cc.xy(3, 5)); builder.add(createButton("New dataset", FileNames.ICON_FILE_NEW, newAction), cc.xy(1, 7)); builder.add(createLabel("Start with an empty file to build up your own data and analyses."), cc.xy(3, 7)); builder.add(createImageLabel(FileNames.IMAGE_FOOTER), cc.xyw(1, 9, 3)); setContentPane(builder.getPanel()); }