List of usage examples for javax.swing JTextArea setText
@BeanProperty(bound = false, description = "the text of this component") public void setText(String t)
TextComponent
to the specified text. From source file:org.broad.igv.track.TrackMenuUtils.java
public static JMenuItem getRemoveMenuItem(final Collection<Track> selectedTracks) { boolean multiple = selectedTracks.size() > 1; JMenuItem item = new JMenuItem("Remove Track" + (multiple ? "s" : "")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (selectedTracks.isEmpty()) { return; }/*from www.ja v a 2s. c o m*/ StringBuffer buffer = new StringBuffer(); for (Track track : selectedTracks) { buffer.append("\n\t"); buffer.append(track.getName()); } String deleteItems = buffer.toString(); JTextArea textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); textArea.setText(deleteItems); JOptionPane optionPane = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_OPTION); optionPane.setPreferredSize(new Dimension(550, 500)); JDialog dialog = optionPane.createDialog(IGV.getMainFrame(), "Remove The Following Tracks"); dialog.setVisible(true); Object choice = optionPane.getValue(); if ((choice == null) || (JOptionPane.YES_OPTION != ((Integer) choice).intValue())) { return; } IGV.getInstance().removeTracks(selectedTracks); IGV.getInstance().doRefresh(); } }); return item; }
From source file:org.ecoinformatics.seek.datasource.eml.eml2.Eml200DataSource.java
public void preview() { String displayText = "PREVIEW NOT IMPLEMENTED FOR THIS ACTOR"; JFrame frame = new JFrame(this.getName() + " Preview"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JScrollPane scrollPane = null; JTable jtable = null;/*from ww w .j ava 2 s . c o m*/ try { // set everything up (datawise) this.initialize(); // check the entity - different displays for different formats // Compressed file if (this._selectedTableEntity.getHasGZipDataFile() || this._selectedTableEntity.getHasTarDataFile() || this._selectedTableEntity.getHasZipDataFile()) { displayText = "Selected entity is a compressed file. \n" + "Preview not implemented for output format: " + this.dataOutputFormat.getExpression(); if (this._dataOutputFormat instanceof Eml200DataOutputFormatUnzippedFileName) { Eml200DataOutputFormatUnzippedFileName temp = (Eml200DataOutputFormatUnzippedFileName) this._dataOutputFormat; displayText = "Files: \n"; for (int i = 0; i < temp.getTargetFilePathInZip().length; i++) { displayText += temp.getTargetFilePathInZip()[i] + "\n"; } } } // SPATIALRASTERENTITY or SPATIALVECTORENTITY are "image entities" // as far as the parser is concerned else if (this._selectedTableEntity.getIsImageEntity()) { // use the content of the cache file displayText = new String(this.getSelectedCachedDataItem().getData()); } // TABLEENTITY else { // holds the rows for the table on disk with some in memory String vectorTempDir = DotKeplerManager.getInstance().getCacheDirString(); // + "vector" // + File.separator; PersistentVector rowData = new PersistentVector(vectorTempDir); // go through the rows and add them to the persistent vector // model Vector row = this.gotRowVectorFromSource(); while (!row.isEmpty()) { rowData.addElement(row); row = this.gotRowVectorFromSource(); } // the column headers for the table Vector columns = this.getColumns(); /* * with java 6, there is a more built-in sorting mechanism that * does not require the custom table sorter class */ TableModel tableModel = new PersistentTableModel(rowData, columns); TableSorter tableSorter = new TableSorter(tableModel); jtable = new JTable(tableSorter) { // make this table read-only by overriding the default // implementation public boolean isCellEditable(int row, int col) { return false; } }; // sets up the listeners for sorting and such tableSorter.setTableHeader(jtable.getTableHeader()); // set up the listener to trash persisted data when done frame.addWindowListener(new PersistentTableModelWindowListener((PersistentTableModel) tableModel)); } } catch (Exception e) { displayText = "Problem encountered while generating preview: \n" + e.getMessage(); log.error(displayText); e.printStackTrace(); } // make sure there is a jtable, otherwise show just a text version of // the data if (jtable != null) { jtable.setVisible(true); // jtable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); scrollPane = new JScrollPane(jtable); } else { JTextArea textArea = new JTextArea(); textArea.setColumns(80); textArea.setText(displayText); textArea.setVisible(true); scrollPane = new JScrollPane(textArea); } scrollPane.setVisible(true); panel.setOpaque(true); panel.add(scrollPane, BorderLayout.CENTER); frame.setContentPane(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:org.executequery.gui.editor.LobDataItemViewerPanel.java
private void setTextAreaText(JTextArea textArea, String text) { textArea.setText(text); textArea.setCaretPosition(0); }
From source file:org.formic.wizard.step.gui.TemplateStep.java
/** * {@inheritDoc}//from w ww.j a va 2 s . c om * @see org.formic.wizard.WizardStep#displayed() */ public void displayed() { if (content instanceof JEditorPane) { JEditorPane editor = (JEditorPane) content; editor.setText(action.processTemplate(html)); editor.setCaretPosition(0); } else { JTextArea area = (JTextArea) content; area.setText(action.processTemplate(text)); area.setCaretPosition(0); } }
From source file:org.genedb.jogra.plugins.TermRationaliser.java
private Box createRationaliserPanel(final String name, final RationaliserJList rjlist) { int preferredHeight = 500; //change accordingly int preferredWidth = 500; Toolkit tk = Toolkit.getDefaultToolkit(); Dimension size = tk.getScreenSize(); int textboxHeight = 10; //change accordingly int textboxWidth = size.width; Box box = Box.createVerticalBox(); box.add(new JLabel(name)); JTextField searchField = new JTextField(20); //Search field on top /* We don't want this textfield's height to expand when * the Rationaliser is dragged to exapnd. So we set it's * height to what we want and the width to the width of * the screen /*from w ww . j a va2s . co m*/ */ searchField.setMaximumSize(new Dimension(textboxWidth, textboxHeight)); rjlist.installJTextField(searchField); box.add(searchField); JScrollPane scrollPane = new JScrollPane(); //scroll pane scrollPane.setViewportView(rjlist); scrollPane.setPreferredSize(new Dimension(preferredWidth, preferredHeight)); box.add(scrollPane); TitledBorder sysidBorder = BorderFactory.createTitledBorder("Systematic IDs"); //systematic ID box sysidBorder.setTitleColor(Color.DARK_GRAY); final JTextArea idField = new JTextArea(1, 1); idField.setMaximumSize(new Dimension(textboxWidth, textboxHeight)); idField.setEditable(false); idField.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY)); idField.setForeground(Color.DARK_GRAY); JScrollPane scroll = new JScrollPane(idField); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); Box sysidBox = Box.createVerticalBox(); sysidBox.add(scroll /*idField*/); sysidBox.setBorder(sysidBorder); box.add(sysidBox); rjlist.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { Term highlightedTerm = (Term) rjlist.getSelectedValue(); if (highlightedTerm != null) { /* For each list, call the relevant methods * to get the systematic IDs. Then for the * right list, add the term name in the * text box below */ if (name.equals(FROM_LIST_NAME)) { idField.setText(StringUtils.collectionToCommaDelimitedString( termService.getSystematicIDs(highlightedTerm, selectedTaxons))); } else if (name.equals(TO_LIST_NAME)) { idField.setText(StringUtils.collectionToCommaDelimitedString( termService.getSystematicIDs(highlightedTerm, null))); /* We allow the user to edit the term name */ textField.setText(highlightedTerm.getName()); } } } }); return box; }
From source file:org.gtdfree.GTDFree.java
/** * This method initializes aboutDialog * // w w w . j a va 2 s .co m * @return javax.swing.JDialog */ private JDialog getAboutDialog() { if (aboutDialog == null) { aboutDialog = new JDialog(getJFrame(), true); aboutDialog.setTitle(Messages.getString("GTDFree.About.Free")); //$NON-NLS-1$ Image i = ApplicationHelper.loadImage(ApplicationHelper.icon_name_large_logo); //$NON-NLS-1$ ImageIcon ii = new ImageIcon(i); JTabbedPane jtp = new JTabbedPane(); JPanel jp = new JPanel(); jp.setLayout(new GridBagLayout()); JLabel jl = new JLabel("GTD-Free", ii, SwingConstants.CENTER); //$NON-NLS-1$ jl.setIconTextGap(22); jl.setFont(jl.getFont().deriveFont((float) 24)); jp.add(jl, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(11, 11, 11, 11), 0, 0)); String s = "Version " + ApplicationHelper.getVersion(); //$NON-NLS-1$ jp.add(new JLabel(s, SwingConstants.CENTER), new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(4, 11, 4, 11), 0, 0)); s = Messages.getString("GTDFree.About.DBType") //$NON-NLS-1$ + getEngine().getGTDModel().getDataRepository().getDatabaseType(); jp.add(new JLabel(s, SwingConstants.CENTER), new GridBagConstraints(0, 2, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(11, 11, 2, 11), 0, 0)); s = Messages.getString("GTDFree.About.DBloc") + getEngine().getDataFolder(); //$NON-NLS-1$ jp.add(new JLabel(s, SwingConstants.CENTER), new GridBagConstraints(0, 3, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2, 11, 4, 11), 0, 0)); jp.add(new JLabel("Copyright 2008,2009 ikesan@users.sourceforge.net", SwingConstants.CENTER), //$NON-NLS-1$ new GridBagConstraints(0, 4, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(11, 11, 11, 11), 0, 0)); jtp.addTab("About", jp); //$NON-NLS-1$ jp = new JPanel(); jp.setLayout(new GridBagLayout()); TableModel tm = new AbstractTableModel() { private static final long serialVersionUID = -8449423008172417278L; private String[] props; private String[] getProperties() { if (props == null) { props = System.getProperties().keySet().toArray(new String[System.getProperties().size()]); Arrays.sort(props); } return props; } @Override public String getColumnName(int column) { switch (column) { case 0: return Messages.getString("GTDFree.About.Prop"); //$NON-NLS-1$ case 1: return Messages.getString("GTDFree.About.Val"); //$NON-NLS-1$ default: return null; } } public int getColumnCount() { return 2; } public int getRowCount() { return getProperties().length; } public Object getValueAt(int rowIndex, int columnIndex) { switch (columnIndex) { case 0: return getProperties()[rowIndex]; case 1: return System.getProperty(getProperties()[rowIndex]); default: return null; } } }; JTable jt = new JTable(tm); jp.add(new JScrollPane(jt), new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(11, 11, 11, 11), 0, 0)); jtp.addTab(Messages.getString("GTDFree.About.SysP"), jp); //$NON-NLS-1$ jp = new JPanel(); jp.setLayout(new GridBagLayout()); JTextArea ta = new JTextArea(); ta.setEditable(false); ta.setText(ApplicationHelper.loadLicense()); ta.setCaretPosition(0); jp.add(new JScrollPane(ta), new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(11, 11, 11, 11), 0, 0)); jtp.addTab("License", jp); //$NON-NLS-1$ aboutDialog.setContentPane(jtp); aboutDialog.setSize(550, 300); //aboutDialog.pack(); aboutDialog.setLocationRelativeTo(getJFrame()); } return aboutDialog; }
From source file:org.jets3t.gui.UserInputFields.java
/** * Builds a user input panel matching the fields specified in the uploader.properties file. * * @param fieldsPanel/*from w w w . j a v a2 s . c o m*/ * the panel component to add prompt and user input components to. * @param uploaderProperties * properties specific to the Uploader application that includes the field.* settings * necessary to build the User Inputs screen. * * @return * true if there is at least one valid user input field, false otherwise. */ public boolean buildFieldsPanel(JPanel fieldsPanel, Jets3tProperties uploaderProperties) { int fieldIndex = 0; for (int fieldNo = 0; fieldNo < 100; fieldNo++) { String fieldName = uploaderProperties.getStringProperty("field." + fieldNo + ".name", null); String fieldType = uploaderProperties.getStringProperty("field." + fieldNo + ".type", null); String fieldPrompt = uploaderProperties.getStringProperty("field." + fieldNo + ".prompt", null); String fieldOptions = uploaderProperties.getStringProperty("field." + fieldNo + ".options", null); String fieldDefault = uploaderProperties.getStringProperty("field." + fieldNo + ".default", null); if (fieldName == null) { log.debug("No field with index number " + fieldNo); continue; } else { if (fieldType == null || fieldPrompt == null) { log.warn("Field '" + fieldName + "' missing .type or .prompt properties"); continue; } if ("message".equals(fieldType)) { JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); } else if ("radio".equals(fieldType)) { if (fieldOptions == null) { log.warn( "Radio button field '" + fieldName + "' is missing the required .options property"); continue; } JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); JPanel optionsPanel = skinsFactory.createSkinnedJPanel("OptionsPanel"); optionsPanel.setLayout(new GridBagLayout()); int columnOffset = 0; ButtonGroup buttonGroup = new ButtonGroup(); StringTokenizer st = new StringTokenizer(fieldOptions, ","); while (st.hasMoreTokens()) { String option = st.nextToken(); JRadioButton radioButton = skinsFactory.createSkinnedJRadioButton(fieldName); radioButton.setText(option); buttonGroup.add(radioButton); if (fieldDefault != null && fieldDefault.equals(option)) { // This option is the default one. radioButton.setSelected(true); } else if (buttonGroup.getButtonCount() == 1) { // Make first button the default. radioButton.setSelected(true); } optionsPanel.add(radioButton, new GridBagConstraints(columnOffset++, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0)); } fieldsPanel.add(optionsPanel, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsNone, 0, 0)); userInputComponentsMap.put(fieldName, buttonGroup); } else if ("selection".equals(fieldType)) { if (fieldOptions == null) { log.warn( "Radio button field '" + fieldName + "' is missing the required .options property"); continue; } JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); JComboBox comboBox = skinsFactory.createSkinnedJComboBox(fieldName); StringTokenizer st = new StringTokenizer(fieldOptions, ","); while (st.hasMoreTokens()) { String option = st.nextToken(); comboBox.addItem(option); } if (fieldDefault != null) { comboBox.setSelectedItem(fieldDefault); } fieldsPanel.add(comboBox, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); userInputComponentsMap.put(fieldName, comboBox); } else if ("text".equals(fieldType)) { JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); JTextField textField = skinsFactory.createSkinnedJTextField(fieldName); if (fieldDefault != null) { textField.setText(fieldDefault); } fieldsPanel.add(textField, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); userInputComponentsMap.put(fieldName, textField); } else if ("password".equals(fieldType)) { JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); JPasswordField passwordField = skinsFactory.createSkinnedJPasswordField(fieldName); if (fieldDefault != null) { passwordField.setText(fieldDefault); } fieldsPanel.add(passwordField, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); userInputComponentsMap.put(fieldName, passwordField); } else if (fieldType.equals("textarea")) { JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 2, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); JTextArea textArea = skinsFactory.createSkinnedJTextArea(fieldName); textArea.setLineWrap(true); if (fieldDefault != null) { textArea.setText(fieldDefault); } JScrollPane scrollPane = skinsFactory.createSkinnedJScrollPane(fieldName); scrollPane.setViewportView(textArea); fieldsPanel.add(scrollPane, new GridBagConstraints(0, fieldIndex++, 2, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, insetsDefault, 0, 0)); userInputComponentsMap.put(fieldName, textArea); } else { log.warn("Unrecognised .type setting for field '" + fieldName + "'"); } } } return isUserInputFieldsAvailable(); }
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);// ww w. ja v a2 s. c om 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;// w w w. j a va 2s .c om 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.kchine.rpf.PoolUtils.java
public static void redirectIO() { final JTextArea area = new JTextArea(); JFrame f = new JFrame("out/err"); f.add(new JScrollPane(area), BorderLayout.CENTER); f.pack();//from w w w. ja v a 2 s. co m f.setVisible(true); f.setSize(500, 500); f.setLocation(100, 100); PrintStream ps = new PrintStream(new OutputStream() { public void write(final int b) throws IOException { SwingUtilities.invokeLater(new Runnable() { public void run() { area.setText(area.getText() + new String(new byte[] { (byte) b })); } }); SwingUtilities.invokeLater(new Runnable() { public void run() { area.setCaretPosition(area.getText().length()); area.repaint(); } }); } public void write(final byte[] b) throws IOException { SwingUtilities.invokeLater(new Runnable() { public void run() { area.setText(area.getText() + new String(b)); } }); SwingUtilities.invokeLater(new Runnable() { public void run() { area.setCaretPosition(area.getText().length()); area.repaint(); } }); } public void write(byte[] b, int off, int len) throws IOException { final byte[] r = new byte[len]; for (int i = 0; i < len; ++i) r[i] = b[off + i]; SwingUtilities.invokeLater(new Runnable() { public void run() { area.setText(area.getText() + new String(r)); } }); SwingUtilities.invokeLater(new Runnable() { public void run() { area.setCaretPosition(area.getText().length()); area.repaint(); } }); } }); System.setOut(ps); System.setErr(ps); }