Exemplo n.º 1
0
 public UndoGarageAction(MessageXBar anXBar) {
   putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(SHORTCUT_STROKE));
   anXBar.attach(this);
   setEnabled(false); // Initially
 }
Exemplo n.º 2
0
  public LoadoutFrame(LoadoutBase<?> aLoadout, MessageXBar aXBar) {
    super(
        aLoadout.toString(),
        true, // resizable
        true, // closable
        false, // maximizable
        true); // iconifiable
    xbar = aXBar;
    xbar.attach(this);
    loadout = aLoadout;

    // Actions
    actionUndoLoadout = new UndoLoadoutAction(xbar, this);
    actionRedoLoadout = new RedoLoadoutAction(xbar, this);
    actionRename = new RenameLoadoutAction(this, xbar);
    actionAddToGarage = new AddToGarageAction(loadout);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(createMenuLoadout());
    menuBar.add(createMenuArmor());
    menuBar.add(createMenuGraphs());
    menuBar.add(createMenuShare());
    setJMenuBar(menuBar);

    // Set the window's location.
    setLocation(xOffset * openFrameCount, yOffset * openFrameCount);
    openFrameCount++;
    infoPanel = new LoadoutInfoPanel(this, aXBar);

    JPanel root = new JPanel(new BorderLayout());
    JPanel mechview = createMechView(aLoadout, aXBar);
    root.add(mechview, BorderLayout.WEST);
    if (ProgramInit.lsml().preferences.uiPreferences.getCompactMode()) {
      JScrollPane scrollpane =
          new JScrollPane(
              infoPanel,
              ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
              ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
      Dimension preferredSize = new Dimension();
      preferredSize.height = (int) (mechview.getPreferredSize().getHeight() + 1);
      preferredSize.width =
          (int)
              (infoPanel.getPreferredSize().getWidth()
                  + scrollpane.getVerticalScrollBar().getPreferredSize().getWidth()
                  + 1);
      scrollpane.setPreferredSize(preferredSize);
      root.add(scrollpane, BorderLayout.EAST);
    } else {
      root.add(infoPanel, BorderLayout.EAST);
    }
    root.add(new StatusBar(this, aXBar), BorderLayout.SOUTH);

    setFrameIcon(null);
    setContentPane(root);

    pack();
    setVisible(true);

    addVetoableChangeListener(
        new VetoableChangeListener() {
          @Override
          public void vetoableChange(PropertyChangeEvent aE) throws PropertyVetoException {
            if (aE.getPropertyName().equals("closed") && aE.getNewValue().equals(true)) {
              if (!isSaved()) {
                int ans =
                    JOptionPane.showConfirmDialog(
                        ProgramInit.lsml(),
                        "Would you like to save " + loadout.getName() + " to your garage?",
                        "Save to garage?",
                        JOptionPane.YES_NO_CANCEL_OPTION);
                if (ans == JOptionPane.YES_OPTION) {
                  (new AddToGarageAction(loadout)).actionPerformed(null);
                } else if (ans == JOptionPane.NO_OPTION) {
                  // Discard loadout
                } else {
                  throw new PropertyVetoException("Save canceled!", aE);
                }
              }
            }
          }
        });
    setupKeybindings();
  }