Search in sources :

Example 11 with JProgressBar

use of javax.swing.JProgressBar in project processdash by dtuma.

the class ProgressDialog method init.

private void init(Component parent, String message) {
    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    JPanel dialogContents = new JPanel(new BorderLayout(5, 5));
    dialogContents.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(dialogContents);
    if (message == null)
        message = "Please wait...";
    messageLabel = new JLabel(message);
    progressBar = new JProgressBar();
    dialogContents.add(messageLabel, BorderLayout.NORTH);
    dialogContents.add(progressBar, BorderLayout.CENTER);
    closeButton = new JButton("Cancel");
    closeButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (running)
                cancelled = true;
            else
                dispose();
        }
    });
    closePanel = borderComponent(closeButton);
    closePanel.setVisible(false);
    dialogContents.add(closePanel, BorderLayout.SOUTH);
    pack();
    setLocationRelativeTo(parent);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JProgressBar(javax.swing.JProgressBar) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel)

Example 12 with JProgressBar

use of javax.swing.JProgressBar in project android_frameworks_base by crdroidandroid.

the class UI method showWaitDialog.

public void showWaitDialog() {
    if (currentWaitDialog == null) {
        currentWaitDialog = new JDialog(this, "Please wait...", true);
        currentWaitDialog.getContentPane().add(new JLabel("Please be patient."), BorderLayout.CENTER);
        JProgressBar progress = new JProgressBar(JProgressBar.HORIZONTAL);
        progress.setIndeterminate(true);
        currentWaitDialog.getContentPane().add(progress, BorderLayout.SOUTH);
        currentWaitDialog.setSize(200, 100);
        currentWaitDialog.setLocationRelativeTo(null);
        showWaitDialogLater();
    }
}
Also used : JProgressBar(javax.swing.JProgressBar) JLabel(javax.swing.JLabel) JDialog(javax.swing.JDialog)

Example 13 with JProgressBar

use of javax.swing.JProgressBar in project JMRI by JMRI.

the class PaneProgPane method printPane.

