Search in sources :

Example 1 with IllegalComponentStateException

use of java.awt.IllegalComponentStateException in project jsql-injection by ron190.

the class CreateAdminPageTab method execute.

@Override
public void execute() {
    if (MediatorGui.tabResults() == null) {
        LOGGER.error("Unexpected unregistered MediatorGui.tabResults() in " + this.getClass());
    }
    String htmlSource = "";
    // Fix #44641: ExceptionInInitializerError on get()
    try {
        // Previous test for 2xx Success and 3xx Redirection was Header only,
        // now get the HTML content.
        // Proxy is used by jsoup
        htmlSource = Jsoup.clean(Jsoup.connect(this.url).get().html().replaceAll("<img.*>", "").replaceAll("<input.*type=\"?hidden\"?.*>", "").replaceAll("<input.*type=\"?(submit|button)\"?.*>", "<div style=\"background-color:#eeeeee;text-align:center;border:1px solid black;width:100px;\">button</div>").replaceAll("<input.*>", "<div style=\"text-align:center;border:1px solid black;width:100px;\">input</div>"), Whitelist.relaxed().addTags("center", "div", "span").addAttributes(":all", "style"));
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (ExceptionInInitializerError | NoClassDefFoundError e) {
        LOGGER.warn("Jsoup not properly configured, please update jsql", e);
    }
    final JTextPane browser = new JTextPane();
    browser.setContentType("text/html");
    browser.setEditable(false);
    // Fix #43220: EmptyStackException on setText()
    try {
        browser.setText(htmlSource);
    } catch (EmptyStackException e) {
        LOGGER.error(e, e);
    }
    final JPopupMenu menu = new JPopupMenu();
    JMenuItem itemCopyUrl = new JMenuItem(I18n.valueByKey("CONTEXT_MENU_COPY_PAGE_URL"));
    I18nView.addComponentForKey("CONTEXT_MENU_COPY_PAGE_URL", itemCopyUrl);
    itemCopyUrl.setIcon(HelperUi.ICON_EMPTY);
    JMenuItem itemCopy = new JMenuItem();
    itemCopy.setAction(browser.getActionMap().get(DefaultEditorKit.copyAction));
    itemCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
    itemCopy.setMnemonic('C');
    itemCopy.setText(I18n.valueByKey("CONTEXT_MENU_COPY"));
    I18nView.addComponentForKey("CONTEXT_MENU_COPY", itemCopy);
    itemCopy.setIcon(HelperUi.ICON_EMPTY);
    JMenuItem itemSelectAll = new JMenuItem();
    itemSelectAll.setIcon(HelperUi.ICON_EMPTY);
    itemSelectAll.setAction(browser.getActionMap().get(DefaultEditorKit.selectAllAction));
    itemSelectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
    itemSelectAll.setText(I18n.valueByKey("CONTEXT_MENU_SELECT_ALL"));
    I18nView.addComponentForKey("CONTEXT_MENU_SELECT_ALL", itemSelectAll);
    itemSelectAll.setMnemonic('A');
    menu.add(itemCopyUrl);
    menu.add(new JSeparator());
    menu.add(itemCopy);
    menu.add(itemSelectAll);
    menu.applyComponentOrientation(ComponentOrientation.getOrientation(I18n.getLocaleDefault()));
    itemCopyUrl.addActionListener(actionEvent -> {
        StringSelection stringSelection = new StringSelection(CreateAdminPageTab.this.url);
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(stringSelection, null);
    });
    itemSelectAll.addActionListener(actionEvent -> browser.selectAll());
    browser.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent arg0) {
            browser.getCaret().setVisible(true);
            browser.getCaret().setSelectionVisible(true);
        }
    });
    browser.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent evt) {
            browser.requestFocusInWindow();
            if (evt.isPopupTrigger()) {
                menu.show(evt.getComponent(), evt.getX(), evt.getY());
            }
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
                // Fix #45348: IllegalComponentStateException on show()
                try {
                    menu.show(evt.getComponent(), evt.getX(), evt.getY());
                } catch (IllegalComponentStateException e) {
                    LOGGER.error(e, e);
                }
                menu.setLocation(ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? evt.getXOnScreen() - menu.getWidth() : evt.getXOnScreen(), evt.getYOnScreen());
            }
        }
    });
    final LightScrollPane scroller = new LightScrollPane(1, 0, 0, 0, browser);
    MediatorGui.tabResults().addTab(this.url.replaceAll(".*/", "") + " ", scroller);
    // Focus on the new tab
    MediatorGui.tabResults().setSelectedComponent(scroller);
    // Create a custom tab header with close button
    TabHeader header = new TabHeader(this.url.replaceAll(".*/", ""), HelperUi.ICON_ADMIN_SERVER);
    MediatorGui.tabResults().setToolTipTextAt(MediatorGui.tabResults().indexOfComponent(scroller), "<html>" + this.url + "</html>");
    // Apply the custom header to the tab
    MediatorGui.tabResults().setTabComponentAt(MediatorGui.tabResults().indexOfComponent(scroller), header);
    // Give focus to the admin page
    browser.requestFocusInWindow();
    // Get back to the top
    SwingUtilities.invokeLater(() -> scroller.scrollPane.getViewport().setViewPosition(new java.awt.Point(0, 0)));
}
Also used : TabHeader(com.jsql.view.swing.tab.TabHeader) FocusAdapter(java.awt.event.FocusAdapter) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) LightScrollPane(com.jsql.view.swing.scrollpane.LightScrollPane) IOException(java.io.IOException) FocusEvent(java.awt.event.FocusEvent) IllegalComponentStateException(java.awt.IllegalComponentStateException) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) StringSelection(java.awt.datatransfer.StringSelection) EmptyStackException(java.util.EmptyStackException) JTextPane(javax.swing.JTextPane) Clipboard(java.awt.datatransfer.Clipboard) JMenuItem(javax.swing.JMenuItem)

