Beispiel #1
0
  private void build() {
    // ============= le panel du dialog
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    // ================================
    catBox = new JComboBox(categories);
    catBox.setMinimumSize(new Dimension(150, 60));
    catBox.setMaximumSize(new Dimension(2000, 80));
    catBox.setBorder(BorderFactory.createTitledBorder("TYPE"));
    catBox.addFocusListener(this);
    panel.add(catBox);

    // ========= Le nom du nouveau media
    nameField.setMinimumSize(new Dimension(150, 60));
    nameField.setMaximumSize(new Dimension(2000, 80));
    nameField.setBorder(BorderFactory.createTitledBorder("NAME"));
    nameField.addFocusListener(this);
    nameField.addFocusListener(
        new FocusListener() {
          public void focusGained(FocusEvent e) {
            nameField.selectAll();
          }

          public void focusLost(FocusEvent e) {}
        });
    panel.add(nameField);

    // ========== La release date par default
    dateChooser.setMinimumSize(new Dimension(150, 60));
    dateChooser.setMaximumSize(new Dimension(2000, 80));
    dateChooser.setFormats(UiConfig.getProperty(UiConfig.LONG_DATE_FORMAT));
    dateChooser.setDate(new Date());
    dateChooser.setBorder(BorderFactory.createTitledBorder("RELEASE DATE"));
    panel.add(dateChooser);

    // ============
    formatField.setMinimumSize(new Dimension(150, 60));
    formatField.setMaximumSize(new Dimension(2000, 80));
    formatField.setBorder(BorderFactory.createTitledBorder("FORMAT(experimental)"));
    formatField.addFocusListener(this);
    formatField.addFocusListener(
        new FocusListener() {
          public void focusGained(FocusEvent e) {
            formatField.selectAll();
          }

          public void focusLost(FocusEvent e) {}
        });
    panel.add(formatField);

    // ============ Le bouton ok
    okButton.setActionCommand("CREATE");
    okButton.setToolTipText("Create " + catBox.getSelectedItem() + " " + nameField.getText());
    okButton.addActionListener(this);
    Icon icon1 = ThemeIcon.SAVE.d32x32();
    if (icon1 != null) {
      okButton.setText("");
      okButton.setIcon(icon1);
    }

    // =========== Le bouton cancel
    cancelButton.setActionCommand("CANCEL");
    cancelButton.addActionListener(this);
    cancelButton.setToolTipText("Cancel");
    Icon icon2 = ThemeIcon.CANCEL.d32x32();
    if (icon2 != null) {
      cancelButton.setText("");
      cancelButton.setIcon(icon2);
    }

    // =========== La toolBar
    toolBar.add(okButton);
    toolBar.add(cancelButton);
    panel.add(new JLabel());
    panel.add(toolBar);
    toolBar.setAlignmentX(CENTER_ALIGNMENT);
  }
