Esempio n. 1
0
  /**
   * Create the GUI and show it. For thread safety, this method should be invoked from the
   * event-dispatching thread.
   */
  private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("Automated File Mover");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent we) {
            try {
              FileOutputStream f_out = new FileOutputStream(LOG_DIRECTORY + "save.data");

              // Write object with ObjectOutputStream
              ObjectOutputStream obj_out = new ObjectOutputStream(f_out);

              // Write object out to disk
              obj_out.writeObject(directoryList);
              obj_out.writeObject(ERROR_LOG_NAME);
              obj_out.writeObject(MOVE_LOG_NAME);
              obj_out.flush();
              obj_out.close();
              printer.printError(LOG_DIRECTORY);
            } catch (IOException x) {
              printer.printError(x.toString());
            }
          }
        });

    // Create and set up the content pane.
    JComponent newContentPane = new fileBackupProgram(frame);
    newContentPane.setOpaque(true); // content panes must be opaque
    frame.setContentPane(newContentPane);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
  }
 public void testIntProperty() throws Exception {
   JComponent rootComponent = getInstrumentedRootComponent("TestIntProperty.form", "BindingTest");
   assertEquals(1, rootComponent.getComponentCount());
   JTextField textField = (JTextField) rootComponent.getComponent(0);
   assertEquals(37, textField.getColumns());
   assertEquals(false, textField.isEnabled());
 }
 public void testCardLayout() throws Exception {
   JComponent rootComponent = getInstrumentedRootComponent("TestCardLayout.form", "BindingTest");
   assertTrue(rootComponent.getLayout() instanceof CardLayout);
   CardLayout cardLayout = (CardLayout) rootComponent.getLayout();
   assertEquals(10, cardLayout.getHgap());
   assertEquals(20, cardLayout.getVgap());
 }
 public void testCardLayoutShow() throws Exception {
   JComponent rootComponent =
       getInstrumentedRootComponent("TestCardLayoutShow.form", "BindingTest");
   assertTrue(rootComponent.getLayout() instanceof CardLayout);
   assertEquals(rootComponent.getComponentCount(), 2);
   assertFalse(rootComponent.getComponent(0).isVisible());
   assertTrue(rootComponent.getComponent(1).isVisible());
 }
  public void testGridLayout() throws Exception {
    JComponent rootComponent =
        getInstrumentedRootComponent("TestGridConstraints.form", "BindingTest");
    final LayoutManager layout = rootComponent.getLayout();
    assertTrue(isInstanceOf(layout, GridLayoutManager.class.getName()));

    assertEquals(1, invokeMethod(layout, "getRowCount"));
    assertEquals(1, invokeMethod(layout, "getColumnCount"));
  }
