Search in sources :

Example 61 with JProgressBar

use of javax.swing.JProgressBar in project UniversalMediaServer by UniversalMediaServer.

the class PluginTab method build.

public JComponent build() {
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation);
    FormLayout layout = new FormLayout(colSpec, ROW_SPEC);
    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.DLU4);
    builder.opaque(true);
    CellConstraints cc = new CellConstraints();
    // Available Plugins section
    JComponent availablePluginsHeading = builder.addSeparator(Messages.getString("PluginTab.1"), FormLayoutUtil.flip(cc.xyw(1, 1, 9), colSpec, orientation));
    availablePluginsHeading = (JComponent) availablePluginsHeading.getComponent(0);
    availablePluginsHeading.setFont(availablePluginsHeading.getFont().deriveFont(Font.BOLD));
    final String[] cols = { Messages.getString("NetworkTab.41"), Messages.getString("PluginTab.3"), Messages.getString("NetworkTab.42"), Messages.getString("NetworkTab.43"), Messages.getString("NetworkTab.53") };
    final JTable table = new JTable(1, cols.length) {

        private static final long serialVersionUID = -5032210766949508624L;

        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }

        @Override
        public String getToolTipText(MouseEvent e) {
            java.awt.Point p = e.getPoint();
            int rowIndex = rowAtPoint(p);
            DownloadPlugins plugin = plugins.get(rowIndex);
            return plugin.htmlString();
        }
    };
    refresh(table, cols);
    /* An attempt to set the correct row height adjusted for font scaling.
		 * It sets all rows based on the font size of cell (0, 0). The + 4 is
		 * to allow 2 pixels above and below the text. */
    DefaultTableCellRenderer cellRenderer = (DefaultTableCellRenderer) table.getCellRenderer(0, 0);
    FontMetrics metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
    table.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
    table.setIntercellSpacing(new Dimension(8, 2));
    // Define column widths
    TableColumn nameColumn = table.getColumnModel().getColumn(0);
    nameColumn.setMinWidth(70);
    TableColumn versionColumn = table.getColumnModel().getColumn(2);
    versionColumn.setPreferredWidth(45);
    TableColumn ratingColumn = table.getColumnModel().getColumn(2);
    ratingColumn.setPreferredWidth(45);
    TableColumn authorColumn = table.getColumnModel().getColumn(3);
    authorColumn.setMinWidth(150);
    TableColumn descriptionColumn = table.getColumnModel().getColumn(4);
    descriptionColumn.setMinWidth(300);
    JScrollPane pane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane.setBorder(BorderFactory.createEmptyBorder());
    pane.setPreferredSize(new Dimension(200, 139));
    builder.add(pane, FormLayoutUtil.flip(cc.xyw(1, 3, 9), colSpec, orientation));
    CustomJButton install = new CustomJButton(Messages.getString("NetworkTab.39"));
    builder.add(install, FormLayoutUtil.flip(cc.xy(1, 5), colSpec, orientation));
    install.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!ExternalFactory.localPluginsInstalled()) {
                JOptionPane.showMessageDialog(looksFrame, Messages.getString("NetworkTab.40"));
                return;
            }
            // need admin rights here.
            try {
                if (!FileUtil.getFilePermissions(configuration.getPluginDirectory()).isWritable()) {
                    JOptionPane.showMessageDialog(looksFrame, Messages.getString("PluginTab.16") + (Platform.isWindows() ? "\n" + Messages.getString("AutoUpdate.13") : ""), Messages.getString("Dialog.PermissionsError"), JOptionPane.ERROR_MESSAGE);
                    return;
                }
            } catch (FileNotFoundException e1) {
                JOptionPane.showMessageDialog(looksFrame, String.format(Messages.getString("PluginTab.17"), configuration.getPluginDirectory()), Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE);
                return;
            }
            final int[] rows = table.getSelectedRows();
            JPanel panel = new JPanel();
            GridLayout layout = new GridLayout(3, 1);
            panel.setLayout(layout);
            final JFrame frame = new JFrame(Messages.getString("NetworkTab.46"));
            frame.setSize(250, 110);
            JProgressBar progressBar = new JProgressBar();
            progressBar.setIndeterminate(true);
            panel.add(progressBar);
            final JLabel label = new JLabel("");
            final JLabel inst = new JLabel("");
            panel.add(inst);
            panel.add(label);
            frame.add(panel);
            // Center the installation progress window
            frame.setLocationRelativeTo(null);
            Runnable r = new Runnable() {

                @Override
                public void run() {
                    for (int i = 0; i < rows.length; i++) {
                        DownloadPlugins plugin = plugins.get(rows[i]);
                        if (plugin.isOld()) {
                            // This plugin requires newer UMS
                            // display error and skip it.
                            JOptionPane.showMessageDialog(looksFrame, "Plugin " + plugin.getName() + " requires a newer version of UMS. Please upgrade.", "Version Error", JOptionPane.ERROR_MESSAGE);
                            frame.setVisible(false);
                            continue;
                        }
                        frame.setVisible(true);
                        inst.setText(Messages.getString("NetworkTab.50") + ": " + plugin.getName());
                        try {
                            plugin.install(label);
                        } catch (Exception e) {
                            LOGGER.debug("An error occurred when trying to install the plugin: " + plugin.getName());
                            LOGGER.debug("Full error: " + e);
                        }
                    }
                    frame.setVisible(false);
                }
            };
            new Thread(r).start();
        }
    });
    CustomJButton refresh = new CustomJButton(Messages.getString("PluginTab.2") + " " + Messages.getString("PluginTab.1").toLowerCase());
    builder.add(refresh, FormLayoutUtil.flip(cc.xy(3, 5), colSpec, orientation));
    refresh.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refresh(table, cols);
        }
    });
    // Installed Plugins section
    JComponent component;
    installedPluginsSeparator = (JPanel) builder.addSeparator(Messages.getString("PluginTab.0"), FormLayoutUtil.flip(cc.xyw(1, 7, 9), colSpec, orientation));
    installedPluginsSeparator.setVisible(false);
    component = (JComponent) installedPluginsSeparator.getComponent(0);
    component.setFont(component.getFont().deriveFont(Font.BOLD));
    pPlugins = new JPanel(new GridLayout());
    pPlugins.setVisible(false);
    builder.add(pPlugins, FormLayoutUtil.flip(cc.xyw(1, 9, 9), colSpec, orientation));
    // Credentials section
    component = builder.addSeparator(Messages.getString("PluginTab.8"), FormLayoutUtil.flip(cc.xyw(1, 11, 9), colSpec, orientation));
    component = (JComponent) component.getComponent(0);
    component.setFont(component.getFont().deriveFont(Font.BOLD));
    /* An attempt to set the correct row height adjusted for font scaling.
		 * It sets all rows based on the font size of cell (0, 0). The + 4 is
		 * to allow 2 pixels above and below the text. */
    cellRenderer = (DefaultTableCellRenderer) credTable.getCellRenderer(0, 0);
    metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
    credTable.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
    credTable.setFillsViewportHeight(true);
    credTable.setIntercellSpacing(new Dimension(8, 2));
    // Define column widths
    TableColumn ownerColumn = credTable.getColumnModel().getColumn(0);
    ownerColumn.setMinWidth(70);
    TableColumn tagColumn = credTable.getColumnModel().getColumn(2);
    tagColumn.setPreferredWidth(45);
    TableColumn usrColumn = credTable.getColumnModel().getColumn(2);
    usrColumn.setPreferredWidth(45);
    TableColumn pwdColumn = credTable.getColumnModel().getColumn(3);
    pwdColumn.setPreferredWidth(45);
    pane = new JScrollPane(credTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane.setBorder(BorderFactory.createEmptyBorder());
    pane.setPreferredSize(new Dimension(200, 95));
    builder.add(pane, FormLayoutUtil.flip(cc.xyw(1, 13, 9), colSpec, orientation));
    // Add button
    CustomJButton add = new CustomJButton(Messages.getString("PluginTab.9"));
    builder.add(add, FormLayoutUtil.flip(cc.xy(1, 15), colSpec, orientation));
    add.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addEditDialog(credTable, -1);
        }
    });
    // Edit button
    CustomJButton edit = new CustomJButton(Messages.getString("PluginTab.11"));
    builder.add(edit, FormLayoutUtil.flip(cc.xy(3, 15), colSpec, orientation));
    edit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addEditDialog(credTable, credTable.getSelectedRow());
        }
    });
    // Delete button
    CustomJButton del = new CustomJButton(Messages.getString("PluginTab.12"));
    builder.add(del, FormLayoutUtil.flip(cc.xy(5, 15), colSpec, orientation));
    del.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int[] rows = credTable.getSelectedRows();
            if (rows.length > 0) {
                int n = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("PluginTab.13"), "", JOptionPane.YES_NO_OPTION);
                if (n == JOptionPane.YES_OPTION) {
                    for (int i = 0; i < rows.length; i++) {
                        String key = (String) credTable.getValueAt(rows[i], 0);
                        if (StringUtils.isNotEmpty((String) credTable.getValueAt(rows[i], 1))) {
                            key = key + "." + (String) credTable.getValueAt(rows[i], 1);
                        }
                        cred.clearProperty(key);
                    }
                }
                try {
                    cred.save();
                } catch (ConfigurationException e1) {
                    LOGGER.warn("Couldn't save credentials file {}", e1.getMessage());
                    LOGGER.trace("", e1);
                }
                refreshCred(credTable);
            }
        }
    });
    // Edit Plugin Credential File button
    CustomJButton credEdit = new CustomJButton(Messages.getString("NetworkTab.54"));
    credEdit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JPanel tPanel = new JPanel(new BorderLayout());
            final JTextArea textArea = new JTextArea();
            textArea.setFont(new Font("Courier", Font.PLAIN, 12));
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new Dimension(900, 450));
            try {
                configuration.initCred();
            } catch (IOException e2) {
                LOGGER.error("Could not create credentials file: {}", e2.getMessage());
                LOGGER.trace("", e2);
                return;
            }
            try {
                cred.save();
            } catch (ConfigurationException e3) {
                LOGGER.error("Could not save credentials file: {}", e3.getMessage());
                LOGGER.trace("", e3);
            }
            File f = configuration.getCredFile();
            try {
                try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8))) {
                    String line;
                    StringBuilder sb = new StringBuilder();
                    while ((line = in.readLine()) != null) {
                        sb.append(line);
                        sb.append("\n");
                    }
                    textArea.setText(sb.toString());
                }
            } catch (IOException e1) {
                LOGGER.error("Could not read credentials file: {}", e1.getMessage());
                LOGGER.trace("", e1);
                return;
            }
            tPanel.add(scrollPane, BorderLayout.NORTH);
            Object[] options = { Messages.getString("LooksFrame.9"), Messages.getString("NetworkTab.45") };
            if (JOptionPane.showOptionDialog(looksFrame, tPanel, Messages.getString("NetworkTab.54"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null) == JOptionPane.OK_OPTION) {
                String text = textArea.getText();
                try {
                    try (FileOutputStream fos = new FileOutputStream(f)) {
                        fos.write(text.getBytes(StandardCharsets.UTF_8));
                        fos.flush();
                    }
                    PMS.getConfiguration().reload();
                    try {
                        cred.refresh();
                    } catch (ConfigurationException e2) {
                        LOGGER.error("An error occurred while updating credentials: {}", e2);
                        LOGGER.trace("", e2);
                    }
                    refreshCred(credTable);
                } catch (Exception e1) {
                    JOptionPane.showMessageDialog(looksFrame, Messages.getString("NetworkTab.55") + ": " + e1.getMessage());
                }
            }
        }
    });
    builder.add(credEdit, FormLayoutUtil.flip(cc.xy(7, 15), colSpec, orientation));
    JPanel panel = builder.getPanel();
    JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    return scrollPane;
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) FileNotFoundException(java.io.FileNotFoundException) JProgressBar(javax.swing.JProgressBar) Font(java.awt.Font) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) ConfigurationException(org.apache.commons.configuration.ConfigurationException) FontMetrics(java.awt.FontMetrics) DownloadPlugins(net.pms.configuration.DownloadPlugins) CellConstraints(com.jgoodies.forms.layout.CellConstraints) FormLayout(com.jgoodies.forms.layout.FormLayout) JScrollPane(javax.swing.JScrollPane) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) MouseEvent(java.awt.event.MouseEvent) InputStreamReader(java.io.InputStreamReader) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) ComponentOrientation(java.awt.ComponentOrientation) Dimension(java.awt.Dimension) IOException(java.io.IOException) TableColumn(javax.swing.table.TableColumn) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) CustomJButton(net.pms.newgui.components.CustomJButton) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) File(java.io.File)

