Example usage for javax.swing ToolTipManager sharedInstance

List of usage examples for javax.swing ToolTipManager sharedInstance

Introduction

In this page you can find the example usage for javax.swing ToolTipManager sharedInstance.

Prototype

public static ToolTipManager sharedInstance() 

Source Link

Document

Returns a shared ToolTipManager instance.

Usage

From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java

/**
 * Creates new form Display3DPanel//from  w ww. j  a  v a  2 s.  co  m
 */
public Display3DPanel() {
    initComponents();
    effectiveHeight = getHeight();
    effectiveWidth = getWidth();
    logger.debug("creating Display3DPanel");
    this.setMinimumSize(new Dimension(200, 200));
    this.setPreferredSize(new Dimension(800, 600));
    GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
    template.setStereo(GraphicsConfigTemplate3D.PREFERRED);

    // Get the GraphicsConfiguration that best fits our needs.
    logger.debug("getting config");
    GraphicsConfiguration gcfg = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getBestConfiguration(template);
    logger.debug("creating canvas");
    canvas = new Canvas3D(gcfg) {
        @Override
        public void postRender() {
            vGraphics = super.getGraphics2D();
            vGraphics.setFont(new Font("sans-serif", Font.PLAIN, 10));
            vGraphics.setColor(Color.YELLOW);
            locToWin.update();
            fireProjectionChanged(new ProjectionEvent(this, locToWin));
            draw2D(vGraphics, locToWin, effectiveWidth, effectiveHeight);
            vGraphics.flush(false);
        }

        @Override
        public void postSwap() {
            if (postRenderSilent || waitForExternalTrigger) {
                return;
            }
            if (!(storingJPEG || storingPNG || storingFrames)) {
                fireFrameRendered();
            }
            if (storingFrames) {
                if (storingJPEG) {
                    writeImage(new File(controlsPanel.getMovieCreationPanel().getCurrentFrameFileName()));
                } else {
                    writeYUV(controlsPanel.getMovieCreationPanel().getGenericFrameFileName());
                }
            }
        }
    };
    canvas.setStereoEnable(false);
    add("Center", canvas);

    pickObject = new PickObject(canvas, objScene, rootObject.getGeometryObj(), objRotate);

    canvas.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            if (evt.isShiftDown()) {
                //              if (e.isShiftDown())
                //                 System.out.println(""+e.getX() + " " + e.getY());
            }
            if (evt.getButton() == MouseEvent.BUTTON1) {
                if (evt.getClickCount() > 1) {
                    reset();
                } else if (pickObject.consumeEmulated3DPick(evt.getX(), evt.getY())) {
                    /* Nothing must be done - everything was done in consumeEmulated3DPick() */
                } else {
                    pickObject.consume2DSelectModule(evt.getX(), evt.getY());
                }
                rootObject.firePickChanged(evt, locToWin);
            }
            if (evt.getButton() == MouseEvent.BUTTON3) {
                if (getControlsFrame() != null) {
                    getControlsFrame().setBounds(evt.getXOnScreen() - 130, evt.getYOnScreen(), 240, 500);
                    getControlsFrame().setVisible(true);
                } else if (getTransientControlsFrame() != null) {
                    getTransientControlsFrame().setBounds(evt.getXOnScreen() - 130, evt.getYOnScreen(), 240,
                            500);
                    getTransientControlsFrame().setVisible(true);
                } else if (application != null) {
                    application.getFrames().getGuiPanel().selectModule(name);
                }
            }
            if (evt.getButton() == MouseEvent.BUTTON2) {
                reset();
            }
        }

        @Override
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            mouseOn = true;
            mouseObserverThread = new Thread(new MouseObserver());
            mouseObserverThread.start();
        }

        @Override
        public void mouseExited(java.awt.event.MouseEvent evt) {
            mouseObserverThread = null;
            mouseOn = false;
        }
    });

    canvas.addMouseMotionListener(new java.awt.event.MouseMotionListener() {
        @Override
        public void mouseDragged(MouseEvent e) {
            //              if (e.isShiftDown())
            //                 System.out.println(""+e.getX() + " " + e.getY());
        }

        @Override
        public void mouseMoved(MouseEvent e) {
        }
    });

    canvas.addMouseWheelListener(new java.awt.event.MouseWheelListener() {
        @Override
        public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
            rescaleFromMouseWheel(evt);
        }
    });

    canvas.addKeyListener(new java.awt.event.KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent evt) {
            formKeyTyped(evt);
        }

        @Override
        public void keyPressed(KeyEvent evt) {
            formKeyPressed(evt);
        }

        @Override
        public void keyReleased(KeyEvent evt) {
            formKeyReleased(evt);
        }
    });

    ToolTipManager.sharedInstance().setLightWeightPopupEnabled(true);
    universe = new SimpleUniverse(canvas);
    view = canvas.getView();
    view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
    view.setTransparencySortingPolicy(View.TRANSPARENCY_SORT_GEOMETRY);

    objScene.addChild(rootObject.getGeometryObj());
    rootObject.setRenderingWindow(this);
    rootObject.getGeometryObj().setUserData(null);

    bg.setCapability(Background.ALLOW_COLOR_WRITE);
    bg.setCapability(Background.ALLOW_COLOR_READ);
    bg.setCapability(Background.ALLOW_IMAGE_WRITE);
    bg.setCapability(Background.ALLOW_IMAGE_READ);
    bg.setCapability(Background.ALLOW_IMAGE_SCALE_MODE_READ);
    bg.setCapability(Background.ALLOW_IMAGE_SCALE_MODE_WRITE);
    bg.setImageScaleMode(Background.SCALE_FIT_ALL);
    bg.setApplicationBounds(bounds);

    myFog.setCapability(LinearFog.ALLOW_DISTANCE_WRITE);
    myFog.setCapability(LinearFog.ALLOW_COLOR_WRITE);
    myFog.setInfluencingBounds(bounds);
    myFog.setFrontDistance(1.);
    myFog.setBackDistance(4.);
    myFogGroup.addChild(myFog);

    mouseRotate.setTransformGroup(objRotate);
    mouseRotate.setSchedulingBounds(bounds);
    mouseRotate.setFactor(mouseRotateSensitivity);

    mouseTranslate.setTransformGroup(objRotate);
    mouseTranslate.setSchedulingBounds(bounds);
    mouseTranslate.setFactor(mouseTranslateSensitivity);

    mouseZoom.setTransformGroup(objRotate);
    mouseZoom.setSchedulingBounds(bounds);

    windowRootObject.addChild(mouseRotate);
    windowRootObject.addChild(mouseTranslate);
    windowRootObject.addChild(mouseZoom);

    objTranslate.addChild(objScene);
    objScale.addChild(objTranslate);
    objRotate.addChild(bg);
    objRotate.addChild(objScale);
    windowRootObject.addChild(objRotate);

    ambientLight = new EditableAmbientLight(new Color3f(.25f, .25f, .25f), bounds, "ambient light", true);
    windowRootObject.addChild(ambientLight.getLight());

    directionalLights.add(new EditableDirectionalLight(new Color3f(0.4f, 0.4f, 0.4f),
            new Vector3f(.1f, .08f, -.5f), bounds, "light 1", true, true));
    directionalLights.add(new EditableDirectionalLight(new Color3f(0.2f, 0.15f, 0.1f),
            new Vector3f(-1.f, -0.4f, -.5f), bounds, "light 2", true, false));
    directionalLights.add(new EditableDirectionalLight(new Color3f(0.1f, 0.1f, 0.15f),
            new Vector3f(0.f, 0.6f, -1.f), bounds, "light 3", true, false));
    directionalLights.add(new EditableDirectionalLight(new Color3f(0.1f, 0.1f, 0.15f),
            new Vector3f(0.f, -0.6f, -1.f), bounds, "light 3", false, false));
    for (int i = 0; i < directionalLights.size(); i++) {
        TransformGroup lightTransform = new TransformGroup();
        lightTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        lightTransform.setName("light" + i + "Transform");
        directionalLightTransforms.add(lightTransform);
        OpenBranchGroup lightGroup = new OpenBranchGroup();
        EditableDirectionalLight light = directionalLights.get(i);
        lightGroup.addChild(light.getLight());
        lightGroup.addChild(light.getBackLight());
        lightTransform.addChild(lightGroup);
        windowRootObject.addChild(lightTransform);
    }
    modelClip.setCapability(ModelClip.ALLOW_ENABLE_READ);
    modelClip.setCapability(ModelClip.ALLOW_ENABLE_WRITE);
    modelClip.setCapability(ModelClip.ALLOW_PLANE_READ);
    modelClip.setCapability(ModelClip.ALLOW_PLANE_WRITE);
    modelClip.setInfluencingBounds(bounds);
    objScene.addChild(modelClip);

    pointLights
            .add(new EditablePointLight(new Color3f(0.4f, 0.4f, 0.4f), bounds, null, null, "light 1", false));
    pointLights
            .add(new EditablePointLight(new Color3f(0.4f, 0.4f, 0.4f), bounds, null, null, "light 1", false));
    pointLights
            .add(new EditablePointLight(new Color3f(0.4f, 0.4f, 0.4f), bounds, null, null, "light 1", false));
    for (int i = 0; i < pointLights.size(); i++) {
        TransformGroup lightTransform = new TransformGroup();
        lightTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        lightTransform.setName("light" + i + "Transform");
        pointLightTransforms.add(lightTransform);
        OpenBranchGroup lightGroup = new OpenBranchGroup();
        EditablePointLight light = pointLights.get(i);
        lightGroup.addChild(light.getLight());
        lightTransform.addChild(lightGroup);
        windowRootObject.addChild(lightTransform);
    }
    alternateTransformObj.addChild(alternateRootObj);
    alternateTransormBranch.addChild(alternateTransformObj);
    windowRootObject.addChild(alternateTransormBranch);

    universe.getViewingPlatform().setNominalViewingTransform();
    universe.addBranchGraph(windowRootObject);

    view.getPhysicalBody().getLeftEyePosition(defaultLeftEye);
    view.getPhysicalBody().getRightEyePosition(defaultRightEye);
    controlsFrame = new Display3DControlsFrame(this);
    controlsPanel = controlsFrame.getControlPanel();
    universe.getViewingPlatform().getViewPlatformTransform().getTransform(initialCameraTransform);

    objReper.addChild(reper.getGeometryObj());
    positionedReper.addChild(objReper);
    positionedReper.setTransform(
            new Transform3D(new float[] { .15f, 0, 0, -.8f, 0, .15f, 0, .76f, 0, 0, .15f, 0, 0, 0, 0, 1 }));
    reperGroup.addChild(positionedReper);
    OpenBranchGroup reperLightGroup = new OpenBranchGroup();
    reperLightGroup.addChild(new AmbientLight(new Color3f(.6f, .6f, .6f)));
    reperLightGroup.addChild(new EditableDirectionalLight(new Color3f(0.4f, 0.4f, 0.4f),
            new Vector3f(.1f, .08f, -1f), bounds, "light 1", true, true).getLight());
    reperGroup.addChild(reperLightGroup);
    universe.addBranchGraph(reperGroup);
    locToWin = new LocalToWindow(rootObject.getGeometryObj(), canvas);

    /**
     * The line below binds reper with scene rotation when using any method that calls
     * objRotate.setTransform(), so: keyboard (explicitly calling), mouse (Java3D is calling
     * setTransform) and some custom ways (e.g. in haptic pointer)
     */
    objRotate.addTransformListener(objReper);
    //        mouseRotate.setupCallback(objReper); // it is not needed, because Java3D calls objRotate.setTranform which fires callback to the reper
}

