@Override public void run() { try { // initialize the statusbar status.removeAll(); JProgressBar progress = new JProgressBar(); progress.setMinimum(0); progress.setMaximum((int) f.length()); status.add(progress); status.revalidate(); // try to start reading Reader in = new FileReader(f); char[] buff = new char[4096]; int nch; while ((nch = in.read(buff, 0, buff.length)) != -1) { doc.insertString(doc.getLength(), new String(buff, 0, nch), null); progress.setValue(progress.getValue() + nch); } } catch (IOException e) { final String msg = e.getMessage(); SwingUtilities.invokeLater( new Runnable() { public void run() { JOptionPane.showMessageDialog( getFrame(), "Could not open file: " + msg, "Error opening file", JOptionPane.ERROR_MESSAGE); } }); } catch (BadLocationException e) { System.err.println(e.getMessage()); } doc.addUndoableEditListener(undoHandler); // we are done... get rid of progressbar status.removeAll(); status.revalidate(); resetUndoManager(); if (elementTreePanel != null) { SwingUtilities.invokeLater( new Runnable() { public void run() { elementTreePanel.setEditor(getEditor()); } }); } }
/** Update the look and feel of the toolbar. */ public void updateLAF() { if (pbOpen != null) { pbOpen.setIcon(UIImages.get(OPEN_ICON)); } if (pbClose != null) { pbClose.setIcon(UIImages.get(CLOSE_ICON)); } pbCut.setIcon(UIImages.get(CUT_ICON)); pbCopy.setIcon(UIImages.get(COPY_ICON)); pbPaste.setIcon(UIImages.get(PASTE_ICON)); pbDelete.setIcon(UIImages.get(DELETE_ICON)); pbUndo.setIcon(UIImages.get(UNDO_ICON)); pbRedo.setIcon(UIImages.get(REDO_ICON)); pbShowBackHistory.setIcon(UIImages.get(PREVIOUS_ICON)); pbBack.setIcon(UIImages.get(BACK_ICON)); pbForward.setIcon(UIImages.get(FORWARD_ICON)); pbShowForwardHistory.setIcon(UIImages.get(NEXT_ICON)); pbSearch.setIcon(UIImages.get(SEARCH_ICON)); pbHelp.setIcon(UIImages.get(HELP_ICON)); if (FormatProperties.imageRollover) { pbImageRollover.setIcon(UIImages.get(IMAGE_ROLLOVER_ICON)); } else { pbImageRollover.setIcon(UIImages.get(IMAGE_ROLLOVEROFF_ICON)); } if (tbrToolBar != null) SwingUtilities.updateComponentTreeUI(tbrToolBar); }
/** Display the forwards window history in a menu. */ private void onShowForwardHistory() { UIScrollableMenu hist = new UIScrollableMenu( LanguageProperties.getString( LanguageProperties.TOOLBARS_BUNDLE, "UIToolBarMain.forwardHistory"), 0); //$NON-NLS-1$ Vector views = history.getForwardHistory(); int currentIndex = history.getCurrentPosition(); int count = views.size(); if (count == 0) return; JMenuItem item = null; for (int i = 0; i < count; i++) { View view = (View) views.elementAt(i); item = new JMenuItem(view.getLabel()); final View fview = view; final int fi = (currentIndex + 1) + i; item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (history.goToHistoryItem(fi)) oParent.addViewToDesktop(fview, fview.getLabel()); } }); hist.add(item); } JPopupMenu pop = hist.getPopupMenu(); pop.pack(); Point loc = pbShowForwardHistory.getLocation(); Dimension size = pbShowForwardHistory.getSize(); Dimension popsize = hist.getPreferredSize(); Point finalP = SwingUtilities.convertPoint(tbrToolBar.getParent(), loc, oParent.getDesktop()); int x = 0; int y = 0; if (oManager.getLeftToolBarController().containsBar(tbrToolBar)) { x = finalP.x + size.width; y = finalP.y; } else if (oManager.getRightToolBarController().containsBar(tbrToolBar)) { x = finalP.x - popsize.width; y = finalP.y; } else if (oManager.getTopToolBarController().containsBar(tbrToolBar)) { x = finalP.x; y = finalP.y + size.width; } else if (oManager.getBottomToolBarController().containsBar(tbrToolBar)) { x = finalP.x; y = finalP.y - popsize.height; } hist.setPopupMenuVisible(true); pop.show(oParent.getDesktop(), x, y); }
@Override @SuppressWarnings("SleepWhileHoldingLock") public void run() { try { // initialize the statusbar status.removeAll(); JProgressBar progress = new JProgressBar(); progress.setMinimum(0); progress.setMaximum(doc.getLength()); status.add(progress); status.revalidate(); // start writing Writer out = new FileWriter(f); Segment text = new Segment(); text.setPartialReturn(true); int charsLeft = doc.getLength(); int offset = 0; while (charsLeft > 0) { doc.getText(offset, Math.min(4096, charsLeft), text); out.write(text.array, text.offset, text.count); charsLeft -= text.count; offset += text.count; progress.setValue(offset); try { Thread.sleep(10); } catch (InterruptedException e) { Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, e); } } out.flush(); out.close(); } catch (IOException e) { final String msg = e.getMessage(); SwingUtilities.invokeLater( new Runnable() { public void run() { JOptionPane.showMessageDialog( getFrame(), "Could not save file: " + msg, "Error saving file", JOptionPane.ERROR_MESSAGE); } }); } catch (BadLocationException e) { System.err.println(e.getMessage()); } // we are done... get rid of progressbar status.removeAll(); status.revalidate(); }
public void adjustmentValueChanged(final AdjustmentEvent evt) { if (!scrollBarsInitialized) return; // If this is not done, mousePressed events accumilate // and the result is that scrolling doesn't stop after // the mouse is released SwingUtilities.invokeLater( new Runnable() { public void run() { if (evt.getAdjustable() == vertical) setFirstLine(vertical.getValue()); else setHorizontalOffset(-horizontal.getValue()); } }); }
public static void main(String[] args) throws Exception { if (args.length > 0 && args[0].equals(EXIT_AFTER_PAINT)) { exitAfterFirstPaint = true; } SwingUtilities.invokeAndWait( new Runnable() { public void run() { JFrame frame = new JFrame(); frame.setTitle(resources.getString("Title")); frame.setBackground(Color.lightGray); frame.getContentPane().setLayout(new BorderLayout()); Notepad notepad = new Notepad(); frame.getContentPane().add("Center", notepad); frame.setJMenuBar(notepad.createMenubar()); frame.addWindowListener(new AppCloser()); frame.pack(); frame.setSize(500, 600); frame.setVisible(true); } }); }