Ejemplo n.º 1
0
  public static void main(String[] args) {

    // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    if (args.length == 1 && args[0].equals(TEST_FLAG)) {

      String[] filesToTest =
          new String[] {
            "examples/l22_cylsoma.swc",
            "examples/l22_sphersoma.swc",
            "examples/l22.swc",
            "examples/l22_small.swc",
            "examples/dCH-cobalt.CNG_small.swc",
            "examples/dCH-cobalt.CNG.swc"
          };

      for (String f : filesToTest) {
        String[] argsNew = new String[] {f, TEST_FLAG};
        SwingUtilities.invokeLater(new main(argsNew));
      }

    } else {
      SwingUtilities.invokeLater(new main(args));
    }
  }
 /**
  * Called whenever a full reply has been received from the 430. Also called with value=-1 if a
  * timeout occurs waiting for a reply or if a garbled reply is received.
  *
  * @param what The parameter that the value refers to. For one byte replies (ACK, NACK, or NACK0)
  *     the command that produced this reply.
  * @param value The value of the "what" parameter. For one byte replies, the <i>negated</i> value
  *     of that byte as an integer.
  */
 protected void processReply(String what, boolean value) {
   if (SwingUtilities.isEventDispatchThread()) {
     processReplyInEventThread(what, value);
   } else {
     SwingUtilities.invokeLater(new ReplyProcessor(what, value));
   }
 }
Ejemplo n.º 3
0
  @Override
  public final void mousePressed(final MouseEvent e) {
    if (!isEnabled() || !isFocusable()) return;

    requestFocusInWindow();
    caret(true);

    if (SwingUtilities.isMiddleMouseButton(e)) copy();

    final boolean shift = e.isShiftDown();
    final boolean selected = editor.selected();
    if (SwingUtilities.isLeftMouseButton(e)) {
      final int c = e.getClickCount();
      if (c == 1) {
        // selection mode
        if (shift) editor.startSelection(true);
        select(e.getPoint(), !shift);
      } else if (c == 2) {
        editor.selectWord();
      } else {
        editor.selectLine();
      }
    } else if (!selected) {
      select(e.getPoint(), true);
    }
  }
Ejemplo n.º 4
0
 protected void uninstallListeners(JFileChooser fc) {
   if (propertyChangeListener != null) {
     fc.removePropertyChangeListener(propertyChangeListener);
   }
   fc.removePropertyChangeListener(getModel());
   SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
   SwingUtilities.replaceUIActionMap(fc, null);
 }
Ejemplo n.º 5
0
 // Utility method to make sure a task is executed on the Swing display
 // thread.
 private void invokeAndWait(Runnable aRunnable) {
   if (!SwingUtilities.isEventDispatchThread()) {
     try {
       SwingUtilities.invokeAndWait(aRunnable);
     } catch (Exception e) {
       e.printStackTrace();
     }
   } else {
     aRunnable.run();
   }
 }
Ejemplo n.º 6
0
  protected void installListeners(JFileChooser fc) {
    propertyChangeListener = createPropertyChangeListener(fc);
    if (propertyChangeListener != null) {
      fc.addPropertyChangeListener(propertyChangeListener);
    }
    fc.addPropertyChangeListener(getModel());

    InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
    ActionMap actionMap = getActionMap();
    SwingUtilities.replaceUIActionMap(fc, actionMap);
  }
Ejemplo n.º 7
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());
              }
            });
      }
    }
  /**
   * Shows the given error message.
   *
   * @param text the text of the error
   */
  private void showErrorMessage(String text) {
    errorPane.setText(text);

    if (errorPane.getParent() == null) add(errorPane, BorderLayout.NORTH);

    SwingUtilities.getWindowAncestor(CreateSip2SipAccountForm.this).pack();
  }
Ejemplo n.º 9
0
 /**
  * When the worker needs to update the GUI we do so by queuing a Runnable for the event
  * dispatching thread with SwingUtilities.invokeLater(). In this case we're just changing the
  * progress bars value.
  */
 void updateStatus(final String t, final int i) {
   if (this.progressBar != null) {
     Runnable doSetProgressBarValue = () -> progressBar.setValue(i);
     SwingUtilities.invokeLater(doSetProgressBarValue);
   }
   this.currentState.setText(t);
 }
