java.awt.event.ActionListener Java Examples

The following examples show how to use java.awt.event.ActionListener. 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: OLCustomizer.java    From netbeans with Apache License 2.0 7 votes vote down vote up
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
    try {
        return super.processKeyBinding(ks, e, condition, pressed);
    } finally {
        //Fix for #166154: passes Enter kb action to dialog
        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
            if (descriptor!=null) {
                ActionListener al = descriptor.getButtonListener();
                if (al!=null) {
                    al.actionPerformed(new ActionEvent(this,
                                                        ActionEvent.ACTION_PERFORMED,
                                                        "OK",           //NOI18N
                                                        e.getWhen(),
                                                        e.getModifiers()));
                }
            }
        }
    }
}
 
Example #2
Source File: bug6520101.java    From jdk8u-jdk with GNU General Public License v2.0 7 votes vote down vote up
public void run() {
    while (!this.chooser.isShowing()) {
        try {
            Thread.sleep(30);
        } catch (InterruptedException exception) {
            exception.printStackTrace();
        }
    }

    Timer timer = new Timer(INTERVAL, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            chooser.cancelSelection();
        }
    });

    timer.setRepeats(false);
    timer.start();
}
 
Example #3
Source File: DragWindow.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Timer createInitialEffect() {
    final Timer timer = new Timer(100, null);
    timer.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if( contentAlpha < 1.0f ) {
                contentAlpha += ALPHA_INCREMENT;
            } else {
                timer.stop();
            }
            if( contentAlpha > 1.0f )
                contentAlpha = 1.0f;
            repaintImageBuffer();
            repaint();
        }
    });
    timer.setInitialDelay(0);
    return timer;
}
 
Example #4
Source File: TemplateChooserPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Component getComponent() {
    if (gui == null) {
        gui = new TemplateChooserPanelGUI(includeTemplatesWithProjects);
        gui.addChangeListener(this);
        gui.setDefaultActionListener(new ActionListener() {

            @Override
            public void actionPerformed( ActionEvent e ) {
                if( null != wizard ) {
                    wizard.doNextClick();
                }
            }
        });
    }
    return gui;
}
 
Example #5
Source File: WizardStepProgressSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void startProgress() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            ProgressHandle progress = getProgressHandle(); // NOI18N
            JComponent bar = ProgressHandleFactory.createProgressComponent(progress);
            stopButton = new JButton(org.openide.util.NbBundle.getMessage(RepositoryStep.class, "BK2022")); // NOI18N
            stopButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    cancel();
                }
            });
            progressComponent = new JPanel();
            progressComponent.setLayout(new BorderLayout(6, 0));
            progressLabel = new JLabel();
            progressLabel.setText(getDisplayName());
            progressComponent.add(progressLabel, BorderLayout.NORTH);
            progressComponent.add(bar, BorderLayout.CENTER);
            progressComponent.add(stopButton, BorderLayout.LINE_END);
            WizardStepProgressSupport.super.startProgress();
            panel.setVisible(true);
            panel.add(progressComponent);
            panel.revalidate();
        }
    });                                                
}
 
Example #6
Source File: UpdateReservationWindow.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 6 votes vote down vote up
public ActionListener roomTypeActionListener() {
	ActionListener rta = (ActionEvent e) -> {
		final String TYPE = roomTypeCmbBox.getSelectedItem().toString();

		switch (TYPE) {
		case "SINGLE":
			personCountSpinner.setValue(1);
			break;
		case "DOUBLE":
			personCountSpinner.setValue(2);
			break;
		case "TWIN":
			personCountSpinner.setValue(2);
			break;
		case "TRIPLE":
			personCountSpinner.setValue(3);
			break;
		default:
			break;
		}
		repaint();
	};
	return rta;
}
 
