Example usage for java.awt ComponentOrientation getOrientation

List of usage examples for java.awt ComponentOrientation getOrientation

Introduction

In this page you can find the example usage for java.awt ComponentOrientation getOrientation.

Prototype

@Deprecated
public static ComponentOrientation getOrientation(ResourceBundle bdl) 

Source Link

Document

Returns the orientation appropriate for the given ResourceBundle's localization.

Usage

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

/**
 * Create the messaging server panel which consists of MultiBit style header
 * and our Netbean visual editor designed panel
 * @param stentWidth/*from  ww  w . ja v  a2s .  c o m*/
 * @return 
 */
private JPanel createMessagingServerPanel(int stentWidth) {

    MultiBitTitledPanel panel = new MultiBitTitledPanel("Messaging Servers",
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));

    // Create layout like other panels
    GridBagConstraints constraints = new GridBagConstraints();

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 0;
    constraints.gridy = 3;
    constraints.weightx = 0.1;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel indent = MultiBitTitledPanel.getIndentPanel(1);
    panel.add(indent, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel stent = MultiBitTitledPanel.createStent(stentWidth);
    panel.add(stent, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 2;
    constraints.gridy = 3;
    constraints.weightx = 0.05;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.CENTER;
    panel.add(MultiBitTitledPanel.createStent(MultiBitTitledPanel.SEPARATION_BETWEEN_NAME_VALUE_PAIRS),
            constraints);

    // Now insert our custom panel

    messagingServerPanel = new CSMessagingServerPanel();
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    panel.add(messagingServerPanel, constraints);

    // fill up right side
    JPanel fill1 = new JPanel();
    fill1.setOpaque(false);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 4;
    constraints.gridy = 10;
    constraints.weightx = 20;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    panel.add(fill1, constraints);

    return panel;
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private JPanel createAppearancePanel(int stentWidth) {
    MultiBitTitledPanel appearancePanel = new MultiBitTitledPanel(
            controller.getLocaliser().getString("showPreferencesPanel.appearanceTitle"),
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));

    GridBagConstraints constraints = new GridBagConstraints();

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 0;//  w w w  .j  a  v  a2 s  . c o  m
    constraints.gridy = 3;
    constraints.weightx = 0.1;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel indent = MultiBitTitledPanel.getIndentPanel(1);
    appearancePanel.add(indent, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel stent = MultiBitTitledPanel.createStent(stentWidth);
    appearancePanel.add(stent, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 2;
    constraints.gridy = 3;
    constraints.weightx = 0.05;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.CENTER;
    appearancePanel.add(
            MultiBitTitledPanel.createStent(MultiBitTitledPanel.SEPARATION_BETWEEN_NAME_VALUE_PAIRS),
            constraints);

    MultiBitLabel fontNameLabel = new MultiBitLabel(
            controller.getLocaliser().getString("fontChooser.fontName"));
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    appearancePanel.add(fontNameLabel, constraints);

    fontNameTextLabel = new MultiBitLabel("");
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 4;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(fontNameTextLabel, constraints);

    MultiBitLabel fontStyleLabel = new MultiBitLabel(
            controller.getLocaliser().getString("fontChooser.fontStyle"));
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    appearancePanel.add(fontStyleLabel, constraints);

    fontStyleTextLabel = new MultiBitLabel("");
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 5;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(fontStyleTextLabel, constraints);

    MultiBitLabel fontSizeLabel = new MultiBitLabel(
            controller.getLocaliser().getString("fontChooser.fontSize"));
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 6;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    appearancePanel.add(fontSizeLabel, constraints);

    fontSizeTextLabel = new MultiBitLabel("");
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 6;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(fontSizeTextLabel, constraints);

    ChooseFontAction chooseFontAction = new ChooseFontAction(controller, this, null);
    MultiBitButton fontChooserButton = new MultiBitButton(chooseFontAction, controller);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 7;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(fontChooserButton, constraints);

    constraints.fill = GridBagConstraints.VERTICAL;
    constraints.gridx = 4;
    constraints.gridy = 8;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(MultiBitTitledPanel.createStent(1, 30), constraints);

    MultiBitLabel lookAndFeelLabel = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.lookAndFeel"));
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 9;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    appearancePanel.add(lookAndFeelLabel, constraints);

    originalLookAndFeel = controller.getModel().getUserPreference(CoreModel.LOOK_AND_FEEL);
    LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();

    lookAndFeelComboBox = new JComboBox();
    lookAndFeelComboBox.addItem(localisedSystemLookAndFeelName);
    if (lookAndFeels != null) {
        for (LookAndFeelInfo info : lookAndFeels) {
            lookAndFeelComboBox.addItem(info.getName());
            if (info.getName().equalsIgnoreCase(originalLookAndFeel)) {
                lookAndFeelComboBox.setSelectedItem(info.getName());
            }
        }
    }

    if (originalLookAndFeel == null || originalLookAndFeel.equals("")
            || CoreModel.SYSTEM_LOOK_AND_FEEL.equalsIgnoreCase(originalLookAndFeel)) {
        lookAndFeelComboBox.setSelectedItem(localisedSystemLookAndFeelName);
    }

    lookAndFeelComboBox.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    lookAndFeelComboBox.setOpaque(false);

    FontMetrics fontMetrics = getFontMetrics(FontSizer.INSTANCE.getAdjustedDefaultFont());
    int textWidth = Math.max(fontMetrics.stringWidth("CDE/Motif"), fontMetrics.stringWidth("Windows classic"));
    Dimension preferredSize = new Dimension(textWidth + TICKER_COMBO_WIDTH_DELTA,
            fontMetrics.getHeight() + EXCHANGE_COMBO_HEIGHT_DELTA);
    lookAndFeelComboBox.setPreferredSize(preferredSize);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 9;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(lookAndFeelComboBox, constraints);

    JPanel fill1 = new JPanel();
    fill1.setOpaque(false);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 4;
    constraints.gridy = 10;
    constraints.weightx = 20;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    appearancePanel.add(fill1, constraints);

    return appearancePanel;
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private JPanel createTickerPanel(int stentWidth) {
    // Load up the original values.
    originalShowTicker = !Boolean.FALSE.toString()
            .equals(controller.getModel().getUserPreference(ExchangeModel.TICKER_SHOW));
    originalExchange1 = controller.getModel().getUserPreference(ExchangeModel.TICKER_FIRST_ROW_EXCHANGE);
    originalCurrency1 = controller.getModel().getUserPreference(ExchangeModel.TICKER_FIRST_ROW_CURRENCY);
    // Map MtGox to Bitstamp + USD
    if (ExchangeData.MT_GOX_EXCHANGE_NAME.equalsIgnoreCase(originalExchange1)) {
        originalExchange1 = ExchangeData.BITSTAMP_EXCHANGE_NAME;
        controller.getModel().setUserPreference(ExchangeModel.TICKER_FIRST_ROW_EXCHANGE,
                ExchangeData.BITSTAMP_EXCHANGE_NAME);

        originalCurrency1 = "USD";
        controller.getModel().setUserPreference(ExchangeModel.TICKER_FIRST_ROW_CURRENCY, "USD");
    }/* ww  w. j  a v a  2 s.c o m*/
    originalShowSecondRow = Boolean.TRUE.toString()
            .equals(controller.getModel().getUserPreference(ExchangeModel.TICKER_SHOW_SECOND_ROW));
    originalExchange2 = controller.getModel().getUserPreference(ExchangeModel.TICKER_SECOND_ROW_EXCHANGE);
    originalCurrency2 = controller.getModel().getUserPreference(ExchangeModel.TICKER_SECOND_ROW_CURRENCY);
    // Map MtGox to Bitstamp
    if (ExchangeData.MT_GOX_EXCHANGE_NAME.equalsIgnoreCase(originalExchange2)) {
        originalExchange2 = ExchangeData.BITSTAMP_EXCHANGE_NAME;
        controller.getModel().setUserPreference(ExchangeModel.TICKER_SECOND_ROW_EXCHANGE,
                ExchangeData.BITSTAMP_EXCHANGE_NAME);

        originalCurrency2 = "USD";
        controller.getModel().setUserPreference(ExchangeModel.TICKER_SECOND_ROW_CURRENCY, "USD");
    }

    MultiBitTitledPanel tickerPanel = new MultiBitTitledPanel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.title2"),
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));
    GridBagConstraints constraints = new GridBagConstraints();

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 3;
    constraints.gridy = 3;
    constraints.weightx = 0.05;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.CENTER;
    tickerPanel.add(MultiBitTitledPanel.createStent(MultiBitTitledPanel.SEPARATION_BETWEEN_NAME_VALUE_PAIRS),
            constraints);

    String showTickerText = controller.getLocaliser().getString("multiBitFrame.ticker.show.text");
    if (showTickerText != null && showTickerText.length() >= 1) {
        // Capitalise text (this is to save adding a new I18n term.
        showTickerText = Character.toUpperCase(showTickerText.charAt(0))
                + showTickerText.toLowerCase().substring(1);
    }
    showTicker = new JCheckBox(showTickerText);
    showTicker.setOpaque(false);
    showTicker.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    showTicker.setSelected(originalShowTicker);

    exchangeInformationLabel = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.exchangeInformation"));
    exchangeInformationLabel.setVisible(originalShowBitcoinConvertedToFiat);

    showBitcoinConvertedToFiat = new JCheckBox(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.showBitcoinConvertedToFiat"));
    showBitcoinConvertedToFiat.setOpaque(false);
    showBitcoinConvertedToFiat.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    showBitcoinConvertedToFiat.setSelected(originalShowBitcoinConvertedToFiat);

    showBitcoinConvertedToFiat.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            boolean selectedChange = (e.getStateChange() == ItemEvent.SELECTED);
            boolean unSelectedChange = (e.getStateChange() == ItemEvent.DESELECTED);
            if (exchangeInformationLabel != null) {
                if (selectedChange) {
                    exchangeInformationLabel.setVisible(true);
                }
                if (unSelectedChange) {
                    exchangeInformationLabel.setVisible(false);
                }
            }
        }
    });

    showExchange = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.exchange"));
    showExchange.setOpaque(false);
    showExchange.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showCurrency = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.currency"));
    showCurrency.setOpaque(false);
    showCurrency.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showLastPrice = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.lastPrice"));
    showLastPrice.setOpaque(false);
    showLastPrice.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showBid = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.bid"));
    showBid.setOpaque(false);
    showBid.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showAsk = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.ask"));
    showAsk.setOpaque(false);
    showAsk.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    String tickerColumnsToShow = controller.getModel().getUserPreference(ExchangeModel.TICKER_COLUMNS_TO_SHOW);
    if (tickerColumnsToShow == null || tickerColumnsToShow.equals("")) {
        tickerColumnsToShow = TickerTableModel.DEFAULT_COLUMNS_TO_SHOW;
    }

    originalShowCurrency = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_CURRENCY);
    showCurrency.setSelected(originalShowCurrency);

    originalShowRate = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_LAST_PRICE);
    showLastPrice.setSelected(originalShowRate);

    originalShowBid = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_BID);
    showBid.setSelected(originalShowBid);

    originalShowAsk = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_ASK);
    showAsk.setSelected(originalShowAsk);

    originalShowExchange = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_EXCHANGE);
    showExchange.setSelected(originalShowExchange);

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 4;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showTicker, constraints);

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 4;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showBitcoinConvertedToFiat, constraints);

    constraints.fill = GridBagConstraints.VERTICAL;
    constraints.gridx = 0;
    constraints.gridy = 6;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(1, 12), constraints);

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.columnsToShow"), 7, tickerPanel);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 8;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showExchange, constraints);

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 9;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showCurrency, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 10;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showLastPrice, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 11;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showBid, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 12;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showAsk, constraints);

    constraints.fill = GridBagConstraints.VERTICAL;
    constraints.gridx = 1;
    constraints.gridy = 13;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(1, 13), constraints);

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.firstRow"), 14, tickerPanel);

    MultiBitLabel exchangeLabel1 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.exchange"));
    exchangeLabel1.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 15;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(exchangeLabel1, constraints);

    String exchangeToUse1;
    if (originalExchange1 == null | "".equals(originalExchange1)) {
        exchangeToUse1 = ExchangeData.DEFAULT_EXCHANGE;
    } else {
        exchangeToUse1 = originalExchange1;
    }

    String exchangeToUse2;
    if (originalExchange2 == null | "".equals(originalExchange2)) {
        exchangeToUse2 = ExchangeData.DEFAULT_EXCHANGE;
    } else {
        exchangeToUse2 = originalExchange2;
    }

    exchangeComboBox1 = new JComboBox(ExchangeData.getAvailableExchanges());
    exchangeComboBox1.setSelectedItem(exchangeToUse1);

    exchangeComboBox1.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    exchangeComboBox1.setOpaque(false);

    FontMetrics fontMetrics = getFontMetrics(FontSizer.INSTANCE.getAdjustedDefaultFont());
    int textWidth = Math.max(fontMetrics.stringWidth(ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME),
            fontMetrics.stringWidth("USD")) + COMBO_WIDTH_DELTA;
    Dimension preferredSize = new Dimension(textWidth + TICKER_COMBO_WIDTH_DELTA,
            fontMetrics.getHeight() + EXCHANGE_COMBO_HEIGHT_DELTA);
    exchangeComboBox1.setPreferredSize(preferredSize);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 15;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 2;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel stent = MultiBitTitledPanel.createStent(stentWidth);
    tickerPanel.add(stent, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 15;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(exchangeComboBox1, constraints);

    oerMessageLabel1 = new MultiBitLabel(
            "    " + controller.getLocaliser().getString("showPreferencesPanel.getAppId.label"));
    oerMessageLabel1.setForeground(Color.GREEN.darker().darker());
    boolean showMessageLabel1 = isBrowserSupported()
            && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse1)
            && (originalOERApiCode == null || originalOERApiCode.trim().length() == 0);
    oerMessageLabel1.setVisible(showMessageLabel1);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 5;
    constraints.gridy = 15;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(oerMessageLabel1, constraints);

    MultiBitLabel currencyLabel1 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.currency"));
    currencyLabel1.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 16;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(currencyLabel1, constraints);

    // Make sure the exchange1 has been created and initialised the list of
    // currencies.
    if (mainFrame != null && mainFrame.getTickerTimerTask1() != null) {
        TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask1();
        synchronized (tickerTimerTask) {
            if (tickerTimerTask.getExchange() == null) {
                tickerTimerTask.createExchangeObjects(exchangeToUse1);
            }
        }
    }

    currencyComboBox1 = new JComboBox();
    Collection<String> currenciesToUse = ExchangeData.getAvailableCurrenciesForExchange(exchangeToUse1);
    if (currenciesToUse != null) {
        for (String currency : currenciesToUse) {
            String item = currency;
            String description = CurrencyConverter.INSTANCE.getCurrencyCodeToDescriptionMap().get(currency);
            if (description != null && description.trim().length() > 0) {
                item = item + " (" + description + ")";
            }
            currencyComboBox1.addItem(item);
            if (currency.equals(originalCurrency1)) {
                currencyComboBox1.setSelectedItem(item);
            }
        }
    }

    currencyComboBox1.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    currencyComboBox1.setOpaque(false);
    currencyComboBox1.setPreferredSize(preferredSize);

    exchangeComboBox1.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                Object item = event.getItem();
                String exchangeShortName = item.toString();
                // Make sure the exchange1 has been created and initialised
                // the list of currencies.
                if (mainFrame != null && mainFrame.getTickerTimerTask1() != null) {
                    TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask1();
                    synchronized (tickerTimerTask) {
                        tickerTimerTask.createExchangeObjects(exchangeShortName);
                        currencyComboBox1.removeAllItems();
                        Collection<String> currenciesToUse = ExchangeData
                                .getAvailableCurrenciesForExchange(exchangeShortName);
                        if (currenciesToUse != null) {
                            for (String currency : currenciesToUse) {
                                String loopItem = currency;
                                String description = CurrencyConverter.INSTANCE
                                        .getCurrencyCodeToDescriptionMap().get(currency);
                                if (description != null && description.trim().length() > 0) {
                                    loopItem = loopItem + " (" + description + ")";
                                }
                                currencyComboBox1.addItem(loopItem);
                            }
                        }
                    }
                }

                // Enable the OpenExchangeRates App ID if required.
                boolean showOER = ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                        .equalsIgnoreCase(exchangeShortName)
                        || ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                                .equalsIgnoreCase((String) exchangeComboBox2.getSelectedItem());
                oerStent.setVisible(showOER);
                oerApiCodeLabel.setVisible(showOER);
                oerApiCodeTextField.setVisible(showOER);
                getOerAppIdButton.setVisible(showOER);

                boolean showMessageLabel = isBrowserSupported()
                        && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeShortName)
                        && (oerApiCodeTextField.getText() == null
                                || oerApiCodeTextField.getText().trim().length() == 0);
                oerMessageLabel1.setVisible(showMessageLabel);
            }
        }
    });

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 16;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(currencyComboBox1, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 17;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(12, 12), constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 18;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 2;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(fontMetrics.stringWidth(exchangeInformationLabel.getText()),
            fontMetrics.getHeight()), constraints);
    tickerPanel.add(exchangeInformationLabel, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 19;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(12, 12), constraints);

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.secondRow"), 20, tickerPanel);

    showSecondRowCheckBox = new JCheckBox(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.showSecondRow"));
    showSecondRowCheckBox.setOpaque(false);
    showSecondRowCheckBox.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    showSecondRowCheckBox.addItemListener(new ChangeTickerShowSecondRowListener());

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 21;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showSecondRowCheckBox, constraints);

    exchangeLabel2 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.exchange"));
    exchangeLabel2.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 22;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(exchangeLabel2, constraints);

    exchangeComboBox2 = new JComboBox(ExchangeData.getAvailableExchanges());
    exchangeComboBox2.setSelectedItem(exchangeToUse2);

    exchangeComboBox2.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    exchangeComboBox2.setOpaque(false);
    exchangeComboBox2.setPreferredSize(preferredSize);

    exchangeComboBox2.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                Object item = event.getItem();
                String exchangeShortName = item.toString();
                // Make sure the exchange2 has been created and initialised
                // the list of currencies.
                if (mainFrame != null && mainFrame.getTickerTimerTask2() != null) {
                    TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask2();
                    synchronized (tickerTimerTask) {
                        tickerTimerTask.createExchangeObjects(exchangeShortName);
                        currencyComboBox2.removeAllItems();
                        Collection<String> currenciesToUse = ExchangeData
                                .getAvailableCurrenciesForExchange(exchangeShortName);
                        if (currenciesToUse != null) {
                            for (String currency : currenciesToUse) {
                                String loopItem = currency;
                                String description = CurrencyConverter.INSTANCE
                                        .getCurrencyCodeToDescriptionMap().get(currency);
                                if (description != null && description.trim().length() > 0) {
                                    loopItem = loopItem + " (" + description + ")";
                                }
                                currencyComboBox2.addItem(loopItem);
                            }
                        }
                    }
                }

                // Enable the OpenExchangeRates App ID if required.
                boolean showOER = ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                        .equalsIgnoreCase(exchangeShortName)
                        || ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                                .equalsIgnoreCase((String) exchangeComboBox1.getSelectedItem());
                oerStent.setVisible(showOER);
                oerApiCodeLabel.setVisible(showOER);
                oerApiCodeTextField.setVisible(showOER);
                getOerAppIdButton.setVisible(showOER);

                boolean showMessageLabel = isBrowserSupported()
                        && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeShortName)
                        && (oerApiCodeTextField.getText() == null
                                || oerApiCodeTextField.getText().trim().length() == 0);
                oerMessageLabel2.setVisible(showMessageLabel);
            }
        }
    });

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 22;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(exchangeComboBox2, constraints);

    oerMessageLabel2 = new MultiBitLabel(
            "    " + controller.getLocaliser().getString("showPreferencesPanel.getAppId.label"));
    oerMessageLabel2.setForeground(Color.GREEN.darker().darker());
    boolean showMessageLabel2 = isBrowserSupported()
            && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse2)
            && (originalOERApiCode == null || originalOERApiCode.trim().length() == 0);
    oerMessageLabel2.setVisible(showMessageLabel2);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 5;
    constraints.gridy = 22;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(oerMessageLabel2, constraints);

    currencyLabel2 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.currency"));
    currencyLabel2.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 23;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(currencyLabel2, constraints);

    // Make sure the exchange2 has been created and initialised the list of
    // currencies.
    if (mainFrame != null && mainFrame.getTickerTimerTask2() != null) {
        TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask2();
        synchronized (tickerTimerTask) {
            if (tickerTimerTask.getExchange() == null) {
                tickerTimerTask.createExchangeObjects(exchangeToUse2);
            }
        }
    }
    currencyComboBox2 = new JComboBox();
    currenciesToUse = ExchangeData.getAvailableCurrenciesForExchange(exchangeToUse2);
    if (currenciesToUse != null) {
        for (String currency : currenciesToUse) {
            String loopItem = currency;
            String description = CurrencyConverter.INSTANCE.getCurrencyCodeToDescriptionMap().get(currency);
            if (description != null && description.trim().length() > 0) {
                loopItem = loopItem + " (" + description + ")";
            }
            currencyComboBox2.addItem(loopItem);
            if (currency.equals(originalCurrency2)) {
                currencyComboBox2.setSelectedItem(loopItem);
            }
        }
    }

    currencyComboBox2.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    currencyComboBox2.setOpaque(false);
    currencyComboBox2.setPreferredSize(preferredSize);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 23;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(currencyComboBox2, constraints);

    showSecondRowCheckBox.setSelected(originalShowSecondRow);
    enableTickerSecondRow(originalShowSecondRow);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 24;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(12, 12), constraints);

    JPanel fill1 = new JPanel();
    fill1.setOpaque(false);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 5;
    constraints.gridy = 25;
    constraints.weightx = 20;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(fill1, constraints);

    boolean showOerSignup = ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse1)
            || ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse2);

    oerStent = MultiBitTitledPanel.createStent(12, 12);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 26;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    oerStent.setVisible(showOerSignup);
    tickerPanel.add(oerStent, constraints);

    oerApiCodeLabel = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.oerLabel.text"));
    oerApiCodeLabel.setToolTipText(HelpContentsPanel
            .createTooltipText(controller.getLocaliser().getString("showPreferencesPanel.oerLabel.tooltip")));
    oerApiCodeLabel.setVisible(showOerSignup);

    oerApiCodeTextField = new MultiBitTextField("", 25, controller);
    oerApiCodeTextField.setHorizontalAlignment(JLabel.LEADING);
    oerApiCodeTextField.setMinimumSize(new Dimension(API_CODE_FIELD_WIDTH, API_CODE_FIELD_HEIGHT));
    oerApiCodeTextField.setPreferredSize(new Dimension(API_CODE_FIELD_WIDTH, API_CODE_FIELD_HEIGHT));
    oerApiCodeTextField.setMaximumSize(new Dimension(API_CODE_FIELD_WIDTH, API_CODE_FIELD_HEIGHT));
    oerApiCodeTextField.setVisible(showOerSignup);
    oerApiCodeTextField.setText(originalOERApiCode);
    oerApiCodeTextField.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent arg0) {
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            String apiCode = oerApiCodeTextField.getText();
            if (apiCode != null && !(WhitespaceTrimmer.trim(apiCode).length() == 0) && !apiCode.equals(
                    controller.getModel().getUserPreference(ExchangeModel.OPEN_EXCHANGE_RATES_API_CODE))) {
                // New API code.
                // Check its length
                if (!(apiCode.trim().length() == LENGTH_OF_OPEN_EXCHANGE_RATE_APP_ID)
                        && !apiCode.equals(haveShownErrorMessageForApiCode)) {
                    haveShownErrorMessageForApiCode = apiCode;
                    // Give user a message that App ID is not in the correct format.
                    JOptionPane.showMessageDialog(null,
                            new String[] { controller
                                    .getLocaliser().getString("showPreferencesPanel.oerValidationError.text1"),
                                    " ",
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text2"),
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text3") },
                            controller.getLocaliser().getString(
                                    "showPreferencesPanel.oerValidationError.title"),
                            JOptionPane.ERROR_MESSAGE,
                            ImageLoader.createImageIcon(ImageLoader.EXCLAMATION_MARK_ICON_FILE));
                    return;
                }
            }
            updateApiCode();
        }
    });
    oerApiCodeTextField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            String apiCode = oerApiCodeTextField.getText();
            if (apiCode != null && !(WhitespaceTrimmer.trim(apiCode).length() == 0) && !apiCode.equals(
                    controller.getModel().getUserPreference(ExchangeModel.OPEN_EXCHANGE_RATES_API_CODE))) {
                // New API code.
                // Check its length
                if (!(apiCode.trim().length() == LENGTH_OF_OPEN_EXCHANGE_RATE_APP_ID)
                        && !apiCode.equals(haveShownErrorMessageForApiCode)) {
                    haveShownErrorMessageForApiCode = apiCode;
                    // Give user a message that App ID is not in the correct format.
                    JOptionPane.showMessageDialog(null,
                            new String[] {
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text1"),
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text2"),
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text3") },
                            controller.getLocaliser().getString(
                                    "showPreferencesPanel.oerValidationError.title"),
                            JOptionPane.ERROR_MESSAGE,
                            ImageLoader.createImageIcon(ImageLoader.EXCLAMATION_MARK_ICON_FILE));
                    return;
                }
            }
            updateApiCode();
        }
    });

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 27;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(oerApiCodeLabel, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 27;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 2;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(oerApiCodeTextField, constraints);

    if (isBrowserSupported()) {
        getOerAppIdButton = new MultiBitButton(
                controller.getLocaliser().getString("showPreferencesPanel.getAppId.text"));
        getOerAppIdButton
                .setToolTipText(controller.getLocaliser().getString("showPreferencesPanel.getAppId.tooltip"));
        getOerAppIdButton.setVisible(showOerSignup);

        getOerAppIdButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                try {
                    openURI(new URI(OPEN_EXCHANGE_RATES_SIGN_UP_URI));
                } catch (URISyntaxException e) {
                    log.debug(e.getMessage());
                }
            }
        });

        constraints.fill = GridBagConstraints.NONE;
        constraints.gridx = 4;
        constraints.gridy = 28;
        constraints.weightx = 1;
        constraints.weighty = 1;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.LINE_START;
        tickerPanel.add(getOerAppIdButton, constraints);
    }

    return tickerPanel;
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private JPanel createBrowserIntegrationPanel(int stentWidth) {
    MultiBitTitledPanel browserIntegrationPanel = new MultiBitTitledPanel(
            controller.getLocaliser().getString("showPreferencesPanel.browserIntegrationTitle"),
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));

    GridBagConstraints constraints = new GridBagConstraints();

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.browserIntegration.messageText"), 3,
            browserIntegrationPanel);//from  ww w.j a  v a  2  s . c  o  m

    ButtonGroup browserIntegrationGroup = new ButtonGroup();
    ignoreAll = new JRadioButton(controller.getLocaliser().getString("showPreferencesPanel.ignoreAll"));
    ignoreAll.setOpaque(false);
    ignoreAll.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    fillAutomatically = new JRadioButton(
            controller.getLocaliser().getString("showPreferencesPanel.fillAutomatically"));
    fillAutomatically.setOpaque(false);
    fillAutomatically.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    askEveryTime = new JRadioButton(controller.getLocaliser().getString("showPreferencesPanel.askEveryTime"));
    askEveryTime.setOpaque(false);
    askEveryTime.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    browserIntegrationGroup.add(ignoreAll);
    browserIntegrationGroup.add(fillAutomatically);
    browserIntegrationGroup.add(askEveryTime);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    browserIntegrationPanel.add(ignoreAll, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 6;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.anchor = GridBagConstraints.LINE_START;
    browserIntegrationPanel.add(fillAutomatically, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 7;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.anchor = GridBagConstraints.LINE_START;
    browserIntegrationPanel.add(askEveryTime, constraints);

    return browserIntegrationPanel;
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private JPanel createButtonPanel() {
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());

    GridBagConstraints constraints = new GridBagConstraints();

    buttonPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, SystemColor.windowBorder));
    buttonPanel.setOpaque(true);//ww  w . jav  a  2 s . co m
    buttonPanel.setBackground(ColorAndFontConstants.MID_BACKGROUND_COLOR);
    buttonPanel.setComponentOrientation(
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));

    Action helpAction;
    if (ComponentOrientation.LEFT_TO_RIGHT == ComponentOrientation
            .getOrientation(controller.getLocaliser().getLocale())) {
        helpAction = new HelpContextAction(controller, ImageLoader.HELP_CONTENTS_BIG_ICON_FILE,
                "multiBitFrame.helpMenuText", "multiBitFrame.helpMenuTooltip", "multiBitFrame.helpMenuText",
                HelpContentsPanel.HELP_PREFERENCES_URL);
    } else {
        helpAction = new HelpContextAction(controller, ImageLoader.HELP_CONTENTS_BIG_RTL_ICON_FILE,
                "multiBitFrame.helpMenuText", "multiBitFrame.helpMenuTooltip", "multiBitFrame.helpMenuText",
                HelpContentsPanel.HELP_PREFERENCES_URL);
    }
    HelpButton helpButton = new HelpButton(helpAction, controller);
    helpButton.setText("");
    helpButton.setToolTipText(controller.getLocaliser().getString("multiBitFrame.helpMenuTooltip"));
    helpButton.setHorizontalAlignment(SwingConstants.LEADING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.weightx = 0.3;
    constraints.weighty = 0.1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    buttonPanel.add(helpButton, constraints);

    ShowPreferencesSubmitAction submitAction = new ShowPreferencesSubmitAction(this.bitcoinController,
            this.exchangeController, this, ImageLoader.createImageIcon(ImageLoader.PREFERENCES_ICON_FILE),
            mainFrame);
    MultiBitButton submitButton = new MultiBitButton(submitAction, controller);
    buttonPanel.add(submitButton);

    UndoPreferencesChangesSubmitAction undoChangesAction = new UndoPreferencesChangesSubmitAction(controller,
            ImageLoader.createImageIcon(ImageLoader.UNDO_ICON_FILE));
    undoChangesButton = new MultiBitButton(undoChangesAction, controller);

    buttonPanel.add(undoChangesButton);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.weightx = 0.1;
    constraints.weighty = 1.0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    buttonPanel.add(submitButton, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 2;
    constraints.gridy = 0;
    constraints.weightx = 0.1;
    constraints.weighty = 1.0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    buttonPanel.add(undoChangesButton, constraints);

    JPanel fill1 = new JPanel();
    fill1.setOpaque(false);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 2;
    constraints.gridy = 0;
    constraints.weightx = 200;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    buttonPanel.add(fill1, constraints);

    return buttonPanel;
}

From source file:org.notebook.gui.widget.GuiUtils.java

/**
 * Sets the component orientation./*from w w  w. j  a  v a  2  s. c  om*/
 */
private static void setComponentOrientation() {
    componentOrientation = ComponentOrientation.getOrientation(Locale.getDefault());
    //      if (Kernel.getInstance() == null) {
    //         componentOrientation = ComponentOrientation.getOrientation(Locale.getDefault());
    //      } else {
    //         if ("ug".equalsIgnoreCase(Kernel.getInstance().state.getLocale().getLocale().getLanguage())) {
    //            componentOrientation = ComponentOrientation.RIGHT_TO_LEFT;
    //         } else {
    //            componentOrientation = ComponentOrientation.getOrientation(Kernel.getInstance().state.getLocale().getLocale());
    //         }
    //
    //      }
}

From source file:uk.chromis.pos.forms.JRootApp.java

/**
 *
 * @param props/*from  w w w. ja v a2s  . c  o  m*/
 * @return
 */
public int initApp(AppProperties props) {

    m_props = props;
    m_jPanelDown.setVisible(!AppConfig.getInstance().getBoolean("till.hideinfo"));

    // support for different component orientation languages.
    applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));

    // Database start
    int rc = INIT_FAIL_RETRY;
    while (rc == INIT_FAIL_RETRY) {
        rc = INIT_SUCCESS;
        try {
            session = AppViewConnection.createSession(m_props);
        } catch (BasicException e) {
            JOpenWarningDlg wDlg = new JOpenWarningDlg(e.getMessage(),
                    AppLocal.getIntString("message.retryorconfig"), true, true);
            wDlg.setModal(true);
            wDlg.setVisible(true);
            rc = JOpenWarningDlg.CHOICE;
        }
    }

    if (rc != INIT_SUCCESS) {
        return rc;
    }

    m_dlSystem = (DataLogicSystem) getBean("uk.chromis.pos.forms.DataLogicSystem");

    String sDBVersion = readDataBaseVersion();
    if (!AppConfig.getInstance().getBoolean("chromis.tickettype") && sDBVersion != null) {
        UpdateTicketType.updateTicketType();
    }

    if (!AppLocal.APP_VERSION.equals(sDBVersion)) {
        // Lets check if this is a historic version of the jar and it is in the database  
        /*            if (m_dlSystem.checkHistoricVersion(AppLocal.APP_VERSION) != 0) {
        StartupDialog dialog = new StartupDialog();
        JFrame frame = new JFrame("");
        JPanel dialogPanel = new JPanel();
        dialogPanel.add(dialog);
        dialog.jTextArea1.setText("\n Unable to run Chromis. \n \n You are trying to run an incompatible version of Chromis."
                + "\n\n The database found is v" + sDBVersion);
        JOptionPane.showMessageDialog(frame,
                dialogPanel,
                "Incompatible version ",
                JOptionPane.PLAIN_MESSAGE);
        System.exit(1);
                    }
                     */
        if (getDbVersion().equals("x")) {
            JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_DANGER,
                    AppLocal.getIntString("message.databasenotsupported", session.DB.getName())));
        } else {
            String changelog = (sDBVersion == null) || ("0.00".equals(sDBVersion))
                    ? "uk/chromis/pos/liquibase/create/chromis.xml"
                    : "uk/chromis/pos/liquibase/upgradeorig/updatesystem.xml";
            JProcessingDlg dlg = new JProcessingDlg(
                    AppLocal.getIntString(
                            sDBVersion == null ? "message.createdatabase" : "message.updatedatabase"),
                    (sDBVersion == null), changelog);
            dlg.setModal(true);
            dlg.setVisible(true);
            if (JProcessingDlg.CHOICE == -1 || JProcessingDlg.DBFAILED) {
                session.close();
                JOpenWarningDlg wDlg;
                if (!"".equals(JProcessingDlg.ERRORMSG)) {
                    wDlg = new JOpenWarningDlg(JProcessingDlg.ERRORMSG,
                            AppLocal.getIntString(
                                    sDBVersion == null ? "message.createfailure" : "message.updatefailure"),
                            false, false);
                    wDlg.setModal(true);
                    wDlg.setVisible(true);
                }
                System.exit(0);
            }
        }
    }

    // Clear the cash drawer table as required, by setting 
    try {
        if ("d".equals(getDbVersion())) {
            SQL = "DELETE FROM DRAWEROPENED WHERE OPENDATE < {fn TIMESTAMPADD(SQL_TSI_DAY ,-"
                    + AppConfig.getInstance().getProperty("dbtable.retaindays") + ", CURRENT_TIMESTAMP)}";
        } else {
            SQL = "DELETE FROM DRAWEROPENED WHERE OPENDATE < (NOW() - INTERVAL '"
                    + AppConfig.getInstance().getProperty("dbtable.retaindays") + "' DAY)";
        }
        stmt.execute(SQL);
    } catch (Exception e) {
    }

    m_propsdb = m_dlSystem.getResourceAsProperties(AppConfig.getInstance().getHost() + "/properties");

    try {
        String sActiveCashIndex = m_propsdb.getProperty("activecash");
        Object[] valcash = sActiveCashIndex == null ? null : m_dlSystem.findActiveCash(sActiveCashIndex);
        if (valcash == null || !AppConfig.getInstance().getHost().equals(valcash[0])) {
            setActiveCash(UUID.randomUUID().toString(),
                    m_dlSystem.getSequenceCash(AppConfig.getInstance().getHost()) + 1, new Date(), null);
            m_dlSystem.execInsertCash(new Object[] { getActiveCashIndex(), AppConfig.getInstance().getHost(),
                    getActiveCashSequence(), getActiveCashDateStart(), getActiveCashDateEnd(), 0 });
        } else {
            setActiveCash(sActiveCashIndex, (Integer) valcash[1], (Date) valcash[2], (Date) valcash[3]);
        }
    } catch (BasicException e) {
        session.close();
        JOpenWarningDlg wDlg = new JOpenWarningDlg(e.getMessage(),
                AppLocal.getIntString("message.retryorconfig"), false, true);
        wDlg.setModal(true);
        wDlg.setVisible(true);
        return JOpenWarningDlg.CHOICE;
    }

    m_sInventoryLocation = m_propsdb.getProperty("location");
    if (m_sInventoryLocation == null) {
        m_sInventoryLocation = "0";
        m_propsdb.setProperty("location", m_sInventoryLocation);
        m_dlSystem.setResourceAsProperties(AppConfig.getInstance().getHost() + "/properties", m_propsdb);
    }

    // setup the display
    m_TP = new DeviceTicket(this, m_props);

    // Inicializamos 
    m_TTP = new TicketParser(getDeviceTicket(), m_dlSystem);

    printerStart();

    // Inicializamos la bascula
    m_Scale = new DeviceScale(this, m_props);

    // Inicializamos la scanpal
    m_Scanner = DeviceScannerFactory.createInstance(m_props);

    new javax.swing.Timer(250, new PrintTimeAction()).start();

    String sWareHouse;

    try {
        sWareHouse = m_dlSystem.findLocationName(m_sInventoryLocation);
    } catch (BasicException e) {
        sWareHouse = null; // no he encontrado el almacen principal
    }

    // Show Hostname, Warehouse and URL in taskbar
    String url;

    try {
        url = session.getURL();
    } catch (SQLException e) {
        url = "";
    }

    m_jHost.setText("<html>" + AppConfig.getInstance().getHost() + " - " + sWareHouse + "<br>" + url);

    // display the new logo if set
    String newLogo = AppConfig.getInstance().getProperty("start.logo");
    if (newLogo != null) {
        if ("".equals(newLogo)) {
            jLabel1.setIcon(
                    new javax.swing.ImageIcon(getClass().getResource("/uk/chromis/fixedimages/chromis.png")));
        } else {
            jLabel1.setIcon(new javax.swing.ImageIcon(newLogo));
        }
    }

    // change text under logo
    String newText = AppConfig.getInstance().getProperty("start.text");
    if (newText != null) {
        if (newText.equals("")) {
            jLabel1.setText("<html><center>Chromis POS - The New Face of Open Source POS<br>"
                    + "Copyright \u00A9 (c) 2015-2016Chromis <br>" + "<br>" + "http://www.chromis.co.uk<br>"
                    + "<br>"
                    + " Chromis POS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.<br>"
                    + "<br>"
                    + " Chromis POS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.<br>"
                    + "<br>"
                    + "You should have received a copy of the GNU General Public License along with Chromis POS.  If not, see http://www.gnu.org/licenses/<br>"
                    + "</center>");
        } else {
            try {
                String newTextCode = new Scanner(new File(newText), "UTF-8").useDelimiter("\\A").next();
                jLabel1.setText(newTextCode);
            } catch (Exception e) {
            }

            jLabel1.setAlignmentX(0.5F);
            jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
            jLabel1.setMaximumSize(new java.awt.Dimension(800, 1024));
            jLabel1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        }
    }

    // Lets copy any database specific reports to the reports folder
    // Get the database version first
    File dbReportsSource = null;
    String currentPath = new File("").getAbsolutePath();

    if (OSValidator.isMac()) {
        try {
            currentPath = new File(
                    JRootApp.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath())
                            .toString();
            currentPath = currentPath.replaceAll("/chromispos.jar", "");
        } catch (URISyntaxException ex) {
            currentPath = "/Applications/chromispos";
        }
    } else {
        currentPath = System.getProperty("user.dir");
    }

    switch (getDbVersion()) {
    case "d":
        dbReportsSource = new File(currentPath + "/reports/uk/chromis/derby");
        break;
    case "m":
        dbReportsSource = new File(currentPath + "/reports/uk/chromis/mysql");
        break;
    case "p":
        dbReportsSource = new File(currentPath + "/reports/uk/chromis/postgresql");
        break;
    }

    File reportsDestination = new File(currentPath + "/reports/uk/chromis/reports");

    try {
        File reportsSource = new File(currentPath + "/reports/uk/chromis/default");
        FileUtils.copyDirectory(reportsSource, new File(currentPath + "/reports/uk/chromis/reports"));
        if ((dbReportsSource) != null) {
            FileUtils.copyDirectory(dbReportsSource, new File(currentPath + "/reports/uk/chromis/reports"));
        }
    } catch (IOException ex) {
        Logger.getLogger(JRootApp.class.getName()).log(Level.SEVERE, null, ex);
    }

    showLogin();

    return INIT_SUCCESS;
}