org-netbeans-core-output2

16:39:34.378 INFO  jd.cli.Main - Decompiling org-netbeans-core-output2.jar
package org.netbeans.core.output2;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.util.Exceptions;
import org.openide.util.Mutex;
import org.openide.windows.IOColors.OutputType;
import org.openide.windows.OutputListener;

abstract class AbstractLines
  implements Lines, Runnable, ActionListener
{
  IntList lineStartList;
  IntMap lineWithListenerToInfo;
  IntMap linesToInfos;
  private int longestLineLen = 0;
  private int knownCharsPerLine = -1;
  private SparseIntList knownLogicalLineCounts = null;
  private int lastStorageSize = -1;
  
  AbstractLines()
  {
    if (Controller.LOG) {
      Controller.log("Creating a new AbstractLines");
    }
    init();
  }
  
  public char[] getText(int paramInt1, int paramInt2, char[] paramArrayOfChar)
  {
    if (paramArrayOfChar == null) {
      paramArrayOfChar = new char[paramInt2 - paramInt1];
    }
    if ((paramInt2 < paramInt1) || (paramInt1 < 0)) {
      throw new IllegalArgumentException("Illogical text range from " + paramInt1 + " to " + paramInt2);
    }
    if (paramInt2 - paramInt1 > paramArrayOfChar.length) {
      throw new IllegalArgumentException("Array size is too small");
    }
    synchronized (readLock())
    {
      if (isDisposed())
      {
        for (i = 0; i < paramInt2 - paramInt1; i++) {
          paramArrayOfChar[i] = '\000';
        }
        return paramArrayOfChar;
      }
      int i = toByteIndex(paramInt1);
      int j = toByteIndex(paramInt2 - paramInt1);
      try
      {
        CharBuffer localCharBuffer = getStorage().getReadBuffer(i, j).asCharBuffer();
        
        int k = Math.min(paramInt2 - paramInt1, localCharBuffer.remaining());
        localCharBuffer.get(paramArrayOfChar, 0, k);
        return paramArrayOfChar;
      }
      catch (Exception localException)
      {
        handleException(localException);
        return new char[0];
      }
    }
  }
  
  CharBuffer getCharBuffer(int paramInt1, int paramInt2)
  {
    if ((paramInt2 < 0) || (paramInt1 < 0)) {
      throw new IllegalArgumentException("Illogical text range from " + paramInt1 + " to " + (paramInt1 + paramInt2));
    }
    synchronized (readLock())
    {
      if (isDisposed()) {
        return null;
      }
      int i = toByteIndex(paramInt1);
      int j = toByteIndex(paramInt2);
      int k = getStorage().size();
      if (k < i + j) {
        throw new ArrayIndexOutOfBoundsException("Bytes from " + i + " to " + (i + j) + " requested, " + "but storage is only " + k + " bytes long");
      }
      try
      {
        return getStorage().getReadBuffer(i, j).asCharBuffer();
      }
      catch (Exception localException)
      {
        return null;
      }
    }
  }
  
  public String getText(int paramInt1, int paramInt2)
  {
    CharBuffer localCharBuffer = getCharBuffer(paramInt1, paramInt2 - paramInt1);
    return localCharBuffer != null ? localCharBuffer.toString() : new String(new char[paramInt2 - paramInt1]);
  }
  
  void onDispose(int paramInt)
  {
    lastStorageSize = paramInt;
  }
  
  int getByteSize()
  {
    synchronized (readLock())
    {
      if (lastStorageSize >= 0) {
        return lastStorageSize;
      }
      Storage localStorage = getStorage();
      return localStorage == null ? 0 : localStorage.size();
    }
  }
  
  private ChangeListener listener = null;
  
  public void addChangeListener(ChangeListener paramChangeListener)
  {
    listener = paramChangeListener;
    synchronized (this)
    {
      if (getLineCount() > 0) {
        fire();
      }
    }
  }
  
  public void removeChangeListener(ChangeListener paramChangeListener)
  {
    if (listener == paramChangeListener) {
      listener = null;
    }
  }
  
  private Timer timer = null;
  private final AtomicBoolean newEvent = new AtomicBoolean(false);
  private boolean dirty;
  
  public void actionPerformed(ActionEvent paramActionEvent)
  {
    newEvent.set(false);
    fire();
    synchronized (newEvent)
    {
      if (!newEvent.get()) {
        timer.stop();
      }
    }
  }
  
  void delayedFire()
  {
    newEvent.set(true);
    if (listener == null) {
      return;
    }
    if (timer == null) {
      timer = new Timer(200, this);
    }
    synchronized (newEvent)
    {
      if ((newEvent.get()) && (!timer.isRunning())) {
        timer.start();
      }
    }
  }
  
  public void fire()
  {
    if (Controller.LOG) {
      Controller.log(this + ": Writer firing " + getStorage().size() + " bytes written");
    }
    if (listener != null) {
      Mutex.EVENT.readAccess(this);
    }
  }
  
  public void run()
  {
    if (listener != null) {
      listener.stateChanged(new ChangeEvent(this));
    }
  }
  
  public boolean hasListeners()
  {
    return firstListenerLine() != -1;
  }
  
  public OutputListener getListener(int paramInt, int[] paramArrayOfInt)
  {
    int i = getLineAt(paramInt);
    int j = getLineStart(i);
    paramInt -= j;
    LineInfo localLineInfo = (LineInfo)lineWithListenerToInfo.get(i);
    if (localLineInfo == null) {
      return null;
    }
    int k = 0;
    for (LineInfo.Segment localSegment : localLineInfo.getLineSegments())
    {
      if (paramInt < localSegment.getEnd())
      {
        if (localSegment.getListener() != null)
        {
          if (paramArrayOfInt != null)
          {
            paramArrayOfInt[0] = (j + k);
            paramArrayOfInt[1] = (j + localSegment.getEnd());
          }
          return localSegment.getListener();
        }
        return null;
      }
      k = localSegment.getEnd();
    }
    return null;
  }
  
  public boolean isListener(int paramInt1, int paramInt2)
  {
    int[] arrayOfInt = new int[2];
    OutputListener localOutputListener = getListener(paramInt1, arrayOfInt);
    return localOutputListener != null;
  }
  
  private void init()
  {
    knownLogicalLineCounts = null;
    lineStartList = new IntList(100);
    lineStartList.add(0);
    linesToInfos = new IntMap();
    lineWithListenerToInfo = new IntMap();
    longestLineLen = 0;
    listener = null;
    dirty = false;
    curDefColors = ((Color[])DEF_COLORS.clone());
  }
  
  public boolean checkDirty(boolean paramBoolean)
  {
    if (isDisposed()) {
      return false;
    }
    boolean bool = dirty;
    if (paramBoolean) {
      dirty = false;
    }
    return bool;
  }
  
  public int[] getLinesWithListeners()
  {
    return lineWithListenerToInfo.getKeys();
  }
  
  public int getCharCount()
  {
    return toCharIndex(getByteSize());
  }
  
  public String getLine(int paramInt)
    throws IOException
  {
    int i = getCharLineStart(paramInt);
    int j = toCharIndex(paramInt < lineStartList.size() - 1 ? lineStartList.get(paramInt + 1) : getByteSize());
    return getText(i, j);
  }
  
  private int getByteLineLength(int paramInt)
  {
    if (paramInt == lineStartList.size() - 1) {
      return Math.max(0, toByteIndex(lastLineLength));
    }
    int i = getByteLineStart(paramInt);
    int j = paramInt < lineStartList.size() - 1 ? lineStartList.get(paramInt + 1) - 2 * "\n".length() : getByteSize();
    return j - i;
  }
  
  public boolean isLineStart(int paramInt)
  {
    int i = toByteIndex(paramInt);
    return (lineStartList.contains(i)) || (i == 0) || ((i == getByteSize()) && (lastLineFinished));
  }
  
  public int length(int paramInt)
  {
    return toCharIndex(getByteLineLength(paramInt));
  }
  
  public int getLineStart(int paramInt)
  {
    return getCharLineStart(paramInt);
  }
  
  private int getByteLineStart(int paramInt)
  {
    if ((paramInt == lineStartList.size()) && (lastLineFinished)) {
      return getByteSize();
    }
    return lineStartList.get(paramInt);
  }
  
  private int getCharLineStart(int paramInt)
  {
    return toCharIndex(getByteLineStart(paramInt));
  }
  
  public int getLineAt(int paramInt)
  {
    int i = toByteIndex(paramInt);
    if (i >= getByteSize()) {
      return getLineCount() - 1;
    }
    return lineStartList.findNearest(i);
  }
  
  public int getLineCount()
  {
    return lineStartList.size();
  }
  
  public Collection<OutputListener> getListenersForLine(int paramInt)
  {
    LineInfo localLineInfo = (LineInfo)lineWithListenerToInfo.get(paramInt);
    if (localLineInfo == null) {
      return Collections.emptyList();
    }
    return localLineInfo.getListeners();
  }
  
  public int firstListenerLine()
  {
    if (isDisposed()) {
      return -1;
    }
    return lineWithListenerToInfo.isEmpty() ? -1 : lineWithListenerToInfo.first();
  }
  
  public OutputListener nearestListener(int paramInt, boolean paramBoolean, int[] paramArrayOfInt)
  {
    int i = getLineAt(paramInt);
    int j = lineWithListenerToInfo.nearest(i, paramBoolean);
    if (j < 0) {
      return null;
    }
    LineInfo localLineInfo = (LineInfo)lineWithListenerToInfo.get(j);
    int k = getLineStart(j);
    OutputListener localOutputListener = null;
    int[] arrayOfInt = new int[2];
    if (i == j)
    {
      if (paramBoolean)
      {
        localLineInfo.getFirstListener(arrayOfInt);
        if (arrayOfInt[0] + k > paramInt)
        {
          j = lineWithListenerToInfo.nearest(j - 1, paramBoolean);
          localLineInfo = (LineInfo)lineWithListenerToInfo.get(j);
          k = getLineStart(j);
          localOutputListener = localLineInfo.getLastListener(arrayOfInt);
        }
      }
      else
      {
        localLineInfo.getLastListener(arrayOfInt);
        if (arrayOfInt[1] + k <= paramInt)
        {
          j = lineWithListenerToInfo.nearest(j + 1, paramBoolean);
          localLineInfo = (LineInfo)lineWithListenerToInfo.get(j);
          k = getLineStart(j);
          localOutputListener = localLineInfo.getFirstListener(arrayOfInt);
        }
      }
    }
    else
    {
      paramInt = k;
      localOutputListener = paramBoolean ? localLineInfo.getLastListener(arrayOfInt) : localLineInfo.getFirstListener(arrayOfInt);
    }
    if (localOutputListener == null) {
      localOutputListener = paramBoolean ? localLineInfo.getListenerBefore(paramInt - k, arrayOfInt) : localLineInfo.getListenerAfter(paramInt - k, arrayOfInt);
    }
    if (localOutputListener != null)
    {
      arrayOfInt[0] += k;
      arrayOfInt[1] += k;
    }
    return localOutputListener;
  }
  
  public int getLongestLineLength()
  {
    return longestLineLen;
  }
  
  public void toPhysicalLineIndex(int[] paramArrayOfInt, int paramInt)
  {
    int i = paramArrayOfInt[0];
    if (i <= 0)
    {
      paramArrayOfInt[0] = 0;
      paramArrayOfInt[1] = 0;
      paramArrayOfInt[2] = lengthToLineCount(length(0), paramInt);
      return;
    }
    if ((paramInt >= longestLineLen) || (getLineCount() < 1))
    {
      paramArrayOfInt[1] = 0;
      paramArrayOfInt[2] = 1;
      return;
    }
    int j = Math.min(findPhysicalLine(i, paramInt), getLineCount() - 1);
    
    int k = getLogicalLineCountAbove(j, paramInt);
    
    int m = length(j);
    int n = lengthToLineCount(m, paramInt);
    
    paramArrayOfInt[0] = j;
    paramArrayOfInt[1] = (i - k);
    paramArrayOfInt[2] = n;
  }
  
  private int findPhysicalLine(int paramInt1, int paramInt2)
  {
    if (paramInt1 == 0) {
      return 0;
    }
    if ((paramInt2 != knownCharsPerLine) || (knownLogicalLineCounts == null)) {
      calcLogicalLineCount(paramInt2);
    }
    return knownLogicalLineCounts.getNextKey(paramInt1);
  }
  
  public int getLogicalLineCountAbove(int paramInt1, int paramInt2)
  {
    if (paramInt1 == 0) {
      return 0;
    }
    if (paramInt2 >= longestLineLen) {
      return paramInt1;
    }
    if ((paramInt2 != knownCharsPerLine) || (knownLogicalLineCounts == null)) {
      calcLogicalLineCount(paramInt2);
    }
    return knownLogicalLineCounts.get(paramInt1 - 1);
  }
  
  public int getLogicalLineCountIfWrappedAt(int paramInt)
  {
    if (paramInt >= longestLineLen) {
      return getLineCount();
    }
    int i = getLineCount();
    if ((paramInt == 0) || (i == 0)) {
      return 0;
    }
    synchronized (readLock())
    {
      if ((paramInt != knownCharsPerLine) || (knownLogicalLineCounts == null)) {
        calcLogicalLineCount(paramInt);
      }
      return knownLogicalLineCounts.get(i - 1);
    }
  }
  
  private void registerLineWithListener(int paramInt, LineInfo paramLineInfo, boolean paramBoolean)
  {
    lineWithListenerToInfo.put(paramInt, paramLineInfo);
    if (paramBoolean) {
      importantLines.add(paramInt);
    }
  }
  
  private IntList importantLines = new IntList(10);
  
  public int firstImportantListenerLine()
  {
    return importantLines.size() == 0 ? -1 : importantLines.get(0);
  }
  
  public boolean isImportantLine(int paramInt)
  {
    return importantLines.contains(paramInt);
  }
  
  private void calcLogicalLineCount(int paramInt)
  {
    synchronized (readLock())
    {
      int i = getLineCount();
      knownLogicalLineCounts = new SparseIntList(30);
      
      int j = 0;
      for (int k = 0; k < i; k++)
      {
        int m = length(k);
        if (m > paramInt)
        {
          j += lengthToLineCount(m, paramInt);
          knownLogicalLineCounts.add(k, j);
        }
        else
        {
          j++;
        }
      }
      knownCharsPerLine = paramInt;
    }
  }
  
  static int lengthToLineCount(int paramInt1, int paramInt2)
  {
    return paramInt1 > paramInt2 ? (paramInt1 + paramInt2 - 1) / paramInt2 : paramInt2 == 0 ? paramInt1 : 1;
  }
  
  void markDirty()
  {
    dirty = true;
  }
  
  boolean isLastLineFinished()
  {
    return lastLineFinished;
  }
  
  private boolean lastLineFinished = true;
  private int lastLineLength = -1;
  static final Color[] DEF_COLORS;
  Color[] curDefColors;
  private static final int MAX_FIND_SIZE = 16384;
  private Pattern pattern;
  
  private void updateLastLine(int paramInt1, int paramInt2)
  {
    synchronized (readLock())
    {
      longestLineLen = Math.max(longestLineLen, paramInt2);
      if (knownLogicalLineCounts == null) {
        return;
      }
      int j = knownLogicalLineCounts.lastIndex() == paramInt1 ? 1 : 0;
      int i;
      if (j != 0)
      {
        assert (!lastLineFinished);
        if (paramInt2 <= knownCharsPerLine)
        {
          knownLogicalLineCounts.removeLast();
        }
        else
        {
          i = knownLogicalLineCounts.lastAdded() - lengthToLineCount(lastLineLength, knownCharsPerLine) + lengthToLineCount(paramInt2, knownCharsPerLine);
          
          knownLogicalLineCounts.updateLast(paramInt1, i);
        }
      }
      else
      {
        if (paramInt2 <= knownCharsPerLine) {
          return;
        }
        if (knownLogicalLineCounts.lastIndex() != -1) {
          i = paramInt1 - (knownLogicalLineCounts.lastIndex() + 1) + knownLogicalLineCounts.lastAdded();
        } else {
          i = Math.max(0, paramInt1 - 1);
        }
        i += lengthToLineCount(paramInt2, knownCharsPerLine);
        knownLogicalLineCounts.add(paramInt1, i);
      }
    }
  }
  
  public void lineUpdated(int paramInt1, int paramInt2, boolean paramBoolean)
  {
    synchronized (readLock())
    {
      int i = toCharIndex(paramInt2);
      if (paramBoolean) {
        i--;
      }
      updateLastLine(lineStartList.size() - 1, i);
      if (paramBoolean) {
        lineStartList.add(paramInt1 + paramInt2);
      }
      lastLineFinished = paramBoolean;
      lastLineLength = (paramBoolean ? -1 : i);
    }
    markDirty();
  }
  
  static int toByteIndex(int paramInt)
  {
    return paramInt << 1;
  }
  
  static int toCharIndex(int paramInt)
  {
    assert (paramInt % 2 == 0) : ("bad index: " + paramInt);
    return paramInt >> 1;
  }
  
  public void saveAs(String paramString)
    throws IOException
  {
    Storage localStorage = getStorage();
    if (localStorage == null) {
      throw new IOException("Data has already been disposed");
    }
    FileOutputStream localFileOutputStream = new FileOutputStream(paramString);
    try
    {
      String str1 = System.getProperty("file.encoding");
      if (str1 == null) {
        str1 = "UTF-8";
      }
      Charset localCharset = Charset.forName(str1);
      CharsetEncoder localCharsetEncoder = localCharset.newEncoder();
      String str2 = System.getProperty("line.separator");
      FileChannel localFileChannel = localFileOutputStream.getChannel();
      ByteBuffer localByteBuffer1 = localCharsetEncoder.encode(CharBuffer.wrap(str2));
      for (int i = 0; i < getLineCount(); i++)
      {
        int j = getCharLineStart(i);
        int k = length(i);
        CharBuffer localCharBuffer = getCharBuffer(j, k);
        ByteBuffer localByteBuffer2 = localCharsetEncoder.encode(localCharBuffer);
        localFileChannel.write(localByteBuffer2);
        if (i != getLineCount() - 1)
        {
          localByteBuffer1.rewind();
          localFileChannel.write(localByteBuffer1);
        }
      }
      localFileChannel.close();
    }
    finally
    {
      localFileOutputStream.close();
    }
  }
  
  static
  {
    Color localColor1 = UIManager.getColor("nb.output.foreground");
    if (localColor1 == null)
    {
      localColor1 = UIManager.getColor("textText");
      if (localColor1 == null) {
        localColor1 = Color.BLACK;
      }
    }
    Color localColor2 = UIManager.getColor("nb.output.err.foreground");
    if (localColor2 == null) {
      localColor2 = new Color(164, 0, 0);
    }
    Color localColor3 = UIManager.getColor("nb.output.link.foreground");
    if (localColor3 == null) {
      localColor3 = Color.BLUE.darker();
    }
    Color localColor4 = UIManager.getColor("nb.output.link.foreground.important");
    if (localColor4 == null) {
      localColor4 = localColor3;
    }
    DEF_COLORS = new Color[] { localColor1, localColor2, localColor3, localColor4 };
  }
  
  public void setDefColor(IOColors.OutputType paramOutputType, Color paramColor)
  {
    curDefColors[paramOutputType.ordinal()] = paramColor;
  }
  
  public Color getDefColor(IOColors.OutputType paramOutputType)
  {
    return curDefColors[paramOutputType.ordinal()];
  }
  
  public LineInfo getLineInfo(int paramInt)
  {
    LineInfo localLineInfo = (LineInfo)linesToInfos.get(paramInt);
    if (localLineInfo != null)
    {
      int i = length(paramInt);
      if (i > localLineInfo.getEnd()) {
        localLineInfo.addSegment(i, false, null, null, false);
      }
      return localLineInfo;
    }
    return new LineInfo(this, length(paramInt));
  }
  
  public LineInfo getExistingLineInfo(int paramInt)
  {
    return (LineInfo)linesToInfos.get(paramInt);
  }
  
  private boolean regExpChanged(String paramString, boolean paramBoolean)
  {
    if (pattern != null) {
      if (!pattern.toString().equals(paramString)) {}
    }
    return (pattern.flags() == 2) == paramBoolean;
  }
  
  public int[] find(int paramInt, String paramString, boolean paramBoolean1, boolean paramBoolean2)
  {
    Storage localStorage = getStorage();
    if (localStorage == null) {
      return null;
    }
    if ((paramBoolean1) && (regExpChanged(paramString, paramBoolean2))) {
      pattern = null;
    }
    if ((!paramBoolean1) && (!paramBoolean2)) {
      paramString = paramString.toLowerCase();
    }
    for (;;)
    {
      int i = getCharCount() - paramInt;
      if (i > 16384)
      {
        int j = getLineAt(paramInt + 16384);
        i = getLineStart(j) + length(j) - paramInt;
      }
      else
      {
        if (i <= 0) {
          break;
        }
      }
      CharBuffer localCharBuffer = null;
      try
      {
        localCharBuffer = localStorage.getReadBuffer(toByteIndex(paramInt), toByteIndex(i)).asCharBuffer();
      }
      catch (IOException localIOException)
      {
        Exceptions.printStackTrace(localIOException);
      }
      if (localCharBuffer == null) {
        break;
      }
      if (paramBoolean1)
      {
        if (pattern == null) {
          pattern = (paramBoolean2 ? Pattern.compile(paramString) : Pattern.compile(paramString, 2));
        }
        Matcher localMatcher = pattern.matcher(localCharBuffer);
        if (localMatcher.find()) {
          return new int[] { paramInt + localMatcher.start(), paramInt + localMatcher.end() };
        }
      }
      else
      {
        int k = paramBoolean2 ? localCharBuffer.toString().indexOf(paramString) : localCharBuffer.toString().toLowerCase().indexOf(paramString);
        if (k != -1) {
          return new int[] { paramInt + k, paramInt + k + paramString.length() };
        }
      }
      paramInt += localCharBuffer.length();
    }
    return null;
  }
  
  public int[] rfind(int paramInt, String paramString, boolean paramBoolean1, boolean paramBoolean2)
  {
    Storage localStorage = getStorage();
    if (localStorage == null) {
      return null;
    }
    if ((paramBoolean1) && (regExpChanged(paramString, paramBoolean2))) {
      pattern = null;
    }
    if ((!paramBoolean1) && (!paramBoolean2)) {
      paramString = paramString.toLowerCase();
    }
    for (;;)
    {
      int i = paramInt;
      paramInt = i - 16384;
      if (paramInt < 0)
      {
        paramInt = 0;
      }
      else
      {
        int j = getLineAt(paramInt);
        paramInt = getLineStart(j);
      }
      if (paramInt == i) {
        break;
      }
      CharBuffer localCharBuffer = null;
      try
      {
        localCharBuffer = localStorage.getReadBuffer(toByteIndex(paramInt), toByteIndex(i - paramInt)).asCharBuffer();
      }
      catch (IOException localIOException)
      {
        Exceptions.printStackTrace(localIOException);
      }
      if (localCharBuffer == null) {
        break;
      }
      if (paramBoolean1)
      {
        if (pattern == null) {
          pattern = (paramBoolean2 ? Pattern.compile(paramString) : Pattern.compile(paramString, 2));
        }
        Matcher localMatcher = pattern.matcher(localCharBuffer);
        int m = -1;
        int n = -1;
        while (localMatcher.find())
        {
          m = localMatcher.start();
          n = localMatcher.end();
        }
        if (m != -1) {
          return new int[] { paramInt + m, paramInt + n };
        }
      }
      else
      {
        int k = paramBoolean2 ? localCharBuffer.toString().lastIndexOf(paramString) : localCharBuffer.toString().toLowerCase().lastIndexOf(paramString);
        if (k != -1) {
          return new int[] { paramInt + k, paramInt + k + paramString.length() };
        }
      }
    }
    return null;
  }
  
  public String toString()
  {
    return lineStartList.toString();
  }
  
  int addSegment(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3, OutputListener paramOutputListener, boolean paramBoolean1, boolean paramBoolean2, Color paramColor)
  {
    int i = length(paramInt2);
    if (i > 0)
    {
      LineInfo localLineInfo = (LineInfo)linesToInfos.get(paramInt2);
      if (localLineInfo == null)
      {
        localLineInfo = new LineInfo(this);
        linesToInfos.put(paramInt2, localLineInfo);
      }
      int j = localLineInfo.getEnd();
      if ((paramInt3 > 0) && (paramInt3 != j))
      {
        localLineInfo.addSegment(paramInt3, false, null, null, false);
        j = paramInt3;
      }
      if (paramOutputListener != null)
      {
        int k = Math.min(j + paramCharSequence.length() - paramInt1, i);
        int m = Math.min(paramCharSequence.length(), paramInt1 + i);
        if (paramCharSequence.charAt(m - 1) == '\n') {
          m--;
        }
        if (paramCharSequence.charAt(m - 1) == '\r') {
          m--;
        }
        int n = 0;
        while ((n + paramInt1 < m) && (Character.isWhitespace(paramCharSequence.charAt(paramInt1 + n)))) {
          n++;
        }
        int i1 = 0;
        if (n != m) {
          while ((i1 < m) && (Character.isWhitespace(paramCharSequence.charAt(m - i1 - 1)))) {
            i1++;
          }
        }
        if (n > 0) {
          localLineInfo.addSegment(j + n, false, null, null, false);
        }
        localLineInfo.addSegment(k - i1, paramBoolean2, paramOutputListener, paramColor, paramBoolean1);
        if (i1 > 0) {
          localLineInfo.addSegment(k, false, null, null, false);
        }
        registerLineWithListener(paramInt2, localLineInfo, paramBoolean1);
      }
      else
      {
        localLineInfo.addSegment(i, paramBoolean2, paramOutputListener, paramColor, paramBoolean1);
      }
    }
    return i;
  }
  
  void updateLinesInfo(CharSequence paramCharSequence, int paramInt1, int paramInt2, OutputListener paramOutputListener, boolean paramBoolean1, boolean paramBoolean2, Color paramColor)
  {
    int i = 0;
    Object localObject = paramCharSequence;
    if (paramOutputListener != null) {
      for (j = 0; j < paramCharSequence.length(); j++) {
        if (paramCharSequence.charAt(j) == '\t')
        {
          StringBuilder localStringBuilder = new StringBuilder(paramCharSequence.length() + 100);
          int m = 0;
          for (int n = j; n < paramCharSequence.length(); n++) {
            if (paramCharSequence.charAt(n) == '\t')
            {
              localStringBuilder.append(paramCharSequence, m, n);
              localStringBuilder.append("        ");
              m = n + 1;
            }
          }
          localStringBuilder.append(paramCharSequence, m, paramCharSequence.length());
          localObject = localStringBuilder;
          break;
        }
      }
    }
    int j = paramInt2 - getLineStart(paramInt1);
    for (int k = paramInt1; k < getLineCount(); k++)
    {
      i += addSegment((CharSequence)localObject, i, k, j, paramOutputListener, paramBoolean1, paramBoolean2, paramColor) + 1;
      j = 0;
    }
  }
  
  void addLineInfo(int paramInt, LineInfo paramLineInfo, boolean paramBoolean)
  {
    linesToInfos.put(paramInt, paramLineInfo);
    if (!paramLineInfo.getListeners().isEmpty()) {
      registerLineWithListener(paramInt, paramLineInfo, paramBoolean);
    }
  }
  
  protected abstract Storage getStorage();
  
  protected abstract boolean isDisposed();
  
  protected abstract void handleException(Exception paramException);
}

