Example usage for javax.swing DefaultListModel DefaultListModel

List of usage examples for javax.swing DefaultListModel DefaultListModel

Introduction

In this page you can find the example usage for javax.swing DefaultListModel DefaultListModel.

Prototype

DefaultListModel

Source Link

Usage

From source file:md.mclama.com.ModManager.java

/**
 * Create the frame.//from   w ww . ja v a 2s  .  c  o m
 */

@SuppressWarnings("serial")
public ModManager() throws MalformedURLException {
    setResizable(false);
    setTitle("McLauncher " + McVersion);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 700, 400);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.setBounds(0, 0, 694, 372);
    contentPane.add(tabbedPane);

    profileListMdl = new DefaultListModel<String>();
    ModListModel = new DefaultListModel<String>();
    listModel = new DefaultListModel<String>();
    getCurrentMods();

    panelLauncher = new JPanel();
    tabbedPane.addTab("Launcher", null, panelLauncher, null);
    panelLauncher.setLayout(null);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(556, 36, 132, 248);
    panelLauncher.add(scrollPane);
    profileList = new JList<String>(profileListMdl);
    profileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    scrollPane.setViewportView(profileList);

    btnNewProfile = new JButton("New");
    btnNewProfile.setFont(new Font("SansSerif", Font.PLAIN, 12));
    btnNewProfile.setBounds(479, 4, 76, 20);
    panelLauncher.add(btnNewProfile);
    btnNewProfile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            newProfile(txtProfile.getText());
        }
    });
    btnNewProfile.setToolTipText("Click to create a new profile.");

    JButton btnRenameProfile = new JButton("Rename");
    btnRenameProfile.setBounds(479, 25, 76, 20);
    panelLauncher.add(btnRenameProfile);
    btnRenameProfile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            renameProfile();
        }
    });
    btnRenameProfile.setToolTipText("Click to rename the selected profile");

    JButton btnDelProfile = new JButton("Delete");
    btnDelProfile.setBounds(479, 50, 76, 20);
    panelLauncher.add(btnDelProfile);
    btnDelProfile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            deleteProfile();
        }
    });
    btnDelProfile.setToolTipText("Click to delete the selected profile.");

    JButton btnLaunch = new JButton("Launch");
    btnLaunch.setBounds(605, 319, 89, 23);
    panelLauncher.add(btnLaunch);
    btnLaunch.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (selProfile != null) {
                LaunchFactorioWithSelectedMods(false); //dont ignore
            }
        }
    });
    btnLaunch.setToolTipText("Click to launch factorio with the selected mod profile.");

    lblAvailableMods = new JLabel("Available Mods");
    lblAvailableMods.setBounds(4, 155, 144, 14);
    panelLauncher.add(lblAvailableMods);
    lblAvailableMods.setFont(new Font("SansSerif", Font.PLAIN, 10));

    lblAvailableMods.setText("Available Mods: " + -1);

    txtGamePath = new JTextField();
    txtGamePath.setBounds(4, 5, 211, 23);
    panelLauncher.add(txtGamePath);
    txtGamePath.setToolTipText("Select tha path to your game!");
    txtGamePath.setFont(new Font("Tahoma", Font.PLAIN, 8));
    txtGamePath.setText("Game Path");
    txtGamePath.setColumns(10);

    JButton btnFind = new JButton("find");
    btnFind.setBounds(227, 3, 32, 23);
    panelLauncher.add(btnFind);

    txtProfile = new JTextField();
    txtProfile.setBounds(556, 2, 132, 22);
    panelLauncher.add(txtProfile);
    txtProfile.setToolTipText("The name of NEW or RENAME profiles");
    txtProfile.setText("Profile1");
    txtProfile.setColumns(10);

    lblModsEnabled = new JLabel("Mods Enabled: -1");
    lblModsEnabled.setBounds(335, 155, 95, 16);
    panelLauncher.add(lblModsEnabled);
    lblModsEnabled.setFont(new Font("SansSerif", Font.PLAIN, 10));

    JScrollPane scrollPane_1 = new JScrollPane();
    scrollPane_1.setBounds(0, 167, 211, 165);
    panelLauncher.add(scrollPane_1);
    modsList = new JList<String>(listModel);
    modsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    modsList.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            String modName = util.getModVersion(modsList.getSelectedValue());
            lblModVersion.setText("Mod Version: " + modName);
            checkDependency(modsList);
            if (modName.contains(".zip")) {
                new File(System.getProperty("java.io.tmpdir") + modName.replace(".zip", "")).delete();
            }
            if (System.currentTimeMillis() - lastClickTime <= 300) { //Double click
                addMod();
            }
            lastClickTime = System.currentTimeMillis();
        }
    });
    scrollPane_1.setViewportView(modsList);
    modsList.setFont(new Font("Tahoma", Font.PLAIN, 9));

    JScrollPane scrollPane_2 = new JScrollPane();
    scrollPane_2.setBounds(333, 167, 211, 165);
    panelLauncher.add(scrollPane_2);
    enabledModsList = new JList<String>(ModListModel);
    enabledModsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    enabledModsList.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            lblModVersion.setText("Mod Version: " + util.getModVersion(enabledModsList.getSelectedValue()));
            checkDependency(enabledModsList);
            if (System.currentTimeMillis() - lastClickTime <= 300) { //Double click
                removeMod();
            }
            lastClickTime = System.currentTimeMillis();
        }
    });
    enabledModsList.setFont(new Font("SansSerif", Font.PLAIN, 10));
    scrollPane_2.setViewportView(enabledModsList);

    JButton btnEnable = new JButton("Enable");
    btnEnable.setBounds(223, 200, 90, 28);
    panelLauncher.add(btnEnable);
    btnEnable.setToolTipText("Add mod -->");

    JButton btnDisable = new JButton("Disable");
    btnDisable.setBounds(223, 240, 90, 28);
    panelLauncher.add(btnDisable);
    btnDisable.setToolTipText("Disable mod ");

    JLabel lblModsAvailable = new JLabel("Mods available");
    lblModsAvailable.setBounds(4, 329, 89, 14);
    panelLauncher.add(lblModsAvailable);
    lblModsAvailable.setFont(new Font("SansSerif", Font.PLAIN, 10));

    JLabel lblEnabledMods = new JLabel("Enabled Mods");
    lblEnabledMods.setBounds(337, 329, 89, 16);
    panelLauncher.add(lblEnabledMods);
    lblEnabledMods.setFont(new Font("SansSerif", Font.PLAIN, 10));

    lblModVersion = new JLabel("Mod Version: (select a mod first)");
    lblModVersion.setBounds(4, 117, 183, 14);
    panelLauncher.add(lblModVersion);
    lblModVersion.setFont(new Font("SansSerif", Font.PLAIN, 10));

    lblRequiredMods = new JLabel("Required Mods: " + reqModsStr);
    lblRequiredMods.setBounds(6, 143, 538, 14);
    panelLauncher.add(lblRequiredMods);
    lblRequiredMods.setHorizontalAlignment(SwingConstants.RIGHT);
    lblRequiredMods.setFont(new Font("SansSerif", Font.PLAIN, 10));

    JButton btnNewButton = new JButton("TEST");
    btnNewButton.setVisible(testBtnEnabled);
    btnNewButton.setEnabled(testBtnEnabled);
    btnNewButton.setBounds(338, 61, 90, 28);
    panelLauncher.add(btnNewButton);
    btnUpdate.setBounds(218, 322, 103, 20);
    panelLauncher.add(btnUpdate);

    btnUpdate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            util.updateLauncher();
        }
    });
    btnUpdate.setVisible(false);
    btnUpdate.setFont(new Font("SansSerif", Font.PLAIN, 9));

    lblModRequires = new JLabel("Mod Requires: (Select a mod first)");
    lblModRequires.setBounds(4, 127, 317, 16);
    panelLauncher.add(lblModRequires);

    btnLaunchIgnore = new JButton("Launch + ignore");
    btnLaunchIgnore.setToolTipText("Ignore any errors that McLauncher may not correctly account for.");
    btnLaunchIgnore.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnLaunchIgnore.setBounds(556, 284, 133, 23);
    panelLauncher.add(btnLaunchIgnore);

    JButton btnConsole = new JButton("Console");
    btnConsole.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean changeto = !con.isVisible();
            con.setVisible(changeto);
            con.updateConsole();
        }
    });
    btnConsole.setBounds(335, 0, 90, 28);
    panelLauncher.add(btnConsole);

    JPanel panelDownloadMods = new JPanel();
    tabbedPane.addTab("Download Mods", null, panelDownloadMods, null);
    panelDownloadMods.setLayout(null);

    scrollPane_3 = new JScrollPane();
    scrollPane_3.setBounds(0, 0, 397, 303);
    panelDownloadMods.add(scrollPane_3);

    dlModel = new DefaultTableModel(new Object[][] {},
            new String[] { "Mod Name", "Author", "Version", "Tags" }) {
        Class[] columnTypes = new Class[] { String.class, String.class, String.class, Object.class };

        public Class getColumnClass(int columnIndex) {
            return columnTypes[columnIndex];
        }

        boolean[] columnEditables = new boolean[] { false, false, false, false };

        public boolean isCellEditable(int row, int column) {
            return columnEditables[column];
        };
    };

    tSorter = new TableRowSorter<DefaultTableModel>(dlModel);
    tableDownloads = new JTable();
    tableDownloads.setRowSorter(tSorter);
    tableDownloads.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            trow = tableDownloads.getSelectedRow();
            trow = tableDownloads.getRowSorter().convertRowIndexToModel(trow);
            getDlModData();
            canDownloadMod = true;
        }
    });
    tableDownloads.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            trow = tableDownloads.getSelectedRow();
            trow = tableDownloads.getRowSorter().convertRowIndexToModel(trow);
            getDlModData();
            canDownloadMod = true;
        }
    });
    tableDownloads.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    tableDownloads.setShowVerticalLines(true);
    tableDownloads.setShowHorizontalLines(true);
    tableDownloads.setModel(dlModel);
    tableDownloads.getColumnModel().getColumn(0).setPreferredWidth(218);
    tableDownloads.getColumnModel().getColumn(1).setPreferredWidth(97);
    tableDownloads.getColumnModel().getColumn(2).setPreferredWidth(77);
    scrollPane_3.setViewportView(tableDownloads);

    btnDownload = new JButton("Download");
    btnDownload.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (canDownloadMod && !CurrentlyDownloading) {
                String dlUrl = getModDownloadUrl();
                try {
                    if (dlUrl.equals("") || dlUrl.equals(" ") || dlUrl == null) {
                        con.log("Log", "No download link for mod, got... '" + dlUrl + "'");
                    } else {
                        CurrentlyDownloading = true;
                        CurrentDownload = new Download(new URL(dlUrl), McLauncher);
                    }
                } catch (MalformedURLException e1) {
                    con.log("Log", "Failed to download mod... No download URL?");
                }
            }
        }
    });
    btnDownload.setBounds(307, 308, 90, 28);
    panelDownloadMods.add(btnDownload);

    btnGotoMod = new JButton("Mod Page");
    btnGotoMod.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            util.openWebpage(modPageUrl);
        }
    });
    btnGotoMod.setEnabled(false);
    btnGotoMod.setBounds(134, 308, 90, 28);
    panelDownloadMods.add(btnGotoMod);

    pBarDownloadMod = new JProgressBar();
    pBarDownloadMod.setBounds(538, 308, 150, 10);
    panelDownloadMods.add(pBarDownloadMod);

    pBarExtractMod = new JProgressBar();
    pBarExtractMod.setBounds(538, 314, 150, 10);
    panelDownloadMods.add(pBarExtractMod);

    lblDownloadModInfo = new JLabel("Download progress");
    lblDownloadModInfo.setBounds(489, 326, 199, 16);
    panelDownloadMods.add(lblDownloadModInfo);
    lblDownloadModInfo.setHorizontalAlignment(SwingConstants.TRAILING);

    panelModImg = new JPanel();
    panelModImg.setBounds(566, 0, 128, 128);
    panelDownloadMods.add(panelModImg);

    txtFilterText = new JTextField();
    txtFilterText.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            if (txtFilterText.getText().equals("Filter Text")) {
                txtFilterText.setText("");
                newFilter();
            }
        }
    });
    txtFilterText.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (!txtFilterText.getText().equals("Filter Text")) {
                newFilter();
            }
        }
    });
    txtFilterText.setText("Filter Text");
    txtFilterText.setBounds(0, 308, 122, 28);
    panelDownloadMods.add(txtFilterText);
    txtFilterText.setColumns(10);

    comboBox = new JComboBox();
    comboBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            newFilter();
        }
    });
    comboBox.setModel(new DefaultComboBoxModel(new String[] { "No tag filter", "Vanilla", "Machine", "Mechanic",
            "New Ore", "Module", "Big Mod", "Power", "GUI", "Map-Gen", "Must-Have", "Equipment" }));
    comboBox.setBounds(403, 44, 150, 26);
    panelDownloadMods.add(comboBox);

    lblModDlCounter = new JLabel("Mod database: ");
    lblModDlCounter.setFont(new Font("SansSerif", Font.PLAIN, 10));
    lblModDlCounter.setBounds(403, 5, 162, 16);
    panelDownloadMods.add(lblModDlCounter);

    txtrDMModDescription = new JTextArea();
    txtrDMModDescription.setBackground(Color.LIGHT_GRAY);
    txtrDMModDescription.setBorder(new LineBorder(new Color(0, 0, 0)));
    txtrDMModDescription.setFocusable(false);
    txtrDMModDescription.setEditable(false);
    txtrDMModDescription.setLineWrap(true);
    txtrDMModDescription.setWrapStyleWord(true);
    txtrDMModDescription.setText("Mod Description: ");
    txtrDMModDescription.setBounds(403, 132, 285, 75);
    panelDownloadMods.add(txtrDMModDescription);

    lblDMModTags = new JTextArea();
    lblDMModTags.setFocusable(false);
    lblDMModTags.setEditable(false);
    lblDMModTags.setBorder(new LineBorder(new Color(0, 0, 0)));
    lblDMModTags.setWrapStyleWord(true);
    lblDMModTags.setLineWrap(true);
    lblDMModTags.setBackground(Color.LIGHT_GRAY);
    lblDMModTags.setText("Mod Tags: ");
    lblDMModTags.setBounds(403, 71, 160, 60);
    panelDownloadMods.add(lblDMModTags);

    lblDMRequiredMods = new JTextArea();
    lblDMRequiredMods.setFocusable(false);
    lblDMRequiredMods.setEditable(false);
    lblDMRequiredMods.setText("Required Mods: ");
    lblDMRequiredMods.setWrapStyleWord(true);
    lblDMRequiredMods.setLineWrap(true);
    lblDMRequiredMods.setBorder(new LineBorder(new Color(0, 0, 0)));
    lblDMRequiredMods.setBackground(Color.LIGHT_GRAY);
    lblDMRequiredMods.setBounds(403, 208, 285, 57);
    panelDownloadMods.add(lblDMRequiredMods);

    lblDLModLicense = new JLabel("");
    lblDLModLicense.setHorizontalAlignment(SwingConstants.RIGHT);
    lblDLModLicense.setBounds(403, 294, 285, 16);
    panelDownloadMods.add(lblDLModLicense);

    lblWipmod = new JLabel("");
    lblWipmod.setBounds(395, 314, 64, 16);
    panelDownloadMods.add(lblWipmod);

    JButton btnCancel = new JButton("Cancel");
    btnCancel.setToolTipText("Stop downloading");
    btnCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            CurrentDownload.cancel();
        }
    });
    btnCancel.setBounds(230, 308, 72, 28);
    panelDownloadMods.add(btnCancel);

    panelOptions = new JPanel();
    tabbedPane.addTab("Options", null, panelOptions, null);
    panelOptions.setLayout(null);
    scrollPane_4.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane_4.setBounds(0, 0, 694, 342);
    panelOptions.add(scrollPane_4);

    panel = new JPanel();
    scrollPane_4.setViewportView(panel);
    panel.setLayout(null);

    lblCloseMclauncherAfter = new JLabel("Close McLauncher after launching Factorio?");
    lblCloseMclauncherAfter.setBounds(6, 6, 274, 16);
    panel.add(lblCloseMclauncherAfter);

    lblCloseMclauncherAfter_1 = new JLabel("Close McLauncher after updating?");
    lblCloseMclauncherAfter_1.setBounds(6, 34, 274, 16);
    panel.add(lblCloseMclauncherAfter_1);

    lblSortNewestDownloadable = new JLabel("Sort newest downloadable mods first?");
    lblSortNewestDownloadable.setBounds(6, 62, 274, 16);
    panel.add(lblSortNewestDownloadable);

    tglbtnNewModsFirst = new JToggleButton("Toggle");
    tglbtnNewModsFirst.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            lblNeedrestart.setText("McLauncher needs to restart for that to work");
            writeData();
        }
    });
    tglbtnNewModsFirst.setSelected(true);
    tglbtnNewModsFirst.setBounds(281, 56, 66, 28);
    panel.add(tglbtnNewModsFirst);

    tglbtnCloseAfterUpdate = new JToggleButton("Toggle");
    tglbtnCloseAfterUpdate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            writeData();
        }
    });
    tglbtnCloseAfterUpdate.setBounds(281, 28, 66, 28);
    panel.add(tglbtnCloseAfterUpdate);

    tglbtnCloseAfterLaunch = new JToggleButton("Toggle");
    tglbtnCloseAfterLaunch.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            writeData();
        }
    });
    tglbtnCloseAfterLaunch.setBounds(281, 0, 66, 28);
    panel.add(tglbtnCloseAfterLaunch);

    tglbtnDisplayon = new JToggleButton("On");
    tglbtnDisplayon.setFont(new Font("SansSerif", Font.PLAIN, 10));
    tglbtnDisplayon.setSelected(true);
    tglbtnDisplayon.setBounds(588, 308, 44, 28);
    panel.add(tglbtnDisplayon);

    tglbtnDisplayoff = new JToggleButton("Off");
    tglbtnDisplayoff.setFont(new Font("SansSerif", Font.PLAIN, 10));
    tglbtnDisplayoff.setBounds(644, 308, 44, 28);
    panel.add(tglbtnDisplayoff);

    lblInfo = new JLabel("What enabled and disabled look like");
    lblInfo.setFont(new Font("SansSerif", Font.PLAIN, 10));
    lblInfo.setHorizontalAlignment(SwingConstants.TRAILING);
    lblInfo.setBounds(359, 314, 231, 16);
    panel.add(lblInfo);

    JSeparator separator = new JSeparator();
    separator.setBounds(6, 55, 676, 24);
    panel.add(separator);

    JSeparator separator_1 = new JSeparator();
    separator_1.setBounds(6, 27, 676, 18);
    panel.add(separator_1);

    JSeparator separator_2 = new JSeparator();
    separator_2.setBounds(6, 84, 676, 24);
    panel.add(separator_2);

    JSeparator separator_3 = new JSeparator();
    separator_3.setOrientation(SwingConstants.VERTICAL);
    separator_3.setBounds(346, 0, 16, 336);
    panel.add(separator_3);

    lblNeedrestart = new JLabel("");
    lblNeedrestart.setBounds(6, 314, 341, 16);
    panel.add(lblNeedrestart);

    tglbtnSendAnonData = new JToggleButton("Toggle");
    tglbtnSendAnonData.setToolTipText("Information regarding the activity of McLauncher.");
    tglbtnSendAnonData.setSelected(true); //set enabled by default.
    tglbtnSendAnonData.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            writeData();
        }
    });
    tglbtnSendAnonData.setBounds(622, 0, 66, 28);
    panel.add(tglbtnSendAnonData);

    lblSendAnonymousUse = new JLabel("Send anonymous use data?");
    lblSendAnonymousUse.setBounds(359, 6, 251, 16);
    panel.add(lblSendAnonymousUse);

    lblDeleteOldMod = new JLabel("Delete old mod before updating?");
    lblDeleteOldMod.setBounds(359, 34, 251, 16);
    panel.add(lblDeleteOldMod);

    tglbtnDeleteBeforeUpdate = new JToggleButton("Toggle");
    tglbtnDeleteBeforeUpdate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            writeData();
        }
    });
    tglbtnDeleteBeforeUpdate.setBounds(622, 28, 66, 28);
    panel.add(tglbtnDeleteBeforeUpdate);

    tglbtnAlertOnModUpdateAvailable = new JToggleButton("Toggle");
    tglbtnAlertOnModUpdateAvailable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            writeData();
        }
    });
    tglbtnAlertOnModUpdateAvailable.setSelected(true);
    tglbtnAlertOnModUpdateAvailable.setBounds(281, 86, 66, 28);
    panel.add(tglbtnAlertOnModUpdateAvailable);

    separator_4 = new JSeparator();
    separator_4.setBounds(0, 112, 676, 24);
    panel.add(separator_4);

    JLabel lblAlertModHas = new JLabel("Alert mod has update on launch?");
    lblAlertModHas.setBounds(6, 92, 231, 16);
    panel.add(lblAlertModHas);

    panelChangelog = new JPanel();
    tabbedPane.addTab("Changelog", null, panelChangelog, null);
    panelChangelog.setLayout(new BoxLayout(panelChangelog, BoxLayout.X_AXIS));

    scrollPane_6 = new JScrollPane();
    panelChangelog.add(scrollPane_6);

    textChangelog = new JTextArea();
    scrollPane_6.setViewportView(textChangelog);
    textChangelog.setEditable(false);
    textChangelog.setText(
            "v0.4.6\r\n\r\n+Fix problem where config file would not save in the correct location. (Thanks Arano-kai)\r\n+McLauncher will now save when you select a path, or profile. (Thanks Arano-kai)\r\n+Fixed an issue where McLauncher could not get the version from a .zip mod. (Thanks Arano-kai)\r\n+Added a Cancel button to stop downloading the current mod. (Suggested by  Arano-kai)\r\n\r\n\r\n\r\nv0.4.5\r\n\r\n+McLauncher should now correctly warn you on failed write/read access.\r\n+McLauncher should now work when a user has both zip and installer versions of factorio. (Thanks Jeroon)\r\n+Attempt to fix an error with dependency and .zip files, With versions. (Thanks Arano-kai)\r\n+Fix only allow single selection of mods. (Thanks Arano-kai)\r\n+Fix for the Launch+Ignore button problem on linux being cut off. (Thanks Arano-kai)\r\n+Display download progress.\r\n+Fixed an error that was thrown when clicking on some mods that had a single dependency mod.\r\n+Double clicking on a mod will now enable or disable the mod. (Thanks Arano-kai)");
    btnLaunchIgnore.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (selProfile != null) {
                LaunchFactorioWithSelectedMods(true); //ignore errors, launch.
            }
        }
    });
    btnLaunchIgnore.setVisible(false);
    //This is my test button. I use this to test things then implement them into the swing.
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            testButtonCode(e);
        }
    });
    //Disable mods button. (from profile)
    btnDisable.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            removeMod();
        }
    });
    //Enable mods button. (to profile)
    btnEnable.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            addMod();
        }
    });
    //Game path button
    btnFind.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            findPath();
        }
    });
    //mouseClick event lister for when you click on a new profile
    profileList.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            selectedProfile();
        }
    });

    readData(); //Load settings

    init(); //some extra init
    getMods(); //Get the mods the user has installed
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * @param clsHash/*  w ww . ja v  a  2s  .co m*/
 */
