/** * Protocols that allow communication between GUI palette and GUI text editor. * * @return whether operation was a success. */ @NbBundle.Messages({"WriteFile_Customizer=Insert", "NAME_java-WriteFile=WriteFile"}) public boolean showDialog() { dialogOK = false; descriptor = new DialogDescriptor( this, Bundle.WriteFile_Customizer(), true, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) { evaluateInput(); dialogOK = true; } dialog.dispose(); } }); dialog = DialogDisplayer.getDefault().createDialog(descriptor); dialog.setResizable(false); dialog.setVisible(true); return dialogOK; }
public void setResizable(boolean b) { if (f != null) { f.setResizable(b); } else if (d != null) { d.setResizable(b); } else if (jif != null) { jif.setResizable(b); } else { throw new IllegalStateException(); } }
void showWarning(Frame frame, String warning) { warningDialog = new Dialog(frame, "警告", true); warningDialog.setSize(200, 100); warningDialog.setLayout(new FlowLayout()); warningDialog.setResizable(false); warningDialog.setLocationRelativeTo(frame); warningText = new Label(warning); warningButton = new Button("确认"); warningDialog.add(warningText); warningDialog.add(warningButton); warningDialog.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { warningDialog.setVisible(false); warningDialog.dispose(); } }); warningButton.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_ENTER) { warningDialog.setVisible(false); warningDialog.dispose(); } } }); warningButton.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { warningDialog.setVisible(false); warningDialog.dispose(); } }); warningDialog.setVisible(true); }
private void openDialog(String title, String string) { // TODO Auto-generated method stub Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dialogSize = new Dimension(200, 120); final Dialog dialog = new Dialog((Frame) getParent(), title); dialog.setSize(dialogSize); dialog.setLayout(null); dialog.setResizable(true); Label label = new Label(string); label.setSize(400, 50); label.setLocation(20, 30); dialog.add(label, "Center"); Button enter = new Button("Return"); enter.setSize(50, 25); enter.setLocation(75, 80); enter.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub dialog.dispose(); } }); dialog.add(enter); dialog.setLocation( (screenSize.width - dialogSize.width + 50) / 2, (screenSize.height - dialogSize.height + 40) / 2); dialog.setModal(true); dialog.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent arg0) { // TODO Auto-generated method stub dialog.dispose(); } }); dialog.setVisible(true); }
public boolean showDialog() { DialogDescriptor dialogDescriptor; dialogDescriptor = new DialogDescriptor( panel, org.openide.util.NbBundle.getMessage( RevertModifications.class, "CTL_UpdateDialog", repository.getName())); // NOI18N dialogDescriptor.setOptions(new Object[] {okButton, cancelButton}); dialogDescriptor.setModal(true); dialogDescriptor.setHelpCtx(new HelpCtx(this.getClass())); dialogDescriptor.setValid(false); Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor); dialog .getAccessibleContext() .setAccessibleDescription( org.openide.util.NbBundle.getMessage( RevertModifications.class, "ACSD_UpdateDialog", repository.getName())); // NOI18N dialog.setVisible(true); dialog.setResizable(false); boolean ret = dialogDescriptor.getValue() == okButton; return ret; }
public static void main(final String[] args) throws Exception { /* Make sure AirReceiver shuts down gracefully */ Runtime.getRuntime() .addShutdownHook( new Thread( new Runnable() { @Override public void run() { onShutdown(); } })); /* Create about dialog */ final Dialog aboutDialog = new Dialog((Dialog) null); final GridBagLayout aboutLayout = new GridBagLayout(); aboutDialog.setLayout(aboutLayout); aboutDialog.setVisible(false); aboutDialog.setTitle("About AirReceiver"); aboutDialog.setResizable(false); { /* Message */ final TextArea title = new TextArea(AboutMessage.split("\n").length + 1, 64); title.setText(AboutMessage); title.setEditable(false); final GridBagConstraints titleConstraints = new GridBagConstraints(); titleConstraints.gridx = 1; titleConstraints.gridy = 1; titleConstraints.fill = GridBagConstraints.HORIZONTAL; titleConstraints.insets = new Insets(0, 0, 0, 0); aboutLayout.setConstraints(title, titleConstraints); aboutDialog.add(title); } { /* Done button */ final Button aboutDoneButton = new Button("Done"); aboutDoneButton.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent evt) { aboutDialog.setVisible(false); } }); final GridBagConstraints aboutDoneConstraints = new GridBagConstraints(); aboutDoneConstraints.gridx = 1; aboutDoneConstraints.gridy = 2; aboutDoneConstraints.anchor = GridBagConstraints.PAGE_END; aboutDoneConstraints.fill = GridBagConstraints.NONE; aboutDoneConstraints.insets = new Insets(0, 0, 0, 0); aboutLayout.setConstraints(aboutDoneButton, aboutDoneConstraints); aboutDialog.add(aboutDoneButton); } aboutDialog.setVisible(false); aboutDialog.setLocationByPlatform(true); aboutDialog.pack(); /* Create tray icon */ final URL trayIconUrl = AirReceiver.class.getClassLoader().getResource("icon_32.png"); final TrayIcon trayIcon = new TrayIcon((new ImageIcon(trayIconUrl, "AirReceiver").getImage())); trayIcon.setToolTip("AirReceiver"); trayIcon.setImageAutoSize(true); final PopupMenu popupMenu = new PopupMenu(); final MenuItem aboutMenuItem = new MenuItem("About"); aboutMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent evt) { aboutDialog.setLocationByPlatform(true); aboutDialog.setVisible(true); } }); popupMenu.add(aboutMenuItem); final MenuItem exitMenuItem = new MenuItem("Quit"); exitMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent evt) { onShutdown(); System.exit(0); } }); popupMenu.add(exitMenuItem); trayIcon.setPopupMenu(popupMenu); SystemTray.getSystemTray().add(trayIcon); /* Create AirTunes RTSP server */ final ServerBootstrap airTunesRtspBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(ExecutorService, ExecutorService)); airTunesRtspBootstrap.setPipelineFactory(new RaopRtspPipelineFactory()); airTunesRtspBootstrap.setOption("reuseAddress", true); airTunesRtspBootstrap.setOption("child.tcpNoDelay", true); airTunesRtspBootstrap.setOption("child.keepAlive", true); s_allChannels.add( airTunesRtspBootstrap.bind( new InetSocketAddress(Inet4Address.getByName("0.0.0.0"), AirtunesServiceRTSPPort))); s_logger.info("Launched RTSP service on port " + AirtunesServiceRTSPPort); /* Create mDNS responders. */ synchronized (s_jmDNSInstances) { for (final NetworkInterface iface : Collections.list(NetworkInterface.getNetworkInterfaces())) { if (iface.isLoopback()) continue; if (iface.isPointToPoint()) continue; if (!iface.isUp()) continue; for (final InetAddress addr : Collections.list(iface.getInetAddresses())) { if (!(addr instanceof Inet4Address) && !(addr instanceof Inet6Address)) continue; try { /* Create mDNS responder for address */ final JmDNS jmDNS = JmDNS.create(addr, HostName + "-jmdns"); s_jmDNSInstances.add(jmDNS); /* Publish RAOP service */ final ServiceInfo airTunesServiceInfo = ServiceInfo.create( AirtunesServiceType, HardwareAddressString + "@" + HostName + " (" + iface.getName() + ")", AirtunesServiceRTSPPort, 0 /* weight */, 0 /* priority */, AirtunesServiceProperties); jmDNS.registerService(airTunesServiceInfo); s_logger.info( "Registered AirTunes service '" + airTunesServiceInfo.getName() + "' on " + addr); } catch (final Throwable e) { s_logger.log(Level.SEVERE, "Failed to publish service on " + addr, e); } } } } }