From source file:pl.edu.icm.visnow.lib.basic.viewers.Viewer2D.Display2DPanel.java

private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
    int x = evt.getX();
    int y = evt.getY();
    currentUnderCursorObj = root.getChiltAt(x, y);
    currentObjectInfo = "";
    currentLocalValueInfo = "";
    currentLocalPositionInfo = "";

    if (currentUnderCursorObj == null || currentUnderCursorObj == root) {
        fireStateChanged();/*from  w  w w.  j  a  v  a 2 s.  c  o  m*/

        if (parentFrame != null) {
            parentFrame.setStatus("");

        }
        tootltipActive = false;
        this.setToolTipText(null);
        return;
    }

    //System.out.println("clicekd - "+((obj==null)?"<empty>":obj.getName()));
    currentObjectInfo = "" + currentUnderCursorObj.getName();

    int[] p = currentUnderCursorObj.getLocalCoords(x, y);
    //System.out.println("["+p[0]+","+p[1]+"]");
    currentLocalPositionInfo = "[" + p[0] + "," + p[1] + "]";

    //System.out.println("local info: " + obj.getGeometryObject2D().getLocalInfoAt(p[0], p[1]));
    currentLocalValueInfo = currentUnderCursorObj.getGeometryObject2D().getLocalInfoAt(p[0], p[1]);

    fireStateChanged();

    if (parentFrame != null) {
        parentFrame.setStatus(
                "" + currentObjectInfo + " | " + currentLocalPositionInfo + " | " + currentLocalValueInfo);

    }

    if (tootltipActive) {
        this.setToolTipText(currentUnderCursorObj.getGeometryObject2D().getDetailedLocalInfoAt(p[0], p[1]));
        ToolTipManager.sharedInstance().setInitialDelay(0);
        ToolTipManager.sharedInstance().setDismissDelay(100000);
        ToolTipManager.sharedInstance().mouseMoved(new MouseEvent(this, 0, 0, 0, x, y, // X-Y of the mouse for the tool tip
                0, false));
    } else {
        this.setToolTipText(null);
    }

}