Example 2 with IllegalComponentStateException

use of java.awt.IllegalComponentStateException in project jsql-injection by ron190.

the class MouseAdapterMenuAction method showPopup.

/**
 * Displays a popup menu for JList.
 * @param mouseEvent Mouse event
 */
@SuppressWarnings("unchecked")
public void showPopup(final MouseEvent mouseEvent) {
    if (mouseEvent.isPopupTrigger()) {
        JList<ItemList> list = (JList<ItemList>) mouseEvent.getSource();
        JPopupMenu popupMenuList = new JPopupMenu();
        boolean isChinese = I18n.getLocaleDefault().getLanguage() == new Locale("zh").getLanguage();
        JMenuItem mnImport = new JMenuItem(isChinese ? I18nView.valueByKey("LIST_IMPORT_CONFIRM_TITLE") : I18n.valueByKey("LIST_IMPORT_CONFIRM_TITLE"));
        I18nView.addComponentForKey("LIST_IMPORT_CONFIRM_TITLE", mnImport);
        JMenuItem mnExport = new JMenuItem(isChinese ? I18nView.valueByKey("LIST_EXPORT_TITLE") : I18n.valueByKey("LIST_EXPORT_TITLE"));
        I18nView.addComponentForKey("LIST_EXPORT_TITLE", mnExport);
        JMenuItem mnCut = new JMenuItem(isChinese ? I18nView.valueByKey("LIST_CUT") : I18n.valueByKey("LIST_CUT"));
        I18nView.addComponentForKey("LIST_CUT", mnCut);
        JMenuItem mnCopy = new JMenuItem(isChinese ? I18nView.valueByKey("CONTEXT_MENU_COPY") : I18n.valueByKey("CONTEXT_MENU_COPY"));
        I18nView.addComponentForKey("CONTEXT_MENU_COPY", mnCopy);
        JMenuItem mnPaste = new JMenuItem(isChinese ? I18nView.valueByKey("LIST_PASTE") : I18n.valueByKey("LIST_PASTE"));
        I18nView.addComponentForKey("LIST_PASTE", mnPaste);
        JMenuItem mnDelete = new JMenuItem(isChinese ? I18nView.valueByKey("LIST_DELETE") : I18n.valueByKey("LIST_DELETE"));
        I18nView.addComponentForKey("LIST_DELETE", mnDelete);
        JMenuItem mnNew = new JMenuItem(isChinese ? I18nView.valueByKey("LIST_NEW_VALUE") : I18n.valueByKey("LIST_NEW_VALUE"));
        I18nView.addComponentForKey("LIST_NEW_VALUE", mnNew);
        JMenuItem mnRestoreDefault = new JMenuItem(isChinese ? I18nView.valueByKey("LIST_RESTORE_DEFAULT") : I18n.valueByKey("LIST_RESTORE_DEFAULT"));
        I18nView.addComponentForKey("LIST_RESTORE_DEFAULT", mnRestoreDefault);
        JMenuItem mnSelectAll = new JMenuItem(isChinese ? I18nView.valueByKey("CONTEXT_MENU_SELECT_ALL") : I18n.valueByKey("CONTEXT_MENU_SELECT_ALL"));
        I18nView.addComponentForKey("CONTEXT_MENU_SELECT_ALL", mnSelectAll);
        mnImport.setIcon(HelperUi.ICON_EMPTY);
        mnExport.setIcon(HelperUi.ICON_EMPTY);
        mnCut.setIcon(HelperUi.ICON_EMPTY);
        mnCopy.setIcon(HelperUi.ICON_EMPTY);
        mnPaste.setIcon(HelperUi.ICON_EMPTY);
        mnDelete.setIcon(HelperUi.ICON_EMPTY);
        mnNew.setIcon(HelperUi.ICON_EMPTY);
        mnRestoreDefault.setIcon(HelperUi.ICON_EMPTY);
        mnSelectAll.setIcon(HelperUi.ICON_EMPTY);
        mnCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
        mnCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
        mnPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
        mnSelectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
        // Create a file chooser
        final JFileChooser importFileDialog = new JFileChooser(PreferencesUtil.getPathFile());
        importFileDialog.setDialogTitle(I18n.valueByKey("LIST_IMPORT_CONFIRM_TITLE"));
        importFileDialog.setMultiSelectionEnabled(true);
        mnNew.addActionListener(new MenuActionNewValue(this.dndList));
        mnImport.addActionListener(actionEvent -> {
            int choice = 0;
            // Fix #42831: ClassCastException on showOpenDialog()
            try {
                choice = importFileDialog.showOpenDialog(this.dndList.getTopLevelAncestor());
            } catch (ClassCastException | NullPointerException e) {
                LOGGER.error(e, e);
            }
            if (choice == JFileChooser.APPROVE_OPTION) {
                this.dndList.dropPasteFile(Arrays.asList(importFileDialog.getSelectedFiles()), this.dndList.locationToIndex(mouseEvent.getPoint()));
            }
        });
        mnCopy.addActionListener(actionEvent -> {
            Action action = this.dndList.getActionMap().get(TransferHandler.getCopyAction().getValue(Action.NAME));
            if (action != null) {
                action.actionPerformed(new ActionEvent(this.dndList, ActionEvent.ACTION_PERFORMED, null));
            }
        });
        mnCut.addActionListener(actionEvent -> {
            Action action = this.dndList.getActionMap().get(TransferHandler.getCutAction().getValue(Action.NAME));
            if (action != null) {
                action.actionPerformed(new ActionEvent(this.dndList, ActionEvent.ACTION_PERFORMED, null));
            }
        });
        mnPaste.addActionListener(actionEvent -> {
            Action action = this.dndList.getActionMap().get(TransferHandler.getPasteAction().getValue(Action.NAME));
            if (action != null) {
                action.actionPerformed(new ActionEvent(this.dndList, ActionEvent.ACTION_PERFORMED, null));
            }
        });
        mnDelete.addActionListener(actionEvent -> this.dndList.removeSelectedItem());
        mnExport.addActionListener(new MenuActionExport(this.dndList));
        mnRestoreDefault.addActionListener(actionEvent -> this.dndList.restore());
        mnSelectAll.addActionListener(actionEvent -> {
            int start = 0;
            int end = this.dndList.getModel().getSize() - 1;
            if (end >= 0) {
                this.dndList.setSelectionInterval(start, end);
            }
        });
        popupMenuList.add(mnNew);
        popupMenuList.add(new JSeparator());
        popupMenuList.add(mnCut);
        popupMenuList.add(mnCopy);
        popupMenuList.add(mnPaste);
        popupMenuList.add(mnDelete);
        popupMenuList.add(new JSeparator());
        popupMenuList.add(mnSelectAll);
        popupMenuList.add(new JSeparator());
        popupMenuList.add(mnImport);
        popupMenuList.add(mnExport);
        popupMenuList.add(new JSeparator());
        popupMenuList.add(mnRestoreDefault);
        popupMenuList.applyComponentOrientation(ComponentOrientation.getOrientation(I18n.getLocaleDefault()));
        // Fix #26274: IllegalComponentStateException on show()
        try {
            popupMenuList.show(list, ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? mouseEvent.getX() - popupMenuList.getWidth() : mouseEvent.getX(), mouseEvent.getY());
        } catch (IllegalComponentStateException e) {
            LOGGER.error(e.getMessage(), e);
        }
        popupMenuList.setLocation(ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? mouseEvent.getXOnScreen() - popupMenuList.getWidth() : mouseEvent.getXOnScreen(), mouseEvent.getYOnScreen());
    }
}
Also used : Locale(java.util.Locale) Action(javax.swing.Action) ActionEvent(java.awt.event.ActionEvent) IllegalComponentStateException(java.awt.IllegalComponentStateException) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) JFileChooser(javax.swing.JFileChooser) JMenuItem(javax.swing.JMenuItem) JList(javax.swing.JList)