Ejemplo n.º 10
0
 /**
  * Assigns the specified list entries and selects the first entry.
  *
  * @param elements result elements
  * @param srch content search string
  */
 void setElements(final TokenSet elements, final String srch) {
   SwingUtilities.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           // set new values and selections
           final int is = elements.size();
           final String[] list = new String[is];
           for (int i = 0; i < is; i++) list[i] = Token.string(elements.key(i + 1));
           if (changed(list)) {
             // check which old values had been selected
             final List<String> values = getSelectedValuesList();
             final IntList il = new IntList();
             for (final String value : values) {
               final byte[] val = Token.token(value);
               for (int i = 0; i < is; i++) {
                 if (Token.eq(val, elements.key(i + 1))) {
                   il.add(i);
                   break;
                 }
               }
             }
             setListData(list);
             setSelectedIndices(il.finish());
           }
           search = srch;
         }
       });
 }
Ejemplo n.º 11
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);
  }
Ejemplo n.º 12
0
    public void mouseClicked(MouseEvent ev) {
      Window w = (Window) ev.getSource();
      Frame f = null;

      if (w instanceof Frame) {
        f = (Frame) w;
      } else {
        return;
      }

      Point convertedPoint = SwingUtilities.convertPoint(w, ev.getPoint(), getTitlePane());

      int state = f.getExtendedState();
      if (getTitlePane() != null && getTitlePane().contains(convertedPoint)) {
        if ((ev.getClickCount() % 2) == 0 && ((ev.getModifiers() & InputEvent.BUTTON1_MASK) != 0)) {
          if (f.isResizable()) {
            if ((state & Frame.MAXIMIZED_BOTH) != 0) {
              f.setExtendedState(state & ~Frame.MAXIMIZED_BOTH);
            } else {
              f.setExtendedState(state | Frame.MAXIMIZED_BOTH);
            }
            return;
          }
        }
      }
    }
Ejemplo n.º 13
0
  /** Reads the view from the specified uri. */
  @Override
  public void read(URI f, URIChooser chooser) throws IOException {
    try {
      final Drawing drawing = createDrawing();
      InputFormat inputFormat = drawing.getInputFormats().get(0);
      inputFormat.read(f, drawing, true);
      SwingUtilities.invokeAndWait(
          new Runnable() {

            @Override
            public void run() {
              view.getDrawing().removeUndoableEditListener(undo);
              view.setDrawing(drawing);
              view.getDrawing().addUndoableEditListener(undo);
              undo.discardAllEdits();
            }
          });
    } catch (InterruptedException e) {
      InternalError error = new InternalError();
      e.initCause(e);
      throw error;
    } catch (InvocationTargetException e) {
      InternalError error = new InternalError();
      e.initCause(e);
      throw error;
    }
  }
 public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
   HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
   final URL url = hyperlinkEvent.getURL();
   //             if (type == HyperlinkEvent.EventType.ENTERED) {
   //               Utility.debugPrintln("patterns","Entered " + url.toString());
   //             } else if (type == HyperlinkEvent.EventType.EXITED) {
   //               Utility.debugPrintln("patterns","Exited");
   //             }
   if (type == HyperlinkEvent.EventType.ACTIVATED) {
     // Utility.debugPrintln("Activated");
     Runnable runner =
         new Runnable() {
           public void run() {
             // Retain reference to original
             Document doc = editorPane.getDocument();
             try {
               editorPane.setPage(url);
             } catch (IOException ioException) {
               JOptionPane.showMessageDialog(
                   frame,
                   "Error following link " + url.toString(),
                   "GIPO Error",
                   JOptionPane.ERROR_MESSAGE);
               editorPane.setDocument(doc);
             }
           }
         };
     SwingUtilities.invokeLater(runner);
   }
 }
Ejemplo n.º 15
0
 /** Switch to a new Look&Feel */
 private void newLookAndFeel(String landf) {
   try {
     UIManager.setLookAndFeel(landf);
     SwingUtilities.updateComponentTreeUI(this);
   } catch (Exception e) {
     System.err.println(e);
   }
 }
Ejemplo n.º 16
0
 // Able to type stuff
 private void ableToType(final boolean tof) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           userText.setEditable(tof);
         }
       });
 }
