Search in sources :

Example 96 with JTable

use of javax.swing.JTable in project megameklab by MegaMek.

the class CriticalTransferHandler method importData.

@Override
public boolean importData(TransferSupport info) {
    if (!info.isDrop()) {
        return false;
    }
    if (info.getComponent() instanceof DropTargetCriticalList) {
        DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) info.getComponent();
        location = Integer.parseInt(list.getName());
        Transferable t = info.getTransferable();
        try {
            Mounted mount = getUnit().getEquipment(Integer.parseInt((String) t.getTransferData(DataFlavor.stringFlavor)));
            if (!UnitUtil.isValidLocation(getUnit(), mount.getType(), location)) {
                JOptionPane.showMessageDialog(null, mount.getName() + " can't be placed in " + getUnit().getLocationName(location) + "!", "Invalid Location", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }
            if (!getUnit().addCritical(location, new CriticalSlot(mount))) {
                JOptionPane.showMessageDialog(null, "Location Full", "Location Full", JOptionPane.INFORMATION_MESSAGE);
            } else {
                changeMountStatus(mount, location, false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return true;
    }
    if ((info.getComponent() instanceof JTable) || (info.getComponent() instanceof JScrollPane)) {
        try {
            Transferable t = info.getTransferable();
            Mounted mount = getUnit().getEquipment(Integer.parseInt((String) t.getTransferData(DataFlavor.stringFlavor)));
            if (getUnit() instanceof BattleArmor) {
                mount.setBaMountLoc(BattleArmor.MOUNT_LOC_NONE);
            } else {
                UnitUtil.removeCriticals(getUnit(), mount);
                changeMountStatus(mount, Entity.LOC_NONE, false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return true;
    }
    return false;
}
Also used : JScrollPane(javax.swing.JScrollPane) Mounted(megamek.common.Mounted) CriticalSlot(megamek.common.CriticalSlot) JTable(javax.swing.JTable) Transferable(java.awt.datatransfer.Transferable) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) EntityLoadingException(megamek.common.loaders.EntityLoadingException) IOException(java.io.IOException) BattleArmor(megamek.common.BattleArmor)

Example 97 with JTable

use of javax.swing.JTable in project megameklab by MegaMek.

the class AeroBayTransferHandler method createTransferable.

@Override
protected Transferable createTransferable(JComponent c) {
    if (c instanceof BayWeaponCriticalTree) {
        return new StringSelection(((BayWeaponCriticalTree) c).encodeSelection());
    } else {
        JTable table = (JTable) c;
        StringJoiner sj = new StringJoiner(",");
        for (int row : table.getSelectedRows()) {
            Mounted mount = (Mounted) ((CriticalTableModel) table.getModel()).getValueAt(row, CriticalTableModel.EQUIPMENT);
            sj.add(Integer.toString(eSource.getEntity().getEquipmentNum(mount)));
        }
        return new StringSelection(sj.toString());
    }
}
Also used : Mounted(megamek.common.Mounted) JTable(javax.swing.JTable) StringJoiner(java.util.StringJoiner) StringSelection(java.awt.datatransfer.StringSelection)

Example 98 with JTable

use of javax.swing.JTable in project JWildfire by thargor6.

the class TinaInternalFrame method getLayersTable.

private JTable getLayersTable() {
    if (layersTable == null) {
        layersTable = new JTable();
        layersTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        layersTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    tinaController.layersTableClicked();
                }
            }
        });
    }
    return layersTable;
}
Also used : JTable(javax.swing.JTable) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 99 with JTable

use of javax.swing.JTable in project JWildfire by thargor6.

the class TinaInternalFrame method getCreatePaletteColorsTable.

/**
 * This method initializes createPaletteColorsTable
 *
 * @return javax.swing.JTable
 */
private JTable getCreatePaletteColorsTable() {
    if (createPaletteColorsTable == null) {
        createPaletteColorsTable = new JTable();
        createPaletteColorsTable.setFont(Prefs.getPrefs().getFont("Dialog", Font.PLAIN, 10));
        createPaletteColorsTable.setSize(new Dimension(177, 80));
    }
    return createPaletteColorsTable;
}
Also used : JTable(javax.swing.JTable) Dimension(java.awt.Dimension)

Example 100 with JTable

use of javax.swing.JTable in project JWildfire by thargor6.

the class TinaInternalFrame method getTabbedPane.

private JTabbedPane getTabbedPane() {
    if (tabbedPane == null) {
        tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        tabbedPane.addTab("Description", null, getPanel_60(), null);
        tabbedPane.addTab("Code preview", null, getPanel_61(), null);
        JPanel panel_1 = new JPanel();
        tabbedPane.addTab("Macro buttons", null, panel_1, null);
        panel_1.setLayout(new BorderLayout(0, 0));
        JPanel panel_2 = new JPanel();
        panel_2.setPreferredSize(new Dimension(120, 10));
        panel_1.add(panel_2, BorderLayout.CENTER);
        panel_2.setLayout(new BorderLayout(0, 0));
        JScrollPane scrollPane_2 = new JScrollPane();
        scrollPane_2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scrollPane_2.setBorder(null);
        panel_2.add(scrollPane_2, BorderLayout.CENTER);
        macroButtonsTable = new JTable();
        macroButtonsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        macroButtonsTable.setFont(Prefs.getPrefs().getFont("Dialog", Font.PLAIN, 10));
        macroButtonsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    tinaController.getJwfScriptController().macroButtonsTableClicked();
                }
            }
        });
        scrollPane_2.setViewportView(macroButtonsTable);
        JPanel panel_3 = new JPanel();
        FlowLayout flowLayout = (FlowLayout) panel_3.getLayout();
        flowLayout.setHgap(0);
        flowLayout.setVgap(1);
        panel_3.setPreferredSize(new Dimension(124, 10));
        panel_1.add(panel_3, BorderLayout.EAST);
        JPanel panel_9 = new JPanel();
        panel_9.setPreferredSize(new Dimension(116, 4));
        panel_9.setMinimumSize(new Dimension(116, 8));
        panel_9.setMaximumSize(new Dimension(32767, 8));
        panel_3.add(panel_9);
        macroButtonMoveUpBtn = new JButton();
        macroButtonMoveUpBtn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                tinaController.getJwfScriptController().macroButtonMoveUp();
            }
        });
        macroButtonMoveUpBtn.setToolTipText("Move the button one up in the list");
        macroButtonMoveUpBtn.setText("Up");
        macroButtonMoveUpBtn.setPreferredSize(new Dimension(58, 24));
        macroButtonMoveUpBtn.setMinimumSize(new Dimension(58, 12));
        macroButtonMoveUpBtn.setMaximumSize(new Dimension(58, 12));
        macroButtonMoveUpBtn.setFont(Prefs.getPrefs().getFont("Dialog", Font.BOLD, 10));
        macroButtonMoveUpBtn.setBounds(new Rectangle(9, 280, 125, 24));
        panel_3.add(macroButtonMoveUpBtn);
        macroButtonMoveDownBtn = new JButton();
        macroButtonMoveDownBtn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                tinaController.getJwfScriptController().macroButtonMoveDown();
            }
        });
        macroButtonMoveDownBtn.setToolTipText("Move the button one down in the list");
        macroButtonMoveDownBtn.setText("Down");
        macroButtonMoveDownBtn.setPreferredSize(new Dimension(58, 24));
        macroButtonMoveDownBtn.setMinimumSize(new Dimension(58, 12));
        macroButtonMoveDownBtn.setMaximumSize(new Dimension(58, 12));
        macroButtonMoveDownBtn.setFont(Prefs.getPrefs().getFont("Dialog", Font.BOLD, 10));
        macroButtonMoveDownBtn.setBounds(new Rectangle(9, 280, 125, 24));
        panel_3.add(macroButtonMoveDownBtn);
        JPanel panel_8 = new JPanel();
        panel_8.setPreferredSize(new Dimension(116, 4));
        panel_8.setMinimumSize(new Dimension(116, 8));
        panel_8.setMaximumSize(new Dimension(32767, 8));
        panel_3.add(panel_8);
        macroButtonDeleteBtn = new JButton();
        macroButtonDeleteBtn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                tinaController.getJwfScriptController().macroButtonDelete();
            }
        });
        macroButtonDeleteBtn.setToolTipText("Delete the button");
        macroButtonDeleteBtn.setText("Delete");
        macroButtonDeleteBtn.setPreferredSize(new Dimension(116, 24));
        macroButtonDeleteBtn.setFont(Prefs.getPrefs().getFont("Dialog", Font.BOLD, 10));
        macroButtonDeleteBtn.setBounds(new Rectangle(9, 280, 125, 24));
        panel_3.add(macroButtonDeleteBtn);
    }
    return tabbedPane;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) JTabbedPane(javax.swing.JTabbedPane) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable)

Aggregations

JTable (javax.swing.JTable)584 JScrollPane (javax.swing.JScrollPane)282 JPanel (javax.swing.JPanel)217 Dimension (java.awt.Dimension)145 JButton (javax.swing.JButton)139 BorderLayout (java.awt.BorderLayout)133 JLabel (javax.swing.JLabel)129 ActionEvent (java.awt.event.ActionEvent)109 ActionListener (java.awt.event.ActionListener)81 TableColumn (javax.swing.table.TableColumn)79 DefaultTableModel (javax.swing.table.DefaultTableModel)75 Component (java.awt.Component)66 BoxLayout (javax.swing.BoxLayout)66 FlowLayout (java.awt.FlowLayout)58 MouseEvent (java.awt.event.MouseEvent)58 JTextField (javax.swing.JTextField)57 TableColumnModel (javax.swing.table.TableColumnModel)52 GridBagConstraints (java.awt.GridBagConstraints)46 TableCellRenderer (javax.swing.table.TableCellRenderer)43 Test (org.junit.Test)43