Search in sources :

Example 6 with ComponentOrientation

use of java.awt.ComponentOrientation in project UniversalMediaServer by UniversalMediaServer.

the class StatusTab method build.

public JComponent build() {
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec("pref, 30dlu, fill:pref:grow, 30dlu, pref", orientation);
    // 1     2          3           4     5
    FormLayout layout = new FormLayout(colSpec, // //////////////////////////////////////////////////
    // Detected Media Renderers --------------------//  1
    "p," + // //
    "9dlu," + // <renderers>                  //  3
    "fill:p:grow," + // //
    "3dlu," + // ---------------------------------------------//  5
    "p," + // |                       |          //
    "3dlu," + // Connected |  Memory Usage         |<bitrate> //  7
    "p," + // |                       |          //
    "3dlu," + // <icon>   |  <statusbar>          |          //  9
    "p,");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.DIALOG);
    builder.opaque(true);
    CellConstraints cc = new CellConstraints();
    // Renderers
    JComponent cmp = builder.addSeparator(Messages.getString("StatusTab.9"), FormLayoutUtil.flip(cc.xyw(1, 1, 5), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    Font bold = cmp.getFont().deriveFont(Font.BOLD);
    Color fgColor = new Color(68, 68, 68);
    cmp.setFont(bold);
    renderers = new JPanel(new GuiUtil.WrapLayout(FlowLayout.CENTER, 20, 10));
    JScrollPane rsp = new JScrollPane(renderers, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    rsp.setBorder(BorderFactory.createEmptyBorder());
    rsp.setPreferredSize(new Dimension(0, 260));
    rsp.getHorizontalScrollBar().setLocation(0, 250);
    builder.add(rsp, cc.xyw(1, 3, 5));
    cmp = builder.addSeparator(null, FormLayoutUtil.flip(cc.xyw(1, 5, 5), colSpec, orientation));
    // Connected
    jl = new JLabel(Messages.getString("StatusTab.3"));
    builder.add(jl, FormLayoutUtil.flip(cc.xy(1, 7, "center, top"), colSpec, orientation));
    jl.setFont(bold);
    jl.setForeground(fgColor);
    imagePanel = buildImagePanel("/resources/images/icon-status-connecting.png");
    builder.add(imagePanel, FormLayoutUtil.flip(cc.xy(1, 9), colSpec, orientation));
    // Memory
    memBarUI = new GuiUtil.SegmentedProgressBarUI(Color.white, Color.gray);
    memBarUI.setActiveLabel("{}", Color.white, 0);
    memBarUI.setActiveLabel("{}", Color.red, 90);
    memBarUI.addSegment("", memColor);
    memBarUI.addSegment("", bufColor);
    memBarUI.setTickMarks(getTickMarks(), "{}");
    memoryProgressBar = new GuiUtil.CustomUIProgressBar(0, 100, memBarUI);
    memoryProgressBar.setStringPainted(true);
    memoryProgressBar.setForeground(new Color(75, 140, 181));
    memoryProgressBar.setString(Messages.getString("StatusTab.5"));
    JLabel mem = builder.addLabel("<html><b>" + Messages.getString("StatusTab.6") + "</b> (" + Messages.getString("StatusTab.12") + ")</html>", FormLayoutUtil.flip(cc.xy(3, 7), colSpec, orientation));
    mem.setForeground(fgColor);
    builder.add(memoryProgressBar, FormLayoutUtil.flip(cc.xyw(3, 9, 1), colSpec, orientation));
    // Bitrate
    String bitColSpec = "left:pref, 3dlu, right:pref:grow";
    PanelBuilder bitrateBuilder = new PanelBuilder(new FormLayout(bitColSpec, "p, 1dlu, p, 1dlu, p"));
    bitrateLabel = new JLabel("<html><b>" + Messages.getString("StatusTab.13") + "</b> (" + Messages.getString("StatusTab.11") + ")</html>");
    bitrateLabel.setForeground(fgColor);
    bitrateBuilder.add(bitrateLabel, FormLayoutUtil.flip(cc.xy(1, 1), bitColSpec, orientation));
    currentBitrateLabel = new JLabel(Messages.getString("StatusTab.14"));
    currentBitrateLabel.setForeground(fgColor);
    bitrateBuilder.add(currentBitrateLabel, FormLayoutUtil.flip(cc.xy(1, 3), bitColSpec, orientation));
    currentBitrate = new JLabel("0");
    currentBitrate.setForeground(fgColor);
    bitrateBuilder.add(currentBitrate, FormLayoutUtil.flip(cc.xy(3, 3), bitColSpec, orientation));
    peakBitrateLabel = new JLabel(Messages.getString("StatusTab.15"));
    peakBitrateLabel.setForeground(fgColor);
    bitrateBuilder.add(peakBitrateLabel, FormLayoutUtil.flip(cc.xy(1, 5), bitColSpec, orientation));
    peakBitrate = new JLabel("0");
    peakBitrate.setForeground(fgColor);
    bitrateBuilder.add(peakBitrate, FormLayoutUtil.flip(cc.xy(3, 5), bitColSpec, orientation));
    builder.add(bitrateBuilder.getPanel(), FormLayoutUtil.flip(cc.xywh(5, 7, 1, 3, "left, top"), colSpec, orientation));
    JPanel panel = builder.getPanel();
    // Apply the orientation to the panel and all components in it
    panel.applyComponentOrientation(orientation);
    JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    startMemoryUpdater();
    return scrollPane;
}
Also used : PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) Color(java.awt.Color) ComponentOrientation(java.awt.ComponentOrientation) Dimension(java.awt.Dimension) Font(java.awt.Font)

Example 7 with ComponentOrientation

use of java.awt.ComponentOrientation in project UniversalMediaServer by UniversalMediaServer.

the class TracesTab method build.

@SuppressWarnings("serial")
public JComponent build() {
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec("pref, pref:grow, pref, 3dlu, pref, pref, pref", orientation);
    int cols = colSpec.split(",").length;
    FormLayout layout = new FormLayout(colSpec, "p, fill:10:grow, p, p");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.opaque(true);
    CellConstraints cc = new CellConstraints();
    // Create the search box
    JPanel jSearchPanel = new JPanel();
    jSearchPanel.setLayout(new BoxLayout(jSearchPanel, BoxLayout.LINE_AXIS));
    jSearchPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel jFilterLabel = new JLabel(Messages.getString("TracesTab.24") + ":");
    jFilterLabel.setDisplayedMnemonic(KeyEvent.VK_F);
    jFilterLabel.setToolTipText(Messages.getString("TracesTab.33"));
    jTracesFilter = new CustomJComboBox<>(levelStrings);
    jTracesFilter.setSelectedIndex(findLevelsIdx(configuration.getLoggingFilterLogsTab()));
    jFilterLabel.setLabelFor(jTracesFilter);
    jTracesFilter.setToolTipText(Messages.getString("TracesTab.33"));
    jTracesFilter.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setLoggingFilterLogsTab(logLevels[jTracesFilter.getSelectedIndex()]);
            LoggingConfig.setTracesFilter();
        }
    });
    jSearchPanel.add(jFilterLabel);
    jSearchPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    jSearchPanel.add(jTracesFilter);
    jSearchPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    jSearchBox = new CustomJTextField();
    jSearchBox.setBackground(new Color(248, 248, 248));
    jSearchBox.setToolTipText(Messages.getString("TracesTab.34"));
    jSearchPanel.add(jSearchBox);
    jSearchPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    JButton jSearchButton = new JButton(Messages.getString("PMS.144"));
    jSearchButton.setMnemonic(KeyEvent.VK_S);
    jSearchButton.setToolTipText(Messages.getString("TracesTab.34"));
    jSearchPanel.add(jSearchButton);
    jSearchPanel.add(jCSSpace = Box.createRigidArea(new Dimension(5, 0)));
    jCSSearch = new CustomJCheckBox(Messages.getString("TracesTab.19"), configuration.getGUILogSearchCaseSensitive());
    jCSSearch.setMnemonic(KeyEvent.VK_C);
    jCSSearch.setToolTipText(Messages.getString("TracesTab.35"));
    jSearchPanel.add(jCSSearch);
    jSearchPanel.add(jRESpace = Box.createRigidArea(new Dimension(5, 0)));
    jRESearch = new CustomJCheckBox("RegEx", configuration.getGUILogSearchRegEx());
    jRESearch.setMnemonic(KeyEvent.VK_R);
    jRESearch.setToolTipText(Messages.getString("TracesTab.36"));
    jSearchPanel.add(jRESearch);
    jSearchPanel.add(jMLSpace = Box.createRigidArea(new Dimension(5, 0)));
    jMLSearch = new CustomJCheckBox(Messages.getString("TracesTab.20"), configuration.getGUILogSearchMultiLine());
    jMLSearch.setMnemonic(KeyEvent.VK_M);
    jMLSearch.setToolTipText(Messages.getString("TracesTab.37"));
    jSearchPanel.add(jMLSearch);
    jSearchPanel.add(jBufferSpace1 = Box.createRigidArea(new Dimension(4, 0)));
    jSearchPanel.add(jBufferSeparator = new JSeparator(SwingConstants.VERTICAL));
    jSearchPanel.add(jBufferSpace2 = Box.createRigidArea(new Dimension(4, 0)));
    jBufferLabel = new JLabel(Messages.getString("TracesTab.17"));
    jBufferLabel.setDisplayedMnemonic(KeyEvent.VK_B);
    jBufferLabel.setToolTipText(Messages.getString("TracesTab.38"));
    jLineBuffer = new CustomJSpinner(new SpinnerIntModel(configuration.getLoggingLogsTabLinebuffer(), PmsConfiguration.LOGGING_LOGS_TAB_LINEBUFFER_MIN, PmsConfiguration.LOGGING_LOGS_TAB_LINEBUFFER_MAX, PmsConfiguration.LOGGING_LOGS_TAB_LINEBUFFER_STEP), true);
    jLineBuffer.setToolTipText(Messages.getString("TracesTab.38"));
    jBufferLabel.setLabelFor(jLineBuffer);
    jSearchPanel.add(jBufferLabel);
    jSearchPanel.add(jBufferSpace3 = Box.createRigidArea(new Dimension(5, 0)));
    jSearchPanel.add(jLineBuffer);
    jLineBuffer.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            jList.setMaxLines((Integer) jLineBuffer.getValue());
            configuration.setLoggingLogsTabLinebuffer(jList.getMaxLines());
        }
    });
    jSearchBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            searchTraces();
        }
    });
    jSearchButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            searchTraces();
        }
    });
    jCSSearch.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setGUILogSearchCaseSensitive(jCSSearch.isSelected());
        }
    });
    jRESearch.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setGUILogSearchRegEx(jRESearch.isSelected());
        }
    });
    jMLSearch.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setGUILogSearchMultiLine(jMLSearch.isSelected());
        }
    });
    builder.add(jSearchPanel, cc.xyw(1, 1, cols));
    // Create traces text box
    jList = new TextAreaFIFO(configuration.getLoggingLogsTabLinebuffer());
    jList.setEditable(false);
    jList.setBackground(Color.WHITE);
    jList.setFont(new Font(Font.MONOSPACED, Font.PLAIN, jList.getFont().getSize()));
    final JPopupMenu popup = new JPopupMenu();
    Action copy = jList.getActionMap().get("copy-to-clipboard");
    JMenuItem copyItem = new JMenuItem(copy);
    copyItem.setText(Messages.getString("General.1"));
    popup.add(copyItem);
    popup.addSeparator();
    JMenuItem clearItem = new JMenuItem(Messages.getString("TracesTab.3"));
    clearItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jList.setText("");
        }
    });
    popup.add(clearItem);
    jList.addMouseListener(new PopupTriggerMouseListener(popup, jList));
    jList.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                searchTraces();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }
    });
    jListPane = new JScrollPane(jList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jListPane.setBorder(BorderFactory.createEmptyBorder());
    new SmartScroller(jListPane);
    builder.add(jListPane, cc.xyw(1, 2, cols));
    // Create the logging options panel
    jOptionsPanel = new JPanel();
    jOptionsPanel.setLayout(new BoxLayout(jOptionsPanel, BoxLayout.LINE_AXIS));
    jOptionsPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), Messages.getString("TracesTab.26")), BorderFactory.createEmptyBorder(10, 5, 10, 5))));
    jBuffered = new CustomJCheckBox(Messages.getString("TracesTab.25"), configuration.getLoggingBuffered());
    jBuffered.setMnemonic(KeyEvent.VK_U);
    jBuffered.setToolTipText(Messages.getString("TracesTab.43"));
    jBuffered.setHorizontalTextPosition(SwingConstants.LEADING);
    jBuffered.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (PMS.getTraceMode() == 2 && jBuffered.isSelected()) {
                jBuffered.setSelected(false);
                return;
            }
            configuration.setLoggingBuffered(jBuffered.isSelected());
            LoggingConfig.setBuffered(jBuffered.isSelected());
        }
    });
    jOptionsPanel.add(jBuffered);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    boolean useSyslog = configuration.getLoggingUseSyslog();
    jUseSyslog = new CustomJCheckBox(Messages.getString("TracesTab.27"), useSyslog);
    jUseSyslog.setMnemonic(KeyEvent.VK_Y);
    jUseSyslog.setToolTipText(Messages.getString("TracesTab.44"));
    jUseSyslog.setHorizontalTextPosition(SwingConstants.LEADING);
    jUseSyslog.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (PMS.getTraceMode() == 2 && jUseSyslog.isSelected()) {
                jUseSyslog.setSelected(false);
                return;
            } else if (jSyslogHost.getText().trim().isEmpty()) {
                jSearchOutput.setText(Messages.getString("TracesTab.31"));
                jUseSyslog.setSelected(false);
                return;
            }
            jSearchOutput.setText("");
            boolean useSyslog = jUseSyslog.isSelected();
            configuration.setLoggingUseSyslog(useSyslog);
            LoggingConfig.setSyslog();
            jSyslogHost.setEnabled(!useSyslog);
            jSyslogPort.setEnabled(!useSyslog);
            jSyslogFacility.setEnabled(!useSyslog);
        }
    });
    jOptionsPanel.add(jUseSyslog);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    JLabel jSyslogHostLabel = new JLabel(Messages.getString("TracesTab.28"));
    jSyslogHostLabel.setDisplayedMnemonic(KeyEvent.VK_N);
    jSyslogHostLabel.setToolTipText(Messages.getString("TracesTab.45"));
    jOptionsPanel.add(jSyslogHostLabel);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    jSyslogHost = new CustomJTextField(configuration.getLoggingSyslogHost(), 10);
    jSyslogHostLabel.setLabelFor(jSyslogHost);
    jSyslogHost.setToolTipText(Messages.getString("TracesTab.45"));
    jSyslogHost.setEnabled(!useSyslog);
    jSyslogHost.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                jSyslogHost.setText(configuration.getLoggingSyslogHost());
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                FocusManager.getCurrentManager().focusNextComponent();
            }
        }
    });
    jSyslogHost.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            String s = ((CustomJTextField) input).getText().trim();
            if (!s.isEmpty() && !(// Hostname or IPv4
            s.matches("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$") || // Simplified IPv6
            s.matches("(^([0-9a-fA-F]{0,4}:)+[0-9a-fA-F]{1,4}([0-9a-fA-F]{0,4}:)*$)|(^([0-9a-fA-F]{0,4}:)*[0-9a-fA-F]{1,4}([0-9a-fA-F]{0,4}:)+$)|(^::$)"))) {
                jSearchOutput.setText(String.format(Messages.getString("TracesTab.32"), s));
                return false;
            }
            jSearchOutput.setText("");
            configuration.setLoggingSyslogHost(jSyslogHost.getText().trim());
            return true;
        }
    });
    jOptionsPanel.add(jSyslogHost);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    JLabel jSyslogPortLabel = new JLabel(Messages.getString("TracesTab.29"));
    jSyslogPortLabel.setToolTipText(Messages.getString("TracesTab.46"));
    jOptionsPanel.add(jSyslogPortLabel);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    jSyslogPort = new CustomJSpinner(new SpinnerIntModel(configuration.getLoggingSyslogPort(), 1, 65535), true);
    jSyslogPort.setToolTipText(Messages.getString("TracesTab.46"));
    jSyslogPort.setEnabled(!useSyslog);
    jSyslogPortLabel.setLabelFor(jSyslogPort);
    jSyslogPort.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            configuration.setLoggingSyslogPort((Integer) jSyslogPort.getValue());
        }
    });
    jOptionsPanel.add(jSyslogPort);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    JLabel jSyslogFacilityLabel = new JLabel(Messages.getString("TracesTab.30"));
    jSyslogFacilityLabel.setDisplayedMnemonic(KeyEvent.VK_A);
    jSyslogFacilityLabel.setToolTipText(Messages.getString("TracesTab.47"));
    jOptionsPanel.add(jSyslogFacilityLabel);
    jOptionsPanel.add(Box.createRigidArea(new Dimension(4, 0)));
    jSyslogFacility = new CustomJComboBox<>(syslogFacilities);
    jSyslogFacility.setToolTipText(Messages.getString("TracesTab.47"));
    jSyslogFacility.setEnabled(!useSyslog);
    jSyslogFacility.setSelectedIndex(findSyslogFacilityIdx(configuration.getLoggingSyslogFacility()));
    jSyslogFacilityLabel.setLabelFor(jSyslogFacility);
    jSyslogFacility.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setLoggingSyslogFacility(syslogFacilities[jSyslogFacility.getSelectedIndex()]);
        }
    });
    jOptionsPanel.add(jSyslogFacility);
    jOptionsPanel.setFocusTraversalPolicyProvider(true);
    builder.add(jOptionsPanel, cc.xyw(1, 3, cols));
    jShowOptions = new CustomJCheckBox(Messages.getString("TracesTab.18"), PMS.getTraceMode() != 2 && configuration.getLoggingUseSyslog());
    jShowOptions.setHorizontalTextPosition(SwingConstants.LEADING);
    jShowOptions.setToolTipText(Messages.getString("TracesTab.41"));
    jShowOptions.setMnemonic(KeyEvent.VK_G);
    jShowOptions.setEnabled(PMS.getTraceMode() != 2);
    jShowOptions.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jOptionsPanel.setVisible(jShowOptions.isSelected());
            if (jShowOptions.isSelected()) {
                jBuffered.requestFocusInWindow();
            }
        }
    });
    builder.add(jShowOptions, cc.xy(3, 4));
    // Add buttons to open logfiles (there may be more than one)
    JPanel pLogFileButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    HashMap<String, String> logFiles = LoggingConfig.getLogFilePaths();
    for (Map.Entry<String, String> logger : logFiles.entrySet()) {
        String loggerNameDisplay = logger.getKey();
        if (logger.getKey().toLowerCase().startsWith("default.log")) {
            loggerNameDisplay = Messages.getString("TracesTab.5");
        }
        CustomJButton b = new CustomJButton(loggerNameDisplay);
        if (!logger.getKey().equals(loggerNameDisplay)) {
            b.setMnemonic(KeyEvent.VK_O);
        }
        b.setToolTipText(logger.getValue());
        b.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                File logFile = new File(((CustomJButton) e.getSource()).getToolTipText());
                try {
                    java.awt.Desktop.getDesktop().open(logFile);
                } catch (IOException | UnsupportedOperationException ioe) {
                    LOGGER.error("Failed to open file \"{}\" in default editor: {}", logFile, ioe);
                }
            }
        });
        pLogFileButtons.add(b);
    }
    builder.add(pLogFileButtons, cc.xy(cols, 4));
    final ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    JLabel rootLevelLabel = new JLabel(Messages.getString("TracesTab.11") + ": ");
    rootLevelLabel.setDisplayedMnemonic(KeyEvent.VK_L);
    rootLevelLabel.setToolTipText(Messages.getString("TracesTab.42"));
    CustomJComboBox<String> rootLevel = new CustomJComboBox<>(levelStrings);
    rootLevelLabel.setLabelFor(rootLevel);
    rootLevel.setSelectedIndex(findLevelsIdx(rootLogger.getLevel()));
    rootLevel.setToolTipText(Messages.getString("TracesTab.42"));
    rootLevel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            CustomJComboBox<?> cb = (CustomJComboBox<?>) e.getSource();
            rootLogger.setLevel(logLevels[cb.getSelectedIndex()]);
            Level newLevel = rootLogger.getLevel();
            if (newLevel.toInt() > Level.INFO_INT) {
                rootLogger.setLevel(Level.INFO);
            }
            LOGGER.info("Changed debug level to " + newLevel);
            if (newLevel != rootLogger.getLevel()) {
                rootLogger.setLevel(newLevel);
            }
            configuration.setRootLogLevel(newLevel);
        }
    });
    builder.add(rootLevelLabel, cc.xy(5, 4));
    builder.add(rootLevel, cc.xy(6, 4));
    if (PMS.getTraceMode() == 2) {
        // Forced trace mode
        rootLevel.setEnabled(false);
    }
    // Add buttons to pack logs (there may be more than one)
    JPanel pLogPackButtons = new JPanel(new FlowLayout(FlowLayout.LEFT));
    if (PMS.getTraceMode() == 0) {
        // PMS was not started in trace mode
        CustomJButton rebootTrace = new CustomJButton(Messages.getString("TracesTab.12"));
        rebootTrace.setToolTipText(Messages.getString("TracesTab.39"));
        rebootTrace.setMnemonic(KeyEvent.VK_T);
        rebootTrace.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int opt = JOptionPane.showConfirmDialog(null, Messages.getString("TracesTab.13"), Messages.getString("TracesTab.14"), JOptionPane.YES_NO_OPTION);
                if (opt == JOptionPane.YES_OPTION) {
                    ProcessUtil.reboot("trace");
                }
            }
        });
        pLogPackButtons.add(rebootTrace);
    }
    CustomJButton packDbg = new CustomJButton(Messages.getString("TracesTab.4"));
    packDbg.setMnemonic(KeyEvent.VK_P);
    packDbg.setToolTipText(Messages.getString("TracesTab.40"));
    packDbg.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JComponent comp = PMS.get().dbgPack().config();
            String[] cancelStr = { Messages.getString("Dialog.Close") };
            JOptionPane.showOptionDialog(looksFrame, comp, Messages.getString("Dialog.Options"), JOptionPane.CLOSED_OPTION, JOptionPane.PLAIN_MESSAGE, null, cancelStr, null);
        }
    });
    pLogPackButtons.add(packDbg);
    builder.add(pLogPackButtons, cc.xy(1, 4));
    builder.add(jSearchOutput, cc.xy(2, 4));
    JPanel builtPanel = builder.getPanel();
    // Add a Ctrl + F shortcut to search field
    builtPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK), "Ctrl_F");
    builtPanel.getActionMap().put("Ctrl_F", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jSearchBox.requestFocusInWindow();
        }
    });
    builtPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), "F3");
    builtPanel.getActionMap().put("F3", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            searchTraces();
        }
    });
    applyViewLevel();
    return builtPanel;
}
Also used : ActionEvent(java.awt.event.ActionEvent) CellConstraints(com.jgoodies.forms.layout.CellConstraints) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) Color(java.awt.Color) ComponentOrientation(java.awt.ComponentOrientation) ActionListener(java.awt.event.ActionListener) Level(ch.qos.logback.classic.Level) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) FlowLayout(java.awt.FlowLayout) Logger(org.slf4j.Logger) Font(java.awt.Font) KeyEvent(java.awt.event.KeyEvent) ChangeListener(javax.swing.event.ChangeListener) FormLayout(com.jgoodies.forms.layout.FormLayout) Dimension(java.awt.Dimension) ChangeEvent(javax.swing.event.ChangeEvent) KeyListener(java.awt.event.KeyListener)

