List of usage examples for javax.swing JFrame dispose
public void dispose()
From source file:org.jivesoftware.sparkimpl.plugin.viewer.PluginViewer.java
private void downloadPlugin(final PublicPlugin plugin) { // Prepare HTTP post final GetMethod post = new GetMethod(plugin.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 (Default.getBoolean("PLUGIN_REPOSITORY_USE_PROXY")) { if (ModelUtil.hasLength(proxyHost) && ModelUtil.hasLength(proxyPort)) { try { httpclient.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort)); } catch (NumberFormatException e) { Log.error(e);//w ww .j a v a2s . c o m } } } // Execute request try { int result = httpclient.executeMethod(post); if (result != 200) { return; } long length = post.getResponseContentLength(); int contentLength = (int) length; progressBar = new JProgressBar(0, contentLength); final JFrame frame = new JFrame(Res.getString("message.downloading", plugin.getName())); frame.setIconImage(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_IMAGE).getImage()); final Thread thread = new Thread(new Runnable() { public void run() { try { Thread.sleep(2000); InputStream stream = post.getResponseBodyAsStream(); URL url = new URL(plugin.getDownloadURL()); String name = URLFileSystem.getFileName(url); String directoryName = URLFileSystem.getName(url); File pluginDownload = new File(PluginManager.PLUGINS_DIRECTORY, name); FileOutputStream out = new FileOutputStream(pluginDownload); copy(stream, out); out.close(); frame.dispose(); // Remove SparkPlugUI // Clear all selections Component[] comps = availablePanel.getComponents(); for (Component comp : comps) { if (comp instanceof SparkPlugUI) { SparkPlugUI sparkPlug = (SparkPlugUI) comp; if (sparkPlug.getPlugin().getDownloadURL().equals(plugin.getDownloadURL())) { availablePanel.remove(sparkPlug); _deactivatedPlugins.remove(sparkPlug.getPlugin().getName()); _prefs.setDeactivatedPlugins(_deactivatedPlugins); PluginManager.getInstance().addPlugin(sparkPlug.getPlugin()); sparkPlug.showOperationButton(); installedPanel.add(sparkPlug); sparkPlug.getPlugin() .setPluginDir(new File(PluginManager.PLUGINS_DIRECTORY, directoryName)); installedPanel.invalidate(); installedPanel.repaint(); availablePanel.invalidate(); availablePanel.invalidate(); availablePanel.validate(); availablePanel.repaint(); } } } } catch (Exception ex) { // Nothing to do } finally { // Release current connection to the connection pool once you are done post.releaseConnection(); } } }); frame.getContentPane().setLayout(new GridBagLayout()); frame.getContentPane().add(new JLabel(Res.getString("message.downloading.spark.plug")), 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(progressBar, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); frame.pack(); frame.setSize(400, 100); GraphicUtils.centerWindowOnComponent(frame, this); frame.setVisible(true); thread.start(); } catch (IOException e) { Log.error(e); } }
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 av a 2 s.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.kchine.rpf.PoolUtils.java
public static void unzip(InputStream is, String destination, NameFilter nameFilter, int bufferSize, boolean showProgress, String taskName, int estimatedFilesNumber) { destination.replace('\\', '/'); if (!destination.endsWith("/")) destination = destination + "/"; final JTextArea area = showProgress ? new JTextArea() : null; final JProgressBar jpb = showProgress ? new JProgressBar(0, 100) : null; final JFrame f = showProgress ? new JFrame(taskName) : null; if (showProgress) { Runnable runnable = new Runnable() { public void run() { area.setFocusable(false); jpb.setIndeterminate(true); JPanel p = new JPanel(new BorderLayout()); p.add(jpb, BorderLayout.SOUTH); p.add(new JScrollPane(area), BorderLayout.CENTER); f.add(p);//from ww w. ja v a 2s .c o m f.pack(); f.setSize(300, 90); f.setVisible(true); locateInScreenCenter(f); } }; if (SwingUtilities.isEventDispatchThread()) runnable.run(); else { SwingUtilities.invokeLater(runnable); } } try { ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is)); int entriesNumber = 0; int currentPercentage = 0; int count; byte data[] = new byte[bufferSize]; ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { if (!entry.isDirectory() && (nameFilter == null || nameFilter.accept(entry.getName()))) { String entryName = entry.getName(); prepareFileDirectories(destination, entryName); String destFN = destination + File.separator + entry.getName(); FileOutputStream fos = new FileOutputStream(destFN); BufferedOutputStream dest = new BufferedOutputStream(fos, bufferSize); while ((count = zis.read(data, 0, bufferSize)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); if (showProgress) { ++entriesNumber; final int p = (int) (100 * entriesNumber / estimatedFilesNumber); if (p > currentPercentage) { currentPercentage = p; final JTextArea fa = area; final JProgressBar fjpb = jpb; SwingUtilities.invokeLater(new Runnable() { public void run() { fjpb.setIndeterminate(false); fjpb.setValue(p); fa.setText("\n" + p + "%" + " Done "); } }); SwingUtilities.invokeLater(new Runnable() { public void run() { fa.setCaretPosition(fa.getText().length()); fa.repaint(); fjpb.repaint(); } }); } } } } zis.close(); if (showProgress) { f.dispose(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.kchine.rpf.PoolUtils.java
public static String cacheJar(URL url, String location, int logInfo, boolean forced) throws Exception { final String jarName = url.toString().substring(url.toString().lastIndexOf("/") + 1); if (!location.endsWith("/") && !location.endsWith("\\")) location += "/"; String fileName = location + jarName; new File(location).mkdirs(); final JTextArea area = ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) ? new JTextArea() : null; final JProgressBar jpb = ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) ? new JProgressBar(0, 100) : null; final JFrame f = ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) ? new JFrame("copying " + jarName + " ...") : null;//ww w . j a v a 2 s .c o m try { ResponseCache.setDefault(null); URLConnection urlC = null; Exception connectionException = null; for (int i = 0; i < RECONNECTION_RETRIAL_NBR; ++i) { try { urlC = url.openConnection(); connectionException = null; break; } catch (Exception e) { connectionException = e; } } if (connectionException != null) throw connectionException; InputStream is = url.openStream(); File file = new File(fileName); long urlLastModified = urlC.getLastModified(); if (!forced) { boolean somethingToDo = !file.exists() || file.lastModified() < urlLastModified || (file.length() != urlC.getContentLength() && !isValidJar(fileName)); if (!somethingToDo) return fileName; } if ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) { Runnable runnable = new Runnable() { public void run() { try { f.setUndecorated(true); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); area.setEditable(false); area.setForeground(Color.white); area.setBackground(new Color(0x00, 0x80, 0x80)); jpb.setIndeterminate(true); jpb.setForeground(Color.white); jpb.setBackground(new Color(0x00, 0x80, 0x80)); JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createLineBorder(Color.black, 3)); p.setBackground(new Color(0x00, 0x80, 0x80)); p.add(jpb, BorderLayout.SOUTH); p.add(area, BorderLayout.CENTER); f.add(p); f.pack(); f.setSize(300, 80); locateInScreenCenter(f); f.setVisible(true); System.out.println("here"); } catch (Exception e) { e.printStackTrace(); } } }; if (SwingUtilities.isEventDispatchThread()) runnable.run(); else { SwingUtilities.invokeLater(runnable); } } if ((logInfo & LOG_PRGRESS_TO_SYSTEM_OUT) != 0) { System.out.println("Downloading " + jarName + ":"); System.out.print("expected:==================================================\ndone :"); } if ((logInfo & LOG_PRGRESS_TO_LOGGER) != 0) { log.info("Downloading " + jarName + ":"); } int jarSize = urlC.getContentLength(); int currentPercentage = 0; FileOutputStream fos = null; fos = new FileOutputStream(fileName); int count = 0; int printcounter = 0; byte data[] = new byte[BUFFER_SIZE]; int co = 0; while ((co = is.read(data, 0, BUFFER_SIZE)) != -1) { fos.write(data, 0, co); count = count + co; int expected = (50 * count / jarSize); while (printcounter < expected) { if ((logInfo & LOG_PRGRESS_TO_SYSTEM_OUT) != 0) { System.out.print("="); } if ((logInfo & LOG_PRGRESS_TO_LOGGER) != 0) { log.info((int) (100 * count / jarSize) + "% done."); } ++printcounter; } if ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) { final int p = (int) (100 * count / jarSize); if (p > currentPercentage) { currentPercentage = p; final JTextArea fa = area; final JProgressBar fjpb = jpb; SwingUtilities.invokeLater(new Runnable() { public void run() { fjpb.setIndeterminate(false); fjpb.setValue(p); fa.setText("Copying " + jarName + " ..." + "\n" + p + "%" + " Done. "); } }); SwingUtilities.invokeLater(new Runnable() { public void run() { fa.setCaretPosition(fa.getText().length()); fa.repaint(); fjpb.repaint(); } }); } } } /* * while ((oneChar = is.read()) != -1) { fos.write(oneChar); * count++; * * final int p = (int) (100 * count / jarSize); if (p > * currentPercentage) { System.out.print(p+" % "); currentPercentage = * p; if (showProgress) { final JTextArea fa = area; final * JProgressBar fjpb = jpb; SwingUtilities.invokeLater(new * Runnable() { public void run() { fjpb.setIndeterminate(false); * fjpb.setValue(p); fa.setText("\n" + p + "%" + " Done "); } }); * * SwingUtilities.invokeLater(new Runnable() { public void run() { * fa.setCaretPosition(fa.getText().length()); fa.repaint(); * fjpb.repaint(); } }); } else { if (p%2==0) System.out.print("="); } } * } * */ is.close(); fos.close(); } catch (MalformedURLException e) { System.err.println(e.toString()); throw e; } catch (IOException e) { System.err.println(e.toString()); } finally { if ((logInfo & LOG_PRGRESS_TO_DIALOG) != 0) { f.dispose(); } if ((logInfo & LOG_PRGRESS_TO_SYSTEM_OUT) != 0) { System.out.println("\n 100% of " + jarName + " has been downloaded \n"); } if ((logInfo & LOG_PRGRESS_TO_LOGGER) != 0) { log.info(" 100% of " + jarName + " has been downloaded"); } } return fileName; }
From source file:org.kepler.sms.OntologyCatalog.java
/** * Description of the Method//from w w w . ja v a 2 s .c om */ protected void initialize(boolean init) { _namedOntModels.clear(); _libraryModels.clear(); _tagBarModels.clear(); if (init) { OntologyConfiguration.instance().initialize(); } // the default ontology is now "ontology.owl" // manager = OWLManager.createOWLOntologyManager(); OntologyConfiguration config = OntologyConfiguration.instance(); // for each ontology create a NamedOntModel from the for (Iterator iter = config.getFilePathNames(); iter.hasNext();) { String ontoFilePath = (String) iter.next(); if (isDebugging) log.debug(ontoFilePath); NamedOntModel mdl; try { mdl = new NamedOntModel(ontoFilePath); boolean success = mdl.initialize(); if (!success) { System.out.println("Could not instantiate model: '" + ontoFilePath + "'"); return; } mdl.setColor(config.getLibraryColor(ontoFilePath)); mdl.setLocal(config.isLibraryLocal(ontoFilePath)); if (isDebugging) log.debug(mdl.getNameSpace()); _namedOntModels.add(mdl); if (isDebugging) log.debug("_namedOntModels.add(" + mdl.getName() + ")"); if (config.isLibraryOntology(ontoFilePath)) { _libraryModels.add(mdl); if (isDebugging) log.debug("_libraryModels.add(" + mdl.getName() + ")"); } // TODO: This can be made more efficient. We don't need to // double // parse it. if (config.isTagBarOntology(ontoFilePath)) { _tagBarModels.add(mdl); if (isDebugging) log.debug("_tagBarModels.add(" + mdl.getName() + ")"); } } catch (Exception e) { JFrame f = new JFrame(); String errmsg = "Cannot locate ontology: " + ontoFilePath; JOptionPane.showMessageDialog(f, errmsg, "Configuration Error", JOptionPane.WARNING_MESSAGE); f.dispose(); } } }
From source file:org.notebook.gui.widget.GuiUtils.java
/** * Adds the dispose action with escape key. * //from w w w . ja v a 2s.c om * @param frame * the frame */ public static void addDisposeActionWithEscapeKey(final JFrame frame) { // Handle escape key to close the dialog KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); Action disposeAction = new AbstractAction() { private static final long serialVersionUID = 0L; @Override public void actionPerformed(ActionEvent e) { frame.dispose(); } }; frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); frame.getRootPane().getActionMap().put("ESCAPE", disposeAction); }
From source file:org.omegat.gui.align.AlignPanelController.java
private void closeFrame(JFrame frame) { if (confirmReset(frame)) { frame.setVisible(false);/* w w w . j a v a2 s. c om*/ confirmSaveSRX(frame); confirmSaveFilters(frame); frame.dispose(); } }
From source file:org.openscience.jmol.app.Jmol.java
private void dispose(JFrame f) { if (historyFile != null && scriptWindow != null) historyFile.addWindowInfo(SCRIPT_WINDOW_NAME, scriptWindow, null); if (historyFile != null && webExport != null) { WebExport.saveHistory();/* w w w .j a v a 2 s . c o m*/ WebExport.cleanUp(); } if (numWindows <= 1) { // Close Jmol report(GT._("Closing Jmol...")); // pluginManager.closePlugins(); System.exit(0); } else { numWindows--; viewer.setModeMouse(JmolConstants.MOUSE_NONE); try { f.dispose(); if (scriptWindow != null) { scriptWindow.dispose(); } } catch (Exception e) { // ignore } } }
From source file:org.squidy.nodes.ReacTIVision.java
public static void showErrorPopUp(String errorMessage) { //get screen size Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); //create pop up final JFrame frame = new JFrame(); frame.setResizable(false);//from w ww . j a v a2 s . c om frame.setAlwaysOnTop(true); frame.setUndecorated(true); JLabel text = new JLabel(" " + errorMessage + " "); frame.getContentPane().setBackground(Color.RED); text.setForeground(Color.WHITE); frame.add(text); frame.pack(); frame.setLocation((dim.width - frame.getWidth()) / 2, (dim.height - frame.getHeight()) / 2); frame.setVisible(true); frame.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent arg0) { frame.dispose(); } }); }
From source file:pcgen.gui2.dialog.OptionsPathDialog.java
public static String promptSettingsPath() { JFrame tempFrame = new JFrame("Select Settings Path"); tempFrame.setLocationRelativeTo(null); OptionsPathDialog dialog = new OptionsPathDialog(tempFrame); tempFrame.setVisible(true);/*from ww w . java 2s .c o m*/ dialog.setVisible(true); tempFrame.setVisible(false); tempFrame.dispose(); return dialog.selectedDir; }