public void printPane(HardcopyWriter w) {
    // if pane is empty, don't print anything
    if (varList.isEmpty() && cvList.isEmpty()) {
        return;
    }
    // future work needed here to print indexed CVs
    // Define column widths for name and value output.
    // Make col 2 slightly larger than col 1 and reduce both to allow for
    // extra spaces that will be added during concatenation
    int col1Width = w.getCharactersPerLine() / 2 - 3 - 5;
    int col2Width = w.getCharactersPerLine() / 2 - 3 + 5;
    try {
        //Create a string of spaces the width of the first column
        StringBuilder spaces = new StringBuilder();
        for (int i = 0; i < col1Width; i++) {
            spaces.append(" ");
        }
        // start with pane name in bold
        String heading1 = SymbolicProgBundle.getMessage("PrintHeadingField");
        String heading2 = SymbolicProgBundle.getMessage("PrintHeadingSetting");
        String s;
        int interval = spaces.length() - heading1.length();
        w.setFontStyle(Font.BOLD);
        // write the section name and dividing line
        s = mName.toUpperCase();
        w.write(s, 0, s.length());
        w.writeBorders();
        //Draw horizontal dividing line for each Pane section
        w.write(w.getCurrentLineNumber(), 0, w.getCurrentLineNumber(), w.getCharactersPerLine() + 1);
        s = "\n";
        w.write(s, 0, s.length());
        // if this isn't the raw CV section, write the column headings
        if (cvList.isEmpty()) {
            w.setFontStyle(Font.BOLD + Font.ITALIC);
            s = "   " + heading1 + spaces.substring(0, interval) + "   " + heading2;
            w.write(s, 0, s.length());
            w.writeBorders();
            s = "\n";
            w.write(s, 0, s.length());
        }
        w.setFontStyle(Font.PLAIN);
        // Define a vector to store the names of variables that have been printed
        // already.  If they have been printed, they will be skipped.
        // Using a vector here since we don't know how many variables will
        // be printed and it allows expansion as necessary
        ArrayList<String> printedVariables = new ArrayList<>(10);
        // index over variables
        for (int i = 0; i < varList.size(); i++) {
            int varNum = varList.get(i);
            VariableValue var = _varModel.getVariable(varNum);
            String name = var.label();
            if (name == null) {
                name = var.item();
            }
            // Check if variable has been printed.  If not store it and print
            boolean alreadyPrinted = false;
            for (String printedVariable : printedVariables) {
                if (name.equals(printedVariable)) {
                    alreadyPrinted = true;
                }
            }
            //If already printed, skip it.  If not, store it and print
            if (alreadyPrinted == true) {
                continue;
            }
            printedVariables.add(name);
            String value = var.getTextValue();
            String originalName = name;
            String originalValue = value;
            // NO I18N
            name = name + " (CV" + var.getCvNum() + ")";
            //define index values for name and value substrings
            int nameLeftIndex = 0;
            int nameRightIndex = name.length();
            int valueLeftIndex = 0;
            int valueRightIndex = value.length();
            String trimmedName;
            String trimmedValue;
            // before writing - if split, repeat until all pieces have been output
            while ((valueLeftIndex < value.length()) || (nameLeftIndex < name.length())) {
                // name split code
                if (name.substring(nameLeftIndex).length() > col1Width) {
                    for (int j = 0; j < col1Width; j++) {
                        String delimiter = name.substring(nameLeftIndex + col1Width - j - 1, nameLeftIndex + col1Width - j);
                        if (delimiter.equals(" ") || delimiter.equals(";") || delimiter.equals(",")) {
                            nameRightIndex = nameLeftIndex + col1Width - j;
                            break;
                        }
                    }
                    trimmedName = name.substring(nameLeftIndex, nameRightIndex);
                    nameLeftIndex = nameRightIndex;
                    int space = spaces.length() - trimmedName.length();
                    s = "   " + trimmedName + spaces.substring(0, space);
                } else {
                    trimmedName = name.substring(nameLeftIndex);
                    int space = spaces.length() - trimmedName.length();
                    s = "   " + trimmedName + spaces.substring(0, space);
                    name = "";
                    nameLeftIndex = 0;
                }
                // value split code
                if (value.substring(valueLeftIndex).length() > col2Width) {
                    for (int j = 0; j < col2Width; j++) {
                        String delimiter = value.substring(valueLeftIndex + col2Width - j - 1, valueLeftIndex + col2Width - j);
                        if (delimiter.equals(" ") || delimiter.equals(";") || delimiter.equals(",")) {
                            valueRightIndex = valueLeftIndex + col2Width - j;
                            break;
                        }
                    }
                    trimmedValue = value.substring(valueLeftIndex, valueRightIndex);
                    valueLeftIndex = valueRightIndex;
                    s = s + "   " + trimmedValue;
                } else {
                    trimmedValue = value.substring(valueLeftIndex);
                    s = s + "   " + trimmedValue;
                    valueLeftIndex = 0;
                    value = "";
                }
                w.write(s, 0, s.length());
                w.writeBorders();
                s = "\n";
                w.write(s, 0, s.length());
            }
            // Check for a Speed Table output and create a graphic display.
            // Java 1.5 has a known bug, #6328248, that prevents printing of progress
            //  bars using old style printing classes.  It results in blank bars on Windows,
            //  but hangs Macs. The version check is a workaround.
            float v = Float.valueOf(java.lang.System.getProperty("java.version").substring(0, 3));
            if (originalName.equals("Speed Table") && v < 1.5) {
                // set the height of the speed table graph in lines
                int speedFrameLineHeight = 11;
                s = "\n";
                // check that there is enough room on the page; if not,
                // space down the rest of the page.
                // don't use page break because we want the table borders to be written
                // to the bottom of the page
                int pageSize = w.getLinesPerPage();
                int here = w.getCurrentLineNumber();
                if (pageSize - here < speedFrameLineHeight) {
                    for (int j = 0; j < (pageSize - here); j++) {
                        w.writeBorders();
                        w.write(s, 0, s.length());
                    }
                }
                // Now that there is page space, create the window to hold the graphic speed table
                JWindow speedWindow = new JWindow();
                // Window size as wide as possible to allow for largest type size
                speedWindow.setSize(512, 165);
                speedWindow.getContentPane().setBackground(Color.white);
                speedWindow.getContentPane().setLayout(null);
                // in preparation for display, extract the speed table values into an array
                StringTokenizer valueTokens = new StringTokenizer(originalValue, ",", false);
                int[] speedVals = new int[28];
                int k = 0;
                while (valueTokens.hasMoreTokens()) {
                    speedVals[k] = Integer.parseInt(valueTokens.nextToken());
                    k++;
                }
                // on the speed table value (half height) and add them to the window
                for (int j = 0; j < 28; j++) {
                    JProgressBar printerBar = new JProgressBar(JProgressBar.VERTICAL, 0, 127);
                    printerBar.setBounds(52 + j * 15, 19, 10, 127);
                    printerBar.setValue(speedVals[j] / 2);
                    printerBar.setBackground(Color.white);
                    printerBar.setForeground(Color.darkGray);
                    printerBar.setBorder(BorderFactory.createLineBorder(Color.black));
                    speedWindow.getContentPane().add(printerBar);
                    // create a set of value labels at the top containing the speed table values
                    JLabel barValLabel = new JLabel(Integer.toString(speedVals[j]), SwingConstants.CENTER);
                    barValLabel.setBounds(50 + j * 15, 4, 15, 15);
                    barValLabel.setFont(new java.awt.Font("Monospaced", 0, 7));
                    speedWindow.getContentPane().add(barValLabel);
                    //Create a set of labels at the bottom with the CV numbers in them
                    JLabel barCvLabel = new JLabel(Integer.toString(67 + j), SwingConstants.CENTER);
                    barCvLabel.setBounds(50 + j * 15, 150, 15, 15);
                    barCvLabel.setFont(new java.awt.Font("Monospaced", 0, 7));
                    speedWindow.getContentPane().add(barCvLabel);
                }
                JLabel cvLabel = new JLabel(Bundle.getMessage("Value"));
                cvLabel.setFont(new java.awt.Font("Monospaced", 0, 7));
                cvLabel.setBounds(25, 4, 26, 15);
                speedWindow.getContentPane().add(cvLabel);
                // I18N seems undesirable for support
                JLabel valueLabel = new JLabel("CV");
                valueLabel.setFont(new java.awt.Font("Monospaced", 0, 7));
                valueLabel.setBounds(37, 150, 13, 15);
                speedWindow.getContentPane().add(valueLabel);
                // pass the complete window to the printing class
                w.write(speedWindow);
                // Now need to write the borders on sides of table
                for (int j = 0; j < speedFrameLineHeight; j++) {
                    w.writeBorders();
                    w.write(s, 0, s.length());
                }
            }
        }
        final int TABLE_COLS = 3;
        // index over CVs
        if (cvList.size() > 0) {
            //            Check how many Cvs there are to print
            int cvCount = cvList.size();
            //set font to Bold
            w.setFontStyle(Font.BOLD);
            // print a simple heading with I18N
            s = String.format("%1$21s", Bundle.getMessage("Value")) + String.format("%1$28s", Bundle.getMessage("Value")) + String.format("%1$28s", Bundle.getMessage("Value"));
            w.write(s, 0, s.length());
            w.writeBorders();
            s = "\n";
            w.write(s, 0, s.length());
            // NO I18N
            s = "            CV  Dec Hex                 CV  Dec Hex                 CV  Dec Hex";
            w.write(s, 0, s.length());
            w.writeBorders();
            s = "\n";
            w.write(s, 0, s.length());
            //set font back to Normal
            w.setFontStyle(0);
            //           }
            /*create an array to hold CV/Value strings to allow reformatting and sorting
                 Same size as the table drawn above (TABLE_COLS columns*tableHeight; heading rows
                 not included). Use the count of how many CVs there are to determine the number
                 of table rows required.  Add one more row if the divison into TABLE_COLS columns
                 isn't even.
                 */
            int tableHeight = cvCount / TABLE_COLS;
            if (cvCount % TABLE_COLS > 0) {
                tableHeight++;
            }
            String[] cvStrings = new String[TABLE_COLS * tableHeight];
            //blank the array
            for (int j = 0; j < cvStrings.length; j++) {
                cvStrings[j] = "";
            }
            // get each CV and value
            int i = 0;
            for (int cvNum : cvList) {
                CvValue cv = _cvModel.getCvByRow(cvNum);
                int value = cv.getValue();
                //convert and pad numbers as needed
                String numString = String.format("%12s", cv.number());
                String valueString = Integer.toString(value);
                String valueStringHex = Integer.toHexString(value).toUpperCase();
                if (value < 16) {
                    valueStringHex = "0" + valueStringHex;
                }
                for (int j = 1; j < 3; j++) {
                    if (valueString.length() < 3) {
                        valueString = " " + valueString;
                    }
                }
                //Create composite string of CV and its decimal and hex values
                s = "  " + numString + "  " + valueString + "  " + valueStringHex + " ";
                //populate printing array - still treated as a single column
                cvStrings[i] = s;
                i++;
            }
            //sort the array in CV order (just the members with values)
            String temp;
            boolean swap = false;
            do {
                swap = false;
                for (i = 0; i < _cvModel.getRowCount() - 1; i++) {
                    if (PrintCvAction.cvSortOrderVal(cvStrings[i + 1].substring(0, 15).trim()) < PrintCvAction.cvSortOrderVal(cvStrings[i].substring(0, 15).trim())) {
                        temp = cvStrings[i + 1];
                        cvStrings[i + 1] = cvStrings[i];
                        cvStrings[i] = temp;
                        swap = true;
                    }
                }
            } while (swap == true);
            //Print the array in four columns
            for (i = 0; i < tableHeight; i++) {
                s = cvStrings[i] + "    " + cvStrings[i + tableHeight] + "    " + cvStrings[i + tableHeight * 2];
                w.write(s, 0, s.length());
                w.writeBorders();
                s = "\n";
                w.write(s, 0, s.length());
            }
        }
        s = "\n";
        w.writeBorders();
        w.write(s, 0, s.length());
        w.writeBorders();
        w.write(s, 0, s.length());
    // handle special cases
    } catch (IOException e) {
        log.warn("error during printing: " + e);
    }
}
Also used : VariableValue(jmri.jmrit.symbolicprog.VariableValue) Font(java.awt.Font) JWindow(javax.swing.JWindow) ArrayList(java.util.ArrayList) JProgressBar(javax.swing.JProgressBar) JLabel(javax.swing.JLabel) IOException(java.io.IOException) StringTokenizer(java.util.StringTokenizer) CvValue(jmri.jmrit.symbolicprog.CvValue)

