Search in sources :

Example 1 with JMenuItemWithMargin

use of com.jsql.view.swing.menubar.JMenuItemWithMargin in project jsql-injection by ron190.

the class CreateAdminPageTab method execute.

@Override
public void execute() {
    String htmlSource = StringUtils.EMPTY;
    // 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).ignoreContentType(true).ignoreHttpErrors(true).get().html().replaceAll("<img[^>]*>", StringUtils.EMPTY).replaceAll("<input[^>]*type=\"?hidden\"?[^>]*>", StringUtils.EMPTY).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.log(LogLevel.CONSOLE_ERROR, "Failure opening page: {}", e.getMessage());
    } catch (ExceptionInInitializerError | NoClassDefFoundError e) {
        LOGGER.log(LogLevel.CONSOLE_JAVA, e, e);
    }
    final var browser = new JTextPane();
    browser.setContentType("text/html");
    browser.setEditable(false);
    // Fix #94242: IndexOutOfBoundsException on setText()
    try {
        browser.setText(htmlSource);
    } catch (IndexOutOfBoundsException | EmptyStackException e) {
        LOGGER.log(LogLevel.CONSOLE_JAVA, e, e);
    }
    final var menu = new JPopupMenu();
    JMenuItem itemCopyUrl = new JMenuItemWithMargin(I18nUtil.valueByKey("CONTEXT_MENU_COPY_PAGE_URL"));
    I18nViewUtil.addComponentForKey("CONTEXT_MENU_COPY_PAGE_URL", itemCopyUrl);
    JMenuItem itemCopy = new JMenuItemWithMargin();
    itemCopy.setAction(browser.getActionMap().get(DefaultEditorKit.copyAction));
    itemCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
    itemCopy.setMnemonic('C');
    itemCopy.setText(I18nUtil.valueByKey("CONTEXT_MENU_COPY"));
    I18nViewUtil.addComponentForKey("CONTEXT_MENU_COPY", itemCopy);
    JMenuItem itemSelectAll = new JMenuItemWithMargin();
    itemSelectAll.setAction(browser.getActionMap().get(DefaultEditorKit.selectAllAction));
    itemSelectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
    itemSelectAll.setText(I18nUtil.valueByKey("CONTEXT_MENU_SELECT_ALL"));
    I18nViewUtil.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(I18nUtil.getLocaleDefault()));
    itemCopyUrl.addActionListener(actionEvent -> {
        var stringSelection = new StringSelection(CreateAdminPageTab.this.url);
        var 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.log(LogLevel.CONSOLE_JAVA, e, e);
                }
                menu.setLocation(ComponentOrientation.RIGHT_TO_LEFT.equals(ComponentOrientation.getOrientation(I18nUtil.getLocaleDefault())) ? evt.getXOnScreen() - menu.getWidth() : evt.getXOnScreen(), evt.getYOnScreen());
            }
        }
    });
    final var scroller = new LightScrollPane(1, 0, 0, 0, browser);
    MediatorHelper.tabResults().addTab(this.url.replaceAll(".*/", StringUtils.EMPTY) + StringUtils.SPACE, scroller);
    // Focus on the new tab
    MediatorHelper.tabResults().setSelectedComponent(scroller);
    // Create a custom tab header with close button
    var header = new TabHeader(this.url.replaceAll(".*/", StringUtils.EMPTY), UiUtil.ICON_ADMIN_SERVER);
    MediatorHelper.tabResults().setToolTipTextAt(MediatorHelper.tabResults().indexOfComponent(scroller), String.format("<html>%s</html>", this.url));
    // Apply the custom header to the tab
    MediatorHelper.tabResults().setTabComponentAt(MediatorHelper.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 : FocusAdapter(java.awt.event.FocusAdapter) JMenuItemWithMargin(com.jsql.view.swing.menubar.JMenuItemWithMargin) LightScrollPane(com.jsql.view.swing.scrollpane.LightScrollPane) FocusEvent(java.awt.event.FocusEvent) JSeparator(javax.swing.JSeparator) StringSelection(java.awt.datatransfer.StringSelection) EmptyStackException(java.util.EmptyStackException) JTextPane(javax.swing.JTextPane) JMenuItem(javax.swing.JMenuItem) TabHeader(com.jsql.view.swing.tab.TabHeader) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) IOException(java.io.IOException) IllegalComponentStateException(java.awt.IllegalComponentStateException) JPopupMenu(javax.swing.JPopupMenu)

Example 2 with JMenuItemWithMargin

use of com.jsql.view.swing.menubar.JMenuItemWithMargin in project jsql-injection by ron190.

the class NodeModelTable method addCheckUncheckItems.

