org-netbeans-core-io-ui

16:39:32.175 INFO  jd.cli.Main - Decompiling org-netbeans-core-io-ui.jar
package org.netbeans.core.io.ui;

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

class IOWindow$IOWindowImpl$1
  implements Icon
{
  IOWindow$IOWindowImpl$1(IOWindow.IOWindowImpl paramIOWindowImpl) {}
  
  public int getIconHeight()
  {
    return 16;
  }
  
  public int getIconWidth()
  {
    return 16;
  }
  
  public void paintIcon(Component paramComponent, Graphics paramGraphics, int paramInt1, int paramInt2) {}
}

/* Location:
 * Qualified Name:     org.netbeans.core.io.ui.IOWindow.IOWindowImpl.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.core.io.ui;

import java.awt.event.MouseEvent;
import javax.swing.JPopupMenu;
import org.openide.awt.MouseUtils.PopupMouseAdapter;

class IOWindow$IOWindowImpl$2
  extends MouseUtils.PopupMouseAdapter
{
  IOWindow$IOWindowImpl$2(IOWindow.IOWindowImpl paramIOWindowImpl) {}
  
  protected void showPopup(MouseEvent paramMouseEvent)
  {
    IOWindow.IOWindowImpl.access$000(this$0).show(this$0, paramMouseEvent.getX(), paramMouseEvent.getY());
  }
}

/* Location:
 * Qualified Name:     org.netbeans.core.io.ui.IOWindow.IOWindowImpl.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.core.io.ui;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import org.openide.util.NbBundle;

class IOWindow$IOWindowImpl$Close
  extends AbstractAction
{
  public IOWindow$IOWindowImpl$Close(IOWindow.IOWindowImpl paramIOWindowImpl)
  {
    super(NbBundle.getMessage(IOWindow.IOWindowImpl.class, "LBL_Close"));
  }
  
  public void actionPerformed(ActionEvent paramActionEvent)
  {
    this$0.removeTab(this$0.getSelectedTab());
  }
}

/* Location:
 * Qualified Name:     org.netbeans.core.io.ui.IOWindow.IOWindowImpl.Close
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.core.io.ui;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import org.openide.util.NbBundle;

class IOWindow$IOWindowImpl$CloseAll
  extends AbstractAction
{
  public IOWindow$IOWindowImpl$CloseAll(IOWindow.IOWindowImpl paramIOWindowImpl)
  {
    super(NbBundle.getMessage(IOWindow.IOWindowImpl.class, "LBL_CloseAll"));
  }
  
  public void actionPerformed(ActionEvent paramActionEvent)
  {
    IOWindow.IOWindowImpl.access$100(this$0);
  }
}

/* Location:
 * Qualified Name:     org.netbeans.core.io.ui.IOWindow.IOWindowImpl.CloseAll
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.core.io.ui;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import org.openide.util.NbBundle;

class IOWindow$IOWindowImpl$CloseOthers
  extends AbstractAction
{
  public IOWindow$IOWindowImpl$CloseOthers(IOWindow.IOWindowImpl paramIOWindowImpl)
  {
    super(NbBundle.getMessage(IOWindow.IOWindowImpl.class, "LBL_CloseOthers"));
  }
  
  public void actionPerformed(ActionEvent paramActionEvent)
  {
    IOWindow.IOWindowImpl.access$200(this$0);
  }
}

/* Location:
 * Qualified Name:     org.netbeans.core.io.ui.IOWindow.IOWindowImpl.CloseOthers
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.core.io.ui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.border.Border;
import org.openide.util.Utilities;

class IOWindow$IOWindowImpl$VariableRightBorder
  implements Border
{
  private JTabbedPane pane;
  
  public IOWindow$IOWindowImpl$VariableRightBorder(IOWindow.IOWindowImpl paramIOWindowImpl, JTabbedPane paramJTabbedPane)
  {
    pane = paramJTabbedPane;
  }
  
  public void paintBorder(Component paramComponent, Graphics paramGraphics, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    if (pane.getParent() != this$0)
    {
      Color localColor = paramGraphics.getColor();
      paramGraphics.setColor(getColor());
      paramGraphics.drawLine(paramInt1 + paramInt3 - 1, paramInt2, paramInt1 + paramInt3 - 1, paramInt2 + paramInt4);
      paramGraphics.setColor(localColor);
    }
  }
  
  public Color getColor()
  {
    if (Utilities.isMac())
    {
      Color localColor1 = UIManager.getColor("controlShadow");
      Color localColor2 = UIManager.getColor("control");
      return new Color((localColor1.getRed() + localColor2.getRed()) / 2, (localColor1.getGreen() + localColor2.getGreen()) / 2, (localColor1.getBlue() + localColor2.getBlue()) / 2);
    }
    return UIManager.getColor("controlShadow");
  }
  
  public Insets getBorderInsets(Component paramComponent)
  {
    if (pane.getParent() == this$0) {
      return new Insets(0, 0, 0, 0);
    }
    return new Insets(0, 0, 0, 2);
  }
  
  public boolean isBorderOpaque()
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.netbeans.core.io.ui.IOWindow.IOWindowImpl.VariableRightBorder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.core.io.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.ObjectStreamException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.awt.MouseUtils.PopupMouseAdapter;
import org.openide.awt.TabbedPaneFactory;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.windows.IOContainer.CallBacks;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;

final class IOWindow$IOWindowImpl
  extends TopComponent
  implements ChangeListener, PropertyChangeListener
{
  static IOWindowImpl DEFAULT;
  private static final String ICON_PROP = "tabIcon";
  private static final String TOOLBAR_ACTIONS_PROP = "toolbarActions";
  private static final String TOOLBAR_BUTTONS_PROP = "toolbarButtons";
  private static final String ICON_RESOURCE = "org/netbeans/core/resources/frames/output.png";
  
  static synchronized IOWindowImpl findDefault()
  {
    if (DEFAULT == null)
    {
      TopComponent localTopComponent = WindowManager.getDefault().findTopComponent("output");
      if (localTopComponent != null)
      {
        if ((localTopComponent instanceof IOWindowImpl))
        {
          DEFAULT = (IOWindowImpl)localTopComponent;
        }
        else
        {
          IllegalStateException localIllegalStateException = new IllegalStateException("Incorrect settings file. Unexpected class returned. Expected: " + IOWindowImpl.class.getName() + " Returned: " + localTopComponent.getClass().getName());
          
          Logger.getLogger(IOWindowImpl.class.getName()).log(Level.WARNING, null, localIllegalStateException);
          
          getDefault();
        }
      }
      else {
        getDefault();
      }
    }
    DEFAULT.getActionMap().remove("org.openide.actions.FindAction");
    return DEFAULT;
  }
  
  public static synchronized IOWindowImpl getDefault()
  {
    if (DEFAULT == null) {
      DEFAULT = new IOWindowImpl();
    }
    return DEFAULT;
  }
  
  public Object readResolve()
    throws ObjectStreamException
  {
    return getDefault();
  }
  
  private static final boolean AQUA = "Aqua".equals(UIManager.getLookAndFeel().getID());
  private JTabbedPane pane;
  private JComponent singleTab;
  private JToolBar toolbar;
  private JPopupMenu popupMenu;
  private Map<JComponent, IOContainer.CallBacks> tabToCb = new HashMap();
  boolean activated;
  JComponent lastSelTab;
  
  public IOWindow$IOWindowImpl()
  {
    pane = TabbedPaneFactory.createCloseButtonTabbedPane();
    pane.addChangeListener(this);
    pane.addPropertyChangeListener("close", this);
    setFocusable(true);
    
    toolbar = new JToolBar();
    toolbar.setOrientation(1);
    toolbar.setLayout(new BoxLayout(toolbar, 1));
    toolbar.setFloatable(false);
    Insets localInsets = toolbar.getMargin();
    JButton localJButton = new JButton();
    localJButton.setBorderPainted(false);
    localJButton.setOpaque(false);
    localJButton.setText(null);
    localJButton.setIcon(new Icon()
    {
      public int getIconHeight()
      {
        return 16;
      }
      
      public int getIconWidth()
      {
        return 16;
      }
      
      public void paintIcon(Component paramAnonymousComponent, Graphics paramAnonymousGraphics, int paramAnonymousInt1, int paramAnonymousInt2) {}
    });
    toolbar.add(localJButton);
    Dimension localDimension1 = localJButton.getPreferredSize();
    Dimension localDimension2 = new Dimension(width + left + right, height + top + bottom);
    toolbar.setMinimumSize(localDimension2);
    toolbar.setPreferredSize(localDimension2);
    toolbar.remove(localJButton);
    setLayout(new BorderLayout());
    add(toolbar, "West");
    toolbar.setBorder(new VariableRightBorder(pane));
    toolbar.setBorderPainted(true);
    
    popupMenu = new JPopupMenu();
    popupMenu.add(new Close());
    popupMenu.add(new CloseAll());
    popupMenu.add(new CloseOthers());
    pane.addMouseListener(new MouseUtils.PopupMouseAdapter()
    {
      protected void showPopup(MouseEvent paramAnonymousMouseEvent)
      {
        popupMenu.show(IOWindow.IOWindowImpl.this, paramAnonymousMouseEvent.getX(), paramAnonymousMouseEvent.getY());
      }
    });
    String str = NbBundle.getMessage(IOWindow.class, "LBL_IO_WINDOW");
    setDisplayName(str);
    setToolTipText(str);
    
    setName(str);
    
    setIcon(ImageUtilities.loadImage("org/netbeans/core/resources/frames/output.png"));
    
    putClientProperty("SlidingName", getDisplayName());
    if (AQUA)
    {
      setBackground(UIManager.getColor("NbExplorerView.background"));
      setOpaque(true);
      toolbar.setBackground(UIManager.getColor("NbExplorerView.background"));
      pane.setBackground(UIManager.getColor("NbExplorerView.background"));
      pane.setOpaque(true);
    }
  }
  
  public void open()
  {
    if (!isOpened()) {
      super.open();
    }
  }
  
  public void requestActive()
  {
    super.requestActive();
    JComponent localJComponent = getSelectedTab();
    if (localJComponent != null) {
      localJComponent.requestFocus();
    }
  }
  
  public void requestVisible()
  {
    if (!isShowing())
    {
      super.requestVisible();
      if (Boolean.TRUE.equals(getClientProperty("isSliding"))) {
        requestActive();
      }
    }
  }
  
  public boolean isActivated()
  {
    return activated;
  }
  
  public void addTab(JComponent paramJComponent, IOContainer.CallBacks paramCallBacks)
  {
    if (paramCallBacks != null) {
      tabToCb.put(paramJComponent, paramCallBacks);
    }
    if (singleTab != null)
    {
      assert (pane.getParent() == null);
      assert (pane.getTabCount() == 0);
      remove(singleTab);
      pane.add(singleTab);
      pane.setIconAt(0, (Icon)singleTab.getClientProperty("tabIcon"));
      pane.setToolTipTextAt(0, singleTab.getToolTipText());
      singleTab = null;
      pane.add(paramJComponent);
      add(pane);
      updateWindowName(null);
    }
    else if (pane.getTabCount() > 0)
    {
      assert (pane.getParent() != null);
      assert (singleTab == null);
      pane.add(paramJComponent);
    }
    else
    {
      assert (pane.getParent() == null);
      assert (singleTab == null);
      setFocusable(false);
      singleTab = paramJComponent;
      add(paramJComponent);
      updateWindowName(singleTab.getName());
      checkTabSelChange();
    }
    revalidate();
  }
  
  public void removeTab(JComponent paramJComponent)
  {
    if (singleTab != null)
    {
      assert (singleTab == paramJComponent);
      remove(singleTab);
      singleTab = null;
      updateWindowName(null);
      checkTabSelChange();
      setFocusable(true);
      revalidate();
      repaint();
    }
    else if (pane.getParent() == this)
    {
      assert (pane.getTabCount() > 1);
      pane.remove(paramJComponent);
      if (pane.getTabCount() == 1)
      {
        singleTab = ((JComponent)pane.getComponentAt(0));
        pane.remove(singleTab);
        remove(pane);
        add(singleTab);
        updateWindowName(singleTab.getName());
      }
      revalidate();
    }
    IOContainer.CallBacks localCallBacks = (IOContainer.CallBacks)tabToCb.remove(paramJComponent);
    if (localCallBacks != null) {
      localCallBacks.closed();
    }
  }
  
  public void selectTab(JComponent paramJComponent)
  {
    if (singleTab == null) {
      pane.setSelectedComponent(paramJComponent);
    }
    checkTabSelChange();
  }
  
  public JComponent getSelectedTab()
  {
    return singleTab != null ? singleTab : (JComponent)pane.getSelectedComponent();
  }
  
  public void setTitle(JComponent paramJComponent, String paramString)
  {
    paramJComponent.setName(paramString);
    if (singleTab != null)
    {
      assert (singleTab == paramJComponent);
      updateWindowName(paramString);
    }
    else
    {
      assert (pane.getParent() == this);
      int i = pane.indexOfComponent(paramJComponent);
      assert (i >= 0);
      pane.setTitleAt(i, paramString);
    }
  }
  
  public void setToolTipText(JComponent paramJComponent, String paramString)
  {
    paramJComponent.setToolTipText(paramString);
    if (singleTab != null)
    {
      if ((!$assertionsDisabled) && (singleTab != paramJComponent)) {
        throw new AssertionError();
      }
    }
    else
    {
      assert (pane.getParent() == this);
      int i = pane.indexOfComponent(paramJComponent);
      assert (i >= 0);
      pane.setToolTipTextAt(i, paramString);
    }
  }
  
  public void setIcon(JComponent paramJComponent, Icon paramIcon)
  {
    if (paramJComponent == singleTab)
    {
      paramJComponent.putClientProperty("tabIcon", paramIcon);
      return;
    }
    int i = pane.indexOfComponent(paramJComponent);
    if (i < 0) {
      return;
    }
    paramJComponent.putClientProperty("tabIcon", paramIcon);
    pane.setIconAt(i, paramIcon);
    pane.setDisabledIconAt(i, paramIcon);
  }
  
  void setToolbarActions(JComponent paramJComponent, Action[] paramArrayOfAction)
  {
    if ((paramArrayOfAction != null) && (paramArrayOfAction.length > 0))
    {
      if (paramArrayOfAction.length > 5) {
        throw new IllegalArgumentException("No more than 5 actions allowed in the output window toolbar");
      }
      paramJComponent.putClientProperty("toolbarActions", paramArrayOfAction);
    }
    if (getSelectedTab() == paramJComponent) {
      updateToolbar(paramJComponent);
    }
  }
  
  public int getPersistenceType()
  {
    return 0;
  }
  
  public String preferredID()
  {
    return "output";
  }
  
  public void processFocusEvent(FocusEvent paramFocusEvent)
  {
    super.processFocusEvent(paramFocusEvent);
    if (Boolean.TRUE.equals(getClientProperty("isSliding"))) {
      repaint(200L);
    }
  }
  
  public void paintComponent(Graphics paramGraphics)
  {
    if (AQUA)
    {
      paramGraphics.setColor(getBackground());
      paramGraphics.fillRect(0, 0, getWidth(), getHeight());
    }
    super.paintComponent(paramGraphics);
    if (hasFocus())
    {
      Insets localInsets = getInsets();
      Color localColor = UIManager.getColor("controlShadow");
      if (localColor == null) {
        localColor = Color.GRAY;
      }
      paramGraphics.setColor(localColor);
      paramGraphics.drawRect(left + 2, top + 2, getWidth() - (left + right + 4), getHeight() - (top + bottom + 4));
    }
  }
  
  void updateWindowName(String paramString)
  {
    String str1 = NbBundle.getMessage(IOWindowImpl.class, "LBL_IO_WINDOW");
    if (paramString != null)
    {
      String str2 = NbBundle.getMessage(IOWindowImpl.class, "FMT_IO_WINDOW", new Object[] { str1, paramString });
      if (str2.indexOf("<html>") != -1)
      {
        str2 = "<html>" + str2.replace("<html>", "");
        setHtmlDisplayName(str2);
        setToolTipText(str2);
      }
      else
      {
        setDisplayName(str2);
        setHtmlDisplayName(null);
        setToolTipText(str2);
      }
    }
    else
    {
      setDisplayName(str1);
      setToolTipText(str1);
      setHtmlDisplayName(null);
    }
  }
  
  private void updateToolbar(JComponent paramJComponent)
  {
    toolbar.removeAll();
    if (paramJComponent != null)
    {
      JButton[] arrayOfJButton = getTabButtons(paramJComponent);
      for (int i = 0; i < arrayOfJButton.length; i++) {
        toolbar.add(arrayOfJButton[i]);
      }
    }
    toolbar.revalidate();
    toolbar.repaint();
  }
  
  JButton[] getTabButtons(JComponent paramJComponent)
  {
    JButton[] arrayOfJButton = (JButton[])paramJComponent.getClientProperty("toolbarButtons");
    if (arrayOfJButton != null) {
      return arrayOfJButton;
    }
    Action[] arrayOfAction = (Action[])paramJComponent.getClientProperty("toolbarActions");
    if (arrayOfAction == null) {
      return new JButton[0];
    }
    arrayOfJButton = new JButton[arrayOfAction.length];
    for (int i = 0; i < arrayOfJButton.length; i++)
    {
      arrayOfJButton[i] = new JButton(arrayOfAction[i]);
      arrayOfJButton[i].setBorderPainted(false);
      arrayOfJButton[i].setOpaque(false);
      arrayOfJButton[i].setText(null);
      arrayOfJButton[i].putClientProperty("hideActionText", Boolean.TRUE);
      Object localObject = arrayOfAction[i].getValue("SmallIcon");
      if (!(localObject instanceof Icon)) {
        throw new IllegalStateException("No icon provided for " + arrayOfAction[i]);
      }
      arrayOfJButton[i].setDisabledIcon(ImageUtilities.createDisabledIcon((Icon)localObject));
    }
    return arrayOfJButton;
  }
  
  protected void componentActivated()
  {
    super.componentActivated();
    activated = true;
    JComponent localJComponent = getSelectedTab();
    IOContainer.CallBacks localCallBacks = (IOContainer.CallBacks)tabToCb.get(localJComponent);
    if (localCallBacks != null) {
      localCallBacks.activated();
    }
  }
  
  protected void componentDeactivated()
  {
    super.componentDeactivated();
    activated = false;
    JComponent localJComponent = getSelectedTab();
    IOContainer.CallBacks localCallBacks = (IOContainer.CallBacks)tabToCb.get(localJComponent);
    if (localCallBacks != null) {
      localCallBacks.deactivated();
    }
  }
  
  public void stateChanged(ChangeEvent paramChangeEvent)
  {
    checkTabSelChange();
  }
  
  public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
  {
    if ("close".equals(paramPropertyChangeEvent.getPropertyName()))
    {
      JComponent localJComponent = (JComponent)paramPropertyChangeEvent.getNewValue();
      removeTab(localJComponent);
    }
  }
  
  void checkTabSelChange()
  {
    JComponent localJComponent = getSelectedTab();
    if (localJComponent != lastSelTab)
    {
      lastSelTab = localJComponent;
      updateToolbar(localJComponent);
      getActionMap().setParent(localJComponent != null ? localJComponent.getActionMap() : null);
    }
  }
  
  private JComponent[] getTabs()
  {
    if (singleTab != null) {
      return new JComponent[] { singleTab };
    }
    JComponent[] arrayOfJComponent = new JComponent[pane.getTabCount()];
    for (int i = 0; i < pane.getTabCount(); i++) {
      arrayOfJComponent[i] = ((JComponent)pane.getComponentAt(i));
    }
    return arrayOfJComponent;
  }
  
  private void closeOtherTabs()
  {
    assert (pane.getParent() == this);
    JComponent localJComponent1 = getSelectedTab();
    for (JComponent localJComponent2 : getTabs()) {
      if (localJComponent2 != localJComponent1) {
        removeTab(localJComponent2);
      }
    }
  }
  
  private void closeAllTabs()
  {
    for (JComponent localJComponent : getTabs()) {
      removeTab(localJComponent);
    }
  }
  
  private class Close
    extends AbstractAction
  {
    public Close()
    {
      super();
    }
    
    public void actionPerformed(ActionEvent paramActionEvent)
    {
      removeTab(getSelectedTab());
    }
  }
  
  private class CloseAll
    extends AbstractAction
  {
    public CloseAll()
    {
      super();
    }
    
    public void actionPerformed(ActionEvent paramActionEvent)
    {
      IOWindow.IOWindowImpl.this.closeAllTabs();
    }
  }
  
  private class CloseOthers
    extends AbstractAction
  {
    public CloseOthers()
    {
      super();
    }
    
    public void actionPerformed(ActionEvent paramActionEvent)
    {
      IOWindow.IOWindowImpl.this.closeOtherTabs();
    }
  }
  
  private class VariableRightBorder
    implements Border
  {
    private JTabbedPane pane;
    
    public VariableRightBorder(JTabbedPane paramJTabbedPane)
    {
      pane = paramJTabbedPane;
    }
    
    public void paintBorder(Component paramComponent, Graphics paramGraphics, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
    {
      if (pane.getParent() != IOWindow.IOWindowImpl.this)
      {
        Color localColor = paramGraphics.getColor();
        paramGraphics.setColor(getColor());
        paramGraphics.drawLine(paramInt1 + paramInt3 - 1, paramInt2, paramInt1 + paramInt3 - 1, paramInt2 + paramInt4);
        paramGraphics.setColor(localColor);
      }
    }
    
    public Color getColor()
    {
      if (Utilities.isMac())
      {
        Color localColor1 = UIManager.getColor("controlShadow");
        Color localColor2 = UIManager.getColor("control");
        return new Color((localColor1.getRed() + localColor2.getRed()) / 2, (localColor1.getGreen() + localColor2.getGreen()) / 2, (localColor1.getBlue() + localColor2.getBlue()) / 2);
      }
      return UIManager.getColor("controlShadow");
    }
    
    public Insets getBorderInsets(Component paramComponent)
    {
      if (pane.getParent() == IOWindow.IOWindowImpl.this) {
        return new Insets(0, 0, 0, 0);
      }
      return new Insets(0, 0, 0, 2);
    }
    
    public boolean isBorderOpaque()
    {
      return true;
    }
  }
}

/* Location:
 * Qualified Name:     org.netbeans.core.io.ui.IOWindow.IOWindowImpl
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.core.io.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.ObjectStreamException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.awt.MouseUtils.PopupMouseAdapter;
import org.openide.awt.TabbedPaneFactory;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.windows.IOContainer.CallBacks;
import org.openide.windows.IOContainer.Provider;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;

public final class IOWindow
  implements IOContainer.Provider
{
  private static IOWindowImpl impl;
  
  IOWindowImpl impl()
  {
    if (impl == null) {
      impl = IOWindowImpl.findDefault();
    }
    return impl;
  }
  
  public void add(JComponent paramJComponent, IOContainer.CallBacks paramCallBacks)
  {
    impl().addTab(paramJComponent, paramCallBacks);
  }
  
  public JComponent getSelected()
  {
    return impl().getSelectedTab();
  }
  
  public boolean isActivated()
  {
    return impl().isActivated();
  }
  
  public void open()
  {
    impl().open();
  }
  
  public void remove(JComponent paramJComponent)
  {
    impl().removeTab(paramJComponent);
  }
  
  public void requestActive()
  {
    impl().requestActive();
  }
  
  public void requestVisible()
  {
    impl().requestVisible();
  }
  
  public void select(JComponent paramJComponent)
  {
    impl().selectTab(paramJComponent);
  }
  
  public void setIcon(JComponent paramJComponent, Icon paramIcon)
  {
    impl().setIcon(paramJComponent, paramIcon);
  }
  
  public void setTitle(JComponent paramJComponent, String paramString)
  {
    impl().setTitle(paramJComponent, paramString);
  }
  
  public void setToolTipText(JComponent paramJComponent, String paramString)
  {
    impl().setToolTipText(paramJComponent, paramString);
  }
  
  public void setToolbarActions(JComponent paramJComponent, Action[] paramArrayOfAction)
  {
    impl().setToolbarActions(paramJComponent, paramArrayOfAction);
  }
  
  public boolean isCloseable(JComponent paramJComponent)
  {
    return true;
  }
  
  static final class IOWindowImpl
    extends TopComponent
    implements ChangeListener, PropertyChangeListener
  {
    static IOWindowImpl DEFAULT;
    private static final String ICON_PROP = "tabIcon";
    private static final String TOOLBAR_ACTIONS_PROP = "toolbarActions";
    private static final String TOOLBAR_BUTTONS_PROP = "toolbarButtons";
    private static final String ICON_RESOURCE = "org/netbeans/core/resources/frames/output.png";
    
    static synchronized IOWindowImpl findDefault()
    {
      if (DEFAULT == null)
      {
        TopComponent localTopComponent = WindowManager.getDefault().findTopComponent("output");
        if (localTopComponent != null)
        {
          if ((localTopComponent instanceof IOWindowImpl))
          {
            DEFAULT = (IOWindowImpl)localTopComponent;
          }
          else
          {
            IllegalStateException localIllegalStateException = new IllegalStateException("Incorrect settings file. Unexpected class returned. Expected: " + IOWindowImpl.class.getName() + " Returned: " + localTopComponent.getClass().getName());
            
            Logger.getLogger(IOWindowImpl.class.getName()).log(Level.WARNING, null, localIllegalStateException);
            
            getDefault();
          }
        }
        else {
          getDefault();
        }
      }
      DEFAULT.getActionMap().remove("org.openide.actions.FindAction");
      return DEFAULT;
    }
    
    public static synchronized IOWindowImpl getDefault()
    {
      if (DEFAULT == null) {
        DEFAULT = new IOWindowImpl();
      }
      return DEFAULT;
    }
    
    public Object readResolve()
      throws ObjectStreamException
    {
      return getDefault();
    }
    
    private static final boolean AQUA = "Aqua".equals(UIManager.getLookAndFeel().getID());
    private JTabbedPane pane;
    private JComponent singleTab;
    private JToolBar toolbar;
    private JPopupMenu popupMenu;
    private Map<JComponent, IOContainer.CallBacks> tabToCb = new HashMap();
    boolean activated;
    JComponent lastSelTab;
    
    public IOWindowImpl()
    {
      pane = TabbedPaneFactory.createCloseButtonTabbedPane();
      pane.addChangeListener(this);
      pane.addPropertyChangeListener("close", this);
      setFocusable(true);
      
      toolbar = new JToolBar();
      toolbar.setOrientation(1);
      toolbar.setLayout(new BoxLayout(toolbar, 1));
      toolbar.setFloatable(false);
      Insets localInsets = toolbar.getMargin();
      JButton localJButton = new JButton();
      localJButton.setBorderPainted(false);
      localJButton.setOpaque(false);
      localJButton.setText(null);
      localJButton.setIcon(new Icon()
      {
        public int getIconHeight()
        {
          return 16;
        }
        
        public int getIconWidth()
        {
          return 16;
        }
        
        public void paintIcon(Component paramAnonymousComponent, Graphics paramAnonymousGraphics, int paramAnonymousInt1, int paramAnonymousInt2) {}
      });
      toolbar.add(localJButton);
      Dimension localDimension1 = localJButton.getPreferredSize();
      Dimension localDimension2 = new Dimension(width + left + right, height + top + bottom);
      toolbar.setMinimumSize(localDimension2);
      toolbar.setPreferredSize(localDimension2);
      toolbar.remove(localJButton);
      setLayout(new BorderLayout());
      add(toolbar, "West");
      toolbar.setBorder(new VariableRightBorder(pane));
      toolbar.setBorderPainted(true);
      
      popupMenu = new JPopupMenu();
      popupMenu.add(new Close());
      popupMenu.add(new CloseAll());
      popupMenu.add(new CloseOthers());
      pane.addMouseListener(new MouseUtils.PopupMouseAdapter()
      {
        protected void showPopup(MouseEvent paramAnonymousMouseEvent)
        {
          popupMenu.show(IOWindow.IOWindowImpl.this, paramAnonymousMouseEvent.getX(), paramAnonymousMouseEvent.getY());
        }
      });
      String str = NbBundle.getMessage(IOWindow.class, "LBL_IO_WINDOW");
      setDisplayName(str);
      setToolTipText(str);
      
      setName(str);
      
      setIcon(ImageUtilities.loadImage("org/netbeans/core/resources/frames/output.png"));
      
      putClientProperty("SlidingName", getDisplayName());
      if (AQUA)
      {
        setBackground(UIManager.getColor("NbExplorerView.background"));
        setOpaque(true);
        toolbar.setBackground(UIManager.getColor("NbExplorerView.background"));
        pane.setBackground(UIManager.getColor("NbExplorerView.background"));
        pane.setOpaque(true);
      }
    }
    
    public void open()
    {
      if (!isOpened()) {
        super.open();
      }
    }
    
    public void requestActive()
    {
      super.requestActive();
      JComponent localJComponent = getSelectedTab();
      if (localJComponent != null) {
        localJComponent.requestFocus();
      }
    }
    
    public void requestVisible()
    {
      if (!isShowing())
      {
        super.requestVisible();
        if (Boolean.TRUE.equals(getClientProperty("isSliding"))) {
          requestActive();
        }
      }
    }
    
    public boolean isActivated()
    {
      return activated;
    }
    
    public void addTab(JComponent paramJComponent, IOContainer.CallBacks paramCallBacks)
    {
      if (paramCallBacks != null) {
        tabToCb.put(paramJComponent, paramCallBacks);
      }
      if (singleTab != null)
      {
        assert (pane.getParent() == null);
        assert (pane.getTabCount() == 0);
        remove(singleTab);
        pane.add(singleTab);
        pane.setIconAt(0, (Icon)singleTab.getClientProperty("tabIcon"));
        pane.setToolTipTextAt(0, singleTab.getToolTipText());
        singleTab = null;
        pane.add(paramJComponent);
        add(pane);
        updateWindowName(null);
      }
      else if (pane.getTabCount() > 0)
      {
        assert (pane.getParent() != null);
        assert (singleTab == null);
        pane.add(paramJComponent);
      }
      else
      {
        assert (pane.getParent() == null);
        assert (singleTab == null);
        setFocusable(false);
        singleTab = paramJComponent;
        add(paramJComponent);
        updateWindowName(singleTab.getName());
        checkTabSelChange();
      }
      revalidate();
    }
    
    public void removeTab(JComponent paramJComponent)
    {
      if (singleTab != null)
      {
        assert (singleTab == paramJComponent);
        remove(singleTab);
        singleTab = null;
        updateWindowName(null);
        checkTabSelChange();
        setFocusable(true);
        revalidate();
        repaint();
      }
      else if (pane.getParent() == this)
      {
        assert (pane.getTabCount() > 1);
        pane.remove(paramJComponent);
        if (pane.getTabCount() == 1)
        {
          singleTab = ((JComponent)pane.getComponentAt(0));
          pane.remove(singleTab);
          remove(pane);
          add(singleTab);
          updateWindowName(singleTab.getName());
        }
        revalidate();
      }
      IOContainer.CallBacks localCallBacks = (IOContainer.CallBacks)tabToCb.remove(paramJComponent);
      if (localCallBacks != null) {
        localCallBacks.closed();
      }
    }
    
    public void selectTab(JComponent paramJComponent)
    {
      if (singleTab == null) {
        pane.setSelectedComponent(paramJComponent);
      }
      checkTabSelChange();
    }
    
    public JComponent getSelectedTab()
    {
      return singleTab != null ? singleTab : (JComponent)pane.getSelectedComponent();
    }
    
    public void setTitle(JComponent paramJComponent, String paramString)
    {
      paramJComponent.setName(paramString);
      if (singleTab != null)
      {
        assert (singleTab == paramJComponent);
        updateWindowName(paramString);
      }
      else
      {
        assert (pane.getParent() == this);
        int i = pane.indexOfComponent(paramJComponent);
        assert (i >= 0);
        pane.setTitleAt(i, paramString);
      }
    }
    
    public void setToolTipText(JComponent paramJComponent, String paramString)
    {
      paramJComponent.setToolTipText(paramString);
      if (singleTab != null)
      {
        if ((!$assertionsDisabled) && (singleTab != paramJComponent)) {
          throw new AssertionError();
        }
      }
      else
      {
        assert (pane.getParent() == this);
        int i = pane.indexOfComponent(paramJComponent);
        assert (i >= 0);
        pane.setToolTipTextAt(i, paramString);
      }
    }
    
    public void setIcon(JComponent paramJComponent, Icon paramIcon)
    {
      if (paramJComponent == singleTab)
      {
        paramJComponent.putClientProperty("tabIcon", paramIcon);
        return;
      }
      int i = pane.indexOfComponent(paramJComponent);
      if (i < 0) {
        return;
      }
      paramJComponent.putClientProperty("tabIcon", paramIcon);
      pane.setIconAt(i, paramIcon);
      pane.setDisabledIconAt(i, paramIcon);
    }
    
    void setToolbarActions(JComponent paramJComponent, Action[] paramArrayOfAction)
    {
      if ((paramArrayOfAction != null) && (paramArrayOfAction.length > 0))
      {
        if (paramArrayOfAction.length > 5) {
          throw new IllegalArgumentException("No more than 5 actions allowed in the output window toolbar");
        }
        paramJComponent.putClientProperty("toolbarActions", paramArrayOfAction);
      }
      if (getSelectedTab() == paramJComponent) {
        updateToolbar(paramJComponent);
      }
    }
    
    public int getPersistenceType()
    {
      return 0;
    }
    
    public String preferredID()
    {
      return "output";
    }
    
    public void processFocusEvent(FocusEvent paramFocusEvent)
    {
      super.processFocusEvent(paramFocusEvent);
      if (Boolean.TRUE.equals(getClientProperty("isSliding"))) {
        repaint(200L);
      }
    }
    
    public void paintComponent(Graphics paramGraphics)
    {
      if (AQUA)
      {
        paramGraphics.setColor(getBackground());
        paramGraphics.fillRect(0, 0, getWidth(), getHeight());
      }
      super.paintComponent(paramGraphics);
      if (hasFocus())
      {
        Insets localInsets = getInsets();
        Color localColor = UIManager.getColor("controlShadow");
        if (localColor == null) {
          localColor = Color.GRAY;
        }
        paramGraphics.setColor(localColor);
        paramGraphics.drawRect(left + 2, top + 2, getWidth() - (left + right + 4), getHeight() - (top + bottom + 4));
      }
    }
    
    void updateWindowName(String paramString)
    {
      String str1 = NbBundle.getMessage(IOWindowImpl.class, "LBL_IO_WINDOW");
      if (paramString != null)
      {
        String str2 = NbBundle.getMessage(IOWindowImpl.class, "FMT_IO_WINDOW", new Object[] { str1, paramString });
        if (str2.indexOf("<html>") != -1)
        {
          str2 = "<html>" + str2.replace("<html>", "");
          setHtmlDisplayName(str2);
          setToolTipText(str2);
        }
        else
        {
          setDisplayName(str2);
          setHtmlDisplayName(null);
          setToolTipText(str2);
        }
      }
      else
      {
        setDisplayName(str1);
        setToolTipText(str1);
        setHtmlDisplayName(null);
      }
    }
    
    private void updateToolbar(JComponent paramJComponent)
    {
      toolbar.removeAll();
      if (paramJComponent != null)
      {
        JButton[] arrayOfJButton = getTabButtons(paramJComponent);
        for (int i = 0; i < arrayOfJButton.length; i++) {
          toolbar.add(arrayOfJButton[i]);
        }
      }
      toolbar.revalidate();
      toolbar.repaint();
    }
    
    JButton[] getTabButtons(JComponent paramJComponent)
    {
      JButton[] arrayOfJButton = (JButton[])paramJComponent.getClientProperty("toolbarButtons");
      if (arrayOfJButton != null) {
        return arrayOfJButton;
      }
      Action[] arrayOfAction = (Action[])paramJComponent.getClientProperty("toolbarActions");
      if (arrayOfAction == null) {
        return new JButton[0];
      }
      arrayOfJButton = new JButton[arrayOfAction.length];
      for (int i = 0; i < arrayOfJButton.length; i++)
      {
        arrayOfJButton[i] = new JButton(arrayOfAction[i]);
        arrayOfJButton[i].setBorderPainted(false);
        arrayOfJButton[i].setOpaque(false);
        arrayOfJButton[i].setText(null);
        arrayOfJButton[i].putClientProperty("hideActionText", Boolean.TRUE);
        Object localObject = arrayOfAction[i].getValue("SmallIcon");
        if (!(localObject instanceof Icon)) {
          throw new IllegalStateException("No icon provided for " + arrayOfAction[i]);
        }
        arrayOfJButton[i].setDisabledIcon(ImageUtilities.createDisabledIcon((Icon)localObject));
      }
      return arrayOfJButton;
    }
    
    protected void componentActivated()
    {
      super.componentActivated();
      activated = true;
      JComponent localJComponent = getSelectedTab();
      IOContainer.CallBacks localCallBacks = (IOContainer.CallBacks)tabToCb.get(localJComponent);
      if (localCallBacks != null) {
        localCallBacks.activated();
      }
    }
    
    protected void componentDeactivated()
    {
      super.componentDeactivated();
      activated = false;
      JComponent localJComponent = getSelectedTab();
      IOContainer.CallBacks localCallBacks = (IOContainer.CallBacks)tabToCb.get(localJComponent);
      if (localCallBacks != null) {
        localCallBacks.deactivated();
      }
    }
    
    public void stateChanged(ChangeEvent paramChangeEvent)
    {
      checkTabSelChange();
    }
    
    public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
    {
      if ("close".equals(paramPropertyChangeEvent.getPropertyName()))
      {
        JComponent localJComponent = (JComponent)paramPropertyChangeEvent.getNewValue();
        removeTab(localJComponent);
      }
    }
    
    void checkTabSelChange()
    {
      JComponent localJComponent = getSelectedTab();
      if (localJComponent != lastSelTab)
      {
        lastSelTab = localJComponent;
        updateToolbar(localJComponent);
        getActionMap().setParent(localJComponent != null ? localJComponent.getActi
1 2

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