Java Code Examples for javax.swing.AbstractButton#addActionListener()

The following examples show how to use javax.swing.AbstractButton#addActionListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StationRadialPanel.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *
 */
public StationRadialPanel(PreferencesExt dbPrefs) {
  super(dbPrefs, "dataset:", true, false);
  radialViewer = new StationRadialViewer(dbPrefs);
  add(radialViewer, BorderLayout.CENTER);

  AbstractButton infoButton = BAMutil.makeButtcon("Information", "Dataset Info", false);
  infoButton.addActionListener(e -> {
    if (radarCollectionDataset != null) {
      Formatter info = new Formatter();
      radarCollectionDataset.getDetailInfo(info);
      detailTA.setText(info.toString());
      detailTA.gotoTop();
      detailWindow.show();
    }
  });
  buttPanel.add(infoButton);
}
 
Example 2
Source File: TemplateParameterEditorDialog.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private JPanel createParametersPanel() {
    JPanel paramsPanel = new JPanel();
    BoxLayout layout = new BoxLayout(paramsPanel, BoxLayout.PAGE_AXIS);
    paramsPanel.setLayout(layout);
    AbstractButton addParamBut = ToolButtonFactory.createButton(UIUtils.loadImageIcon("/org/esa/snap/resources/images/icons/Add16.png"), false);
    addParamBut.setAlignmentX(Component.LEFT_ALIGNMENT);
    paramsPanel.add(addParamBut);

    this.paramsTable =  new OperatorParametersTable(this.fakeOperatorDescriptor, appContext);
    JScrollPane tableScrollPane = new JScrollPane(paramsTable);
    tableScrollPane.setPreferredSize(new Dimension(500, 130));
    tableScrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
    paramsPanel.add(tableScrollPane);
    addParamBut.addActionListener((ActionEvent e) -> paramsTable.addParameterToTable());
    TitledBorder title = BorderFactory.createTitledBorder("Template Parameters");
    paramsPanel.setBorder(title);
    return paramsPanel;
}
 
Example 3
Source File: MultipleRoiComputePanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private AbstractButton createShowMaskManagerButton() {
    final AbstractButton showMaskManagerButton =
            ToolButtonFactory.createButton(ImageUtilities.loadImageIcon("org/esa/snap/rcp/icons/MaskManager24.png", false), false);
    showMaskManagerButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    final TopComponent maskManagerTopComponent = WindowManager.getDefault().findTopComponent("MaskManagerTopComponent");
                    maskManagerTopComponent.open();
                    maskManagerTopComponent.requestActive();
                }
            });
        }
    });
    return showMaskManagerButton;
}
 
Example 4
Source File: Hdf5DataPanel.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Hdf5DataPanel(PreferencesExt p, boolean useBuilders) {
  super(p, "file:", true, false);
  hdf5Table = useBuilders ? new Hdf5NewDataTable(prefs, buttPanel) : new Hdf5DataTable(prefs, buttPanel);
  add(hdf5Table, BorderLayout.CENTER);

  AbstractButton infoButton = BAMutil.makeButtcon("Information", "Detail Info", false);
  infoButton.addActionListener(e -> {
    Formatter f = new Formatter();
    try {
      hdf5Table.showInfo(f);
    } catch (IOException ioe) {
      StringWriter sw = new StringWriter(5000);
      ioe.printStackTrace(new PrintWriter(sw));
      detailTA.setText(sw.toString());
      detailWindow.show();
      return;
    }
    detailTA.setText(f.toString());
    detailTA.gotoTop();
    detailWindow.show();
  });
  buttPanel.add(infoButton);
}
 
Example 5
Source File: Utils.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the button passed in.
 */
private static void setupButton(AbstractButton button, URL icon, URL selectedIcon, String actionCommand, String tooltip, ActionListener listener){
	button.setActionCommand(actionCommand);
	
	
	button.setToolTipText(tooltip);
	button.addActionListener(listener);
	
	
	if(icon == null){
		// No icon, just set the text to the tooltip
		button.setText(tooltip);
	}else{
		Utils.setIcon(button, icon);
		// set a selected icon if it exists
		//String selectedPath = path.replaceAll(".png", "_selected.png");
		//if(new File(selectedPath).exists())
		if(selectedIcon!=null)
			button.setSelectedIcon(new ImageIcon(selectedIcon));
	}
}
 