Example #7
Source File: DialogDisplayer50960Test.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRedundantActionPerformed () {
    JButton b1 = new JButton ("Do");
    JButton b2 = new JButton ("Don't");
    ActionListener listener = new ActionListener () {
        public void actionPerformed (ActionEvent event) {
            assertFalse ("actionPerformed() only once.", performed);
            performed = true;
        }
    };
    DialogDescriptor dd = new DialogDescriptor (
                        "...",
                        "My Dialog",
                        true,
                        new JButton[] {b1, b2},
                        b2,
                        DialogDescriptor.DEFAULT_ALIGN,
                        null,
                        null
                    );
    dd.setButtonListener (listener);
    Dialog dlg = DialogDisplayer.getDefault ().createDialog (dd);
    b1.doClick ();
    assertTrue ("Button b1 invoked.", performed);
}
 
Example #8
Source File: GUIUtils.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * Add a new checkbox to given component
 *
 * @param container Component to add the checkbox to
 * @param text Checkbox' text
 * @param icon Checkbox' icon or null
 * @param listener Checkbox' listener or null
 * @param actionCommand Checkbox' action command or null
 * @param mnemonic Checkbox' mnemonic (virtual key code) or 0
 * @param toolTip Checkbox' tool tip or null
 * @param state Checkbox' state
 * @return Created checkbox
 */
public static JCheckBox addCheckbox(Container component, String text, Icon icon,
    ActionListener listener, String actionCommand, int mnemonic, String toolTip, boolean state) {
  JCheckBox checkbox = new JCheckBox(text, icon, state);
  if (listener != null)
    checkbox.addActionListener(listener);
  if (actionCommand != null)
    checkbox.setActionCommand(actionCommand);
  if (mnemonic > 0)
    checkbox.setMnemonic(mnemonic);
  if (toolTip != null)
    checkbox.setToolTipText(toolTip);
  if (component != null)
    component.add(checkbox);
  return checkbox;
}
 
Example #9
Source File: FeatureAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    FeatureInfo info = FoDLayersProvider.getInstance().whichProvides(fo);
    String n = Actions.cutAmpersand((String)fo.getAttribute("displayName")); // NOI18N
    boolean success = Utilities.featureDialog(info, n, n);
    if (!success) {
        return;
    }
    
    FileObject newFile = FileUtil.getConfigFile(fo.getPath());
    if (newFile == null) {
        throw new IllegalStateException("Cannot find file: " + fo.getPath());
    }
    
    Object obj = newFile.getAttribute("instanceCreate"); // NOI18N
    if (obj instanceof ActionListener) {
        ((ActionListener)obj).actionPerformed(e);
    }
}
 
Example #10
Source File: IOWindow.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public SubComponent[] getSubComponents() {
    if( singleTab != null )
        return new SubComponent[0];
    JComponent[] tabs = getTabs();
    SubComponent[] res = new SubComponent[tabs.length];
    for( int i=0; i<res.length; i++ ) {
        final JComponent theTab = tabs[i];
        String title = pane.getTitleAt( i );
        res[i] = new SubComponent( title, new ActionListener() {

            @Override
            public void actionPerformed( ActionEvent e ) {
                if( singleTab != null || pane.indexOfComponent( theTab ) < 0 )
                    return; //the tab is gone already
                selectTab( theTab );
            }
        }, theTab == getSelectedTab() );
    }
    return res;
}
 
Example #11
Source File: RotatingIcon.java    From btdex with GNU General Public License v3.0 6 votes vote down vote up
public RotatingIcon(Icon icon) {
	delegateIcon = icon;
	
	rotatingTimer = new Timer( 200, new ActionListener() {
		@Override
		public void actionPerformed( ActionEvent e ) {
			angleInDegrees = angleInDegrees + 40;
			if ( angleInDegrees == 360 ){
				angleInDegrees = 0;
			}
			
			for(DefaultTableModel model : cells.keySet()) {
				for(Point c : cells.get(model))
					model.fireTableCellUpdated(c.x, c.y);					
			}
		}
	} );
	rotatingTimer.setRepeats( false );
	rotatingTimer.start();
}
 
