/**
   * Sets the mute status icon to the status panel.
   *
   * @param isMute indicates if the call with this peer is muted
   */
  public void setMute(final boolean isMute) {
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              setMute(isMute);
            }
          });
      return;
    }

    if (isMute) {
      muteStatusLabel.setIcon(new ImageIcon(ImageLoader.getImage(ImageLoader.MUTE_STATUS_ICON)));
      muteStatusLabel.setBorder(BorderFactory.createEmptyBorder(2, 3, 2, 3));
    } else {
      muteStatusLabel.setIcon(null);
      muteStatusLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    }

    // Update input volume control button state to reflect the current
    // mute status.
    if (localLevel.isSelected() != isMute) localLevel.setSelected(isMute);

    this.revalidate();
    this.repaint();
  }
  private void setAllSlidersComp(final String[] data) {

    if (SwingUtilities.isEventDispatchThread()) {
      Main_frame.compressor_attack_slider.setValue(Integer.parseInt(data[8]));
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              Main_frame.compressor_attack_slider.setValue(Integer.parseInt(data[8]));
            }
          });
    }

    if (SwingUtilities.isEventDispatchThread()) {
      Main_frame.compressor_decay_slider.setValue(Integer.parseInt(data[9]));
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              Main_frame.compressor_decay_slider.setValue(Integer.parseInt(data[9]));
            }
          });
    }
    if (SwingUtilities.isEventDispatchThread()) {
      Main_frame.compressor_ratio_slider.setValue(Integer.parseInt(data[10]));
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              Main_frame.compressor_ratio_slider.setValue(Integer.parseInt(data[10]));
            }
          });
    }

    if (SwingUtilities.isEventDispatchThread()) {
      Main_frame.compressor_threshold_slider.setValue(Integer.parseInt(data[11]));
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              Main_frame.compressor_threshold_slider.setValue(Integer.parseInt(data[11]));
            }
          });
    }

    if (SwingUtilities.isEventDispatchThread()) {
      Main_frame.compressor_button.setSelected(Integer.parseInt(data[7]) == 1 ? true : false);
      Main_frame.compressor_button.setText(Integer.parseInt(data[7]) == 1 ? "ON" : "OFF");
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              Main_frame.compressor_button.setSelected(
                  Integer.parseInt(data[7]) == 1 ? true : false);
              Main_frame.compressor_button.setText(Integer.parseInt(data[7]) == 1 ? "ON" : "OFF");
            }
          });
    }
  }
  private void setAllSlidersDelay(final String[] data) {

    if (SwingUtilities.isEventDispatchThread()) {
      Main_frame.delay_time_slider.setValue(Integer.parseInt(data[13]));
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              Main_frame.delay_time_slider.setValue(Integer.parseInt(data[13]));
            }
          });
    }

    if (SwingUtilities.isEventDispatchThread()) {
      Main_frame.delay_feedback_slider.setValue(Integer.parseInt(data[14]));
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              Main_frame.delay_feedback_slider.setValue(Integer.parseInt(data[14]));
            }
          });
    }

    if (SwingUtilities.isEventDispatchThread()) {
      Main_frame.delay_mix_slider.setValue(Integer.parseInt(data[15]));
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              Main_frame.delay_mix_slider.setValue(Integer.parseInt(data[15]));
            }
          });
    }

    if (SwingUtilities.isEventDispatchThread()) {
      Main_frame.delay_button.setSelected(Integer.parseInt(data[12]) == 1 ? true : false);
      Main_frame.delay_button.setText(Integer.parseInt(data[12]) == 1 ? "ON" : "OFF");
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              Main_frame.delay_button.setSelected(Integer.parseInt(data[12]) == 1 ? true : false);
              Main_frame.delay_button.setText(Integer.parseInt(data[12]) == 1 ? "ON" : "OFF");
            }
          });
    }
  }
  protected void executeScript(final String script) {
    if (webBrowser == null || script.length() == 0) return;

    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              webBrowser.runInSequence(
                  new Runnable() {
                    public void run() {
                      webBrowser.executeJavascript(script);
                    }
                  });
              logJavaScript(script, null);
            }
          });
    } else {
      webBrowser.runInSequence(
          new Runnable() {
            public void run() {
              webBrowser.executeJavascript(script);
            }
          });
      logJavaScript(script, null);
    }
  }
    public static void showExceptionDialog(Component owner, String title, String message, Exception exc) {
        if (SwingUtilities.isEventDispatchThread()) {
            ExceptionDialog eDlg;
            if (!(owner instanceof Window)) {
                if (owner != null) {
                    owner = SwingUtilities.getWindowAncestor(owner);
                }
                if (owner == null) {
                    owner = Launcher2.application.getFrame();
                }
            }


            if (owner instanceof Dialog) {
                eDlg = new ExceptionDialog((Dialog)owner, title, message, exc);
            } else if (owner instanceof Frame) {
                eDlg = new ExceptionDialog((Frame)owner, title, message, exc);
            } else {
                JOptionPane.showMessageDialog(owner, message + "\n" + exc.getMessage(), Utils._("Error"), JOptionPane.ERROR_MESSAGE);
                return;
            }
            eDlg.setVisible(true);
        } else {
            try {
                SwingUtilities.invokeAndWait(new DisplayRunnable(owner, title, message, exc));
            } catch (InterruptedException e) {
                log.log(Level.WARNING, "Error showing exception dialog.", e);
            } catch (InvocationTargetException e) {
                log.log(Level.WARNING, "Error showing exception dialog.", e);
            }
        }
    }
 public void removeAllIconRenderers(Collection<EditorMessageIconRenderer> renderers) {
   assert SwingUtilities.isEventDispatchThread()
       : "LeftEditorHighlighter.removeAllIconRenderers() should be called in eventDispatchThread";
   if (myIconRenderers.removeAll(renderers)) {
     relayoutOnIconRendererChanges();
   }
 }