From source file:pl.otros.logview.gui.LogViewMainFrame.java

public LogViewMainFrame(DataConfiguration c) throws InitializationException {
    super();/*from  www .  ja  v a  2s  . c  o  m*/
    this.configuration = c;
    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    String title = "OtrosLogViewer";
    try {
        title += ' ' + VersionUtil.getRunningVersion();
    } catch (Exception e) {
        LOGGER.warning("Can't load version of running OLV");
    }
    this.setTitle(title);
    try {
        String iconPath = "img/otros/logo16.png";
        if (System.getProperty("os.name").contains("Linux")) {
            iconPath = "img/otros/logo64.png";
        }
        BufferedImage icon = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream(iconPath));
        this.setIconImage(icon);
    } catch (Exception e1) {
        LOGGER.warning("Can't load icon: " + e1.getMessage());
    }
    Exception modalDisplayException = null;
    // If non-terminal load problem occurs, queue to display for user on
    // top of the app UI.
    try {
        OtrosSplash.setMessage("Loading plugins");
        LvDynamicLoader.getInstance().setStatusObserver(OtrosSplash.getSplashStatusObserver());
        LvDynamicLoader.getInstance().loadAll();
        OtrosSplash.setMessage("Loading plugins loaded");
    } catch (IOException e) {
        LOGGER.severe("Problem with loading automatic markers, filter or log importers: " + e.getMessage());
        modalDisplayException = e;
    } catch (InitializationException ie) {
        // Details should have been logged at lower level
        modalDisplayException = ie;
    }
    OtrosSplash.setMessage("Initializing GUI");
    allPluginables = AllPluginables.getInstance();
    logImportersContainer = allPluginables.getLogImportersContainer();
    messageColorizercontainer = allPluginables.getMessageColorizers();
    searchResultColorizer = (SearchResultColorizer) messageColorizercontainer
            .getElement(SearchResultColorizer.class.getName());
    cardLayout = new CardLayout();
    cardLayoutPanel = new JPanel(cardLayout);
    JLabel statusLabel = new JLabel(" ");
    observer = new JLabelStatusObserver(statusLabel);
    logsTabbedPane = new JTabbedPane();
    enableDisableComponetsForTabs = new EnableDisableComponetsForTabs(logsTabbedPane);
    logsTabbedPane.addChangeListener(enableDisableComponetsForTabs);

    otrosApplication = new OtrosApplication();
    otrosApplication.setAllPluginables(AllPluginables.getInstance());
    otrosApplication.setApplicationJFrame(this);
    otrosApplication.setConfiguration(configuration);
    otrosApplication.setjTabbedPane(logsTabbedPane);
    otrosApplication.setStatusObserver(observer);
    otrosApplication.setOtrosVfsBrowserDialog(new JOtrosVfsBrowserDialog(getVfsFavoritesConfiguration()));
    otrosApplication.setServices(new ServicesImpl(otrosApplication));
    SingleInstanceRequestResponseDelegate.getInstance().setOtrosApplication(otrosApplication);
    ToolTipManager.sharedInstance().setDismissDelay(5000);

    JProgressBar heapBar = new JProgressBar();
    heapBar.setPreferredSize(new Dimension(190, 15));
    new Thread(new MemoryUsedStatsUpdater(heapBar, 1500), "MemoryUsedUpdater").start();
    JPanel statusPanel = new JPanel(new MigLayout("fill", "[fill, push, grow][right][right]", "[]"));
    statusPanel.add(statusLabel);
    final JButton ideConnectedLabel = new JButton(Ide.IDEA.getIconDiscounted());
    statusPanel.add(ideConnectedLabel);
    statusPanel.add(new JButton(new SwitchAutoJump(otrosApplication)));
    statusPanel.add(heapBar);

    initMenu();
    initToolbar();
    addEmptyViewListener();
    addMenuBarReloadListener();
    otrosApplication.setSearchField(searchField);
    cardLayoutPanel.add(logsTabbedPane, CARD_LAYOUT_LOGS_TABLE);
    EmptyViewPanel emptyViewPanel = new EmptyViewPanel(otrosApplication);
    final JScrollPane jScrollPane = new JScrollPane(emptyViewPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            jScrollPane.getVerticalScrollBar().setValue(0);
        }
    });
    cardLayoutPanel.add(jScrollPane, CARD_LAYOUT_EMPTY);
    cardLayout.show(cardLayoutPanel, CARD_LAYOUT_EMPTY);
    enableDisableComponetsForTabs.stateChanged(null);
    Container cp = getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(toolBar, BorderLayout.NORTH);
    cp.add(cardLayoutPanel, BorderLayout.CENTER);
    cp.add(statusPanel, BorderLayout.SOUTH);
    initGlobalHotKeys();
    initPosition();
    if (configuration.getBoolean(ConfKeys.LOAD_EXPERIMENTAL_FEATURES, false)) {
        initExperimental();
    }
    setTransferHandler(new DragAndDropFilesHandler(otrosApplication));
    initPlugins();
    OtrosSplash.hide();
    setVisible(true);
    if (modalDisplayException != null)
        JOptionPane.showMessageDialog(this,
                "Problem with loading automatic markers," + "filter or log importers:\n"
                        + modalDisplayException.getMessage(),
                "Initialization Error", JOptionPane.ERROR_MESSAGE);
    // Check new version on start
    if (c.getBoolean(ConfKeys.VERSION_CHECK_ON_STARTUP, true)) {
        new ChekForNewVersionOnStartupAction(otrosApplication).actionPerformed(null);
    }
    new TipOfTheDay(c).showTipOfTheDayIfNotDisabled(this);
    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventQueueProxy());
    ListUncaughtExceptionHandlers listUncaughtExceptionHandlers = new ListUncaughtExceptionHandlers(//
            new LoggingExceptionHandler(), //
            new ShowErrorDialogExceptionHandler(otrosApplication), //
            new StatusObserverExceptionHandler(observer));
    Thread.setDefaultUncaughtExceptionHandler(listUncaughtExceptionHandlers);
    ListeningScheduledExecutorService listeningScheduledExecutorService = otrosApplication.getServices()
            .getTaskSchedulerService().getListeningScheduledExecutorService();
    listeningScheduledExecutorService.scheduleAtFixedRate(
            new IdeAvailabilityCheck(ideConnectedLabel, otrosApplication.getServices().getJumpToCodeService()),
            5, 5, TimeUnit.SECONDS);
    ideConnectedLabel.addActionListener(new IdeIntegrationConfigAction(otrosApplication));
}

