/**
   * Create a new tab to the FlexiBar, with the specified title and the specified component inside
   * the tab.
   *
   * @param title the title of the tab to be added
   * @param comp the component inserted in the tab
   */
  public void add(String title, JComponent comp) {
    JButton button = new JButton(title);
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            System.out.println("click");
            setSelected((JButton) arg0.getSource());
          }
        });
    button.setMinimumSize(new Dimension(this.B_WIDTH, this.B_HEIGHT));
    button.setMaximumSize(new Dimension(this.B_WIDTH, this.B_HEIGHT));
    button.setPreferredSize(new Dimension(this.B_WIDTH, this.B_HEIGHT));
    button.setAlignmentX(LEFT_ALIGNMENT);
    comp.setMinimumSize(new Dimension(this.P_WIDTH, this.P_HEIGHT));
    comp.setMaximumSize(new Dimension(this.P_WIDTH, this.P_HEIGHT));
    // comp.setPreferredSize(new Dimension(this.P_WIDTH,this.P_HEIGHT));
    comp.setAlignmentX(LEFT_ALIGNMENT);
    if (currentSelected == -1) {
      comp.setVisible(true);
      currentSelected = 0;
    } else comp.setVisible(false);

    listComponent.add(button);
    listComponent.add(comp);

    panel.add(button);
    panel.add(comp);
  }
示例#2
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;
  }
 private JPanel getPanel() {
   if (panel == null) {
     panel = new JPanel();
     panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
     provider = Lookup.getDefault().lookupAll(OptionsProvider.class);
     for (OptionsProvider p : provider) {
       JComponent comp = p.getComponent(this);
       panel.add(comp);
       comp.setAlignmentX(Component.LEFT_ALIGNMENT);
       comp.setAlignmentY(Component.TOP_ALIGNMENT);
     }
     panel.add(Box.createVerticalGlue());
   }
   return panel;
 }
  /** Opens a new window with a drawing view. */
  protected void open(DrawingView newDrawingView) {
    getVersionControlStrategy().assertCompatibleVersion();
    setUndoManager(new UndoManager());
    fIconkit = new Iconkit(this);
    getContentPane().setLayout(new BorderLayout());

    // status line must be created before a tool is set
    fStatusLine = createStatusLine();
    getContentPane().add(fStatusLine, BorderLayout.SOUTH);

    // create dummy tool until the default tool is activated during toolDone()
    setTool(new NullTool(this), "");
    setView(newDrawingView);
    JComponent contents = createContents(view());
    contents.setAlignmentX(LEFT_ALIGNMENT);

    JToolBar tools = createToolPalette();
    createTools(tools);

    JPanel activePanel = new JPanel();
    activePanel.setAlignmentX(LEFT_ALIGNMENT);
    activePanel.setAlignmentY(TOP_ALIGNMENT);
    activePanel.setLayout(new BorderLayout());
    activePanel.add(tools, BorderLayout.NORTH);
    activePanel.add(contents, BorderLayout.CENTER);

    getContentPane().add(activePanel, BorderLayout.CENTER);

    JMenuBar mb = new JMenuBar();
    createMenus(mb);
    setJMenuBar(mb);

    Dimension d = defaultSize();
    if (d.width > mb.getPreferredSize().width) {
      setSize(d.width, d.height);
    } else {
      setSize(mb.getPreferredSize().width, d.height);
    }
    addListeners();
    setVisible(true);
    fStorageFormatManager = createStorageFormatManager();

    toolDone();
  }
示例#5
0
 public FloatControlPanel(final FloatControl control, int axis) {
   super(control);
   setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
   this.control = control;
   boolean rotary = control.isRotary(); // || axis == BoxLayout.X_AXIS; // !!! simple heuristic
   if (rotary) {
     pot = new ControlKnob(control);
     addMenu(); // doesn't work with JSlider
   } else {
     pot = new ControlSlider(control);
   }
   String name = abbreviate(control.getAnnotation());
   JLabel label = new JLabel(name);
   label.setLabelFor(pot);
   label.setFont(font);
   label.setAlignmentX(0.5f);
   add(label);
   pot.setAlignmentX(0.5f);
   add(pot);
 }
