Exemple #1
0
  /**
   * Starts file chooser.
   *
   * @param dir whether it needs dir or file
   */
  protected void startFileChooser(
      final Widget paramWi, final String directory, final boolean dirOnly) {
    final Host host = getFirstConnectedHost();
    if (host == null) {
      Tools.appError("Connection to host lost.");
      return;
    }
    final VMSHardwareInfo thisClass = this;
    final JFileChooser fc =
        new JFileChooser(getLinuxDir(directory, host), getFileSystemView(host, directory)) {
          /** Serial version UID. */
          private static final long serialVersionUID = 1L;

          @Override
          public final void setCurrentDirectory(final File dir) {
            super.setCurrentDirectory(new LinuxFile(thisClass, host, dir.toString(), "d", 0, 0));
          }
        };
    fc.setBackground(ClusterBrowser.STATUS_BACKGROUND);
    fc.setDialogType(JFileChooser.CUSTOM_DIALOG);
    if (dirOnly) {
      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    }
    fc.setDialogTitle(Tools.getString("VMSDiskInfo.FileChooserTitle") + host.getName());
    //        fc.setApproveButtonText(Tools.getString("VMSDiskInfo.Approve"));
    fc.setApproveButtonToolTipText(Tools.getString("VMSDiskInfo.Approve.ToolTip"));
    fc.putClientProperty("FileChooser.useShellFolder", Boolean.FALSE);
    final int ret =
        fc.showDialog(Tools.getGUIData().getMainFrame(), Tools.getString("VMSDiskInfo.Approve"));
    linuxFileCache.clear();
    if (ret == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null) {
      final String name = fc.getSelectedFile().getAbsolutePath();
      paramWi.setValue(name);
    }
  }
Exemple #2
0
  /** Appends a text whith specified color to the terminal area. */
  private void append(final String text, final MutableAttributeSet colorAS) {
    userCommand = false;
    final MyDocument doc = (MyDocument) terminalArea.getStyledDocument();
    mPosLock.lock();
    final int end = terminalArea.getDocument().getLength();
    pos = end + pos - maxPos;
    maxPos = end;
    final char[] chars = text.toCharArray();
    StringBuilder colorString = new StringBuilder(10);
    boolean inside = false;
    for (int i = 0; i < chars.length; i++) {
      final char c = chars[i];
      final String s = Character.toString(c);
      boolean printit = true;
      if (c == 8) {
        /* one position to the left */
        printit = false;
        pos--;
      } else if (i < chars.length - 1 && c == 13 && chars[i + 1] == 10) {
        /* new line */
        prevLine = maxPos + 2;
        pos = maxPos;
      } else if (c == 13) {
        /* beginning of the same line */
        pos = prevLine;
        printit = false;
      } else if (c == 27) {
        /* funny colors, e.g. in sles */
        inside = true;
        printit = false;
        colorString = new StringBuilder(10);
      }
      if (inside) {
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
          /* we are done */
          inside = false;
          if (c == 'm') {
            Color newColor = getColorFromString(colorString.toString());

            if (newColor == null) {
              newColor = defaultOutputColor;
            }
            StyleConstants.setForeground(colorAS, newColor);
            colorString = new StringBuilder(10);
          } else if (c == 'G') {
            final int g = getCharCount(colorString.toString());
            pos = prevLine + g;
            while (pos > maxPos) {
              try {
                doc.insertString(maxPos, " ", colorAS);
                maxPos++;
              } catch (javax.swing.text.BadLocationException e1) {
                Tools.appError("TerminalPanel pos: " + pos, e1);
              }
            }
          }
        } else if (printit) {
          colorString.append(s);
        }
        printit = false;
      }

      if (printit) {
        if (pos < maxPos) {
          try {
            commandOffset = pos - 1;
            doc.removeForced(pos, 1);
          } catch (javax.swing.text.BadLocationException e) {
            Tools.appError("TerminalPanel pos: " + pos, e);
          }
        }
        try {
          doc.insertString(pos, s, colorAS);
        } catch (javax.swing.text.BadLocationException e1) {
          Tools.appError("TerminalPanel pos: " + pos, e1);
        }
        pos++;
        if (maxPos < pos) {
          maxPos = pos;
        }
      }
    }
    commandOffset = terminalArea.getDocument().getLength();
    terminalArea.setCaretPosition(terminalArea.getDocument().getLength());
    mPosLock.unlock();
    userCommand = true;
  }