Exemplo n.º 1
0
 @Override
 public void actionPerformed(final ActionEvent e) {
   if (StockpileItemAction.OK.name().equals(e.getActionCommand())) {
     save();
   }
   if (StockpileItemAction.CANCEL.name().equals(e.getActionCommand())) {
     setVisible(false);
   }
   if (StockpileItemAction.COPY.name().equals(e.getActionCommand())) {
     autoSet();
     autoValidate();
   }
 }
Exemplo n.º 2
0
  public StockpileItemDialog(final Program program) {
    super(program, TabsStockpile.get().addStockpileItem(), Images.TOOL_STOCKPILE.getImage());

    ListenerClass listener = new ListenerClass();

    JLabel jItemsLabel = new JLabel(TabsStockpile.get().item());
    jItems = new JComboBox();
    AutoCompleteSupport<Item> itemAutoComplete =
        AutoCompleteSupport.install(
            jItems, EventModels.createSwingThreadProxyList(items), new ItemFilterator());
    itemAutoComplete.setStrict(true);
    itemAutoComplete.setCorrectsCase(true);
    jItems.addItemListener(listener); // Must be added after AutoCompleteSupport

    JLabel jCountMinimumLabel = new JLabel(TabsStockpile.get().countMinimum());
    jCountMinimum = new JTextField();
    jCountMinimum.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(final FocusEvent e) {
            jCountMinimum.selectAll();
          }
        });
    jCountMinimum.addCaretListener(listener);

    jCopy = new JCheckBox(TabsStockpile.get().copy());
    jCopy.setActionCommand(StockpileItemAction.COPY.name());
    jCopy.addActionListener(listener);

    jOK = new JButton(TabsStockpile.get().ok());
    jOK.setActionCommand(StockpileItemAction.OK.name());
    jOK.addActionListener(listener);
    jOK.setEnabled(false);

    jCancel = new JButton(TabsStockpile.get().cancel());
    jCancel.setActionCommand(StockpileItemAction.CANCEL.name());
    jCancel.addActionListener(listener);

    layout.setHorizontalGroup(
        layout
            .createParallelGroup(GroupLayout.Alignment.TRAILING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addGroup(
                        layout
                            .createParallelGroup()
                            .addComponent(jItemsLabel)
                            .addComponent(jCountMinimumLabel))
                    .addGroup(
                        layout
                            .createParallelGroup()
                            .addComponent(jItems, 300, 300, 300)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(jCountMinimum, 100, 100, Short.MAX_VALUE)
                                    .addComponent(jCopy))))
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addComponent(
                        jOK, Program.BUTTONS_WIDTH, Program.BUTTONS_WIDTH, Program.BUTTONS_WIDTH)
                    .addComponent(
                        jCancel,
                        Program.BUTTONS_WIDTH,
                        Program.BUTTONS_WIDTH,
                        Program.BUTTONS_WIDTH)));
    layout.setVerticalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout
                    .createParallelGroup()
                    .addComponent(
                        jItemsLabel,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT)
                    .addComponent(
                        jItems,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT))
            .addGroup(
                layout
                    .createParallelGroup()
                    .addComponent(
                        jCountMinimumLabel,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT)
                    .addComponent(
                        jCountMinimum,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT)
                    .addComponent(
                        jCopy,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT))
            .addGroup(
                layout
                    .createParallelGroup()
                    .addComponent(
                        jOK, Program.BUTTONS_HEIGHT, Program.BUTTONS_HEIGHT, Program.BUTTONS_HEIGHT)
                    .addComponent(
                        jCancel,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT,
                        Program.BUTTONS_HEIGHT)));
  }