Beispiel #2
0
  /**
   * Fill the given panel by adding all necessary components to the different locations.
   *
   * @param panel The container to fill. Must have an BorderLayout.
   */
  public void fillPanel(Container panel) {
    panel.add(this, BorderLayout.CENTER);

    /** sideToolBar: add map modes icons */
    if (Main.pref.getBoolean("sidetoolbar.mapmodes.visible", true)) {
      toolBarActions.setAlignmentX(0.5f);
      toolBarActions.setInheritsPopupMenu(true);
      sideToolBar.add(toolBarActions);
      listAllMapModesButton.setAlignmentX(0.5f);
      listAllMapModesButton.setBorder(null);
      listAllMapModesButton.setFont(listAllMapModesButton.getFont().deriveFont(Font.PLAIN));
      listAllMapModesButton.setInheritsPopupMenu(true);
      sideToolBar.add(listAllMapModesButton);
    }

    /** sideToolBar: add toggle dialogs icons */
    if (Main.pref.getBoolean("sidetoolbar.toggledialogs.visible", true)) {
      ((JToolBar) sideToolBar).addSeparator(new Dimension(0, 18));
      toolBarToggle.setAlignmentX(0.5f);
      toolBarToggle.setInheritsPopupMenu(true);
      sideToolBar.add(toolBarToggle);
      listAllToggleDialogsButton.setAlignmentX(0.5f);
      listAllToggleDialogsButton.setBorder(null);
      listAllToggleDialogsButton.setFont(
          listAllToggleDialogsButton.getFont().deriveFont(Font.PLAIN));
      listAllToggleDialogsButton.setInheritsPopupMenu(true);
      sideToolBar.add(listAllToggleDialogsButton);
    }

    /** sideToolBar: add dynamic popup menu */
    sideToolBar.setComponentPopupMenu(
        new JPopupMenu() {
          static final int staticMenuEntryCount = 2;
          JCheckBoxMenuItem doNotHide =
              new JCheckBoxMenuItem(
                  new AbstractAction(tr("Do not hide toolbar")) {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState();
                      Main.pref.put("sidetoolbar.always-visible", sel);
                    }
                  });

          {
            addPopupMenuListener(
                new PopupMenuListener() {
                  @Override
                  public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    final Object src = ((JPopupMenu) e.getSource()).getInvoker();
                    if (src instanceof IconToggleButton) {
                      insert(new Separator(), 0);
                      insert(
                          new AbstractAction() {
                            {
                              putValue(NAME, tr("Hide this button"));
                              putValue(
                                  SHORT_DESCRIPTION,
                                  tr("Click the arrow at the bottom to show it again."));
                            }

                            @Override
                            public void actionPerformed(ActionEvent e) {
                              ((IconToggleButton) src).setButtonHidden(true);
                              validateToolBarsVisibility();
                            }
                          },
                          0);
                    }
                    doNotHide.setSelected(Main.pref.getBoolean("sidetoolbar.always-visible", true));
                  }

                  @Override
                  public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                    while (getComponentCount() > staticMenuEntryCount) {
                      remove(0);
                    }
                  }

                  @Override
                  public void popupMenuCanceled(PopupMenuEvent e) {}
                });

            add(
                new AbstractAction(tr("Hide edit toolbar")) {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    Main.pref.put("sidetoolbar.visible", false);
                  }
                });
            add(doNotHide);
          }
        });
    ((JToolBar) sideToolBar).setFloatable(false);

    /** sideToolBar: decide scroll- and visibility */
    if (Main.pref.getBoolean("sidetoolbar.scrollable", true)) {
      final ScrollViewport svp = new ScrollViewport(sideToolBar, ScrollViewport.VERTICAL_DIRECTION);
      svp.addMouseWheelListener(
          new MouseWheelListener() {
            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
              svp.scroll(0, e.getUnitsToScroll() * 5);
            }
          });
      sideToolBar = svp;
    }
    sideToolBar.setVisible(Main.pref.getBoolean("sidetoolbar.visible", true));
    sidetoolbarPreferencesChangedListener =
        new Preferences.PreferenceChangedListener() {
          @Override
          public void preferenceChanged(PreferenceChangeEvent e) {
            if ("sidetoolbar.visible".equals(e.getKey())) {
              sideToolBar.setVisible(Main.pref.getBoolean("sidetoolbar.visible"));
            }
          }
        };
    Main.pref.addPreferenceChangeListener(sidetoolbarPreferencesChangedListener);

    /** sideToolBar: add it to the panel */
    panel.add(sideToolBar, BorderLayout.WEST);

    /** statusLine: add to panel */
    if (statusLine != null && Main.pref.getBoolean("statusline.visible", true)) {
      panel.add(statusLine, BorderLayout.SOUTH);
    }
  }
  // Must be delegated through ActionFrame(Action)
  private ActionFrame(Action a, LibAction la) {
    super(la.description, false);
    if (la.parent == null) setTitle(Messages.getString("Action.UNKNOWN")); // $NON-NLS-1$
    if (la.actImage != null)
      setFrameIcon(new ImageIcon(la.actImage.getScaledInstance(16, 16, Image.SCALE_SMOOTH)));
    String s;
    ResourceReference<GmObject> at = a.getAppliesTo();
    if (at == GmObject.OBJECT_SELF) s = Messages.getString("ActionFrame.SELF"); // $NON-NLS-1$
    else s = Messages.getString("ActionFrame.OTHER"); // $NON-NLS-1$
    appliesObject = new ResourceMenu<GmObject>(Resource.Kind.OBJECT, s, false, 100);
    appliesObject.setEnabled(GmObject.refAsInt(at) >= 0);
    appliesObject.setOpaque(false);
    appliesObject.setSelected(at);
    act = a;

    appliesPanel = new JPanel();
    appliesPanel.setOpaque(false);
    appliesPanel.setLayout(new GridBagLayout());

    GridBagConstraints gbc;
    applies = new IndexButtonGroup(3, true, false);
    JRadioButton button = new JRadioButton(Messages.getString("ActionFrame.SELF")); // $NON-NLS-1$
    button.setOpaque(false);
    applies.add(button, -1);
    gbc = new GridBagConstraints();
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    appliesPanel.add(button, gbc);
    button = new JRadioButton(Messages.getString("ActionFrame.OTHER")); // $NON-NLS-1$
    button.setOpaque(false);
    applies.add(button, -2);
    gbc = new GridBagConstraints();
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    appliesPanel.add(button, gbc);
    button = new JRadioButton(Messages.getString("ActionFrame.OBJECT")); // $NON-NLS-1$
    button.setHorizontalAlignment(JRadioButton.LEFT);
    button.setOpaque(false);
    button.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            boolean sel = ((JRadioButton) e.getSource()).isSelected();
            appliesObject.setEnabled(sel);
          }
        });
    applies.add(button, 0);
    gbc = new GridBagConstraints();
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    appliesPanel.add(button, gbc);
    gbc = new GridBagConstraints();
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.insets = new Insets(0, 2, 0, 6);
    appliesPanel.add(appliesObject, gbc);
    applies.setValue(Math.min(GmObject.refAsInt(at), 0));

    if (la.interfaceKind == LibAction.INTERFACE_CODE) {
      setSize(600, 400);
      setClosable(true);
      setMaximizable(true);
      setResizable(true);
      setIconifiable(true);

      tool = new JToolBar();
      tool.setFloatable(false);
      tool.setAlignmentX(0);
      save = new JButton(LGM.getIconForKey("ActionFrame.SAVE")); // $NON-NLS-1$
      save.addActionListener(this);
      //			add(save);
      tool.add(save);
      tool.addSeparator();

      code = new GMLTextArea(a.getArguments().get(0).getVal());
      code.addEditorButtons(tool);

      tool.addSeparator();
      tool.add(new JLabel(Messages.getString("ActionFrame.APPLIES"))); // $NON-NLS-1$
      tool.add(appliesPanel);

      status = new JPanel(new FlowLayout());
      status.setLayout(new BoxLayout(status, BoxLayout.X_AXIS));
      status.setMaximumSize(new Dimension(Integer.MAX_VALUE, 11));
      final JLabel caretPos =
          new JLabel((code.getCaretLine() + 1) + ":" + (code.getCaretColumn() + 1));
      status.add(caretPos);
      code.addCaretListener(
          new CaretListener() {
            public void caretUpdate(CaretEvent e) {
              caretPos.setText((code.getCaretLine() + 1) + ":" + (code.getCaretColumn() + 1));
            }
          });

      add(tool, BorderLayout.NORTH);
      add(code, BorderLayout.CENTER);
      add(status, BorderLayout.SOUTH);

      setFocusTraversalPolicy(new TextAreaFocusTraversalPolicy(code));
      appliesPanel.setLayout(new BoxLayout(appliesPanel, BoxLayout.LINE_AXIS));
    } else makeArgumentPane(a, la);
    pack();
    repaint();
    SubframeInformer.fireSubframeAppear(this);
  }