Example 62 with JProgressBar

use of javax.swing.JProgressBar in project elki by elki-project.

the class LogPanel method publish.

/**
 * Publish a logging record.
 *
 * @param record Log record to publish
 */
protected void publish(final LogRecord record) {
    if (record instanceof ProgressLogRecord) {
        ProgressLogRecord preg = (ProgressLogRecord) record;
        Progress prog = preg.getProgress();
        JProgressBar pbar = getOrCreateProgressBar(prog);
        updateProgressBar(prog, pbar);
        if (prog.isComplete()) {
            removeProgressBar(prog, pbar);
        }
        if (prog.isComplete() || prog instanceof StepProgress) {
            publishTextRecord(record);
        }
    } else {
        publishTextRecord(record);
    }
}
Also used : FiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress) Progress(de.lmu.ifi.dbs.elki.logging.progress.Progress) StepProgress(de.lmu.ifi.dbs.elki.logging.progress.StepProgress) MutableProgress(de.lmu.ifi.dbs.elki.logging.progress.MutableProgress) IndefiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.IndefiniteProgress) JProgressBar(javax.swing.JProgressBar) ProgressLogRecord(de.lmu.ifi.dbs.elki.logging.progress.ProgressLogRecord) StepProgress(de.lmu.ifi.dbs.elki.logging.progress.StepProgress)

