Search in sources :

Example 1 with LanguageCellRenderer

use of net.technicpack.ui.controls.lang.LanguageCellRenderer in project LauncherV3 by TechnicPack.

the class LoginFrame method initComponents.

/**
 * Generate & setup UI components for the frame
 */
private void initComponents() {
    setLayout(new GridBagLayout());
    // Close button
    JButton closeButton = new JButton();
    closeButton.setContentAreaFilled(false);
    closeButton.setBorder(BorderFactory.createEmptyBorder());
    closeButton.setIcon(resources.getIcon("close.png"));
    closeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    closeButton.addActionListener(e -> closeButtonClicked());
    closeButton.setFocusable(false);
    add(closeButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 0, 0, 7), 0, 0));
    // Logo at the top
    JLabel platformImage = new JLabel();
    platformImage.setIcon(resources.getIcon("platform_logo.png"));
    add(platformImage, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(30, 0, 0, 0), 0, 0));
    // Select account label
    selectLabel = new JLabel(resources.getString("login.select"));
    selectLabel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    selectLabel.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    add(selectLabel, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 20, 0, 20), 0, 0));
    // addAccounts = new JLabel(resources.getString("login.instructions"));
    // addAccounts.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    // addAccounts.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    // add(addAccounts, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    // 
    // visitBrowser = new JLabel(resources.getString("login.checkbrowser"));
    // visitBrowser.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    // visitBrowser.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    // add(visitBrowser,  new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    // Setup account select box
    nameSelect = new JComboBox<>();
    if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("mac")) {
        nameSelect.setUI(new MetalComboBoxUI());
    }
    nameSelect.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    nameSelect.setEditable(true);
    nameSelect.setBorder(new RoundBorder(LauncherFrame.COLOR_BUTTON_BLUE, 1, 10));
    nameSelect.setForeground(LauncherFrame.COLOR_BUTTON_BLUE);
    nameSelect.setBackground(LauncherFrame.COLOR_FORMELEMENT_INTERNAL);
    nameSelect.setVisible(false);
    UserCellRenderer userRenderer = new UserCellRenderer(resources, this.skinRepository);
    userRenderer.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    userRenderer.setSelectedBackgroundColor(LauncherFrame.COLOR_FORMELEMENT_INTERNAL);
    userRenderer.setSelectedForegroundColor(LauncherFrame.COLOR_BUTTON_BLUE);
    userRenderer.setUnselectedBackgroundColor(LauncherFrame.COLOR_CENTRAL_BACK_OPAQUE);
    userRenderer.setUnselectedForegroundColor(LauncherFrame.COLOR_BUTTON_BLUE);
    nameSelect.setRenderer(userRenderer);
    UserCellEditor userEditor = new UserCellEditor(resources.getFont(ResourceLoader.FONT_OPENSANS, 16), this.skinRepository, LauncherFrame.COLOR_BUTTON_BLUE);
    nameSelect.setEditor(userEditor);
    userEditor.addKeyListener(this);
    nameSelect.setUI(new SimpleButtonComboUI(new RoundedBorderFormatter(new RoundBorder(LauncherFrame.COLOR_BUTTON_BLUE, 1, 0)), resources, LauncherFrame.COLOR_SCROLL_TRACK, LauncherFrame.COLOR_SCROLL_THUMB));
    nameSelect.addActionListener(e -> setCurrentUser((IUserType) nameSelect.getSelectedItem()));
    add(nameSelect, new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 20, 0, 20), 4, 4));
    // Login button
    login = new RoundedButton(resources.getString("login.button"));
    login.setBorder(BorderFactory.createEmptyBorder(5, 17, 10, 17));
    login.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 18));
    login.setContentAreaFilled(false);
    login.setForeground(LauncherFrame.COLOR_BUTTON_BLUE);
    login.setHoverForeground(LauncherFrame.COLOR_BLUE);
    login.addActionListener(e -> login());
    add(login, new GridBagConstraints(0, 6, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(12, 20, 0, 20), 0, 0));
    // Microsoft login button
    addMicrosoft = new RoundedButton(resources.getString("login.addmicrosoft"));
    addMicrosoft.setBorder(BorderFactory.createEmptyBorder(5, 17, 10, 17));
    addMicrosoft.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14));
    addMicrosoft.setContentAreaFilled(false);
    addMicrosoft.setForeground(LauncherFrame.COLOR_BUTTON_BLUE);
    addMicrosoft.setHoverForeground(LauncherFrame.COLOR_BLUE);
    addMicrosoft.addActionListener(e -> addMicrosoftAccount());
    add(addMicrosoft, new GridBagConstraints(0, 7, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(50, 20, 0, 20), 0, 0));
    // Add mojang account button
    addMojang = new RoundedButton(resources.getString("login.addmojang"));
    addMojang.setBorder(BorderFactory.createEmptyBorder(5, 17, 10, 17));
    addMojang.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14));
    addMojang.setContentAreaFilled(false);
    addMojang.setForeground(LauncherFrame.COLOR_BUTTON_BLUE);
    addMojang.setHoverForeground(LauncherFrame.COLOR_BLUE);
    addMojang.addActionListener(e -> addMojangAccount());
    add(addMojang, new GridBagConstraints(0, 8, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(12, 20, 0, 20), 0, 0));
    // Mojang username label
    usernameLabel = new JLabel(resources.getString("login.username"));
    usernameLabel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    usernameLabel.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    add(usernameLabel, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 20, 0, 20), 0, 0));
    // Mojang username field
    username = new JTextField();
    username.setBorder(new RoundBorder(LauncherFrame.COLOR_BUTTON_BLUE, 1, 10));
    username.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    username.setBackground(LauncherFrame.COLOR_FORMELEMENT_INTERNAL);
    username.setForeground(LauncherFrame.COLOR_BUTTON_BLUE);
    username.setCaretColor(LauncherFrame.COLOR_BUTTON_BLUE);
    username.addKeyListener(this);
    add(username, new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 20, 0, 20), 4, 17));
    // Mojang password label
    passwordLabel = new JLabel(resources.getString("login.password"));
    passwordLabel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    passwordLabel.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    add(passwordLabel, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(12, 20, 0, 20), 0, 0));
    // Setup password box
    password = new JPasswordField();
    password.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    password.setBorder(new RoundBorder(LauncherFrame.COLOR_BUTTON_BLUE, 1, 10));
    password.setForeground(LauncherFrame.COLOR_BUTTON_BLUE);
    password.setBackground(LauncherFrame.COLOR_FORMELEMENT_INTERNAL);
    password.addKeyListener(this);
    password.setEchoChar('*');
    password.addActionListener(e -> login());
    password.setCaretColor(LauncherFrame.COLOR_BUTTON_BLUE);
    add(password, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 20, 0, 20), 4, 17));
    // Disable Mojang login elements
    usernameLabel.setVisible(false);
    username.setVisible(false);
    passwordLabel.setVisible(false);
    password.setVisible(false);
    // "Remember this account"
    Font rememberFont = resources.getFont(ResourceLoader.FONT_OPENSANS, 14);
    rememberAccount = new JCheckBox("<html><body style=\"color:#D0D0D0\">" + resources.getString("login.remember") + "</body></html>", false);
    rememberAccount.setFont(rememberFont);
    rememberAccount.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    rememberAccount.setOpaque(false);
    rememberAccount.setHorizontalTextPosition(SwingConstants.LEFT);
    rememberAccount.setHorizontalAlignment(SwingConstants.RIGHT);
    rememberAccount.setBorder(BorderFactory.createEmptyBorder());
    rememberAccount.setIconTextGap(6);
    rememberAccount.addKeyListener(this);
    rememberAccount.setSelectedIcon(resources.getIcon("checkbox_closed.png"));
    rememberAccount.setIcon(resources.getIcon("checkbox_open.png"));
    rememberAccount.addActionListener(e -> toggleRemember());
    rememberAccount.setFocusPainted(false);
    // add(rememberAccount, new GridBagConstraints(1,6,2,1,1.0,0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(24,20,0,20),0,0));
    add(Box.createVerticalGlue(), new GridBagConstraints(0, 8, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    JPanel linkPane = new JPanel();
    linkPane.setBackground(LauncherFrame.COLOR_SELECTOR_BACK);
    linkPane.setBorder(BorderFactory.createEmptyBorder(7, 0, 7, 0));
    linkPane.setLayout(new BoxLayout(linkPane, BoxLayout.LINE_AXIS));
    linkPane.add(Box.createHorizontalStrut(8));
    languages = new JComboBox();
    String defaultLocaleText = resources.getString("launcheroptions.language.default");
    if (!resources.isDefaultLocaleSupported()) {
        defaultLocaleText = defaultLocaleText.concat(" (" + resources.getString("launcheroptions.language.unavailable") + ")");
    }
    languages.addItem(new LanguageItem(ResourceLoader.DEFAULT_LOCALE, defaultLocaleText, resources));
    for (int i = 0; i < LauncherMain.supportedLanguages.length; i++) {
        languages.addItem(new LanguageItem(resources.getCodeFromLocale(LauncherMain.supportedLanguages[i]), LauncherMain.supportedLanguages[i].getDisplayName(LauncherMain.supportedLanguages[i]), resources.getVariant(LauncherMain.supportedLanguages[i])));
    }
    if (!settings.getLanguageCode().equalsIgnoreCase(ResourceLoader.DEFAULT_LOCALE)) {
        Locale loc = resources.getLocaleFromCode(settings.getLanguageCode());
        for (int i = 0; i < LauncherMain.supportedLanguages.length; i++) {
            if (loc.equals(LauncherMain.supportedLanguages[i])) {
                languages.setSelectedIndex(i + 1);
                break;
            }
        }
    }
    languages.setBorder(BorderFactory.createEmptyBorder());
    languages.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14));
    languages.setUI(new LanguageCellUI(resources, new RoundedBorderFormatter(new LineBorder(Color.black, 1)), LauncherFrame.COLOR_SCROLL_TRACK, LauncherFrame.COLOR_SCROLL_THUMB));
    languages.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    languages.setBackground(LauncherFrame.COLOR_SELECTOR_BACK);
    languages.setRenderer(new LanguageCellRenderer(resources, "globe.png", LauncherFrame.COLOR_SELECTOR_BACK, LauncherFrame.COLOR_WHITE_TEXT));
    languages.setEditable(false);
    languages.setFocusable(false);
    languages.addActionListener(e -> languageChanged());
    linkPane.add(languages);
    linkPane.add(Box.createHorizontalGlue());
    JButton termsLink = new JButton(resources.getString("login.terms"));
    termsLink.setContentAreaFilled(false);
    termsLink.setBorder(BorderFactory.createEmptyBorder());
    termsLink.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    termsLink.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14));
    termsLink.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    termsLink.addActionListener(e -> visitTerms());
    linkPane.add(termsLink);
    linkPane.add(Box.createHorizontalStrut(8));
    add(linkPane, new GridBagConstraints(0, 9, 3, 1, 1.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
}
Also used : Locale(java.util.Locale) RoundedButton(net.technicpack.ui.controls.RoundedButton) LineBorder(javax.swing.border.LineBorder) LanguageCellRenderer(net.technicpack.ui.controls.lang.LanguageCellRenderer) RoundedBorderFormatter(net.technicpack.ui.controls.list.popupformatters.RoundedBorderFormatter) LanguageCellUI(net.technicpack.ui.controls.lang.LanguageCellUI) MetalComboBoxUI(javax.swing.plaf.metal.MetalComboBoxUI) SimpleButtonComboUI(net.technicpack.ui.controls.list.SimpleButtonComboUI) IUserType(net.technicpack.launchercore.auth.IUserType) RoundBorder(net.technicpack.ui.controls.borders.RoundBorder) LanguageItem(net.technicpack.ui.listitems.LanguageItem)

Example 2 with LanguageCellRenderer

use of net.technicpack.ui.controls.lang.LanguageCellRenderer in project LauncherV3 by TechnicPack.

the class OptionsDialog method initControlValues.

private void initControlValues() {
    javaArgs.getDocument().removeDocumentListener(javaArgsListener);
    javaArgs.setText(settings.getJavaArgs());
    javaArgs.getDocument().addDocumentListener(javaArgsListener);
    wrapperCommand.getDocument().removeDocumentListener(wrapperCommandListener);
    wrapperCommand.setText(settings.getWrapperCommand());
    wrapperCommand.getDocument().addDocumentListener(wrapperCommandListener);
    installField.setText(settings.getTechnicRoot().getAbsolutePath());
    clientId.setText(settings.getClientId());
    for (ActionListener listener : showConsole.getActionListeners()) showConsole.removeActionListener(listener);
    showConsole.setSelected(settings.getShowConsole());
    showConsole.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeShowConsole();
        }
    });
    for (ActionListener listener : askFirstBox.getActionListeners()) askFirstBox.removeActionListener(listener);
    askFirstBox.setSelected(!settings.shouldAutoAcceptModpackRequirements());
    askFirstBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeAskFirst();
        }
    });
    for (ActionListener listener : useMojangJava.getActionListeners()) useMojangJava.removeActionListener(listener);
    useMojangJava.setSelected(settings.shouldUseMojangJava());
    useMojangJava.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeUseMojangJava();
        }
    });
    for (ActionListener listener : launchToModpacks.getActionListeners()) launchToModpacks.removeActionListener(listener);
    launchToModpacks.setSelected(settings.getLaunchToModpacks());
    launchToModpacks.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeLaunchToModpacks();
        }
    });
    for (ActionListener listener : versionSelect.getActionListeners()) versionSelect.removeActionListener(listener);
    versionSelect.removeAllItems();
    versionSelect.addItem(new DefaultVersionItem(javaVersions.getVersion(null, true), resources));
    IJavaVersion best64Bit = javaVersions.getBest64BitVersion();
    if (best64Bit != null)
        versionSelect.addItem(new Best64BitVersionItem(javaVersions.getVersion("64bit", true), resources));
    for (IJavaVersion version : javaVersions.getVersions()) {
        versionSelect.addItem(new JavaVersionItem(version, resources));
    }
    String settingsVersion = settings.getJavaVersion();
    boolean settingsBitness = settings.getJavaBitness();
    if (settingsVersion == null || settingsVersion.isEmpty() || settingsVersion.equals("default"))
        versionSelect.setSelectedIndex(0);
    else if (settingsVersion.equals("64bit"))
        versionSelect.setSelectedIndex(1);
    else {
        for (int i = 2; i < versionSelect.getItemCount(); i++) {
            if (((JavaVersionItem) versionSelect.getItemAt(i)).getVersionNumber().equals(settingsVersion) && ((JavaVersionItem) versionSelect.getItemAt(i)).is64Bit() == settingsBitness) {
                versionSelect.setSelectedIndex(i);
                break;
            }
        }
    }
    versionSelect.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeJavaVersion();
        }
    });
    rebuildMemoryList();
    for (ActionListener listener : streamSelect.getActionListeners()) {
        streamSelect.removeActionListener(listener);
    }
    streamSelect.removeAllItems();
    streamSelect.addItem(new StreamItem(resources.getString("launcheroptions.build.stable"), "stable"));
    streamSelect.addItem(new StreamItem(resources.getString("launcheroptions.build.beta"), "beta"));
    streamSelect.setSelectedIndex((settings.getBuildStream().equals("beta")) ? 1 : 0);
    streamSelect.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeStream();
        }
    });
    for (ActionListener listener : launchSelect.getActionListeners()) launchSelect.removeActionListener(listener);
    launchSelect.removeAllItems();
    launchSelect.addItem(new OnLaunchItem(resources.getString("launcheroptions.packlaunch.hide"), LaunchAction.HIDE));
    launchSelect.addItem(new OnLaunchItem(resources.getString("launcheroptions.packlaunch.close"), LaunchAction.CLOSE));
    launchSelect.addItem(new OnLaunchItem(resources.getString("launcheroptions.packlaunch.nothing"), LaunchAction.NOTHING));
    switch(settings.getLaunchAction()) {
        case HIDE:
            launchSelect.setSelectedIndex(0);
            break;
        case CLOSE:
            launchSelect.setSelectedIndex(1);
            break;
        case NOTHING:
            launchSelect.setSelectedIndex(2);
            break;
        default:
            launchSelect.setSelectedIndex(0);
    }
    launchSelect.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeLaunchAction();
        }
    });
    for (ActionListener listener : langSelect.getActionListeners()) langSelect.removeActionListener(listener);
    langSelect.removeAllItems();
    String defaultLocaleText = resources.getString("launcheroptions.language.default");
    if (!resources.isDefaultLocaleSupported()) {
        defaultLocaleText = defaultLocaleText.concat(" (" + resources.getString("launcheroptions.language.unavailable") + ")");
    }
    langSelect.setRenderer(new LanguageCellRenderer(resources, null, langSelect.getBackground(), langSelect.getForeground()));
    langSelect.addItem(new LanguageItem(ResourceLoader.DEFAULT_LOCALE, defaultLocaleText, resources));
    for (int i = 0; i < LauncherMain.supportedLanguages.length; i++) {
        langSelect.addItem(new LanguageItem(resources.getCodeFromLocale(LauncherMain.supportedLanguages[i]), LauncherMain.supportedLanguages[i].getDisplayName(LauncherMain.supportedLanguages[i]), resources.getVariant(LauncherMain.supportedLanguages[i])));
    }
    if (!settings.getLanguageCode().equalsIgnoreCase(ResourceLoader.DEFAULT_LOCALE)) {
        Locale loc = resources.getLocaleFromCode(settings.getLanguageCode());
        for (int i = 0; i < LauncherMain.supportedLanguages.length; i++) {
            if (loc.equals(LauncherMain.supportedLanguages[i])) {
                langSelect.setSelectedIndex(i + 1);
                break;
            }
        }
    }
    langSelect.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeLanguage();
        }
    });
    widthInput.getDocument().removeDocumentListener(dimensionListener);
    heightInput.getDocument().removeDocumentListener(dimensionListener);
    int width = settings.getCustomWidth();
    int height = settings.getCustomHeight();
    width = (width < 1) ? 800 : width;
    height = (height < 1) ? 600 : height;
    widthInput.setText(Integer.toString(width));
    heightInput.setText(Integer.toString(height));
    widthInput.getDocument().addDocumentListener(dimensionListener);
    heightInput.getDocument().addDocumentListener(dimensionListener);
    for (ActionListener listener : windowSelect.getActionListeners()) {
        windowSelect.removeActionListener(listener);
    }
    windowSelect.removeAllItems();
    windowSelect.addItem(resources.getString("launcheroptions.video.windowSize.default"));
    windowSelect.addItem(resources.getString("launcheroptions.video.windowSize.fullscreen"));
    windowSelect.addItem(resources.getString("launcheroptions.video.windowSize.custom"));
    switch(settings.getLaunchWindowType()) {
        case DEFAULT:
            windowSelect.setSelectedIndex(0);
            break;
        case FULLSCREEN:
            windowSelect.setSelectedIndex(1);
            break;
        case CUSTOM:
            windowSelect.setSelectedIndex(2);
            break;
    }
    windowSelect.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeWindowType();
        }
    });
    updateDimensionsEnabled();
    for (ActionListener listener : useStencil.getActionListeners()) {
        useStencil.removeActionListener(listener);
    }
    useStencil.removeAllItems();
    useStencil.addItem(resources.getString("launcheroptions.video.stencil.enabled"));
    useStencil.addItem(resources.getString("launcheroptions.video.stencil.disabled"));
    if (settings.shouldUseStencilBuffer())
        useStencil.setSelectedIndex(0);
    else
        useStencil.setSelectedIndex(1);
    useStencil.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeEnableStencil();
        }
    });
}
Also used : Locale(java.util.Locale) StreamItem(net.technicpack.launcher.ui.listitems.StreamItem) ActionEvent(java.awt.event.ActionEvent) DefaultVersionItem(net.technicpack.ui.listitems.javaversion.DefaultVersionItem) Best64BitVersionItem(net.technicpack.ui.listitems.javaversion.Best64BitVersionItem) JavaVersionItem(net.technicpack.ui.listitems.javaversion.JavaVersionItem) IJavaVersion(net.technicpack.launchercore.launch.java.IJavaVersion) OnLaunchItem(net.technicpack.launcher.ui.listitems.OnLaunchItem) LanguageCellRenderer(net.technicpack.ui.controls.lang.LanguageCellRenderer) ActionListener(java.awt.event.ActionListener) LanguageItem(net.technicpack.ui.listitems.LanguageItem)

