Exemplo n.º 1
0
  /**
   * Create the Swing components that let you change the transparency of the color received from the
   * JColorChooser.
   *
   * @param initialValue the starting alpha value for the color.
   * @return JComponent to adjust the transparency value.
   */
  public JComponent getTransparancyAdjustment(int initialValue) {
    transparency = initialValue;
    // This sets initial transparency effect in preview...
    setPreviewColor(preview.getColor());
    JPanel slidePanel = new JPanel();
    Box slideBox = Box.createHorizontalBox();

    JSlider opaqueSlide =
        new JSlider(JSlider.HORIZONTAL, 0 /* min */, 255 /* max */, initialValue /* initial */);
    java.util.Hashtable<Integer, JLabel> dict = new java.util.Hashtable<Integer, JLabel>();
    String opaqueLabel = i18n.get(ColorTracker.class, "opaque", "opaque");
    String clearLabel = i18n.get(ColorTracker.class, "clear", "clear");
    if (opaqueLabel == null || opaqueLabel.length() == 0) {
      // translations are too long :(
      dict.put(new Integer(126), new JLabel(clearLabel));
    } else {
      dict.put(new Integer(50), new JLabel(clearLabel));
      dict.put(new Integer(200), new JLabel(opaqueLabel));
    }
    // commented because polish translations are too long
    opaqueSlide.setLabelTable(dict);
    opaqueSlide.setPaintLabels(true);
    opaqueSlide.setMajorTickSpacing(50);
    opaqueSlide.setPaintTicks(true);
    opaqueSlide.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent ce) {
            JSlider slider = (JSlider) ce.getSource();
            if (slider.getValueIsAdjusting()) {
              transparency = slider.getValue();
            }
            // This sets transparency in preview...
            setPreviewColor(preview.getColor());
          }
        });

    preview.setPreferredSize(new Dimension(100, slideBox.getHeight()));
    slideBox.add(preview);
    slideBox.add(Box.createGlue());
    slideBox.add(opaqueSlide);
    slideBox.add(Box.createGlue());
    slidePanel.add(slideBox);
    // You know what, it just has to be something, so the
    // UIManager will think it's valid. It will get resized as
    // appropriate when the JDialog gets packed.
    slidePanel.setSize(new Dimension(50, 50));
    return slidePanel;
  }
Exemplo n.º 2
0
 public void drawBox(Graphics g) {
   for (Box i : boxList) {
     g.drawImage(i.getImage(), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null);
   }
 }