Search in sources :

Example 21 with JWindow

use of javax.swing.JWindow in project clusterMaker2 by RBVI.

the class ResultsPanel method createClusterImage.

/**
 * Convert a network to an image.  This is used by the MCODEResultsPanel.
 *
 * @param cluster Input network to convert to an image
 * @param height  Height that the resulting image should be
 * @param width   Width that the resulting image should be
 * @param layouter Reference to the layout algorithm
 * @param layoutNecessary Determinant of cluster size growth or shrinkage, the former requires layout
 * @return The resulting image
 */
public Image createClusterImage(final NodeCluster cluster, final int height, final int width, SpringEmbeddedLayouter layouter, boolean layoutNecessary) {
    // System.out.println("CCI: inside method");
    final CyRootNetwork root = clusterManager.getService(CyRootNetworkManager.class).getRootNetwork(network);
    // need to create a method get the subnetwork for a cluster
    final CyNetwork net = cluster.getSubNetwork(network, root, SavePolicy.DO_NOT_SAVE);
    // System.out.println("CCI: after getting root and network ");
    // Progress reporters.
    // There are three basic tasks, the progress of each is calculated and then combined
    // using the respective weighting to get an overall progress global progress
    // setting up the nodes and edges is deemed as 25% of the whole task
    int weightSetupNodes = 20;
    int weightSetupEdges = 5;
    // layout it is 70%
    double weightLayout = 75.0;
    double goalTotal = weightSetupNodes + weightSetupEdges;
    if (layoutNecessary) {
        goalTotal += weightLayout;
    }
    // keeps track of progress as a percent of the totalGoal
    double progress = 0;
    final VisualStyle vs = getClusterStyle();
    // System.out.println("CCI: after getClusterStyle");
    final CyNetworkView clusterView = createNetworkView(net, vs);
    // System.out.println("CCI: after createNetworkView");
    clusterView.setVisualProperty(NETWORK_WIDTH, new Double(width));
    clusterView.setVisualProperty(NETWORK_HEIGHT, new Double(height));
    for (View<CyNode> nv : clusterView.getNodeViews()) {
        if (interrupted) {
            // problems the next time around
            if (layouter != null)
                layouter.resetDoLayout();
            resetLoading();
            return null;
        }
        // Node position
        final double x;
        final double y;
        // first prevents the program from throwing a null pointer exception in the second condition)
        if (cluster.getView() != null && cluster.getView().getNodeView(nv.getModel()) != null) {
            // If it does, then we take the layout position that was already generated for it
            x = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_X_LOCATION);
            y = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_Y_LOCATION);
        } else {
            // Otherwise, randomize node positions before layout so that they don't all layout in a line
            // (so they don't fall into a local minimum for the SpringEmbedder)
            // If the SpringEmbedder implementation changes, this code may need to be removed
            // size is small for many default drawn graphs, thus +100
            x = (clusterView.getVisualProperty(NETWORK_WIDTH) + 100) * Math.random();
            y = (clusterView.getVisualProperty(NETWORK_HEIGHT) + 100) * Math.random();
            if (!layoutNecessary) {
                goalTotal += weightLayout;
                progress /= (goalTotal / (goalTotal - weightLayout));
                layoutNecessary = true;
            }
        }
        nv.setVisualProperty(NODE_X_LOCATION, x);
        nv.setVisualProperty(NODE_Y_LOCATION, y);
    // Might be specific to MCODE
    /*
			// Node shape
			if (cluster.getSeedNode() == nv.getModel().getSUID()) {
				nv.setLockedValue(NODE_SHAPE, NodeShapeVisualProperty.RECTANGLE);
			} else {
				nv.setLockedValue(NODE_SHAPE, NodeShapeVisualProperty.ELLIPSE);
			}
			 */
    /*
			// Update loader
			if (loader != null) {
				progress += 100.0 * (1.0 / (double) clusterView.getNodeViews().size()) *
							((double) weightSetupNodes / (double) goalTotal);
				loader.setProgress((int) progress, "Setup: nodes");
			}
			
			*/
    }
    if (clusterView.getEdgeViews() != null) {
        for (int i = 0; i < clusterView.getEdgeViews().size(); i++) {
            if (interrupted) {
                // logger.error("Interrupted: Edge Setup");
                if (layouter != null)
                    layouter.resetDoLayout();
                resetLoading();
                return null;
            }
        /*
				if (loader != null) {
					progress += 100.0 * (1.0 / (double) clusterView.getEdgeViews().size()) *
								((double) weightSetupEdges / (double) goalTotal);
					loader.setProgress((int) progress, "Setup: edges");
				}
				*/
        }
    }
    if (layoutNecessary) {
        if (layouter == null) {
            layouter = new SpringEmbeddedLayouter();
        }
        layouter.setGraphView(clusterView);
        // The doLayout method should return true if the process completes without interruption
        if (!layouter.doLayout(weightLayout, goalTotal, progress)) {
            // Otherwise, if layout is not completed, set the interruption to false, and return null, not an image
            resetLoading();
            return null;
        }
    }
    final Image image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g = (Graphics2D) image.getGraphics();
    SwingUtilities.invokeLater(new Runnable() {

        // @Override
        public void run() {
            try {
                final Dimension size = new Dimension(width, height);
                JPanel panel = new JPanel();
                panel.setPreferredSize(size);
                panel.setSize(size);
                panel.setMinimumSize(size);
                panel.setMaximumSize(size);
                panel.setBackground((Color) vs.getDefaultValue(NETWORK_BACKGROUND_PAINT));
                JWindow window = new JWindow();
                window.getContentPane().add(panel, BorderLayout.CENTER);
                RenderingEngine<CyNetwork> re = renderingEngineFactory.createRenderingEngine(panel, clusterView);
                vs.apply(clusterView);
                clusterView.fitContent();
                clusterView.updateView();
                window.pack();
                window.repaint();
                re.createImage(width, height);
                re.printCanvas(g);
                g.dispose();
                if (clusterView.getNodeViews().size() > 0) {
                    cluster.setView(clusterView);
                }
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    });
    layouter.resetDoLayout();
    resetLoading();
    return image;
}
Also used : JPanel(javax.swing.JPanel) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) Color(java.awt.Color) JWindow(javax.swing.JWindow) CyNetwork(org.cytoscape.model.CyNetwork) Dimension(java.awt.Dimension) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 22 with JWindow