Example 63 with JProgressBar

use of javax.swing.JProgressBar in project ripme by RipMeApp.

the class MainWindow method createUI.

private void createUI(Container pane) {
    // If creating the tray icon fails, ignore it.
    try {
        setupTrayIcon();
    } catch (Exception e) {
    }
    EmptyBorder emptyBorder = new EmptyBorder(5, 5, 5, 5);
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.ipadx = 2;
    gbc.gridx = 0;
    gbc.weighty = 0;
    gbc.ipady = 2;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.PAGE_START;
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) {
        logger.error("[!] Exception setting system theme:", e);
    }
    ripTextfield = new JTextField("", 20);
    ripTextfield.addMouseListener(new ContextMenuMouseListener());
    ImageIcon ripIcon = new ImageIcon(mainIcon);
    ripButton = new JButton("<html><font size=\"5\"><b>Rip</b></font></html>", ripIcon);
    stopButton = new JButton("<html><font size=\"5\"><b>Stop</b></font></html>");
    stopButton.setEnabled(false);
    try {
        Image stopIcon = ImageIO.read(getClass().getClassLoader().getResource("stop.png"));
        stopButton.setIcon(new ImageIcon(stopIcon));
    } catch (Exception ignored) {
    }
    JPanel ripPanel = new JPanel(new GridBagLayout());
    ripPanel.setBorder(emptyBorder);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 0;
    gbc.gridx = 0;
    ripPanel.add(new JLabel("URL:", JLabel.RIGHT), gbc);
    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.gridx = 1;
    ripPanel.add(ripTextfield, gbc);
    gbc.weighty = 0;
    gbc.weightx = 0;
    gbc.gridx = 2;
    ripPanel.add(ripButton, gbc);
    gbc.gridx = 3;
    ripPanel.add(stopButton, gbc);
    gbc.weightx = 1;
    statusLabel = new JLabel("Inactive");
    statusLabel.setHorizontalAlignment(JLabel.CENTER);
    openButton = new JButton();
    openButton.setVisible(false);
    JPanel statusPanel = new JPanel(new GridBagLayout());
    statusPanel.setBorder(emptyBorder);
    gbc.gridx = 0;
    statusPanel.add(statusLabel, gbc);
    gbc.gridy = 1;
    statusPanel.add(openButton, gbc);
    gbc.gridy = 0;
    JPanel progressPanel = new JPanel(new GridBagLayout());
    progressPanel.setBorder(emptyBorder);
    statusProgress = new JProgressBar(0, 100);
    progressPanel.add(statusProgress, gbc);
    JPanel optionsPanel = new JPanel(new GridBagLayout());
    optionsPanel.setBorder(emptyBorder);
    optionLog = new JButton("Log");
    optionHistory = new JButton("History");
    optionQueue = new JButton("Queue");
    optionConfiguration = new JButton("Configuration");
    optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
    optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
    optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
    optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
    try {
        Image icon;
        icon = ImageIO.read(getClass().getClassLoader().getResource("comment.png"));
        optionLog.setIcon(new ImageIcon(icon));
        icon = ImageIO.read(getClass().getClassLoader().getResource("time.png"));
        optionHistory.setIcon(new ImageIcon(icon));
        icon = ImageIO.read(getClass().getClassLoader().getResource("list.png"));
        optionQueue.setIcon(new ImageIcon(icon));
        icon = ImageIO.read(getClass().getClassLoader().getResource("gear.png"));
        optionConfiguration.setIcon(new ImageIcon(icon));
    } catch (Exception e) {
    }
    gbc.gridx = 0;
    optionsPanel.add(optionLog, gbc);
    gbc.gridx = 1;
    optionsPanel.add(optionHistory, gbc);
    gbc.gridx = 2;
    optionsPanel.add(optionQueue, gbc);
    gbc.gridx = 3;
    optionsPanel.add(optionConfiguration, gbc);
    logPanel = new JPanel(new GridBagLayout());
    logPanel.setBorder(emptyBorder);
    logText = new JTextPane();
    logText.setEditable(false);
    JScrollPane logTextScroll = new JScrollPane(logText);
    logTextScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    logPanel.setVisible(false);
    logPanel.setPreferredSize(new Dimension(300, 250));
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1;
    logPanel.add(logTextScroll, gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weighty = 0;
    historyPanel = new JPanel(new GridBagLayout());
    historyPanel.setBorder(emptyBorder);
    historyPanel.setVisible(false);
    historyPanel.setPreferredSize(new Dimension(300, 250));
    historyTableModel = new AbstractTableModel() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getColumnName(int col) {
            return HISTORY.getColumnName(col);
        }

        @Override
        public Class<?> getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }

        @Override
        public Object getValueAt(int row, int col) {
            return HISTORY.getValueAt(row, col);
        }

        @Override
        public int getRowCount() {
            return HISTORY.toList().size();
        }

        @Override
        public int getColumnCount() {
            return HISTORY.getColumnCount();
        }

        @Override
        public boolean isCellEditable(int row, int col) {
            return (col == 0 || col == 4);
        }

        @Override
        public void setValueAt(Object value, int row, int col) {
            if (col == 4) {
                HISTORY.get(row).selected = (Boolean) value;
                historyTableModel.fireTableDataChanged();
            }
        }
    };
    historyTable = new JTable(historyTableModel);
    historyTable.addMouseListener(new HistoryMenuMouseListener());
    historyTable.setAutoCreateRowSorter(true);
    for (int i = 0; i < historyTable.getColumnModel().getColumnCount(); i++) {
        // Default
        int width = 130;
        switch(i) {
            case // URL
            0:
                width = 270;
                break;
            case 3:
                width = 40;
                break;
            case 4:
                width = 15;
                break;
        }
        historyTable.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    JScrollPane historyTableScrollPane = new JScrollPane(historyTable);
    historyButtonRemove = new JButton("Remove");
    historyButtonClear = new JButton("Clear");
    historyButtonRerip = new JButton("Re-rip Checked");
    gbc.gridx = 0;
    // History List Panel
    JPanel historyTablePanel = new JPanel(new GridBagLayout());
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1;
    historyTablePanel.add(historyTableScrollPane, gbc);
    gbc.ipady = 180;
    gbc.gridy = 0;
    historyPanel.add(historyTablePanel, gbc);
    gbc.ipady = 0;
    JPanel historyButtonPanel = new JPanel(new GridBagLayout());
    historyButtonPanel.setPreferredSize(new Dimension(300, 10));
    historyButtonPanel.setBorder(emptyBorder);
    gbc.gridx = 0;
    historyButtonPanel.add(historyButtonRemove, gbc);
    gbc.gridx = 1;
    historyButtonPanel.add(historyButtonClear, gbc);
    gbc.gridx = 2;
    historyButtonPanel.add(historyButtonRerip, gbc);
    gbc.gridy = 1;
    gbc.gridx = 0;
    gbc.weighty = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    historyPanel.add(historyButtonPanel, gbc);
    queuePanel = new JPanel(new GridBagLayout());
    queuePanel.setBorder(emptyBorder);
    queuePanel.setVisible(false);
    queuePanel.setPreferredSize(new Dimension(300, 250));
    queueListModel = new DefaultListModel();
    JList queueList = new JList(queueListModel);
    queueList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    queueList.addMouseListener(new QueueMenuMouseListener());
    JScrollPane queueListScroll = new JScrollPane(queueList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    for (String item : Utils.getConfigList("queue")) {
        queueListModel.addElement(item);
    }
    if (queueListModel.size() > 0) {
        optionQueue.setText("Queue (" + queueListModel.size() + ")");
    } else {
        optionQueue.setText("Queue");
    }
    gbc.gridx = 0;
    JPanel queueListPanel = new JPanel(new GridBagLayout());
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1;
    queueListPanel.add(queueListScroll, gbc);
    queuePanel.add(queueListPanel, gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weighty = 0;
    gbc.ipady = 0;
    configurationPanel = new JPanel(new GridBagLayout());
    configurationPanel.setBorder(emptyBorder);
    configurationPanel.setVisible(false);
    // TODO Configuration components
    configUpdateButton = new JButton("Check for updates");
    configUpdateLabel = new JLabel("Current version: " + UpdateUtils.getThisJarVersion(), JLabel.RIGHT);
    JLabel configThreadsLabel = new JLabel("Maximum download threads:", JLabel.RIGHT);
    JLabel configTimeoutLabel = new JLabel("Timeout (in milliseconds):", JLabel.RIGHT);
    JLabel configRetriesLabel = new JLabel("Retry download count:", JLabel.RIGHT);
    configThreadsText = new JTextField(Integer.toString(Utils.getConfigInteger("threads.size", 3)));
    configTimeoutText = new JTextField(Integer.toString(Utils.getConfigInteger("download.timeout", 60000)));
    configRetriesText = new JTextField(Integer.toString(Utils.getConfigInteger("download.retries", 3)));
    configOverwriteCheckbox = addNewCheckbox("Overwrite existing files?", "file.overwrite", false);
    configAutoupdateCheckbox = addNewCheckbox("Auto-update?", "auto.update", true);
    configPlaySound = addNewCheckbox("Sound when rip completes", "play.sound", false);
    configShowPopup = addNewCheckbox("Notification when rip starts", "download.show_popup", false);
    configSaveOrderCheckbox = addNewCheckbox("Preserve order", "download.save_order", true);
    configSaveLogs = addNewCheckbox("Save logs", "log.save", false);
    configSaveURLsOnly = addNewCheckbox("Save URLs only", "urls_only.save", false);
    configSaveAlbumTitles = addNewCheckbox("Save album titles", "album_titles.save", true);
    configClipboardAutorip = addNewCheckbox("Autorip from Clipboard", "clipboard.autorip", false);
    configSaveDescriptions = addNewCheckbox("Save descriptions", "descriptions.save", true);
    configPreferMp4 = addNewCheckbox("Prefer MP4 over GIF", "prefer.mp4", false);
    configWindowPosition = addNewCheckbox("Restore window position", "window.position", true);
    configURLHistoryCheckbox = addNewCheckbox("Remember URL history", "remember.url_history", true);
    configLogLevelCombobox = new JComboBox(new String[] { "Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug" });
    configLogLevelCombobox.setSelectedItem(Utils.getConfigString("log.level", "Log level: Debug"));
    setLogLevel(configLogLevelCombobox.getSelectedItem().toString());
    configSaveDirLabel = new JLabel();
    try {
        String workingDir = (Utils.shortenPath(Utils.getWorkingDirectory()));
        configSaveDirLabel.setText(workingDir);
        configSaveDirLabel.setForeground(Color.BLUE);
        configSaveDirLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    } catch (Exception e) {
    }
    configSaveDirLabel.setToolTipText(configSaveDirLabel.getText());
    configSaveDirLabel.setHorizontalAlignment(JLabel.RIGHT);
    configSaveDirButton = new JButton("Select Save Directory...");
    gbc.gridy = 0;
    gbc.gridx = 0;
    configurationPanel.add(configUpdateLabel, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configUpdateButton, gbc);
    gbc.gridy = 1;
    gbc.gridx = 0;
    configurationPanel.add(configAutoupdateCheckbox, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configLogLevelCombobox, gbc);
    gbc.gridy = 2;
    gbc.gridx = 0;
    configurationPanel.add(configThreadsLabel, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configThreadsText, gbc);
    gbc.gridy = 3;
    gbc.gridx = 0;
    configurationPanel.add(configTimeoutLabel, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configTimeoutText, gbc);
    gbc.gridy = 4;
    gbc.gridx = 0;
    configurationPanel.add(configRetriesLabel, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configRetriesText, gbc);
    gbc.gridy = 5;
    gbc.gridx = 0;
    configurationPanel.add(configOverwriteCheckbox, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configSaveOrderCheckbox, gbc);
    gbc.gridy = 6;
    gbc.gridx = 0;
    configurationPanel.add(configPlaySound, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configSaveLogs, gbc);
    gbc.gridy = 7;
    gbc.gridx = 0;
    configurationPanel.add(configShowPopup, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configSaveURLsOnly, gbc);
    gbc.gridy = 8;
    gbc.gridx = 0;
    configurationPanel.add(configClipboardAutorip, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configSaveAlbumTitles, gbc);
    gbc.gridy = 9;
    gbc.gridx = 0;
    configurationPanel.add(configSaveDescriptions, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configPreferMp4, gbc);
    gbc.gridy = 10;
    gbc.gridx = 0;
    configurationPanel.add(configWindowPosition, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configURLHistoryCheckbox, gbc);
    gbc.gridy = 11;
    gbc.gridx = 0;
    configurationPanel.add(configSaveDirLabel, gbc);
    gbc.gridx = 1;
    configurationPanel.add(configSaveDirButton, gbc);
    emptyPanel = new JPanel();
    emptyPanel.setPreferredSize(new Dimension(0, 0));
    emptyPanel.setSize(0, 0);
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.gridy = 0;
    pane.add(ripPanel, gbc);
    gbc.gridy = 1;
    pane.add(statusPanel, gbc);
    gbc.gridy = 2;
    pane.add(progressPanel, gbc);
    gbc.gridy = 3;
    pane.add(optionsPanel, gbc);
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridy = 4;
    pane.add(logPanel, gbc);
    gbc.gridy = 5;
    pane.add(historyPanel, gbc);
    gbc.gridy = 5;
    pane.add(queuePanel, gbc);
    gbc.gridy = 5;
    pane.add(configurationPanel, gbc);
    gbc.gridy = 5;
    pane.add(emptyPanel, gbc);
    gbc.weighty = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) DefaultListModel(javax.swing.DefaultListModel) JTextField(javax.swing.JTextField) JTextPane(javax.swing.JTextPane) EmptyBorder(javax.swing.border.EmptyBorder) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) BadLocationException(javax.swing.text.BadLocationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel) JList(javax.swing.JList)

Example 64 with JProgressBar

use of javax.swing.JProgressBar in project pivot by apache.

the class SwingDemo method createSwingFrame.

private static void createSwingFrame() {
    // Create the internal frame that will contain the Swing components
    JInternalFrame internalFrame = new JInternalFrame("Swing Components");
    desktop.add(internalFrame);
    Box box = Box.createVerticalBox();
    box.setBorder(new EmptyBorder(8, 8, 8, 8));
    box.add(new JLabel("Hello from Swing!"));
    box.add(Box.createVerticalStrut(8));
    box.add(new JButton("JButton"));
    box.add(Box.createVerticalStrut(8));
    JCheckBox jCheckBox = new JCheckBox("JCheckBox");
    jCheckBox.setSelected(true);
    box.add(jCheckBox);
    box.add(Box.createVerticalStrut(8));
    ButtonGroup buttonGroup = new ButtonGroup();
    JRadioButton jRadioButton1 = new JRadioButton("JRadioButton 1", true);
    buttonGroup.add(jRadioButton1);
    box.add(jRadioButton1);
    JRadioButton jRadioButton2 = new JRadioButton("JRadioButton 2", true);
    buttonGroup.add(jRadioButton2);
    box.add(jRadioButton2);
    JRadioButton jRadioButton3 = new JRadioButton("JRadioButton 3", true);
    buttonGroup.add(jRadioButton3);
    box.add(jRadioButton3);
    box.add(Box.createVerticalStrut(8));
    JProgressBar jProgressBar = new JProgressBar();
    jProgressBar.setIndeterminate(true);
    box.add(jProgressBar);
    internalFrame.add(new JScrollPane(box));
    // Open and select the internal frame
    internalFrame.setLocation(50, 50);
    internalFrame.setSize(480, 360);
    internalFrame.setVisible(true);
    internalFrame.setResizable(true);
}
Also used : JCheckBox(javax.swing.JCheckBox) JScrollPane(javax.swing.JScrollPane) JRadioButton(javax.swing.JRadioButton) ButtonGroup(javax.swing.ButtonGroup) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) EmptyBorder(javax.swing.border.EmptyBorder) JInternalFrame(javax.swing.JInternalFrame)

