Exemplo n.º 1
0
    @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());
              }
            });
      }
    }
Exemplo n.º 2
0
  private void addExternalItem(final FcpPersistentPut uploadRequest) {
    final FrostUploadItem ulItem = new FrostUploadItem();
    ulItem.setGqIdentifier(uploadRequest.getIdentifier());
    ulItem.setExternal(true);
    // direct uploads maybe have no filename, use identifier
    String fileName = uploadRequest.getFilename();
    if (fileName == null) {
      fileName = uploadRequest.getIdentifier();
    } else if (fileName.indexOf('/') > -1 || fileName.indexOf('\\') > -1) {
      // filename contains directories, use only filename
      final String stmp = new File(fileName).getName();
      if (stmp.length() > 0) {
        fileName = stmp; // use plain filename
      }
    }
    ulItem.setFile(new File(fileName));
    ulItem.setFileName(fileName);
    ulItem.setFileSize(uploadRequest.getFileSize());
    ulItem.setPriority(uploadRequest.getPriority());

    ulItem.setState(FrostUploadItem.STATE_PROGRESS);
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            uploadModel.addExternalItem(ulItem);
          }
        });
    applyState(ulItem, uploadRequest);
  }
Exemplo n.º 3
0
  /** @see nl.lxtreme.ols.api.devices.CaptureCallback#captureStarted(int, int, int) */
  @Override
  public synchronized void captureStarted(
      final int aSampleRate, final int aChannelCount, final int aChannelMask) {
    final Runnable runner =
        new Runnable() {
          @Override
          public void run() {
            updateActions();
          }
        };

    if (SwingUtilities.isEventDispatchThread()) {
      runner.run();
    } else {
      SwingUtilities.invokeLater(runner);
    }
  }
Exemplo n.º 4
0
 /** Dispatches a request to repaint the entire main frame. */
 private void repaintMainFrame() {
   SwingUtilities.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           ClientController.this.mainFrame.repaint();
         }
       });
 }
Exemplo n.º 5
0
 public static void main(String args[]) {
   // Create the frame on the event dispatching thread.
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           new Slideshow(imagePaths);
         }
       });
 }
Exemplo n.º 6
0
 public void valueChanged(TreeSelectionEvent e) {
   Node node = (Node) getTree().getLastSelectedPathComponent();
   if (getSheet() == null) return;
   if (node == null) {
     node = (Node) getTree().getPathForRow(0).getLastPathComponent();
   }
   nextToSetTo = node;
   if (getSheet().getObject() != nextToSetTo) {
     SwingUtilities.invokeLater(setSheetObject);
   }
 }
Exemplo n.º 7
0
    @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();
    }
Exemplo n.º 8
0
  public void disconnected() {
    isConnected = false;

    MainFrame.getInstance().setDisconnected();

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            uploadModel.removeExternalUploads();
            downloadModel.removeExternalDownloads();
          }
        });
    logger.severe("disconnected!");
  }
Exemplo n.º 9
0
  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);
          }
        });
  }
Exemplo n.º 10
0
 public void persistentRequestRemoved(final FcpPersistentGet downloadRequest) {
   if (downloadModelItems.containsKey(downloadRequest.getIdentifier())) {
     final FrostDownloadItem dlItem = downloadModelItems.get(downloadRequest.getIdentifier());
     if (dlItem.isExternal()) {
       SwingUtilities.invokeLater(
           new Runnable() {
             public void run() {
               List<FrostDownloadItem> itemList = new ArrayList<FrostDownloadItem>();
               itemList.add(dlItem);
               downloadModel.removeItems(itemList);
             }
           });
     } else {
       if (dlItem.isInternalRemoveExpected()) {
         dlItem.setInternalRemoveExpected(false); // clear flag
       } else if (dlItem.getState() != FrostDownloadItem.STATE_DONE) {
         dlItem.setEnabled(false);
         dlItem.setState(FrostDownloadItem.STATE_FAILED);
         dlItem.setErrorCodeDescription("Disappeared from global queue");
       }
     }
   }
 }