List of usage examples for javax.swing JToggleButton JToggleButton
public JToggleButton(Action a)
From source file:org.languagetool.gui.Main.java
private void createGUI() { loadRecentFiles();//ww w . j a v a 2 s .co m frame = new JFrame("LanguageTool " + JLanguageTool.VERSION); setLookAndFeel(); openAction = new OpenAction(); saveAction = new SaveAction(); saveAsAction = new SaveAsAction(); checkAction = new CheckAction(); autoCheckAction = new AutoCheckAction(true); showResultAction = new ShowResultAction(true); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new CloseListener()); URL iconUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(TRAY_ICON); frame.setIconImage(new ImageIcon(iconUrl).getImage()); textArea = new JTextArea(); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.addKeyListener(new ControlReturnTextCheckingListener()); textLineNumber = new TextLineNumber(textArea, 2); numberedTextAreaPane = new JScrollPane(textArea); numberedTextAreaPane.setRowHeaderView(textLineNumber); resultArea = new JTextPane(); undoRedo = new UndoRedoSupport(this.textArea, messages); frame.setJMenuBar(createMenuBar()); GridBagConstraints buttonCons = new GridBagConstraints(); JPanel insidePanel = new JPanel(); insidePanel.setOpaque(false); insidePanel.setLayout(new GridBagLayout()); buttonCons.gridx = 0; buttonCons.gridy = 0; buttonCons.anchor = GridBagConstraints.LINE_START; insidePanel.add(new JLabel(messages.getString("textLanguage") + " "), buttonCons); //create a ComboBox with flags, do not include hidden languages languageBox = LanguageComboBox.create(messages, EXTERNAL_LANGUAGE_SUFFIX, true, false); buttonCons.gridx = 1; buttonCons.gridy = 0; buttonCons.anchor = GridBagConstraints.LINE_START; insidePanel.add(languageBox, buttonCons); JCheckBox autoDetectBox = new JCheckBox(messages.getString("atd")); buttonCons.gridx = 2; buttonCons.gridy = 0; buttonCons.gridwidth = GridBagConstraints.REMAINDER; buttonCons.anchor = GridBagConstraints.LINE_START; insidePanel.add(autoDetectBox, buttonCons); buttonCons.gridx = 0; buttonCons.gridy = 1; buttonCons.gridwidth = GridBagConstraints.REMAINDER; buttonCons.fill = GridBagConstraints.HORIZONTAL; buttonCons.anchor = GridBagConstraints.LINE_END; buttonCons.weightx = 1.0; insidePanel.add(statusLabel, buttonCons); Container contentPane = frame.getContentPane(); GridBagLayout gridLayout = new GridBagLayout(); contentPane.setLayout(gridLayout); GridBagConstraints cons = new GridBagConstraints(); cons.gridx = 0; cons.gridy = 1; cons.fill = GridBagConstraints.HORIZONTAL; cons.anchor = GridBagConstraints.FIRST_LINE_START; JToolBar toolbar = new JToolBar("Toolbar", JToolBar.HORIZONTAL); toolbar.setFloatable(false); contentPane.add(toolbar, cons); JButton openButton = new JButton(openAction); openButton.setHideActionText(true); openButton.setFocusable(false); toolbar.add(openButton); JButton saveButton = new JButton(saveAction); saveButton.setHideActionText(true); saveButton.setFocusable(false); toolbar.add(saveButton); JButton saveAsButton = new JButton(saveAsAction); saveAsButton.setHideActionText(true); saveAsButton.setFocusable(false); toolbar.add(saveAsButton); JButton spellButton = new JButton(this.checkAction); spellButton.setHideActionText(true); spellButton.setFocusable(false); toolbar.add(spellButton); JToggleButton autoSpellButton = new JToggleButton(autoCheckAction); autoSpellButton.setHideActionText(true); autoSpellButton.setFocusable(false); toolbar.add(autoSpellButton); JButton clearTextButton = new JButton(new ClearTextAction()); clearTextButton.setHideActionText(true); clearTextButton.setFocusable(false); toolbar.add(clearTextButton); cons.insets = new Insets(5, 5, 5, 5); cons.fill = GridBagConstraints.BOTH; cons.weightx = 10.0f; cons.weighty = 10.0f; cons.gridx = 0; cons.gridy = 2; cons.weighty = 5.0f; splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, numberedTextAreaPane, new JScrollPane(resultArea)); mainPanel.setLayout(new GridLayout(0, 1)); contentPane.add(mainPanel, cons); mainPanel.add(splitPane); cons.fill = GridBagConstraints.HORIZONTAL; cons.gridx = 0; cons.gridy = 3; cons.weightx = 1.0f; cons.weighty = 0.0f; cons.insets = new Insets(4, 12, 4, 12); contentPane.add(insidePanel, cons); ltSupport = new LanguageToolSupport(this.frame, this.textArea, this.undoRedo); ResultAreaHelper.install(messages, ltSupport, resultArea); languageBox.selectLanguage(ltSupport.getLanguage()); languageBox.setEnabled(!ltSupport.getConfig().getAutoDetect()); autoDetectBox.setSelected(ltSupport.getConfig().getAutoDetect()); taggerShowsDisambigLog = ltSupport.getConfig().getTaggerShowsDisambigLog(); languageBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { // we cannot re-use the existing LT object anymore frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); Language lang = languageBox.getSelectedLanguage(); ComponentOrientation componentOrientation = ComponentOrientation .getOrientation(lang.getLocale()); textArea.applyComponentOrientation(componentOrientation); resultArea.applyComponentOrientation(componentOrientation); ltSupport.setLanguage(lang); } } }); autoDetectBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { boolean selected = e.getStateChange() == ItemEvent.SELECTED; languageBox.setEnabled(!selected); ltSupport.getConfig().setAutoDetect(selected); if (selected) { Language detected = ltSupport.autoDetectLanguage(textArea.getText()); languageBox.selectLanguage(detected); } } }); ltSupport.addLanguageToolListener(new LanguageToolListener() { @Override public void languageToolEventOccurred(LanguageToolEvent event) { if (event.getType() == LanguageToolEvent.Type.CHECKING_STARTED) { String msg = org.languagetool.tools.Tools.i18n(messages, "checkStart"); statusLabel.setText(msg); if (event.getCaller() == getFrame()) { setWaitCursor(); checkAction.setEnabled(false); } } else if (event.getType() == LanguageToolEvent.Type.CHECKING_FINISHED) { if (event.getCaller() == getFrame()) { checkAction.setEnabled(true); unsetWaitCursor(); } String msg = org.languagetool.tools.Tools.i18n(messages, "checkDone", event.getSource().getMatches().size(), event.getElapsedTime()); statusLabel.setText(msg); } else if (event.getType() == LanguageToolEvent.Type.LANGUAGE_CHANGED) { languageBox.selectLanguage(ltSupport.getLanguage()); } else if (event.getType() == LanguageToolEvent.Type.RULE_ENABLED) { //this will trigger a check and the result will be updated by //the CHECKING_FINISHED event } else if (event.getType() == LanguageToolEvent.Type.RULE_DISABLED) { String msg = org.languagetool.tools.Tools.i18n(messages, "checkDoneNoTime", event.getSource().getMatches().size()); statusLabel.setText(msg); } } }); frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); Language lang = ltSupport.getLanguage(); ComponentOrientation componentOrientation = ComponentOrientation.getOrientation(lang.getLocale()); textArea.applyComponentOrientation(componentOrientation); resultArea.applyComponentOrientation(componentOrientation); ResourceBundle textLanguageMessageBundle = JLanguageTool.getMessageBundle(ltSupport.getLanguage()); textArea.setText(textLanguageMessageBundle.getString("guiDemoText")); Configuration config = ltSupport.getConfig(); if (config.getFontName() != null || config.getFontStyle() != Configuration.FONT_STYLE_INVALID || config.getFontSize() != Configuration.FONT_SIZE_INVALID) { String fontName = config.getFontName(); if (fontName == null) { fontName = textArea.getFont().getFamily(); } int fontSize = config.getFontSize(); if (fontSize == Configuration.FONT_SIZE_INVALID) { fontSize = textArea.getFont().getSize(); } Font font = new Font(fontName, config.getFontStyle(), fontSize); textArea.setFont(font); } frame.pack(); frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); frame.setLocationByPlatform(true); splitPane.setDividerLocation(200); MainWindowStateBean state = localStorage.loadProperty("gui.state", MainWindowStateBean.class); if (state != null) { if (state.getBounds() != null) { frame.setBounds(state.getBounds()); ResizeComponentListener.setBoundsProperty(frame, state.getBounds()); } if (state.getDividerLocation() != null) { splitPane.setDividerLocation(state.getDividerLocation()); } if (state.getState() != null) { frame.setExtendedState(state.getState()); } } ResizeComponentListener.attachToWindow(frame); maybeStartServer(); }
From source file:org.metacsp.utility.UI.SearchTreeFrame.java
public SearchTreeFrame(DelegateForest<MetaVariable, ConstraintNetwork> graph) { this.graph = graph; treeLayout = new TreeLayout<MetaVariable, ConstraintNetwork>(graph); radialLayout = new RadialTreeLayout<MetaVariable, ConstraintNetwork>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<MetaVariable, ConstraintNetwork>(treeLayout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<MetaVariable, ConstraintNetwork>()); vv.getRenderContext().setVertexLabelTransformer(new Transformer<MetaVariable, String>() { @Override// www . j a va2s . com public String transform(MetaVariable arg0) { return arg0.toString(); } }); vv.setVertexToolTipTransformer(new Transformer<MetaVariable, String>() { @Override public String transform(MetaVariable arg0) { return arg0.toString(); } }); //vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); vv.getRenderContext().setArrowFillPaintTransformer(new Transformer<ConstraintNetwork, Paint>() { @Override public Paint transform(ConstraintNetwork arg0) { return Color.lightGray; } }); //System.out.println(graph.getVertices()); rings = new Rings(); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse<?, ?> graphMouse = new DefaultModalGraphMouse<Object, Object>(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); radial.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LayoutTransition<MetaVariable, ConstraintNetwork> lt = new LayoutTransition<MetaVariable, ConstraintNetwork>( vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<MetaVariable, ConstraintNetwork> lt = new LayoutTransition<MetaVariable, ConstraintNetwork>( vv, radialLayout, treeLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); content.add(controls, BorderLayout.SOUTH); }
From source file:org.ngrinder.recorder.ui.RecordingControlPanel.java
/** * Create "Start Recording" Button and attach the event handler. * /* w ww. ja v a 2 s .c o m*/ * @return created Button. */ private JToggleButton createRecordingButton() { JToggleButton button = decoratedToSimpleButton(new JToggleButton("Start Recording")); button.setText("Start Recording"); button.setSelected(false); button.setMinimumSize(new Dimension(100, 30)); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JToggleButton button = (JToggleButton) e.getSource(); if (button.isSelected()) { button.setText("Stop Recording"); button.setSelected(true); messageBus.getPublisher(Topics.START_RECORDING).propertyChange(new PropertyChangeEvent( RecordingControlPanel.this, "Start Recording", null, getFilteredFileTypes())); } else { if (!stopConfirm()) { button.setSelected(true); return; } messageBus.getPublisher(Topics.STOP_RECORDING) .propertyChange(new PropertyChangeEvent(RecordingControlPanel.this, "Stop Recording", null, Pair.of(getFilteredFileTypes(), getGenerationOption()))); button.setText("Start Recording"); } } }); return button; }
From source file:org.nuclos.client.layout.wysiwyg.component.properties.PropertiesPanel.java
/** * This Method shows the Properties of a {@link WYSIWYGSubFormColumn} * @param c//from www. jav a2 s . c o m * @param tableLayoutUtil */ public static void showPropertiesForSubFormColumn(final WYSIWYGSubFormColumn c, TableLayoutUtil tableLayoutUtil) { final JToggleButton button = new JToggleButton(PROPERTIES_DIALOG.LABEL_DEFAULT_VALUES); List<AbstractButton> buttonlist = new ArrayList<AbstractButton>(); buttonlist.add(button); final PropertiesPanel dialog = new PropertiesPanel(c, tableLayoutUtil, buttonlist); if ((Boolean) c.getProperties().getProperty(WYSIWYGSubFormColumn.PROPERTY_DEFAULTVALUES).getValue()) { button.setSelected(true); dialog.properties.setEnabled(false); } button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (button.isSelected()) { if (dialog.properties.isEditing()) { dialog.properties.getCellEditor().stopCellEditing(); } for (String s : c.getPropertyNames()) { if ((PropertyUtils.getPropertyMode(c, s) & WYSIWYGEditorModes.ENABLED) == WYSIWYGEditorModes.ENABLED) { dialog.getModel().setValueAt(c.getDefaultPropertyValue(s), dialog.values.indexOf(s), 1); } } dialog.properties.setEnabled(false); } else { dialog.properties.setEnabled(true); } } }); dialog.setVisible(true); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java
/** * Helper method to create the tool bar hosting the management items. * /*w w w . ja va 2s . c o m*/ * @return See above. */ private JComponent createManagementBar() { bar = new JToolBar(); bar.setFloatable(false); bar.setRollover(true); bar.setBorder(null); JToggleButton button = new JToggleButton(controller.getAction(TreeViewerControl.INSPECTOR)); button.setSelected(true); bar.add(button); button = new JToggleButton(controller.getAction(TreeViewerControl.METADATA)); button.setSelected(true); bar.add(button); JButton b = new JButton(controller.getAction(TreeViewerControl.BROWSE)); UIUtilities.unifiedButtonLookAndFeel(b); bar.add(b); switch (TreeViewerAgent.runAsPlugin()) { case TreeViewer.IMAGE_J: b = UIUtilities.formatButtonFromAction(controller.getAction(TreeViewerControl.VIEW)); UIUtilities.unifiedButtonLookAndFeel(b); b.addMouseListener(new MouseAdapter() { /** * Displays the menu when the user releases the mouse. * @see MouseListener#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { controller.showMenu(TreeViewer.VIEW_MENU, (JComponent) e.getSource(), e.getPoint()); } }); bar.add(b); break; default: b = new JButton(controller.getAction(TreeViewerControl.VIEW)); UIUtilities.unifiedButtonLookAndFeel(b); bar.add(b); } bar.add(new JSeparator(JSeparator.VERTICAL)); //Now register the agent if any TaskBar tb = TreeViewerAgent.getRegistry().getTaskBar(); List<JComponent> l = tb.getToolBarEntries(TaskBar.AGENTS); if (l != null) { Iterator<JComponent> i = l.iterator(); JComponent comp; while (i.hasNext()) { comp = i.next(); UIUtilities.unifiedButtonLookAndFeel(comp); bar.add(comp); } bar.add(new JSeparator(JSeparator.VERTICAL)); } fullScreen = new JToggleButton(controller.getAction(TreeViewerControl.FULLSCREEN)); fullScreen.setSelected(model.isFullScreen()); //bar.add(fullScreen); if (TreeViewerAgent.isAdministrator()) { b = new JButton(controller.getAction(TreeViewerControl.UPLOAD_SCRIPT)); UIUtilities.unifiedButtonLookAndFeel(b); bar.add(b); } TreeViewerAction a = controller.getAction(TreeViewerControl.AVAILABLE_SCRIPTS); b = new JButton(a); Icon icon = b.getIcon(); Dimension d = new Dimension(UIUtilities.DEFAULT_ICON_WIDTH, UIUtilities.DEFAULT_ICON_HEIGHT); if (icon != null) d = new Dimension(icon.getIconWidth(), icon.getIconHeight()); busyLabel = new JXBusyLabel(d); busyLabel.setVisible(true); b.addMouseListener((RunScriptAction) a); UIUtilities.unifiedButtonLookAndFeel(b); scriptButton = b; bar.add(b); index = bar.getComponentCount() - 1; bar.add(new JSeparator(JSeparator.VERTICAL)); MouseAdapter adapter = new MouseAdapter() { /** * Shows the menu corresponding to the display mode. */ public void mousePressed(MouseEvent me) { createGroupsAndUsersMenu((Component) me.getSource(), me.getPoint()); } }; a = controller.getAction(TreeViewerControl.SWITCH_USER); IconManager icons = IconManager.getInstance(); menuButton = new JButton(icons.getIcon(IconManager.FILTER_MENU)); menuButton.setVisible(true); menuButton.setText(GROUP_DISPLAY_TEXT); menuButton.setHorizontalTextPosition(SwingConstants.LEFT); menuButton.addMouseListener(adapter); bar.add(menuButton); setPermissions(); return bar; }
From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java
/** * Helper method to create the tool bar hosting the edit items. * // w w w.j a va2s . c o m * @return See above. */ private JToolBar createSearchBar() { JToolBar bar = new JToolBar(); bar.setFloatable(false); bar.setRollover(true); bar.setBorder(null); bar.add(new JSeparator(JSeparator.VERTICAL)); bar.add(new JToggleButton(controller.getAction(TreeViewerControl.SEARCH))); return bar; }
From source file:org.openscience.jmol.app.Jmol.java
/** * Create a button to go inside of the toolbar. By default this * will load an image resource. The image filename is relative to * the classpath (including the '.' directory if its a part of the * classpath), and may either be in a JAR file or a separate file. * * @param key The key in the resource file to serve as the basis * of lookups./* w w w. j a v a2 s . c o m*/ * @return Button */ protected AbstractButton createToolbarButton(String key) { ImageIcon ii = JmolResourceHandler.getIconX(key + "Image"); AbstractButton b = new JButton(ii); String isToggleString = JmolResourceHandler.getStringX(key + "Toggle"); if (isToggleString != null) { boolean isToggle = Boolean.valueOf(isToggleString).booleanValue(); if (isToggle) { b = new JToggleButton(ii); if (key.equals("rotate")) buttonRotate = b; toolbarButtonGroup.add(b); String isSelectedString = JmolResourceHandler.getStringX(key + "ToggleSelected"); if (isSelectedString != null) { boolean isSelected = Boolean.valueOf(isSelectedString).booleanValue(); b.setSelected(isSelected); } } } b.setRequestFocusEnabled(false); b.setMargin(new Insets(1, 1, 1, 1)); Action a = null; String actionCommand = null; if (key.endsWith("Script")) { actionCommand = JmolResourceHandler.getStringX(key); a = executeScriptAction; } else { actionCommand = key; a = getAction(key); } if (a != null) { b.setActionCommand(actionCommand); b.addActionListener(a); a.addPropertyChangeListener(new ActionChangedListener(b)); b.setEnabled(a.isEnabled()); } else { b.setEnabled(false); } String tip = guimap.getLabel(key + "Tip"); if (tip != null) { b.setToolTipText(tip); } return b; }
From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java
private JPanel getNorthPanel() { JPanel ret = new JPanel(); ret.setLayout(new BorderLayout()); JPanel pnlTextFilter = new JPanel(); CRFlowLayout layout = new CRFlowLayout(); layout.setAlignment(CRFlowLayout.LEFT); pnlTextFilter.setLayout(layout);//from w w w . jav a2s . c om txtFilter = new JButtonTextField(); txtFilter.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { doFilter(); } @Override public void insertUpdate(DocumentEvent e) { doFilter(); } @Override public void changedUpdate(DocumentEvent e) { doFilter(); } }); pnlTextFilter.add(txtFilter); btnToggleFilters = new JToggleButton(OrbisGISIcon.FILTER); btnToggleFilters.setMargin(new Insets(0, 0, 0, 0)); btnToggleFilters.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pnlFilters.setVisible(!pnlFilters.isVisible()); } }); btnToggleFilters.setBorderPainted(false); btnToggleFilters.setContentAreaFilled(false); pnlTextFilter.add(btnToggleFilters); ret.add(pnlTextFilter, BorderLayout.NORTH); JPanel pnlFilters = getFilterAndTagPanel(); ret.add(pnlFilters, BorderLayout.CENTER); return ret; }
From source file:org.parosproxy.paros.extension.manualrequest.http.impl.HttpPanelSender.java
private JToggleButton getButtonFollowRedirects() { if (followRedirect == null) { followRedirect = new JToggleButton( new ImageIcon(HttpPanelSender.class.getResource("/resource/icon/16/118.png"))); // Arrow // turn//from w w w . j av a 2 s .c o m // around // left followRedirect.setToolTipText(Constant.messages.getString("manReq.checkBox.followRedirect")); followRedirect.setSelected(true); } return followRedirect; }
From source file:org.parosproxy.paros.extension.manualrequest.http.impl.HttpPanelSender.java
private JToggleButton getButtonUseTrackingSessionState() { if (useTrackingSessionState == null) { useTrackingSessionState = new JToggleButton( new ImageIcon(HttpPanelSender.class.getResource("/resource/icon/fugue/cookie.png"))); // Cookie useTrackingSessionState.setToolTipText(Constant.messages.getString("manReq.checkBox.useSession")); }/*from w w w . ja v a 2 s . c o m*/ return useTrackingSessionState; }