public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();
    if (boundedRangeModel != null) {
      int value = boundedRangeModel.getValue();
      if (source == forwardButton) {
        boundedRangeModel.setValue(
            value == boundedRangeModel.getMaximum() ? boundedRangeModel.getMinimum() : value + 1);
      } else if (source == rewindButton) {
        boundedRangeModel.setValue(
            value == boundedRangeModel.getMinimum() ? boundedRangeModel.getMaximum() : value - 1);
      } else if (source == startButton) {
        if (startButton.isSelected() != player.isActive()) {
          if (startButton.isSelected()) {
            player.start();
          } else {
            player.stop();
          }
        }
      } else if (source == audioButton) {

        player.setAudioEnabled(audioButton.isSelected());
      } else if (source == colorCyclingButton) {
        if (player instanceof ColorCyclePlayer) {
          ((ColorCyclePlayer) player).setColorCyclingStarted(colorCyclingButton.isSelected());
        }
      }
    }
  }
Ejemplo n.º 2
0
 private void moveScrollBar(int k) {
   myBoundedRangeModel.setValue(myBoundedRangeModel.getValue() + k);
 }
Ejemplo n.º 3
0
 private void scrollToBottom() {
   myBoundedRangeModel.setValue(myTermSize.height);
 }
Ejemplo n.º 4
0
 public void adjustmentValueChanged(AdjustmentEvent e) {
   if (!brm.getValueIsAdjusting()) {
     if (wasAtBottom) brm.setValue(brm.getMaximum());
   } else wasAtBottom = ((brm.getValue() + brm.getExtent()) == brm.getMaximum());
 }