Example 3 with IllegalComponentStateException

use of java.awt.IllegalComponentStateException in project logisim-evolution by reds-heig.

the class Frame method savePreferences.

public void savePreferences() {
    AppPreferences.TICK_FREQUENCY.set(Double.valueOf(proj.getSimulator().getTickFrequency()));
    AppPreferences.LAYOUT_SHOW_GRID.setBoolean(layoutZoomModel.getShowGrid());
    AppPreferences.LAYOUT_ZOOM.set(Double.valueOf(layoutZoomModel.getZoomFactor()));
    if (appearance != null) {
        ZoomModel aZoom = appearance.getZoomModel();
        AppPreferences.APPEARANCE_SHOW_GRID.setBoolean(aZoom.getShowGrid());
        AppPreferences.APPEARANCE_ZOOM.set(Double.valueOf(aZoom.getZoomFactor()));
    }
    int state = getExtendedState() & ~JFrame.ICONIFIED;
    AppPreferences.WINDOW_STATE.set(Integer.valueOf(state));
    Dimension dim = getSize();
    AppPreferences.WINDOW_WIDTH.set(Integer.valueOf(dim.width));
    AppPreferences.WINDOW_HEIGHT.set(Integer.valueOf(dim.height));
    Point loc;
    try {
        loc = getLocationOnScreen();
    } catch (IllegalComponentStateException e) {
        loc = Projects.getLocation(this);
    }
    if (loc != null) {
        AppPreferences.WINDOW_LOCATION.set(loc.x + "," + loc.y);
    }
    AppPreferences.WINDOW_LEFT_SPLIT.set(Double.valueOf(leftRegion.getFraction()));
    if (Double.valueOf(rightRegion.getFraction()) < 1.0)
        AppPreferences.WINDOW_RIGHT_SPLIT.set(Double.valueOf(rightRegion.getFraction()));
    AppPreferences.WINDOW_MAIN_SPLIT.set(Double.valueOf(mainRegion.getFraction()));
    AppPreferences.DIALOG_DIRECTORY.set(JFileChoosers.getCurrentDirectory());
}
Also used : BasicZoomModel(com.cburch.logisim.gui.generic.BasicZoomModel) ZoomModel(com.cburch.logisim.gui.generic.ZoomModel) Dimension(java.awt.Dimension) Point(java.awt.Point) IllegalComponentStateException(java.awt.IllegalComponentStateException) Point(java.awt.Point)