Esempio n. 6
0
 public void setVisible(boolean bShow, String title) {
   if (bShow) {
     String strDir = "";
     String strFreq = "";
     String strTraynum = "";
     m_strHelpFile = getHelpFile(title);
     String strSampleName = getSampleName(title);
     String frameBounds = getFrameBounds(title);
     StringTokenizer tok = new QuotedStringTokenizer(title);
     if (tok.hasMoreTokens()) strDir = tok.nextToken();
     if (tok.hasMoreTokens()) strFreq = tok.nextToken();
     if (tok.hasMoreTokens()) strTraynum = tok.nextToken();
     else {
       try {
         Integer.parseInt(strDir);
         // if strdir is number, then strdir is empty, and the
         // strfreq is the number
         strTraynum = strFreq;
         strFreq = strDir;
         strDir = "";
       } catch (Exception e) {
       }
     }
     try {
       setTitle(gettitle(strFreq));
       m_lblSampleName.setText("3");
       boolean bVast = isVast(strTraynum);
       CardLayout layout = (CardLayout) m_pnlSampleName.getLayout();
       if (!bVast) {
         if (strSampleName == null) {
           strSampleName = getSampleName(strDir, strTraynum);
         }
         m_lblSampleName.setText(strSampleName);
         layout.show(m_pnlSampleName, OTHER);
       } else {
         m_strDir = strDir;
         setTrays();
         layout.show(m_pnlSampleName, VAST);
         m_trayTimer.start();
       }
       boolean bSample = bVast || !strSampleName.trim().equals("");
       m_pnlSampleName.setVisible(bSample);
       m_lblLogin.setForeground(getBackground());
       m_lblLogin.setVisible(false);
       m_passwordField.setText("");
       m_passwordField.setCaretPosition(0);
     } catch (Exception e) {
       Messages.writeStackTrace(e);
     }
     setBounds(frameBounds);
     ExpPanel exp = Util.getActiveView();
     if (exp != null) exp.waitLogin(true);
   }
   writePersistence();
   setVisible(bShow);
 }
    /**
     * Returns the maximum amount of space the layout can use.
     *
     * @param the Container for which this layout manager is being used
     * @return a Dimension object containing the layout's maximum size
     */
    public Dimension maximumLayoutSize(Container target) {
      Dimension cpd, mbd, tpd;
      int cpWidth = Integer.MAX_VALUE;
      int cpHeight = Integer.MAX_VALUE;
      int mbWidth = Integer.MAX_VALUE;
      int mbHeight = Integer.MAX_VALUE;
      int tpWidth = Integer.MAX_VALUE;
      int tpHeight = Integer.MAX_VALUE;
      Insets i = target.getInsets();
      JRootPane root = (JRootPane) target;

      if (root.getContentPane() != null) {
        cpd = root.getContentPane().getMaximumSize();
        if (cpd != null) {
          cpWidth = cpd.width;
          cpHeight = cpd.height;
        }
      }

      if (root.getMenuBar() != null) {
        mbd = root.getMenuBar().getMaximumSize();
        if (mbd != null) {
          mbWidth = mbd.width;
          mbHeight = mbd.height;
        }
      }

      if (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof HokageRootPaneUI)) {
        JComponent titlePane = ((HokageRootPaneUI) root.getUI()).getTitlePane();
        if (titlePane != null) {
          tpd = titlePane.getMaximumSize();
          if (tpd != null) {
            tpWidth = tpd.width;
            tpHeight = tpd.height;
          }
        }
      }

      int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
      // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE
      // Only will happen if sums to more than 2 billion units.  Not likely.
      if (maxHeight != Integer.MAX_VALUE) {
        maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
      }

      int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
      // Similar overflow comment as above
      if (maxWidth != Integer.MAX_VALUE) {
        maxWidth += i.left + i.right;
      }

      return new Dimension(maxWidth, maxHeight);
    }
Esempio n. 8
0
  /*
   *  Create a BufferedImage for Swing components.
   *  The entire component will be captured to an image.
   *
   *  @param	 component Swing component to create image from
   *  @param	 fileName name of file to be created or null
   *  @return	image the image for the given region
   *  @exception IOException if an error occurs during writing
   */
  public static BufferedImage createImage(JComponent component, String fileName)
      throws IOException {
    Dimension d = component.getSize();

    if (d.width == 0) {
      d = component.getPreferredSize();
      component.setSize(d);
    }

    Rectangle region = new Rectangle(0, 0, d.width, d.height);
    return ScreenCapture.createImage(component, region, fileName);
  }
Esempio n. 9
0
 /** [Internal] */
 public void paintComponent(Graphics g) {
   boolean opq = true;
   if (theOpaque != null) opq = theOpaque;
   super.setOpaque(opq);
   // if(theBackground!=null)super.setBackground(theBackground);
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   Rectangle rt = getBounds();
   rt.x = 0;
   rt.y = 0;
   doBuffer(g2, opq, rt);
   chkFPS();
 }
Esempio n. 10
0
    protected void clear(JComponent comp) {
      int nCompCount = comp.getComponentCount();
      ArrayList aListComps = new ArrayList();

      for (int i = 0; i < comp.getComponentCount(); i++) {
        Component compChild = comp.getComponent(i);
        if (compChild instanceof JComponent) {
          JComponent jcomp = (JComponent) compChild;
          if (jcomp instanceof JCheckBox || jcomp instanceof JTextField) aListComps.add(comp);
          else clear(jcomp);
        }
      }
      clear(aListComps);
    }