Ejemplo n.º 5
0
  protected void runTestGL(
      final GLCapabilities caps,
      final FrameLayout frameLayout,
      final boolean twoCanvas,
      final boolean resizeByComp)
      throws InterruptedException, InvocationTargetException {
    final JFrame frame = new JFrame("Bug816: " + this.getTestMethodName());
    Assert.assertNotNull(frame);
    final Container framePane = frame.getContentPane();

    final GLCanvas glCanvas1 = new GLCanvas(caps);
    Assert.assertNotNull(glCanvas1);
    final GLCanvas glCanvas2;
    if (twoCanvas) {
      glCanvas2 = new GLCanvas(caps);
      Assert.assertNotNull(glCanvas2);
    } else {
      glCanvas2 = null;
    }

    final Dimension glcDim = new Dimension(width / 2, height);
    final Dimension frameDim = new Dimension(twoCanvas ? width + 64 : width / 2 + 64, height + 64);

    setComponentSize(null, glCanvas1, glcDim, glCanvas2, glcDim);

    switch (frameLayout) {
      case None:
        {
          framePane.add(glCanvas1);
        }
        break;
      case Flow:
        {
          final Container c = new Container();
          c.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
          c.add(glCanvas1);
          if (twoCanvas) {
            c.add(glCanvas2);
          }
          framePane.add(c);
        }
        break;
      case DoubleBorderCenterSurrounded:
        {
          final Container c = new Container();
          c.setLayout(new BorderLayout());
          c.add(new Button("north"), BorderLayout.NORTH);
          c.add(new Button("south"), BorderLayout.SOUTH);
          c.add(new Button("east"), BorderLayout.EAST);
          c.add(new Button("west"), BorderLayout.WEST);
          if (twoCanvas) {
            final Container c2 = new Container();
            c2.setLayout(new GridLayout(1, 2));
            c2.add(glCanvas1);
            c2.add(glCanvas2);
            c.add(c2, BorderLayout.CENTER);
          } else {
            c.add(glCanvas1, BorderLayout.CENTER);
          }
          framePane.setLayout(new BorderLayout());
          framePane.add(new Button("NORTH"), BorderLayout.NORTH);
          framePane.add(new Button("SOUTH"), BorderLayout.SOUTH);
          framePane.add(new Button("EAST"), BorderLayout.EAST);
          framePane.add(new Button("WEST"), BorderLayout.WEST);
          framePane.add(c, BorderLayout.CENTER);
        }
        break;
      case Box:
        {
          final Container c = new Container();
          c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
          c.add(glCanvas1);
          if (twoCanvas) {
            c.add(glCanvas2);
          }
          framePane.add(c);
        }
        break;
      case Split:
        {
          final Dimension sbDim = new Dimension(16, 16);
          final JScrollPane vsp =
              new JScrollPane(
                  ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
          {
            final JScrollBar vsb = vsp.getVerticalScrollBar();
            vsb.setPreferredSize(sbDim);
            final BoundedRangeModel model = vsb.getModel();
            model.setMinimum(0);
            model.setMaximum(100);
            model.setValue(50);
            model.setExtent(1);
            vsb.setEnabled(true);
          }
          final JScrollPane hsp =
              new JScrollPane(
                  ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
          {
            final JScrollBar hsb = hsp.getHorizontalScrollBar();
            hsb.setPreferredSize(sbDim);
            final BoundedRangeModel model = hsb.getModel();
            model.setMinimum(0);
            model.setMaximum(100);
            model.setValue(50);
            model.setExtent(1);
            hsb.setEnabled(true);
          }
          final JSplitPane horizontalSplitPane =
              new JSplitPane(
                  JSplitPane.HORIZONTAL_SPLIT, true, twoCanvas ? glCanvas2 : vsp, glCanvas1);
          horizontalSplitPane.setResizeWeight(0.5);
          final JSplitPane verticalSplitPane =
              new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, horizontalSplitPane, hsp);
          verticalSplitPane.setResizeWeight(0.5);
          framePane.add(verticalSplitPane);
        }
        break;
    }
    final GearsES2 demo1 = new GearsES2(swapInterval);
    glCanvas1.addGLEventListener(demo1);
    if (twoCanvas) {
      final RedSquareES2 demo2 = new RedSquareES2(swapInterval);
      glCanvas2.addGLEventListener(demo2);
    }

    final Animator animator = new Animator();
    animator.add(glCanvas1);
    if (twoCanvas) {
      animator.add(glCanvas2);
    }
    final QuitAdapter quitAdapter = new QuitAdapter();
    new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame);

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            if (resizeByComp) {
              frame.pack();
            } else {
              setFrameSize(frame, true, frameDim);
            }
            frame.setVisible(true);
          }
        });
    Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true));
    if (twoCanvas) {
      Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas2, true));
    }

    animator.start();
    Assert.assertTrue(animator.isStarted());
    Assert.assertTrue(animator.isAnimating());

    System.err.println(
        "canvas1 pos/siz: "
            + glCanvas1.getX()
            + "/"
            + glCanvas1.getY()
            + " "
            + glCanvas1.getSurfaceWidth()
            + "x"
            + glCanvas1.getSurfaceHeight());
    if (twoCanvas) {
      System.err.println(
          "canvas2 pos/siz: "
              + glCanvas2.getX()
              + "/"
              + glCanvas2.getY()
              + " "
              + glCanvas2.getSurfaceWidth()
              + "x"
              + glCanvas2.getSurfaceHeight());
    }

    Thread.sleep(Math.max(1000, duration / 2));
    if (null != rwsize) {
      final Dimension compRSizeHalf = new Dimension(rwsize.width / 2, rwsize.height);
      final Dimension frameRSizeHalf =
          new Dimension(twoCanvas ? rwsize.width + 64 : rwsize.width / 2 + 64, rwsize.height + 64);
      if (resizeByComp) {
        setComponentSize(frame, glCanvas1, compRSizeHalf, glCanvas2, compRSizeHalf);
      } else {
        setFrameSize(frame, true, frameRSizeHalf);
      }
      System.err.println(
          "resize canvas1 pos/siz: "
              + glCanvas1.getX()
              + "/"
              + glCanvas1.getY()
              + " "
              + glCanvas1.getSurfaceWidth()
              + "x"
              + glCanvas1.getSurfaceHeight());
      if (twoCanvas) {
        System.err.println(
            "resize canvas2 pos/siz: "
                + glCanvas2.getX()
                + "/"
                + glCanvas2.getY()
                + " "
                + glCanvas2.getSurfaceWidth()
                + "x"
                + glCanvas2.getSurfaceHeight());
      }
    }

    final long t0 = System.currentTimeMillis();
    long t1 = t0;
    while (!quitAdapter.shouldQuit() && t1 - t0 < duration) {
      Thread.sleep(100);
      t1 = System.currentTimeMillis();
    }

    Assert.assertNotNull(frame);
    Assert.assertNotNull(glCanvas1);
    if (twoCanvas) {
      Assert.assertNotNull(glCanvas2);
    } else {
      Assert.assertNull(glCanvas2);
    }

    Assert.assertNotNull(animator);
    animator.stop();
    Assert.assertFalse(animator.isAnimating());
    Assert.assertFalse(animator.isStarted());

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            frame.setVisible(false);
          }
        });
    Assert.assertEquals(false, frame.isVisible());
    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            frame.remove(glCanvas1);
            if (twoCanvas) {
              frame.remove(glCanvas2);
            }
            frame.dispose();
          }
        });
  }
