Search in sources :

Example 1 with JTextFieldPlaceholder

use of com.jsql.view.swing.text.JTextFieldPlaceholder in project jsql-injection by ron190.

the class Menubar method switchLocale.

public void switchLocale(Locale oldLocale, Locale newLocale, boolean isStartup) {
    I18n.setLocaleDefault(ResourceBundle.getBundle("com.jsql.i18n.jsql", newLocale));
    JTableHeader header = MediatorGui.panelConsoles().getNetworkTable().getTableHeader();
    TableColumnModel colMod = header.getColumnModel();
    if (newLocale.getLanguage() == new Locale("zh").getLanguage()) {
        StyleConstants.setFontFamily(SwingAppender.ERROR, HelperUi.FONT_NAME_UBUNTU_REGULAR);
        StyleConstants.setFontFamily(SwingAppender.WARN, HelperUi.FONT_NAME_UBUNTU_REGULAR);
        StyleConstants.setFontFamily(SwingAppender.INFO, HelperUi.FONT_NAME_UBUNTU_REGULAR);
        StyleConstants.setFontFamily(SwingAppender.DEBUG, HelperUi.FONT_NAME_UBUNTU_REGULAR);
        StyleConstants.setFontFamily(SwingAppender.TRACE, HelperUi.FONT_NAME_UBUNTU_REGULAR);
        StyleConstants.setFontFamily(SwingAppender.ALL, HelperUi.FONT_NAME_UBUNTU_REGULAR);
        MediatorGui.managerBruteForce().getResult().setFont(HelperUi.FONT_UBUNTU_REGULAR);
        colMod.getColumn(0).setHeaderValue(I18nView.valueByKey("NETWORK_TAB_METHOD_COLUMN"));
        colMod.getColumn(1).setHeaderValue(I18nView.valueByKey("NETWORK_TAB_URL_COLUMN"));
        colMod.getColumn(2).setHeaderValue(I18nView.valueByKey("NETWORK_TAB_SIZE_COLUMN"));
        colMod.getColumn(3).setHeaderValue(I18nView.valueByKey("NETWORK_TAB_TYPE_COLUMN"));
    } else {
        StyleConstants.setFontFamily(SwingAppender.ERROR, HelperUi.FONT_NAME_UBUNTU_MONO);
        StyleConstants.setFontFamily(SwingAppender.WARN, HelperUi.FONT_NAME_UBUNTU_MONO);
        StyleConstants.setFontFamily(SwingAppender.INFO, HelperUi.FONT_NAME_UBUNTU_MONO);
        StyleConstants.setFontFamily(SwingAppender.DEBUG, HelperUi.FONT_NAME_UBUNTU_MONO);
        StyleConstants.setFontFamily(SwingAppender.TRACE, HelperUi.FONT_NAME_UBUNTU_MONO);
        StyleConstants.setFontFamily(SwingAppender.ALL, HelperUi.FONT_NAME_UBUNTU_MONO);
        MediatorGui.managerBruteForce().getResult().setFont(HelperUi.FONT_UBUNTU_MONO);
        colMod.getColumn(0).setHeaderValue(I18n.valueByKey("NETWORK_TAB_METHOD_COLUMN"));
        colMod.getColumn(1).setHeaderValue(I18n.valueByKey("NETWORK_TAB_URL_COLUMN"));
        colMod.getColumn(2).setHeaderValue(I18n.valueByKey("NETWORK_TAB_SIZE_COLUMN"));
        colMod.getColumn(3).setHeaderValue(I18n.valueByKey("NETWORK_TAB_TYPE_COLUMN"));
    }
    header.repaint();
    for (String key : I18nView.keys()) {
        for (Object componentSwing : I18nView.componentsByKey(key)) {
            Class<?> classComponent = componentSwing.getClass();
            try {
                if (componentSwing instanceof JTextFieldPlaceholder) {
                    Method setPlaceholderText = classComponent.getMethod("setPlaceholderText", new Class<?>[] { String.class });
                    setPlaceholderText.invoke(componentSwing, I18n.valueByKey(key));
                } else {
                    Method methodSetText = classComponent.getMethod("setText", new Class<?>[] { String.class });
                    methodSetText.setAccessible(true);
                    if (newLocale.getLanguage() == new Locale("zh").getLanguage()) {
                        methodSetText.invoke(componentSwing, I18nView.valueByKey(key));
                    } else {
                        methodSetText.invoke(componentSwing, I18n.valueByKey(key));
                    }
                }
            } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                LOGGER.error("Reflection for " + key + " failed while switching locale", e);
            }
        }
    }
    ComponentOrientation componentOrientation = ComponentOrientation.getOrientation(I18n.getLocaleDefault());
    MediatorGui.frame().applyComponentOrientation(componentOrientation);
    this.itemArabic.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    this.itemEnglish.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemChinese.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemRussian.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemFrench.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemCzech.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemDutch.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemGerman.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemRomanian.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemTurkish.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIndonesian.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemItalian.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemSpanish.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemPortuguese.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemPolish.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoArabic.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    this.itemIntoHindi.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoRussia.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoChina.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoFrench.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoTurkish.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoCzech.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoGerman.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoDutch.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoIndonesian.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoItalian.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoSpanish.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoPortuguese.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoPolish.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoKorean.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoJapanese.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoTamil.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.itemIntoOther.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    if (ComponentOrientation.getOrientation(oldLocale) != ComponentOrientation.getOrientation(newLocale)) {
        Component c1 = MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().getLeftComponent();
        Component c2 = MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().getRightComponent();
        MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().setLeftComponent(null);
        MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().setRightComponent(null);
        MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().setLeftComponent(c2);
        MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().setRightComponent(c1);
        if (isStartup) {
            MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().setDividerLocation(MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().getDividerLocation());
        } else {
            MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().setDividerLocation(MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().getWidth() - MediatorGui.frame().getSplitHorizontalTopBottom().getSplitVerticalLeftRight().getDividerLocation());
        }
    }
    MediatorGui.tabResults().setComponentOrientation(ComponentOrientation.getOrientation(newLocale));
    // I18n of tree empty node
    if (MediatorGui.treeDatabase().isRootVisible()) {
        DefaultTreeModel model = (DefaultTreeModel) MediatorGui.managerDatabase().getTree().getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        model.reload(root);
        MediatorGui.managerDatabase().getTree().revalidate();
    }
    // Fix glitches on Linux
    MediatorGui.frame().revalidate();
}
Also used : Locale(java.util.Locale) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel) ComponentOrientation(java.awt.ComponentOrientation) Method(java.lang.reflect.Method) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) InvocationTargetException(java.lang.reflect.InvocationTargetException) JTextFieldPlaceholder(com.jsql.view.swing.text.JTextFieldPlaceholder) Component(java.awt.Component)

Aggregations

JTextFieldPlaceholder (com.jsql.view.swing.text.JTextFieldPlaceholder)1 Component (java.awt.Component)1 ComponentOrientation (java.awt.ComponentOrientation)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Locale (java.util.Locale)1 JTableHeader (javax.swing.table.JTableHeader)1 TableColumnModel (javax.swing.table.TableColumnModel)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1