Example #12
Source File: WeakTimerListener.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent evt) {
    ActionListener src = (ActionListener)ref.get();
    if (src != null) {
        src.actionPerformed(evt);

    } else { // source listener was garbage collected
        if (evt.getSource() instanceof Timer) {
            Timer timer = (Timer)evt.getSource();
            timer.removeActionListener(this);

            if (stopTimer) {
                timer.stop();
            }
        }
    }
}
 
Example #13
Source File: Preferences.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
private Component createLocationSector() {
    JPanel panel = new JPanel(new BorderLayout());
    location = new JTextField();
    location.setPreferredSize(new Dimension(180, location
            .getPreferredSize().height));
    JButton button = new JButton("...");
    button.setToolTipText("Base.Location.ToolTip");
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(location.getText());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);
            if (chooser.showOpenDialog(Preferences.this) == JFileChooser.APPROVE_OPTION) {
                location.setText(chooser.getSelectedFile()
                        .getAbsolutePath());
            }

        }
    });
    panel.add(location, BorderLayout.CENTER);
    panel.add(button, BorderLayout.EAST);
    return panel;
}
 
Example #14
Source File: ProgressLabel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void setupProgress() {
    setIcon(createProgressIcon());
    t = new Timer(100, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Component comp = refComp.get();
            TreeListNode nd = refNode.get();
            if (nd == null && comp == null) {
                t.stop();
                Container p = getParent();
                if (p != null) {
                    p.remove(ProgressLabel.this);
                }
            } else {
                busyIcon.tick();
                ProgressLabel.this.repaint();
                if (nd != null) {
                    nd.fireContentChanged();
                } else {
                    comp.repaint();
                }
            }
        }
    });
    t.setRepeats(true);
    super.setVisible(false);
}
 
Example #15
Source File: GroupContext.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public JPopupMenu getPopupMenu(final Set<UserObject> selectedUserObjects) {
  JPopupMenu menu = new JPopupMenu();
  ResourceBundleUtil labels = ResourceBundleUtil.getBundle(I18nPlantOverview.TREEVIEW_PATH);

  JMenuItem item = new JMenuItem(labels.getString("groupsMouseAdapter.popupMenuItem_removeFromGroup.text"));
  item.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
      openTCSView.removeGroupMembers(selectedUserObjects);
    }
  });

  menu.add(item);

  return menu;
}
 
Example #16
Source File: AboutDialog.java    From SubTitleSearcher with Apache License 2.0 6 votes vote down vote up
public static void main(String args[]) {
	final JFrame frame = new JFrame("test");
	frame.setSize(800, 500);
	// frame.setBackground(Color.LIGHT_GRAY);
	frame.setVisible(true);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	JButton btn = new JButton("test");
	btn.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			new AboutDialog(frame).setVisible(true);
		}

	});
	frame.add(btn);
	new AboutDialog(frame).setVisible(true);

}
 
Example #17
Source File: ServiceProvidersTablePanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of ServiceProvidersTablePanel
 */
public ServiceProvidersTablePanel(ServiceProvidersTableModel tablemodel, STSConfiguration stsConfig, ConfigVersion cfgVersion) {
    super(tablemodel);
    this.stsConfig = stsConfig;
    this.tablemodel = tablemodel;
    this.cfgVersion = cfgVersion;
    
    this.editButton.setVisible(true);

    addedProviders = new HashMap<String, ServiceProviderElement>();
    
    editActionListener = new EditActionListener();
    ActionListener editListener = WeakListeners.create(ActionListener.class,
            editActionListener, editButton);
    editButton.addActionListener(editListener);

    addActionListener = new AddActionListener();
    ActionListener addListener = WeakListeners.create(ActionListener.class,
            addActionListener, addButton);
    addButton.addActionListener(addListener);
    
    removeActionListener = new RemoveActionListener();
    ActionListener removeListener = WeakListeners.create(ActionListener.class,
            removeActionListener, removeButton);
    removeButton.addActionListener(removeListener);
}
 
Example #18
Source File: ButtonFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates button to maximize currently selected document in the given tab displayer.
 * @param controller Tab displayer's controller.
 * @return Button to maximize selected document tab.
 */