From source file:processing.app.Editor.java

protected SketchTextArea createTextArea() throws IOException {
    final SketchTextArea textArea = new SketchTextArea(base.getPdeKeywords());
    textArea.requestFocusInWindow();/*from w w w .j  ava 2  s.  c o m*/
    textArea.setMarkOccurrences(PreferencesData.getBoolean("editor.advanced"));
    textArea.setMarginLineEnabled(false);
    textArea.setCodeFoldingEnabled(PreferencesData.getBoolean("editor.code_folding"));
    textArea.setAntiAliasingEnabled(PreferencesData.getBoolean("editor.antialias"));
    textArea.setTabsEmulated(PreferencesData.getBoolean("editor.tabs.expand"));
    textArea.setTabSize(PreferencesData.getInteger("editor.tabs.size"));
    textArea.setEditorListener(new EditorListener(this));
    textArea.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
            try {
                platform.openURL(hyperlinkEvent.getURL().toExternalForm());
            } catch (Exception e) {
                Base.showWarning(e.getMessage(), e.getMessage(), e);
            }
        }
    });
    textArea.addCaretListener(new CaretListener() {

        @Override
        public void caretUpdate(CaretEvent e) {
            int lineStart = textArea.getDocument().getDefaultRootElement().getElementIndex(e.getMark());
            int lineEnd = textArea.getDocument().getDefaultRootElement().getElementIndex(e.getDot());

            lineStatus.set(lineStart, lineEnd);
        }

    });

    ToolTipManager.sharedInstance().registerComponent(textArea);

    configurePopupMenu(textArea);
    return textArea;
}