Example 6
Source File: Hdf4Panel.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Hdf4Panel(PreferencesExt p, boolean useBuilders) {
  super(p, "file:", true, false);
  hdf4Table = useBuilders ? new Hdf4NewTable(prefs) : new Hdf4Table(prefs);
  add(hdf4Table, BorderLayout.CENTER);

  AbstractButton eosdump = BAMutil.makeButtcon("alien", "Show EOS processing", false);
  eosdump.addActionListener(e -> {
    try {
      Formatter f = new Formatter();
      hdf4Table.getEosInfo(f);
      detailTA.setText(f.toString());
      detailWindow.show();
    } catch (IOException ioe) {
      StringWriter sw = new StringWriter(5000);
      ioe.printStackTrace(new PrintWriter(sw));
      detailTA.setText(sw.toString());
      detailWindow.show();
    }
  });
  buttPanel.add(eosdump);
}
 
Example 7
Source File: GribFilesOpPanel.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *
 */
public GribFilesOpPanel(PreferencesExt p) {
  super(p, "collection:", true, false);
  gribTable = new GribFilesPanel(prefs);
  add(gribTable, BorderLayout.CENTER);
  gribTable.addPropertyChangeListener(new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent e) {
      if (e.getPropertyName().equals("openGrib1Collection")) {
        String filename = (String) e.getNewValue();
        ToolsUI.getToolsUI().openGrib1Collection(filename);
      }
    }
  });

  AbstractButton showButt = BAMutil.makeButtcon("Information", "Show Collection", false);
  showButt.addActionListener(e -> {
    Formatter f = new Formatter();
    gribTable.showCollection(f);
    detailTA.setText(f.toString());
    detailTA.gotoTop();
    detailWindow.show();
  });
  buttPanel.add(showButt);
}
 
Example 8
Source File: SourceProductList.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private AbstractButton createAddInputButton() {
    final AbstractButton addButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Plus24.gif"),
                                                                    false);
    addButton.addActionListener(e -> {
        final JPopupMenu popup = new JPopupMenu("Add");
        final Rectangle buttonBounds = addButton.getBounds();
        final AddProductAction addProductAction = new AddProductAction(appContext, listModel);
        addProductAction.setProductFilter(productFilter);
        popup.add(addProductAction);
        popup.add(new AddFileAction(appContext, listModel, propertyNameLastOpenInputDir, propertyNameLastOpenedFormat, propertyNameFormatNames));
        popup.add(new AddDirectoryAction(appContext, listModel, false, propertyNameLastOpenInputDir, defaultPattern));
        popup.add(new AddDirectoryAction(appContext, listModel, true, propertyNameLastOpenInputDir, defaultPattern));
        popup.show(addButton, 1, buttonBounds.height + 1);
    });
    return addButton;
}
 
Example 9
Source File: ChartPagePanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private JPanel createTopPanel() {
    refreshButton = ToolButtonFactory.createButton(
            UIUtils.loadImageIcon("icons/ViewRefresh22.png"),
            false);
    refreshButton.setToolTipText("Refresh View");
    refreshButton.setName("refreshButton");
    refreshButton.addActionListener(e -> {
        updateChartData();
        refreshButton.setEnabled(false);
    });

    AbstractButton switchToTableButton = ToolButtonFactory.createButton(
            UIUtils.loadImageIcon("icons/Table24.png"),
            false);
    switchToTableButton.setToolTipText("Switch to Table View");
    switchToTableButton.setName("switchToTableButton");
    switchToTableButton.setEnabled(hasAlternativeView());
    switchToTableButton.addActionListener(e -> showAlternativeView());

    final TableLayout tableLayout = new TableLayout(6);
    tableLayout.setColumnFill(2, TableLayout.Fill.HORIZONTAL);
    tableLayout.setColumnWeightX(2, 1.0);
    tableLayout.setRowPadding(0, new Insets(0, 4, 0, 0));
    JPanel buttonPanel = new JPanel(tableLayout);
    buttonPanel.add(refreshButton);
    tableLayout.setRowPadding(0, new Insets(0, 0, 0, 0));
    buttonPanel.add(switchToTableButton);
    buttonPanel.add(new JPanel());

    return buttonPanel;
}
 
