|
| 1 | +/* |
| 2 | + * This file is part of Arduino. |
| 3 | + * |
| 4 | + * Copyright 2014 Arduino LLC (http://www.arduino.cc/) |
| 5 | + * |
| 6 | + * Arduino is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | + * |
| 20 | + * As a special exception, you may use this file as part of a free software |
| 21 | + * library without restriction. Specifically, if other files instantiate |
| 22 | + * templates or use macros or inline functions from this file, or you compile |
| 23 | + * this file and link it with other files to produce an executable, this |
| 24 | + * file does not by itself cause the resulting executable to be covered by |
| 25 | + * the GNU General Public License. This exception does not however |
| 26 | + * invalidate any other reasons why the executable file might be covered by |
| 27 | + * the GNU General Public License. |
| 28 | + */ |
| 29 | +package cc.arduino.packages.contributions.ui; |
| 30 | + |
| 31 | +import java.awt.BorderLayout; |
| 32 | +import java.awt.Component; |
| 33 | +import java.awt.Dialog; |
| 34 | +import java.awt.Dimension; |
| 35 | +import java.awt.FlowLayout; |
| 36 | +import java.awt.Window; |
| 37 | +import java.awt.event.ActionListener; |
| 38 | + |
| 39 | +import javax.swing.Box; |
| 40 | +import javax.swing.BoxLayout; |
| 41 | +import javax.swing.JButton; |
| 42 | +import javax.swing.JDialog; |
| 43 | +import javax.swing.JLabel; |
| 44 | +import javax.swing.JPanel; |
| 45 | +import javax.swing.JProgressBar; |
| 46 | +import javax.swing.border.EmptyBorder; |
| 47 | + |
| 48 | +import cc.arduino.packages.contributions.ContributionInstaller; |
| 49 | +import cc.arduino.packages.contributions.ContributionInstaller.Listener; |
| 50 | + |
| 51 | +@SuppressWarnings("serial") |
| 52 | +public class ContributionInstallerUI extends JDialog { |
| 53 | + |
| 54 | + private final JPanel contentPanel = new JPanel(); |
| 55 | + private JButton cancelButton; |
| 56 | + private JProgressBar progressBar; |
| 57 | + private JLabel operationLabel; |
| 58 | + |
| 59 | + public ContributionInstallerUI(Window parent) { |
| 60 | + super(parent, "Installer progress", Dialog.ModalityType.APPLICATION_MODAL); |
| 61 | + |
| 62 | + setBounds(100, 100, 450, 300); |
| 63 | + getContentPane().setLayout(new BorderLayout()); |
| 64 | + contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); |
| 65 | + getContentPane().add(contentPanel, BorderLayout.CENTER); |
| 66 | + contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); |
| 67 | + { |
| 68 | + Box verticalBox = Box.createVerticalBox(); |
| 69 | + contentPanel.add(verticalBox); |
| 70 | + { |
| 71 | + Component verticalGlue = Box.createVerticalGlue(); |
| 72 | + verticalBox.add(verticalGlue); |
| 73 | + } |
| 74 | + { |
| 75 | + Box horizontalBox = Box.createHorizontalBox(); |
| 76 | + verticalBox.add(horizontalBox); |
| 77 | + { |
| 78 | + Component horizontalGlue = Box.createHorizontalGlue(); |
| 79 | + horizontalBox.add(horizontalGlue); |
| 80 | + } |
| 81 | + { |
| 82 | + JLabel lblNewLabel = new JLabel("Description"); |
| 83 | + horizontalBox.add(lblNewLabel); |
| 84 | + } |
| 85 | + { |
| 86 | + Component horizontalGlue = Box.createHorizontalGlue(); |
| 87 | + horizontalBox.add(horizontalGlue); |
| 88 | + } |
| 89 | + } |
| 90 | + { |
| 91 | + Component verticalGlue = Box.createVerticalGlue(); |
| 92 | + verticalBox.add(verticalGlue); |
| 93 | + } |
| 94 | + { |
| 95 | + Box horizontalBox = Box.createHorizontalBox(); |
| 96 | + verticalBox.add(horizontalBox); |
| 97 | + { |
| 98 | + operationLabel = new JLabel("Current running operation"); |
| 99 | + horizontalBox.add(operationLabel); |
| 100 | + } |
| 101 | + { |
| 102 | + Component horizontalGlue = Box.createHorizontalGlue(); |
| 103 | + horizontalBox.add(horizontalGlue); |
| 104 | + } |
| 105 | + } |
| 106 | + { |
| 107 | + Component verticalStrut = Box.createVerticalStrut(20); |
| 108 | + verticalStrut.setPreferredSize(new Dimension(0, 5)); |
| 109 | + verticalStrut.setMinimumSize(new Dimension(0, 5)); |
| 110 | + verticalBox.add(verticalStrut); |
| 111 | + } |
| 112 | + { |
| 113 | + progressBar = new JProgressBar(); |
| 114 | + progressBar.setStringPainted(true); |
| 115 | + progressBar.setValue(10); |
| 116 | + progressBar.setSize(new Dimension(0, 30)); |
| 117 | + progressBar.setMinimumSize(new Dimension(10, 30)); |
| 118 | + progressBar.setMaximumSize(new Dimension(32767, 30)); |
| 119 | + verticalBox.add(progressBar); |
| 120 | + } |
| 121 | + } |
| 122 | + { |
| 123 | + JPanel buttonPane = new JPanel(); |
| 124 | + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
| 125 | + getContentPane().add(buttonPane, BorderLayout.SOUTH); |
| 126 | + { |
| 127 | + cancelButton = new JButton("Cancel"); |
| 128 | + cancelButton.setActionCommand("Cancel"); |
| 129 | + buttonPane.add(cancelButton); |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + public void onCancel(ActionListener listener) { |
| 135 | + cancelButton.addActionListener(listener); |
| 136 | + } |
| 137 | + |
| 138 | + public void setOperationText(String message) { |
| 139 | + operationLabel.setText(message); |
| 140 | + } |
| 141 | + |
| 142 | + public void setProgress(int progress) { |
| 143 | + progressBar.setValue(progress); |
| 144 | + } |
| 145 | + |
| 146 | + public void attach(ContributionInstaller installer) { |
| 147 | + installer.setListener(new Listener() { |
| 148 | + @Override |
| 149 | + public void onProgress(double progress, String message) { |
| 150 | + setOperationText(message); |
| 151 | + setProgress((int) progress); |
| 152 | + } |
| 153 | + }); |
| 154 | + } |
| 155 | +} |
0 commit comments