Example 14 with JProgressBar

use of javax.swing.JProgressBar in project JMRI by JMRI.

the class BusyDialog method initComponents.

public void initComponents() {
    setLocationRelativeTo(frame);
    setPreferredSize(new Dimension(200, 100));
    setMinimumSize(new Dimension(200, 100));
    setLayout(new BorderLayout(10, 10));
    pbar = new JProgressBar();
    pbar.setIndeterminate(true);
    pbar.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
    //pbar.setBorderPainted(true);
    this.add(pbar, BorderLayout.CENTER);
}
Also used : BorderLayout(java.awt.BorderLayout) JProgressBar(javax.swing.JProgressBar) Dimension(java.awt.Dimension)

Example 15 with JProgressBar

use of javax.swing.JProgressBar in project JMRI by JMRI.

the class AbstractLoaderPane method initComponents.

@Override
public void initComponents() throws Exception {
    super.initComponents();
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    {
        /* Create panels for displaying a filename and for providing a file 
             * seleciton pushbutton
             */
        inputFileNamePanel = new JPanel();
        inputFileNamePanel.setLayout(new FlowLayout());
        JLabel l = new JLabel(Bundle.getMessage("LabelInpFile"));
        inputFileLabelWidth = l.getMinimumSize().width;
        l.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT);
        inputFileNamePanel.add(l);
        inputFileNamePanel.add(new Box.Filler(new java.awt.Dimension(5, 20), new java.awt.Dimension(5, 20), new java.awt.Dimension(5, 20)));
        inputFileNamePanel.add(inputFileName);
        add(inputFileNamePanel);
        JPanel p = new JPanel();
        p.setLayout(new FlowLayout());
        JButton selectButton = new JButton(Bundle.getMessage("ButtonSelect"));
        selectButton.addActionListener((ActionEvent e) -> {
            inputContent = new MemoryContents();
            setDefaultFieldValues();
            updateDownloadVerifyButtons();
            selectInputFile();
            doRead(chooser);
        });
        p.add(selectButton);
        add(p);
    }
    {
        // Create a panel for displaying the addressing type, via radio buttons
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        JLabel l = new JLabel(Bundle.getMessage("LabelBitMode") + " ");
        l.setEnabled(false);
        p.add(l);
        p.add(address16bit);
        p.add(address24bit);
        addressSizeButtonGroup.add(address16bit);
        addressSizeButtonGroup.add(address24bit);
        addressSizeButtonGroup.clearSelection();
        address16bit.setEnabled(false);
        address24bit.setEnabled(false);
        add(p);
    }
    setDefaultFieldValues();
    add(new JSeparator());
    addOptionsPanel();
    {
        // create a panel for the upload, verify, and abort buttons
        JPanel p = new JPanel();
        p.setLayout(new FlowLayout());
        loadButton = new JButton(Bundle.getMessage("ButtonLoad"));
        loadButton.setEnabled(false);
        loadButton.setToolTipText(Bundle.getMessage("TipLoadDisabled"));
        p.add(loadButton);
        loadButton.addActionListener((java.awt.event.ActionEvent e) -> {
            doLoad();
        });
        verifyButton = new JButton(Bundle.getMessage("ButtonVerify"));
        verifyButton.setEnabled(false);
        verifyButton.setToolTipText(Bundle.getMessage("TipVerifyDisabled"));
        p.add(verifyButton);
        verifyButton.addActionListener((java.awt.event.ActionEvent e) -> {
            doVerify();
        });
        add(p);
        abortButton = new JButton(Bundle.getMessage("ButtonAbort"));
        abortButton.setEnabled(false);
        abortButton.setToolTipText(Bundle.getMessage("TipAbortDisabled"));
        p.add(abortButton);
        abortButton.addActionListener((java.awt.event.ActionEvent e) -> {
            setOperationAborted(true);
        });
        add(p);
        add(new JSeparator());
        // create progress bar
        bar = new JProgressBar(0, 100);
        bar.setStringPainted(true);
        add(bar);
        add(new JSeparator());
        {
            // create a panel for displaying a status message
            p = new JPanel();
            p.setLayout(new FlowLayout());
            status.setText(Bundle.getMessage("StatusSelectFile"));
            status.setAlignmentX(JLabel.LEFT_ALIGNMENT);
            p.add(status);
            add(p);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JLabel(javax.swing.JLabel) ActionEvent(java.awt.event.ActionEvent) JSeparator(javax.swing.JSeparator) MemoryContents(jmri.jmrit.MemoryContents)

Aggregations

JProgressBar (javax.swing.JProgressBar)87 JLabel (javax.swing.JLabel)53 JPanel (javax.swing.JPanel)40 JButton (javax.swing.JButton)32 Dimension (java.awt.Dimension)30 BorderLayout (java.awt.BorderLayout)28 ActionEvent (java.awt.event.ActionEvent)20 JScrollPane (javax.swing.JScrollPane)20 ActionListener (java.awt.event.ActionListener)16 Insets (java.awt.Insets)14 IOException (java.io.IOException)14 GridBagConstraints (java.awt.GridBagConstraints)13 GridBagLayout (java.awt.GridBagLayout)13 FlowLayout (java.awt.FlowLayout)12 JCheckBox (javax.swing.JCheckBox)12 ArrayList (java.util.ArrayList)11 JDialog (javax.swing.JDialog)11 File (java.io.File)10 ImageIcon (javax.swing.ImageIcon)10 JComboBox (javax.swing.JComboBox)9