Example 10
Source File: TimeSeriesPlayerForm.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private AbstractButton createPlusButton() {
    final AbstractButton plusButton = ToolButtonFactory.createButton(plusIcon, false);
    plusButton.setToolTipText("Increase playing speed");
    plusButton.addActionListener(e -> {
        if (speedSlider.getValue() < speedSlider.getMaximum()) {
            speedSlider.setValue(speedSlider.getValue() + 1);
        }
    });
    return plusButton;
}
 
Example 11
Source File: TitledPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private JComponent getCollapseButton(JComponent bodyComponent, boolean isInitiallyCollapsed) {
    final AbstractButton hideAndShowButton;
    if (isInitiallyCollapsed) {
        hideAndShowButton = ToolButtonFactory.createButton(CollapseSupport.expandIcon, false);
        hideAndShowButton.setRolloverIcon(CollapseSupport.expandRolloverIcon);
        hideAndShowButton.setToolTipText("Expand Panel");
    } else {
        hideAndShowButton = ToolButtonFactory.createButton(CollapseSupport.collapseIcon, false);
        hideAndShowButton.setRolloverIcon(CollapseSupport.collapseRolloverIcon);
        hideAndShowButton.setToolTipText("Collapse Panel");
    }
    hideAndShowButton.addActionListener(new CollapseSupport(isInitiallyCollapsed, bodyComponent, hideAndShowButton));

    return hideAndShowButton;
}
 
Example 12
Source File: TimeSeriesPlayerForm.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private AbstractButton createStopButton() {
    final AbstractButton stopButton = ToolButtonFactory.createButton(stopIcon, false);
    stopButton.setToolTipText("Stop playing the time series");
    stopButton.addActionListener(e -> {
        timer.stop();
        timeSlider.setValue(0);
        playButton.setIcon(playIcon);
        playButton.setRolloverIcon(playIcon);
        playButton.setSelected(false);
    });
    return stopButton;
}
 
Example 13
Source File: MosaicExpressionsPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private Component createNewVariableButton() {
    AbstractButton newVariableButton = createButton("icons/Plus24.gif", "newVariable");
    newVariableButton.setToolTipText("Add new processing variable"); /*I18N*/
    newVariableButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final int rows = variablesTable.getRowCount();
            addRow(variablesTable, new Object[]{"variable_" + rows, ""}); /*I18N*/
        }
    });
    return newVariableButton;
}
 
Example 14
Source File: MosaicExpressionsPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private Component createMoveConditionDownButton() {
    AbstractButton moveConditionDownButton = createButton("icons/MoveDown24.gif", "moveConditionDown");
    moveConditionDownButton.setToolTipText("Move down selected rows."); /*I18N*/
    moveConditionDownButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            moveRowsDown(conditionsTable, conditionsTable.getSelectedRows());
        }
    });
    return moveConditionDownButton;
}
 
Example 15
Source File: TimeSeriesPlayerForm.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
TimeSeriesPlayerForm(String helpId) {
        this.setLayout(new BorderLayout(4, 4));
        this.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
        this.setPreferredSize(new Dimension(350, 200));
        JPanel firstPanel = new JPanel(createLayout());
        firstPanel.setPreferredSize(new Dimension(300, 150));
        final JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
        final JPanel secondPanel = new JPanel(new BorderLayout());
//        BoxLayout boxLayout = new BoxLayout(secondPanel, BoxLayout.Y_AXIS);
//        secondPanel.setLayout(boxLayout);

        dateLabel = new JLabel("Date: ");
        timeSlider = createTimeSlider();
        playButton = createPlayButton();
        stopButton = createStopButton();
        repeatButton = createRepeatButton();
        blendButton = createBlendButton();
        speedLabel = new JLabel("Speed:");
        minusButton = createMinusButton();
        speedSlider = createSpeedSlider();
        speedUnit = new JLabel();
        plusButton = createPlusButton();
        exportButton = createExportButton();

        AbstractButton helpButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Help22.png"), false);
        helpButton.setToolTipText("Help");
        helpButton.addActionListener(e -> new HelpCtx(helpId).display());
        updateSpeedUnit();
        setUIEnabled(false);

        buttonsPanel.add(playButton);
        buttonsPanel.add(stopButton);
        buttonsPanel.add(repeatButton);
        buttonsPanel.add(new JSeparator(JSeparator.VERTICAL));
        buttonsPanel.add(blendButton);
        buttonsPanel.add(new JSeparator(JSeparator.VERTICAL));
        buttonsPanel.add(speedLabel);
        buttonsPanel.add(minusButton);
        buttonsPanel.add(speedSlider);
        buttonsPanel.add(plusButton);
        buttonsPanel.add(speedUnit);
        buttonsPanel.add(new JLabel("           "));
        secondPanel.add(exportButton, BorderLayout.NORTH);
        secondPanel.add(helpButton, BorderLayout.SOUTH);

        firstPanel.add(dateLabel);
        firstPanel.add(timeSlider);
        firstPanel.add(buttonsPanel);

        this.add(BorderLayout.CENTER, firstPanel);
        this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
        this.add(BorderLayout.EAST, secondPanel);
    }
 