Esempio n. 11
0
 /*
  *  Create a BufferedImage for Swing components.
  *  All or part of the component can be captured to an image.
  *
  *  @param	 component Swing component to create image from
  *  @param	 region The region of the component to be captured to an image
  *  @param	 fileName name of file to be created or null
  *  @return	image the image for the given region
  *  @exception IOException if an error occurs during writing
  */
 public static BufferedImage createImage(JComponent component, Rectangle region, String fileName)
     throws IOException {
   boolean opaqueValue = component.isOpaque();
   component.setOpaque(true);
   BufferedImage image =
       new BufferedImage(region.width, region.height, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2d = image.createGraphics();
   g2d.setClip(region);
   component.paint(g2d);
   g2d.dispose();
   component.setOpaque(opaqueValue);
   ScreenCapture.writeImage(image, fileName);
   return image;
 }
Esempio n. 12
0
  private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("Main");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    JComponent newContentPane = new Main();
    newContentPane.setOpaque(true); // content panes must be opaque
    frame.setContentPane(newContentPane);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
  }
  public void testGridConstraints() throws Exception {
    JComponent rootComponent =
        getInstrumentedRootComponent("TestGridConstraints.form", "BindingTest");
    assertEquals(1, rootComponent.getComponentCount());
    final LayoutManager layout = rootComponent.getLayout();
    assertTrue(isInstanceOf(layout, GridLayoutManager.class.getName()));

    final Object constraints =
        invokeMethod(layout, "getConstraints", new Class[] {int.class}, new Object[] {0});
    assertTrue(isInstanceOf(constraints, GridConstraints.class.getName()));

    assertEquals(1, invokeMethod(constraints, "getColSpan"));
    assertEquals(1, invokeMethod(constraints, "getRowSpan"));
  }
Esempio n. 14
0
  /**
   * Sets the window title pane -- the JComponent used to provide a plaf a way to override the
   * native operating system's window title pane with one whose look and feel are controlled by the
   * plaf. The plaf creates and sets this value; the default is null, implying a native operating
   * system window title pane.
   *
   * @param content the <code>JComponent</code> to use for the window title pane.
   */
  private void setTitlePane(JRootPane root, JComponent titlePane) {
    JLayeredPane layeredPane = root.getLayeredPane();
    JComponent oldTitlePane = getTitlePane();

    if (oldTitlePane != null) {
      oldTitlePane.setVisible(false);
      layeredPane.remove(oldTitlePane);
    }
    if (titlePane != null) {
      layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER);
      titlePane.setVisible(true);
    }
    this.titlePane = titlePane;
  }
Esempio n. 15
0
  // Create the GUI and show it.
  private static void createAndShowGUI() {

    // Create and set up the window.
    frame = new JFrame("Capture Replay");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    JComponent newContentPane = new CaptureReplay();
    newContentPane.setOpaque(true); // content panes must be opaque
    frame.setContentPane(newContentPane);
    frame.setPreferredSize(new Dimension(400, 400));

    // Display the window.
    frame.pack();
    frame.setVisible(true);
  }
  public void setSimulator(HackSimulatorGUI simulator) {
    ((JComponent) simulator).setLocation(0, TOOLBAR_HEIGHT);
    this.getContentPane().add((JComponent) simulator, null);
    ((JComponent) simulator).revalidate();
    repaint();

    if (simulator.getUsageFileName() != null) {
      usageWindow = new HTMLViewFrame(simulator.getUsageFileName());
      usageWindow.setSize(450, 430);
    }

    if (simulator.getAboutFileName() != null) {
      aboutWindow = new HTMLViewFrame(simulator.getAboutFileName());
      aboutWindow.setSize(450, 420);
    }
  }
