示例#1
0
 /** Returns the height of the dialog. */
 protected int dialogHeight() {
   return Tools.getDefaultInt("ConfigDialog.height");
 }
示例#2
0
  /** Returns input pane where user can configure a drbd resource. */
  @Override
  protected JComponent getInputPane() {
    final DrbdResourceInfo dri = getDrbdVolumeInfo().getDrbdResourceInfo();
    final DrbdInfo drbdInfo = dri.getDrbdInfo();
    dri.getInfoPanel();
    dri.waitForInfoPanel();
    Tools.waitForSwing();
    final JPanel inputPane = new JPanel();
    inputPane.setLayout(new BoxLayout(inputPane, BoxLayout.X_AXIS));

    final JPanel optionsPanel = new JPanel();
    optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS));
    optionsPanel.setAlignmentY(Component.TOP_ALIGNMENT);
    /* common options */
    final Map<String, String> commonPreferredValue = new HashMap<String, String>();
    commonPreferredValue.put(PROTOCOL, "C");
    commonPreferredValue.put(DEGR_WFC_TIMEOUT_PARAM, "0");
    commonPreferredValue.put(CRAM_HMAC_ALG, "sha1");
    commonPreferredValue.put(SHARED_SECRET, getRandomSecret());
    commonPreferredValue.put(ON_IO_ERROR, "detach");
    if (drbdInfo.getDrbdResources().size() <= 1) {
      for (final String commonP : COMMON_PARAMS) {
        /* for the first resource set common options. */
        final String commonValue = drbdInfo.getResource().getValue(commonP);
        if (commonPreferredValue.containsKey(commonP)) {
          final String defaultValue = drbdInfo.getParamDefault(commonP);
          if ((defaultValue == null && "".equals(commonValue))
              || (defaultValue != null && defaultValue.equals(commonValue))) {
            drbdInfo.paramComboBoxGet(commonP, null).setValue(commonPreferredValue.get(commonP));
            dri.getResource().setValue(commonP, commonPreferredValue.get(commonP));
          } else {
            dri.getResource().setValue(commonP, commonValue);
          }
        }
      }
    } else {
      /* resource options, if not defined in common section. */
      for (final String commonP : COMMON_PARAMS) {
        final String commonValue = drbdInfo.getResource().getValue(commonP);
        if ("".equals(commonValue) && commonPreferredValue.containsKey(commonP)) {
          dri.getResource().setValue(commonP, commonPreferredValue.get(commonP));
        }
      }
    }

    /* address combo boxes */
    dri.addHostAddresses(
        optionsPanel,
        ClusterBrowser.SERVICE_LABEL_WIDTH,
        ClusterBrowser.SERVICE_FIELD_WIDTH,
        true,
        buttonClass(nextButton()));
    dri.addWizardParams(
        optionsPanel,
        PARAMS,
        buttonClass(nextButton()),
        Tools.getDefaultInt("Dialog.DrbdConfig.Resource.LabelWidth"),
        Tools.getDefaultInt("Dialog.DrbdConfig.Resource.FieldWidth"),
        null);

    inputPane.add(optionsPanel);
    final JScrollPane sp = new JScrollPane(inputPane);
    sp.setMaximumSize(new Dimension(Short.MAX_VALUE, 200));
    sp.setPreferredSize(new Dimension(Short.MAX_VALUE, 200));
    return sp;
  }
示例#3
0
 /** Returns the width of the dialog. */
 protected int dialogWidth() {
   return Tools.getDefaultInt("ConfigDialog.width");
 }
示例#4
0
  /** Prepares a new <code>TerminalPanel</code> object. */
  public TerminalPanel(final Host host) {
    super();
    this.host = host;
    host.setTerminalPanel(this);
    /* Sets terminal some of the output colors. This is in no way complete
     * or correct and probably doesn't have to be. */
    terminalColor.put("0", Tools.getDefaultColor("TerminalPanel.TerminalWhite"));
    terminalColor.put("30", Tools.getDefaultColor("TerminalPanel.TerminalBlack"));
    terminalColor.put("31", Tools.getDefaultColor("TerminalPanel.TerminalRed"));
    terminalColor.put("32", Tools.getDefaultColor("TerminalPanel.TerminalGreen"));
    terminalColor.put("33", Tools.getDefaultColor("TerminalPanel.TerminalYellow"));
    terminalColor.put("34", Tools.getDefaultColor("TerminalPanel.TerminalBlue"));
    terminalColor.put("35", Tools.getDefaultColor("TerminalPanel.TerminalPurple"));
    terminalColor.put("36", Tools.getDefaultColor("TerminalPanel.TerminalCyan"));
    final Font f = new Font("Monospaced", Font.PLAIN, Tools.getConfigData().scaled(14));
    terminalArea = new JTextPane();
    terminalArea.setStyledDocument(new MyDocument());
    final DefaultCaret caret =
        new DefaultCaret() {
          private static final long serialVersionUID = 1L;

          @Override
          protected synchronized void damage(final Rectangle r) {
            if (r != null) {
              x = r.x;
              y = r.y;
              width = 8;
              height = r.height;
              repaint();
            }
          }

          @Override
          public void paint(final Graphics g) {
            /* painting cursor. If it is not visible it is out of focus, we
             * make it barely visible. */
            try {
              TextUI mapper = getComponent().getUI();
              Rectangle r = mapper.modelToView(getComponent(), getDot(), getDotBias());
              if (r == null) {
                return;
              }
              g.setColor(getComponent().getCaretColor());
              if (isVisible() && editEnabled) {
                g.fillRect(r.x, r.y, 8, r.height);
              } else {
                g.drawRect(r.x, r.y, 8, r.height);
              }
            } catch (BadLocationException e) {
              Tools.appError("Drawing of cursor failed", e);
            }
          }
        };
    terminalArea.setCaret(caret);
    terminalArea.addCaretListener(
        new CaretListener() {
          @Override
          public void caretUpdate(final CaretEvent e) {
            /* don't do this if caret moved because of selection */
            mPosLock.lock();
            try {
              if (e != null && e.getDot() < commandOffset && e.getDot() == e.getMark()) {
                terminalArea.setCaretPosition(commandOffset);
              }
            } finally {
              mPosLock.unlock();
            }
          }
        });

    /* set font and colors */
    terminalArea.setFont(f);
    terminalArea.setBackground(Tools.getDefaultColor("TerminalPanel.Background"));

    commandColor = new SimpleAttributeSet();
    StyleConstants.setForeground(commandColor, Tools.getDefaultColor("TerminalPanel.Command"));

    errorColor = new SimpleAttributeSet();
    StyleConstants.setForeground(errorColor, Tools.getDefaultColor("TerminalPanel.Error"));

    outputColor = new SimpleAttributeSet();
    defaultOutputColor = Tools.getDefaultColor("TerminalPanel.Output");
    StyleConstants.setForeground(outputColor, defaultOutputColor);

    promptColor = new SimpleAttributeSet();
    StyleConstants.setForeground(promptColor, host.getPmColors()[0]);

    append(prompt(), promptColor);
    terminalArea.setEditable(true);
    getViewport().add(terminalArea, BorderLayout.PAGE_END);
    setPreferredSize(
        new Dimension(Short.MAX_VALUE, Tools.getDefaultInt("MainPanel.TerminalPanelHeight")));
    setMinimumSize(getPreferredSize());
    setMaximumSize(getPreferredSize());
  }