Ejemplo n.º 1
0
  /**
   * Creates body of the dialog. You can redefine getDialogTitle(), getDescription(), getInputPane()
   * methods to customize this body.
   */
  protected final JPanel body() {
    final JPanel pane = new JPanel();
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    final JEditorPane descPane =
        new JEditorPane(
            Tools.MIME_TYPE_TEXT_HTML,
            "<span style='font:bold italic;font-family:Dialog; font-size:"
                + Tools.getConfigData().scaled(14)
                + ";'>"
                + getDialogTitle()
                + "</span><br>"
                + "<span style='font-family:Dialog; font-size:"
                + Tools.getConfigData().scaled(12)
                + ";'>"
                + getDescription()
                + "</span>");
    descPane.setSize(300, Integer.MAX_VALUE);

    descPane.setBackground(Tools.getDefaultColor("ConfigDialog.Background"));
    descPane.setEditable(false);
    final JScrollPane descSP = new JScrollPane(descPane);
    descSP.setBorder(null);
    descSP.setAlignmentX(Component.LEFT_ALIGNMENT);
    descSP.setMinimumSize(new Dimension(0, 50));
    pane.add(descSP);
    final JComponent inputPane = getInputPane();
    if (inputPane != null) {
      inputPane.setMinimumSize(new Dimension(Short.MAX_VALUE, INPUT_PANE_HEIGHT));
      inputPane.setBackground(Tools.getDefaultColor("ConfigDialog.Background"));
      inputPane.setAlignmentX(Component.LEFT_ALIGNMENT);
      pane.add(inputPane);
    }
    pane.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Light"));
    return pane;
  }
Ejemplo n.º 2
0
 /** Returns panel with checkbox. */
 protected final JPanel getComponentPanel(final String text, final JComponent component) {
   final JPanel mp = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
   mp.setBackground(Tools.getDefaultColor("ConfigDialog.Background"));
   mp.add(new JLabel(text));
   mp.add(new JLabel(" "));
   mp.add(component);
   mp.setAlignmentX(Component.LEFT_ALIGNMENT);
   return mp;
 }
Ejemplo n.º 3
0
 /** Returns array of volume group checkboxes. */
 private Map<String, JCheckBox> getPVCheckBoxes(final Set<String> selectedPVs) {
   final Map<String, JCheckBox> components = new LinkedHashMap<String, JCheckBox>();
   for (final BlockDevice pv : host.getPhysicalVolumes()) {
     final String pvName = pv.getName();
     final JCheckBox button = new JCheckBox(pvName, selectedPVs.contains(pvName));
     button.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Light"));
     components.put(pvName, button);
   }
   return components;
 }
Ejemplo n.º 4
0
 /** Returns answer pane in a scroll pane. */
 protected final JScrollPane getAnswerPane(final String initialText) {
   answerPane = new JEditorPane(Tools.MIME_TYPE_TEXT_PLAIN, initialText);
   answerPane.setBackground(Tools.getDefaultColor("ConfigDialog.AnswerPane"));
   answerPane.setForeground(java.awt.Color.WHITE);
   // answerPane.setBackground(
   //                    Tools.getDefaultColor("ConfigDialog.AnswerPane"));
   // descSP.setBorder(null);
   answerPane.setEditable(false);
   final JScrollPane scrollPane = new JScrollPane(answerPane);
   scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   scrollPane.setMaximumSize(new Dimension(Short.MAX_VALUE, 80));
   scrollPane.setPreferredSize(new Dimension(Short.MAX_VALUE, 80));
   return scrollPane;
 }