Example 16
Source File: PauseAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    final AbstractButton suspendIOButton = new JToggleButton();
    Actions.connect(suspendIOButton, this);
    updateButton(suspendIOButton);
    final class Controller implements Runnable, ActionListener {
        private RequestProcessor.Task updateTask;
        
        Controller() {
            updateTask = RP.create(this);
            scheduleUpdate(0);
        }
        
        @Override
        public void run() {
            if (!EventQueue.isDispatchThread()) {
                EventQueue.invokeLater(this);
                return;
            }
            if (!suspendIOButton.isShowing()) {
                return;
            }
            updateButton(suspendIOButton);
            scheduleUpdate(0);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            updateButton(suspendIOButton);
            run();
            scheduleUpdate(100);
        }

        private void scheduleUpdate(int time) {
            if (time == 0) {
                time = 1500;
            }
            updateTask.schedule(time);
        }
    }
    Controller c = new Controller();
    suspendIOButton.addActionListener(c);
    
    return suspendIOButton;
}
 
Example 17
Source File: SlideGestureRecognizer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Attaches given button to this recognizer, it means starts listening
 * on its various mouse and action events
 */
public void attachButton (AbstractButton button) {
    button.addActionListener(this);
    button.addMouseListener(this);
    button.addMouseMotionListener(this);
}
 
Example 18
Source File: PixelExtractionParametersForm.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private JComponent[] createCoordinatesComponents() {
    Product selectedProduct = appContext.getSelectedProduct();
    if (selectedProduct != null) {
        final PlacemarkGroup pinGroup = selectedProduct.getPinGroup();
        for (int i = 0; i < pinGroup.getNodeCount(); i++) {
            coordinateTableModel.addPlacemark(pinGroup.get(i));
        }
    }

    JTable coordinateTable = new JTable(coordinateTableModel);
    coordinateTable.setName("coordinateTable");
    coordinateTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    coordinateTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    coordinateTable.setRowSelectionAllowed(true);
    coordinateTable.getTableHeader().setReorderingAllowed(false);
    coordinateTable.setDefaultRenderer(Double.class, new DecimalTableCellRenderer(new DecimalFormat("0.0000")));
    coordinateTable.setPreferredScrollableViewportSize(new Dimension(250, 100));
    coordinateTable.getColumnModel().getColumn(1).setCellEditor(new DecimalCellEditor(-90, 90));
    coordinateTable.getColumnModel().getColumn(2).setCellEditor(new DecimalCellEditor(-180, 180));

    final DateFormat dateFormat = ProductData.UTC.createDateFormat("yyyy-MM-dd'T'HH:mm:ss"); // ISO 8601
    final DateFormat timeFormat = ProductData.UTC.createDateFormat("HH:mm:ss"); // ISO 8601
    DateTimePickerCellEditor cellEditor = new DateTimePickerCellEditor(dateFormat, timeFormat);
    cellEditor.setClickCountToStart(1);
    coordinateTable.getColumnModel().getColumn(3).setCellEditor(cellEditor);
    coordinateTable.getColumnModel().getColumn(3).setPreferredWidth(200);
    final DateCellRenderer dateCellRenderer = new DateCellRenderer(dateFormat);
    dateCellRenderer.setHorizontalAlignment(SwingConstants.RIGHT);
    coordinateTable.getColumnModel().getColumn(3).setCellRenderer(dateCellRenderer);
    final JScrollPane rasterScrollPane = new JScrollPane(coordinateTable);

    final AbstractButton addButton = ToolButtonFactory.createButton(ADD_ICON, false);
    addButton.addActionListener(new AddPopupListener());
    final AbstractButton removeButton = ToolButtonFactory.createButton(REMOVE_ICON, false);
    removeButton.addActionListener(new RemovePlacemarksListener(coordinateTable, coordinateTableModel));
    final JPanel buttonPanel = new JPanel();
    final BoxLayout layout = new BoxLayout(buttonPanel, BoxLayout.Y_AXIS);
    buttonPanel.setLayout(layout);
    buttonPanel.add(addButton);
    buttonPanel.add(removeButton);
    return new JComponent[]{rasterScrollPane, buttonPanel};
}
 
