looks-2.2.0

16:38:59.507 INFO  jd.cli.Main - Decompiling looks-2.2.0.jar
package com.jgoodies.looks;

import javax.swing.JComponent;
import javax.swing.JMenuBar;
import javax.swing.JToolBar;

public final class BorderStyle
{
  public static final BorderStyle EMPTY = new BorderStyle("Empty");
  public static final BorderStyle SEPARATOR = new BorderStyle("Separator");
  public static final BorderStyle ETCHED = new BorderStyle("Etched");
  private final String name;
  
  private BorderStyle(String name)
  {
    this.name = name;
  }
  
  public static BorderStyle from(JToolBar toolBar, String clientPropertyKey)
  {
    return from0(toolBar, clientPropertyKey);
  }
  
  public static BorderStyle from(JMenuBar menuBar, String clientPropertyKey)
  {
    return from0(menuBar, clientPropertyKey);
  }
  
  private static BorderStyle from0(JComponent c, String clientPropertyKey)
  {
    Object value = c.getClientProperty(clientPropertyKey);
    if ((value instanceof BorderStyle)) {
      return (BorderStyle)value;
    }
    if ((value instanceof String)) {
      return valueOf((String)value);
    }
    return null;
  }
  
  private static BorderStyle valueOf(String name)
  {
    if (name.equalsIgnoreCase(EMPTYname)) {
      return EMPTY;
    }
    if (name.equalsIgnoreCase(SEPARATORname)) {
      return SEPARATOR;
    }
    if (name.equalsIgnoreCase(ETCHEDname)) {
      return ETCHED;
    }
    throw new IllegalArgumentException("Invalid BorderStyle name " + name);
  }
  