Example 3 with LanguageCellRenderer

use of net.technicpack.ui.controls.lang.LanguageCellRenderer in project LauncherV3 by TechnicPack.

the class InstallerFrame method setupPortableMode.

private void setupPortableMode(JPanel panel) {
    panel.setLayout(new GridBagLayout());
    JLabel portableSpiel = new JLabel("<html><body align=\"left\" style='margin-right:10px;'>" + resources.getString("launcher.installer.portablespiel") + "</body></html>");
    portableSpiel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    portableSpiel.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    portableSpiel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.add(portableSpiel, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(9, 8, 9, 3), 0, 0));
    panel.add(Box.createGlue(), new GridBagConstraints(0, 1, 3, 1, 1.0, 0.7, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    JLabel installFolderLabel = new JLabel(resources.getString("launcher.installer.folder"));
    installFolderLabel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    installFolderLabel.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    panel.add(installFolderLabel, new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 24, 0, 8), 0, 0));
    String installDir = "";
    if (settings.isPortable())
        installDir = settings.getTechnicRoot().getAbsolutePath();
    portableInstallDir = new JTextField(installDir);
    portableInstallDir.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    portableInstallDir.setForeground(LauncherFrame.COLOR_BLUE);
    portableInstallDir.setBackground(LauncherFrame.COLOR_FORMELEMENT_INTERNAL);
    portableInstallDir.setHighlighter(null);
    portableInstallDir.setEditable(false);
    portableInstallDir.setCursor(null);
    portableInstallDir.setBorder(new RoundBorder(LauncherFrame.COLOR_BUTTON_BLUE, 1, 8));
    panel.add(portableInstallDir, new GridBagConstraints(1, 2, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 0, 5), 0, 16));
    RoundedButton selectInstall = new RoundedButton(resources.getString("launcher.installer.select"));
    selectInstall.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    selectInstall.setContentAreaFilled(false);
    selectInstall.setForeground(LauncherFrame.COLOR_BUTTON_BLUE);
    selectInstall.setHoverForeground(LauncherFrame.COLOR_BLUE);
    selectInstall.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectPortable();
        }
    });
    panel.add(selectInstall, new GridBagConstraints(2, 2, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 0, 16), 0, 0));
    panel.add(Box.createGlue(), new GridBagConstraints(0, 3, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    String defaultLocaleText = resources.getString("launcheroptions.language.default");
    if (!resources.isDefaultLocaleSupported()) {
        defaultLocaleText = defaultLocaleText.concat(" (" + resources.getString("launcheroptions.language.unavailable") + ")");
    }
    portableLanguages = new JComboBox();
    portableLanguages.addItem(new LanguageItem(ResourceLoader.DEFAULT_LOCALE, defaultLocaleText, resources));
    for (int i = 0; i < LauncherMain.supportedLanguages.length; i++) {
        portableLanguages.addItem(new LanguageItem(resources.getCodeFromLocale(LauncherMain.supportedLanguages[i]), LauncherMain.supportedLanguages[i].getDisplayName(LauncherMain.supportedLanguages[i]), resources.getVariant(LauncherMain.supportedLanguages[i])));
    }
    if (!settings.getLanguageCode().equalsIgnoreCase(ResourceLoader.DEFAULT_LOCALE)) {
        Locale loc = resources.getLocaleFromCode(settings.getLanguageCode());
        for (int i = 0; i < LauncherMain.supportedLanguages.length; i++) {
            if (loc.equals(LauncherMain.supportedLanguages[i])) {
                portableLanguages.setSelectedIndex(i + 1);
                break;
            }
        }
    }
    portableLanguages.setBorder(new RoundBorder(LauncherFrame.COLOR_SCROLL_THUMB, 1, 10));
    portableLanguages.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14));
    portableLanguages.setUI(new LanguageCellUI(resources, new RoundedBorderFormatter(new LineBorder(Color.black, 1)), LauncherFrame.COLOR_SCROLL_TRACK, LauncherFrame.COLOR_SCROLL_THUMB));
    portableLanguages.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    portableLanguages.setBackground(LauncherFrame.COLOR_SELECTOR_BACK);
    portableLanguages.setRenderer(new LanguageCellRenderer(resources, "globe.png", LauncherFrame.COLOR_SELECTOR_BACK, LauncherFrame.COLOR_WHITE_TEXT));
    portableLanguages.setEditable(false);
    portableLanguages.setFocusable(false);
    portableLanguages.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            portableLanguageChanged();
        }
    });
    panel.add(portableLanguages, new GridBagConstraints(0, 4, 1, 0, 0, 0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 8, 8, 0), 0, 0));
    portableInstallButton = new RoundedButton(resources.getString("launcher.installer.install"));
    portableInstallButton.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    portableInstallButton.setContentAreaFilled(false);
    portableInstallButton.setForeground(LauncherFrame.COLOR_GREY_TEXT);
    portableInstallButton.setHoverForeground(LauncherFrame.COLOR_BLUE);
    portableInstallButton.setBorder(BorderFactory.createEmptyBorder(5, 17, 10, 17));
    portableInstallButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            portableInstall();
        }
    });
    portableInstallButton.setEnabled(false);
    if (!installDir.equals("")) {
        portableInstallButton.setForeground(LauncherFrame.COLOR_BUTTON_BLUE);
        portableInstallButton.setEnabled(true);
    }
    panel.add(portableInstallButton, new GridBagConstraints(1, 4, 2, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 8, 8), 0, 0));
}
Also used : Locale(java.util.Locale) RoundedButton(net.technicpack.ui.controls.RoundedButton) ActionEvent(java.awt.event.ActionEvent) LineBorder(javax.swing.border.LineBorder) LanguageCellRenderer(net.technicpack.ui.controls.lang.LanguageCellRenderer) ActionListener(java.awt.event.ActionListener) LanguageCellUI(net.technicpack.ui.controls.lang.LanguageCellUI) RoundedBorderFormatter(net.technicpack.ui.controls.list.popupformatters.RoundedBorderFormatter) RoundBorder(net.technicpack.ui.controls.borders.RoundBorder) LanguageItem(net.technicpack.ui.listitems.LanguageItem)