Example 19
Source File: ToolAdapterTabbedEditorDialog.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected JPanel createVariablesPanel() {
    JPanel variablesBorderPanel = new JPanel();
    BoxLayout layout = new BoxLayout(variablesBorderPanel, BoxLayout.PAGE_AXIS);
    variablesBorderPanel.setLayout(layout);

    AbstractButton addVariableButton =
            ToolButtonFactory.createButton(UIUtils.loadImageIcon(Bundle.Icon_Add()), false);
    addVariableButton.setText(Bundle.CTL_Button_Add_Variable_Text());
    addVariableButton.setMaximumSize(new Dimension(150, controlHeight));
    addVariableButton.setAlignmentX(Component.LEFT_ALIGNMENT);

    AbstractButton addDependentVariableButton =
            ToolButtonFactory.createButton(UIUtils.loadImageIcon(Bundle.Icon_Add()), false);
    addDependentVariableButton.setText(Bundle.CTL_Button_Add_PDVariable_Text());
    addDependentVariableButton.setMaximumSize(new Dimension(250, controlHeight));
    addDependentVariableButton.setAlignmentX(Component.LEFT_ALIGNMENT);

    JPanel buttonsPannel = new JPanel(new SpringLayout());
    buttonsPannel.add(addVariableButton);
    buttonsPannel.add(addDependentVariableButton);
    SpringUtilities.makeCompactGrid(buttonsPannel, 1, 2, 0, 0, 0, 0);
    buttonsPannel.setAlignmentX(Component.LEFT_ALIGNMENT);
    variablesBorderPanel.add(buttonsPannel);

    varTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    varTable.setRowHeight(controlHeight);
    int widths[] = {controlHeight, 3 * controlHeight, 10 * controlHeight};
    for (int i = 0; i < widths.length; i++) {
        TableColumn column = varTable.getColumnModel().getColumn(i);
        column.setPreferredWidth(widths[i]);
        column.setWidth(widths[i]);

    }
    JScrollPane scrollPane = new JScrollPane(varTable);
    scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
    variablesBorderPanel.add(scrollPane);
    variablesBorderPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    Dimension variablesPanelDimension =
            new Dimension((formWidth - 3 * DEFAULT_PADDING) / 2 - 2 * DEFAULT_PADDING, 130);
    variablesBorderPanel.setMinimumSize(variablesPanelDimension);
    variablesBorderPanel.setMaximumSize(variablesPanelDimension);
    variablesBorderPanel.setPreferredSize(variablesPanelDimension);

    addVariableButton.addActionListener(e -> {
        newOperatorDescriptor.getVariables().add(new SystemVariable("key", ""));
        varTable.revalidate();
    });

    addDependentVariableButton.addActionListener(e -> {
        newOperatorDescriptor.getVariables().add(new SystemDependentVariable("key", ""));
        varTable.revalidate();
    });

    return variablesBorderPanel;
}
 
Example 20
Source File: SourceProductList.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private AbstractButton createRemoveInputButton() {
    final AbstractButton removeButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Minus24.gif"),
                                                                       false);
    removeButton.addActionListener(e -> listModel.removeElementsAt(inputPathsList.getSelectedIndices()));
    return removeButton;
}