Beispiel #4
0
  /**
   * Fill the given panel by adding all necessary components to the different locations.
   *
   * @param panel The container to fill. Must have an BorderLayout.
   */
  public void fillPanel(Container panel) {
    panel.add(this, BorderLayout.CENTER);
    JToolBar jb = new JToolBar(JToolBar.VERTICAL);
    jb.setFloatable(false);
    toolBarActions.setAlignmentX(0.5f);
    jb.add(toolBarActions);
    listAllMapModesButton.setAlignmentX(0.5f);
    listAllMapModesButton.setBorder(null);
    listAllMapModesButton.setFont(listAllMapModesButton.getFont().deriveFont(Font.PLAIN));
    jb.add(listAllMapModesButton);

    if (Main.pref.getBoolean("sidetoolbar.togglevisible", true)) {
      jb.addSeparator(new Dimension(0, 18));
      toolBarToggle.setAlignmentX(0.5f);
      jb.add(toolBarToggle);
      listAllToggleDialogsButton.setAlignmentX(0.5f);
      listAllToggleDialogsButton.setBorder(null);
      listAllToggleDialogsButton.setFont(
          listAllToggleDialogsButton.getFont().deriveFont(Font.PLAIN));
      jb.add(listAllToggleDialogsButton);
    }

    final Component toToggle;
    if (Main.pref.getBoolean("sidetoolbar.scrollable", true)) {
      final ScrollViewport svp = new ScrollViewport(jb, ScrollViewport.VERTICAL_DIRECTION);
      toToggle = svp;
      panel.add(svp, BorderLayout.WEST);
      jb.addMouseWheelListener(
          new MouseWheelListener() {

            public void mouseWheelMoved(MouseWheelEvent e) {
              svp.scroll(0, e.getUnitsToScroll() * 5);
            }
          });
    } else {
      toToggle = jb;
      panel.add(jb, BorderLayout.WEST);
    }
    toToggle.setVisible(Main.pref.getBoolean("sidetoolbar.visible", true));

    jb.addMouseListener(
        new PopupMenuLauncher(
            new JPopupMenu() {

              {
                add(
                    new AbstractAction(tr("Hide edit toolbar")) {

                      @Override
                      public void actionPerformed(ActionEvent e) {
                        Main.pref.put("sidetoolbar.visible", false);
                      }
                    });
              }
            }));

    Main.pref.addPreferenceChangeListener(
        new Preferences.PreferenceChangedListener() {

          @Override
          public void preferenceChanged(PreferenceChangeEvent e) {
            if ("sidetoolbar.visible".equals(e.getKey())) {
              toToggle.setVisible(Main.pref.getBoolean("sidetoolbar.visible"));
            }
          }
        });

    if (statusLine != null && Main.pref.getBoolean("statusline.visible", true)) {
      panel.add(statusLine, BorderLayout.SOUTH);
    }
  }