Example 4 with LanguageCellRenderer

use of net.technicpack.ui.controls.lang.LanguageCellRenderer in project LauncherV3 by TechnicPack.

the class InstallerFrame method setupStandardInstall.

private void setupStandardInstall(JPanel panel) {
    panel.setLayout(new GridBagLayout());
    JLabel standardSpiel = new JLabel("<html><body align=\"left\" style='margin-right:10px;'>" + resources.getString("launcher.installer.standardspiel") + "</body></html>");
    standardSpiel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    standardSpiel.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    standardSpiel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.add(standardSpiel, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(9, 0, 0, 3), 0, 0));
    panel.add(Box.createGlue(), new GridBagConstraints(0, 1, 3, 1, 1.0, 0.7, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    standardDefaultDirectory = new JCheckBox(resources.getString("launcher.installer.default"));
    standardDefaultDirectory.setOpaque(false);
    standardDefaultDirectory.setHorizontalAlignment(SwingConstants.RIGHT);
    standardDefaultDirectory.setBorder(BorderFactory.createEmptyBorder());
    standardDefaultDirectory.setIconTextGap(0);
    standardDefaultDirectory.setSelectedIcon(resources.getIcon("checkbox_closed.png"));
    standardDefaultDirectory.setIcon(resources.getIcon("checkbox_open.png"));
    standardDefaultDirectory.setFocusPainted(false);
    standardDefaultDirectory.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    standardDefaultDirectory.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    standardDefaultDirectory.setIconTextGap(6);
    standardDefaultDirectory.setSelected(settings.isPortable() || settings.getTechnicRoot().getAbsolutePath().equals(OperatingSystem.getOperatingSystem().getUserDirectoryForApp("technic").getAbsolutePath()));
    standardDefaultDirectory.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            useDefaultDirectoryChanged();
        }
    });
    panel.add(standardDefaultDirectory, new GridBagConstraints(0, 2, 3, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 24, 12, 0), 0, 0));
    JLabel installFolderLabel = new JLabel(resources.getString("launcher.installer.folder"));
    installFolderLabel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    installFolderLabel.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    panel.add(installFolderLabel, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 24, 0, 8), 0, 0));
    String installDir = OperatingSystem.getOperatingSystem().getUserDirectoryForApp("technic").getAbsolutePath();
    if (!settings.isPortable())
        installDir = settings.getTechnicRoot().getAbsolutePath();
    standardInstallDir = new JTextField(installDir);
    standardInstallDir.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    standardInstallDir.setBackground(LauncherFrame.COLOR_FORMELEMENT_INTERNAL);
    standardInstallDir.setHighlighter(null);
    standardInstallDir.setEditable(false);
    standardInstallDir.setCursor(null);
    panel.add(standardInstallDir, new GridBagConstraints(1, 3, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 0, 5), 0, 16));
    standardSelectButton = new RoundedButton(resources.getString("launcher.installer.select"));
    standardSelectButton.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    standardSelectButton.setContentAreaFilled(false);
    standardSelectButton.setHoverForeground(LauncherFrame.COLOR_BLUE);
    standardSelectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectStandard();
        }
    });
    panel.add(standardSelectButton, new GridBagConstraints(2, 3, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 0, 16), 0, 0));
    useDefaultDirectoryChanged();
    panel.add(Box.createGlue(), new GridBagConstraints(0, 4, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    String defaultLocaleText = resources.getString("launcheroptions.language.default");
    if (!resources.isDefaultLocaleSupported()) {
        defaultLocaleText = defaultLocaleText.concat(" (" + resources.getString("launcheroptions.language.unavailable") + ")");
    }
    standardLanguages = new JComboBox();
    standardLanguages.addItem(new LanguageItem(ResourceLoader.DEFAULT_LOCALE, defaultLocaleText, resources));
    for (int i = 0; i < LauncherMain.supportedLanguages.length; i++) {
        standardLanguages.addItem(new LanguageItem(resources.getCodeFromLocale(LauncherMain.supportedLanguages[i]), LauncherMain.supportedLanguages[i].getDisplayName(LauncherMain.supportedLanguages[i]), resources.getVariant(LauncherMain.supportedLanguages[i])));
    }
    if (!settings.getLanguageCode().equalsIgnoreCase(ResourceLoader.DEFAULT_LOCALE)) {
        Locale loc = resources.getLocaleFromCode(settings.getLanguageCode());
        for (int i = 0; i < LauncherMain.supportedLanguages.length; i++) {
            if (loc.equals(LauncherMain.supportedLanguages[i])) {
                standardLanguages.setSelectedIndex(i + 1);
                break;
            }
        }
    }
    standardLanguages.setBorder(new RoundBorder(LauncherFrame.COLOR_SCROLL_THUMB, 1, 10));
    standardLanguages.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14));
    standardLanguages.setUI(new LanguageCellUI(resources, new RoundedBorderFormatter(new LineBorder(Color.black, 1)), LauncherFrame.COLOR_SCROLL_TRACK, LauncherFrame.COLOR_SCROLL_THUMB));
    standardLanguages.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    standardLanguages.setBackground(LauncherFrame.COLOR_SELECTOR_BACK);
    standardLanguages.setRenderer(new LanguageCellRenderer(resources, "globe.png", LauncherFrame.COLOR_SELECTOR_BACK, LauncherFrame.COLOR_WHITE_TEXT));
    standardLanguages.setEditable(false);
    standardLanguages.setFocusable(false);
    standardLanguages.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            standardLanguageChanged();
        }
    });
    panel.add(standardLanguages, new GridBagConstraints(0, 5, 1, 0, 0, 0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 8, 8, 0), 0, 0));
    RoundedButton install = new RoundedButton(resources.getString("launcher.installer.install"));
    install.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16));
    install.setContentAreaFilled(false);
    install.setForeground(LauncherFrame.COLOR_BUTTON_BLUE);
    install.setHoverForeground(LauncherFrame.COLOR_BLUE);
    install.setBorder(BorderFactory.createEmptyBorder(5, 17, 10, 17));
    install.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            standardInstall();
        }
    });
    panel.add(install, new GridBagConstraints(1, 5, 2, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 8, 8), 0, 0));
}
Also used : Locale(java.util.Locale) RoundedButton(net.technicpack.ui.controls.RoundedButton) ActionEvent(java.awt.event.ActionEvent) LineBorder(javax.swing.border.LineBorder) LanguageCellRenderer(net.technicpack.ui.controls.lang.LanguageCellRenderer) ActionListener(java.awt.event.ActionListener) LanguageCellUI(net.technicpack.ui.controls.lang.LanguageCellUI) RoundedBorderFormatter(net.technicpack.ui.controls.list.popupformatters.RoundedBorderFormatter) RoundBorder(net.technicpack.ui.controls.borders.RoundBorder) LanguageItem(net.technicpack.ui.listitems.LanguageItem)

