List of usage examples for javax.swing AbstractButton addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:org.esa.snap.rcp.spectrum.SpectrumTopComponent.java
private void initUI() { final JFreeChart chart = ChartFactory.createXYLineChart(Bundle.CTL_SpectrumTopComponent_Name(), "Wavelength (nm)", "", null, PlotOrientation.VERTICAL, true, true, false); chart.getXYPlot().getRangeAxis().addChangeListener(axisChangeEvent -> { if (!isCodeInducedAxisChange) { rangeAxisAdjustmentIsFrozen = !((ValueAxis) axisChangeEvent.getAxis()).isAutoRange(); }/*from w ww .j av a 2 s . com*/ }); chart.getXYPlot().getDomainAxis().addChangeListener(axisChangeEvent -> { if (!isCodeInducedAxisChange) { domainAxisAdjustmentIsFrozen = !((ValueAxis) axisChangeEvent.getAxis()).isAutoRange(); } }); chart.getXYPlot().getRangeAxis().setAutoRange(false); rangeAxisAdjustmentIsFrozen = false; chart.getXYPlot().getDomainAxis().setAutoRange(false); domainAxisAdjustmentIsFrozen = false; chartPanel = new ChartPanel(chart); chartHandler = new ChartHandler(chart); final XYPlotMarker plotMarker = new XYPlotMarker(chartPanel, new XYPlotMarker.Listener() { @Override public void pointSelected(XYDataset xyDataset, int seriesIndex, Point2D dataPoint) { //do nothing } @Override public void pointDeselected() { //do nothing } }); filterButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Filter24.gif"), false); filterButton.setName("filterButton"); filterButton.setEnabled(false); filterButton.addActionListener(e -> { selectSpectralBands(); recreateChart(); }); showSpectrumForCursorButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/CursorSpectrum24.gif"), true); showSpectrumForCursorButton.addActionListener(e -> recreateChart()); showSpectrumForCursorButton.setName("showSpectrumForCursorButton"); showSpectrumForCursorButton.setSelected(true); showSpectrumForCursorButton.setToolTipText("Show spectrum at cursor position."); showSpectraForSelectedPinsButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/SelectedPinSpectra24.gif"), true); showSpectraForSelectedPinsButton.addActionListener(e -> { if (isShowingSpectraForAllPins()) { showSpectraForAllPinsButton.setSelected(false); } else if (!isShowingSpectraForSelectedPins()) { plotMarker.setInvisible(); } recreateChart(); }); showSpectraForSelectedPinsButton.setName("showSpectraForSelectedPinsButton"); showSpectraForSelectedPinsButton.setToolTipText("Show spectra for selected pins."); showSpectraForAllPinsButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/PinSpectra24.gif"), true); showSpectraForAllPinsButton.addActionListener(e -> { if (isShowingSpectraForSelectedPins()) { showSpectraForSelectedPinsButton.setSelected(false); } else if (!isShowingSpectraForAllPins()) { plotMarker.setInvisible(); } recreateChart(); }); showSpectraForAllPinsButton.setName("showSpectraForAllPinsButton"); showSpectraForAllPinsButton.setToolTipText("Show spectra for all pins."); showGridButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/SpectrumGrid24.gif"), true); showGridButton.addActionListener(e -> chartHandler.setGridVisible(showGridButton.isSelected())); showGridButton.setName("showGridButton"); showGridButton.setToolTipText("Show diagram grid."); AbstractButton exportSpectraButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false); exportSpectraButton.addActionListener(new SpectraExportAction(this)); exportSpectraButton.setToolTipText("Export spectra to text file."); exportSpectraButton.setName("exportSpectraButton"); AbstractButton helpButton = ToolButtonFactory.createButton(new HelpAction(this), false); helpButton.setName("helpButton"); helpButton.setToolTipText("Help."); final JPanel buttonPane = GridBagUtils.createPanel(); final GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.insets.top = 2; gbc.gridy = 0; buttonPane.add(filterButton, gbc); gbc.gridy++; buttonPane.add(showSpectrumForCursorButton, gbc); gbc.gridy++; buttonPane.add(showSpectraForSelectedPinsButton, gbc); gbc.gridy++; buttonPane.add(showSpectraForAllPinsButton, gbc); gbc.gridy++; buttonPane.add(showGridButton, gbc); gbc.gridy++; buttonPane.add(exportSpectraButton, gbc); gbc.gridy++; gbc.insets.bottom = 0; gbc.fill = GridBagConstraints.VERTICAL; gbc.weighty = 1.0; gbc.gridwidth = 2; buttonPane.add(new JLabel(" "), gbc); // filler gbc.fill = GridBagConstraints.NONE; gbc.weighty = 0.0; gbc.gridy = 10; gbc.anchor = GridBagConstraints.EAST; buttonPane.add(helpButton, gbc); chartPanel.setPreferredSize(new Dimension(300, 200)); chartPanel.setBackground(Color.white); chartPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createBevelBorder(BevelBorder.LOWERED), BorderFactory.createEmptyBorder(2, 2, 2, 2))); chartPanel.addChartMouseListener(plotMarker); JPanel mainPane = new JPanel(new BorderLayout(4, 4)); mainPane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPane.add(BorderLayout.CENTER, chartPanel); mainPane.add(BorderLayout.EAST, buttonPane); mainPane.setPreferredSize(new Dimension(320, 200)); SnapApp.getDefault().getProductManager().addListener(new ProductManager.Listener() { @Override public void productAdded(ProductManager.Event event) { // ignored } @Override public void productRemoved(ProductManager.Event event) { final Product product = event.getProduct(); if (getCurrentProduct() == product) { chartPanel.getChart().getXYPlot().setDataset(null); setCurrentView(null); setCurrentProduct(null); } if (currentView != null) { final RasterDataNode currentRaster = currentView.getRaster(); if (rasterToSpectraMap.containsKey(currentRaster)) { rasterToSpectraMap.remove(currentRaster); } if (rasterToSpectralBandsMap.containsKey(currentRaster)) { rasterToSpectralBandsMap.remove(currentRaster); } } PlacemarkGroup pinGroup = product.getPinGroup(); for (int i = 0; i < pinGroup.getNodeCount(); i++) { chartHandler.removePinInformation(pinGroup.get(i)); } } }); final ProductSceneView view = getSelectedProductSceneView(); if (view != null) { productSceneViewSelected(view); } setDisplayName(Bundle.CTL_SpectrumTopComponent_Name()); setLayout(new BorderLayout()); add(mainPane, BorderLayout.CENTER); updateUIState(); }
From source file:SoundManagerTest.java
/** * Creates a button (either JButton or JToggleButton). *//*from w ww.ja v a 2 s. c o m*/ public AbstractButton createButton(String name, boolean canToggle) { AbstractButton button; if (canToggle) { button = new JToggleButton(name); } else { button = new JButton(name); } button.addActionListener(this); button.setIgnoreRepaint(true); button.setFocusable(false); return button; }
From source file:org.esa.beam.visat.toolviews.spectrum.SpectrumToolView.java
@Override public JComponent createControl() { final JFreeChart chart = ChartFactory.createXYLineChart(CHART_TITLE, "Wavelength (nm)", "", null, PlotOrientation.VERTICAL, true, true, false); chart.getXYPlot().getRangeAxis().addChangeListener(new AxisChangeListener() { @Override/* w ww . ja va 2 s .c o m*/ public void axisChanged(AxisChangeEvent axisChangeEvent) { if (!isCodeInducedAxisChange) { rangeAxisAdjustmentIsFrozen = !((ValueAxis) axisChangeEvent.getAxis()).isAutoRange(); } } }); chart.getXYPlot().getDomainAxis().addChangeListener(new AxisChangeListener() { @Override public void axisChanged(AxisChangeEvent axisChangeEvent) { if (!isCodeInducedAxisChange) { domainAxisAdjustmentIsFrozen = !((ValueAxis) axisChangeEvent.getAxis()).isAutoRange(); } } }); chart.getXYPlot().getRangeAxis().setAutoRange(false); rangeAxisAdjustmentIsFrozen = false; chart.getXYPlot().getDomainAxis().setAutoRange(false); domainAxisAdjustmentIsFrozen = false; chartPanel = new ChartPanel(chart); chartHandler = new ChartHandler(chart); final XYPlotMarker plotMarker = new XYPlotMarker(chartPanel, new XYPlotMarker.Listener() { @Override public void pointSelected(XYDataset xyDataset, int seriesIndex, Point2D dataPoint) { if (hasDiagram()) { if (cursorSynchronizer == null) { cursorSynchronizer = new CursorSynchronizer(VisatApp.getApp()); } if (!cursorSynchronizer.isEnabled()) { cursorSynchronizer.setEnabled(true); } } } @Override public void pointDeselected() { cursorSynchronizer.setEnabled(false); } }); titleBase = getDescriptor().getTitle(); filterButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Filter24.gif"), false); filterButton.setName("filterButton"); filterButton.setEnabled(false); filterButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectSpectralBands(); recreateChart(); } }); showSpectrumForCursorButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/CursorSpectrum24.gif"), true); showSpectrumForCursorButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { recreateChart(); } }); showSpectrumForCursorButton.setName("showSpectrumForCursorButton"); showSpectrumForCursorButton.setSelected(true); showSpectrumForCursorButton.setToolTipText("Show spectrum at cursor position."); showSpectraForSelectedPinsButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/SelectedPinSpectra24.gif"), true); showSpectraForSelectedPinsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (isShowingSpectraForAllPins()) { showSpectraForAllPinsButton.setSelected(false); } else if (!isShowingSpectraForSelectedPins()) { plotMarker.setInvisible(); } recreateChart(); } }); showSpectraForSelectedPinsButton.setName("showSpectraForSelectedPinsButton"); showSpectraForSelectedPinsButton.setToolTipText("Show spectra for selected pins."); showSpectraForAllPinsButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/PinSpectra24.gif"), true); showSpectraForAllPinsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (isShowingSpectraForSelectedPins()) { showSpectraForSelectedPinsButton.setSelected(false); } else if (!isShowingSpectraForAllPins()) { plotMarker.setInvisible(); } recreateChart(); } }); showSpectraForAllPinsButton.setName("showSpectraForAllPinsButton"); showSpectraForAllPinsButton.setToolTipText("Show spectra for all pins."); // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007) // showAveragePinSpectrumButton = ToolButtonFactory.createButton( // UIUtils.loadImageIcon("icons/AverageSpectrum24.gif"), true); // showAveragePinSpectrumButton.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent e) { // // todo - implement // } // }); // showAveragePinSpectrumButton.setName("showAveragePinSpectrumButton"); // showAveragePinSpectrumButton.setToolTipText("Show average spectrum of all pin spectra."); showGridButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/SpectrumGrid24.gif"), true); showGridButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { chartHandler.setGridVisible(showGridButton.isSelected()); } }); showGridButton.setName("showGridButton"); showGridButton.setToolTipText("Show diagram grid."); // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007) // showGraphPointsButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/GraphPoints24.gif"), true); // showGraphPointsButton.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent e) { // // todo - implement // JOptionPane.showMessageDialog(null, "Not implemented"); // } // }); // showGraphPointsButton.setName("showGraphPointsButton"); // showGraphPointsButton.setToolTipText("Show graph points grid."); AbstractButton exportSpectraButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false); exportSpectraButton.addActionListener(new SpectraExportAction(this)); exportSpectraButton.setToolTipText("Export spectra to text file."); exportSpectraButton.setName("exportSpectraButton"); AbstractButton helpButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Help22.png"), false); helpButton.setName("helpButton"); helpButton.setToolTipText("Help."); /*I18N*/ final JPanel buttonPane = GridBagUtils.createPanel(); final GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.insets.top = 2; gbc.gridy = 0; buttonPane.add(filterButton, gbc); gbc.gridy++; buttonPane.add(showSpectrumForCursorButton, gbc); gbc.gridy++; buttonPane.add(showSpectraForSelectedPinsButton, gbc); gbc.gridy++; buttonPane.add(showSpectraForAllPinsButton, gbc); gbc.gridy++; // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007) // buttonPane.add(showAveragePinSpectrumButton, gbc); // gbc.gridy++; buttonPane.add(showGridButton, gbc); gbc.gridy++; // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007) // buttonPane.add(showGraphPointsButton, gbc); // gbc.gridy++; buttonPane.add(exportSpectraButton, gbc); gbc.gridy++; gbc.insets.bottom = 0; gbc.fill = GridBagConstraints.VERTICAL; gbc.weighty = 1.0; gbc.gridwidth = 2; buttonPane.add(new JLabel(" "), gbc); // filler gbc.fill = GridBagConstraints.NONE; gbc.weighty = 0.0; gbc.gridy = 10; gbc.anchor = GridBagConstraints.EAST; buttonPane.add(helpButton, gbc); chartPanel.setPreferredSize(new Dimension(300, 200)); chartPanel.setBackground(Color.white); chartPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createBevelBorder(BevelBorder.LOWERED), BorderFactory.createEmptyBorder(2, 2, 2, 2))); chartPanel.addChartMouseListener(plotMarker); JPanel mainPane = new JPanel(new BorderLayout(4, 4)); mainPane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPane.add(BorderLayout.CENTER, chartPanel); mainPane.add(BorderLayout.EAST, buttonPane); mainPane.setPreferredSize(new Dimension(320, 200)); if (getDescriptor().getHelpId() != null) { HelpSys.enableHelpOnButton(helpButton, getDescriptor().getHelpId()); HelpSys.enableHelpKey(mainPane, getDescriptor().getHelpId()); } // Add an internal frame listener to VISAT so that we can update our // spectrum dialog with the information of the currently activated // product scene view. // VisatApp.getApp().addInternalFrameListener(new SpectrumIFL()); VisatApp.getApp().getProductManager().addListener(new ProductManager.Listener() { @Override public void productAdded(ProductManager.Event event) { // ignored } @Override public void productRemoved(ProductManager.Event event) { final Product product = event.getProduct(); if (getCurrentProduct() == product) { chartPanel.getChart().getXYPlot().setDataset(null); setCurrentView(null); setCurrentProduct(null); } if (productToAllSpectraMap.containsKey(product)) { productToAllSpectraMap.remove(product); } if (productToBandsMap.containsKey(product)) { productToBandsMap.remove(product); } PlacemarkGroup pinGroup = product.getPinGroup(); for (int i = 0; i < pinGroup.getNodeCount(); i++) { chartHandler.removePinInformation(pinGroup.get(i)); } } }); final ProductSceneView view = VisatApp.getApp().getSelectedProductSceneView(); if (view != null) { handleViewActivated(view); } else { setCurrentView(view); } updateUIState(); return mainPane; }
From source file:org.esa.beam.visat.toolviews.stat.StatisticsPanel.java
private AbstractButton getExportButton() { final AbstractButton export = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false);// w w w .ja v a 2 s .c o m export.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPopupMenu viewPopup = new JPopupMenu("Export"); viewPopup.add(exportAsCsvAction); viewPopup.add(putStatisticsIntoVectorDataAction); final Rectangle buttonBounds = export.getBounds(); viewPopup.show(export, 1, buttonBounds.height + 1); } }); export.setEnabled(false); return export; }
From source file:org.nuclos.client.ui.collect.Chart.java
public void addToolbarFunction(String actionCommand, AbstractButton button, JMenuItem mi, int pos) { if (toolbarButtons.containsKey(actionCommand)) toolbar.remove(toolbarButtons.get(actionCommand)); toolbarButtons.put(actionCommand, button); button.setActionCommand(actionCommand); button.addActionListener(this); toolbar.add(button, pos);/*from w ww .ja v a 2 s. c o m*/ toolbar.validate(); if (toolbarMenuItems.containsKey(actionCommand)) toolbarOrder.remove(actionCommand); toolbarMenuItems.put(actionCommand, mi); mi.setActionCommand(actionCommand); mi.addActionListener(this); toolbarOrder.add(pos, actionCommand); }
From source file:org.nuclos.client.ui.collect.Chart.java
/** * @param entityName/* w ww . j a va 2s . co m*/ * @param toolBarOrientation @see JToolbar#setOrientation * @param foreignKeyFieldToParent Needs only be specified if not unique. @see #getForeignKeyFieldToParent() * @precondition entityName != null * @postcondition this.getForeignKeyFieldToParent() == foreignKeyFieldToParent */ public Chart(String entityName, int iScrollPane, int toolBarOrientation, String foreignKeyFieldToParent, boolean bFromProperties, boolean bSearchable) { super(new GridLayout(1, 1)); this.bFromProperties = bFromProperties; this.bSearchable = bSearchable; this.subform = new SubForm(entityName, -1, foreignKeyFieldToParent, bFromProperties) { private TableModelListener tblmdllistener; public void setupTableModelListener() { // set all columns visble. if (!(getSubformTable().getModel() instanceof CollectableTableModel<?>)) return; CollectableEntity colEntity = DefaultCollectableEntityProvider.getInstance() .getCollectableEntity(subform.getEntityName()); List<CollectableEntityField> lstclctefColumns = new ArrayList<CollectableEntityField>(); for (String sFieldName : colEntity.getFieldNames()) { if (!sFieldName.equalsIgnoreCase("genericObject")) lstclctefColumns.add(colEntity.getEntityField(sFieldName)); } ((CollectableTableModel<?>) getSubformTable().getModel()).setColumns(lstclctefColumns); this.tblmdllistener = new TableModelListener() { boolean enabled = Chart.this.isEnabled(); @Override public void tableChanged(TableModelEvent ev) { Chart.this.setEnabled( (subform.getJTable().getModel() instanceof SearchConditionTableModelImpl) ? false : enabled); String type = getProperty(PROPERTY_TYPE, String.class); if (type != null) { JFreeChart chart = ChartFunction.valueOf(type).createChart(Chart.this); panel.setChart(chart); panel.repaint(); } } }; getSubformTable().getModel().addTableModelListener(this.tblmdllistener); } public void removeTableModelListener() { getSubformTable().getModel().removeTableModelListener(this.tblmdllistener); this.tblmdllistener = null; } }; if (iScrollPane != -1) { this.scrollPane = new JScrollPane(); } else this.scrollPane = new JPanel(new BorderLayout()); this.toolbar = UIUtils.createNonFloatableToolBar(toolBarOrientation); this.listeners = new ArrayList<ChartToolListener>(); if (entityName == null) { throw new NullArgumentException("entityName"); } this.entityName = entityName; String sDataSource = entityName.substring(MasterDataMetaVO.CHART_ENTITY_PREFIX.length()).toLowerCase(); try { DatasourceVO datasourceVO = DatasourceDelegate.getInstance().getChartByName(sDataSource); if (datasourceVO != null) { final List<DatasourceParameterVO> lstParams = DatasourceDelegate.getInstance() .getParametersFromXML(datasourceVO.getSource()); for (Iterator iterator = lstParams.iterator(); iterator.hasNext();) { DatasourceParameterVO datasourceParameterVO = (DatasourceParameterVO) iterator.next(); if (datasourceParameterVO.getParameter().equals("genericObject")) iterator.remove(); } if (!lstParams.isEmpty() && !bSearchable && !bFromProperties) { JPanel pnl = new JPanel(new BorderLayout()); ParameterPanel pnlParameters = new ParameterPanel(lstParams, new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (e != null && e.getSource() instanceof ParameterPanel) { try { Map<String, Object> mpParams = new HashMap<String, Object>(); ((ParameterPanel) e.getSource()).fillParameterMap(lstParams, mpParams); subform.setMapParams(mpParams); } catch (Exception e2) { //ignore. } } } }); pnl.add(pnlParameters, BorderLayout.NORTH); JSplitPane splitPane = new JSplitPane( toolBarOrientation == -1 ? JSplitPane.VERTICAL_SPLIT : toolBarOrientation, pnl, scrollPane); contentPane.add(splitPane, BorderLayout.CENTER); } else contentPane.add(scrollPane, BorderLayout.CENTER); } else { contentPane.add(scrollPane, BorderLayout.CENTER); } } catch (Exception e) { throw new NuclosFatalException("init failed for datasource " + sDataSource, e); } if (toolBarOrientation == -1) { this.toolbar.setVisible(false); } else { this.toolbar.setOrientation(toolBarOrientation); } this.foreignKeyFieldToParent = foreignKeyFieldToParent; layer = new JXLayer<JComponent>(contentPane, new TranslucentLockableUI()); layer.setName("JXLayerGlasspane"); add(layer); this.init(iScrollPane); toolbarButtons = new HashMap<String, AbstractButton>(); toolbarMenuItems = new HashMap<String, JMenuItem>(); toolbarOrder = new ArrayList<String>(); for (ToolbarFunction func : ToolbarFunction.values()) { AbstractButton button = func.createButton(); JMenuItem mi = func.createMenuItem(); toolbarButtons.put(func.name(), button); toolbarMenuItems.put(func.name(), mi); toolbar.add(button); if (func.equals(ToolbarFunction.PRINT)) { button.addActionListener(panel); mi.addActionListener(panel); } else { button.addActionListener(this); mi.addActionListener(this); } toolbarOrder.add(func.name()); } subform.setReadOnly(true); setEnabled(!bFromProperties && !bSearchable); addChartToolListener(new ChartToolListener() { @Override public void toolbarAction(String actionCommand) { if (actionCommand.equals(ToolbarFunction.SHOW.name())) { actionCommandShow(); } else if (actionCommand.equals(ToolbarFunction.SAVE.name())) { actionCommandSave(); } } }); assert this.getForeignKeyFieldToParent() == foreignKeyFieldToParent; }
From source file:org.nuclos.client.ui.collect.SubForm.java
/** * @param entityName// w ww . j a va 2 s . c o m * @param toolBarOrientation @see JToolbar#setOrientation * @param foreignKeyFieldToParent Needs only be specified if not unique. @see #getForeignKeyFieldToParent() * @precondition entityName != null * @postcondition this.getForeignKeyFieldToParent() == foreignKeyFieldToParent */ public SubForm(String entityName, int toolBarOrientation, String foreignKeyFieldToParent, boolean bLayout) { super(new GridLayout(1, 1)); this.rowHeightCtrl = new RowHeightController(this); this.bLayout = bLayout; this.toolbar = UIUtils.createNonFloatableToolBar(toolBarOrientation); this.listeners = new ArrayList<SubFormToolListener>(); subformtbl = new SubFormTable(this) { protected void configureEnclosingScrollPane() { super.configureEnclosingScrollPane(); if (getSubFormFilter() != null) { getSubFormFilter().setupTableHeaderForScrollPane(scrollPane); } } }; subformtbl.addMouseListener(new SubFormPopupMenuMouseAdapter(subformtbl)); subformtbl.addMouseListener(new DoubleClickMouseAdapter()); subformtbl.addMouseMotionListener(new URIMouseAdapter()); subformtbl.addMouseListener(new URIMouseAdapter()); contentPane.add(scrollPane, BorderLayout.CENTER); if (entityName == null) { throw new NullArgumentException("entityName"); } this.entityName = entityName; if (toolBarOrientation == -1) { this.toolbar.setVisible(false); } else { this.toolbar.setOrientation(toolBarOrientation); } this.foreignKeyFieldToParent = foreignKeyFieldToParent; this.collectableComponentFactory = CollectableComponentFactory.getInstance(); layer = new JXLayer<JComponent>(contentPane, new TranslucentLockableUI()); layer.setName("JXLayerGlasspane"); add(layer); toolbarButtons = new HashMap<String, AbstractButton>(); toolbarMenuItems = new HashMap<String, JMenuItem>(); toolbarOrder = new ArrayList<String>(); for (ToolbarFunction func : ToolbarFunction.values()) { AbstractButton button = func.createButton(); JMenuItem mi = func.createMenuItem(); toolbarButtons.put(func.name(), button); toolbarMenuItems.put(func.name(), mi); toolbar.add(button); button.addActionListener(this); mi.addActionListener(this); toolbarOrder.add(func.name()); } setToolbarFunctionState(ToolbarFunction.REMOVE, ToolbarFunctionState.DISABLED); setToolbarFunctionState(ToolbarFunction.MULTIEDIT, ToolbarFunctionState.HIDDEN); setToolbarFunctionState(ToolbarFunction.DOCUMENTIMPORT, ToolbarFunctionState.HIDDEN); setToolbarFunctionState(ToolbarFunction.FILTER, ToolbarFunctionState.HIDDEN); this.init(); assert this.getForeignKeyFieldToParent() == foreignKeyFieldToParent; }
From source file:org.openmicroscopy.shoola.agents.imviewer.util.player.MoviePlayerControl.java
/** Adds an {@link ActionListener} to an {@link AbstractButton}. * /*from www .j av a2 s .com*/ * @param button The component to attach the listener to. * @param id The action command ID. */ private void attachButtonListener(AbstractButton button, int id) { button.addActionListener(this); button.setActionCommand("" + id); }
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./* www.j ava 2s .com*/ * @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.photovault.swingui.framework.AbstractController.java
/** * Register an action that can be executed by this controller. * * @param source The source component, this method sets action command and registers the controller as listener. * @param actionCommand The action command, used as a key when registering and executing actions. * @param action An actual action implementation. *//* w w w . j a va 2 s.co m*/ public void registerAction(AbstractButton source, String actionCommand, DefaultAction action) { source.setActionCommand(actionCommand); source.addActionListener(this); this.actions.put(actionCommand, action); final String cmd = actionCommand; final AbstractController ctrl = this; // TODO: Is this really needed??? action.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("enabled")) { fireEvent(new ActionStateChangeEvent(ctrl, cmd, (Boolean) evt.getNewValue())); } } }); }