From source file:processing.app.EditorTab.java

private SketchTextArea createTextArea(RSyntaxDocument document) throws IOException {
    final SketchTextArea textArea = new SketchTextArea(document, editor.base.getPdeKeywords());
    textArea.setName("editor");
    textArea.setFocusTraversalKeysEnabled(false);
    //textArea.requestFocusInWindow();
    textArea.setMarkOccurrences(PreferencesData.getBoolean("editor.advanced"));
    textArea.setMarginLineEnabled(false);
    textArea.setCodeFoldingEnabled(PreferencesData.getBoolean("editor.code_folding"));
    textArea.setAutoIndentEnabled(PreferencesData.getBoolean("editor.indent"));
    textArea.setCloseCurlyBraces(PreferencesData.getBoolean("editor.auto_close_braces", true));
    textArea.setAntiAliasingEnabled(PreferencesData.getBoolean("editor.antialias"));
    textArea.setTabsEmulated(PreferencesData.getBoolean("editor.tabs.expand"));
    textArea.setTabSize(PreferencesData.getInteger("editor.tabs.size"));
    textArea.addHyperlinkListener(evt -> {
        try {// w ww. j  av a 2  s  .c  o m
            UpdatableBoardsLibsFakeURLsHandler boardLibHandler = new UpdatableBoardsLibsFakeURLsHandler(
                    editor.base);
            boardLibHandler.openBoardLibManager(evt.getURL());
        } catch (Exception e) {
            try {
                editor.platform.openURL(editor.getSketch().getFolder(), evt.getURL().toExternalForm());
            } catch (Exception f) {
                Base.showWarning(f.getMessage(), f.getMessage(), f);
            }
        }
    });
    textArea.addCaretListener(e -> {
        Element root = textArea.getDocument().getDefaultRootElement();
        int lineStart = root.getElementIndex(e.getMark());
        int lineEnd = root.getElementIndex(e.getDot());

        editor.lineStatus.set(lineStart, lineEnd);
    });
    ToolTipManager.sharedInstance().registerComponent(textArea);

    configurePopupMenu(textArea);
    return textArea;
}

From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java

public AsciidocBrowserApplication(final String[] args) {
    super("Asciidoc Browser");
    setIconImage(Icons.APPLICATION.image());

    setSize(1200, 1024);/*from   w  w  w  . j a v a2  s  . co m*/

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent e) {
            actionExit();
        }
    });

    JPanel buttonPanel = new JPanel();
    backButton = new JButton("");
    backButton.setIcon(Icons.BACK.icon());
    backButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionBack();
        }
    });
    buttonPanel.setLayout(new MigLayout("", "[1px][][][][]", "[1px]"));

    JButton btnOptionsbutton = new JButton("");
    btnOptionsbutton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            settingsDialog.setVisible(true);
        }
    });
    btnOptionsbutton.setIcon(Icons.OPTIONS.icon());
    buttonPanel.add(btnOptionsbutton, "flowx,cell 0 0");
    backButton.setEnabled(false);
    buttonPanel.add(backButton, "cell 0 0,grow");
    forwardButton = new JButton("");
    forwardButton.setIcon(Icons.FORWARD.icon());
    forwardButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionForward();
        }
    });
    forwardButton.setEnabled(false);
    buttonPanel.add(forwardButton, "cell 0 0,grow");
    getContentPane().setLayout(new MigLayout("", "[793.00px,grow]", "[44px][930px]"));
    getContentPane().add(buttonPanel, "cell 0 0,growx,aligny top");
    locationTextField = new JTextField(65);
    locationTextField.setText("");
    locationTextField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB) {
                actionGo();
                refreshDocumentTree();
            }
        }
    });
    locationTextField.setTransferHandler(
            new TextFieldTransferHandler(locationTextField.getTransferHandler(), new Runnable() {
                @Override
                public void run() {
                    locationTextField.setText("");
                }
            }, new Runnable() {

                @Override
                public void run() {
                    actionGo();
                    refreshDocumentTree();
                }
            }));

    homebutton = new JButton("");
    homebutton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            locationTextField.setText(Settings.getHome());
            actionGo();
            refreshDocumentTree();
        }
    });

    refreshButton = new JButton("");
    refreshButton.setToolTipText("Refresh");
    refreshButton.setEnabled(false);
    refreshButton.setIcon(Icons.REFRESH.icon());
    refreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionGo();
            refreshPreview();
        }
    });
    buttonPanel.add(refreshButton, "cell 1 0");

    homebutton.setIcon(Icons.HOME.icon());
    buttonPanel.add(homebutton, "cell 2 0");
    buttonPanel.add(locationTextField, "cell 3 0,grow");

    treeSourceSplitPane = new JSplitPane();
    treeSourceSplitPane.setResizeWeight(0.3);
    getContentPane().add(treeSourceSplitPane, "cell 0 1,grow");

    treeScrollPane = new JScrollPane();
    treeScrollPane.setMinimumSize(new Dimension(200, 200));
    treeSourceSplitPane.setLeftComponent(treeScrollPane);

    documentTree = new DocumentTree(documentModel);
    documentTree.setCellRenderer(new TooltipsTreeCellRenderer());
    ToolTipManager.sharedInstance().registerComponent(documentTree);
    ToolTipManager.sharedInstance().setInitialDelay(INITIAL_TOOLTIP_DELAY);
    ToolTipManager.sharedInstance().setReshowDelay(0);
    documentTree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(final TreeSelectionEvent tse) {
            TreePath newLeadSelectionPath = tse.getNewLeadSelectionPath();
            if (newLeadSelectionPath != null && !newLeadSelectionPath.equals(currentSelectionPath)) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) newLeadSelectionPath
                        .getLastPathComponent();
                FileWrapper file = (FileWrapper) node.getUserObject();
                showFile(file, true);
                refreshPreview();
            }
        }
    });
    treeScrollPane.setViewportView(documentTree);

    sourceEditorPane = new JEditorPane();
    sourceEditorPane.setContentType("text/html");
    sourceEditorPane.setEditable(false);
    sourceEditorPane.addHyperlinkListener(new HandleHyperlinkUpdate());
    JScrollPane fileScrollPane = new JScrollPane(sourceEditorPane);
    fileScrollPane.setMinimumSize(new Dimension(600, 600));

    documentTabbedPane = new JTabbedPane(SwingConstants.BOTTOM);
    documentTabbedPane.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(final ChangeEvent ce) {
            refreshPreview();
        }
    });
    sourceLogSplitPane = new JSplitPane();
    sourceLogSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    treeSourceSplitPane.setRightComponent(sourceLogSplitPane);
    sourceLogSplitPane.setTopComponent(documentTabbedPane);
    documentTabbedPane.add(fileScrollPane);
    documentTabbedPane.setTitleAt(0, "Source");

    browserPane = new BrowserPane();

    previewScrollPane = new JScrollPane(browserPane);
    documentTabbedPane.addTab("Preview", null, previewScrollPane, null);

    console = new JConsole();
    System.setErr(console.getErr());
    System.setOut(console.getOut());
    sourceLogSplitPane.setBottomComponent(console);

    executor = new AsciidocExecutor();
}