Aggregations

Locale (java.util.Locale)4 LanguageCellRenderer (net.technicpack.ui.controls.lang.LanguageCellRenderer)4 LanguageItem (net.technicpack.ui.listitems.LanguageItem)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 LineBorder (javax.swing.border.LineBorder)3 RoundedButton (net.technicpack.ui.controls.RoundedButton)3 RoundBorder (net.technicpack.ui.controls.borders.RoundBorder)3 LanguageCellUI (net.technicpack.ui.controls.lang.LanguageCellUI)3 RoundedBorderFormatter (net.technicpack.ui.controls.list.popupformatters.RoundedBorderFormatter)3 MetalComboBoxUI (javax.swing.plaf.metal.MetalComboBoxUI)1 OnLaunchItem (net.technicpack.launcher.ui.listitems.OnLaunchItem)1 StreamItem (net.technicpack.launcher.ui.listitems.StreamItem)1 IUserType (net.technicpack.launchercore.auth.IUserType)1 IJavaVersion (net.technicpack.launchercore.launch.java.IJavaVersion)1 SimpleButtonComboUI (net.technicpack.ui.controls.list.SimpleButtonComboUI)1 Best64BitVersionItem (net.technicpack.ui.listitems.javaversion.Best64BitVersionItem)1 DefaultVersionItem (net.technicpack.ui.listitems.javaversion.DefaultVersionItem)1 JavaVersionItem (net.technicpack.ui.listitems.javaversion.JavaVersionItem)1