private void showClassList(final Hashtable<String, Boolean> clsHash) {
    boolean wasVisible = false;
    boolean wasCreated = false;
    if (classFrame == null) {
        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g"));

        classList = new JList(new DefaultListModel());
        //pb.add(UIHelper.createLabel("Unused Classes"), cc.xy(1,1));
        pb.add(UIHelper.createScrollPane(classList), cc.xy(1, 1));

        pb.setDefaultDialogBorder();

        classFrame = new CustomFrame("Used Classes", CustomFrame.OK_BTN, pb.getPanel());
        classFrame.setOkLabel("Close");
        classFrame.createUI();
        wasCreated = true;

    } else {
        wasVisible = classFrame.isVisible();
    }

    Hashtable<String, Boolean> allClassesHash = new Hashtable<String, Boolean>();
    for (DBTableInfo ti : DBTableIdMgr.getInstance().getTables()) {
        allClassesHash.put(ti.getShortClassName(), true);
    }

    for (String key : clsHash.keySet()) {
        allClassesHash.remove(key);
    }

    ((DefaultListModel) classList.getModel()).clear();
    TreeSet<String> keys = new TreeSet<String>(allClassesHash.keySet());
    for (String key : keys) {
        ((DefaultListModel) classList.getModel()).addElement(key);
    }

    // Can't believe I have to do this
    Rectangle r = classFrame.getBounds();
    r.height++;
    classFrame.setBounds(r);
    r.height--;
    //----
    classFrame.setBounds(r);

    if (wasCreated) {
        classFrame.pack();
    }

    if (!wasVisible) {
        UIHelper.centerAndShow(classFrame);
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchTroopsFrame.java

private void updateTagList() {
    DefaultListModel m = new DefaultListModel();
    m.addElement(NoTag.getSingleton());//w  w  w.  ja  va2  s . c  om
    for (ManageableType t : TagManager.getSingleton().getAllElements()) {
        Tag ta = (Tag) t;
        m.addElement(ta);
    }
    jXGroupsList.setModel(m);
}

From source file:net.sf.jabref.gui.ContentSelectorDialog2.java

private void setupWordSelector() {

    // Have we already created a listmodel for this field?
    wordListModel = wordListModels.get(currentField);
    if (wordListModel == null) {
        wordListModel = new DefaultListModel<>();
        wordList.setModel(wordListModel);
        wordListModels.put(currentField, wordListModel);

        int index = 0;
        for (String s : metaData.getContentSelectors(currentField)) {
            wordListModel.add(index, s);
            index++;//  www  .  j  ava  2s.c  om
        }
    } else {
        wordList.setModel(wordListModel);
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchReportFrame.java

private void buildMenu() {
    // <editor-fold defaultstate="collapsed" desc="view task pane">
    JXTaskPane viewTaskPane = new JXTaskPane();
    viewTaskPane.setTitle("Anzeigen");

    viewTaskPane.getContentPane().add(//from   w ww .j a  v a2 s .c  o  m
            factoryButton("/res/ui/view_report.png", "Die gew&auml;hlten Berichte ffnen", new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    ReportTableTab tab = getActiveTab();
                    if (tab != null) {
                        tab.viewReport();
                    }
                }
            }));
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="transfer task pane">
    JXTaskPane transferTaskPane = new JXTaskPane();
    transferTaskPane.setTitle("bertragen");

    transferTaskPane.getContentPane().add(factoryButton("/res/ui/troop_info_add.png",
            "&Uuml;bertr&auml;gt die &uuml;berlebenden Truppen des Verteidigers", new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    ReportTableTab tab = getActiveTab();
                    if (tab != null) {
                        tab.transferTroopInfos();
                    }
                }
            }));

    transferTaskPane.getContentPane().add(factoryButton("/res/ui/report_toAStar.png",
            "&Uuml;bertr&auml;gt den gew&auml;hlten Berichte nach A*Star", new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    ReportTableTab tab = getActiveTab();
                    if (tab != null) {
                        tab.transferSelection(ReportTableTab.TRANSFER_TYPE.ASTAR);
                    }
                }
            }));
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="misc task pane">
    JXTaskPane miscPane = new JXTaskPane();
    miscPane.setTitle("Sonstiges");

    miscPane.getContentPane()
            .add(factoryButton("/res/ui/document_new_24x24.png", "Neuen Plan erstellen", new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    fireCreateAttackPlanEvent(e);
                }
            }));

    miscPane.getContentPane().add(factoryButton("/res/ui/medal.png",
            "Statistiken zu den gew&auml;hlten Berichten erstellen", new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    ReportTableTab tab = getActiveTab();
                    if (tab != null) {
                        String[] groups = ReportManager.getSingleton().getGroups();
                        DefaultListModel model = new DefaultListModel();
                        for (String group : groups) {
                            model.addElement(group);
                        }

                        jReportSetsForStatsList.setModel(model);
                        jCreateStatsFrame.setLocationRelativeTo(DSWorkbenchReportFrame.this);
                        jCreateStatsFrame.setVisible(true);
                    }
                }
            }));

    miscPane.getContentPane().add(factoryButton("/res/ui/report_cleanup.png",
            "Veraltete und doppelte Berichte im gewhlten Berichtset l&ouml;schen", new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    cleanupReports();
                }
            }));

    miscPane.getContentPane().add(factoryButton("/res/ui/index_edit.png",
            "Definierte Regeln bearbeiten oder neu erstellen", new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    rulesDialog.rebuildRuleList();
                    rulesDialog.setLocationRelativeTo(DSWorkbenchReportFrame.this);
                    rulesDialog.setVisible(true);
                }
            }));

    miscPane.getContentPane().add(factoryButton("/res/ui/index_refresh.png",
            "Definierte Regeln jetzt auf das gew&auml;hlte Berichtset anwenden", new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    ReportTableTab tab = getActiveTab();
                    if (tab != null) {
                        int changed = ReportManager.getSingleton().filterNow(tab.getReportSet());
                        tab = getActiveTab();
                        if (tab != null) {
                            tab.showInfo(changed + " Berichte neu eingeordnet");
                        }
                    }
                }
            }));
    // </editor-fold>

    centerPanel.setupTaskPane(viewTaskPane, transferTaskPane, miscPane);
}

