Branch libreoffice-5-0-4
[LibreOffice.git] / scripting / examples / java / Newsgroup / StatusWindow.java
blob7b37c8fa79d004c7ebdce22f08791cc9f813be70
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package org.libreoffice.example.java_scripts;
21 import java.awt.*;
22 import java.awt.event.*;
23 import javax.swing.*;
24 import javax.swing.border.*;
26 public class StatusWindow extends JFrame {
28 private JProgressBar progressBar = null;
29 private JTextField statusLabel = null;
30 private JButton cancelButton = null;
31 private JFrame statusWindow = null;
32 private PostNewsgroup mainWindow = null;
34 private final int MAXPROGRESS = 13;
35 private final int MINPROGRESS = 0;
38 public StatusWindow(PostNewsgroup mw, String title, int parentX, int parentY) {
39 this.setTitle(title);
40 this.setLocation(parentX + 100, parentY + 100);
41 statusWindow = this;
42 mainWindow = mw;
44 mainWindow.enableButtons(false);
46 statusWindow.addWindowListener(new WindowAdapter() {
47 public void windowClosing(WindowEvent event) {
48 mainWindow.enableButtons(true);
50 });
52 progressBar = new JProgressBar();
53 progressBar.setStringPainted(true);
54 progressBar.setMaximum(MAXPROGRESS);
55 progressBar.setMinimum(MINPROGRESS);
56 progressBar.setSize(30, 400);
58 JLabel progLabel = new JLabel("Progress:");
60 JPanel progressPanel = new JPanel();
61 progressPanel.setLayout(new BorderLayout(10, 0));
62 progressPanel.add(progLabel, "West");
63 progressPanel.add(progressBar, "East");
65 statusLabel = new JTextField();
66 statusLabel.setColumns(25);
67 statusLabel.setEditable(false);
68 statusLabel.setBorder(null);
69 JPanel statusPanel = new JPanel();
70 statusPanel.setLayout(new BorderLayout());
71 statusPanel.add(statusLabel, "West");
73 cancelButton = new JButton("Cancel");
74 cancelButton.setSize(30, 100);
75 cancelButton.setEnabled(false);
76 cancelButton.addActionListener(new ActionListener() {
77 public void actionPerformed(ActionEvent event) {
78 // cancelling actions
79 mainWindow.enableButtons(true);
80 statusWindow.dispose();
82 });
84 JPanel buttonPanel = new JPanel();
85 buttonPanel.setLayout(new BorderLayout(0, 5));
86 buttonPanel.add(cancelButton, "East");
87 buttonPanel.add(new JSeparator(SwingConstants.HORIZONTAL), "North");
89 Container container = getContentPane();
90 container.setLayout(new GridBagLayout());
91 GridBagConstraints constraints = new GridBagConstraints();
92 constraints.fill = GridBagConstraints.BOTH;
94 constraints.gridx = 0;
95 constraints.gridy = 0;
96 constraints.gridwidth = 1;
97 constraints.gridheight = 1;
98 constraints.insets = new Insets(15, 15, 10, 15);
99 container.add(progressPanel, constraints);
101 constraints.gridx = 0;
102 constraints.gridy = 1;
103 constraints.gridwidth = 1;
104 constraints.gridheight = 1;
105 constraints.insets = new Insets(10, 15, 10, 15);
106 container.add(statusPanel, constraints);
108 constraints.gridx = 0;
109 constraints.gridy = 2;
110 constraints.gridwidth = 1;
111 constraints.gridheight = 1;
112 constraints.insets = new Insets(10, 15, 5, 15);
113 container.add(buttonPanel, constraints);
115 this.pack();
116 this.setResizable(false);
121 public void setStatus(int progress, String status) {
122 progressBar.setValue(progress);
123 statusLabel.setText(status);
124 statusLabel.setToolTipText(status);
126 if (progress == MAXPROGRESS) {
127 cancelButton.setEnabled(true);
128 cancelButton.setText("Close");
131 update(getGraphics());
132 mainWindow.update(mainWindow.getGraphics());
136 public void enableCancelButton(boolean enable) {
137 if (enable) {
138 cancelButton.setEnabled(true);
139 cancelButton.setText("Finish");
140 } else {
141 cancelButton.setEnabled(false);
142 cancelButton.setText("Cancel");