From source file:view.MainWindow.java

private void setupTreePopups() {
    jtOpenedDocuments.addMouseListener(new MouseAdapter() {
        @Override//from w w  w  . ja  v a 2  s. com
        public void mouseClicked(MouseEvent e) {

            if (SwingUtilities.isRightMouseButton(e)) {
                JPopupMenu popup = new JPopupMenu();
                if (null != jtOpenedDocuments.getSelectionRows()) {
                    if (1 >= jtOpenedDocuments.getSelectionRows().length) {
                        int row = jtOpenedDocuments.getClosestRowForLocation(e.getX(), e.getY());
                        jtOpenedDocuments.setSelectionRow(row);
                    } else {
                        int row = jtOpenedDocuments.getClosestRowForLocation(e.getX(), e.getY());
                        boolean selected = false;
                        for (int i : jtOpenedDocuments.getSelectionRows()) {
                            if (i == row) {
                                selected = true;
                                break;
                            }
                        }
                        if (!selected) {
                            jtOpenedDocuments.setSelectionRow(row);
                        }
                    }

                    JMenuItem m = null;
                    ActionListener open = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            loadPdf(getSelectedFile(jtOpenedDocuments), true);
                        }
                    };

                    ActionListener remove = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            closeDocument(true);
                        }
                    };

                    ActionListener removeOthers = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            final ArrayList<File> alFilesToClose = new ArrayList<>();
                            boolean showDialog = false;
                            for (File file : getOpenedFiles()) {
                                if (!getSelectedOpenedFiles().contains(file)) {
                                    alFilesToClose.add(file);
                                    if (file.equals(openedFile)) {
                                        showDialog = true;
                                    }
                                }
                            }
                            closeDocuments(alFilesToClose, showDialog);
                        }
                    };

                    ActionListener removeAll = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            closeDocuments(getOpenedFiles(), true);
                        }
                    };

                    ActionListener show = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            try {
                                Desktop.getDesktop().open(getSelectedFile(jtOpenedDocuments).getParentFile());
                            } catch (IOException ex) {
                                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    };

                    if (!openedFile.equals(getSelectedFile(jtOpenedDocuments))) {
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.open"));
                        m.addActionListener(open);
                        popup.add(m);
                    }
                    m = new JMenuItem(getSelectedOpenedFiles().size() > 1
                            ? Bundle.getBundle().getString("menuItem.removeTheseLoadedDocuments")
                            : Bundle.getBundle().getString("menuItem.removeThisLoadedDocument"));
                    m.addActionListener(remove);
                    popup.add(m);
                    if (getOpenedFiles().size() > 1) {
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.removeOtherLoadedDocuments"));
                        m.addActionListener(removeOthers);
                        popup.add(m);
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.removeAllLoadedDocuments"));
                        m.addActionListener(removeAll);
                        popup.add(m);
                    }
                    if (getSelectedOpenedFiles().size() == 1) {
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer"));
                        m.addActionListener(show);
                        popup.add(m);
                    }

                    popup.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    jtExplorer.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {

            if (SwingUtilities.isRightMouseButton(e)) {
                JPopupMenu popup = new JPopupMenu();
                if (null != jtExplorer.getSelectionRows()) {
                    if (1 >= jtExplorer.getSelectionRows().length) {
                        int row = jtExplorer.getClosestRowForLocation(e.getX(), e.getY());
                        jtExplorer.setSelectionRow(row);
                    } else {
                        int row = jtExplorer.getClosestRowForLocation(e.getX(), e.getY());
                        boolean selected = false;
                        for (int i : jtExplorer.getSelectionRows()) {
                            if (i == row) {
                                selected = true;
                                break;
                            }
                        }
                        if (!selected) {
                            jtExplorer.setSelectionRow(row);
                        }
                    }

                    JMenuItem m = null;
                    ActionListener loadFile = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (jtExplorer.getSelectionRows().length == 1) {
                                loadPdf(getSelectedFile(jtExplorer), true);
                            } else {
                                ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer);
                                for (File f : sl) {
                                    loadPdf(f, false);
                                }
                            }
                        }
                    };
                    ActionListener loadFolder = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (jtExplorer.getSelectionRows().length == 1) {
                                File f = getSelectedFile(jtExplorer);
                                loadFolder(f, false);
                            } else {
                                ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer);
                                for (File f : sl) {
                                    loadFolder(f, false);
                                }
                            }
                        }
                    };
                    ActionListener loadFolderRecursively = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (jtExplorer.getSelectionRows().length == 1) {
                                File f = getSelectedFile(jtExplorer);
                                loadFolder(f, true);
                            } else {
                                ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer);
                                for (File s : sl) {
                                    loadFolder(s, true);
                                }
                            }
                        }
                    };
                    ActionListener remove = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            ArrayList<File> listaF = getMultipleSelectedFiles(jtExplorer);
                            closeDocuments(listaF, true);
                        }
                    };

                    ActionListener show = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            try {
                                Desktop.getDesktop()
                                        .open(getSelectedFile(jtExplorer).isFile()
                                                ? getSelectedFile(jtExplorer).getParentFile()
                                                : getSelectedFile(jtExplorer));
                            } catch (IOException ex) {
                                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    };

                    if (files.isEmpty()) {
                        if (jtExplorer.getSelectionRows().length <= 1) {
                            File f = getSelectedFile(jtExplorer);
                            if (f.isDirectory()) {
                                m = new JMenuItem(
                                        Bundle.getBundle().getString("menuItem.openDocumentsInThisFolder"));
                                m.addActionListener(loadFolder);
                                popup.add(m);
                                m = new JMenuItem(Bundle.getBundle()
                                        .getString("menuItem.openDocumentsThisFolderRecursive"));
                                m.addActionListener(loadFolderRecursively);
                                popup.add(m);
                                m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer"));
                                m.addActionListener(show);
                                popup.add(m);
                            } else {
                                m = new JMenuItem(Bundle.getBundle().getString("menuItem.openDocument"));
                                m.addActionListener(loadFile);
                                popup.add(m);
                                m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer"));
                                m.addActionListener(show);
                                popup.add(m);
                            }

                        } else {
                            ArrayList<File> l = getMultipleSelectedFiles(jtExplorer);
                            boolean file = l.get(0).isFile();
                            boolean allSame = true;
                            for (File f : l) {
                                if (file != f.isFile()) {
                                    allSame = false;
                                    break;
                                }
                            }
                            if (allSame) {
                                if (file) {
                                    m = new JMenuItem(Bundle.getBundle().getString("menuItem.openDocuments"));
                                    m.addActionListener(loadFile);
                                    popup.add(m);
                                } else {
                                    m = new JMenuItem(Bundle.getBundle()
                                            .getString("menuItem.openDocumentsInTheseFolders"));
                                    m.addActionListener(loadFolder);
                                    popup.add(m);
                                }
                            }
                        }
                    } else {
                        File f = getSelectedFile(jtExplorer);
                        if (f.isDirectory()) {
                            m = new JMenuItem(
                                    Bundle.getBundle().getString("menuItem.openDocumentsInThisFolder"));
                            m.addActionListener(loadFolder);
                            popup.add(m);
                            m = new JMenuItem(
                                    Bundle.getBundle().getString("menuItem.openDocumentsThisFolderRecursive"));
                            m.addActionListener(loadFolderRecursively);
                            popup.add(m);
                        } else if (files.contains(getSelectedFile(jtExplorer))) {
                            m = new JMenuItem(
                                    Bundle.getBundle().getString("menuItem.removeFromLoadedDocuments"));
                            m.addActionListener(remove);
                            popup.add(m);
                        } else {
                            m = new JMenuItem(Bundle.getBundle().getString("menuItem.addToLoadedDocuments"));
                            m.addActionListener(loadFile);
                            popup.add(m);
                        }
                    }
                    popup.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    jtExplorer.setCellRenderer(new TooltipTreeCellRenderer());
    ToolTipManager.sharedInstance().registerComponent(jtExplorer);

    FileListTreeCellRenderer renderer1 = new FileListTreeCellRenderer((MainWindow) this);
    jtOpenedDocuments.setCellRenderer(renderer1);
    ToolTipManager.sharedInstance().registerComponent(jtOpenedDocuments);
}