From source file:es.emergya.ui.gis.popups.ConsultaHistoricos.java

private JPanel getElementos() {
    JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEADING));
    panel.setOpaque(false);/*from w  w w  . j  ava  2  s .c  o  m*/
    panel.setBorder(new TitledBorder("Elementos a Consultar"));

    JLabel jLabel = new JLabel("Recursos", SwingConstants.RIGHT);
    jLabel.setPreferredSize(ConsultaHistoricos.DIMENSION_LABEL);
    panel.add(jLabel);
    recursos = new JList(new DefaultListModel());
    recursos.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK), "selectAll");
    recursos.getActionMap().put("selectAll", new AbstractAction() {

        private static final long serialVersionUID = -5515338515763292526L;

        @Override
        public void actionPerformed(ActionEvent e) {
            recursos.setSelectionInterval(0, recursos.getModel().getSize() - 1);
        }
    });
    recursos.addListSelectionListener(listSelectionListener);
    final JScrollPane jScrollPaneR = new JScrollPane(recursos, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jScrollPaneR.getViewport().setPreferredSize(DIMENSION_JLIST);
    panel.add(jScrollPaneR);

    jLabel = new JLabel("Incidencias", SwingConstants.RIGHT);
    jLabel.setPreferredSize(ConsultaHistoricos.DIMENSION_LABEL);
    panel.add(jLabel);
    incidencias = new JList(new DefaultListModel());
    incidencias.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK), "selectAll");
    incidencias.getActionMap().put("selectAll", new AbstractAction() {

        private static final long serialVersionUID = -5515338515763292526L;

        @Override
        public void actionPerformed(ActionEvent e) {
            incidencias.setSelectionInterval(0, incidencias.getModel().getSize() - 1);
        }
    });
    incidencias.addListSelectionListener(listSelectionListener);
    final JScrollPane jScrollPaneI = new JScrollPane(incidencias, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jScrollPaneI.getViewport().setPreferredSize(DIMENSION_JLIST);
    panel.setPreferredSize(DIMENSION_2JLIST);
    panel.add(jScrollPaneI);
    return panel;
}

