List of usage examples for javax.swing JFrame addWindowListener
public synchronized void addWindowListener(WindowListener l)
From source file:org.gridchem.client.GridChem.java
public static void main(String[] args) { Trace.entry();//from w w w . j a va 2s. com try { setCommandLineOptions(); parseCommandLine(args); } catch (Exception e) { System.out.println("Invalid command line option given: " + e.getMessage()); } //JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); // Edited by Shashank & Sandeep @ CCS,UKY April 10 2005 JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); /*MetalTheme theme = new G03Input.ColorTheme(); MetalLookAndFeel.setCurrentTheme(theme); try { UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); SwingUtilities.updateComponentTreeUI(frame); } catch(Exception e) { System.out.println(e); }*/ // Use the native look and feel since Java's is pretty lame. try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { // Ignore exceptions, which only result in the wrong look and feel. System.out.println("GridChem.main: an exception related to the" + " look and feel was ignored."); } init(); frame.setTitle("GridChem " + Env.getVersion()); frame.getContentPane().add(oc); frame.addWindowListener(new WindowListener() { public void windowActivated(WindowEvent arg0) { } public void windowClosed(WindowEvent arg0) { } public void windowClosing(WindowEvent arg0) { if (Settings.authenticated) { GMS3.logout(); } } public void windowDeactivated(WindowEvent arg0) { } public void windowDeiconified(WindowEvent arg0) { } public void windowIconified(WindowEvent arg0) { } public void windowOpened(WindowEvent arg0) { } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); // Centering the frame on the screen Toolkit kit = frame.getToolkit(); Dimension screenSize = kit.getScreenSize(); int screenWidth = screenSize.width; int screenHeight = screenSize.height; Dimension windowSize = frame.getSize(); int windowWidth = windowSize.width; int windowHeight = windowSize.height; int upperLeftX = (screenWidth - windowWidth) / 2; int upperLeftY = (screenHeight - windowHeight) / 2; frame.setLocation(upperLeftX, upperLeftY); frame.setVisible(true); Trace.exit(); }
From source file:org.jbpm.bpel.tutorial.atm.terminal.AtmTerminal.java
public static void main(String[] args) { deployClient();// w w w. j a v a 2s. co m FrontEnd atmFrontEnd = createAtmFrontEnd(); selectNativeLookAndFeel(); AtmPanel atmPanel = createAtmPanel(atmFrontEnd); JFrame mainFrame = new JFrame("ATM"); mainFrame.addWindowListener(AtmFrameListener.INSTANCE); mainFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); mainFrame.getContentPane().add(atmPanel); mainFrame.pack(); mainFrame.setVisible(true); }
From source file:org.jets3t.apps.cockpitlite.CockpitLite.java
/** * Runs Cockpit as a stand-alone application. * @param args//from w ww . j av a2 s.co m * @throws Exception */ public static void main(String args[]) throws Exception { JFrame ownerFrame = new JFrame("JetS3t Cockpit-Lite"); ownerFrame.addWindowListener(new WindowListener() { public void windowOpened(WindowEvent e) { } public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } public void windowClosed(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } }); // Read arguments as properties of the form: <propertyName>'='<propertyValue> Properties argumentProperties = new Properties(); if (args.length > 0) { for (int i = 0; i < args.length; i++) { String arg = args[i]; int delimIndex = arg.indexOf("="); if (delimIndex >= 0) { String name = arg.substring(0, delimIndex); String value = arg.substring(delimIndex + 1); argumentProperties.put(name, value); } else { System.out.println("Ignoring property argument with incorrect format: " + arg); } } } new CockpitLite(ownerFrame, argumentProperties); }
From source file:org.jivesoftware.sparkimpl.updater.CheckUpdates.java
public void downloadUpdate(final File downloadedFile, final SparkVersion version) { final java.util.Timer timer = new java.util.Timer(); // Prepare HTTP post final GetMethod post = new GetMethod(version.getDownloadURL()); // Get HTTP client Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443)); final HttpClient httpclient = new HttpClient(); String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); if (ModelUtil.hasLength(proxyHost) && ModelUtil.hasLength(proxyPort)) { try {/*www . j a v a 2s . co m*/ httpclient.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort)); } catch (NumberFormatException e) { Log.error(e); } } // Execute request try { int result = httpclient.executeMethod(post); if (result != 200) { return; } long length = post.getResponseContentLength(); int contentLength = (int) length; bar = new JProgressBar(0, contentLength); } catch (IOException e) { Log.error(e); } final JFrame frame = new JFrame(Res.getString("title.downloading.im.client")); frame.setIconImage(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_IMAGE).getImage()); titlePanel = new TitlePanel(Res.getString("title.upgrading.client"), Res.getString("message.version", version.getVersion()), SparkRes.getImageIcon(SparkRes.SEND_FILE_24x24), true); final Thread thread = new Thread(new Runnable() { public void run() { try { InputStream stream = post.getResponseBodyAsStream(); long size = post.getResponseContentLength(); ByteFormat formater = new ByteFormat(); sizeText = formater.format(size); titlePanel.setDescription(Res.getString("message.version", version.getVersion()) + " \n" + Res.getString("message.file.size", sizeText)); downloadedFile.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(downloadedFile); copy(stream, out); out.close(); if (!cancel) { downloadComplete = true; promptForInstallation(downloadedFile, Res.getString("title.download.complete"), Res.getString("message.restart.spark")); } else { out.close(); downloadedFile.delete(); } UPDATING = false; frame.dispose(); } catch (Exception ex) { // Nothing to do } finally { timer.cancel(); // Release current connection to the connection pool once you are done post.releaseConnection(); } } }); frame.getContentPane().setLayout(new GridBagLayout()); frame.getContentPane().add(titlePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); frame.getContentPane().add(bar, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); JEditorPane pane = new JEditorPane(); boolean displayContentPane = version.getChangeLogURL() != null || version.getDisplayMessage() != null; try { pane.setEditable(false); if (version.getChangeLogURL() != null) { pane.setEditorKit(new HTMLEditorKit()); pane.setPage(version.getChangeLogURL()); } else if (version.getDisplayMessage() != null) { pane.setText(version.getDisplayMessage()); } if (displayContentPane) { frame.getContentPane().add(new JScrollPane(pane), new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); } } catch (IOException e) { Log.error(e); } frame.getContentPane().setBackground(Color.WHITE); frame.pack(); if (displayContentPane) { frame.setSize(600, 400); } else { frame.setSize(400, 100); } frame.setLocationRelativeTo(SparkManager.getMainWindow()); GraphicUtils.centerWindowOnScreen(frame); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { thread.interrupt(); cancel = true; UPDATING = false; if (!downloadComplete) { JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.updating.cancelled"), Res.getString("title.cancelled"), JOptionPane.ERROR_MESSAGE); } } }); frame.setVisible(true); thread.start(); timer.scheduleAtFixedRate(new TimerTask() { int seconds = 1; public void run() { ByteFormat formatter = new ByteFormat(); long value = bar.getValue(); long average = value / seconds; String text = formatter.format(average) + "/Sec"; String total = formatter.format(value); titlePanel.setDescription(Res.getString("message.version", version.getVersion()) + " \n" + Res.getString("message.file.size", sizeText) + "\n" + Res.getString("message.transfer.rate") + ": " + text + "\n" + Res.getString("message.total.downloaded") + ": " + total); seconds++; } }, 1000, 1000); }
From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java
/** * Setup System Tray Icon.//from ww w . java 2 s .c o m * * @param frame owner frame */ private void setupTrayIcon(final JFrame frame) { idleIcon = Toolkit.getDefaultToolkit() .getImage(ClassLoader.getSystemResource("META-INF/resources/node_inactive.png")); activeIcon = Toolkit.getDefaultToolkit() .getImage(ClassLoader.getSystemResource("META-INF/resources/node_active.png")); frame.setIconImage(idleIcon); // If system tray is supported by OS if (SystemTray.isSupported()) { trayIcon = new TrayIcon(idleIcon, "Nebula Grid Node", createTrayPopup()); trayIcon.setImageAutoSize(true); trayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (!frame.isVisible()) { frame.setVisible(true); } frame.setExtendedState(JFrame.NORMAL); frame.requestFocus(); frame.toFront(); } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException ae) { log.debug("[UI] Unable to Initialize Tray Icon"); return; } frame.addWindowListener(new WindowAdapter() { @Override public void windowIconified(WindowEvent e) { // Hide (can be shown using tray icon) frame.setVisible(false); } }); } }
From source file:org.openscience.jchempaint.application.JChemPaint.java
public static JChemPaintPanel showInstance(IChemModel chemModel, String title, boolean debug) { JFrame f = new JFrame(title + " - JChemPaint"); chemModel.setID(title);//from ww w . j av a 2 s .c o m f.addWindowListener(new JChemPaintPanel.AppCloser()); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); JChemPaintPanel p = new JChemPaintPanel(chemModel, GUI_APPLICATION, debug, null); p.updateStatusBar(); f.setPreferredSize(new Dimension(800, 494)); //1.618 f.add(p); f.pack(); Point point = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); int w2 = (f.getWidth() / 2); int h2 = (f.getHeight() / 2); f.setLocation(point.x - w2, point.y - h2); f.setVisible(true); frameList.add(f); return p; }
From source file:org.openscience.jmol.app.Jmol.java
Jmol(Splash splash, JFrame frame, Jmol parent, int startupWidth, int startupHeight, String commandOptions, Point loc) {//w w w . ja v a 2s . co m super(true); this.frame = frame; this.startupWidth = startupWidth; this.startupHeight = startupHeight; numWindows++; try { say("history file is " + historyFile.getFile().getAbsolutePath()); } catch (Exception e) { } frame.setTitle("Jmol"); frame.getContentPane().setBackground(Color.lightGray); frame.getContentPane().setLayout(new BorderLayout()); this.splash = splash; setBorder(BorderFactory.createEtchedBorder()); setLayout(new BorderLayout()); language = GT.getLanguage(); status = (StatusBar) createStatusBar(); say(GT._("Initializing 3D display...")); // display = new DisplayPanel(status, guimap, haveDisplay.booleanValue(), startupWidth, startupHeight); String adapter = System.getProperty("model"); if (adapter == null || adapter.length() == 0) adapter = "smarter"; if (adapter.equals("smarter")) { report("using Smarter Model Adapter"); modelAdapter = new SmarterJmolAdapter(); } else if (adapter.equals("cdk")) { report("the CDK Model Adapter is currently no longer supported. Check out http://bioclipse.net/. -- using Smarter"); // modelAdapter = new CdkJmolAdapter(null); modelAdapter = new SmarterJmolAdapter(); } else { report("unrecognized model adapter:" + adapter + " -- using Smarter"); modelAdapter = new SmarterJmolAdapter(); } appletContext = commandOptions; viewer = JmolViewer.allocateViewer(display, modelAdapter); viewer.setAppletContext("", null, null, commandOptions); if (display != null) display.setViewer(viewer); say(GT._("Initializing Preferences...")); preferencesDialog = new PreferencesDialog(frame, guimap, viewer); say(GT._("Initializing Recent Files...")); recentFiles = new RecentFilesDialog(frame); if (haveDisplay.booleanValue()) { say(GT._("Initializing Script Window...")); scriptWindow = new ScriptWindow(viewer, frame); } MyStatusListener myStatusListener; myStatusListener = new MyStatusListener(); viewer.setJmolStatusListener(myStatusListener); say(GT._("Initializing Measurements...")); measurementTable = new MeasurementTable(viewer, frame); // Setup Plugin system // say(GT._("Loading plugins...")); // pluginManager = new CDKPluginManager( // System.getProperty("user.home") + System.getProperty("file.separator") // + ".jmol", new JmolEditBus(viewer) // ); // pluginManager.loadPlugin("org.openscience.cdkplugin.dirbrowser.DirBrowserPlugin"); // pluginManager.loadPlugin("org.openscience.cdkplugin.dirbrowser.DadmlBrowserPlugin"); // pluginManager.loadPlugins( // System.getProperty("user.home") + System.getProperty("file.separator") // + ".jmol/plugins" // ); // feature to allow for globally installed plugins // if (System.getProperty("plugin.dir") != null) { // pluginManager.loadPlugins(System.getProperty("plugin.dir")); // } if (haveDisplay.booleanValue()) { // install the command table say(GT._("Building Command Hooks...")); commands = new Hashtable(); if (display != null) { Action[] actions = getActions(); for (int i = 0; i < actions.length; i++) { Action a = actions[i]; commands.put(a.getValue(Action.NAME), a); } } menuItems = new Hashtable(); say(GT._("Building Menubar...")); executeScriptAction = new ExecuteScriptAction(); menubar = createMenubar(); add("North", menubar); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add("North", createToolbar()); JPanel ip = new JPanel(); ip.setLayout(new BorderLayout()); ip.add("Center", display); panel.add("Center", ip); add("Center", panel); add("South", status); say(GT._("Starting display...")); display.start(); //say(GT._("Setting up File Choosers...")); /* pcs.addPropertyChangeListener(chemFileProperty, exportAction); pcs.addPropertyChangeListener(chemFileProperty, povrayAction); pcs.addPropertyChangeListener(chemFileProperty, writeAction); pcs.addPropertyChangeListener(chemFileProperty, toWebAction); pcs.addPropertyChangeListener(chemFileProperty, printAction); pcs.addPropertyChangeListener(chemFileProperty, viewMeasurementTableAction); */ if (menuFile != null) { menuStructure = viewer.getFileAsString(menuFile); } jmolpopup = JmolPopup.newJmolPopup(viewer, true, menuStructure, true); } // prevent new Jmol from covering old Jmol if (loc != null) { frame.setLocation(loc); } else if (parent != null) { Point location = parent.frame.getLocationOnScreen(); int maxX = screenSize.width - 50; int maxY = screenSize.height - 50; location.x += 40; location.y += 40; if ((location.x > maxX) || (location.y > maxY)) { location.setLocation(0, 0); } frame.setLocation(location); } frame.getContentPane().add("Center", this); frame.addWindowListener(new Jmol.AppCloser()); frame.pack(); frame.setSize(startupWidth, startupHeight); ImageIcon jmolIcon = JmolResourceHandler.getIconX("icon"); Image iconImage = jmolIcon.getImage(); frame.setIconImage(iconImage); // Repositionning windows if (scriptWindow != null) historyFile.repositionWindow(SCRIPT_WINDOW_NAME, scriptWindow, 200, 100); say(GT._("Setting up Drag-and-Drop...")); FileDropper dropper = new FileDropper(); final JFrame f = frame; dropper.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { //System.out.println("Drop triggered..."); f.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (evt.getPropertyName().equals(FileDropper.FD_PROPERTY_FILENAME)) { final String filename = evt.getNewValue().toString(); viewer.openFile(filename); } else if (evt.getPropertyName().equals(FileDropper.FD_PROPERTY_INLINE)) { final String inline = evt.getNewValue().toString(); viewer.openStringInline(inline); } f.setCursor(Cursor.getDefaultCursor()); } }); this.setDropTarget(new DropTarget(this, dropper)); this.setEnabled(true); say(GT._("Launching main frame...")); }
From source file:org.rvsnoop.ui.RvSnoopApplication.java
@Override protected void startup() { setMainFrame(injector.getInstance(Application.class).getFrame()); final JFrame frame = getMainFrame(); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new FrameClosingListener()); addExitListener(new MaybeExit()); ApplicationActionMap actionMap = getContext().getActionMap(); JMenu fileMenu = frame.getJMenuBar().getMenu(0); fileMenu.addSeparator();// w ww . ja v a 2 s .c om fileMenu.add(actionMap.get("quit")); frame.getJMenuBar().add(createHelpMenu()); getContext().getResourceMap().injectComponents(frame); if (AppHelper.getPlatform() == PlatformType.OS_X) { configureMacOsEventHandlers(); } if (initialProjectFile == null) { final JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new ProjectFileFilter()); final int option = chooser.showDialog(null, "Open Project"); initialProjectFile = chooser.getSelectedFile(); if (JFileChooser.APPROVE_OPTION != option || initialProjectFile == null) { exit(); } } show(frame); injector.getInstance(ProjectService.class).openProject(initialProjectFile); }
From source file:org.sleeksnap.ScreenSnapper.java
/** * Open the settings panel/*from w w w. j ava2 s. c o m*/ */ public boolean openSettings() { if (optionsOpen) { return false; } optionsOpen = true; final JFrame frame = new JFrame("Sleeksnap Settings"); final OptionPanel panel = new OptionPanel(this); panel.getUploaderPanel().setImageUploaders(uploaders.get(ImageUpload.class).values()); panel.getUploaderPanel().setTextUploaders(uploaders.get(TextUpload.class).values()); panel.getUploaderPanel().setURLUploaders(uploaders.get(URLUpload.class).values()); panel.getUploaderPanel().setFileUploaders(uploaders.get(FileUpload.class).values()); panel.setHistory(history); panel.doneBuilding(); frame.add(panel); frame.pack(); frame.setVisible(true); frame.setResizable(false); try { frame.setIconImage(ImageIO.read(Util.getResourceByName("/icon32x32.png"))); } catch (final IOException e1) { e1.printStackTrace(); } Util.centerFrame(frame); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosed(final WindowEvent e) { optionsOpen = false; LogPanelHandler.unbind(); } }); return true; }
From source file:org.springframework.richclient.application.support.AbstractApplicationWindow.java
protected JFrame createNewWindowControl() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); WindowAdapter windowCloseHandler = new WindowAdapter() { public void windowClosing(WindowEvent e) { close();// w ww . j a v a2s . c o m } }; frame.addWindowListener(windowCloseHandler); return frame; }