Search in sources :

Example 31 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project android-classyshark by google.

the class GuiMode method buildAndShowClassyShark.

private static void buildAndShowClassyShark(List<String> cmdLineArgs) {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (UnsupportedLookAndFeelException | IllegalAccessException | ClassNotFoundException | InstantiationException | SecurityException ex) {
        ex.printStackTrace();
    }
    JFrame frame = buildClassySharkFrame(cmdLineArgs);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    theme.applyTo(frame);
}
Also used : UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) JFrame(javax.swing.JFrame)

Example 32 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException 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(Utils.getLocalizedString("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(Utils.getLocalizedString("Log"));
    optionHistory = new JButton(Utils.getLocalizedString("History"));
    optionQueue = new JButton(Utils.getLocalizedString("queue"));
    optionConfiguration = new JButton(Utils.getLocalizedString("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(Utils.getLocalizedString("remove"));
    historyButtonClear = new JButton(Utils.getLocalizedString("clear"));
    historyButtonRerip = new JButton(Utils.getLocalizedString("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(queueMenuMouseListener = new QueueMenuMouseListener(d -> updateQueue(queueListModel)));
    JScrollPane queueListScroll = new JScrollPane(queueList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    for (String item : Utils.getConfigList("queue")) {
        queueListModel.addElement(item);
    }
    updateQueue();
    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(Utils.getLocalizedString("check.for.updates"));
    configUpdateLabel = new JLabel(Utils.getLocalizedString("current.version") + ": " + UpdateUtils.getThisJarVersion(), JLabel.RIGHT);
    configThreadsLabel = new JLabel(Utils.getLocalizedString("max.download.threads") + ":", JLabel.RIGHT);
    configTimeoutLabel = new JLabel(Utils.getLocalizedString("timeout.mill"), JLabel.RIGHT);
    configRetriesLabel = new JLabel(Utils.getLocalizedString("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(Utils.getLocalizedString("overwrite.existing.files"), "file.overwrite", false);
    configAutoupdateCheckbox = addNewCheckbox(Utils.getLocalizedString("auto.update"), "auto.update", true);
    configPlaySound = addNewCheckbox(Utils.getLocalizedString("sound.when.rip.completes"), "play.sound", false);
    configShowPopup = addNewCheckbox(Utils.getLocalizedString("notification.when.rip.starts"), "download.show_popup", false);
    configSaveOrderCheckbox = addNewCheckbox(Utils.getLocalizedString("preserve.order"), "download.save_order", true);
    configSaveLogs = addNewCheckbox(Utils.getLocalizedString("save.logs"), "log.save", false);
    configSaveURLsOnly = addNewCheckbox(Utils.getLocalizedString("save.urls.only"), "urls_only.save", false);
    configSaveAlbumTitles = addNewCheckbox(Utils.getLocalizedString("save.album.titles"), "album_titles.save", true);
    configClipboardAutorip = addNewCheckbox(Utils.getLocalizedString("autorip.from.clipboard"), "clipboard.autorip", false);
    configSaveDescriptions = addNewCheckbox(Utils.getLocalizedString("save.descriptions"), "descriptions.save", true);
    configPreferMp4 = addNewCheckbox(Utils.getLocalizedString("prefer.mp4.over.gif"), "prefer.mp4", false);
    configWindowPosition = addNewCheckbox(Utils.getLocalizedString("restore.window.position"), "window.position", true);
    configURLHistoryCheckbox = addNewCheckbox(Utils.getLocalizedString("remember.url.history"), "remember.url_history", true);
    configUrlFileChooserButton = new JButton(Utils.getLocalizedString("download.url.list"));
    configLogLevelCombobox = new JComboBox<>(new String[] { "Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug" });
    configSelectLangComboBox = new JComboBox<>(Utils.getSupportedLanguages());
    configSelectLangComboBox.setSelectedItem(Utils.getSelectedLanguage());
    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(Utils.getLocalizedString("select.save.dir") + "...");
    addItemToConfigGridBagConstraints(gbc, 0, configUpdateLabel, configUpdateButton);
    addItemToConfigGridBagConstraints(gbc, 1, configAutoupdateCheckbox, configLogLevelCombobox);
    addItemToConfigGridBagConstraints(gbc, 2, configThreadsLabel, configThreadsText);
    addItemToConfigGridBagConstraints(gbc, 3, configTimeoutLabel, configTimeoutText);
    addItemToConfigGridBagConstraints(gbc, 4, configRetriesLabel, configRetriesText);
    addItemToConfigGridBagConstraints(gbc, 5, configOverwriteCheckbox, configSaveOrderCheckbox);
    addItemToConfigGridBagConstraints(gbc, 6, configPlaySound, configSaveLogs);
    addItemToConfigGridBagConstraints(gbc, 7, configShowPopup, configSaveURLsOnly);
    addItemToConfigGridBagConstraints(gbc, 8, configClipboardAutorip, configSaveAlbumTitles);
    addItemToConfigGridBagConstraints(gbc, 9, configSaveDescriptions, configPreferMp4);
    addItemToConfigGridBagConstraints(gbc, 10, configWindowPosition, configURLHistoryCheckbox);
    addItemToConfigGridBagConstraints(gbc, 11, configSelectLangComboBox, configUrlFileChooserButton);
    addItemToConfigGridBagConstraints(gbc, 12, configSaveDirLabel, configSaveDirButton);
    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) JLabel(javax.swing.JLabel) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) BadLocationException(javax.swing.text.BadLocationException) MalformedURLException(java.net.MalformedURLException) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) JTable(javax.swing.JTable) AbstractTableModel(javax.swing.table.AbstractTableModel) JList(javax.swing.JList)

Aggregations

UnsupportedLookAndFeelException (javax.swing.UnsupportedLookAndFeelException)32 LookAndFeel (javax.swing.LookAndFeel)8 File (java.io.File)6 LookAndFeelInfo (javax.swing.UIManager.LookAndFeelInfo)6 Component (java.awt.Component)5 JFileChooser (javax.swing.JFileChooser)5 JFrame (javax.swing.JFrame)5 JDialog (javax.swing.JDialog)4 JPanel (javax.swing.JPanel)4 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)4 JLabel (javax.swing.JLabel)3 BorderLayout (java.awt.BorderLayout)2 Color (java.awt.Color)2 Dimension (java.awt.Dimension)2 FlowLayout (java.awt.FlowLayout)2 Font (java.awt.Font)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Preferences (java.util.prefs.Preferences)2 DefaultListModel (javax.swing.DefaultListModel)2