示例#6
0
  public SwingUpdaterUI(String oldBuildDesc, String newBuildDesc, InstallOperation operation) {
    myOperation = operation;

    myProcessTitle = new JLabel(" ");
    myProcessProgress = new JProgressBar(0, 100);
    myProcessStatus = new JLabel(" ");

    myCancelButton = new JButton(CANCEL_BUTTON_TITLE);

    myConsole = new JTextArea();
    myConsole.setLineWrap(true);
    myConsole.setWrapStyleWord(true);
    myConsole.setCaretPosition(myConsole.getText().length());
    myConsole.setTabSize(1);
    myConsolePane = new JPanel(new BorderLayout());
    myConsolePane.add(new JScrollPane(myConsole));
    myConsolePane.setBorder(BUTTONS_BORDER);
    myConsolePane.setVisible(false);

    myCancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            doCancel();
          }
        });

    myFrame = new JFrame();
    myFrame.setTitle(TITLE);

    myFrame.setLayout(new BorderLayout());
    myFrame.getRootPane().setBorder(FRAME_BORDER);
    myFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    myFrame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            doCancel();
          }
        });

    JPanel processPanel = new JPanel();
    processPanel.setLayout(new BoxLayout(processPanel, BoxLayout.Y_AXIS));
    processPanel.add(myProcessTitle);
    processPanel.add(myProcessProgress);
    processPanel.add(myProcessStatus);

    processPanel.add(myConsolePane);
    for (Component each : processPanel.getComponents()) {
      ((JComponent) each).setAlignmentX(Component.LEFT_ALIGNMENT);
    }

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setBorder(BUTTONS_BORDER);
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
    buttonsPanel.add(Box.createHorizontalGlue());
    buttonsPanel.add(myCancelButton);

    myProcessTitle.setText("<html>Updating " + oldBuildDesc + " to " + newBuildDesc + "...");

    myFrame.add(processPanel, BorderLayout.CENTER);
    myFrame.add(buttonsPanel, BorderLayout.SOUTH);

    myFrame.setMinimumSize(new Dimension(500, 50));
    myFrame.pack();
    myFrame.setLocationRelativeTo(null);

    myFrame.setVisible(true);

    myQueue.add(
        new UpdateRequest() {
          @Override
          public void perform() {
            doPerform();
          }
        });

    startRequestDispatching();
  }
 private void setComponentSize(JComponent component, int w, int h) {
   component.setMinimumSize(new Dimension(w, h));
   component.setMaximumSize(new Dimension(w, h));
   component.setPreferredSize(new Dimension(w, h));
   component.setAlignmentX(Component.LEFT_ALIGNMENT);
 }
