List of usage examples for javax.swing JButton getAction
public Action getAction()
Action
for this ActionEvent
source, or null
if no Action
is set. From source file:net.sf.taverna.t2.workbench.views.results.processor.RenderedProcessorResultComponent.java
/** * Clears the result panel./*from w w w . jav a 2 s .c om*/ */ public void clearResult() { refreshButton.setEnabled(false); renderedResultPanel.removeAll(); // Update the 'save result' buttons appropriately for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) { JButton saveButton = (JButton) saveButtonsPanel.getComponent(i); SaveIndividualResultSPI action = (SaveIndividualResultSPI) (saveButton.getAction()); // Update the action action.setResultReference(null); saveButton.setEnabled(false); } renderersComboBox.setModel(new DefaultComboBoxModel<String>()); renderersComboBox.setEnabled(false); revalidate(); repaint(); }
From source file:net.sf.taverna.t2.workbench.views.results.workflow.RenderedResultComponent.java
/** * Clears the result panel.// w w w. j a va 2s . com */ public void clearResult() { refreshButton.setEnabled(false); wrapTextCheckBox.setVisible(false); renderedResultPanel.removeAll(); // Update the 'save result' buttons appropriately for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) { JButton saveButton = (JButton) saveButtonsPanel.getComponent(i); SaveIndividualResultSPI action = (SaveIndividualResultSPI) saveButton.getAction(); // Update the action action.setResultReference(null); saveButton.setEnabled(false); } renderersComboBox.setModel(new DefaultComboBoxModel<String>()); renderersComboBox.setEnabled(false); revalidate(); repaint(); }
From source file:net.sf.taverna.t2.workbench.views.results.processor.RenderedProcessorResultComponent.java
/** * Update the component based on the node selected from the * ResultViewComponent tree.//from w w w . ja v a2s. c om */ public void updateResult() { if (recognisedRenderersForMimeType == null) recognisedRenderersForMimeType = new ArrayList<>(); if (otherRenderers == null) otherRenderers = new ArrayList<>(); ProcessorResultTreeNode result = (ProcessorResultTreeNode) node; // Reference to the result data path = result.getReference(); // Enable the combo box renderersComboBox.setEnabled(true); /* * Update the 'save result' buttons appropriately as the result node had * changed */ for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) { JButton saveButton = (JButton) saveButtonsPanel.getComponent(i); SaveIndividualResultSPI action = (SaveIndividualResultSPI) (saveButton.getAction()); // Update the action with the new result reference action.setResultReference(path); saveButton.setEnabled(true); } if (DataBundles.isValue(path) || DataBundles.isReference(path)) { // Enable refresh button refreshButton.setEnabled(true); List<MimeType> mimeTypes = new ArrayList<>(); try (InputStream inputstream = RendererUtils.getInputStream(path)) { mimeTypes.addAll(getMimeTypes(inputstream)); } catch (IOException e) { logger.warn("Error getting mimetype", e); } if (mimeTypes.isEmpty()) { // If MIME types is empty - add "plain/text" MIME type mimeTypes.add(new MimeType("text/plain")); } else if (mimeTypes.size() == 1 && mimeTypes.get(0).toString().equals("chemical/x-fasta")) { /* * If MIME type is recognised as "chemical/x-fasta" only then * this might be an error from MIME magic (i.e., sometimes it * recognises stuff that is not "chemical/x-fasta" as * "chemical/x-fasta" and then Seq Vista renderer is used that * causes errors) - make sure we also add the renderers for * "text/plain" and "text/xml" as it is most probably just * normal xml text and push the "chemical/x-fasta" to the bottom * of the list. */ mimeTypes.add(0, new MimeType("text/plain")); mimeTypes.add(1, new MimeType("text/xml")); } for (MimeType mimeType : mimeTypes) for (Renderer renderer : rendererRegistry.getRenderersForMimeType(mimeType.toString())) if (!recognisedRenderersForMimeType.contains(renderer)) recognisedRenderersForMimeType.add(renderer); // if there are no renderers then force text/plain if (recognisedRenderersForMimeType.isEmpty()) recognisedRenderersForMimeType = rendererRegistry.getRenderersForMimeType("text/plain"); /* * Add all other available renderers that are not recognised to be * able to handle the MIME type of the result */ otherRenderers = rendererRegistry.getRenderers(); otherRenderers.removeAll(recognisedRenderersForMimeType); mimeList = new String[recognisedRenderersForMimeType.size() + otherRenderers.size()]; rendererList = new ArrayList<>(); /* * First add the ones that can handle the MIME type of the result * item */ for (int i = 0; i < recognisedRenderersForMimeType.size(); i++) { mimeList[i] = recognisedRenderersForMimeType.get(i).getType(); rendererList.add(recognisedRenderersForMimeType.get(i)); } // Then add the other renderers just in case for (int i = 0; i < otherRenderers.size(); i++) { mimeList[recognisedRenderersForMimeType.size() + i] = otherRenderers.get(i).getType(); rendererList.add(otherRenderers.get(i)); } renderersComboBox.setModel(new DefaultComboBoxModel<>(mimeList)); if (mimeList.length > 0) { int index = 0; // Find the index of the current MIME type for this output port. for (int i = 0; i < mimeList.length; i++) if (mimeList[i].equals(lastUsedMIMEtype)) { index = i; break; } int previousindex = renderersComboBox.getSelectedIndex(); renderersComboBox.setSelectedIndex(index); /* * force rendering as setSelectedIndex will not fire an * itemstatechanged event if previousindex == index and we still * need render the result as we may have switched from a * different result item in a result list but the renderer index * stayed the same */ if (previousindex == index) renderResult(); // draw the rendered result component } } else if (DataBundles.isError(path)) { // Disable refresh button refreshButton.setEnabled(false); @SuppressWarnings("unused") ErrorDocument errorDocument; try { errorDocument = DataBundles.getError(path); } catch (IOException e) { logger.warn("Error getting the error document", e); } // Reset the renderers as we have an error item recognisedRenderersForMimeType = null; otherRenderers = null; DefaultMutableTreeNode root = new DefaultMutableTreeNode("Error Trace"); // TODO handle error documents // ResultsUtils.buildErrorDocumentTree(root, errorDocument, referenceService); JTree errorTree = new JTree(root); errorTree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { Component renderer = null; if (value instanceof DefaultMutableTreeNode) { Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); if (userObject instanceof ErrorDocument) renderer = getErrorDocumentRenderer(tree, selected, expanded, leaf, row, hasFocus, (ErrorDocument) userObject); } if (renderer == null) renderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (renderer instanceof JLabel) { JLabel label = (JLabel) renderer; label.setIcon(null); } return renderer; } private Component getErrorDocumentRenderer(JTree tree, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus, ErrorDocument errorDocument) { return super.getTreeCellRendererComponent(tree, "<html>" + escapeHtml(errorDocument.getMessage()) + "</html>", selected, expanded, leaf, row, hasFocus); } }); renderersComboBox.setModel(new DefaultComboBoxModel<>(new String[] { ERROR_DOCUMENT })); renderedResultPanel.removeAll(); renderedResultPanel.add(errorTree, CENTER); repaint(); } }
From source file:net.sf.taverna.t2.workbench.views.results.workflow.RenderedResultComponent.java
/** * Update the component based on the node selected from the * ResultViewComponent tree./*ww w . jav a 2 s. c om*/ */ public void updateResult() { if (recognisedRenderersForMimeType == null) recognisedRenderersForMimeType = new ArrayList<>(); if (otherRenderers == null) otherRenderers = new ArrayList<>(); // Enable the combo box renderersComboBox.setEnabled(true); /* * Update the 'save result' buttons appropriately as the result node had * changed */ for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) { JButton saveButton = (JButton) saveButtonsPanel.getComponent(i); SaveIndividualResultSPI action = (SaveIndividualResultSPI) saveButton.getAction(); // Update the action with the new result reference action.setResultReference(path); saveButton.setEnabled(true); } if (DataBundles.isValue(path) || DataBundles.isReference(path)) { // Enable refresh button refreshButton.setEnabled(true); List<MimeType> mimeTypes = new ArrayList<>(); try (InputStream inputstream = getInputStream(path)) { mimeTypes.addAll(getMimeTypes(inputstream)); } catch (IOException e) { logger.warn("Error getting mimetype", e); } if (mimeTypes.isEmpty()) // If MIME types is empty - add "plain/text" MIME type mimeTypes.add(new MimeType("text/plain")); else if (mimeTypes.size() == 1 && mimeTypes.get(0).toString().equals("chemical/x-fasta")) { /* * If MIME type is recognised as "chemical/x-fasta" only then * this might be an error from MIME magic (i.e., sometimes it * recognises stuff that is not "chemical/x-fasta" as * "chemical/x-fasta" and then Seq Vista renderer is used that * causes errors) - make sure we also add the renderers for * "text/plain" and "text/xml" as it is most probably just * normal xml text and push the "chemical/x-fasta" to the bottom * of the list. */ mimeTypes.add(0, new MimeType("text/plain")); mimeTypes.add(1, new MimeType("text/xml")); } for (MimeType mimeType : mimeTypes) { List<Renderer> renderersList = rendererRegistry.getRenderersForMimeType(mimeType.toString()); for (Renderer renderer : renderersList) if (!recognisedRenderersForMimeType.contains(renderer)) recognisedRenderersForMimeType.add(renderer); } // if there are no renderers then force text/plain if (recognisedRenderersForMimeType.isEmpty()) recognisedRenderersForMimeType = rendererRegistry.getRenderersForMimeType("text/plain"); /* * Add all other available renderers that are not recognised to be * able to handle the MIME type of the result */ otherRenderers = new ArrayList<>(rendererRegistry.getRenderers()); otherRenderers.removeAll(recognisedRenderersForMimeType); mimeList = new String[recognisedRenderersForMimeType.size() + otherRenderers.size()]; rendererList = new ArrayList<>(); /* * First add the ones that can handle the MIME type of the result * item */ for (int i = 0; i < recognisedRenderersForMimeType.size(); i++) { mimeList[i] = recognisedRenderersForMimeType.get(i).getType(); rendererList.add(recognisedRenderersForMimeType.get(i)); } // Then add the other renderers just in case for (int i = 0; i < otherRenderers.size(); i++) { mimeList[recognisedRenderersForMimeType.size() + i] = otherRenderers.get(i).getType(); rendererList.add(otherRenderers.get(i)); } renderersComboBox.setModel(new DefaultComboBoxModel<String>(mimeList)); if (mimeList.length > 0) { int index = 0; // Find the index of the current MIME type for this output port. for (int i = 0; i < mimeList.length; i++) if (mimeList[i].equals(lastUsedMIMEtype)) { index = i; break; } int previousindex = renderersComboBox.getSelectedIndex(); renderersComboBox.setSelectedIndex(index); /* * force rendering as setSelectedIndex will not fire an * itemstatechanged event if previousindex == index and we still * need render the result as we may have switched from a * different result item in a result list but the renderer index * stayed the same */ if (previousindex == index) renderResult(); // draw the rendered result component } } else if (DataBundles.isError(path)) { // Disable refresh button refreshButton.setEnabled(false); // Hide wrap text check box - only works for actual data wrapTextCheckBox.setVisible(false); // Reset the renderers as we have an error item recognisedRenderersForMimeType = null; otherRenderers = null; DefaultMutableTreeNode root = new DefaultMutableTreeNode("Error Trace"); try { ErrorDocument errorDocument = DataBundles.getError(path); try { buildErrorDocumentTree(root, errorDocument); } catch (IOException e) { logger.warn("Error building error document tree", e); } } catch (IOException e) { logger.warn("Error getting the error document", e); } JTree errorTree = new JTree(root); errorTree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { Component renderer = null; if (value instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value; Object userObject = treeNode.getUserObject(); if (userObject instanceof ErrorDocument) renderer = renderErrorDocument(tree, selected, expanded, leaf, row, hasFocus, (ErrorDocument) userObject); } if (renderer == null) renderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (renderer instanceof JLabel) { JLabel label = (JLabel) renderer; label.setIcon(null); } return renderer; } private Component renderErrorDocument(JTree tree, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus, ErrorDocument errorDocument) { return super.getTreeCellRendererComponent(tree, "<html>" + escapeHtml(errorDocument.getMessage()) + "</html>", selected, expanded, leaf, row, hasFocus); } }); renderersComboBox.setModel(new DefaultComboBoxModel<>(new String[] { ERROR_DOCUMENT })); renderedResultPanel.removeAll(); renderedResultPanel.add(errorTree, CENTER); repaint(); } }
From source file:de.atomfrede.tools.evalutation.ui.ExceptionDialog.java
@SuppressWarnings("serial") @Override/*www. java 2 s. co m*/ public ButtonPanel createButtonPanel() { ButtonPanel buttonPanel = new ButtonPanel(); JButton closeButton = new JButton(); JButton detailButton = new JButton(); detailButton.setMnemonic('D'); closeButton.setName(OK); buttonPanel.addButton(closeButton, ButtonPanel.AFFIRMATIVE_BUTTON); buttonPanel.addButton(detailButton, ButtonPanel.OTHER_BUTTON); closeButton.setAction(new AbstractAction("Close") { @Override public void actionPerformed(ActionEvent e) { setDialogResult(RESULT_AFFIRMED); setVisible(false); dispose(); } }); detailButton.setAction(new AbstractAction("Details >>") { @Override public void actionPerformed(ActionEvent e) { if (_detailsPanel.isVisible()) { _detailsPanel.setVisible(false); putValue(Action.NAME, "Details <<"); pack(); } else { _detailsPanel.setVisible(true); putValue(Action.NAME, "<< Details"); pack(); } } }); setDefaultCancelAction(closeButton.getAction()); setDefaultAction(closeButton.getAction()); getRootPane().setDefaultButton(closeButton); buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); buttonPanel.setSizeConstraint(ButtonPanel.NO_LESS_THAN); return buttonPanel; }
From source file:org.nuclos.client.common.NuclosCollectController.java
/** * @todo this method is misused - it sets shortcuts for many things other than tabs... * @param frame/*from ww w . j a v a 2s.com*/ */ @Override protected void setupShortcutsForTabs(MainFrameTab frame) { final CollectPanel<Clct> pnlCollect = this.getCollectPanel(); final DetailsPanel pnlDetails = this.getDetailsPanel(); final Action actSelectSearchTab = new AbstractAction() { @Override public void actionPerformed(ActionEvent ev) { if (pnlCollect.isTabbedPaneEnabledAt(CollectPanel.TAB_SEARCH)) { pnlCollect.setTabbedPaneSelectedComponent(getSearchPanel()); } } }; KeyBindingProvider.bindActionToComponent(KeyBindingProvider.ACTIVATE_SEARCH_PANEL_1, actSelectSearchTab, pnlCollect); KeyBindingProvider.bindActionToComponent(KeyBindingProvider.ACTIVATE_SEARCH_PANEL_2, actSelectSearchTab, pnlCollect); //TODO This is a workaround. The detailpanel should keep the focus final Action actGrabFocus = new AbstractAction() { @Override public void actionPerformed(ActionEvent ev) { pnlDetails.grabFocus(); } }; /** * A <code>ChainedAction</code> is an action composed of a primary and a secondary action. * It behaves exactly like the primary action, except that additionally, the secondary action is performed * after the primary action. */ class ChainedAction implements Action { private final Action actPrimary; private final Action actSecondary; public ChainedAction(Action actPrimary, Action actSecondary) { this.actPrimary = actPrimary; this.actSecondary = actSecondary; } @Override public void addPropertyChangeListener(PropertyChangeListener listener) { actPrimary.addPropertyChangeListener(listener); } @Override public Object getValue(String sKey) { return actPrimary.getValue(sKey); } @Override public boolean isEnabled() { return actPrimary.isEnabled(); } @Override public void putValue(String sKey, Object oValue) { actPrimary.putValue(sKey, oValue); } @Override public void removePropertyChangeListener(PropertyChangeListener listener) { actPrimary.removePropertyChangeListener(listener); } @Override public void setEnabled(boolean bEnabled) { actPrimary.setEnabled(bEnabled); } @Override public void actionPerformed(ActionEvent ev) { actPrimary.actionPerformed(ev); actSecondary.actionPerformed(ev); } } //final Action actRefresh = new ChainedAction(this.getRefreshCurrentCollectableAction(), actGrabFocus); this.getCollectPanel().setTabbedPaneToolTipTextAt(CollectPanel.TAB_SEARCH, getSpringLocaleDelegate().getMessage("NuclosCollectController.13", "Suche (F7) (Strg+F)")); this.getCollectPanel().setTabbedPaneToolTipTextAt(CollectPanel.TAB_RESULT, getSpringLocaleDelegate().getMessage("NuclosCollectController.7", "Ergebnis (F8)")); this.getCollectPanel().setTabbedPaneToolTipTextAt(CollectPanel.TAB_DETAILS, getSpringLocaleDelegate().getMessage("NuclosCollectController.3", "Details (F2)")); // the search action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.START_SEARCH, this.getSearchAction(), pnlCollect); KeyBinding keybinding = KeyBindingProvider.REFRESH; // the refresh action KeyBindingProvider.removeActionFromComponent(keybinding, pnlDetails); pnlDetails.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keybinding.getKeystroke(), keybinding.getKey()); pnlDetails.getActionMap().put(keybinding.getKey(), this.getRefreshCurrentCollectableAction()); KeyBindingProvider.removeActionFromComponent(keybinding, getResultPanel()); getResultPanel().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keybinding.getKeystroke(), keybinding.getKey()); getResultPanel().getActionMap().put(keybinding.getKey(), getResultPanel().btnRefresh.getAction()); // the new action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEW, this.getNewAction(), pnlDetails); // the new with search values action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEW_SEARCHVALUE, this.getNewWithSearchValuesAction(), pnlCollect); // the save action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SAVE_1, this.getSaveAction(), pnlCollect); KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SAVE_2, this.getSaveAction(), pnlCollect); // first the navigation actions are performed and then the focus is grabbed: final Action actFirst = new ChainedAction(this.getFirstAction(), actGrabFocus); final Action actLast = new ChainedAction(this.getLastAction(), actGrabFocus); final Action actPrevious = new ChainedAction(this.getPreviousAction(), actGrabFocus); final Action actNext = new ChainedAction(this.getNextAction(), actGrabFocus); // the first action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.FIRST, actFirst, pnlDetails); pnlDetails.btnFirst.setAction(actFirst); // the last action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.LAST, actLast, pnlDetails); pnlDetails.btnLast.setAction(actLast); // the previous action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.PREVIOUS_1, actPrevious, pnlDetails); KeyBindingProvider.bindActionToComponent(KeyBindingProvider.PREVIOUS_2, actPrevious, pnlDetails); pnlDetails.btnPrevious.setAction(actPrevious); // the next action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEXT_1, actNext, pnlDetails); KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEXT_2, actNext, pnlDetails); pnlDetails.btnNext.setAction(actNext); Action actClose = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { getTab().dispose(); } }; KeyBindingProvider.bindActionToComponent(KeyBindingProvider.CLOSE_CHILD, actClose, pnlCollect); if (getResultPanel() != null && getResultTable() != null) { final JButton btnEdit = getResultPanel().btnEdit; KeyBindingProvider.bindActionToComponent(KeyBindingProvider.EDIT_1, btnEdit.getAction(), getResultTable()); if (getResultTable().getActionMap().get(KeyBindingProvider.EDIT_2.getKey()) == null) KeyBindingProvider.bindActionToComponent(KeyBindingProvider.EDIT_2, btnEdit.getAction(), getResultTable()); } }
From source file:studio.ui.Studio.java
public void onData(DataEvent<?> event) { if (event instanceof TabIndexChanged && event.getSource() instanceof CloseTabbedPane) { rebuildMenus((TabIndexChanged) event); if (event.getSource() instanceof EditorsTabbedPane && ((EditorsTabbedPane) event.getSource()).getTabCount() > 0) { if (((TabIndexChanged) event).getData() > -1) { Editor editor = ((EditorsTabbedPane) event.getSource()) .getEditor(((TabIndexChanged) event).getData()); if (editor != null) { setTitle(AppInformation.getInformation().getTitle() + editor.getTitle()); ((EditorsTabbedPane) event.getSource()).setTitleAt(((TabIndexChanged) event).getData(), editor.getName(true)); ((EditorsTabbedPane) event.getSource()) .setToolTipTextAt(((TabIndexChanged) event).getData(), editor.getTooltip()); }/* w w w.j av a2 s.c o m*/ } else { setTitle(AppInformation.getInformation().getTitle()); } } else { setTitle(AppInformation.getInformation().getTitle()); } } else { if (event instanceof TabCountChanged) { if (event.getSource() instanceof ConsolesTabbedPane) { splitViewer.setDividerSize(((TabCountChanged) event).getData() == 1 ? 9 : 0); splitViewer.setDividerLocation(((TabCountChanged) event).getData() == 1 ? .7d : 1d); } } else { if (event instanceof EditorClosed) { if (event.getSource() instanceof EditorsTabbedPane) { EditorsTabbedPane tabEditors = (EditorsTabbedPane) event.getSource(); if (tabEditors.getTabCount() == 0) { ToolBarActions toolBar = appToolbar.getToolBar("File"); for (int count = 0; count < toolBar.getComponentCount(); count++) { if (toolBar.getComponent(count) instanceof JButton) { JButton button = (JButton) toolBar.getComponent(count); if (button.getAction() instanceof CloseAction) { button.getAction().setEnabled(false); } else { if (button.getAction() instanceof SaveAction) { button.getAction().setEnabled(false); } } } } toolBar = appToolbar.getToolBar("Edit"); for (int count = 0; count < toolBar.getComponentCount(); count++) { if (toolBar.getComponent(count) instanceof JButton) { JButton button = (JButton) toolBar.getComponent(count); if (button.getAction().isEnabled()) { button.getAction().setEnabled(false); } } } } } } } } }