Search in sources :

Example 6 with JWindow

use of javax.swing.JWindow in project intellij-community by JetBrains.

the class HeavyWeightPopupCache method create.

/**
   * Returns a cached window or creates a new one if cache is empty.
   *
   * @param owner the window from which a popup is displayed
   * @return a window for the specified owner
   */
public static Window create(Window owner) {
    if (owner != null) {
        HeavyWeightPopupCache cache = getCache(owner);
        if (cache != null) {
            Window popup = cache.poll();
            if (popup != null)
                return popup;
        }
    }
    Window popup = new JWindow(owner);
    popup.setType(Window.Type.POPUP);
    return popup;
}
Also used : JWindow(javax.swing.JWindow) Window(java.awt.Window) JWindow(javax.swing.JWindow)

Example 7 with JWindow

use of javax.swing.JWindow in project gephi by gephi.

the class JPopupPane method showPopupPane.

public void showPopupPane() {
    if (pane == null) {
        pane = new JPopupPaneComponent();
    }
    if (popupWindow == null) {
        popupWindow = new JWindow(WindowManager.getDefault().getMainWindow());
    }
    popupWindow.getContentPane().add(pane);
    showingPopup = true;
    Toolkit.getDefaultToolkit().addAWTEventListener(hideListener, AWTEvent.MOUSE_EVENT_MASK);
    WindowManager.getDefault().getMainWindow().addWindowStateListener(hideListener);
    WindowManager.getDefault().getMainWindow().addComponentListener(hideListener);
    resizePopup();
    popupWindow.setVisible(true);
    pane.requestFocus();
}
Also used : JWindow(javax.swing.JWindow)

Example 8 with JWindow

use of javax.swing.JWindow 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 9 with JWindow

use of javax.swing.JWindow in project Spark by igniterealtime.

the class RoarPanel method popupWindow.

/**
 * Creates a popupwindow with specified items, displays it for given time,
 * and notifies its owner on closure
 *
 * @param owner
 *            , the owner of this Panel
 * @param icon
 *            , the icon to display
 * @param head
 *            , the header
 * @param text
 *            , the message body
 * @param x
 *            , the x locaiton on screen
 * @param y
 *            , the y location on screen
 * @param duration
 *            , the display duration
 * @param backgroundcolor
 *            , the background color
 * @param headercolor
 *            , the headertext color
 * @param textcolor
 *            , the messagebody color
 */
public static void popupWindow(final RoarDisplayType owner, Icon icon, String head, String text, int x, int y, int duration, Color backgroundcolor, Color headercolor, Color textcolor, final Action action) {
    final JWindow window = createWindow(icon, head, text, x, y, backgroundcolor, headercolor, textcolor);
    fadein(window);
    if (duration > 0) {
        TimerTask closeTimer = new TimerTask() {

            public void run() {
                closePanel(owner, window);
            }
        };
        Timer t = new Timer();
        t.schedule(closeTimer, duration);
    }
    window.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            action.actionPerformed(null);
            closePanel(owner, window);
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) TimerTask(java.util.TimerTask) Timer(java.util.Timer) JWindow(javax.swing.JWindow) MouseAdapter(java.awt.event.MouseAdapter)

Example 10 with JWindow

use of javax.swing.JWindow in project CCDD by nasa.

the class CcddConstants method setLaFAdjustments.

/**
 ********************************************************************************************
 * Set GUI adjustment(s) based on the selected look & feel
 *
 * @param lookAndFeel
 *            name of the look & feel in effect
 ********************************************************************************************
 */
protected static void setLaFAdjustments(String lookAndFeel) {
    // Find the width, in pixels, needed to display a vertical scroll bar by creating a dummy
    // scroll bar. Set the scroll bar to null afterwards to free up its memory
    JScrollPane sp = new JScrollPane(null, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    LAF_SCROLL_BAR_WIDTH = sp.getPreferredSize().width * 2 + 2;
    sp = null;
    // Determine the height, in pixels, of a check box and check box icon. The correct height
    // is not returned by the UI manager for all look & feels unless the check box is first
    // realized, so an invisible window is created, a check box instantiated, then the window
    // removed. The check box height returned by the UI manager is now correct
    JWindow wndw = new JWindow();
    JCheckBox chbx = new JCheckBox();
    chbx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    wndw.add(chbx);
    wndw.pack();
    LAF_CHECK_BOX_HEIGHT = chbx.getHeight();
    wndw.dispose();
}
Also used : JScrollPane(javax.swing.JScrollPane) JCheckBox(javax.swing.JCheckBox) JWindow(javax.swing.JWindow)

Aggregations

JWindow (javax.swing.JWindow)23 JLabel (javax.swing.JLabel)10 Dimension (java.awt.Dimension)8 JPanel (javax.swing.JPanel)8 Window (java.awt.Window)7 JFrame (javax.swing.JFrame)7 MouseEvent (java.awt.event.MouseEvent)6 JButton (javax.swing.JButton)6 Color (java.awt.Color)5 Point (java.awt.Point)5 ActionEvent (java.awt.event.ActionEvent)5 MouseAdapter (java.awt.event.MouseAdapter)5 JComponent (javax.swing.JComponent)5 Frame (java.awt.Frame)4 GraphicsConfiguration (java.awt.GraphicsConfiguration)4 Image (java.awt.Image)4 ActionListener (java.awt.event.ActionListener)4 BorderLayout (java.awt.BorderLayout)3 Graphics2D (java.awt.Graphics2D)3 BufferedImage (java.awt.image.BufferedImage)3