Esempio n. 17
0
  /**
   * Create preview component.
   *
   * @param type type
   * @param comboBox the options.
   * @param prefSize the preferred size
   * @return the component.
   */
  private static Component createPreview(int type, final JComboBox comboBox, Dimension prefSize) {
    JComponent preview = null;

    if (type == DeviceConfigurationComboBoxModel.AUDIO) {
      Object selectedItem = comboBox.getSelectedItem();

      if (selectedItem instanceof AudioSystem) {
        AudioSystem audioSystem = (AudioSystem) selectedItem;

        if (!NoneAudioSystem.LOCATOR_PROTOCOL.equalsIgnoreCase(audioSystem.getLocatorProtocol())) {
          preview = new TransparentPanel(new GridBagLayout());
          createAudioSystemControls(audioSystem, preview);
        }
      }
    } else if (type == DeviceConfigurationComboBoxModel.VIDEO) {
      JLabel noPreview =
          new JLabel(
              NeomediaActivator.getResources().getI18NString("impl.media.configform.NO_PREVIEW"));

      noPreview.setHorizontalAlignment(SwingConstants.CENTER);
      noPreview.setVerticalAlignment(SwingConstants.CENTER);

      preview = createVideoContainer(noPreview);
      preview.setPreferredSize(prefSize);

      Object selectedItem = comboBox.getSelectedItem();
      CaptureDeviceInfo device = null;
      if (selectedItem instanceof DeviceConfigurationComboBoxModel.CaptureDevice)
        device = ((DeviceConfigurationComboBoxModel.CaptureDevice) selectedItem).info;

      Exception exception;
      try {
        createVideoPreview(device, preview);
        exception = null;
      } catch (IOException ex) {
        exception = ex;
      } catch (MediaException ex) {
        exception = ex;
      }
      if (exception != null) {
        logger.error("Failed to create preview for device " + device, exception);
        device = null;
      }
    }

    return preview;
  }
Esempio n. 18
0
  /** Handles the event when the key is pressed */
  public void processKeyEvent(KeyEvent e) {
    int keyCode = e.getKeyCode();

    if (e.getID() == KeyEvent.KEY_PRESSED) {
      if (keyCode == KeyEvent.VK_Z) lockZoom();
      else if (keyCode == KeyEvent.VK_T) fixElTimePointer(currTime);
    } else super.processKeyEvent(e);
  }
Esempio n. 19
0
    /**
     * Returns the amount of space the layout would like to have.
     *
     * @param the Container for which this layout manager is being used
     * @return a Dimension object containing the layout's preferred size
     */
    public Dimension preferredLayoutSize(Container parent) {
      Dimension cpd, mbd, tpd;
      int cpWidth = 0;
      int cpHeight = 0;
      int mbWidth = 0;
      int mbHeight = 0;
      int tpWidth = 0;
      int tpHeight = 0;
      Insets i = parent.getInsets();
      JRootPane root = (JRootPane) parent;

      if (root.getContentPane() != null) {
        cpd = root.getContentPane().getPreferredSize();
      } else {
        cpd = root.getSize();
      }
      if (cpd != null) {
        cpWidth = cpd.width;
        cpHeight = cpd.height;
      }

      if (root.getMenuBar() != null) {
        mbd = root.getMenuBar().getPreferredSize();
        if (mbd != null) {
          mbWidth = mbd.width;
          mbHeight = mbd.height;
        }
      }

      if (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof HokageRootPaneUI)) {
        JComponent titlePane = ((HokageRootPaneUI) root.getUI()).getTitlePane();
        if (titlePane != null) {
          tpd = titlePane.getPreferredSize();
          if (tpd != null) {
            tpWidth = tpd.width;
            tpHeight = tpd.height;
          }
        }
      }

      return new Dimension(
          Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
          cpHeight + mbHeight + tpWidth + i.top + i.bottom);
    }