private void addCheckUncheckItems(JPopupMenuCustomExtract tablePopupMenu, final TreePath path) {
    JMenuItem menuItemCheckAll = new JMenuItemWithMargin(I18nViewUtil.valueByKey("COLUMNS_CHECK_ALL"), 'C');
    I18nViewUtil.addComponentForKey("COLUMNS_CHECK_ALL", menuItemCheckAll);
    JMenuItem menuItemUncheckAll = new JMenuItemWithMargin(I18nViewUtil.valueByKey("COLUMNS_UNCHECK_ALL"), 'U');
    I18nViewUtil.addComponentForKey("COLUMNS_UNCHECK_ALL", menuItemUncheckAll);
    if (!this.isLoaded()) {
        menuItemCheckAll.setEnabled(false);
        menuItemUncheckAll.setEnabled(false);
    }
    menuItemCheckAll.addActionListener(new ActionCheckbox(true, path));
    menuItemUncheckAll.addActionListener(new ActionCheckbox(false, path));
    tablePopupMenu.add(new JSeparator());
    tablePopupMenu.add(menuItemCheckAll);
    tablePopupMenu.add(menuItemUncheckAll);
}
Also used : JMenuItemWithMargin(com.jsql.view.swing.menubar.JMenuItemWithMargin) JMenuItem(javax.swing.JMenuItem) JSeparator(javax.swing.JSeparator)

Example 3 with JMenuItemWithMargin

use of com.jsql.view.swing.menubar.JMenuItemWithMargin in project jsql-injection by ron190.

the class AbstractNodeModel method initializeItemLoadPause.

private void initializeItemLoadPause(DefaultMutableTreeNode currentTableNode, JPopupMenuCustomExtract popupMenu, AbstractSuspendable suspendableTask) {
    JMenuItem menuItemLoad = new JMenuItemWithMargin(this.isRunning ? I18nViewUtil.valueByKey("THREAD_STOP") : I18nViewUtil.valueByKey("THREAD_LOAD"), 'o');
    if (!this.isContainingSelection && !this.isRunning) {
        menuItemLoad.setEnabled(false);
    }
    menuItemLoad.addActionListener(new ActionLoadStop(this, currentTableNode));
    JMenuItem menuItemPause = new JMenuItemWithMargin(// Report #133: ignore if thread not found
    suspendableTask != null && suspendableTask.isPaused() ? I18nViewUtil.valueByKey("THREAD_RESUME") : I18nViewUtil.valueByKey("THREAD_PAUSE"), 's');
    if (!this.isRunning) {
        menuItemPause.setEnabled(false);
    }
    menuItemPause.addActionListener(new ActionPauseUnpause(this));
    popupMenu.add(menuItemLoad);
    popupMenu.add(menuItemPause);
}
Also used : ActionPauseUnpause(com.jsql.view.swing.tree.ActionPauseUnpause) JMenuItemWithMargin(com.jsql.view.swing.menubar.JMenuItemWithMargin) JMenuItem(javax.swing.JMenuItem) ActionLoadStop(com.jsql.view.swing.tree.ActionLoadStop)

Example 4 with JMenuItemWithMargin

use of com.jsql.view.swing.menubar.JMenuItemWithMargin in project jsql-injection by ron190.

the class AbstractNodeModel method initializeItemRenameReload.

private void initializeItemRenameReload(DefaultMutableTreeNode currentTableNode, TreePath path, JPopupMenuCustomExtract popupMenu) {
    String textReload;
    if (this instanceof NodeModelDatabase) {
        textReload = I18nViewUtil.valueByKey("RELOAD_TABLES");
    } else if (this instanceof NodeModelTable) {
        textReload = I18nViewUtil.valueByKey("RELOAD_COLUMNS");
    } else {
        textReload = "?";
    }
    JMenuItem menuItemReload = new JMenuItemWithMargin(textReload);
    menuItemReload.setEnabled(!this.isRunning);
    menuItemReload.addActionListener(actionEvent -> AbstractNodeModel.this.runAction());
    JMenuItem menuItemRename = new JMenuItemWithMargin(I18nViewUtil.valueByKey("RENAME_NODE"));
    menuItemRename.setEnabled(!this.isRunning);
    menuItemRename.addActionListener(actionEvent -> {
        AbstractNodeModel nodeModel = (AbstractNodeModel) currentTableNode.getUserObject();
        nodeModel.setIsEdited(true);
        AbstractNodeModel.this.getPanel().getLabel().setVisible(false);
        AbstractNodeModel.this.getPanel().getEditable().setVisible(true);
        MediatorHelper.treeDatabase().setSelectionPath(path);
    });
    popupMenu.add(new JSeparator());
    popupMenu.add(menuItemRename);
    popupMenu.add(menuItemReload);
}
Also used : JMenuItemWithMargin(com.jsql.view.swing.menubar.JMenuItemWithMargin) JMenuItem(javax.swing.JMenuItem) JSeparator(javax.swing.JSeparator)