Example 8 with ComponentOrientation

use of java.awt.ComponentOrientation 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)

Example 9 with ComponentOrientation

use of java.awt.ComponentOrientation in project omegat by omegat-org.

the class EditorController method applyOrientationToEditor.

/**
 * Define editor's orientation by target language orientation.
 */
private void applyOrientationToEditor() {
    ComponentOrientation targetOrientation = null;
    switch(currentOrientation) {
        case ALL_LTR:
            targetOrientation = ComponentOrientation.LEFT_TO_RIGHT;
            break;
        case ALL_RTL:
            targetOrientation = ComponentOrientation.RIGHT_TO_LEFT;
            break;
        case DIFFER:
            if (targetLangIsRTL) {
                // using target lang direction gives better result when user starts editing.
                targetOrientation = ComponentOrientation.RIGHT_TO_LEFT;
            } else {
                targetOrientation = ComponentOrientation.LEFT_TO_RIGHT;
            }
    }
    // set editor's orientation by target language
    editor.setComponentOrientation(targetOrientation);
}
Also used : ComponentOrientation(java.awt.ComponentOrientation)

Aggregations

ComponentOrientation (java.awt.ComponentOrientation)9 PanelBuilder (com.jgoodies.forms.builder.PanelBuilder)7 FormLayout (com.jgoodies.forms.layout.FormLayout)6 CellConstraints (com.jgoodies.forms.layout.CellConstraints)5 Dimension (java.awt.Dimension)4 Font (java.awt.Font)3 File (java.io.File)3 Color (java.awt.Color)2 Component (java.awt.Component)2 FontMetrics (java.awt.FontMetrics)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 JComponent (javax.swing.JComponent)2 JPanel (javax.swing.JPanel)2 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)2 TableColumn (javax.swing.table.TableColumn)2 CustomJButton (net.pms.newgui.components.CustomJButton)2 Level (ch.qos.logback.classic.Level)1