Esempio n. 20
0
  /** Opens a new window with a drawing view. */
  protected void open(DrawingView newDrawingView) {
    getVersionControlStrategy().assertCompatibleVersion();
    setUndoManager(new UndoManager());
    fIconkit = new Iconkit(this);
    getContentPane().setLayout(new BorderLayout());

    // status line must be created before a tool is set
    fStatusLine = createStatusLine();
    getContentPane().add(fStatusLine, BorderLayout.SOUTH);

    // create dummy tool until the default tool is activated during toolDone()
    setTool(new NullTool(this), "");
    setView(newDrawingView);
    JComponent contents = createContents(view());
    contents.setAlignmentX(LEFT_ALIGNMENT);

    JToolBar tools = createToolPalette();
    createTools(tools);

    JPanel activePanel = new JPanel();
    activePanel.setAlignmentX(LEFT_ALIGNMENT);
    activePanel.setAlignmentY(TOP_ALIGNMENT);
    activePanel.setLayout(new BorderLayout());
    activePanel.add(tools, BorderLayout.NORTH);
    activePanel.add(contents, BorderLayout.CENTER);

    getContentPane().add(activePanel, BorderLayout.CENTER);

    JMenuBar mb = new JMenuBar();
    createMenus(mb);
    setJMenuBar(mb);

    Dimension d = defaultSize();
    if (d.width > mb.getPreferredSize().width) {
      setSize(d.width, d.height);
    } else {
      setSize(mb.getPreferredSize().width, d.height);
    }
    addListeners();
    setVisible(true);
    fStorageFormatManager = createStorageFormatManager();

    toolDone();
  }
  private void addField(OptionField field) {
    // Add label
    JLabel l = new JLabel(field.getDisplayName() + ":");
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = currentRow;
    c.insets = new Insets(5, 2, 2, 2);
    c.anchor = GridBagConstraints.NORTHWEST;
    content.add(l, c);

    // Add enable checkbox
    if (field.getEnableToggle() != null) {
      c = new GridBagConstraints();
      c.gridx = 1;
      c.gridy = currentRow;
      c.fill = GridBagConstraints.BOTH;
      c.insets = new Insets(2, 2, 2, 2);
      c.anchor = GridBagConstraints.NORTHWEST;
      content.add(field.getEnableToggle(), c);
    }

    // Add field
    c = new GridBagConstraints();
    c.gridx = 2;
    c.gridy = currentRow;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(2, 2, 2, 2);
    c.anchor = GridBagConstraints.NORTHWEST;
    content.add(field.getComponent(), c);

    // Add change listener
    field.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent e) {
            fireChangeEvent();
          }
        });

    // Update state
    currentRow++;
    pack();
  }
Esempio n. 22
0
 /**
  * Adds drag and drop functionality.
  *
  * @param comp component
  * @param dnd drag and drop handler
  */
 public static void addDrop(final JComponent comp, final DropHandler dnd) {
   comp.setDropTarget(
       new DropTarget(comp, DnDConstants.ACTION_COPY_OR_MOVE, null, true, null) {
         @Override
         public synchronized void drop(final DropTargetDropEvent dtde) {
           dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
           final Transferable tr = dtde.getTransferable();
           for (final Object o : contents(tr)) dnd.drop(o);
           comp.requestFocusInWindow();
         }
       });
 }
Esempio n. 23
0
 public void paint(Graphics g) {
   if (comp != null) {
     width = comp.getWidth() / 6;
     height = comp.getHeight() * 2 / 3;
   }
   g.setColor(bgColor);
   g.fillRect(x, y, width, height);
   g.setColor(fgColor);
   g.setFont(font);
   g.drawString(strTray, x / 2 + width / 2, y + height + 10);
   super.paint(g);
 }
Esempio n. 24
0
  /**
   * Creates preview for the (video) device in the video container.
   *
   * @param device the device
   * @param videoContainer the video container
   * @throws IOException a problem accessing the device
   * @throws MediaException a problem getting preview
   */
  private static void createVideoPreview(CaptureDeviceInfo device, JComponent videoContainer)
      throws IOException, MediaException {
    videoContainer.removeAll();

    videoContainer.revalidate();
    videoContainer.repaint();

    if (device == null) return;

    for (MediaDevice mediaDevice : mediaService.getDevices(MediaType.VIDEO, MediaUseCase.ANY)) {
      if (((MediaDeviceImpl) mediaDevice).getCaptureDeviceInfo().equals(device)) {
        Dimension videoContainerSize = videoContainer.getPreferredSize();
        Component preview =
            (Component)
                mediaService.getVideoPreviewComponent(
                    mediaDevice, videoContainerSize.width, videoContainerSize.height);

        if (preview != null) videoContainer.add(preview);
        break;
      }
    }
  }