Ejemplo n.º 17
0
 private void postInfo(final String message) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           showInfo(message);
         }
       });
 }
Ejemplo n.º 18
0
 private void setButtonLabel(final JButton button, final String label) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           button.setText(label);
         }
       });
 }
Ejemplo n.º 19
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);
    }
  }
Ejemplo n.º 20
0
 // Update chat window
 private void showMessage(final String text) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           chatWindow.append(text);
         }
       });
 }
Ejemplo n.º 21
0
 public static void setStepText(final int step, final String text) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           _stepLabels[step].setText(text);
         }
       });
 }
Ejemplo n.º 22
0
 public static void main(String[] args) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           new MainWindow().setVisible(true);
         }
       });
 }
Ejemplo n.º 23
0
 /**
  * Decrease the segment count in the according row of the main window download table.
  *
  * @param filename The filename of the row to update in main window
  */
 private void decrSegCount(final String filename) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           mainApp.decrSegCount(filename);
         }
       });
 }
Ejemplo n.º 24
0
 private void updateTextArea(final String text) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           jTextArea.append(text);
         }
       });
 }
Ejemplo n.º 25
0
  public static void main(String[] args) {
    //      args = new String[]{"nothing=junk"};
    RSF par = new RSF(args);
    // RSFFrame sf = new RSFFrame();
    //
    //
    //
    //

    ArrayList<String> cubes = new ArrayList<String>();
    ArrayList<String> points = new ArrayList<String>();
    ArrayList<String> lines = new ArrayList<String>();
    for (String arg : args) {
      if (arg.contains("cube")) {
        String cube = par.getString(arg.split("=")[0], "");
        System.err.printf("Found cube: %s\n", cube);
        cubes.add(cube);
      } else if (arg.contains("point")) {
        String point = par.getString(arg.split("=")[0], "");
        System.err.printf("Found point: %s\n", point);
        points.add(point);
      } else if (arg.contains("line")) {
        String line = par.getString(arg.split("=")[0], "");
        System.err.printf("Found line: %s\n", line);
        lines.add(line);
      }
    }

    final String[] cubeNames = new String[cubes.size()];
    for (int i = 0; i < cubes.size(); ++i) {
      cubeNames[i] = cubes.get(i);
    }

    final String[] lineNames = new String[lines.size()];
    for (int i = 0; i < lines.size(); ++i) {
      lineNames[i] = lines.get(i);
    }
    final String[] pointNames = new String[points.size()];
    for (int i = 0; i < points.size(); ++i) {
      pointNames[i] = points.get(i);
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            RSFFrame frame = new RSFFrame();
            for (String name : cubeNames) {
              frame.addRSFCube(name);
            }
            for (String name : lineNames) {
              frame.addRSFLine(name);
            }
            for (String name : pointNames) {
              frame.addRSFPoint(name);
            }
          }
        });
  }
Ejemplo n.º 26
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();
         }
       });
 }
Ejemplo n.º 27
0
 public void showCommunicationErrorDialogLater(
     final Exception e, final String message, final Object... args) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           showCommunicationErrorDialog(e, message, args);
         }
       });
 }
Ejemplo n.º 28
0
 /*
  *  Create a BufferedImage for AWT components.
  *
  *  @param	 component AWT component to create image from
  *  @param	 fileName name of file to be created or null
  *  @return	image the image for the given region
  *  @exception AWTException see Robot class constructors
  *  @exception IOException if an error occurs during writing
  */
 public static BufferedImage createImage(Component component, String fileName)
     throws AWTException, IOException {
   Point p = new Point(0, 0);
   SwingUtilities.convertPointToScreen(p, component);
   Rectangle region = component.getBounds();
   region.x = p.x;
   region.y = p.y;
   return ScreenCapture.createImage(region, fileName);
 }
 public static void main(String[] args) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
           showAsFrame(new IntelliHintsDemo());
         }
       });
 }
Ejemplo n.º 30
0
  @Override
  public final void mouseDragged(final MouseEvent e) {
    if (!SwingUtilities.isLeftMouseButton(e)) return;

    // selection mode
    select(e.getPoint(), false);
    final int y = Math.max(20, Math.min(e.getY(), getHeight() - 20));
    if (y != e.getY()) scroll.pos(scroll.pos() + e.getY() - y);
  }