Exemple #7
0
  public void getFriendMessage(
      String lccno,
      final String msg,
      final FontStyle fontStyle,
      final Date sendDate,
      final Map<String, String> imgs)
      throws Exception {
    MessageFrame msgFrame = getMessageFrame();
    final MemberBean memberBean = TreeUtil.getMemberBeanByLccno(lccno);
    if (memberBean == null) {
      RightCornerPopMessageManager.showDefaultRightCornerPopMessage(lccno + "用户已被删除,他的离线信息无法显示");
      return;
    }
    final FriendChatPanel panel = getFriendChatPanel(memberBean);
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeAndWait(
          new Runnable() {

            @Override
            public void run() {
              try {
                handleFriendMsg(panel, memberBean, msg, fontStyle, sendDate, imgs);
              } catch (Exception e) {
                log.error("insertFriendMsg", e);
                showErrorDialog("error", e.getMessage());
              }
            }
          });
    } else {
      handleFriendMsg(panel, memberBean, msg, fontStyle, sendDate, imgs);
    }
    if (!msgFrame.isVisible()) {
      msgFrame.setVisible(true);
    }
  }
 // This can come on any thread. If we are in the process of reloading
 // the image and determining our state (loading == true) we don't fire
 // preference changed, or repaint, we just reset the fWidth/fHeight as
 // necessary and return. This is ok as we know when loading finishes
 // it will pick up the new height/width, if necessary.
 @Override
 public boolean imageUpdate(
     final Image img,
     final int flags,
     final int x,
     final int y,
     final int newWidth,
     final int newHeight) {
   if (SwingUtilities.isEventDispatchThread()) {
     safePreferenceChanged();
     refreshImage();
     preferenceChanged(null, true, true);
     // Repaint when done or when new pixels arrive:
     if ((flags & (FRAMEBITS | ALLBITS)) != 0) {
       repaint(0);
     } else if ((flags & SOMEBITS) != 0) {
       repaint(100);
     }
   } else {
     // Avoids a possible deadlock between us waiting for imageLoaderMutex and it waiting on
     // us...
     SwingUtilities.invokeLater(
         new Runnable() {
           @Override
           public void run() {
             imageUpdate(img, flags, x, y, newWidth, newHeight);
           }
         });
   }
   return ((flags & ALLBITS) == 0);
 }
  // Terrible hack because whoever wrote DnDTabbedPane stole my GlassPane
  public void resetGlassPane() {
    if (!SwingUtilities.isEventDispatchThread()) {
      throw new RuntimeException("Not invoked from eventDispatchThread");
    }

    setGlassPane(SearchResultPanel.getInstance());
  }
  /** Retrieves the value from the specified text field as a {@link String}. */
  @SuppressWarnings({"UnusedCatchParameter"})
  private String getTextComponentValueAsString(final JTextComponent textComponent) {
    if (SwingUtilities.isEventDispatchThread()) {
      final String textFieldValue;
      try {
        final String text1 = textComponent.getText();
        textFieldValue = (text1 != null) ? text1.trim() : null;
      } catch (Exception e) {
        LOG.error("Exception while getting the value from text field. Returning null instead.", e);
        return null;
      }
      return textFieldValue;
    } else {
      final String[] textFieldValue = new String[1];
      try {
        SwingUtilities.invokeAndWait(
            new Runnable() {
              public void run() {
                textFieldValue[0] = textComponent.getText();
              }
            });
      } catch (Exception e) {
        LOG.error("Exception while getting the value from text field. Returning null instead.", e);
        return null;
      }

      return textFieldValue[0];
    }
  }