Ejemplo n.º 6
0
 /** Run the task. */
 public void run() {
   final BoundedRangeModel model = progressBar.getModel();
   switch (task) {
     case -LABEL:
       {
         value = description.getText();
         return;
       }
     case +LABEL:
       {
         description.setText((String) value);
         return;
       }
     case PROGRESS:
       {
         model.setValue(((Integer) value).intValue());
         progressBar.setIndeterminate(false);
         return;
       }
     case STARTED:
       {
         model.setRangeProperties(0, 1, 0, 100, false);
         window.setVisible(true);
         break; // Need further action below.
       }
     case COMPLETE:
       {
         model.setRangeProperties(100, 1, 0, 100, false);
         window.setVisible(warningArea != null);
         cancel.setEnabled(false);
         break; // Need further action below.
       }
   }
   /*
    * Some of the tasks above requires an action on the window, which may be a JDialog or
    * a JInternalFrame. We need to determine the window type before to apply the action.
    */
   synchronized (ProgressWindow.this) {
     if (window instanceof JDialog) {
       final JDialog window = (JDialog) ProgressWindow.this.window;
       switch (task) {
         case -TITLE:
           {
             value = window.getTitle();
             return;
           }
         case +TITLE:
           {
             window.setTitle((String) value);
             return;
           }
         case STARTED:
           {
             window.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
             return;
           }
         case COMPLETE:
           {
             window.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
             return;
           }
         case DISPOSE:
           {
             window.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
             if (warningArea == null || !window.isVisible()) {
               window.dispose();
             }
             return;
           }
       }
     } else {
       final JInternalFrame window = (JInternalFrame) ProgressWindow.this.window;
       switch (task) {
         case -TITLE:
           {
             value = window.getTitle();
             return;
           }
         case +TITLE:
           {
             window.setTitle((String) value);
             return;
           }
         case STARTED:
           {
             window.setClosable(false);
             return;
           }
         case COMPLETE:
           {
             window.setClosable(true);
             return;
           }
         case DISPOSE:
           {
             window.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
             if (warningArea == null || !window.isVisible()) {
               window.dispose();
             }
             return;
           }
       }
     }
     /*
      * Si la tâche spécifiée n'est aucune des tâches énumérées ci-haut,
      * on supposera que l'on voulait afficher un message d'avertissement.
      */
     if (warningArea == null) {
       final JTextArea warningArea = new JTextArea();
       final JScrollPane scroll = new JScrollPane(warningArea);
       final JPanel namedArea = new JPanel(new BorderLayout());
       ProgressWindow.this.warningArea = warningArea;
       warningArea.setFont(Font.getFont("Monospaced"));
       warningArea.setEditable(false);
       namedArea.setBorder(BorderFactory.createEmptyBorder(0, HMARGIN, VMARGIN, HMARGIN));
       namedArea.add(new JLabel(getString(VocabularyKeys.WARNING)), BorderLayout.NORTH);
       namedArea.add(scroll, BorderLayout.CENTER);
       content.add(namedArea, BorderLayout.CENTER);
       if (window instanceof JDialog) {
         final JDialog window = (JDialog) ProgressWindow.this.window;
         window.setResizable(true);
       } else {
         final JInternalFrame window = (JInternalFrame) ProgressWindow.this.window;
         window.setResizable(true);
       }
       window.setSize(WIDTH, HEIGHT + WARNING_HEIGHT);
       window.setVisible(true); // Seems required in order to force relayout.
     }
     final JTextArea warningArea = (JTextArea) ProgressWindow.this.warningArea;
     warningArea.append((String) value);
   }
 }