use of javax.swing.JWindow in project gate-core by GateNLP.

the class AnnotationEditor method initGUI.

protected void initGUI() {
    popupWindow = new JWindow(SwingUtilities.getWindowAncestor(owner.getTextComponent())) {

        @Override
        public void pack() {
            // than the main frame
            if (isVisible()) {
                int maxHeight = MainFrame.getInstance().getHeight();
                int otherHeight = getHeight() - featuresScroller.getHeight();
                maxHeight -= otherHeight;
                if (featuresScroller.getPreferredSize().height > maxHeight) {
                    featuresScroller.setMaximumSize(new Dimension(featuresScroller.getMaximumSize().width, maxHeight));
                    featuresScroller.setPreferredSize(new Dimension(featuresScroller.getPreferredSize().width, maxHeight));
                }
            }
            super.pack();
        }

        @Override
        public void setVisible(boolean b) {
            super.setVisible(b);
            // when the editor is shown put the focus in the type combo box
            if (b) {
                typeCombo.requestFocus();
            }
        }
    };
    JPanel pane = new JPanel();
    pane.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
    pane.setLayout(new GridBagLayout());
    pane.setBackground(UIManager.getLookAndFeelDefaults().getColor("ToolTip.background"));
    popupWindow.setContentPane(pane);
    Insets insets0 = new Insets(0, 0, 0, 0);
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.gridwidth = 1;
    constraints.gridy = 0;
    constraints.gridx = GridBagConstraints.RELATIVE;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.insets = insets0;
    solButton = new JButton();
    solButton.setContentAreaFilled(false);
    solButton.setBorderPainted(false);
    solButton.setMargin(insets0);
    pane.add(solButton, constraints);
    sorButton = new JButton();
    sorButton.setContentAreaFilled(false);
    sorButton.setBorderPainted(false);
    sorButton.setMargin(insets0);
    pane.add(sorButton, constraints);
    delButton = new JButton();
    delButton.setContentAreaFilled(false);
    delButton.setBorderPainted(false);
    delButton.setMargin(insets0);
    constraints.insets = new Insets(0, 20, 0, 20);
    pane.add(delButton, constraints);
    constraints.insets = insets0;
    eolButton = new JButton();
    eolButton.setContentAreaFilled(false);
    eolButton.setBorderPainted(false);
    eolButton.setMargin(insets0);
    pane.add(eolButton, constraints);
    eorButton = new JButton();
    eorButton.setContentAreaFilled(false);
    eorButton.setBorderPainted(false);
    eorButton.setMargin(insets0);
    pane.add(eorButton, constraints);
    pinnedButton = new JToggleButton(MainFrame.getIcon("pin"));
    pinnedButton.setSelectedIcon(MainFrame.getIcon("pin-in"));
    pinnedButton.setSelected(false);
    pinnedButton.setBorderPainted(false);
    pinnedButton.setContentAreaFilled(false);
    constraints.weightx = 1;
    constraints.insets = new Insets(0, 0, 0, 0);
    constraints.anchor = GridBagConstraints.EAST;
    pane.add(pinnedButton, constraints);
    dismissButton = new JButton();
    dismissButton.setBorder(null);
    constraints.anchor = GridBagConstraints.NORTHEAST;
    pane.add(dismissButton, constraints);
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.insets = insets0;
    typeCombo = new JComboBox<String>();
    typeCombo.setEditable(true);
    typeCombo.setBackground(UIManager.getLookAndFeelDefaults().getColor("ToolTip.background"));
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridy = 1;
    constraints.gridwidth = 7;
    constraints.weightx = 1;
    constraints.insets = new Insets(3, 2, 2, 2);
    pane.add(typeCombo, constraints);
    featuresEditor = new FeaturesSchemaEditor();
    featuresEditor.setBackground(UIManager.getLookAndFeelDefaults().getColor("ToolTip.background"));
    try {
        featuresEditor.init();
    } catch (ResourceInstantiationException rie) {
        throw new GateRuntimeException(rie);
    }
    constraints.gridy = 2;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.BOTH;
    featuresScroller = new JScrollPane(featuresEditor);
    pane.add(featuresScroller, constraints);
    // add the search and annotate GUI at the bottom of the annotator editor
    SearchAndAnnotatePanel searchPanel = new SearchAndAnnotatePanel(pane.getBackground(), this, popupWindow);
    constraints.insets = new Insets(0, 0, 0, 0);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.gridx = 0;
    constraints.gridy = GridBagConstraints.RELATIVE;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.gridheight = GridBagConstraints.REMAINDER;
    constraints.weightx = 0.0;
    constraints.weighty = 0.0;
    pane.add(searchPanel, constraints);
    popupWindow.pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JWindow(javax.swing.JWindow) JButton(javax.swing.JButton) FeaturesSchemaEditor(gate.gui.FeaturesSchemaEditor) Dimension(java.awt.Dimension) ResourceInstantiationException(gate.creole.ResourceInstantiationException) JToggleButton(javax.swing.JToggleButton) GateRuntimeException(gate.util.GateRuntimeException) SearchAndAnnotatePanel(gate.gui.annedit.SearchAndAnnotatePanel)

Example 23 with JWindow

use of javax.swing.JWindow in project lobcder by skoulouzis.

the class Util method showSplashWindow.

/**
 * <p>Displays a splash window for a specific amount of time with a set of rendering parameters
 * for the message, font type, window size and frame owner.</p>
 *
 * @param message
 * 	- the text to display
 * @param messageFont
 * 	- the font of text
 * @param duration
 * 	- how long to show the window in milliseconds
 * @param windowSize
 * 	- the size of the window
 * @param frameOwner
 * 	- the parent window or owner, null if none
 */
public static void showSplashWindow(String message, Font messageFont, int duration, Dimension windowSize, Window frameOwner) {
    JLabel saved = new JLabel(message);
    saved.setHorizontalAlignment(JLabel.CENTER);
    saved.setOpaque(true);
    saved.setFont(messageFont);
    final JWindow window = new JWindow(frameOwner);
    window.add(saved, BorderLayout.CENTER);
    window.setSize(windowSize);
    saved.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
    center(window);
    window.setVisible(true);
    Timer timer = new Timer(duration, new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            window.setVisible(false);
            window.dispose();
        }
    });
    timer.setRepeats(false);
    timer.start();
}
Also used : Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JWindow(javax.swing.JWindow) JLabel(javax.swing.JLabel)

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