  public String toString()
  {
    return name;
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.BorderStyle
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import javax.swing.JTextField;
import javax.swing.UIManager;

public final class ComboBoxEditorTextField
  extends JTextField
{
  public ComboBoxEditorTextField(boolean isTableCellEditor)
  {
    super("", UIManager.getInt("ComboBox.editorColumns"));
    if (isTableCellEditor) {
      setMargin(UIManager.getInsets("ComboBox.tableEditorInsets"));
    }
    setBorder(UIManager.getBorder("ComboBox.editorBorder"));
  }
  
  public void setText(String s)
  {
    if (getText().equals(s)) {
      return;
    }
    super.setText(s);
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ComboBoxEditorTextField
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.Container;
import java.awt.FocusTraversalPolicy;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.AttributedCharacterIterator;
import java.text.DateFormat.Field;
import java.text.Format;
import java.text.Format.Field;
import java.text.ParseException;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.ButtonModel;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JFormattedTextField.AbstractFormatter;
import javax.swing.JSpinner;
import javax.swing.JSpinner.DateEditor;
import javax.swing.LookAndFeel;
import javax.swing.SpinnerDateModel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.text.Document;
import javax.swing.text.InternationalFormatter;

public final class ExtBasicArrowButtonHandler
  extends AbstractAction
  implements MouseListener, FocusListener
{
  private final Timer autoRepeatTimer;
  private final boolean isNext;
  private JSpinner spinner;
  private JButton arrowButton;
  
  public ExtBasicArrowButtonHandler(String name, boolean isNext)
  {
    super(name);
    this.isNext = isNext;
    autoRepeatTimer = new Timer(60, this);
    autoRepeatTimer.setInitialDelay(300);
  }
  
  private JSpinner eventToSpinner(AWTEvent e)
  {
    Object src = e.getSource();
    while (((src instanceof Component)) && (!(src instanceof JSpinner))) {
      src = ((Component)src).getParent();
    }
    return (src instanceof JSpinner) ? (JSpinner)src : null;
  }
  
  public void actionPerformed(ActionEvent e)
  {
    JSpinner spinner = this.spinner;
    if (!(e.getSource() instanceof Timer))
    {
      spinner = eventToSpinner(e);
      if ((e.getSource() instanceof JButton)) {
        arrowButton = ((JButton)e.getSource());
      }
    }
    else if ((arrowButton != null) && (!arrowButton.getModel().isPressed()) && (autoRepeatTimer.isRunning()))
    {
      autoRepeatTimer.stop();
      spinner = null;
      arrowButton = null;
    }
    if (spinner != null) {
      try
      {
        int calendarField = getCalendarField(spinner);
        spinner.commitEdit();
        if (calendarField != -1) {
          ((SpinnerDateModel)spinner.getModel()).setCalendarField(calendarField);
        }
        Object value = isNext ? spinner.getNextValue() : spinner.getPreviousValue();
        if (value != null)
        {
          spinner.setValue(value);
          select(spinner);
        }
      }
      catch (IllegalArgumentException iae)
      {
        UIManager.getLookAndFeel().provideErrorFeedback(spinner);
      }
      catch (ParseException pe)
      {
        UIManager.getLookAndFeel().provideErrorFeedback(spinner);
      }
    }
  }
  
  private void select(JSpinner aSpinner)
  {
    JComponent editor = aSpinner.getEditor();
    if ((editor instanceof JSpinner.DateEditor))
    {
      JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
      JFormattedTextField ftf = dateEditor.getTextField();
      Format format = dateEditor.getFormat();
      Object value;
      if ((format != null) && ((value = aSpinner.getValue()) != null))
      {
        SpinnerDateModel model = dateEditor.getModel();
        DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
        if (field != null) {
          try
          {
            AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
            if ((!select(ftf, iterator, field)) && (field == DateFormat.Field.HOUR0)) {
              select(ftf, iterator, DateFormat.Field.HOUR1);
            }
          }
          catch (IllegalArgumentException iae) {}
        }
      }
    }
  }
  
  private boolean select(JFormattedTextField ftf, AttributedCharacterIterator iterator, DateFormat.Field field)
  {
    int max = ftf.getDocument().getLength();
    
    iterator.first();
    do
    {
      Map attrs = iterator.getAttributes();
      if ((attrs != null) && (attrs.containsKey(field)))
      {
        int start = iterator.getRunStart(field);
        int end = iterator.getRunLimit(field);
        if ((start != -1) && (end != -1) && (start <= max) && (end <= max)) {
          ftf.select(start, end);
        }
        return true;
      }
    } while (iterator.next() != 65535);
    return false;
  }
  
  private int getCalendarField(JSpinner aSpinner)
  {
    JComponent editor = aSpinner.getEditor();
    if ((editor instanceof JSpinner.DateEditor))
    {
      JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
      JFormattedTextField ftf = dateEditor.getTextField();
      int start = ftf.getSelectionStart();
      JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
      if ((formatter instanceof InternationalFormatter))
      {
        Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
        for (int counter = 0; counter < fields.length; counter++) {
          if ((fields[counter] instanceof DateFormat.Field))
          {
            int calendarField;
            int calendarField;
            if (fields[counter] == DateFormat.Field.HOUR1) {
              calendarField = 10;
            } else {
              calendarField = ((DateFormat.Field)fields[counter]).getCalendarField();
            }
            if (calendarField != -1) {
              return calendarField;
            }
          }
        }
      }
    }
    return -1;
  }
  
  public void mousePressed(MouseEvent e)
  {
    if ((SwingUtilities.isLeftMouseButton(e)) && (e.getComponent().isEnabled()))
    {
      spinner = eventToSpinner(e);
      autoRepeatTimer.start();
      focusSpinnerIfNecessary();
    }
  }
  
  public void mouseReleased(MouseEvent e)
  {
    autoRepeatTimer.stop();
    spinner = null;
    arrowButton = null;
  }
  
  public void mouseClicked(MouseEvent e) {}
  
  public void mouseEntered(MouseEvent e)
  {
    if ((spinner != null) && (!autoRepeatTimer.isRunning())) {
      autoRepeatTimer.start();
    }
  }
  
  public void mouseExited(MouseEvent e)
  {
    if (autoRepeatTimer.isRunning()) {
      autoRepeatTimer.stop();
    }
  }
  
  private void focusSpinnerIfNecessary()
  {
    Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if ((spinner.isRequestFocusEnabled()) && ((fo == null) || (!SwingUtilities.isDescendingFrom(fo, spinner))))
    {
      Container root = spinner;
      if (!root.isFocusCycleRoot()) {
        root = root.getFocusCycleRootAncestor();
      }
      if (root != null)
      {
        FocusTraversalPolicy ftp = root.getFocusTraversalPolicy();
        Component child = ftp.getComponentAfter(root, spinner);
        if ((child != null) && (SwingUtilities.isDescendingFrom(child, spinner))) {
          child.requestFocus();
        }
      }
    }
  }
  
  public void focusGained(FocusEvent e) {}
  
  public void focusLost(FocusEvent e)
  {
    if (autoRepeatTimer.isRunning()) {
      autoRepeatTimer.stop();
    }
    spinner = null;
    if (arrowButton != null)
    {
      ButtonModel model = arrowButton.getModel();
      model.setPressed(false);
      model.setArmed(false);
      arrowButton = null;
    }
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtBasicArrowButtonHandler
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;

public final class ExtBasicCheckBoxMenuItemUI
  extends ExtBasicRadioButtonMenuItemUI
{
  protected String getPropertyPrefix()
  {
    return "CheckBoxMenuItem";
  }
  
  public static ComponentUI createUI(JComponent b)
  {
    return new ExtBasicCheckBoxMenuItemUI();
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtBasicCheckBoxMenuItemUI
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicMenuItemUI;

public class ExtBasicMenuItemUI
  extends BasicMenuItemUI
{
  private static final int MINIMUM_WIDTH = 80;
  private MenuItemRenderer renderer;
  
  public static ComponentUI createUI(JComponent b)
  {
    return new ExtBasicMenuItemUI();
  }
  
  protected void installDefaults()
  {
    super.installDefaults();
    renderer = createRenderer(menuItem, iconBorderEnabled(), acceleratorFont, selectionForeground, disabledForeground, acceleratorForeground, acceleratorSelectionForeground);
    
    Integer gap = (Integer)UIManager.get(getPropertyPrefix() + ".textIconGap");
    
    defaultTextIconGap = (gap != null ? gap.intValue() : 2);
  }
  
  protected boolean iconBorderEnabled()
  {
    return false;
  }
  
  protected void uninstallDefaults()
  {
    super.uninstallDefaults();
    renderer = null;
  }
  
  protected Dimension getPreferredMenuItemSize(JComponent c, Icon aCheckIcon, Icon anArrowIcon, int textIconGap)
  {
    Dimension size = renderer.getPreferredMenuItemSize(c, aCheckIcon, anArrowIcon, textIconGap);
    
    int width = Math.max(80, width);
    int height = height;
    return new Dimension(width, height);
  }
  
  protected void paintMenuItem(Graphics g, JComponent c, Icon aCheckIcon, Icon anArrowIcon, Color background, Color foreground, int textIconGap)
  {
    renderer.paintMenuItem(g, c, aCheckIcon, anArrowIcon, background, foreground, textIconGap);
  }
  
  protected MenuItemRenderer createRenderer(JMenuItem menuItem, boolean iconBorderEnabled, Font acceleratorFont, Color selectionForeground, Color disabledForeground, Color acceleratorForeground, Color acceleratorSelectionForeground)
  {
    return new MenuItemRenderer(menuItem, iconBorderEnabled(), acceleratorFont, selectionForeground, disabledForeground, acceleratorForeground, acceleratorSelectionForeground);
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtBasicMenuItemUI
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

class ExtBasicMenuUI$1 {}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtBasicMenuUI.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;

final class ExtBasicMenuUI$RolloverHandler
  extends MouseAdapter
{
  ExtBasicMenuUI$RolloverHandler(ExtBasicMenuUI.1 x0)
  {
    this();
  }
  
  public void mouseEntered(MouseEvent e)
  {
    AbstractButton b = (AbstractButton)e.getSource();
    b.getModel().setRollover(true);
  }
  
  public void mouseExited(MouseEvent e)
  {
    AbstractButton b = (AbstractButton)e.getSource();
    b.getModel().setRollover(false);
  }
  
  private ExtBasicMenuUI$RolloverHandler() {}
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtBasicMenuUI.RolloverHandler
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicMenuUI;

public class ExtBasicMenuUI
  extends BasicMenuUI
{
  private static final String MENU_PROPERTY_PREFIX = "Menu";
  private static final String SUBMENU_PROPERTY_PREFIX = "MenuItem";
  private String propertyPrefix;
  private MenuItemRenderer renderer;
  private MouseListener mouseListener;
  
  public ExtBasicMenuUI()
  {
    propertyPrefix = "Menu";
  }
  
  public static ComponentUI createUI(JComponent b)
  {
    return new ExtBasicMenuUI();
  }
  
  protected void installDefaults()
  {
    super.installDefaults();
    if ((arrowIcon == null) || ((arrowIcon instanceof UIResource))) {
      arrowIcon = UIManager.getIcon("Menu.arrowIcon");
    }
    renderer = new MenuItemRenderer(menuItem, false, acceleratorFont, selectionForeground, disabledForeground, acceleratorForeground, acceleratorSelectionForeground);
    
    Integer gap = (Integer)UIManager.get(getPropertyPrefix() + ".textIconGap");
    
    defaultTextIconGap = (gap != null ? gap.intValue() : 2);
    LookAndFeel.installBorder(menuItem, getPropertyPrefix() + ".border");
  }
  
  protected void uninstallDefaults()
  {
    super.uninstallDefaults();
    renderer = null;
  }
  
  protected String getPropertyPrefix()
  {
    return propertyPrefix;
  }
  
  protected Dimension getPreferredMenuItemSize(JComponent c, Icon aCheckIcon, Icon anArrowIcon, int textIconGap)
  {
    if (isSubMenu(menuItem))
    {
      ensureSubMenuInstalled();
      return renderer.getPreferredMenuItemSize(c, aCheckIcon, anArrowIcon, textIconGap);
    }
    return super.getPreferredMenuItemSize(c, aCheckIcon, anArrowIcon, textIconGap);
  }
  
  protected void paintMenuItem(Graphics g, JComponent c, Icon aCheckIcon, Icon anArrowIcon, Color background, Color foreground, int textIconGap)
  {
    if (isSubMenu(menuItem)) {
      renderer.paintMenuItem(g, c, aCheckIcon, anArrowIcon, background, foreground, textIconGap);
    } else {
      super.paintMenuItem(g, c, aCheckIcon, anArrowIcon, background, foreground, textIconGap);
    }
  }
  
  private void ensureSubMenuInstalled()
  {
    if (propertyPrefix.equals("MenuItem")) {
      return;
    }
    ButtonModel model = menuItem.getModel();
    
    boolean oldArmed = model.isArmed();
    boolean oldSelected = model.isSelected();
    
    uninstallRolloverListener();
    uninstallDefaults();
    propertyPrefix = "MenuItem";
    installDefaults();
    
    model.setArmed(oldArmed);
    model.setSelected(oldSelected);
  }
  
  protected void installListeners()
  {
    super.installListeners();
    mouseListener = new RolloverHandler(null);
    menuItem.addMouseListener(mouseListener);
  }
  
  protected void uninstallListeners()
  {
    super.uninstallListeners();
    uninstallRolloverListener();
  }
  
  private void uninstallRolloverListener()
  {
    if (mouseListener != null)
    {
      menuItem.removeMouseListener(mouseListener);
      mouseListener = null;
    }
  }
  
  private boolean isSubMenu(JMenuItem aMenuItem)
  {
    return !((JMenu)aMenuItem).isTopLevelMenu();
  }
  
  private static final class RolloverHandler
    extends MouseAdapter
  {
    RolloverHandler(ExtBasicMenuUI.1 x0)
    {
      this();
    }
    
    public void mouseEntered(MouseEvent e)
    {
      AbstractButton b = (AbstractButton)e.getSource();
      b.getModel().setRollover(true);
    }
    
    public void mouseExited(MouseEvent e)
    {
      AbstractButton b = (AbstractButton)e.getSource();
      b.getModel().setRollover(false);
    }
    
    private RolloverHandler() {}
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtBasicMenuUI
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.JComponent;
import javax.swing.JSeparator;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPopupMenuSeparatorUI;

public final class ExtBasicPopupMenuSeparatorUI
  extends BasicPopupMenuSeparatorUI
{
  private static final int SEPARATOR_HEIGHT = 2;
  private Insets insets;
  private static ComponentUI popupMenuSeparatorUI;
  
  public static ComponentUI createUI(JComponent b)
  {
    if (popupMenuSeparatorUI == null) {
      popupMenuSeparatorUI = new ExtBasicPopupMenuSeparatorUI();
    }
    return popupMenuSeparatorUI;
  }
  
  protected void installDefaults(JSeparator s)
  {
    super.installDefaults(s);
    insets = UIManager.getInsets("PopupMenuSeparator.margin");
  }
  
  public void paint(Graphics g, JComponent c)
  {
    Dimension s = c.getSize();
    
    int topInset = insets.top;
    int leftInset = insets.left;
    int rightInset = insets.right;
    
    g.setColor(UIManager.getColor("MenuItem.background"));
    g.fillRect(0, 0, width, height);
    
    g.translate(0, topInset);
    g.setColor(c.getForeground());
    g.drawLine(leftInset, 0, width - rightInset, 0);
    
    g.setColor(c.getBackground());
    g.drawLine(leftInset, 1, width - rightInset, 1);
    g.translate(0, -topInset);
  }
  
  public Dimension getPreferredSize(JComponent c)
  {
    return new Dimension(0, insets.top + 2 + insets.bottom);
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtBasicPopupMenuSeparatorUI
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import java.awt.Point;
import java.awt.event.MouseEvent;
import javax.swing.ButtonModel;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.plaf.ComponentUI;

public class ExtBasicRadioButtonMenuItemUI
  extends ExtBasicMenuItemUI
{
  protected String getPropertyPrefix()
  {
    return "RadioButtonMenuItem";
  }
  
  public static ComponentUI createUI(JComponent b)
  {
    return new ExtBasicRadioButtonMenuItemUI();
  }
  
  protected boolean iconBorderEnabled()
  {
    return true;
  }
  
  public void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement[] path, MenuSelectionManager manager)
  {
    Point p = e.getPoint();
    if ((x >= 0) && (x < item.getWidth()) && (y >= 0) && (y < item.getHeight()))
    {
      if (e.getID() == 502)
      {
        manager.clearSelectedPath();
        item.doClick(0);
        item.setArmed(false);
      }
      else
      {
        manager.setSelectedPath(path);
      }
    }
    else if (item.getModel().isArmed())
    {
      MenuElement[] newPath = new MenuElement[path.length - 1];
      
      int i = 0;
      for (int c = path.length - 1; i < c; i++) {
        newPath[i] = path[i];
      }
      manager.setSelectedPath(newPath);
    }
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtBasicRadioButtonMenuItemUI
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import javax.swing.UIManager;

public final class ExtBasicSpinnerLayout
  implements LayoutManager
{
  private static final Dimension ZERO_SIZE = new Dimension(0, 0);
  private Component nextButton = null;
  private Component previousButton = null;
  private Component editor = null;
  
  public void addLayoutComponent(String name, Component c)
  {
    if ("Next".equals(name)) {
      nextButton = c;
    } else if ("Previous".equals(name)) {
      previousButton = c;
    } else if ("Editor".equals(name)) {
      editor = c;
    }
  }
  
  public void removeLayoutComponent(Component c)
  {
    if (c == nextButton) {
      c = null;
    } else if (c == previousButton) {
      previousButton = null;
    } else if (c == editor) {
      editor = null;
    }
  }
  
  private Dimension preferredSize(Component c)
  {
    return c == null ? ZERO_SIZE : c.getPreferredSize();
  }
  
  public Dimension preferredLayoutSize(Container parent)
  {
    Dimension nextD = preferredSize(nextButton);
    Dimension previousD = preferredSize(previousButton);
    Dimension editorD = preferredSize(editor);
    
    Dimension size = new Dimension(width, height);
    width += Math.max(width, width);
    Insets insets = parent.getInsets();
    width += left + right;
    height += top + bottom;
    return size;
  }
  
  public Dimension minimumLayoutSize(Container parent)
  {
    return preferredLayoutSize(parent);
  }
  
  private void setBounds(Component c, int x, int y, int width, int height)
  {
    if (c != null) {
      c.setBounds(x, y, width, height);
    }
  }
  
  public void layoutContainer(Container parent)
  {
    int width = parent.getWidth();
    int height = parent.getHeight();
    
    Insets insets = parent.getInsets();
    Dimension nextD = preferredSize(nextButton);
    Dimension previousD = preferredSize(previousButton);
    int buttonsWidth = Math.max(width, width);
    int editorHeight = height - (top + bottom);
    
    Insets buttonInsets = UIManager.getInsets("Spinner.arrowButtonInsets");
    if (buttonInsets == null) {
      buttonInsets = insets;
    }
    int buttonsX;
    int buttonsX;
    int editorX;
    int editorWidth;
    if (parent.getComponentOrientation().isLeftToRight())
    {
      int editorX = left;
      int editorWidth = width - left - buttonsWidth - right;
      
      buttonsX = width - buttonsWidth - right;
    }
    else
    {
      buttonsX = left;
      editorX = buttonsX + buttonsWidth;
      editorWidth = width - left - buttonsWidth - right;
    }
    int nextY = top;
    int nextHeight = height / 2 + height % 2 - nextY;
    int previousY = top + nextHeight;
    int previousHeight = height - previousY - bottom;
    
    setBounds(editor, editorX, top, editorWidth, editorHeight);
    setBounds(nextButton, buttonsX, nextY, buttonsWidth, nextHeight);
    setBounds(previousButton, buttonsX, previousY, buttonsWidth, previousHeight);
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtBasicSpinnerLayout
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import com.jgoodies.looks.LookUtils;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import javax.swing.plaf.basic.BasicOptionPaneUI.ButtonAreaLayout;

public final class ExtButtonAreaLayout
  extends BasicOptionPaneUI.ButtonAreaLayout
{
  public ExtButtonAreaLayout(boolean syncAllWidths, int padding)
  {
    super(syncAllWidths, padding);
  }
  
  public void layoutContainer(Container container)
  {
    Component[] children = container.getComponents();
    if ((children != null) && (children.length > 0))
    {
      int numChildren = children.length;
      Dimension[] sizes = new Dimension[numChildren];
      
      int yLocation = getInsetstop;
      if (syncAllWidths)
      {
        int maxWidth = getMinimumButtonWidth();
        for (int counter = 0; counter < numChildren; counter++)
        {
          sizes[counter] = children[counter].getPreferredSize();
          maxWidth = Math.max(maxWidth, width);
        }
        int xOffset;
        int xLocation;
        int xOffset;
        if (getCentersChildren())
        {
          int xLocation = (getSizewidth - (maxWidth * numChildren + (numChildren - 1) * padding)) / 2;
          
          xOffset = padding + maxWidth;
        }
        else
        {
          int xOffset;
          if (numChildren > 1)
          {
            int xLocation = 0;
            xOffset = (getSizewidth - maxWidth * numChildren) / (numChildren - 1) + maxWidth;
          }
          else
          {
            xLocation = (getSizewidth - maxWidth) / 2;
            xOffset = 0;
          }
        }
        boolean ltr = container.getComponentOrientation().isLeftToRight();
        for (counter = 0; counter < numChildren; counter++)
        {
          int index = ltr ? counter : numChildren - counter - 1;
          
          children[index].setBounds(xLocation, yLocation, maxWidth, height);
          
          xLocation += xOffset;
        }
      }
      else
      {
        int totalWidth = 0;
        for (int counter = 0; counter < numChildren; counter++)
        {
          sizes[counter] = children[counter].getPreferredSize();
          totalWidth += width;
        }
        totalWidth += (numChildren - 1) * padding;
        
        boolean cc = getCentersChildren();
        int xOffset;
        int xLocation;
        int xOffset;
        if (cc)
        {
          int xLocation = (getSizewidth - totalWidth) / 2;
          xOffset = padding;
        }
        else
        {
          int xLocation;
          if (numChildren > 1)
          {
            int xOffset = (getSizewidth - totalWidth) / (numChildren - 1);
            
            xLocation = 0;
          }
          else
          {
            xLocation = (getSizewidth - totalWidth) / 2;
            
            xOffset = 0;
          }
        }
        boolean ltr = container.getComponentOrientation().isLeftToRight();
        for (counter = 0; counter < numChildren; counter++)
        {
          int index = ltr ? counter : numChildren - counter - 1;
          
          children[index].setBounds(xLocation, yLocation, width, height);
          
          xLocation += xOffset + width;
        }
      }
    }
  }
  
  public Dimension minimumLayoutSize(Container c)
  {
    if (c != null)
    {
      Component[] children = c.getComponents();
      if ((children != null) && (children.length > 0))
      {
        int numChildren = children.length;
        int height = 0;
        Insets cInsets = c.getInsets();
        int extraHeight = top + bottom;
        if (syncAllWidths)
        {
          int maxWidth = getMinimumButtonWidth();
          for (int counter = 0; counter < numChildren; counter++)
          {
            Dimension aSize = children[counter].getPreferredSize();
            height = Math.max(height, height);
            maxWidth = Math.max(maxWidth, width);
          }
          return new Dimension(maxWidth * numChildren + (numChildren - 1) * padding, extraHeight + height);
        }
        int totalWidth = 0;
        for (int counter = 0; counter < numChildren; counter++)
        {
          Dimension aSize = children[counter].getPreferredSize();
          height = Math.max(height, height);
          totalWidth += width;
        }
        totalWidth += (numChildren - 1) * padding;
        return new Dimension(totalWidth, extraHeight + height);
      }
    }
    return new Dimension(0, 0);
  }
  
  private int getMinimumButtonWidth()
  {
    return LookUtils.IS_LOW_RESOLUTION ? 75 : 100;
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtButtonAreaLayout
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import javax.swing.JPasswordField;
import javax.swing.UIManager;
import javax.swing.text.BadLocationException;
import javax.swing.text.Element;
import javax.swing.text.PasswordView;
import javax.swing.text.Position.Bias;

public final class ExtPasswordView
  extends PasswordView
{
  public ExtPasswordView(Element element)
  {
    super(element);
  }
  
  public float getPreferredSpan(int axis)
  {
    overrideEchoChar();
    return super.getPreferredSpan(axis);
  }
  
  public Shape modelToView(int pos, Shape a, Position.Bias b)
    throws BadLocationException
  {
    overrideEchoChar();
    return super.modelToView(pos, a, b);
  }
  
  public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias)
  {
    overrideEchoChar();
    return super.viewToModel(fx, fy, a, bias);
  }
  
  protected int drawEchoCharacter(Graphics g, int x, int y, char c)
  {
    Container container = getContainer();
    if (!(container instanceof JPasswordField)) {
      return super.drawEchoCharacter(g, x, y, c);
    }
    JPasswordField field = (JPasswordField)container;
    if (canOverrideEchoChar(field)) {
      c = getEchoChar();
    }
    Graphics2D g2 = (Graphics2D)g;
    Object newAAHint = RenderingHints.VALUE_ANTIALIAS_ON;
    Object oldAAHint = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    if (newAAHint != oldAAHint) {
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, newAAHint);
    } else {
      oldAAHint = null;
    }
    int newX = super.drawEchoCharacter(g, x, y, c);
    if (oldAAHint != null) {
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAAHint);
    }
    return newX;
  }
  
  private void overrideEchoChar()
  {
    Container container = getContainer();
    if (!(container instanceof JPasswordField)) {
      return;
    }
    JPasswordField field = (JPasswordField)container;
    if (canOverrideEchoChar(field)) {
      setFieldEchoChar(field, getEchoChar());
    }
  }
  
  private boolean canOverrideEchoChar(JPasswordField field)
  {
    return (field.echoCharIsSet()) && (field.getEchoChar() == '*');
  }
  
  private void setFieldEchoChar(JPasswordField field, char newEchoChar)
  {
    char oldEchoChar = field.getEchoChar();
    if (oldEchoChar == newEchoChar) {
      return;
    }
    field.setEchoChar(newEchoChar);
  }
  
  private static char getEchoChar()
  {
    return ((Character)UIManager.get("PasswordField.echoChar")).charValue();
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.ExtPasswordView
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

class MenuItemRenderer$1 {}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.MenuItemRenderer.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import java.awt.Component;
import java.awt.Graphics;
import javax.swing.Icon;

class MenuItemRenderer$NullIcon
  implements Icon
{
  MenuItemRenderer$NullIcon(MenuItemRenderer.1 x0)
  {
    this();
  }
  
  public int getIconWidth()
  {
    return 0;
  }
  
  public int getIconHeight()
  {
    return 0;
  }
  
  private MenuItemRenderer$NullIcon() {}
  
  public void paintIcon(Component c, Graphics g, int x, int y) {}
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.common.MenuItemRenderer.NullIcon
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.common;

import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.text.View;

public class MenuItemRenderer
{
  protected static final String HTML_KEY = "html";
  static final String MAX_TEXT_WIDTH = "maxTextWidth";
  static final String MAX_ACC_WIDTH = "maxAccWidth";
  private static final Icon NO_ICON = new NullIcon(null);
  static Rectangle zeroRect = new Rectangle(0, 0, 0, 0);
  static Rectangle iconRect = new Rectangle();
  static Rectangle textRect = new Rectangle();
  static Rectangle acceleratorRect = new Rectangle();
  static Rectangle checkIconRect = new Rectangle();
  static Rectangle arrowIconRect = new Rectangle();
  static Rectangle viewRect = new Rectangle(32767, 32767);
  static Rectangle r = new Rectangle();
  private final JMenuItem menuItem;
  private final boolean iconBorderEnabled;
  private final Font acceleratorFont;
  private final Color selectionForeground;
  private final Color disabledForeground;
  private final Color acceleratorForeground;
  private final Color acceleratorSelectionForeground;
  private final String acceleratorDelimiter;
  private final Icon fillerIcon;
  
  public MenuItemRenderer(JMenuItem menuItem, boolean iconBorderEnabled, Font acceleratorFont, Color selectionForeground, Color disabledForeground, Color acceleratorForeground, Color acceleratorSelectionForeground)
  {
    this.menuItem = menuItem;
    this.iconBorderEnabled = iconBorderEnabled;
    this.acceleratorFont = acceleratorFont;
    this.selectionForeground = selectionForeground;
    this.disabledForeground = disabledForeground;
    this.acceleratorForeground = acceleratorForeground;
    this.acceleratorSelectionForeground = acceleratorSelectionForeground;
    acceleratorDelimiter = UIManager.getString("MenuItem.acceleratorDelimiter");
    fillerIcon = new MinimumSizedIcon();
  }
  
  private Icon getIcon(JMenuItem aMenuItem, Icon defaultIcon)
  {
    Icon icon = aMenuItem.getIcon();
    if (icon == null) {
      return defaultIcon;
    }
    ButtonModel model = aMenuItem.getModel();
    if (!model.isEnabled()) {
      return model.isSelected() ? aMenuItem.getDisabledSelectedIcon() : aMenuItem.getDisabledIcon();
    }
    if ((model.isPressed()) && (model.isArmed()))
    {
      Icon pressedIcon = aMenuItem.getPressedIcon();
      return pressedIcon != null ? pressedIcon : icon;
    }
    if (model.isSelected())
    {
      Icon selectedIcon = aMenuItem.getSelectedIcon();
      return selectedIcon != null ? selectedIcon : icon;
    }
    return icon;
  }
  
  private boolean hasCustomIcon()
  {
    return getIcon(menuItem, null) != null;
  }
  
  private Icon getWrappedIcon(Icon icon)
  {
    if (hideIcons()) {
      return NO_ICON;
    }
    if (icon == null) {
      return fillerIcon;
    }
    return (iconBorderEnabled) && (hasCustomIcon()) ? new MinimumSizedCheckIcon(icon, menuItem) : new MinimumSizedIcon(icon);
  }
  
  private void resetRects()
  {
    iconRect.setBounds(zeroRect);
    textRect.setBounds(zeroRect);
    acceleratorRect.setBounds(zeroRect);
    checkIconRect.setBounds(zeroRect);
    arrowIconRect.setBounds(zeroRect);
    viewRect.setBounds(0, 0, 32767, 32767);
    r.setBounds(zeroRect);
  }
  
  public Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap)
  {
    JMenuItem b = (JMenuItem)c;
    String text = b.getText();
    KeyStroke accelerator = b.getAccelerator();
    String acceleratorText = "";
    if (accelerator != null)
    {
      int modifiers = accelerator.getModifiers();
      if (modifiers > 0)
      {
        acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
        acceleratorText = acceleratorText + acceleratorDelimiter;
      }
      int keyCode = accelerator.getKeyCode();
      if (keyCode != 0) {
        acceleratorText = acceleratorText + KeyEvent.getKeyText(keyCode);
      } else {
        acceleratorText = acceleratorText + accelerator.getKeyChar();
      }
    }
    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);
    FontMetrics fmAccel = b.getFontMetrics(acceleratorFont);
    
    resetRects();
    
    Icon wrappedIcon = getWrappedIcon(getIcon(menuItem, checkIcon));
    Icon wrappedArrowIcon = new MinimumSizedIcon(arrowIcon);
    Icon icon = wrappedIcon.getIconHeight() > fillerIcon.getIconHeight() ? wrappedIcon : null;
    
    layoutMenuItem(fm, text, fmAccel, acceleratorText, icon, wrappedIcon, wrappedArrowIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, acceleratorRect, checkIconRect, arrowIconRect, text == null ? 0 : defaultTextIconGap, defaultTextIconGap);
    
    r.setBounds(textRect);
    r = SwingUtilities.computeUnion(iconRectx, iconRecty, iconRectwidth, iconRectheight, r);
    
    Container parent = menuItem.getParent();
    if ((parent != null) && ((parent instanceof JComponent)) && ((!(menuItem instanceof JMenu)) || (!((JMenu)menuItem).isTopLevelMenu())))
    {
      JComponent p = (JComponent)parent;
      
      Integer maxTextWidth = (Integer)p.getClientProperty("maxTextWidth");
      Integer maxAccWidth = (Integer)p.getClientProperty("maxAccWidth");
      
      int maxTextValue = maxTextWidth != null ? maxTextWidth.intValue() : 0;
      int maxAccValue = maxAccWidth != null ? maxAccWidth.intValue() : 0;
      if (rwidth < maxTextValue) {
        rwidth = maxTextValue;
      } else {
        p.putClientProperty("maxTextWidth", new Integer(rwidth));
      }
      if (acceleratorRectwidth > maxAccValue)
      {
        maxAccValue = acceleratorRectwidth;
        p.putClientProperty("maxAccWidth", new Integer(acceleratorRectwidth));
      }
      rwidth += maxAccValue;
      rwidth += 10;
    }
    if (useCheckAndArrow())
    {
      rwidth += checkIconRectwidth;
      rwidth += defaultTextIconGap;
      
      rwidth += defaultTextIconGap;
      rwidth += arrowIconRectwidth;
    }
    rwidth += 2 * defaultTextIconGap;
    
    Insets insets = b.getInsets();
    if (insets != null)
    {
      rwidth += left + right;
      rheight += top + bottom;
    }
    if (rheight % 2 == 1) {
      rheight += 1;
    }
    return r.getSize();
  }
  
  public void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap)
  {
    JMenuItem b = (JMenuItem)c;
    ButtonModel model = b.getModel();
    
    int menuWidth = b.getWidth();
    int menuHeight = b.getHeight();
    In
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd