Ignore:
Timestamp:
2016-02-19T17:54:54+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Style preference panel like the website

Location:
applications/editors/josm/plugins/mapillary
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r31976 r32076  
    22package org.openstreetmap.josm.plugins.mapillary.gui;
    33
    4 import java.awt.FlowLayout;
     4import java.awt.BorderLayout;
     5import java.awt.Color;
    56import java.awt.GridBagConstraints;
    67import java.awt.GridBagLayout;
    78import java.awt.event.ActionEvent;
    89import java.io.IOException;
    9 
     10import java.io.InputStream;
     11
     12import javax.imageio.ImageIO;
    1013import javax.swing.AbstractAction;
    1114import javax.swing.BorderFactory;
    1215import javax.swing.Box;
     16import javax.swing.BoxLayout;
     17import javax.swing.ImageIcon;
    1318import javax.swing.JButton;
    1419import javax.swing.JCheckBox;
     
    2833import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryUser;
    2934import org.openstreetmap.josm.plugins.mapillary.oauth.OAuthPortListener;
     35import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryColorScheme;
     36import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryColorScheme.MapillaryButton;
    3037import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryURL;
    3138import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
     
    4249
    4350  private final JCheckBox reverseButtons = new JCheckBox(I18n.tr("Reverse buttons position when displaying images."));
    44   private final JComboBox<String> downloadMode = new JComboBox<>(new String[]{
     51  private final JComboBox<String> downloadModeComboBox = new JComboBox<>(new String[]{
    4552      MapillaryDownloader.MODES.Automatic.toString(),
    4653      MapillaryDownloader.MODES.Semiautomatic.toString(),
     
    5158  private final JCheckBox moveTo = new JCheckBox(I18n.tr("Move to picture''s location with next/previous buttons"));
    5259
    53   private final JButton loginButton = new JButton(new LoginAction(this));
    54   private final JButton logoutButton = new JButton(new LogoutAction());
     60  private final JButton loginButton = new MapillaryButton(I18n.tr("Login"), new LoginAction(this));
     61  private final JButton logoutButton = new MapillaryButton(I18n.tr("Logout"), new LogoutAction());
    5562  private final JLabel loginLabel = new JLabel();
    5663  private final JPanel loginPanel = new JPanel();
     
    6370  @Override
    6471  public void addGui(PreferenceTabbedPane gui) {
    65     JPanel panel = new JPanel();
    66     this.reverseButtons.setSelected(Main.pref.getBoolean("mapillary.reverse-buttons"));
    67     this.displayHour.setSelected(Main.pref.getBoolean("mapillary.display-hour", true));
    68     this.format24.setSelected(Main.pref.getBoolean("mapillary.format-24"));
    69     this.moveTo.setSelected(Main.pref.getBoolean("mapillary.move-to-picture", true));
    70 
    71     panel.setLayout(new GridBagLayout());
    72     panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    73 
    74     panel.add(this.reverseButtons, GBC.eol());
     72    JPanel container = new JPanel(new BorderLayout());
     73
     74    loginPanel.setLayout(new BoxLayout(loginPanel, BoxLayout.LINE_AXIS));
     75    loginPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
     76    loginPanel.setBackground(MapillaryColorScheme.TOOLBAR_DARK_GREY);
     77    JLabel brandImage = new JLabel();
     78    try (InputStream is = MapillaryPreferenceSetting.class.getResourceAsStream("/images/mapillary-logo-white.png")) {
     79      if (is != null) {
     80        brandImage.setIcon(new ImageIcon(ImageIO.read(is)));
     81      } else {
     82        Main.warn("Could not load Mapillary brand image!");
     83      }
     84    } catch (IOException e) {
     85      Main.warn("While reading Mapillary brand image, an IO-exception occured!");
     86    }
     87    loginPanel.add(brandImage, 0);
     88    loginPanel.add(Box.createHorizontalGlue(), 1);
     89    loginLabel.setForeground(Color.WHITE);
     90    loginLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
     91    loginPanel.add(loginLabel, 2);
     92    loginPanel.add(loginButton, 3);
     93    onLogout();
     94    container.add(loginPanel, BorderLayout.NORTH);
     95
     96    JPanel mainPanel = new JPanel();
     97    reverseButtons.setSelected(Main.pref.getBoolean("mapillary.reverse-buttons"));
     98    displayHour.setSelected(Main.pref.getBoolean("mapillary.display-hour", true));
     99    format24.setSelected(Main.pref.getBoolean("mapillary.format-24"));
     100    moveTo.setSelected(Main.pref.getBoolean("mapillary.move-to-picture", true));
     101
     102    mainPanel.setLayout(new GridBagLayout());
     103    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
     104
    75105    // Sets the value of the ComboBox.
    76106    String downloadMode = Main.pref.get("mapillary.download-mode");
     
    78108        || MapillaryDownloader.MODES.Semiautomatic.toString().equals(downloadMode)
    79109        || MapillaryDownloader.MODES.Manual.toString().equals(downloadMode)) {
    80       this.downloadMode.setSelectedItem(Main.pref.get("mapillary.download-mode"));
     110      downloadModeComboBox.setSelectedItem(Main.pref.get("mapillary.download-mode"));
    81111    }
    82112    JPanel downloadModePanel = new JPanel();
    83113    downloadModePanel.add(new JLabel(I18n.tr("Download mode")));
    84     downloadModePanel.add(this.downloadMode);
    85     panel.add(downloadModePanel, GBC.eol());
    86     panel.add(displayHour, GBC.eol());
    87     panel.add(format24, GBC.eol());
    88     panel.add(moveTo, GBC.eol());
    89 
    90     loginPanel.setLayout(new FlowLayout(FlowLayout.LEADING));
    91     loginPanel.add(loginButton, 0);
    92     loginPanel.add(loginLabel, 1);
    93     onLogout();
    94     panel.add(loginPanel, GBC.eol());
    95     panel.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.BOTH));
     114    downloadModePanel.add(downloadModeComboBox);
     115    mainPanel.add(downloadModePanel, GBC.eol());
     116
     117    mainPanel.add(reverseButtons, GBC.eol());
     118    mainPanel.add(displayHour, GBC.eol());
     119    mainPanel.add(format24, GBC.eol());
     120    mainPanel.add(moveTo, GBC.eol());
     121    MapillaryColorScheme.styleAsDefaultPanel(
     122      mainPanel, downloadModePanel, reverseButtons, displayHour, format24, moveTo
     123    );
     124    mainPanel.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.BOTH));
     125
     126    container.add(mainPanel, BorderLayout.CENTER);
    96127
    97128    synchronized (gui.getDisplayPreference().getTabPane()) {
    98       gui.getDisplayPreference().addSubTab(this, "Mapillary", new JScrollPane(panel));
     129      gui.getDisplayPreference().addSubTab(this, "Mapillary", new JScrollPane(container));
    99130      gui.getDisplayPreference().getTabPane().setIconAt(gui.getDisplayPreference().getTabPane().getTabCount()-1, MapillaryPlugin.ICON12);
    100131    }
     
    118149  @Override
    119150  public void onLogin(final String username) {
    120     loginPanel.add(logoutButton, 1);
     151    loginPanel.remove(loginButton);
     152    loginPanel.add(logoutButton, 3);
    121153    loginLabel.setText(I18n.tr("You are logged in as ''{0}''.", username));
    122     loginButton.setText(I18n.tr("Re-Login"));
    123     logoutButton.setText(I18n.tr("Logout"));
     154    loginPanel.revalidate();
     155    loginPanel.repaint();
    124156  }
    125157
     
    127159  public void onLogout() {
    128160    loginPanel.remove(logoutButton);
     161    loginPanel.add(loginButton, 3);
    129162    loginLabel.setText(I18n.tr("You are currently not logged in."));
    130     loginButton.setText(I18n.tr("Login"));
     163    loginPanel.revalidate();
     164    loginPanel.repaint();
    131165  }
    132166
     
    137171
    138172    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), false);
    139     if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES.Automatic.toString()))
     173    if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Automatic.toString()))
    140174      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Automatic.toString());
    141     if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES.Semiautomatic.toString()))
     175    if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Semiautomatic.toString()))
    142176      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Semiautomatic.toString());
    143     if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES.Manual.toString())) {
     177    if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Manual.toString())) {
    144178      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Manual.toString());
    145179      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), true);
Note: See TracChangeset for help on using the changeset viewer.