Esempio n. 25
0
    /**
     * Instructs the layout manager to perform the layout for the specified container.
     *
     * @param the Container for which this layout manager is being used
     */
    public void layoutContainer(Container parent) {
      JRootPane root = (JRootPane) parent;
      Rectangle b = root.getBounds();
      Insets i = root.getInsets();
      int nextY = 0;
      int w = b.width - i.right - i.left;
      int h = b.height - i.top - i.bottom;

      if (root.getLayeredPane() != null) {
        root.getLayeredPane().setBounds(i.left, i.top, w, h);
      }
      if (root.getGlassPane() != null) {
        root.getGlassPane().setBounds(i.left, i.top, w, h);
      }
      // Note: This is laying out the children in the layeredPane,
      // technically, these are not our children.
      if (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof HokageRootPaneUI)) {
        JComponent titlePane = ((HokageRootPaneUI) root.getUI()).getTitlePane();
        if (titlePane != null) {
          Dimension tpd = titlePane.getPreferredSize();
          if (tpd != null) {
            int tpHeight = tpd.height;
            titlePane.setBounds(0, 0, w, tpHeight);
            nextY += tpHeight;
          }
        }
      }
      if (root.getMenuBar() != null) {
        Dimension mbd = root.getMenuBar().getPreferredSize();
        root.getMenuBar().setBounds(0, nextY, w, mbd.height);
        nextY += mbd.height;
      }
      if (root.getContentPane() != null) {
        Dimension cpd = root.getContentPane().getPreferredSize();
        root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY);
      }
    }
    protected void configureEnableToggle(
        Boolean initiallyEnabled, String valueIfDisabled, final List<JComponent> components) {
      if (initiallyEnabled != null) {
        enable = new JCheckBox();
        boolean enabled = initiallyEnabled.booleanValue();
        this.enable.setSelected(enabled);
        for (JComponent c : components) {
          c.setEnabled(enabled);
        }
        this.valueIfDisabled = valueIfDisabled;

        final OptionField f = this;
        this.enable.addItemListener(
            new ItemListener() {
              @Override
              public void itemStateChanged(ItemEvent e) {
                for (JComponent c : components) {
                  c.setEnabled(f.isEnabled());
                }
                fireChangeEvent();
              }
            });
      }
    }
    public void paintComponent(Graphics g) {
      super.paintComponent(g);

      Graphics2D g2 = (Graphics2D) g;

      if (!text.equals("")) {
        g2.translate(0, getSize().getHeight());
        g2.rotate(-Math.PI / 2);
        g2.setColor(Color.black);
        g2.drawString(text, 20, 14);

        g2.translate(0, -getSize().getHeight());
        g2.transform(AffineTransform.getQuadrantRotateInstance(1));
      }
    }
Esempio n. 28
0
  /**
   * Registers the keystroke of the given action as "command" of the given component.
   *
   * <p>This code is based on the Sulky-tools, found at &lt;http://github.com/huxi/sulky&gt;.
   *
   * @param aComponent the component that should react on the keystroke, cannot be <code>null</code>
   *     ;
   * @param aAction the action of the keystroke, cannot be <code>null</code>;
   * @param aCommandName the name of the command to register the keystore under.
   */
  public static void registerKeystroke(
      final JComponent aComponent, final Action aAction, final String aCommandName) {
    final KeyStroke keyStroke = (KeyStroke) aAction.getValue(Action.ACCELERATOR_KEY);
    if (keyStroke == null) {
      return;
    }

    InputMap inputMap = aComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = aComponent.getActionMap();
    inputMap.put(keyStroke, aCommandName);
    actionMap.put(aCommandName, aAction);

    inputMap = aComponent.getInputMap(JComponent.WHEN_FOCUSED);
    Object value = inputMap.get(keyStroke);
    if (value != null) {
      inputMap.put(keyStroke, aCommandName);
    }

    inputMap = aComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    value = inputMap.get(keyStroke);
    if (value != null) {
      inputMap.put(keyStroke, aCommandName);
    }
  }
  public void paint(Graphics g) {
    super.paint(g);
    if (thumbnail != null) {
      int x = getWidth() / 2 - thumbnail.getIconWidth() / 2;
      int y = getHeight() / 2 - thumbnail.getIconHeight() / 2;
      if (y < 0) {
        y = 0;
      }

      if (x < 5) {
        x = 5;
      }
      thumbnail.paintIcon(this, g, x, y);
    }
  }
    public void setText(String txt) {
      text = txt;
      textlabel.repaint();
      if (!text.equals("")) {
        if (!isVisible()) {
          // Only setVisible if its needed
          // or the focus window will change
          toFront();
          setVisible(true);
        }

        // Give focus to capture window if its there
        if (cw.isVisible()) cw.requestFocus();
      } else {
        // Hide window
        setVisible(false);
      }
    }