Example 5 with JMenuItemWithMargin

use of com.jsql.view.swing.menubar.JMenuItemWithMargin in project jsql-injection by ron190.

the class MouseAdapterMenuAction method initializeMenu.

private JPopupMenu initializeMenu(final MouseEvent mouseEvent) {
    var popupMenuList = new JPopupMenu();
    boolean isAsian = I18nUtil.isAsian(I18nUtil.getLocaleDefault());
    JMenuItem mnImport = new JMenuItemWithMargin();
    JMenuItem mnExport = new JMenuItemWithMargin();
    JMenuItem mnCut = new JMenuItemWithMargin();
    JMenuItem mnCopy = new JMenuItemWithMargin();
    JMenuItem mnPaste = new JMenuItemWithMargin();
    JMenuItem mnDelete = new JMenuItemWithMargin();
    JMenuItem mnNew = new JMenuItemWithMargin();
    JMenuItem mnRestoreDefault = new JMenuItemWithMargin();
    JMenuItem mnSelectAll = new JMenuItemWithMargin();
    Stream.of(new SimpleEntry<>(mnImport, "LIST_IMPORT_CONFIRM_TITLE"), new SimpleEntry<>(mnExport, "LIST_EXPORT_TITLE"), new SimpleEntry<>(mnCut, "LIST_CUT"), new SimpleEntry<>(mnCopy, "CONTEXT_MENU_COPY"), new SimpleEntry<>(mnPaste, "LIST_PASTE"), new SimpleEntry<>(mnDelete, "LIST_DELETE"), new SimpleEntry<>(mnNew, "LIST_NEW_VALUE"), new SimpleEntry<>(mnRestoreDefault, "LIST_RESTORE_DEFAULT"), new SimpleEntry<>(mnSelectAll, "CONTEXT_MENU_SELECT_ALL")).forEach(entry -> {
        entry.getKey().setText(isAsian ? I18nViewUtil.valueByKey(entry.getValue()) : I18nUtil.valueByKey(entry.getValue()));
        entry.getKey().setName(entry.getValue());
        I18nViewUtil.addComponentForKey(entry.getValue(), entry.getKey());
    });
    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 var importFileDialog = new JFileChooser(MediatorHelper.model().getMediatorUtils().getPreferencesUtil().getPathFile());
    importFileDialog.setDialogTitle(I18nUtil.valueByKey("LIST_IMPORT_CONFIRM_TITLE"));
    importFileDialog.setMultiSelectionEnabled(true);
    mnNew.addActionListener(new MenuActionNewValue(this.dndList));
    mnImport.addActionListener(actionEvent -> {
        var choice = 0;
        // Fix #42831: ClassCastException on showOpenDialog()
        try {
            choice = importFileDialog.showOpenDialog(this.dndList.getTopLevelAncestor());
        } catch (ClassCastException | NullPointerException e) {
            LOGGER.log(LogLevel.CONSOLE_JAVA, e, e);
        }
        if (choice == JFileChooser.APPROVE_OPTION) {
            this.dndList.dropPasteFile(Arrays.asList(importFileDialog.getSelectedFiles()), this.dndList.locationToIndex(mouseEvent.getPoint()));
        }
    });
    mnCopy.addActionListener(actionEvent -> {
        var 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 -> {
        var 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 -> {
        var 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 -> {
        var 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);
    return popupMenuList;
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) ActionEvent(java.awt.event.ActionEvent) JMenuItemWithMargin(com.jsql.view.swing.menubar.JMenuItemWithMargin) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) JFileChooser(javax.swing.JFileChooser) JMenuItem(javax.swing.JMenuItem)

Aggregations

JMenuItemWithMargin (com.jsql.view.swing.menubar.JMenuItemWithMargin)5 JMenuItem (javax.swing.JMenuItem)5 JSeparator (javax.swing.JSeparator)4 JPopupMenu (javax.swing.JPopupMenu)2 LightScrollPane (com.jsql.view.swing.scrollpane.LightScrollPane)1 TabHeader (com.jsql.view.swing.tab.TabHeader)1 ActionLoadStop (com.jsql.view.swing.tree.ActionLoadStop)1 ActionPauseUnpause (com.jsql.view.swing.tree.ActionPauseUnpause)1 IllegalComponentStateException (java.awt.IllegalComponentStateException)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 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 EmptyStackException (java.util.EmptyStackException)1 JFileChooser (javax.swing.JFileChooser)1 JTextPane (javax.swing.JTextPane)1