Ejemplo n.º 5
0
  /**
   * Shows dialog and wait for answer. Returns next dialog, or null if it there is no next dialog.
   */
  public final ConfigDialog showDialog() {
    /* making non modal dialog */
    dialogGate = new CountDownLatch(1);
    dialogPanel = null; /* TODO: disabled caching because back button
                               wouldn't work with
                               dialogPanel.setContentPane(optionPane) method
                               it would work with optionPane.createDialog...
                               but that causes lockups with old javas and
                               gnome. */
    if (dialogPanel == null) {
      final ImageIcon[] icons = getIcons();
      MyButton defaultButtonClass = null;
      final List<JComponent> allOptions = new ArrayList<JComponent>(additionalOptions);
      if (skipButtonEnabled()) {
        skipButton = new JCheckBox(Tools.getString("Dialog.ConfigDialog.SkipButton"));
        skipButton.setEnabled(false);
        skipButton.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Light"));
        skipButton.addItemListener(skipButtonListener());
        allOptions.add(skipButton);
      }
      final String[] buttons = buttons();
      /* populate buttonToObjectMap */
      for (int i = 0; i < buttons.length; i++) {
        options[i] = new MyButton(buttons[i], icons[i]);
        options[i].setBackgroundColor(Tools.getDefaultColor("ConfigDialog.Button"));
        allOptions.add(options[i]);
        buttonToObjectMap.put(buttons[i], options[i]);
        if (buttons[i].equals(defaultButton())) {
          defaultButtonClass = options[i];
        }
      }
      /* create option pane */
      final JPanel b = body();
      final MyButton dbc = defaultButtonClass;
      Tools.invokeAndWait(
          new Runnable() {
            public void run() {
              optionPane =
                  new JOptionPane(
                      b,
                      getMessageType(),
                      JOptionPane.DEFAULT_OPTION,
                      icon(),
                      allOptions.toArray(new JComponent[allOptions.size()]),
                      dbc);
              optionPane.setPreferredSize(new Dimension(dialogWidth(), dialogHeight()));
              optionPane.setMaximumSize(new Dimension(dialogWidth(), dialogHeight()));
              optionPane.setMinimumSize(new Dimension(dialogWidth(), dialogHeight()));

              optionPane.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Dark"));
              final Container mainFrame = Tools.getGUIData().getMainFrame();
              if (mainFrame instanceof JApplet) {
                final JFrame noframe = new JFrame();
                dialogPanel = new JDialog(noframe);
                dialogPanel.setContentPane(optionPane);
              } else {
                dialogPanel = new JDialog((JFrame) mainFrame);
                dialogPanel.setContentPane(optionPane);
              }
              dialogPanel.setModal(false);
              dialogPanel.setResizable(true);
            }
          });
      /* set location like the previous dialog */
    }
    /* add action listeners */
    final Map<MyButton, OptionPaneActionListener> optionPaneActionListeners =
        new HashMap<MyButton, OptionPaneActionListener>();
    for (final MyButton o : options) {
      final OptionPaneActionListener ol = new OptionPaneActionListener();
      optionPaneActionListeners.put(o, ol);
      o.addActionListener(ol);
    }

    final PropertyChangeListener propertyChangeListener =
        new PropertyChangeListener() {
          @Override
          public void propertyChange(final PropertyChangeEvent evt) {
            if (JOptionPane.VALUE_PROPERTY.equals(evt.getPropertyName())
                && !"uninitializedValue".equals(evt.getNewValue())) {
              optionPaneAnswer = optionPane.getValue();
              dialogGate.countDown();
            }
          }
        };
    optionPane.addPropertyChangeListener(propertyChangeListener);
    initDialog();
    Tools.invokeAndWait(
        new Runnable() {
          public void run() {
            dialogPanel.setPreferredSize(new Dimension(dialogWidth(), dialogHeight()));
            dialogPanel.setMaximumSize(new Dimension(dialogWidth(), dialogHeight()));
            dialogPanel.setMinimumSize(new Dimension(dialogWidth(), dialogHeight()));
            dialogPanel.setLocationRelativeTo(Tools.getGUIData().getMainFrame());
            dialogPanel.setVisible(true);
          }
        });
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            dialogPanel.setLocationRelativeTo(Tools.getGUIData().getMainFrameContentPane());
            /* although the location was set before, it is set again as a
             * workaround for gray dialogs with nothing in it, that appear
             * in some comination of Java and compiz. */
          }
        });
    initDialogAfterVisible();
    try {
      dialogGate.await();
    } catch (InterruptedException ignored) {
      Thread.currentThread().interrupt();
    }

    if (optionPaneAnswer instanceof String) {
      setPressedButton((String) optionPaneAnswer);
    } else {
      setPressedButton(cancelButton());
    }
    optionPane.removePropertyChangeListener(propertyChangeListener);
    /* remove action listeners */
    for (final MyButton o : options) {
      o.removeActionListener(optionPaneActionListeners.get(o));
    }
    dialogPanel.dispose();
    return checkAnswer();
  }
Ejemplo n.º 6
0
 /**
  * Creates progress bar that can be used during connecting to the host and returns pane, where the
  * progress bar is displayed.
  */
 public final JPanel getProgressBarPane(final String title, final CancelCallback cancelCallback) {
   progressBar = new ProgressBar(title, cancelCallback);
   final JPanel p = progressBar.getProgressBarPane();
   p.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Dark"));
   return p;
 }
Ejemplo n.º 7
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());
  }
