List of usage examples for javax.swing JButton getText
public String getText()
From source file:org.quackedcube.impl.Gui.java
public JComponent generateContent() { //Inital creation JPanel clockPanel = new JPanel(new BorderLayout()); JPanel virtualCubePanel = new JPanel(new BorderLayout()); JPanel logPanel = new JPanel(new BorderLayout()); virtualCubePanel/*from ww w . j a v a 2s. c o m*/ .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Cube Position")); logPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Log")); //Clock setup clock = new Clock(); clock.setPreferredSize(new Dimension((int) clock.getPreferredSize().getWidth(), 100)); clock.setFont(new Font("Arial", Font.PLAIN, 180)); clock.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Timer")); clock.setAlignmentX(JComponent.CENTER_ALIGNMENT); clockPanel.add(clock, BorderLayout.CENTER); //Logging panel setup logScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); logScroll.setAlignmentX(Component.RIGHT_ALIGNMENT); logPane.setEditable(false); logPane.setAlignmentX(Component.CENTER_ALIGNMENT); logPanel.add(logScroll, BorderLayout.CENTER); //Virtual Cube panel log.trace("Creating virtual cube"); virtualCubePanel.add(virtualCube = new VirtualBuilder(), BorderLayout.CENTER); log.trace("Done creating virtual cube."); JPanel virtualCubeControl = new JPanel(new FlowLayout()); virtualCubeControl.add(new JButton("Rotate") { { final JButton self = this; addActionListener(new ActionListener() { final String start = "Rotate"; final String end = "Stop Rotating"; @Override public void actionPerformed(ActionEvent e) { if (self.getText().equals(start)) { Gui.this.virtualCube.rotate(); self.setText(end); } else if (self.getText().equals(end)) { Gui.this.virtualCube.stopRotating(); self.setText(start); } } }); } }); virtualCubeControl.add(new JButton("Reset Position") { { addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Gui.this.virtualCube.resetPosition(); } }); setEnabled(false); } }); virtualCubePanel.add(virtualCubeControl, BorderLayout.SOUTH); log.trace("Creating content pane"); JPanel contentPane = new JPanel(new MigLayout("fill", "fill", "fill")); contentPane.add(clock, "dock north"); //span 2, hmax 25%, wrap contentPane.add(virtualCubePanel, "growprio 20"); contentPane.add(logPanel, "span 1 2"); return contentPane; }
From source file:org.revager.tools.GUITools.java
/** * Creates a new image button./* w ww. j ava 2 s . c o m*/ * * @param icon * the normal icon * @param rolloverIcon * the rollover icon * @param action * the action * * @return the newly created image button */ public static JButton newImageButton(ImageIcon icon, ImageIcon rolloverIcon, Action action) { JButton button = new JButton(action); button.setToolTipText(button.getText()); button.setText(null); button.setContentAreaFilled(false); button.setBorder(new EmptyBorder(0, 0, 0, 0)); button.setMargin(new Insets(0, 0, 0, 0)); button.setBorderPainted(false); button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); button.setFocusPainted(false); button.setFocusable(false); button.setIcon(icon); button.setRolloverIcon(rolloverIcon); button.setRolloverSelectedIcon(rolloverIcon); button.setSelectedIcon(rolloverIcon); return button; }
From source file:pl.otros.logview.gui.LogViewMainFrame.java
private void initToolbar() { toolBar = new JToolBar(); final JComboBox searchMode = new JComboBox( new String[] { "String contains search: ", "Regex search: ", "Query search: " }); final SearchAction searchActionForward = new SearchAction(otrosApplication, SearchDirection.FORWARD); final SearchAction searchActionBackward = new SearchAction(otrosApplication, SearchDirection.REVERSE); searchFieldCbxModel = new DefaultComboBoxModel(); searchField = new JXComboBox(searchFieldCbxModel); searchField.setEditable(true);// ww w . jav a 2s . c om AutoCompleteDecorator.decorate(searchField); searchField.setMinimumSize(new Dimension(150, 10)); searchField.setPreferredSize(new Dimension(250, 10)); searchField.setToolTipText( "<HTML>Enter text to search.<BR/>" + "Enter - search next,<BR/>Alt+Enter search previous,<BR/>" + "Ctrl+Enter - mark all found</HTML>"); final DelayedSwingInvoke delayedSearchResultUpdate = new DelayedSwingInvoke() { @Override protected void performActionHook() { JTextComponent editorComponent = (JTextComponent) searchField.getEditor().getEditorComponent(); int stringEnd = editorComponent.getSelectionStart(); if (stringEnd < 0) { stringEnd = editorComponent.getText().length(); } try { String selectedText = editorComponent.getText(0, stringEnd); if (StringUtils.isBlank(selectedText)) { return; } OtrosJTextWithRulerScrollPane<JTextPane> logDetailWithRulerScrollPane = otrosApplication .getSelectedLogViewPanel().getLogDetailWithRulerScrollPane(); MessageUpdateUtils.highlightSearchResult(logDetailWithRulerScrollPane, otrosApplication.getAllPluginables().getMessageColorizers()); RulerBarHelper.scrollToFirstMarker(logDetailWithRulerScrollPane); } catch (BadLocationException e) { LOGGER.log(Level.SEVERE, "Can't update search highlight", e); } } }; JTextComponent searchFieldTextComponent = (JTextComponent) searchField.getEditor().getEditorComponent(); searchFieldTextComponent.getDocument().addDocumentListener(new DocumentInsertUpdateHandler() { @Override protected void documentChanged(DocumentEvent e) { delayedSearchResultUpdate.performAction(); } }); final MarkAllFoundAction markAllFoundAction = new MarkAllFoundAction(otrosApplication); final SearchModeValidatorDocumentListener searchValidatorDocumentListener = new SearchModeValidatorDocumentListener( (JTextField) searchField.getEditor().getEditorComponent(), observer, SearchMode.STRING_CONTAINS); SearchMode searchModeFromConfig = configuration.get(SearchMode.class, "gui.searchMode", SearchMode.STRING_CONTAINS); final String lastSearchString; int selectedSearchMode = 0; if (searchModeFromConfig.equals(SearchMode.STRING_CONTAINS)) { selectedSearchMode = 0; lastSearchString = configuration.getString(ConfKeys.SEARCH_LAST_STRING, ""); } else if (searchModeFromConfig.equals(SearchMode.REGEX)) { selectedSearchMode = 1; lastSearchString = configuration.getString(ConfKeys.SEARCH_LAST_REGEX, ""); } else if (searchModeFromConfig.equals(SearchMode.QUERY)) { selectedSearchMode = 2; lastSearchString = configuration.getString(ConfKeys.SEARCH_LAST_QUERY, ""); } else { LOGGER.warning("Unknown search mode " + searchModeFromConfig); lastSearchString = ""; } Component editorComponent = searchField.getEditor().getEditorComponent(); if (editorComponent instanceof JTextField) { final JTextField sfTf = (JTextField) editorComponent; sfTf.getDocument().addDocumentListener(searchValidatorDocumentListener); sfTf.getDocument().addDocumentListener(new DocumentInsertUpdateHandler() { @Override protected void documentChanged(DocumentEvent e) { try { int length = e.getDocument().getLength(); if (length > 0) { searchResultColorizer.setSearchString(e.getDocument().getText(0, length)); } } catch (BadLocationException e1) { LOGGER.log(Level.SEVERE, "Error: ", e1); } } }); sfTf.addKeyListener(new SearchFieldKeyListener(searchActionForward, sfTf)); sfTf.setText(lastSearchString); } searchMode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SearchMode mode = null; boolean validationEnabled = false; String confKey = null; String lastSearch = ((JTextField) searchField.getEditor().getEditorComponent()).getText(); if (searchMode.getSelectedIndex() == 0) { mode = SearchMode.STRING_CONTAINS; searchValidatorDocumentListener.setSearchMode(mode); validationEnabled = false; searchMode.setToolTipText("Checking if log message contains string (case is ignored)"); confKey = ConfKeys.SEARCH_LAST_STRING; } else if (searchMode.getSelectedIndex() == 1) { mode = SearchMode.REGEX; validationEnabled = true; searchMode .setToolTipText("Checking if log message matches regular expression (case is ignored)"); confKey = ConfKeys.SEARCH_LAST_REGEX; } else if (searchMode.getSelectedIndex() == 2) { mode = SearchMode.QUERY; validationEnabled = true; String querySearchTooltip = "<HTML>" + // "Advance search using SQL-like quries (i.e. level>=warning && msg~=failed && thread==t1)<BR/>" + // "Valid operator for query search is ==, ~=, !=, LIKE, EXISTS, <, <=, >, >=, &&, ||, ! <BR/>" + // "See wiki for more info<BR/>" + // "</HTML>"; searchMode.setToolTipText(querySearchTooltip); confKey = ConfKeys.SEARCH_LAST_QUERY; } searchValidatorDocumentListener.setSearchMode(mode); searchValidatorDocumentListener.setEnable(validationEnabled); searchActionForward.setSearchMode(mode); searchActionBackward.setSearchMode(mode); markAllFoundAction.setSearchMode(mode); configuration.setProperty("gui.searchMode", mode); searchResultColorizer.setSearchMode(mode); List<Object> list = configuration.getList(confKey); searchFieldCbxModel.removeAllElements(); for (Object o : list) { searchFieldCbxModel.addElement(o); } searchField.setSelectedItem(lastSearch); } }); searchMode.setSelectedIndex(selectedSearchMode); final JCheckBox markFound = new JCheckBox("Mark search result"); markFound.setMnemonic(KeyEvent.VK_M); searchField.addKeyListener(markAllFoundAction); configuration.addConfigurationListener(markAllFoundAction); JButton markAllFoundButton = new JButton(markAllFoundAction); final JComboBox markColor = new JComboBox(MarkerColors.values()); markFound.setSelected(configuration.getBoolean("gui.markFound", true)); markFound.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { boolean selected = markFound.isSelected(); searchActionForward.setMarkFound(selected); searchActionBackward.setMarkFound(selected); configuration.setProperty("gui.markFound", markFound.isSelected()); } }); markColor.setRenderer(new MarkerColorsComboBoxRenderer()); // markColor.addActionListener(new ActionListener() { // // @Override // public void actionPerformed(ActionEvent e) { // MarkerColors markerColors = (MarkerColors) markColor.getSelectedItem(); // searchActionForward.setMarkerColors(markerColors); // searchActionBackward.setMarkerColors(markerColors); // markAllFoundAction.setMarkerColors(markerColors); // configuration.setProperty("gui.markColor", markColor.getSelectedItem()); // otrosApplication.setSelectedMarkColors(markerColors); // } // }); markColor.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { MarkerColors markerColors = (MarkerColors) markColor.getSelectedItem(); searchActionForward.setMarkerColors(markerColors); searchActionBackward.setMarkerColors(markerColors); markAllFoundAction.setMarkerColors(markerColors); configuration.setProperty("gui.markColor", markColor.getSelectedItem()); otrosApplication.setSelectedMarkColors(markerColors); } }); markColor.getModel() .setSelectedItem(configuration.get(MarkerColors.class, "gui.markColor", MarkerColors.Aqua)); buttonSearch = new JButton(searchActionForward); buttonSearch.setMnemonic(KeyEvent.VK_N); JButton buttonSearchPrev = new JButton(searchActionBackward); buttonSearchPrev.setMnemonic(KeyEvent.VK_P); enableDisableComponetsForTabs.addComponet(buttonSearch); enableDisableComponetsForTabs.addComponet(buttonSearchPrev); enableDisableComponetsForTabs.addComponet(searchField); enableDisableComponetsForTabs.addComponet(markFound); enableDisableComponetsForTabs.addComponet(markAllFoundButton); enableDisableComponetsForTabs.addComponet(searchMode); enableDisableComponetsForTabs.addComponet(markColor); toolBar.add(searchMode); toolBar.add(searchField); toolBar.add(buttonSearch); toolBar.add(buttonSearchPrev); toolBar.add(markFound); toolBar.add(markAllFoundButton); toolBar.add(markColor); JButton nextMarked = new JButton(new JumpToMarkedAction(otrosApplication, Direction.FORWARD)); nextMarked.setToolTipText(nextMarked.getText()); nextMarked.setText(""); nextMarked.setMnemonic(KeyEvent.VK_E); enableDisableComponetsForTabs.addComponet(nextMarked); toolBar.add(nextMarked); JButton prevMarked = new JButton(new JumpToMarkedAction(otrosApplication, Direction.BACKWARD)); prevMarked.setToolTipText(prevMarked.getText()); prevMarked.setText(""); prevMarked.setMnemonic(KeyEvent.VK_R); enableDisableComponetsForTabs.addComponet(prevMarked); toolBar.add(prevMarked); enableDisableComponetsForTabs.addComponet(toolBar.add(new SearchByLevel(otrosApplication, 1, Level.INFO))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, 1, Level.WARNING))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, 1, Level.SEVERE))); enableDisableComponetsForTabs.addComponet(toolBar.add(new SearchByLevel(otrosApplication, -1, Level.INFO))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, -1, Level.WARNING))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, -1, Level.SEVERE))); }
From source file:wsattacker.sso.openid.attacker.gui.MainGui.java
@Override public void actionPerformed(ActionEvent e) { JButton pressedButton = (JButton) e.getSource(); //System.out.println("pressed button: " + pressedButton.getText()); if (pressedButton == lastPressedButton) { // do nothing return;//from ww w .j ava 2s . c om } // remove selection from LAST pressed button lastPressedButton.setFont(defaultFont); lastPressedButton = pressedButton; // add selection to pressed button pressedButton.setFont(boldUnderline); JXTaskPane taskPaneOfPressedButton = (JXTaskPane) SwingUtilities.getAncestorOfClass(JXTaskPane.class, pressedButton); if (taskPaneOfPressedButton.getTitle().equals("Attacker IdP")) { switch (pressedButton.getText()) { case "Server Configuration": splitPane.setRightComponent(attackerIdpServerConfigurationGui); break; case "HTML Discovery": splitPane.setRightComponent(attackerIdpHtmlConfigurationGui); break; case "XRDS Discovery": splitPane.setRightComponent(attackerIdpXrdsConfigurationGui); break; case "Valid Data": splitPane.setRightComponent(attackerIdpValidDataGui); break; case "Attack Data": splitPane.setRightComponent(attackerIdpAttackDataGui); break; case "Attack Overview": splitPane.setRightComponent(attackerIdpAttackOverviewGui); break; } } else { switch (pressedButton.getText()) { case "Server Configuration": splitPane.setRightComponent(analyzerIdpServerConfigurationGui); break; case "HTML Discovery": splitPane.setRightComponent(analyzerIdpHtmlConfigurationGui); break; case "XRDS Discovery": splitPane.setRightComponent(analyzerIdpXrdsConfigurationGui); break; case "Valid Data": splitPane.setRightComponent(analyzerIdpValidDataGui); break; case "Attack Data": splitPane.setRightComponent(analyzerIdpAttackDataGui); break; case "Parameter Overview": splitPane.setRightComponent(analyzerIdpAttackOverviewGui); break; case "Automated Analysis": splitPane.setRightComponent(evaluationGui); break; case "Reports": splitPane.setRightComponent(reportGui); break; case "Log": splitPane.setRightComponent(logGui); break; } } }