Search in sources :

Example 1 with NewsInfoPanel

use of net.technicpack.launcher.ui.components.news.NewsInfoPanel in project LauncherV3 by TechnicPack.

the class LauncherFrame method initComponents.

// ///////////////////////////////////////////////
// End Action responses
// ///////////////////////////////////////////////
private void initComponents() {
    BorderLayout layout = new BorderLayout();
    getRootPane().getContentPane().setLayout(layout);
    // ///////////////////////////////////////////////////////////
    // HEADER
    // ///////////////////////////////////////////////////////////
    JPanel header = new JPanel();
    header.setLayout(new BoxLayout(header, BoxLayout.LINE_AXIS));
    header.setBackground(COLOR_BLUE);
    header.setForeground(COLOR_WHITE_TEXT);
    header.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 10));
    getRootPane().getContentPane().add(header, BorderLayout.PAGE_START);
    ImageIcon headerIcon = resources.getIcon("platform_icon_title.png");
    JButton headerLabel = new JButton(headerIcon);
    headerLabel.setBorder(BorderFactory.createEmptyBorder(5, 8, 5, 0));
    headerLabel.setContentAreaFilled(false);
    headerLabel.setFocusPainted(false);
    headerLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    headerLabel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DesktopUtils.browseUrl("https://www.technicpack.net/");
        }
    });
    header.add(headerLabel);
    header.add(Box.createRigidArea(new Dimension(6, 0)));
    ActionListener tabListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectTab(e.getActionCommand());
        }
    };
    discoverTab = new HeaderTab(resources.getString("launcher.title.discover"), resources);
    header.add(discoverTab);
    discoverTab.setActionCommand(TAB_DISCOVER);
    discoverTab.addActionListener(tabListener);
    modpacksTab = new HeaderTab(resources.getString("launcher.title.modpacks"), resources);
    modpacksTab.setIsActive(true);
    modpacksTab.setHorizontalTextPosition(SwingConstants.LEADING);
    modpacksTab.addActionListener(tabListener);
    modpacksTab.setActionCommand(TAB_MODPACKS);
    header.add(modpacksTab);
    newsTab = new HeaderTab(resources.getString("launcher.title.news"), resources);
    newsTab.setLayout(null);
    newsTab.addActionListener(tabListener);
    newsTab.setActionCommand(TAB_NEWS);
    header.add(newsTab);
    CountCircle newsCircle = new CountCircle();
    newsCircle.setBackground(COLOR_RED);
    newsCircle.setForeground(COLOR_WHITE_TEXT);
    newsCircle.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16, Font.BOLD));
    newsTab.add(newsCircle);
    newsCircle.setBounds(10, 17, 25, 25);
    header.add(Box.createHorizontalGlue());
    JPanel rightHeaderPanel = new JPanel();
    rightHeaderPanel.setOpaque(false);
    rightHeaderPanel.setLayout(new BoxLayout(rightHeaderPanel, BoxLayout.PAGE_AXIS));
    rightHeaderPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    JPanel windowGadgetPanel = new JPanel();
    windowGadgetPanel.setOpaque(false);
    windowGadgetPanel.setLayout(new BoxLayout(windowGadgetPanel, BoxLayout.LINE_AXIS));
    windowGadgetPanel.setAlignmentX(RIGHT_ALIGNMENT);
    ImageIcon minimizeIcon = resources.getIcon("minimize.png");
    JButton minimizeButton = new JButton(minimizeIcon);
    minimizeButton.setBorder(BorderFactory.createEmptyBorder());
    minimizeButton.setContentAreaFilled(false);
    minimizeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
    minimizeButton.setFocusable(false);
    minimizeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            minimizeWindow();
        }
    });
    windowGadgetPanel.add(minimizeButton);
    ImageIcon closeIcon = resources.getIcon("close.png");
    JButton closeButton = new JButton(closeIcon);
    closeButton.setBorder(BorderFactory.createEmptyBorder());
    closeButton.setContentAreaFilled(false);
    closeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            closeWindow();
        }
    });
    closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
    closeButton.setFocusable(false);
    windowGadgetPanel.add(closeButton);
    rightHeaderPanel.add(windowGadgetPanel);
    rightHeaderPanel.add(Box.createVerticalGlue());
    JButton launcherOptionsLabel = new JButton(resources.getString("launcher.title.options"));
    launcherOptionsLabel.setIcon(resources.getIcon("options_cog.png"));
    launcherOptionsLabel.setFont(resources.getFont(ResourceLoader.FONT_RALEWAY, 14));
    launcherOptionsLabel.setForeground(COLOR_WHITE_TEXT);
    launcherOptionsLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    launcherOptionsLabel.setHorizontalTextPosition(SwingConstants.LEADING);
    launcherOptionsLabel.setAlignmentX(RIGHT_ALIGNMENT);
    launcherOptionsLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    launcherOptionsLabel.setBorder(BorderFactory.createEmptyBorder());
    launcherOptionsLabel.setContentAreaFilled(false);
    launcherOptionsLabel.setFocusPainted(false);
    launcherOptionsLabel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            openLauncherOptions();
        }
    });
    rightHeaderPanel.add(launcherOptionsLabel);
    header.add(rightHeaderPanel);
    // ///////////////////////////////////////////////////////////
    // CENTRAL AREA
    // ///////////////////////////////////////////////////////////
    centralPanel = new TintablePanel();
    centralPanel.setBackground(COLOR_CHARCOAL);
    centralPanel.setForeground(COLOR_WHITE_TEXT);
    centralPanel.setTintColor(COLOR_CENTRAL_BACK);
    getRootPane().getContentPane().add(centralPanel, BorderLayout.CENTER);
    centralPanel.setLayout(new BorderLayout());
    modpackPanel = new ModpackInfoPanel(resources, iconRepo, logoRepo, backgroundRepo, avatarRepo, discordApi, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            openModpackOptions((ModpackModel) e.getSource());
        }
    }, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshModpackOptions((ModpackModel) e.getSource());
        }
    });
    modpackSelector.setInfoPanel(modpackPanel);
    modpackSelector.setLauncherFrame(this);
    playButton = modpackPanel.getPlayButton();
    playButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof ModpackModel) {
                setupPlayButtonText((ModpackModel) e.getSource(), userModel.getCurrentUser());
            } else if (installer.isCurrentlyRunning()) {
                installer.cancel();
                setupPlayButtonText(modpackSelector.getSelectedPack(), userModel.getCurrentUser());
            } else {
                launchModpack();
            }
        }
    });
    modpackPanel.getDeleteButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(LauncherFrame.this, resources.getString("modpackoptions.delete.confirmtext"), resources.getString("modpackoptions.delete.confirmtitle"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                modpackSelector.getSelectedPack().delete();
                modpackSelector.forceRefresh();
            }
        }
    });
    infoSwap = new JPanel();
    infoLayout = new CardLayout();
    infoSwap.setLayout(infoLayout);
    infoSwap.setOpaque(false);
    newsInfoPanel = new NewsInfoPanel(resources, avatarRepo);
    infoSwap.add(discoverInfoPanel, "discover");
    JPanel newsHost = new JPanel();
    infoSwap.add(newsHost, "news");
    JPanel modpackHost = new JPanel();
    infoSwap.add(modpackHost, "modpacks");
    centralPanel.add(infoSwap, BorderLayout.CENTER);
    newsSelector = new NewsSelector(resources, newsInfoPanel, platformApi, avatarRepo, newsCircle, settings);
    newsHost.setLayout(new BorderLayout());
    newsHost.add(newsInfoPanel, BorderLayout.CENTER);
    newsHost.add(newsSelector, BorderLayout.WEST);
    modpackHost.setLayout(new BorderLayout());
    modpackHost.add(modpackPanel, BorderLayout.CENTER);
    modpackHost.add(modpackSelector, BorderLayout.WEST);
    footer = new TintablePanel();
    footer.setTintColor(COLOR_CENTRAL_BACK);
    footer.setBackground(COLOR_FOOTER);
    footer.setLayout(new BoxLayout(footer, BoxLayout.LINE_AXIS));
    footer.setForeground(COLOR_WHITE_TEXT);
    footer.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 12));
    userWidget = new UserWidget(resources, skinRepository);
    userWidget.setMaximumSize(userWidget.getPreferredSize());
    footer.add(userWidget);
    JLabel dashText = new JLabel("| ");
    dashText.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    dashText.setFont(resources.getFont(ResourceLoader.FONT_RALEWAY, 15));
    footer.add(dashText);
    JButton logout = new JButton(resources.getString("launcher.user.logout"));
    logout.setBorder(BorderFactory.createEmptyBorder());
    logout.setContentAreaFilled(false);
    logout.setFocusable(false);
    logout.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    logout.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    logout.setFont(resources.getFont(ResourceLoader.FONT_RALEWAY, 15));
    logout.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            logout();
        }
    });
    footer.add(logout);
    installProgress = new ProgressBar();
    installProgress.setForeground(Color.white);
    installProgress.setBackground(LauncherFrame.COLOR_GREEN);
    installProgress.setBorder(BorderFactory.createEmptyBorder(5, 45, 4, 45));
    installProgress.setIcon(resources.getIcon("download_icon.png"));
    installProgress.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 12));
    installProgress.setVisible(false);
    footer.add(installProgress);
    installProgressPlaceholder = Box.createHorizontalGlue();
    footer.add(installProgressPlaceholder);
    JButton buildCtrl = new JButton(resources.getIcon("akliz-logo.png"));
    buildCtrl.setBorder(BorderFactory.createEmptyBorder());
    buildCtrl.setContentAreaFilled(false);
    buildCtrl.setHorizontalTextPosition(SwingConstants.RIGHT);
    buildCtrl.setHorizontalAlignment(SwingConstants.RIGHT);
    buildCtrl.setFocusable(false);
    buildCtrl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    buildCtrl.addActionListener(e -> DesktopUtils.browseUrl("https://www.akliz.net/technic"));
    footer.add(buildCtrl);
    getRootPane().getContentPane().add(footer, BorderLayout.PAGE_END);
    if (resources.hasResource("teaser.png")) {
        getRootPane().setGlassPane(new SplatPane(modpacksTab, resources.getIcon("teaser.png"), JLabel.SOUTH, 5, 0));
        getRootPane().getGlassPane().setVisible(true);
    }
}
Also used : CountCircle(net.technicpack.ui.controls.feeds.CountCircle) SplatPane(net.technicpack.ui.controls.SplatPane) NewsInfoPanel(net.technicpack.launcher.ui.components.news.NewsInfoPanel) NewsSelector(net.technicpack.launcher.ui.components.news.NewsSelector) ModpackInfoPanel(net.technicpack.launcher.ui.components.modpacks.ModpackInfoPanel) ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) TintablePanel(net.technicpack.ui.controls.TintablePanel) ProgressBar(net.technicpack.ui.controls.installation.ProgressBar)

Aggregations

ModpackInfoPanel (net.technicpack.launcher.ui.components.modpacks.ModpackInfoPanel)1 NewsInfoPanel (net.technicpack.launcher.ui.components.news.NewsInfoPanel)1 NewsSelector (net.technicpack.launcher.ui.components.news.NewsSelector)1 ModpackModel (net.technicpack.launchercore.modpacks.ModpackModel)1 SplatPane (net.technicpack.ui.controls.SplatPane)1 TintablePanel (net.technicpack.ui.controls.TintablePanel)1 CountCircle (net.technicpack.ui.controls.feeds.CountCircle)1 ProgressBar (net.technicpack.ui.controls.installation.ProgressBar)1