示例#8
0
文件: SeekAction.java 项目: hof/jin
    /** Creates the ui of this panel, laying out all the ui elements. */
    private void createUI() {
      I18n i18n = getI18n();

      final int labelPad = 4; // To align labels with checkboxes

      // Time controls
      JLabel timeLabel = i18n.createLabel("timeLabel");
      timeLabel.setLabelFor(timeField);

      JLabel incLabel = i18n.createLabel("incrementLabel");
      incLabel.setLabelFor(incField);

      JLabel secondsLabel = i18n.createLabel("secondsLabel");
      JLabel minutesLabel = i18n.createLabel("minutesLabel");

      timeField.setMaximumSize(timeField.getPreferredSize());
      incField.setMaximumSize(incField.getPreferredSize());

      JComponent timeContainer = new JPanel(new TableLayout(5, labelPad, 2));
      timeContainer.add(Box.createHorizontalStrut(0));
      timeContainer.add(timeLabel);
      timeContainer.add(Box.createHorizontalStrut(10));
      timeContainer.add(timeField);
      timeContainer.add(minutesLabel);
      timeContainer.add(Box.createHorizontalStrut(0));
      timeContainer.add(incLabel);
      timeContainer.add(Box.createHorizontalStrut(10));
      timeContainer.add(incField);
      timeContainer.add(secondsLabel);

      // Variant
      JLabel variantLabel = i18n.createLabel("variantLabel");
      variantLabel.setLabelFor(variantChoice);
      variantChoice.setMaximumSize(variantChoice.getPreferredSize());

      JComponent variantContainer = SwingUtils.createHorizontalBox();
      variantContainer.add(Box.createHorizontalStrut(labelPad));
      variantContainer.add(variantLabel);
      variantContainer.add(Box.createHorizontalStrut(10));
      variantContainer.add(variantChoice);
      variantContainer.add(Box.createHorizontalGlue());

      // Color
      JLabel colorLabel = i18n.createLabel("colorLabel");

      JComponent colorContainer = SwingUtils.createHorizontalBox();
      colorContainer.add(Box.createHorizontalStrut(labelPad));
      colorContainer.add(colorLabel);
      colorContainer.add(Box.createHorizontalStrut(15));
      colorContainer.add(autoColor);
      colorContainer.add(Box.createHorizontalStrut(10));
      colorContainer.add(whiteColor);
      colorContainer.add(Box.createHorizontalStrut(10));
      colorContainer.add(blackColor);
      colorContainer.add(Box.createHorizontalGlue());

      // Limit opponent rating
      JLabel minLabel = i18n.createLabel("minRatingLabel");
      minLabel.setLabelFor(minRatingField);
      JLabel maxLabel = i18n.createLabel("maxRatingLabel");
      maxLabel.setLabelFor(maxRatingField);
      minRatingField.setMaximumSize(minRatingField.getPreferredSize());
      maxRatingField.setMaximumSize(minRatingField.getPreferredSize());

      JComponent limitRatingBoxContainer = SwingUtils.createHorizontalBox();
      limitRatingBoxContainer.add(limitRatingBox);
      limitRatingBoxContainer.add(Box.createHorizontalGlue());

      final JComponent minMaxContainer = SwingUtils.createHorizontalBox();
      minMaxContainer.add(Box.createHorizontalStrut(40));
      minMaxContainer.add(minLabel);
      minMaxContainer.add(Box.createHorizontalStrut(10));
      minMaxContainer.add(minRatingField);
      minMaxContainer.add(Box.createHorizontalStrut(20));
      minMaxContainer.add(maxLabel);
      minMaxContainer.add(Box.createHorizontalStrut(10));
      minMaxContainer.add(maxRatingField);
      minMaxContainer.add(Box.createHorizontalGlue());

      JComponent limitRatingContainer = SwingUtils.createVerticalBox();
      limitRatingContainer.add(limitRatingBoxContainer);
      limitRatingContainer.add(Box.createVerticalStrut(3));
      limitRatingContainer.add(minMaxContainer);

      // Buttons panel
      JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
      JButton issueSeekButton = i18n.createButton("issueSeekButton");
      JButton cancelButton = i18n.createButton("cancelButton");

      setDefaultButton(issueSeekButton);
      cancelButton.setDefaultCapable(false);

      buttonsPanel.add(issueSeekButton);
      buttonsPanel.add(cancelButton);

      JButton moreLessButton = i18n.createButton("moreOptionsButton");
      moreLessButton.setDefaultCapable(false);
      moreLessButton.setActionCommand("more");
      JPanel moreLessPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
      moreLessPanel.add(moreLessButton);

      final JComponent advancedPanelHolder = new JPanel(new BorderLayout());

      // Layout the subcontainers in the main container
      setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
      timeContainer.setAlignmentX(LEFT_ALIGNMENT);
      add(timeContainer);
      add(Box.createVerticalStrut(2));
      isRatedBox.setAlignmentX(LEFT_ALIGNMENT);
      add(isRatedBox);
      advancedPanelHolder.setAlignmentX(LEFT_ALIGNMENT);
      add(advancedPanelHolder);
      add(Box.createVerticalStrut(5));
      moreLessPanel.setAlignmentX(LEFT_ALIGNMENT);
      add(moreLessPanel);

      add(Box.createVerticalStrut(10));
      buttonsPanel.setAlignmentX(LEFT_ALIGNMENT);
      add(buttonsPanel);

      // Advanced options panel
      final JComponent advancedPanel = SwingUtils.createVerticalBox();
      advancedPanel.add(Box.createVerticalStrut(4));
      variantContainer.setAlignmentX(LEFT_ALIGNMENT);
      advancedPanel.add(variantContainer);
      advancedPanel.add(Box.createVerticalStrut(4));
      colorContainer.setAlignmentX(LEFT_ALIGNMENT);
      advancedPanel.add(colorContainer);
      advancedPanel.add(Box.createVerticalStrut(2));
      limitRatingContainer.setAlignmentX(LEFT_ALIGNMENT);
      advancedPanel.add(limitRatingContainer);
      advancedPanel.add(Box.createVerticalStrut(2));
      manualAcceptBox.setAlignmentX(LEFT_ALIGNMENT);
      advancedPanel.add(manualAcceptBox);
      advancedPanel.add(Box.createVerticalStrut(2));
      useFormulaBox.setAlignmentX(LEFT_ALIGNMENT);
      advancedPanel.add(useFormulaBox);

      AWTUtilities.setContainerEnabled(minMaxContainer, limitRatingBox.isSelected());
      limitRatingBox.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent evt) {
              AWTUtilities.setContainerEnabled(minMaxContainer, limitRatingBox.isSelected());
            }
          });

      moreLessButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              if (evt.getActionCommand().equals("more")) {
                JButton moreLessButton = (JButton) evt.getSource();
                moreLessButton.setText(getI18n().getString("lessOptionsButton.text"));
                moreLessButton.setActionCommand("less");
                advancedPanelHolder.add(advancedPanel, BorderLayout.CENTER);
                SeekPanel.this.resizeContainerToFit();
              } else {
                JButton moreLessButton = (JButton) evt.getSource();
                moreLessButton.setText(getI18n().getString("moreOptionsButton.text"));
                moreLessButton.setActionCommand("more");
                advancedPanelHolder.remove(advancedPanel);
                SeekPanel.this.resizeContainerToFit();
              }
            }
          });

      cancelButton.addActionListener(new ClosingListener(null));
      issueSeekButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              int time, inc;

              try {
                time = Integer.parseInt(timeField.getText());
              } catch (NumberFormatException e) {
                getI18n().error("timeError");
                return;
              }

              try {
                inc = Integer.parseInt(incField.getText());
              } catch (NumberFormatException e) {
                getI18n().error("incError");
                return;
              }

              boolean isRated = isRatedBox.isSelected();

              WildVariant variant = (WildVariant) variantChoice.getSelectedItem();

              Player color =
                  autoColor.isSelected()
                      ? null
                      : whiteColor.isSelected() ? Player.WHITE_PLAYER : Player.BLACK_PLAYER;

              int minRating, maxRating;
              if (limitRatingBox.isSelected()) {
                try {
                  minRating = Integer.parseInt(minRatingField.getText());
                } catch (NumberFormatException e) {
                  getI18n().error("minRatingError");
                  return;
                }
                try {
                  maxRating = Integer.parseInt(maxRatingField.getText());
                } catch (NumberFormatException e) {
                  getI18n().error("maxRatingError");
                  return;
                }
              } else {
                minRating = Integer.MIN_VALUE;
                maxRating = Integer.MAX_VALUE;
              }

              boolean manualAccept = manualAcceptBox.isSelected();
              boolean useFormula = useFormulaBox.isSelected();

              close(
                  new UserSeek(
                      time,
                      inc,
                      isRated,
                      variant,
                      color,
                      minRating,
                      maxRating,
                      manualAccept,
                      useFormula));
            }
          });
    }
  /**
   * Creates a new instance of CategoryPropertyRenderer
   *
   * @param property an instance of XmlCategory
   * @param ignoreCategory true if it must only render the sub items of the given category
   */
  public CategoryPropertyRenderer(XmlCategory category, boolean ignoreCategory) {
    super(new GridBagLayout());

    this.category = category;

    this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    this.setAlignmentX(0.0f);
    this.setAlignmentY(0.0f);

    int y = 1;
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.anchor = gbc.LINE_START;

    if (!ignoreCategory) {
      gbc.gridx = 1;
      gbc.gridy = y;
      gbc.gridheight = 1;
      gbc.gridwidth = 1;
      gbc.anchor = gbc.WEST;
      //            gbc.anchor = gbc.FIRST_LINE_START;
      //            gbc.weightx = 1;
      //            gbc.weighty = 0;
      gbc.insets = new Insets(0, 0, 3, 0);

      JLabel title =
          new JLabel(
              "<html><u><font color=\"#FF0000\">" + category.getLabel() + "</font></u></html>");

      if (DEBUG) {
        title.setBackground(Color.PINK);
        title.setOpaque(true);
      }

      title.setHorizontalTextPosition(SwingConstants.RIGHT);
      title.setAlignmentX(0.0f);

      if (category.getIcon() != null) {
        if (category.getIcon().trim().length() > 0) {
          try {
            title.setIcon(ResourceLoader.getInstance().getIconNamed(category.getIcon()));
          } catch (ResourceException e) {
            e.printStackTrace();
          }
        }
      }

      this.add(title, gbc);

      y += 2;
    }

    int separatorStart = y;

    /* add elements recursively */
    if (this.category != null) {
      if (this.category.getItems() != null) {
        Iterator<XmlPropertyContainer> it = this.category.getItems().iterator();

        while (it.hasNext()) {
          Object current = it.next();

          boolean added = false;

          if (current instanceof XmlProperty) {
            XmlProperty property = (XmlProperty) current;

            PropertyEditor editor = EditorPropertiesComponentFactory.editProperty(property);

            if (editor != null) {
              /* create property label */
              JLabel label = EditorPropertiesComponentFactory.createLabel(property);
              editor.setLabel(label);

              JComponent[] components = new JComponent[2];
              components[0] = label;
              components[1] = editor.getComponent();

              for (int i = 0; i < components.length; i++) {
                JComponent component = components[i];
                if (component != null) {
                  if (!added) added = true;

                  gbc = new GridBagConstraints();

                  gbc.gridx = i + 1;
                  gbc.gridy = y;
                  gbc.gridheight = 1;
                  gbc.gridwidth = 1;
                  //                                    gbc.weightx = 1;
                  //                                    gbc.weighty = 0;
                  gbc.anchor = gbc.FIRST_LINE_START;

                  gbc.anchor = gbc.WEST;

                  gbc.insets = new Insets(0, LEFT_BORDER, 0, 0);
                  component.setAlignmentX(0.0f);
                  component.setAlignmentY(0.0f);
                  this.add(component, gbc);
                }
              }
            }
          } else if (current instanceof XmlCategory) {
            gbc = new GridBagConstraints();

            gbc.gridx = 1;
            gbc.gridy = y;
            gbc.gridheight = 1;
            gbc.gridwidth = 10;
            gbc.insets = new Insets(0, LEFT_BORDER, 0, 0);
            gbc.anchor = gbc.WEST;
            //                        gbc.weightx = 1;
            //                        gbc.weighty = 0;
            added = true;
            JPanel panel = EditorPropertiesComponentFactory.renderCategory((XmlCategory) current);
            //                        JPanel panel =
            // EditorPropertiesComponentFactory.renderCategoryItems( (XmlCategory)current );

            panel.setAlignmentX(0.0f);
            panel.setAlignmentY(0.0f);

            if (DEBUG) {
              panel.setBackground(Color.GREEN);

              System.out.println("sub category : " + ((XmlCategory) current).getLabel());

              System.out.println("ajout avec contrainte : ");
              System.out.println("\tgridx : " + gbc.gridx);
              System.out.println("\tgridy : " + gbc.gridy);
              System.out.println("\tanchor : " + gbc.anchor);
              System.out.println("\tfill : " + gbc.fill);
              System.out.println("\tgridheight : " + gbc.gridheight);
              System.out.println("\tgridwidth : " + gbc.gridwidth);
              System.out.println("\tinsets : " + gbc.insets);
              System.out.println("\tipadx : " + gbc.ipadx);
              System.out.println("\tipady : " + gbc.ipady);
              System.out.println("\tweightx : " + gbc.weightx);
              System.out.println("\tweighty : " + gbc.weighty);

              System.out.println("panel properties : ");
              System.out.println("\tpanel align x : " + panel.getAlignmentX());
              System.out.println("\tpanel align y : " + panel.getAlignmentY());
              System.out.println("\tborder : " + panel.getBorder());
              System.out.println("\tinsets : " + panel.getInsets());
            }

            this.add(panel, gbc);
          }

          if (added) {
            y += 2;
            gbc = new GridBagConstraints();
            gbc.gridy = y;
            this.add(new JToolBar.Separator(new Dimension(2, 2)), gbc);

            y += 1;

            if (current instanceof XmlCategory) {
              gbc = new GridBagConstraints();
              gbc.gridy = y;
              this.add(new JToolBar.Separator(new Dimension(2, 2)), gbc);

              y += 1;
            }
          }
        }

        /* add a JSeparator to group elements of this category */
        //                gbc.gridx      = 1;
        //                gbc.gridy      = separatorStart;
        //                gbc.gridwidth  = 1;
        //                gbc.gridheight = y - separatorStart;
        //                gbc.insets     = new Insets(0, 0, 0, 0);
        //
        //                System.out.println("height : " + (y - separatorStart));
        //                this.add(new JSeparator(SwingConstants.VERTICAL), gbc);
      }
    }

    /** add a virtual label with weight at 1 to disable space distribution to previous items */
    gbc = new GridBagConstraints();

    gbc.gridx = 999;
    gbc.gridy = 999;
    gbc.weightx = 1.0f;
    gbc.weighty = 1.0f;
    this.add(new JLabel(""), gbc);
  }
 private void addLeftToPanel(JPanel p, JComponent c) {
   c.setAlignmentX(Component.LEFT_ALIGNMENT);
   p.add(c);
 }
 protected void align(JComponent c) {
   c.setAlignmentX(JComponent.LEFT_ALIGNMENT);
   c.setAlignmentY(JComponent.TOP_ALIGNMENT);
 }