From source file:net.sf.xmm.moviemanager.gui.DialogIMDB.java

ArrayList<ModelIMDbSearchHit> performSearch() {

    DefaultListModel model = new DefaultListModel();
    model.addElement(/*from w  w w. j  av a2 s . c  o  m*/
            new ModelIMDbSearchHit(Localizer.get("DialogIMDB.list-element.messsage.search-in-progress"))); //$NON-NLS-1$
    listMovies.setModel(model);

    ArrayList<ModelIMDbSearchHit> hits = null;

    try {
        hits = IMDbLib.newIMDb(MovieManager.getConfig().getHttpSettings())
                .getSimpleMatches(searchStringField.getText());
        handleSearchResults(hits);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        executeErrorMessage(e);
        dispose();
    }
    return hits;
}

From source file:ca.sqlpower.swingui.enterprise.client.ServerProjectsManagerPanel.java

/**
 * This constructor creates a dialog for modifying and loading a project
 * from a single server designated by the given serverInfo parameter.
 * //from   w  w w. j  av a2  s. c o  m
 * @param serverInfo
 *            Projects will be retrieved from this server based on the
 *            information and displayed. The dialog will allow editing the
 *            security as well as creating and deleting projects on this
 *            server.
 * @param dialogOwner
 *            The dialog to parent new dialogs to.
 * @param upf
 *            A user prompter factory for displaying error and warning
 *            messages to users.
 * @param closeAction
 *            An action that will close the dialog or frame that this dialog
 *            is contained in.
 * @param defaultFileDirectory
 *            A default file directory to start looking for files in if the
 *            user wants to upload a project. If null this will default to
 *            the user's home directory.
 * @param cookieStore
 *            A cookie store for HTTP requests. Used by the
 *            {@link ClientSideSessionUtils}.
 */