public static JButton createMaximizeButton( final Controller controller ) {
    final JButton btn = new JButton();
    Icon icon = UIManager.getIcon("nb.multitabs.button.maximize.icon");
    if (icon == null) {
        icon = ImageUtilities.loadImageIcon( "org/netbeans/core/multitabs/resources/maximize.png", true ); //NOI18N
    }
    btn.setIcon( icon );
    btn.setToolTipText( NbBundle.getMessage(ButtonFactory.class, "Hint_MaximizeRestore") );
    btn.addActionListener( new ActionListener() {

        @Override
        public void actionPerformed( ActionEvent e ) {
            controller.postActionEvent( new TabActionEvent( btn, TabbedContainer.COMMAND_MAXIMIZE, -1 ) );
        }
    });
    btn.setFocusable( false );
    return btn;
}
 
Example #19
Source File: ReportEditorView.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
protected JToggleButton createOpenViewButton(ButtonGroup group,
                                             final SubView view) {
    JToggleButton button = new JToggleButton(view.getTitle());
    group.add(button);
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            actionsRemoved(activeView.getActions());
            beforeSubviewActivated(view);
            content.removeAll();
            content.add(view, BorderLayout.CENTER);
            content.revalidate();
            content.repaint();
            activeView = view;
            actionsAdded(view.getActions());
        }
    });

    return button;
}
 
Example #20
Source File: ParamEditor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void showDialog() {

	if(editable == Editable.NEITHER) {
	    NotifyDescriptor d = 
		new NotifyDescriptor(this, title, 
				     NotifyDescriptor.DEFAULT_OPTION,
				     NotifyDescriptor.PLAIN_MESSAGE, 
				     new Object[] { NotifyDescriptor.OK_OPTION },
				     NotifyDescriptor.OK_OPTION); 
	    DialogDisplayer.getDefault().notify(d);
	}
	else {
	    editDialog = new DialogDescriptor
		(this, title, true, DialogDescriptor.OK_CANCEL_OPTION,
		 DialogDescriptor.CANCEL_OPTION,
		 new ActionListener() {
		     public void actionPerformed(ActionEvent e) {
			 evaluateInput(); 
		     }
		 }); 

	    dialog = DialogDisplayer.getDefault().createDialog(editDialog);
	    dialog.setVisible(true);
	    this.repaint();
	}
    }
 
Example #21
Source File: Font2DTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public ChoiceV2( ActionListener al, boolean fontChoice) {
    this(al);
    if(fontChoice) {
        //Register this component in ToolTipManager
        setToolTipText("");
        bitSet = new BitSet();
        setRenderer(new ChoiceV2Renderer(this));
    }
}
 
Example #22
Source File: Test6179222.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Test6179222 test = new Test6179222();
    // test 6179222
    test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
    // test 6265540
    test(EventHandler.create(ActionListener.class, test, "bar.doit"));
    if (!test.bar.invoked) {
        throw new Error("Bar was not set");
    }
}
 
Example #23
Source File: Controller.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void removeActionListener( ActionListener al ) {
    synchronized( this ) {
        if (actionListenerList != null) {
            actionListenerList.remove(al);
            if (actionListenerList.isEmpty()) {
                actionListenerList = null;
            }
        }
    }
}
 
Example #24
Source File: ERDesignerToolbarEntry.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
public ERDesignerToolbarEntry(String aId) {
	super(aId);

	addActionListener(new ActionListener() {

		@Override
		public void actionPerformed(ActionEvent e) {
			menu.show(ERDesignerToolbarEntry.this, 0, getSize().height);
		}
	});
}
 
Example #25
Source File: CommonUI.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static JButton createButton(String text, ActionListener listener, int mnemonic)
{
    JButton button = new JButton(text);
    if(listener != null)
        button.addActionListener(listener);
    if(mnemonic != -1)
        button.setMnemonic(mnemonic);
    setButtonSize(button, buttonPrefSize);
    return button;
}
 