Exemple #11
0
  public void init() {

    if (SwingUtilities.isEventDispatchThread()) {
      if (initMessage != null) {
        init(initMessage);
      }
    } else {
      try {
        SwingUtilities.invokeAndWait(
            new Runnable() {

              public void run() {
                if (initMessage != null) {
                  init(initMessage);
                } else {
                  // System.err.println("Warning: Attempting to init without initMessage");
                }
              }
            });
      } catch (InterruptedException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
Exemple #12
0
  /**
   * Handles a message received from the remote party.
   *
   * @param msg The Message object that was received.
   */
  private void doMessageReceived(Message msg) {
    assert (SwingUtilities.isEventDispatchThread()) : "not in UI thread";

    if (msg.getType() == Message.Type.ERROR) {
      JOptionPane.showMessageDialog(
          this,
          msg.getError().getMessage(),
          JavolinApp.getAppName() + ": Error",
          JOptionPane.ERROR_MESSAGE);
    } else if (msg.getType() == Message.Type.HEADLINE) {
      // Do nothing
    } else {
      String jid = msg.getFrom();
      if (jid != null) setUserResource(jid);

      Date date = null;
      PacketExtension ext = msg.getExtension("x", "jabber:x:delay");
      if (ext != null && ext instanceof DelayInformation) {
        date = ((DelayInformation) ext).getStamp();
      }

      mLog.message(mRemoteIdFull, mRemoteNick, msg.getBody(), date);
      Audio.playMessage();
    }
  }
 public void setZoom(float zoom) {
   if (!SwingUtilities.isEventDispatchThread()) {
     throw new IllegalStateException("Must be on EDT");
   }
   if (zoom == zoom && zoom > 0.01 && Math.abs(zoom - this.zoom) > 0.01) {
     JScrollBar hsb = scrollPane.getHorizontalScrollBar();
     JScrollBar vsb = scrollPane.getVerticalScrollBar();
     float hv = (float) hsb.getValue();
     float vv = (float) vsb.getValue();
     float hm = (float) hsb.getMaximum();
     float vm = (float) vsb.getMaximum();
     this.zoom = zoom;
     view.setSize(view.getPreferredSize());
     listener.setEnabled(false); // don't send adjustment events
     Dimension viewsize = view.getSize();
     hv *= ((float) viewsize.width) / hm;
     vv *= ((float) viewsize.height) / vm;
     hsb.setMaximum(viewsize.width);
     vsb.setMaximum(viewsize.height);
     hsb.setValue(Math.round(hv));
     vsb.setValue(Math.round(vv));
     listener.setEnabled(true);
     view.revalidate();
     view.repaint();
   }
 }
 private void checkEDT() {
   if (!SwingUtilities.isEventDispatchThread()) {
     IllegalStateException e = new IllegalStateException();
     log.error("Not in EDT!", e);
     throw e;
   }
 }
Exemple #15
0
  public void setSize(final int width, final int height) {
    Runnable runnable =
        new Runnable() {
          public void run() {
            image = new BufferedImage(width + 1, height + 1, BufferedImage.TYPE_INT_RGB);

            setPreferredSize(new Dimension(width, height));
            Container container = VMComponent.this;

            while ((container = container.getParent()) != null) {
              if (container instanceof JFrame) {
                JFrame frame = (JFrame) container;
                frame.pack();

                break;
              }
            }
          }
        };

    if (SwingUtilities.isEventDispatchThread()) {
      runnable.run();
    } else {
      try {
        SwingUtilities.invokeAndWait(runnable);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  /**
   * Creates new form CChannelList
   *
   * @param L
   */
  public CChannelList(LMain L) {

    LM = L;

    Runnable doWorkRunnable =
        new Runnable() {

          public void run() {
            channeltablemodel = new CChannelTableModel(LM);
            channeltablesorter = new TableRowSorter<CChannelTableModel>(channeltablemodel);

            initComponents();

            ChannelTable.getColumnModel().getColumn(0).setMaxWidth(50);
            ChannelTable.getColumnModel().getColumn(1).setMaxWidth(150);
            ChannelTable.getColumnModel().getColumn(2).setMaxWidth(50);
          }
        };

    if (SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(doWorkRunnable);
    } else {
      try {
        SwingUtilities.invokeAndWait(doWorkRunnable);
      } catch (InterruptedException ex) {
        Logger.getLogger(CChannelList.class.getName()).log(Level.SEVERE, null, ex);
      } catch (InvocationTargetException ex) {
        Logger.getLogger(CChannelList.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
  /**
   * Sets the jobs for that model
   *
   * @param jobs
   * @throws SQLException
   */
  public void setJobs(final ArrayList<ExperimentResult> jobs) throws SQLException {

    Runnable updateTable =
        new Runnable() {

          @Override
          public void run() {
            ExperimentResultsBrowserTableModel.this.jobs = jobs;
            if (jobs != null) {
              gridQueues = new HashMap<Integer, GridQueue>();
              parameters = new HashMap<Integer, String>();
              try {
                ArrayList<GridQueue> queues = GridQueueDAO.getAll();
                for (GridQueue q : queues) {
                  gridQueues.put(q.getId(), q);
                }
              } catch (Exception e) {
              }
            }
            ExperimentResultsBrowserTableModel.this.fireTableDataChanged();
          }
        };
    if (SwingUtilities.isEventDispatchThread()) {
      // already in EDT
      updateTable.run();
    } else {
      // we have to run this in the EDT, otherwise sync exceptions
      SwingUtilities.invokeLater(updateTable);
    }
  }
  private List<String> runCompiler(final Consumer<ErrorReportingCallback> runnable) {
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    final ErrorReportingCallback callback = new ErrorReportingCallback(semaphore);
    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            try {
              if (useJps()) {
                getProject().save();
                CompilerTestUtil.saveSdkTable();
                File ioFile = VfsUtil.virtualToIoFile(myModule.getModuleFile());
                if (!ioFile.exists()) {
                  getProject().save();
                  assert ioFile.exists() : "File does not exist: " + ioFile.getPath();
                }
              }
              runnable.consume(callback);
            } catch (Exception e) {
              throw new RuntimeException(e);
            }
          }
        });

    // tests run in awt
    while (!semaphore.waitFor(100)) {
      if (SwingUtilities.isEventDispatchThread()) {
        UIUtil.dispatchAllInvocationEvents();
      }
    }
    callback.throwException();
    return callback.getMessages();
  }
  /** Updates the scrollbar to reflect the current size of the document */
  private void updateScrollBar() {

    final int value, maximum;

    int documentSize = this.documentSize.get();

    value = this.fastTextView.getParagraph();
    maximum = Math.max(0, documentSize - 1) + 10;

    Runnable scrollbarUpdater =
        new Runnable() {

          @Override
          public void run() {

            FastTextPane.this.ignoreAdjustmentChange = true;
            FastTextPane.this.scrollBar.setValues(value, 10, 0, maximum);
            FastTextPane.this.ignoreAdjustmentChange = false;
          }
        };

    if (SwingUtilities.isEventDispatchThread()) {
      scrollbarUpdater.run();
    } else {
      SwingUtilities.invokeLater(scrollbarUpdater);
    }
  }
  @Override
  protected void finish() {
    if (canceled) return;
    if (lastException != null) {
      ExceptionDialogUtil.explainException(lastException);
    }
    Runnable r =
        new Runnable() {
          public void run() {
            ChangesetCache.getInstance().update(downloadedChangesets);
          }
        };

    if (SwingUtilities.isEventDispatchThread()) {
      r.run();
    } else {
      try {
        SwingUtilities.invokeAndWait(r);
      } catch (InterruptedException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof RuntimeException) {
          BugReportExceptionHandler.handleException(t);
        } else if (t instanceof Exception) {
          ExceptionUtil.explainException(e);
        } else {
          BugReportExceptionHandler.handleException(t);
        }
      }
    }
  }
  @SuppressWarnings("unused")
  private void showDialog() {

    if (!SwingUtilities.isEventDispatchThread()) {
      selectedOption =
          JOptionPane.showOptionDialog(
              this,
              panel,
              tr("PT_Assistant Proceed Request"),
              JOptionPane.DEFAULT_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              options,
              0);
    } else {

      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              showDialog();
            }
          });
    }
  }
Exemple #22
0
  public void systemChanged(final ProcessWrapper pProcess, final Command pCmd, final int pEvent) {
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              systemChanged(pProcess, pCmd, pEvent);
            }
          });
      return;
    }

    if (pProcess != selected) {
      return;
    }
    commands.fireTableDataChanged();

    if (pEvent == ControlListener.COMMAND_ADDED) {
      int last = commands.getRowCount() - 1;
      cmdTable.setRowSelectionInterval(last, last);
    } else if (pEvent == ControlListener.COMMAND_UPDATED) {
      // Prevent selection loss
      int selectedRow = commands.find(pCmd);
      cmdTable.setRowSelectionInterval(selectedRow, selectedRow);
    }
  }
 /**
  * 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));
   }
 }
 public static void runOnSwingThread(Runnable run) {
   if (javax.swing.SwingUtilities.isEventDispatchThread()) {
     run.run();
   } else {
     runOnSwingThreadLater(run);
   }
 }
  /**
   * Positions the nodes on the layout according to the results of numerous iterations of the
   * Kamada-Kawai spring-embedding algorithm. Essentially, the network is modeled as a collection of
   * nodes connected by springs with resting lengths proportional to the length of the shortest path
   * distance between each node pair. Nodes are normally positioned in a circle, and then each node
   * in sequence is repositioned until the "energy" of all of its springs are minimized to a
   * parameter value epsilon. The location of the local minima for each node is estimated with
   * iterations of a Newtown-Raphson steepest descent method. Repositioning ceases when all nodes
   * have energy below epsilon. In this implementation, epsilon is initialized at a high value, and
   * than decreased as in simulated annealing. the layout SHOULD stop when a low value (epsilon < 1)
   * is reached or when energies of nodes can now longer be decreased.
   *
   * <p>Note: In the current implementation the layout may not always converge! however, the
   * maxPasses parameter can be set lower to interrupt cycling layouts. Also has not been tested/
   * implemented on weighted graphs. The Kamada-Kawai algorithm was not intended to run on
   * disconnected graphs (graphs with multiple components. The kludgy solution implemented here is
   * to run the algorithm independently on each of the components (of size > 1). This is somewhat
   * unsatisfactory as the components will often overlap.
   *
   * <p>The KK algorithm is relatively slow, especially on the first round. However, it often
   * discovers layouts of regularly structured graphs which are "better" and more repeatable than
   * the Fruchmen-Reingold technique. Implementation of the numerics of the Newton-Raphson method
   * follows Shawn Lorae Stutzman, Auburn University, 12/12/96 <A
   * href="http://mathcs.mta.ca/research/rosebrugh/gdct/javasource.htm">
   * http://mathcs.mta.ca/research/rosebrugh/gdct/javasource.htm</A>
   *
   * <p>Kamada, Tomihisa and Satoru Kawai (1989) "An Algorithm for Drawing Undirected Graphs" <CITE>
   * Information Processing Letters</CITE> 31:7-15
   */
  public void updateLayout() {
    // check that layout should be drawn
    if (update) {
      isEventThread = SwingUtilities.isEventDispatchThread();
      stop = false;
      if (circleLayout) {
        // give nodes circular initial coord to begin with
        circleLayout();
      }

      if (firstLayout) {
        firstLayout = false;
        circleLayout();
      }

      // runs kk algorithm on each component individualy
      ArrayList components = NetUtilities.getComponents(nodeList);
      Iterator compIter = components.iterator();

      while (compIter.hasNext() && !stop) {
        ArrayList comp = (ArrayList) compIter.next();
        if (comp.size() > 1) runKamadaOn(comp);
      }

      // rescale node positions to fit in window
      if (rescaleLayout) rescalePositions(nodeList);
    }
  }
  void log(@NonNls String msg, Document document, boolean synchronously, @NonNls Object... args) {
    if (debug()) {
      @NonNls
      String s =
          (SwingUtilities.isEventDispatchThread() ? "-    " : "-")
              + msg
              + (synchronously ? " (sync)" : "")
              + (document == null
                  ? ""
                  : "; Document: "
                      + System.identityHashCode(document)
                      + "; stage: "
                      + getCommitStage(document))
              + "; my indic="
              + myProgressIndicator
              + " ||";

      for (Object arg : args) {
        s += "; " + arg;
      }
      System.out.println(s);
      synchronized (log) {
        log.append(s).append("\n");
        if (log.length() > 1000000) {
          log.delete(0, 1000000);
        }
      }
    }
  }
 public void relayout(boolean updateFolding) {
   assert SwingUtilities.isEventDispatchThread()
       : "LeftEditorHighlighter.relayout() should be executed in eventDispatchThread";
   SNode editedNode = myEditorComponent.getEditedNode();
   // additional check - during editor dispose process some Folding area painters can be removed
   // calling relayout()..
   if (myEditorComponent.isDisposed()
       || (editedNode != null && jetbrains.mps.util.SNodeOperations.isDisposed(editedNode))) {
     return;
   }
   if (myRightToLeft) {
     recalculateFoldingAreaWidth();
     updateSeparatorLinePosition();
     if (updateFolding) {
       for (AbstractFoldingAreaPainter painter : myFoldingAreaPainters) {
         painter.relayout();
       }
       // wee need to recalculateIconRenderersWidth only if one of collections was folded/unfolded
       recalculateIconRenderersWidth();
     }
     recalculateTextColumnWidth();
   } else {
     recalculateTextColumnWidth();
     if (updateFolding) {
       for (AbstractFoldingAreaPainter painter : myFoldingAreaPainters) {
         painter.relayout();
       }
       // wee need to recalculateIconRenderersWidth only if one of collections was folded/unfolded
       recalculateIconRenderersWidth();
     }
     recalculateFoldingAreaWidth();
     updateSeparatorLinePosition();
   }
   updatePreferredSize();
 }