Example 65 with JProgressBar

use of javax.swing.JProgressBar in project gate-core by GateNLP.

the class DocumentEditor method initViews.

protected void initViews() {
    viewsInited = true;
    // start building the UI
    setLayout(new BorderLayout());
    JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    progressBar.setMaximumSize(new Dimension(Integer.MAX_VALUE, progressBar.getPreferredSize().height));
    add(progressBar, BorderLayout.CENTER);
    progressBar.setString("Building views");
    progressBar.setValue(10);
    // create the skeleton UI
    topSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, null, null);
    topSplit.setResizeWeight(0.3);
    topSplit.setContinuousLayout(true);
    topSplit.setOneTouchExpandable(true);
    bottomSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topSplit, null);
    bottomSplit.setResizeWeight(0.7);
    bottomSplit.setContinuousLayout(true);
    bottomSplit.setOneTouchExpandable(true);
    horizontalSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, bottomSplit, null);
    horizontalSplit.setResizeWeight(0.7);
    horizontalSplit.setContinuousLayout(true);
    horizontalSplit.setOneTouchExpandable(true);
    // create the bars
    topBar = new JToolBar(JToolBar.HORIZONTAL);
    topBar.setFloatable(false);
    add(topBar, BorderLayout.NORTH);
    progressBar.setValue(40);
    centralViews = new ArrayList<DocumentView>();
    verticalViews = new ArrayList<DocumentView>();
    horizontalViews = new ArrayList<DocumentView>();
    // parse all Creole resources and look for document views
    Set<String> vrSet = Gate.getCreoleRegister().getVrTypes();
    List<ResourceData> viewTypes = new ArrayList<ResourceData>();
    for (String vr : vrSet) {
        ResourceData rData = Gate.getCreoleRegister().get(vr);
        try {
            if (DocumentView.class.isAssignableFrom(rData.getResourceClass())) {
                viewTypes.add(rData);
            }
        } catch (ClassNotFoundException cnfe) {
            cnfe.printStackTrace();
        }
    }
    // sort view types by label
    Collections.sort(viewTypes, new Comparator<ResourceData>() {

        @Override
        public int compare(ResourceData rd1, ResourceData rd2) {
            return rd1.getName().compareTo(rd2.getName());
        }
    });
    for (ResourceData viewType : viewTypes) {
        try {
            // create the resource
            DocumentView aView = (DocumentView) Factory.createResource(viewType.getClassName());
            aView.setTarget(document);
            aView.setOwner(this);
            // add the view
            addView(aView, viewType.getName());
        } catch (ResourceInstantiationException rie) {
            rie.printStackTrace();
        }
    }
    // select the main central view only
    if (centralViews.size() > 0)
        setCentralView(0);
    // populate the main VIEW
    remove(progressBar);
    add(horizontalSplit, BorderLayout.CENTER);
    searchAction = new SearchAction();
    JButton searchButton = new JButton(searchAction);
    searchButton.setMargin(new Insets(0, 0, 0, 0));
    topBar.add(Box.createHorizontalStrut(5));
    topBar.add(searchButton);
    // add a key binding for the search function
    getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("control F"), "Search in text");
    getActionMap().put("Search in text", searchAction);
    // create menu that contains several options for the document editor
    final OptionsMap config = Gate.getUserConfig();
    final JPopupMenu optionsMenu = new JPopupMenu("Options menu");
    final JMenuItem saveCurrentLayoutMenuItem = new JMenuItem(new AbstractAction("Save Current Layout") {

        @Override
        public void actionPerformed(ActionEvent evt) {
            saveSettings();
        }
    });
    optionsMenu.add(saveCurrentLayoutMenuItem);
    final JCheckBoxMenuItem restoreLayoutAutomaticallyMenuItem = new JCheckBoxMenuItem("Restore Layout Automatically");
    restoreLayoutAutomaticallyMenuItem.setSelected(Gate.getUserConfig().getBoolean(DocumentEditor.class.getName() + ".restoreLayoutAutomatically"));
    restoreLayoutAutomaticallyMenuItem.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            // whenever the user checks/unchecks, update the config
            config.put(DocumentEditor.class.getName() + ".restoreLayoutAutomatically", restoreLayoutAutomaticallyMenuItem.isSelected());
        }
    });
    optionsMenu.add(restoreLayoutAutomaticallyMenuItem);
    final JCheckBoxMenuItem readOnly = new JCheckBoxMenuItem("Read-only");
    readOnly.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            config.put(GateConstants.DOCEDIT_READ_ONLY, readOnly.isSelected());
            setEditable(!readOnly.isSelected());
        }
    });
    readOnly.setSelected(config.getBoolean(GateConstants.DOCEDIT_READ_ONLY));
    optionsMenu.addSeparator();
    optionsMenu.add(readOnly);
    // right to left orientation
    final JCheckBoxMenuItem rightToLeftOrientation = new JCheckBoxMenuItem("Right To Left Orientation");
    rightToLeftOrientation.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            config.put(GateConstants.DOC_RTOL_ORIENTATION, rightToLeftOrientation.isSelected());
            setRightToLeftOrientation(rightToLeftOrientation.isSelected());
        }
    });
    optionsMenu.addSeparator();
    optionsMenu.add(rightToLeftOrientation);
    ButtonGroup buttonGroup = new ButtonGroup();
    final JRadioButtonMenuItem insertAppend = new JRadioButtonMenuItem("Insert Append");
    buttonGroup.add(insertAppend);
    insertAppend.setSelected(config.getBoolean(GateConstants.DOCEDIT_INSERT_APPEND));
    insertAppend.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            config.put(GateConstants.DOCEDIT_INSERT_APPEND, insertAppend.isSelected());
        }
    });
    optionsMenu.addSeparator();
    optionsMenu.add(insertAppend);
    final JRadioButtonMenuItem insertPrepend = new JRadioButtonMenuItem("Insert Prepend");
    buttonGroup.add(insertPrepend);
    insertPrepend.setSelected(config.getBoolean(GateConstants.DOCEDIT_INSERT_PREPEND));
    insertPrepend.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            config.put(GateConstants.DOCEDIT_INSERT_PREPEND, insertPrepend.isSelected());
        }
    });
    optionsMenu.add(insertPrepend);
    // if none set then set the default one
    if (!(insertAppend.isSelected() || insertPrepend.isSelected())) {
        insertAppend.setSelected(true);
    }
    JMenuButton menuButton = new JMenuButton(optionsMenu);
    menuButton.setIcon(MainFrame.getIcon("expanded"));
    menuButton.setToolTipText("Options for the document editor");
    // icon is not centred
    menuButton.setMargin(new Insets(0, 0, 0, 1));
    topBar.add(Box.createHorizontalGlue());
    topBar.add(menuButton);
    // when the editor is shown restore views if layout saving is enable
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            if (Gate.getUserConfig().getBoolean(DocumentEditor.class.getName() + ".restoreLayoutAutomatically")) {
                restoreSettings();
            }
        }
    });
    validate();
}
Also used : OptionsMap(gate.util.OptionsMap) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) ActionEvent(java.awt.event.ActionEvent) JProgressBar(javax.swing.JProgressBar) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) BorderLayout(java.awt.BorderLayout) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) ResourceData(gate.creole.ResourceData) JMenuButton(gate.swing.JMenuButton) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) Dimension(java.awt.Dimension) JToolBar(javax.swing.JToolBar) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) ResourceInstantiationException(gate.creole.ResourceInstantiationException) ButtonGroup(javax.swing.ButtonGroup) ItemListener(java.awt.event.ItemListener) JSplitPane(javax.swing.JSplitPane)

Aggregations

JProgressBar (javax.swing.JProgressBar)86 JLabel (javax.swing.JLabel)52 JPanel (javax.swing.JPanel)39 JButton (javax.swing.JButton)32 Dimension (java.awt.Dimension)30 BorderLayout (java.awt.BorderLayout)27 ActionEvent (java.awt.event.ActionEvent)20 JScrollPane (javax.swing.JScrollPane)20 ActionListener (java.awt.event.ActionListener)16 Insets (java.awt.Insets)14 IOException (java.io.IOException)14 GridBagConstraints (java.awt.GridBagConstraints)13 GridBagLayout (java.awt.GridBagLayout)13 JCheckBox (javax.swing.JCheckBox)12 FlowLayout (java.awt.FlowLayout)11 ArrayList (java.util.ArrayList)11 JDialog (javax.swing.JDialog)11 File (java.io.File)10 ImageIcon (javax.swing.ImageIcon)10 JComboBox (javax.swing.JComboBox)9