Example #26
Source File: DisabledUndoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public TestDialog(Frame frame, String name) {
    super(frame, name);
    int scrollBoth = TextArea.SCROLLBARS_BOTH;
    instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
    add("North", instructionsText);

    messageText = new TextArea("", 5, maxStringLength, scrollBoth);
    add("Center", messageText);

    buttonP = new Panel();
    failB = new Button("Fail");
    failB.setActionCommand("fail");
    failB.addActionListener(this);
    passB = new Button("Pass");
    buttonP.add(passB);
    buttonP.add(failB);
    passB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            DisabledUndoTest.pass();
        }
    });

    add("South", buttonP);
    pack();
    setVisible(true);
}
 
Example #27
Source File: I18nServiceImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Provides a component usable as property customizer (so typically a modal
 * dialog) that allows to choose (or create) a properties bundle file within
 * the project of given form data object. The selected file should be
 * written to the given property editor (via setValue) as a resource name
 * string.
 */
@Override
public Component getBundleSelectionComponent(final PropertyEditor prEd, FileObject srcFile) {
    try {
        final FileSelector fs = new FileSelector(srcFile, JavaResourceHolder.getTemplate());
        return fs.getDialog(NbBundle.getMessage(I18nServiceImpl.class, "CTL_SELECT_BUNDLE_TITLE"), // NOI18N
                            new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent ev) {
                DataObject bundleDO = fs.getSelectedDataObject();
                if (bundleDO != null) {
                    ClassPath cp = ClassPath.getClassPath(bundleDO.getPrimaryFile(), ClassPath.SOURCE);
                    if (cp != null) {
                        String bundleName = cp.getResourceName(bundleDO.getPrimaryFile(), '/', false);
                        prEd.setValue(bundleName);
                    }
                }
            }
        });
    }
    catch (IOException ex) {
        // means that template for properties file was not found - unlikely
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
    }
    return null;
}
 
Example #28
Source File: VisualSortDemo.java    From mvisc with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args)
	{
//		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//		logger.info(Core.VERSION);
		final ArrayList<File> animalFiles = new ArrayList<File>();
		final JFrame frame = new JFrame();
		frame.setSize(200, 100);
		
		
		frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
		
		final JButton createModelButton = new JButton("create model");
		JButton compareButton = new JButton("compare");
		
		createModelButton.addActionListener(new ActionListener() {
			

			public void actionPerformed(ActionEvent e) {
				dir = FileUtils.selectDirectory(frame, "select folder with (old) .zoo-files to create model");
				ArrayList<File> animalFile = new ArrayList<File>();
				FileUtils.getImages(dir, animalFile, true);
				createModelButton.setText("CREATING!");
				try {
					generateCodeBook(animalFile, new File(osBaseDir + "_.json"));
				} catch (IOException e1) {
					e1.printStackTrace();
				}
				createModelButton.setText("DONE!");
				createModelButton.setEnabled(false);
			}
		});
		
		frame.add(createModelButton);
//		frame.add(compareButton);
		
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			
	}
 
Example #29
Source File: RelationSetView.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Resource init() {
  setLayout(new BorderLayout());

  text.setEditable(false);

  add(text, BorderLayout.CENTER);

  JButton btnRefresh = new JButton("Refresh", MainFrame.getIcon("Refresh"));
  btnRefresh.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent arg0) {
      refresh();
    }
  });

  JToolBar toolbar = new JToolBar(JToolBar.HORIZONTAL);
  toolbar.setFloatable(false);

  toolbar.add(btnRefresh);
  toolbar.addSeparator();
  toolbar.add(new JLabel("Currently this view is not automatically updated"));

  // not currently need as we now support the listners properly
  // add(toolbar, BorderLayout.NORTH);

  return this;
}
 
Example #30
Source File: Test6179222.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Test6179222 test = new Test6179222();
    // test 6179222
    test(EventHandler.create(ActionListener.class, test, "foo", "source.icon"));
    // test 6265540
    test(EventHandler.create(ActionListener.class, test, "bar.doit"));
    if (!test.bar.invoked) {
        throw new Error("Bar was not set");
    }
}