public ServerProjectsManagerPanel(SPServerInfo serverInfo, Component dialogOwner, UserPrompterFactory upf,
        Action closeAction, File defaultFileDirectory, CookieStore cookieStore) {
    this.serverInfo = serverInfo;
    this.dialogOwner = dialogOwner;
    this.upf = upf;
    this.closeAction = closeAction;
    this.defaultFileDirectory = defaultFileDirectory;
    this.cookieStore = cookieStore;

    cookieStore.clear();

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("pref:grow, 5dlu, pref", "pref, pref, pref"));

    servers = null;

    projects = new JList(new DefaultListModel());
    projects.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            refreshPanel();
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                getOpenAction().actionPerformed(null);
            }
        }
    });

    JScrollPane projectsPane = new JScrollPane(projects);
    projectsPane.setPreferredSize(new Dimension(250, 300));

    CellConstraints cc = new CellConstraints();
    builder.add(new JLabel(serverInfo.getName() + "'s projects:"), cc.xyw(1, 1, 2));
    builder.nextLine();
    builder.add(projectsPane, cc.xywh(1, 2, 1, 2));

    DefaultFormBuilder buttonBarBuilder = new DefaultFormBuilder(new FormLayout("pref"));
    buttonBarBuilder.append(new JButton(refreshAction));
    buttonBarBuilder.append(securityButton);
    buttonBarBuilder.append(new JButton(newAction));
    buttonBarBuilder.append(openButton);
    buttonBarBuilder.append(new JButton(deleteAction));
    buttonBarBuilder.append(new JButton(closeAction));
    builder.add(buttonBarBuilder.getPanel(), cc.xy(3, 2));
    builder.setDefaultDialogBorder();
    panel = builder.getPanel();
}