Exemple #28
0
 /**
  * Wait for a specific condition to be true, without having to wait longer
  *
  * <p>To be used in tests, will do an assert if the total delay is longer than WAITFOR_MAX_DELAY
  *
  * <p>Typical use: waitFor(()->{return replyVariable != null;},"reply not received")
  *
  * @param condition name of condition being waited for; will appear in Assert.fail if condition
  *     not true fast enough
  */
 public static void waitFor(ReleaseUntil condition, String name) {
   if (javax.swing.SwingUtilities.isEventDispatchThread()) {
     log.error("Cannot use waitFor on Swing thread", new Exception());
     return;
   }
   int delay = 0;
   try {
     while (delay < WAITFOR_MAX_DELAY) {
       if (condition.ready()) return;
       int priority = Thread.currentThread().getPriority();
       try {
         Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
         Thread.sleep(WAITFOR_DELAY_STEP);
         delay += WAITFOR_DELAY_STEP;
       } catch (InterruptedException e) {
         Assert.fail("failed due to InterruptedException");
       } finally {
         Thread.currentThread().setPriority(priority);
       }
     }
     Assert.fail("\"" + name + "\" did not occur in time");
   } catch (Exception ex) {
     Assert.fail("Exception while waiting for \"" + name + "\" " + ex);
   }
 }
Exemple #29
0
 public static void doSafely(Runnable run) {
   if (SwingUtilities.isEventDispatchThread()) {
     run.run();
   } else {
     SwingUtilities.invokeLater(run);
   }
 }
  // evaluate a netlogo report asynchronously; return the result to this callback as the argument
  public void asynchronousReport(final String cmd, final String callback) {
    final JSObject window = JSObject.getWindow(this);

    if (SwingUtilities.isEventDispatchThread()) {
      Thread t =
          new Thread("reporter thread off of EDT") {
            public void run() {
              Object retval = null;
              try {
                retval = panel().report(cmd);
                Object[] args = {retval};
                window.call(callback, args);
              } catch (CompilerException e) {
                e.printStackTrace();
              }
            }
          };
      t.start();
    } else {
      Object retval = null;
      try {
        retval = panel().report(cmd);
        Object[] args = {retval};
        window.call(callback, args);
      } catch (CompilerException e) {
        e.printStackTrace();
      }
    }
  }