From source file:view.MultipleValidationDialog.java

/**
 * Creates new form MultipleValidationDialog
 *
 * @param parent/*from   w  w  w . j a  va 2  s  .  c  om*/
 * @param modal
 * @param files
 */
public MultipleValidationDialog(java.awt.Frame parent, boolean modal, final ArrayList<File> files) {
    super(parent, modal);
    initComponents();

    updateText();

    this.setSize(1024, 768);
    lblRevision.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    final DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode(null);
    panelSignatureDetails.setVisible(false);
    btnSaveInFile.setEnabled(false);
    jtValidation.setModel(null);
    jtValidation.setVisible(false);
    progressBar.setString(Bundle.getBundle().getString("pb.validating") + " 1 "
            + Bundle.getBundle().getString("of") + " " + files.size());
    progressBar.setMaximum(files.size());
    final ValidationListener vl = new ValidationListener() {
        int numParsed = 1;

        @Override
        public void onValidationComplete(SignatureValidation sv) {
            Map.Entry<ValidationFileListEntry, ArrayList<SignatureValidation>> tempEntry = null;
            while (tempEntry == null) {
                for (Map.Entry<ValidationFileListEntry, ArrayList<SignatureValidation>> entry : hmValidation
                        .entrySet()) {
                    if (entry.getKey().getFilename().equals(sv.getFilename())) {
                        tempEntry = entry;
                        break;
                    }
                }
                if (sv.isCertification()) {
                    if (sv.isValid()) {
                        tempEntry.getKey()
                                .setValidationStatus(ValidationFileListEntry.ValidationStatus.CERTIFIED);
                    } else {
                        tempEntry.getKey()
                                .setValidationStatus(ValidationFileListEntry.ValidationStatus.INVALID);
                    }
                } else if (sv.isValid()) {
                    tempEntry.getKey().setValidationStatus(ValidationFileListEntry.ValidationStatus.ALL_OK);
                } else {
                    tempEntry.getKey().setValidationStatus(ValidationFileListEntry.ValidationStatus.INVALID);
                }
                tempEntry.getValue().add(sv);
            }
        }
    };

    Runnable r = new Runnable() {
        @Override
        public void run() {
            int numParsed = 0;
            for (File file : files) {
                try {
                    ArrayList<SignatureValidation> svList = new ArrayList<>();
                    int numSigs = CCInstance.getInstance().getNumberOfSignatures(file.getAbsolutePath());
                    ValidationFileListEntry vfle = new ValidationFileListEntry(file.getAbsolutePath(), numSigs,
                            ValidationFileListEntry.ValidationStatus.UNKNOWN);
                    hmValidation.put(vfle, svList);
                    CCInstance.getInstance().validatePDF(file.getAbsolutePath(), vl);
                    dmtn.insert(new DefaultMutableTreeNode(vfle), 0);
                } catch (IOException | DocumentException | GeneralSecurityException ex) {
                    if (ex.getLocalizedMessage().contains("keystore\\aCCinaPDF_cacerts")) {
                        JOptionPane.showMessageDialog(MultipleValidationDialog.this,
                                Bundle.getBundle().getString("errorDefaultKeystore"),
                                WordUtils.capitalize(Bundle.getBundle().getString("error")),
                                JOptionPane.ERROR_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(MultipleValidationDialog.this,
                                Bundle.getBundle().getString("unknownErrorLog"),
                                WordUtils.capitalize(Bundle.getBundle().getString("error")),
                                JOptionPane.ERROR_MESSAGE);
                        controller.Logger.getLogger().addEntry(ex);
                    }
                    break;
                }
                numParsed++;
                progressBar.setValue(numParsed);
                progressBar.setString(Bundle.getBundle().getString("pb.validating") + " " + numParsed + " "
                        + Bundle.getBundle().getString("of") + " " + files.size());

                TreeModel tm = new DefaultTreeModel(dmtn);
                jtFiles.setModel(tm);
            }
            progressBar.setString(Bundle.getBundle().getString("pb.validationComplete"));
            if (numParsed > 0) {
                jtFiles.setSelectionRow(0);
                btnSaveInFile.setEnabled(true);
            }
        }
    };

    Thread t = new Thread(r);
    t.start();

    jtValidation.setVisible(true);

    FileListTreeCellRenderer renderer1 = new FileListTreeCellRenderer();
    jtFiles.setCellRenderer(renderer1);
    ToolTipManager.sharedInstance().registerComponent(jtFiles);
    ValidationTreeCellRenderer renderer = new ValidationTreeCellRenderer();
    jtValidation.setCellRenderer(renderer);
}

From source file:view.WorkspacePanel.java

/**
 * Creates new form MiddlePanel/*from w ww. ja  va  2  s  . co m*/
 */
public WorkspacePanel() {
    initComponents();
    if (Bundle.getBundle().getCurrentLocale() == null) {
        Bundle.getBundle().setCurrentLocale(Bundle.Locales.English);
    }
    updateText();
    status = Status.READY;
    cl = (CardLayout) this.rightPanel.getLayout();
    topToolbar.setVisible(false);
    bottomToolbar.setVisible(false);
    rightPanel.setVisible(false);
    clSign.setVisible(false);
    rightPanel.setBackground(Color.WHITE);
    lblText.setVisible(false);
    jScrollPane1.setVisible(false);
    btnChangeAppearance.setVisible(false);
    add(jMenuBar1, BorderLayout.NORTH);
    ToolTipManager.sharedInstance().registerComponent(jtValidation);
    jSplitPane1.setDividerSize(0);
    cbVisibleSignature.setSelected(true);
    lblRevision.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    clearSignatureFields();
    jsImagePanel.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.isControlDown()) {
                e.consume();
                if (e.getWheelRotation() < 0) {
                    zoomIn();
                } else {
                    zoomOut();
                }
                fixTempSignaturePosition(true);
            }
        }
    });
}