Example 4 with IllegalComponentStateException

use of java.awt.IllegalComponentStateException in project jmulticard by ctt-gob-es.

the class Utils method showToolTip.

/**
 * Muestra u oculta un tooltip relacionado con un bot&oacute;n.
 * @param show Boolean que indica si se muestra el tooltip
 * @param tip JWindow que muestra el contenido del tooltip
 * @param boton JButton al que se relaciona el tooltip
 * @param tipText JLabel que muestra el contenido del tooltip
 */
static void showToolTip(final boolean show, final JWindow tip, final JButton boton, final JLabel tipText) {
    tipText.setText(boton.getToolTipText());
    // $NON-NLS-1$
    tip.setBackground((Color) UIManager.get("ToolTip.background"));
    // $NON-NLS-1$
    tipText.setBackground((Color) UIManager.get("ToolTip.background"));
    tipText.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(0, 3, 0, 3)));
    // $NON-NLS-1$
    tipText.setFont((Font) UIManager.get("ToolTip.font"));
    tipText.setOpaque(true);
    tip.add(tipText);
    Point p = new Point();
    try {
        p = boton.getLocationOnScreen();
    } catch (final IllegalComponentStateException e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        Logger.getLogger("es.gob.jmulticard").warning("Error mostrando el tooltip: " + e);
    }
    int factor = 0;
    if (boton.getSize().getHeight() > 34) {
        factor = (int) (boton.getSize().getHeight() * 0.5);
    }
    tip.setLocation((int) p.getX(), (int) p.getY() + 30 + factor);
    tip.pack();
    tip.setVisible(show);
}
Also used : Point(java.awt.Point) IllegalComponentStateException(java.awt.IllegalComponentStateException) Point(java.awt.Point)

