下面列出了javax.swing.JProgressBar#setString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void updateTransferProgress(LogFile logFile, int progress)
{
JProgressBar jpb = _transferTableModel.getJProgressBar(logFile.getName());
jpb.setValue(progress);
jpb.setString(progress+"%");
SwingUtilities.invokeLater
(
new Runnable(){
public void run()
{
TransferPanel.this.getTranferTable().updateUI();
}
}
);
}
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
if(value instanceof ProgressWatcher.Operation &&
!(value instanceof ProgressWatcher.ThreadInfo)) {
ProgressWatcher.Operation op = (ProgressWatcher.Operation)value;
if(op.getUserObject() == null) {
JProgressBar pb = new JProgressBar(op.progress);
pb.setString(op.description);
pb.setStringPainted(true);
op.setUserObject(pb);
}
return (Component)op.getUserObject();
}
else {
JLabel l = (JLabel)old.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
l.setIcon(Resource.THREAD);
return l;
}
}
public Progressbar() {
super(new BorderLayout());
((BorderLayout)getLayout()).setHgap(20);
setBorder(BorderFactory.createEmptyBorder(10,5,5,5));
label = new JLabel("Creating tree structure");
Font font = label.getFont().deriveFont(Font.PLAIN,12);
label.setFont(font);
add(label,BorderLayout.WEST);
progressbar = new JProgressBar(0,100);
progressbar.setValue(-1);
progressbar.setStringPainted(true);
progressbar.setString("");
progressbar.setIndeterminate(true);
add(progressbar,BorderLayout.CENTER);
}
private void createTabs(JFrame frame) {
frame.getContentPane().setLayout(new BorderLayout());
JTabbedPane tabs = new JTabbedPane();
frame.getContentPane().add(tabs, BorderLayout.CENTER);
progress = new JProgressBar();
progress.setString("");
progress.setStringPainted(true);
frame.getContentPane().add(progress, BorderLayout.SOUTH);
progress.setString("Est. progress: 0% Elapsed time: 00:00:00 Est. time left: N/A");
Font orig = progress.getFont();
progress.setFont(new Font(orig.getFamily(), Font.BOLD, orig.getSize() + 1));
SummaryPanel summary = new SummaryPanel(getState());
tabs.add("Summary", summary);
GraphsPanel graphs = new GraphsPanel(getState());
tabs.add("Graphs", graphs);
StatefulItemClassSet<ApplicationItem> appSet =
getState().getItemClassSet(StatefulItemClass.APPLICATION);
ClassRenderer applications = new ApplicationTable("Applications", appSet);
tablemap.put(StatefulItemClass.APPLICATION, applications);
tabs.add("Applications", (Component) applications);
StatefulItemClassSet<TaskItem> taskSet =
getState().getItemClassSet(StatefulItemClass.TASK);
ClassRenderer tasks = new TasksRenderer("Tasks", taskSet);
tablemap.put(StatefulItemClass.TASK, tasks);
tabs.add("Tasks", (Component) tasks);
gantt = new GanttChart(getState());
tabs.add("Gantt Chart", gantt);
}
private JProgressBar makeProgress(SpringLayout sl, JLabel label) {
if (label != null) {
add(label);
}
JProgressBar pb = new JProgressBar();
pb.setString("");
pb.setStringPainted(true);
add(pb);
fixEdges(sl, label, pb, this);
return pb;
}
public void addLogDownload(LogFile logFile)
{
if (RemoteLogRepositoryBackend.getInstance().isConnected())
{
RemoteLogRepositoryBackend.getInstance().enqueueDownload(logFile);
JProgressBar jpb = new JProgressBar();
jpb.setStringPainted(true);
jpb.setString("Requesting");
this._middlePanel._downloadsPanel.addRow(new JLabel(logFile.getName()), jpb);
}
}
public void addLogUpload(LogFile logFile)
{
if (RemoteLogRepositoryBackend.getInstance().isConnected())
{
RemoteLogRepositoryBackend.getInstance().enqueueUpload(logFile);
JProgressBar jpb = new JProgressBar();
jpb.setStringPainted(true);
jpb.setString("Requesting");
this._middlePanel._uploadsPanel.addRow(new JLabel(logFile.getName()), jpb);
}
}
protected void setupInstance(JProgressBar instance) {
super.setupInstance(instance);
instance.setBorderPainted(paintBorder);
if (model != null) instance.setModel(model.createInstance());
if (progressString != null) instance.setString(progressString);
instance.setStringPainted(paintString);
instance.setIndeterminate(indeterminate);
}
protected void setupInstance(JProgressBar instance) {
super.setupInstance(instance);
instance.setBorderPainted(paintBorder);
if (model != null) instance.setModel(model.createInstance());
if (progressString != null) instance.setString(progressString);
instance.setStringPainted(paintString);
instance.setIndeterminate(indeterminate);
}
public TimerFrame() {
setUndecorated(true);
getContentPane().setBackground(Color.lightGray);
setShape(new RoundRectangle2D.Double(0, -20, GlobalSettings.WIDTH/2, 44, 20, 20));
setSize(GlobalSettings.WIDTH/2, 24);
setLocation(getX(), 0);
horizontalPositioner.tick();
setAlwaysOnTop(true);
setFocusable(false);
setType(Type.UTILITY);
setFocusableWindowState(false);
getContentPane().setLayout(new BorderLayout());
progressBar = new JProgressBar();
progressBar.setForeground(Color.lightGray);
progressBar.setBackground(Color.GREEN);
progressBar.setString("1 min");
progressBar.setStringPainted(true);
progressBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
progressBar.setBorderPainted(false);
progressBar.setValue(50);
progressBar.setFont(new Font("Consolas", Font.BOLD, 19));
progressBar.addMouseListener(new ProgressMouseListener());
progressBar.setCursor(new Cursor(Cursor.HAND_CURSOR));
getContentPane().add(progressBar);
}
/**
* Create the dialog to show the progress
*/
private void createProgressDialog()
{
_progressDialog = new JDialog(_parentFrame, I18nManager.getText(_dialogTitleKey));
_progressDialog.setLocationRelativeTo(_parentFrame);
_progressBar = new JProgressBar(0, 100);
_progressBar.setValue(0);
_progressBar.setStringPainted(true);
_progressBar.setString("");
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
panel.add(new JLabel(I18nManager.getText(_labelKey)));
panel.add(_progressBar);
panel.add(Box.createVerticalStrut(6)); // spacer
JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
_function.cancel();
}
});
panel.add(cancelButton);
_progressDialog.getContentPane().add(panel);
_progressDialog.pack();
_progressDialog.setVisible(true);
}
private void makeProgressBars(SpringLayout l) {
JComponent prevLabel = null, prevBar = null;
bars = new JProgressBar[SummaryItem.STATES.length];
SpringLayout ls = new SpringLayout();
JPanel appSummary = new JPanel();
appSummary.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "App Summary"));
add(appSummary);
l.putConstraint(SpringLayout.WEST, appSummary, 5, SpringLayout.WEST, this);
l.putConstraint(SpringLayout.EAST, appSummary, -5, SpringLayout.EAST, this);
l.putConstraint(SpringLayout.NORTH, appSummary, 25, SpringLayout.NORTH, this);
appSummary.setLayout(ls);
for (int i = 0; i < SummaryItem.STATES.length; i++) {
JLabel label = new JLabel(SummaryItem.STATES[i] + ":");
appSummary.add(label);
JProgressBar lb = new JProgressBar();
bars[i] = lb;
lb.setString("0");
lb.setStringPainted(true);
appSummary.add(lb);
fixEdges(ls, label, lb, appSummary);
if (prevLabel == null) {
ls.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, appSummary);
}
else {
ls.putConstraint(SpringLayout.NORTH, label, 10, SpringLayout.SOUTH, prevLabel);
}
prevLabel = label;
prevBar = lb;
}
JLabel hl = new JLabel("Heap:");
memory = makeProgress(l, hl);
l.putConstraint(SpringLayout.SOUTH, appSummary, -25, SpringLayout.NORTH, hl);
l.putConstraint(SpringLayout.SOUTH, hl, -25, SpringLayout.SOUTH, this);
Spring maxW = Spring.constant(0);
for (int i = 0; i < SummaryItem.STATES.length; i++) {
maxW = Spring.max(maxW, ls.getConstraints(appSummary.getComponent(i * 2)).getWidth());
}
for (int i = 0; i < SummaryItem.STATES.length; i++) {
SpringLayout.Constraints c = ls.getConstraints(appSummary.getComponent(i * 2));
c.setWidth(maxW);
}
}
private void installPlugin(final File plugin) {
final JDialog dialog = new JDialog(frame, "Installing Plugin", true);
dialog.getContentPane().setLayout(new BorderLayout());
JProgressBar bar = new JProgressBar();
bar.setIndeterminate(true);
bar.setString("Installing Plugin. Please wait...");
bar.setStringPainted(true);
dialog.getContentPane().add(bar, BorderLayout.CENTER);
dialog.pack();
dialog.setSize(225, 55);
final SwingWorker<File, Void> installerThread = new SwingWorker<File, Void>() {
@Override
public File doInBackground() {
File pluginsDir = new File(binDir.getParentFile(), "plugins");
String tempName = plugin.getName() + ".part";
File tempPluginsFile = new File(pluginsDir, tempName);
File realPluginsFile = new File(pluginsDir, plugin.getName());
// Copy Plugin into Dir.
try {
// Just for fun. Show no matter what for two seconds.
Thread.sleep(2000);
copy(plugin.toURI().toURL(), tempPluginsFile);
// If successfull, rename to real plugin name.
tempPluginsFile.renameTo(realPluginsFile);
}
catch (Exception e) {
e.printStackTrace();
}
return realPluginsFile;
}
@Override
public void done() {
dialog.setVisible(false);
}
};
// Start installation
installerThread.execute();
dialog.setLocationRelativeTo(frame);
dialog.setVisible(true);
}
private String removeNesting(double error, double timeStep, String prop, JProgressBar progress) throws BioSimException {
if (prop.contains("Pr=?{") || prop.contains("St=?{")) {
if (progress != null) {
progress.setString("Determining Sat Sets.");
}
int transientPropIndex = prop.indexOf("Pr=?{");
int steadyStatePropIndex = prop.indexOf("St=?{");
if (transientPropIndex == -1) {
transientPropIndex = Integer.MAX_VALUE;
}
if (steadyStatePropIndex == -1) {
steadyStatePropIndex = Integer.MAX_VALUE;
}
int index = 0;
if (transientPropIndex < steadyStatePropIndex) {
index = transientPropIndex;
}
else {
index = steadyStatePropIndex;
}
String newProp = prop.substring(0, index);
String cond = prop.substring(index);
String nest;
if (transientPropIndex < steadyStatePropIndex) {
nest = "Pr=?{";
}
else {
nest = "St=?{";
}
int braces = 1;
for (int i = 5; i < cond.length(); i++) {
char c = cond.charAt(i);
if (c == '{') {
braces++;
}
else if (c == '}') {
braces--;
}
nest += c;
index = i;
if (braces == 0) {
break;
}
}
index++;
cond = cond.substring(index);
String check = nest.substring(5, nest.length() - 1);
if (check.contains("Pr=?{") || check.contains("St=?{")) {
if (transientPropIndex < steadyStatePropIndex) {
nest = "Pr=?{" + removeNesting(error, timeStep, check, progress) + "}";
}
else {
nest = "St=?{" + removeNesting(error, timeStep, check, progress) + "}";
}
}
newProp += determineNestedProbability(error, timeStep, nest)
+ removeNesting(error, timeStep, cond, progress);
return newProp;
}
return prop;
}
private String removeNesting(double error, double timeStep, String prop, JProgressBar progress) throws BioSimException {
if (prop.contains("Pr=?{") || prop.contains("St=?{")) {
if (progress != null) {
progress.setString("Determining Sat Sets.");
}
int transientPropIndex = prop.indexOf("Pr=?{");
int steadyStatePropIndex = prop.indexOf("St=?{");
if (transientPropIndex == -1) {
transientPropIndex = Integer.MAX_VALUE;
}
if (steadyStatePropIndex == -1) {
steadyStatePropIndex = Integer.MAX_VALUE;
}
int index = 0;
if (transientPropIndex < steadyStatePropIndex) {
index = transientPropIndex;
}
else {
index = steadyStatePropIndex;
}
String newProp = prop.substring(0, index);
String cond = prop.substring(index);
String nest;
if (transientPropIndex < steadyStatePropIndex) {
nest = "Pr=?{";
}
else {
nest = "St=?{";
}
int braces = 1;
for (int i = 5; i < cond.length(); i++) {
char c = cond.charAt(i);
if (c == '{') {
braces++;
}
else if (c == '}') {
braces--;
}
nest += c;
index = i;
if (braces == 0) {
break;
}
}
index++;
cond = cond.substring(index);
String check = nest.substring(5, nest.length() - 1);
if (check.contains("Pr=?{") || check.contains("St=?{")) {
if (transientPropIndex < steadyStatePropIndex) {
nest = "Pr=?{" + removeNesting(error, timeStep, check, progress) + "}";
}
else {
nest = "St=?{" + removeNesting(error, timeStep, check, progress) + "}";
}
}
newProp += determineNestedProbability(error, timeStep, nest)
+ removeNesting(error, timeStep, cond, progress);
return newProp;
}
return prop;
}
private void updateProgress(final ProgressType progressType, final int value, final int max) {
final String sizeText = getSizeText(value);
this.transferSizeField.setValue(sizeText);
final long newTimestamp = System.currentTimeMillis();
final double lastTransferRate = this.lastTransferRate;
final long lastProgressValue = this.lastProgressValue;
final long lastTimestamp = this.lastTimestamp;
final long elapsed = newTimestamp - lastTimestamp;
double newTransferRate = Double.NaN;
if (elapsed > 0) {
newTransferRate = (value - lastProgressValue) / elapsed;
if (!Double.isNaN(lastTransferRate)) {
// Weighed average
newTransferRate = (newTransferRate + (lastTransferRate * 5.0)) / 6.0;
}
}
if (!Double.isNaN(newTransferRate)) {
this.transferRateField.setValue(round1(newTransferRate) + " Kb/sec");
final int cl = this.knownContentLength;
if ((cl > 0) && (newTransferRate > 0)) {
this.timeLeftField.setValue(Timing.getElapsedText((long) ((cl - value) / newTransferRate)));
}
}
this.lastTimestamp = newTimestamp;
this.lastProgressValue = value;
this.lastTransferRate = newTransferRate;
final JProgressBar pb = this.progressBar;
if (progressType == ProgressType.CONNECTING) {
pb.setIndeterminate(true);
pb.setStringPainted(true);
pb.setString("Connecting...");
this.setTitle(this.destinationField.getValue() + ": Connecting...");
} else if (max <= 0) {
pb.setIndeterminate(true);
pb.setStringPainted(false);
this.setTitle(sizeText + " " + this.destinationField.getValue());
} else {
final int percent = (value * 100) / max;
pb.setIndeterminate(false);
pb.setStringPainted(true);
pb.setMaximum(max);
pb.setValue(value);
final String percentText = percent + "%";
pb.setString(percentText);
this.setTitle(percentText + " " + this.destinationField.getValue());
}
}