From source file:de.tor.tribes.ui.views.DSWorkbenchTagFrame.java

private void updateVillageList() {
    List<Tag> selection = getSelectedTags();
    DefaultListModel model = new DefaultListModel();

    List<Village> villages = new LinkedList<>();
    for (Tag t : selection) {
        for (Integer id : t.getVillageIDs()) {
            Village v = DataHolder.getSingleton().getVillagesById().get(id);
            if (v != null && !villages.contains(v)) {
                villages.add(v);//from   w ww . j  av a2  s.  com
            }
        }
    }
    if (!selection.isEmpty() && !villages.isEmpty()) {
        Collections.sort(villages);
        for (Village v : villages) {
            model.addElement(v);
        }
    }
    jVillageList.setModel(model);
}

From source file:edu.ku.brc.specify.tools.l10nios.StrLocalizerAppForiOS.java

/**
 * /*from w w w .j  a v a2s .c  o m*/
 */
private void createUI() {
    IconManager.setApplicationClass(Specify.class);
    IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$
    IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$
    IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$

    System.setProperty("edu.ku.brc.ui.db.PickListDBAdapterFactory", //$NON-NLS-1$
            "edu.ku.brc.specify.tools.StrLocPickListFactory"); // Needed By the Auto Cosmplete UI  //$NON-NLS-1$

    CellConstraints cc = new CellConstraints();

    fileList = new JList(fileModel = new DefaultListModel());
    termList = new JList(model = new ItemModel(null));

    srcLbl = setTAReadOnly(UIHelper.createTextArea(3, 40));
    //srcLbl.setBorder(new LineBorder(srcLbl.getForeground()));
    textField = UIHelper.createTextField(40);

    comment = setTAReadOnly(UIHelper.createTextArea(3, 40));

    /*textField.getDocument().addDocumentListener(new DocumentAdaptor() {
    @Override
    protected void changed(DocumentEvent e)
    {
        hasChanged = true;
    }
    });*/

    statusBar = new JStatusBar();
    statusBar.setSectionText(1, "     "); //$NON-NLS-1$ //$NON-NLS-2$
    UIRegistry.setStatusBar(statusBar);

    srcLbl.setEditable(false);

    rsController = new ResultSetController(null, false, false, false, "", 1, true);

    transBtn = UIHelper.createButton(getResourceString("StrLocalizerApp.Translate"));
    transBtn.setVisible(false);

    PanelBuilder pbr = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,4px,p,4px,p,4px,p,4px,p,4px,p"));

    //pbr.add(UIHelper.createLabel(getResourceString("StrLocalizerApp.FileLbl")), cc.xy(1, 1));
    //fileLbl = UIHelper.createLabel("   ");
    //pbr.add(fileLbl, cc.xy(3, 1));

    int y = 1;
    pbr.addSeparator("Item", cc.xyw(1, y, 3));
    y += 2;

    pbr.add(UIHelper.createLabel("English:", SwingConstants.RIGHT), cc.xy(1, y));
    pbr.add(srcLbl, cc.xy(3, y));
    y += 2;

    pbr.add(UIHelper.createFormLabel("Comment", SwingConstants.RIGHT), cc.xy(1, y));
    pbr.add(comment, cc.xy(3, y));
    y += 2;

    destLbl = UIHelper.createFormLabel("", SwingConstants.RIGHT);//destLanguage.getDisplayName());
    pbr.add(destLbl, cc.xy(1, y));
    pbr.add(textField, cc.xy(3, y));
    y += 2;

    pbr.add(rsController.getPanel(), cc.xyw(1, y, 3));
    y += 2;
    pbr.add(transBtn, cc.xy(1, y));

    JScrollPane sp = UIHelper.createScrollPane(termList);

    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,4px,f:p:g,10px,p"));
    pb.addSeparator("Localize", cc.xy(1, 1));
    pb.add(sp, cc.xy(1, 3));
    pb.add(pbr.getPanel(), cc.xy(1, 5));
    pb.setDefaultDialogBorder();

    ResultSetController.setBackStopRS(rsController);

    PanelBuilder fpb = new PanelBuilder(new FormLayout("8px,f:p:g", "p,4px,f:p:g"));
    JScrollPane filesp = UIHelper.createScrollPane(fileList);
    fpb.add(UIHelper.createLabel("Files", SwingConstants.CENTER), cc.xy(2, 1));
    fpb.add(filesp, cc.xy(2, 3));

    setLayout(new BorderLayout());
    add(fpb.getPanel(), BorderLayout.WEST);
    add(pb.getPanel(), BorderLayout.CENTER);
    add(statusBar, BorderLayout.SOUTH);

    mainPane = this;

    textField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            checkForChange();
        }
    });

    termList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                itemSelected();
            }
        }
    });

    fileList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fileSelected();
            }
        }
    });

    transBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String txt = srcLbl.getText();
            String newText = translate(txt);
            if (StringUtils.isNotEmpty(newText)) {
                newText = newText.replace("&#039;", "'");
                textField.setText(newText);
                L10NItem entry = (L10NItem) termList.getSelectedValue();
                entry.setValue(textField.getText());
            }
        }
    });

    rscListener = new ResultSetControllerListener() {
        @Override
        public void newRecordAdded() {
        }

        @Override
        public void indexChanged(int newIndex) {
            termList.setSelectedIndex(newIndex);
        }

        @Override
        public boolean indexAboutToChange(int oldIndex, int newIndex) {
            return true;
        }
    };

    rsController.addListener(rscListener);
}