Ejemplo n.º 8
0
/**
 * An implementation of an empty tab panel with new cluster and host button.
 *
 * @author Rasto Levrinc
 * @version $Id$
 */
final class EmptyViewPanel extends ViewPanel implements AllHostsUpdatable {
  /** Serial version UID. */
  private static final long serialVersionUID = 1L;
  /** Browser. */
  private final EmptyBrowser browser;
  /** Background color of the status panel. */
  private static final Color STATUS_BACKGROUND =
      Tools.getDefaultColor("ViewPanel.Status.Background");
  /** Add cluster icon. */
  private static final ImageIcon CLUSTER_ICON =
      Tools.createImageIcon(Tools.getDefault("ClusterTab.ClusterIcon"));
  /** Add host icon. */
  private static final ImageIcon HOST_ICON =
      Tools.createImageIcon(Tools.getDefault("HostTab.HostIcon"));
  /** Dimension of the big buttons. */
  private static final Dimension BIG_BUTTON_DIMENSION = new Dimension(300, 100);
  /** Logo panel for card layout. */
  private static final String LOGO_PANEL_STRING = "LOGO-STRING";
  /** Prepares a new <code>ClusterViewPanel</code> object. */
  EmptyViewPanel() {
    super();
    browser = new EmptyBrowser();
    Tools.getGUIData().setEmptyBrowser(browser);
    browser.setEmptyViewPanel(this);
    browser.initHosts();

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.setMinimumSize(new Dimension(0, 110));
    buttonPanel.setPreferredSize(new Dimension(0, 110));
    buttonPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 110));
    buttonPanel.setBackground(STATUS_BACKGROUND);
    add(buttonPanel, BorderLayout.NORTH);
    final JPanel logoPanel = new JPanel(new CardLayout());
    logoPanel.setBackground(java.awt.Color.WHITE);
    final ImageIcon logoImage = Tools.createImageIcon("startpage_head.jpg");

    final JLabel logo = new JLabel(logoImage);
    final JPanel lPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    lPanel.setBackground(java.awt.Color.WHITE);
    lPanel.add(logo);
    logoPanel.add(lPanel, LOGO_PANEL_STRING);
    final JPanel smallButtonPanel = new JPanel();
    smallButtonPanel.setBackground(STATUS_BACKGROUND);
    smallButtonPanel.setLayout(new BoxLayout(smallButtonPanel, BoxLayout.Y_AXIS));
    buttonPanel.add(smallButtonPanel);
    /* check for upgrade field. */
    smallButtonPanel.add(Tools.getGUIData().getClustersPanel().registerUpgradeTextField());
    /* add new host button */
    final MyButton addHostButton =
        new MyButton(Tools.getString("ClusterTab.AddNewHost"), HOST_ICON);
    addHostButton.setBackgroundColor(Browser.STATUS_BACKGROUND);
    addHostButton.setPreferredSize(BIG_BUTTON_DIMENSION);
    addHostButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final Thread thread =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        final AddHostDialog ahd = new AddHostDialog();
                        ahd.showDialogs();
                      }
                    });
            thread.start();
          }
        });
    Tools.getGUIData().registerAddHostButton(addHostButton);
    buttonPanel.add(addHostButton);
    createEmptyView();
    add(logoPanel, BorderLayout.SOUTH);
    Tools.getGUIData().registerAllHostsUpdate(this);
    Tools.getGUIData().allHostsUpdate();

    /* add new cluster button */
    final MyButton addClusterButton =
        new MyButton(Tools.getString("ClusterTab.AddNewCluster"), CLUSTER_ICON);
    addClusterButton.setBackgroundColor(Browser.STATUS_BACKGROUND);
    addClusterButton.setPreferredSize(BIG_BUTTON_DIMENSION);
    addClusterButton.setMinimumSize(BIG_BUTTON_DIMENSION);
    addClusterButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final Thread thread =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        AddClusterDialog acd = new AddClusterDialog();
                        acd.showDialogs();
                      }
                    });
            thread.start();
          }
        });
    Tools.getGUIData().registerAddClusterButton(addClusterButton);
    Tools.getGUIData().checkAddClusterButtons();
    buttonPanel.add(addClusterButton);
    if (!Tools.getConfigData().getAutoHosts().isEmpty()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              addHostButton.pressButton();
            }
          });
    }
  }

  /** creates cluster view and updates the tree. */
  private void createEmptyView() {
    getTree(browser);
    browser.updateHosts();
  }

  /** Updates the all hosts menu item. */
  @Override
  public void allHostsUpdate() {
    browser.updateHosts();
  }
}