/* Location:
 * Qualified Name:     org.netbeans.core.output2.AbstractLines
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.core.output2;

import java.io.CharConversionException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.openide.windows.IOContainer;
import org.openide.xml.XMLUtil;

class Controller$CoalescedNameUpdater
  implements Runnable
{
  private Set<OutputTab> components = new HashSet();
  
  Controller$CoalescedNameUpdater(Controller paramController) {}
  
  public void add(OutputTab paramOutputTab)
  {
    components.add(paramOutputTab);
  }
  
  public void remove(OutputTab paramOutputTab)
  {
    components.remove(paramOutputTab);
  }
  
  public void run()
  {
    for (OutputTab localOutputTab : components)
    {
      NbIO localNbIO = localOutputTab.getIO();
      if (Controller.access$000(this$0).containsKey(localNbIO))
      {
        if (Controller.LOG) {
          Controller.log("Update name for " + localNbIO.getName() + " stream " + "closed is " + localNbIO.isStreamClosed());
        }
        String str1;
        try
        {
          str1 = XMLUtil.toAttributeValue(localNbIO.getName());
        }
        catch (CharConversionException localCharConversionException)
        {
          str1 = localNbIO.getName();
        }
        String str2 = "<html><b>" + str1 + " </b>&nbsp;</html>";
        if (Controller.LOG) {
          Controller.log("  set name to " + str2);
        }
        localNbIO.getIOContainer().setTitle(localOutputTab, str2.replace("&apos;", "'"));
      }
    }
    Controller.access$202(this$0, null);
  }
}

/* Location:
 * Qualified Name:     org.netbeans.core.output2.Controller.CoalescedNameUpdater
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.core.output2;

import java.io.IOException;
import org.openide.util.Exceptions;
import org.openide.windows.OutputEvent;

class Controller$ControllerOutputEvent
  extends OutputEvent
{
  private int line;
  private OutWriter out;
  
  Controller$ControllerOutputEvent(NbIO paramNbIO, int paramInt)
  {
    super(paramNbIO);
    out = paramNbIO.out();
    line = paramInt;
  }
  
  Controller$ControllerOutputEvent(NbIO paramNbIO, OutWriter paramOutWriter, int paramInt)
  {
    this(paramNbIO, paramInt);
    out = paramOutWriter;
  }
  
  void setLine(int paramInt)
  {
    line = paramInt;
  }
  
  public String getLine()
  {
    NbIO localNbIO = (NbIO)getSource();
    OutWriter localOutWriter = localNbIO.out();
    try
    {
      if (localOutWriter != null)
      {
        String str = localOutWriter.getLines().getLine(line);
        if (str.endsWith("\n")) {
          str = str.substring(0, str.length() - 1);
        }
        if (str.endsWith("\r")) {}
        return str.substring(0, str.length() - 1);
      }
    }
    catch (IOException localIOException1)
    {
      IOException localIOException2 = new IOException("Could not fetch line " + line + " on " + localNbIO.getName());
      localIOException2.initCause(localIOException1);
      Exceptions.printStackTrace(localIOException1);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.netbeans.core.output2.Controller.ControllerOutputEvent
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.core.output2;

import java.awt.Font;
import java.io.CharConversionException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.prefs.Preferences;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.netbeans.core.output2.ui.AbstractOutputPane;
import org.openide.util.Exceptions;
import org.openide.util.NbPreferences;
import org.openide.windows.IOColors.OutputType;
import org.openide.windows.IOContainer;
import org.openide.windows.IOSelect.AdditionalOperation;
import org.openide.windows.OutputEvent;
import org.openide.xml.XMLUtil;

public class Controller
{
  static Controller controller;
  
  public static Controller getDefault()
  {
    if (controller == null) {
      controller = new Controller();
    }
    return controller;
  }
  
  private Map<NbIO, OutputTab> ioToTab = new HashMap();
  private static final String KEY_FONTSIZE = "fontsize";
  private static final String KEY_FONTNAME = "fontname";
  private static final String KEY_FONTSTYLE = "fontstyle";
  private static final String KEY_FONTSIZE_MONOSPACED = "fontsize_monospaced";
  private static final int MIN_FONT_SIZE = 3;
  private static Font defaultFont;
  private Font currentFontMS;
  
  void eventDispatched(IOEvent paramIOEvent)
  {
    if (LOG) {
      log("Event received: " + paramIOEvent);
    }
    NbIO localNbIO = paramIOEvent.getIO();
    int i = paramIOEvent.getCommand();
    boolean bool = paramIOEvent.getValue();
    Object localObject = paramIOEvent.getData();
    OutputTab localOutputTab = (OutputTab)ioToTab.get(localNbIO);
    if (LOG) {
      log("Passing command to controller " + paramIOEvent);
    }
    performCommand(localOutputTab, localNbIO, i, bool, localObject);
    paramIOEvent.consume();
  }
  
  private OutputTab createOutputTab(NbIO paramNbIO)
  {
    if (LOG) {
      log("Create component for nbio " + paramNbIO);
    }
    OutputTab localOutputTab1 = new OutputTab(paramNbIO);
    localOutputTab1.setName(paramNbIO.getName() + " ");
    Action[] arrayOfAction = paramNbIO.getToolbarActions();
    if (arrayOfAction != null) {
      localOutputTab1.setToolbarActions(arrayOfAction);
    }
    if (LOG) {
      log("Adding new tab " + localOutputTab1);
    }
    ioToTab.put(paramNbIO, localOutputTab1);
    IOContainer localIOContainer = paramNbIO.getIOContainer();
    localIOContainer.add(localOutputTab1, localOutputTab1);
    localIOContainer.setToolbarActions(localOutputTab1, arrayOfAction);
    if (paramNbIO.getIcon() != null) {
      localIOContainer.setIcon(localOutputTab1, paramNbIO.getIcon());
    }
    if (paramNbIO.getToolTipText() != null) {
      localIOContainer.setToolTipText(localOutputTab1, paramNbIO.getToolTipText());
    }
    paramNbIO.setClosed(false);
    for (OutputTab localOutputTab2 : ioToTab.values()) {
      updateName(localOutputTab2);
    }
    return localOutputTab1;
  }
  
  void removeTab(NbIO paramNbIO)
  {
    OutputTab localOutputTab = (OutputTab)ioToTab.remove(paramNbIO);
    removeFromUpdater(localOutputTab);
  }
  
  private Font currentFont = currentFont();
  private boolean allMonospaced;
  
  void changeFontSizeBy(int paramInt, boolean paramBoolean)
  {
    int i = (paramBoolean ? currentFontMS.getSize() : currentFont.getSize()) + paramInt;
    if (i < 3) {
      i = 3;
    } else if (i > 72) {
      i = 72;
    }
    String str = (paramBoolean) || (allMonospaced) ? "fontsize_monospaced" : "fontsize";
    NbPreferences.forModule(Controller.class).putInt(str, i);
    Font localFont;
    if ((paramBoolean) || (allMonospaced))
    {
      currentFontMS = getCurrentFontMS().deriveFont(i);
      localFont = currentFontMS;
      if (allMonospaced) {
        currentFont = currentFontMS;
      }
    }
    else
    {
      currentFont = currentFont.deriveFont(i);
      localFont = currentFont;
    }
    for (OutputTab localOutputTab : ioToTab.values()) {
      if ((allMonospaced) || (localOutputTab.getOutputPane().isWrapped() == paramBoolean)) {
        localOutputTab.getOutputPane().setViewFont(localFont);
      }
    }
  }
  
  void changeFont(Font paramFont)
  {
    currentFont = (paramFont == null ? getDefaultFont() : paramFont);
    allMonospaced = isDefaultFontType(currentFont);
    if (allMonospaced)
    {
      currentFontMS = currentFont;
      NbPreferences.forModule(Controller.class).putInt("fontsize_monospaced", currentFont.getSize());
    }
    NbPreferences.forModule(Controller.class).putInt("fontsize", currentFont.getSize());
    NbPreferences.forModule(Controller.class).putInt("fontstyle", currentFont.getStyle());
    NbPreferences.forModule(Controller.class).put("fontname", currentFont.getName());
    for (OutputTab localOutputTab : ioToTab.values()) {
      if ((allMonospaced) || (!localOutputTab.getOutputPane().isWrapped())) {
        localOutputTab.getOutputPane().setViewFont(currentFont);
      }
    }
  }
  
  private static Font getDefaultFont()
  {
    if (defaultFont == null)
    {
      int i = UIManager.getInt("uiFontSize");
      if (i < 3) {
        i = UIManager.getInt("customFontSize");
      }
      if (i < 3)
      {
        Font localFont = (Font)UIManager.get("controlFont");
        if (localFont != null) {
          i = localFont.getSize();
        }
      }
      if (i < 3) {
        i = 11;
      }
      defaultFont = new Font("Monospaced", 0, i);
    }
    return defaultFont;
  }
  
  public Font getCurrentFont()
  {
    return currentFont;
  }
  
  private Font currentFont()
  {
    String str = NbPreferences.forModule(Controller.class).get("fontname", "Monospaced");
    int i = NbPreferences.forModule(Controller.class).getInt(str.equals("Monospaced") ? "fontsize_monospaced" : "fontsize", -1);
    int j = NbPreferences.forModule(Controller.class).getInt("fontstyle", -1);
    Font localFont;
    if ((i == -1) || (j == -1))
    {
      localFont = getDefaultFont();
      if (i != -1) {
        localFont = localFont.deriveFont(i);
      }
      allMonospaced = true;
    }
    else
    {
      localFont = new Font(str, j, i);
      allMonospaced = isDefaultFontType(localFont);
    }
    return localFont;
  }
  
  private boolean isDefaultFontType(Font paramFont)
  {
    Font localFont = getDefaultFont();
    return (localFont.getName().equals(paramFont.getName())) && (localFont.getStyle() == paramFont.getStyle());
  }
  
  public Font getCurrentFontMS()
  {
    if (currentFontMS == null)
    {
      currentFontMS = getDefaultFont();
      int i = NbPreferences.forModule(Controller.class).getInt("fontsize_monospaced", -1);
      if (i != -1) {
        currentFontMS = currentFontMS.deriveFont(i);
      }
    }
    return currentFontMS;
  }
  
  void removeFromUpdater(OutputTab paramOutputTab)
  {
    if (nameUpdater != null) {
      nameUpdater.remove(paramOutputTab);
    }
  }
  
  void updateName(OutputTab paramOutputTab)
  {
    if (nameUpdater == null)
    {
      if (LOG) {
        log("Update name for " + paramOutputTab.getIO() + " dispatching a name updater");
      }
      nameUpdater = new CoalescedNameUpdater();
      SwingUtilities.invokeLater(nameUpdater);
    }
    nameUpdater.add(paramOutputTab);
  }
  
  private static boolean htmlTabsBroken()
  {
    String str = System.getProperty("java.version");
    for (int i = 14; i < 18; i++) {
      if (str.startsWith("1.6.0_" + i)) {
        return true;
      }
    }
    if ((str.startsWith("1.6.0_20")) && ("Aqua".equals(UIManager.getLookAndFeel().getID()))) {
      return true;
    }
    return false;
  }
  
  private static final boolean DONT_USE_HTML = htmlTabsBroken();
  private CoalescedNameUpdater nameUpdater = null;
  
  private class CoalescedNameUpdater
    implements Runnable
  {
    private Set<OutputTab> components = new HashSet();
    
    CoalescedNameUpdater() {}
    
    public void add(OutputTab paramOutputTab)
    {
      components.add(paramOutputTab);
    }
    
    public void remove(OutputTab paramOutputTab)
    {
      components.remove(paramOutputTab);
    }
    
    public void run()
    {
      for (OutputTab localOutputTab : components)
      {
        NbIO localNbIO = localOutputTab.getIO();
        if (ioToTab.containsKey(localNbIO))
        {
          if (Controller.LOG) {
            Controller.log("Update name for " + localNbIO.getName() + " stream " + "closed is " + localNbIO.isStreamClosed());
          }
          String str1;
          try
          {
            str1 = XMLUtil.toAttributeValue(localNbIO.getName());
          }
          catch (CharConversionException localCharConversionException)
          {
            str1 = localNbIO.getName();
          }
          String str2 = "<html><b>" + str1 + " </b>&nbsp;</html>";
          if (Controller.LOG) {
            Controller.log("  set name to " + str2);
          }
          localNbIO.getIOContainer().setTitle(localOutputTab, str2.replace("&apos;", "'"));
        }
      }
      nameUpdater = null;
    }
  }
  
  void performCommand(OutputTab paramOutputTab, NbIO paramNbIO, int paramInt, boolean paramBoolean, Object paramObject)
  {
    if (LOG) {
      log("PERFORMING: " + IOEvent.cmdToString(paramInt) + " value=" + paramBoolean + " on " + paramNbIO + " tob " + paramOutputTab);
    }
    IOContainer localIOContainer = paramNbIO.getIOContainer();
    Object localObject;
    switch (paramInt)
    {
    case 0: 
      createOutputTab(paramNbIO);
      break;
    case 2: 
      if ((paramBoolean) && (paramOutputTab == null)) {
        paramOutputTab = createOutputTab(paramNbIO);
      }
      if (paramOutputTab != null) {
        paramOutputTab.setInputVisible(paramBoolean);
      }
      break;
    case 6: 
      if (paramOutputTab == null) {
        paramOutputTab = createOutputTab(paramNbIO);
      }
      if (paramNbIO.isFocusTaken()) {
        localIOContainer.
1 2 3 4 5 6 7 8

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