Example 5 with IllegalComponentStateException

use of java.awt.IllegalComponentStateException in project lwjgl by LWJGL.

the class AWTUtil method setCursorPosition.

public static void setCursorPosition(Component component, Robot robot, int x, int y) {
    if (robot != null) {
        try {
            Point location = component.getLocationOnScreen();
            int transformed_x = location.x + x;
            int transformed_y = location.y + transformY(component, y);
            robot.mouseMove(transformed_x, transformed_y);
        } catch (IllegalComponentStateException e) {
            LWJGLUtil.log("Failed to set cursor position: " + e);
        }
    }
}
Also used : Point(java.awt.Point) IllegalComponentStateException(java.awt.IllegalComponentStateException) Point(java.awt.Point)

Aggregations

IllegalComponentStateException (java.awt.IllegalComponentStateException)7 Point (java.awt.Point)4 JPopupMenu (javax.swing.JPopupMenu)3 JMenuItem (javax.swing.JMenuItem)2 JSeparator (javax.swing.JSeparator)2 BasicZoomModel (com.cburch.logisim.gui.generic.BasicZoomModel)1 ZoomModel (com.cburch.logisim.gui.generic.ZoomModel)1 LightScrollPane (com.jsql.view.swing.scrollpane.LightScrollPane)1 TabHeader (com.jsql.view.swing.tab.TabHeader)1 Dimension (java.awt.Dimension)1 Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1 ActionEvent (java.awt.event.ActionEvent)1 FocusAdapter (java.awt.event.FocusAdapter)1 FocusEvent (java.awt.event.FocusEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 EmptyStackException (java.util.EmptyStackException)1 Locale (java.util.Locale)1