Example usage for java.awt.event ItemListener ItemListener

List of usage examples for java.awt.event ItemListener ItemListener

Introduction

In this page you can find the example usage for java.awt.event ItemListener ItemListener.

Prototype

ItemListener

Source Link

Usage

From source file:cimat.tesis.sna.visualization.ClusteringDemo.java

private void setUpView(BufferedReader br) throws IOException {

    Factory<Number> vertexFactory = new Factory<Number>() {
        int n = 0;

        public Number create() {
            return n++;
        }//from w w  w .j av  a 2 s .  c  o m
    };
    Factory<Number> edgeFactory = new Factory<Number>() {
        int n = 0;

        public Number create() {
            return n++;
        }
    };

    PajekNetReader<Graph<Number, Number>, Number, Number> pnr = new PajekNetReader<Graph<Number, Number>, Number, Number>(
            vertexFactory, edgeFactory);

    final Graph<Number, Number> graph = new SparseMultigraph<Number, Number>();

    pnr.load(br, graph);

    //Create a simple layout frame
    //specify the Fruchterman-Rheingold layout algorithm
    final AggregateLayout<Number, Number> layout = new AggregateLayout<Number, Number>(
            new FRLayout<Number, Number>(graph));

    vv = new VisualizationViewer<Number, Number>(layout);
    vv.setBackground(Color.white);
    //Tell the renderer to use our own customized color rendering
    vv.getRenderContext()
            .setVertexFillPaintTransformer(MapTransformer.<Number, Paint>getInstance(vertexPaints));
    vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<Number, Paint>() {
        public Paint transform(Number v) {
            if (vv.getPickedVertexState().isPicked(v)) {
                return Color.cyan;
            } else {
                return Color.BLACK;
            }
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(MapTransformer.<Number, Paint>getInstance(edgePaints));

    vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Number, Stroke>() {
        protected final Stroke THIN = new BasicStroke(1);
        protected final Stroke THICK = new BasicStroke(2);

        public Stroke transform(Number e) {
            Paint c = edgePaints.get(e);
            if (c == Color.LIGHT_GRAY)
                return THIN;
            else
                return THICK;
        }
    });

    //add restart button
    JButton scramble = new JButton("Restart");
    scramble.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Layout layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }

    });

    DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
    vv.setGraphMouse(gm);

    final JToggleButton groupVertices = new JToggleButton("Group Clusters");

    //Create slider to adjust the number of edges to remove when clustering
    final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL);
    edgeBetweennessSlider.setBackground(Color.WHITE);
    edgeBetweennessSlider.setPreferredSize(new Dimension(210, 50));
    edgeBetweennessSlider.setPaintTicks(true);
    edgeBetweennessSlider.setMaximum(graph.getEdgeCount());
    edgeBetweennessSlider.setMinimum(0);
    edgeBetweennessSlider.setValue(0);
    edgeBetweennessSlider.setMajorTickSpacing(10);
    edgeBetweennessSlider.setPaintLabels(true);
    edgeBetweennessSlider.setPaintTicks(true);

    //      edgeBetweennessSlider.setBorder(BorderFactory.createLineBorder(Color.black));
    //TO DO: edgeBetweennessSlider.add(new JLabel("Node Size (PageRank With Priors):"));
    //I also want the slider value to appear
    final JPanel eastControls = new JPanel();
    eastControls.setOpaque(true);
    eastControls.setLayout(new BoxLayout(eastControls, BoxLayout.Y_AXIS));
    eastControls.add(Box.createVerticalGlue());
    eastControls.add(edgeBetweennessSlider);

    final String COMMANDSTRING = "Edges removed for clusters: ";
    final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue();

    final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize);
    eastControls.setBorder(sliderBorder);
    //eastControls.add(eastSize);
    eastControls.add(Box.createVerticalGlue());

    groupVertices.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            clusterAndRecolor(layout, edgeBetweennessSlider.getValue(), similarColors,
                    e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });

    clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected());

    edgeBetweennessSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                int numEdgesToRemove = source.getValue();
                clusterAndRecolor(layout, numEdgesToRemove, similarColors, groupVertices.isSelected());
                sliderBorder.setTitle(COMMANDSTRING + edgeBetweennessSlider.getValue());
                eastControls.repaint();
                vv.validate();
                vv.repaint();
            }
        }
    });

    Container content = getContentPane();
    content.add(new GraphZoomScrollPane(vv));
    JPanel south = new JPanel();
    JPanel grid = new JPanel(new GridLayout(2, 1));
    grid.add(scramble);
    grid.add(groupVertices);
    south.add(grid);
    south.add(eastControls);
    JPanel p = new JPanel();
    p.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    p.add(gm.getModeComboBox());
    south.add(p);
    content.add(south, BorderLayout.SOUTH);
}

From source file:biomine.bmvis2.crawling.CrawlSuggestionList.java

public CrawlSuggestionList() {
    // setMinimumSize(new Dimension(600,200));

    // initialize layout
    GridBagLayout layout = new GridBagLayout();

    this.setLayout(layout);
    GridBagConstraints c = new GridBagConstraints();

    c.weightx = 1;//from   w ww  .  j  a va 2  s . co m
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = 1;
    c.gridheight = 1;

    dbSelect = new JComboBox();
    for (String db : Databases.getDatabases()) {
        dbSelect.addItem(db);
    }

    dbSelect.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            suggestionQuery.setDb(dbSelect.getSelectedItem().toString());
        }
    });

    this.add(dbSelect, c);
    c.gridy++;
    this.add(query, c);

    c.gridwidth = 1;
    c.weighty = 3;
    c.weightx = 10;
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 0;
    c.gridy++;
    // listScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    listScroller = new JScrollPane(list);
    this.add(listScroller, c);

    c.weighty = 0;
    c.weightx = 10;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy++;
    this.add(new JLabel("Selected nodes:"), c);

    c.weighty = 3;
    c.weightx = 10;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy++;
    JScrollPane selectedScroller = new JScrollPane(selectedList);
    this.add(selectedScroller, c);

    // initialize components
    back.setAction(new AbstractAction("< back to unfiltered results") {

        public void actionPerformed(ActionEvent arg0) {
            suggestionQuery.back();
            updateList();
        }
    });
    query.addCaretListener(new CaretListener() {
        public void caretUpdate(CaretEvent arg0) {
            updateList();
        }

    });

    list.setModel(new SuggestListModel());
    list.addMouseListener(new SuggestMouseListener(list));
    list.addMouseMotionListener(new SuggestMouseListener(list));

    list.setCellRenderer(new SuggestCellRenderer());

    selectedList.setModel(new SelectedListModel());
    selectedList.addMouseListener(new SuggestMouseListener(selectedList));
    selectedList.addMouseMotionListener(new SuggestMouseListener(selectedList));
    selectedList.setCellRenderer(new SuggestCellRenderer());
}

From source file:op.care.med.inventory.DlgNewStocks.java

private void initDialog() {
    ignoreEvent = true;//from w w w . jav a2s  . c  o  m

    expiry = null;
    logicalPrinter = OPDE.getPrintProcessor().getSelectedLogicalPrinter();
    printForm = OPDE.getPrintProcessor().getSelectedForm();

    if (logicalPrinter != null && printForm != null) {
        btnPrint.setEnabled(true);
        SYSPropsTools.restoreState(this.getClass().getName() + "::btnPrint", btnPrint);
    } else {
        btnPrint.setSelected(false);
    }

    lblPZN.setText(SYSTools.xx("newstocks.lblPZN"));
    lblProd.setText(SYSTools.xx("newstocks.lblProd"));
    lblPack.setText(SYSTools.xx("newstocks.lblPack"));
    lblAmount.setText(SYSTools.xx("newstocks.lblAmount"));
    lblInventory.setText(SYSTools.xx("newstocks.lblInventory"));
    lblRemark.setText(SYSTools.xx("misc.msg.comment"));
    lblExpires.setText(SYSTools.xx("misc.msg.expires"));
    lblResident.setText(SYSTools.xx("misc.msg.resident"));

    amount = null;
    cmbMProdukt.setRenderer(TradeFormTools.getRenderer(TradeFormTools.LONG));

    attentionIconVorrat = new JLabel(
            OverlayableUtils.getPredefinedOverlayIcon(OverlayableIconsFactory.ATTENTION));
    infoIconVorrat = new JLabel(OverlayableUtils.getPredefinedOverlayIcon(OverlayableIconsFactory.INFO));
    correctIconVorrat = new JLabel(OverlayableUtils.getPredefinedOverlayIcon(OverlayableIconsFactory.CORRECT));
    questionIconVorrat = new JLabel(
            OverlayableUtils.getPredefinedOverlayIcon(OverlayableIconsFactory.QUESTION));

    cmbVorrat = new OverlayComboBox();
    cmbVorrat.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent itemEvent) {
            inventory = (MedInventory) itemEvent.getItem();
        }
    });
    cmbVorrat.setFont(SYSConst.ARIAL14);
    ovrVorrat = new DefaultOverlayable(cmbVorrat);
    mainPane.add(ovrVorrat, CC.xywh(5, 13, 4, 1));

    attentionIconBW = new JLabel(OverlayableUtils.getPredefinedOverlayIcon(OverlayableIconsFactory.ATTENTION));
    cmbBW = new OverlayComboBox();
    cmbBW.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent itemEvent) {
            cmbBWItemStateChanged(itemEvent);
        }
    });
    cmbBW.setFont(SYSConst.ARIAL14);
    ovrBW = new DefaultOverlayable(cmbBW);
    mainPane.add(ovrBW, CC.xywh(7, 17, 2, 1));

    if (resident == null) {
        ovrBW.addOverlayComponent(attentionIconBW, DefaultOverlayable.SOUTH_WEST);
        attentionIconBW.setToolTipText(SYSTools.xx("misc.msg.emptyselection"));
    } else {
        txtBWSuche.setEnabled(false);
        cmbBW.setModel(new DefaultComboBoxModel(new Resident[] { resident }));
    }

    attentionIconMenge = new JLabel(
            OverlayableUtils.getPredefinedOverlayIcon(OverlayableIconsFactory.ATTENTION));
    correctIconMenge = new JLabel(OverlayableUtils.getPredefinedOverlayIcon(OverlayableIconsFactory.CORRECT));
    txtMenge = new OverlayTextField();
    txtMenge.addCaretListener(new CaretListener() {
        @Override
        public void caretUpdate(CaretEvent caretEvent) {
            txtMengeCaretUpdate(caretEvent);
        }
    });
    txtMenge.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent focusEvent) {
            txtMengeFocusGained(focusEvent);
        }
    });
    txtMenge.setFont(SYSConst.ARIAL14);
    ovrMenge = new DefaultOverlayable(txtMenge);
    mainPane.add(ovrMenge, CC.xy(5, 11));

    lblWeightControl.setText(SYSTools.xx("opde.medication.tx.controlWeight"));
    lblWeightControl.setToolTipText(SYSTools.xx("opde.medication.controlWeight.newBottle.bottle.only"));
    weight = null;
    txtWeightControl.setVisible(false);
    txtWeightControl.setText("");
    lblWeightControl.setVisible(false);

    ignoreEvent = false;
    setVisible(true);
}

From source file:com.google.code.facebook.graph.sna.applet.LensDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the zoomand hyperbolic features.
 * /*from   w  w w.  j  a v  a2  s  . co m*/
 */
public LensDemo() {

    // create a simple graph for the demo
    graph = TestGraphs.getOneComponentGraph();

    graphLayout = new FRLayout<String, Number>(graph);
    ((FRLayout) graphLayout).setMaxIterations(1000);

    Dimension preferredSize = new Dimension(600, 600);
    Map<String, Point2D> map = new HashMap<String, Point2D>();
    Transformer<String, Point2D> vlf = TransformerUtils.mapTransformer(map);
    grid = this.generateVertexGrid(map, preferredSize, 25);
    gridLayout = new StaticLayout<String, Number>(grid, vlf, preferredSize);

    final VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>(
            graphLayout, preferredSize);
    vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);

    PickedState<String> ps = vv.getPickedVertexState();
    PickedState<Number> pes = vv.getPickedEdgeState();
    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(ps, Color.red, Color.yellow));
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.cyan));
    vv.setBackground(Color.white);

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());

    final Transformer<String, Shape> ovals = vv.getRenderContext().getVertexShapeTransformer();
    final Transformer<String, Shape> squares = new ConstantTransformer(new Rectangle2D.Float(-10, -10, 20, 20));

    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller());

    Container content = getContentPane();
    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    content.add(gzsp);

    /**
     * the regular graph mouse for the normal view
     */
    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    hyperbolicViewSupport = new ViewLensSupport<String, Number>(vv,
            new HyperbolicShapeTransformer(vv,
                    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)),
            new ModalLensGraphMouse());
    hyperbolicLayoutSupport = new LayoutLensSupport<String, Number>(vv,
            new HyperbolicTransformer(vv,
                    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)),
            new ModalLensGraphMouse());
    magnifyViewSupport = new ViewLensSupport<String, Number>(vv,
            new MagnifyShapeTransformer(vv,
                    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)),
            new ModalLensGraphMouse(new LensMagnificationGraphMousePlugin(1.f, 6.f, .2f)));
    magnifyLayoutSupport = new LayoutLensSupport<String, Number>(vv,
            new MagnifyTransformer(vv,
                    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)),
            new ModalLensGraphMouse(new LensMagnificationGraphMousePlugin(1.f, 6.f, .2f)));
    hyperbolicLayoutSupport.getLensTransformer()
            .setLensShape(hyperbolicViewSupport.getLensTransformer().getLensShape());
    magnifyViewSupport.getLensTransformer()
            .setLensShape(hyperbolicLayoutSupport.getLensTransformer().getLensShape());
    magnifyLayoutSupport.getLensTransformer()
            .setLensShape(magnifyViewSupport.getLensTransformer().getLensShape());

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    ButtonGroup radio = new ButtonGroup();
    JRadioButton normal = new JRadioButton("None");
    normal.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                if (hyperbolicViewSupport != null) {
                    hyperbolicViewSupport.deactivate();
                }
                if (hyperbolicLayoutSupport != null) {
                    hyperbolicLayoutSupport.deactivate();
                }
                if (magnifyViewSupport != null) {
                    magnifyViewSupport.deactivate();
                }
                if (magnifyLayoutSupport != null) {
                    magnifyLayoutSupport.deactivate();
                }
            }
        }
    });

    final JRadioButton hyperView = new JRadioButton("Hyperbolic View");
    hyperView.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    final JRadioButton hyperModel = new JRadioButton("Hyperbolic Layout");
    hyperModel.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            hyperbolicLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    final JRadioButton magnifyView = new JRadioButton("Magnified View");
    magnifyView.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            magnifyViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    final JRadioButton magnifyModel = new JRadioButton("Magnified Layout");
    magnifyModel.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            magnifyLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    JLabel modeLabel = new JLabel("     Mode Menu >>");
    modeLabel.setUI(new VerticalLabelUI(false));
    radio.add(normal);
    radio.add(hyperModel);
    radio.add(hyperView);
    radio.add(magnifyModel);
    radio.add(magnifyView);
    normal.setSelected(true);

    graphMouse.addItemListener(hyperbolicLayoutSupport.getGraphMouse().getModeListener());
    graphMouse.addItemListener(hyperbolicViewSupport.getGraphMouse().getModeListener());
    graphMouse.addItemListener(magnifyLayoutSupport.getGraphMouse().getModeListener());
    graphMouse.addItemListener(magnifyViewSupport.getGraphMouse().getModeListener());

    ButtonGroup graphRadio = new ButtonGroup();
    JRadioButton graphButton = new JRadioButton("Graph");
    graphButton.setSelected(true);
    graphButton.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                visualizationModel.setGraphLayout(graphLayout);
                vv.getRenderContext().setVertexShapeTransformer(ovals);
                vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
                vv.repaint();
            }
        }
    });
    JRadioButton gridButton = new JRadioButton("Grid");
    gridButton.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                visualizationModel.setGraphLayout(gridLayout);
                vv.getRenderContext().setVertexShapeTransformer(squares);
                vv.getRenderContext().setVertexLabelTransformer(new ConstantTransformer(null));
                vv.repaint();
            }
        }
    });
    graphRadio.add(graphButton);
    graphRadio.add(gridButton);

    JPanel modePanel = new JPanel(new GridLayout(3, 1));
    modePanel.setBorder(BorderFactory.createTitledBorder("Display"));
    modePanel.add(graphButton);
    modePanel.add(gridButton);

    JMenuBar menubar = new JMenuBar();
    menubar.add(graphMouse.getModeMenu());
    gzsp.setCorner(menubar);

    Box controls = Box.createHorizontalBox();
    JPanel zoomControls = new JPanel(new GridLayout(2, 1));
    zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom"));
    JPanel hyperControls = new JPanel(new GridLayout(3, 2));
    hyperControls.setBorder(BorderFactory.createTitledBorder("Examiner Lens"));
    zoomControls.add(plus);
    zoomControls.add(minus);

    hyperControls.add(normal);
    hyperControls.add(new JLabel());

    hyperControls.add(hyperModel);
    hyperControls.add(magnifyModel);

    hyperControls.add(hyperView);
    hyperControls.add(magnifyView);

    controls.add(zoomControls);
    controls.add(hyperControls);
    controls.add(modePanel);
    controls.add(modeLabel);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToColor.java

public NumberToColor() {
    setName("Number to Color");
    setDescription("Use color to represent numeric values");

    //initialize UI
    configUI.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;//from w  w  w.j  ava  2  s  .co m
    c.gridy = 0;
    c.ipadx = 5;
    c.ipady = 5;
    c.insets = new Insets(5, 5, 5, 5);
    c.gridwidth = 2;
    //        c.weightx = 0.8;

    editor = new GradientEditorPanel();
    configUI.add(editor, c);

    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 1;
    //        JButton button = new JButton("Apply");
    //        configUI.add(button, c);
    //        button.setToolTipText("Apply preset gradient");
    //
    //        button.addActionListener(new ActionListener() {
    //
    //            @Override
    //            public void actionPerformed(ActionEvent e) {
    //
    //                try {
    //                    GradientItem item = (GradientItem) presetColorComboBox.getSelectedItem();
    //
    //                    editor.clearColors();
    //
    //                    Color c[] = item.getColors();
    //                    float p[] = item.getPositions();
    //
    //                    editor.setStart(c[0]);
    //                    editor.setEnd(c[c.length - 1]);
    //
    //                    if (c.length > 2) {
    //                        for (int i = 1; i < c.length - 1; i++) {
    //                            editor.addColor(c[i], p[i]);
    //                        }
    //                    }
    //
    //                } catch (Exception ex) {
    //                    editor.clearColors();
    //                    editor.setStart(DEFAULT_MIN_COLOR);
    //                    editor.setEnd(DEFAULT_MAX_COLOR);
    //                }
    //
    //                updateRenderer();
    //            }
    //        });
    configUI.add(new JLabel("Preset palette:"), c);

    c.gridx = 1;
    c.gridwidth = 1;
    presetColorComboBox = new JComboBox();

    presetColorComboBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {

            try {
                GradientItem item = (GradientItem) presetColorComboBox.getSelectedItem();
                presetColorComboBox.setToolTipText(item.getToolTip());

                editor.clearColors();

                Color c[] = item.getColors();
                float p[] = item.getPositions();

                editor.setStart(c[0]);
                editor.setEnd(c[c.length - 1]);

                if (c.length > 2) {
                    for (int i = 1; i < c.length - 1; i++) {
                        editor.addColor(c[i], p[i]);
                    }
                }

                try {
                    Double[] ranges = item.getRanges();
                    if (ranges != null) {
                        minValueField.setText(ranges[0].toString());
                        maxValueField.setText(ranges[1].toString());
                        editor.setMinValue(ranges[0].floatValue());
                        editor.setMaxValue(ranges[1].floatValue());
                    }
                } catch (Exception ex) {
                    minValueField.setText("-1");
                    maxValueField.setText("1");
                    editor.setMinValue(-1);
                    editor.setMaxValue(1);
                }

            } catch (Exception ex) {
                editor.clearColors();
                editor.setStart(DEFAULT_MIN_COLOR);
                editor.setEnd(DEFAULT_MAX_COLOR);
            }
        }
    });

    //       
    configUI.add(presetColorComboBox, c);
    presetColorComboBox.setRenderer(new GradientComboItemRenderer());

    presetColorComboBox
            .addItem(new GradientItem(new Color[] { DEFAULT_MIN_COLOR, Color.BLACK, DEFAULT_MAX_COLOR },
                    new float[] { 0f, 0.5f, 1f }, "TBP", "Teal - Black - Pink"));

    presetColorComboBox.addItem(new GradientItem(new Color[] { Color.GREEN, Color.RED }, new float[] { 0f, 1f },
            "GR", "Green - Red"));

    presetColorComboBox.addItem(new GradientItem(new Color[] { Color.GREEN, Color.BLACK, Color.RED },
            new float[] { 0f, 0.5f, 1f }, "RBG", "Red - Black - Green"));

    presetColorComboBox.addItem(new GradientItem(new Color[] { Color.ORANGE, Color.BLUE },
            new float[] { 0f, 1f }, "OB", "Orange - Blue"));

    presetColorComboBox.addItem(new GradientItem(new Color[] { Color.ORANGE, Color.BLACK, Color.BLUE },
            new float[] { 0f, 0.5f, 1f }, "OBB", "Orange - Black - Blue"));

    presetColorComboBox.addItem(new GradientItem(new Color[] { Color.BLACK, Color.GREEN },
            new float[] { 0f, 1f }, "BG", "Black - Green"));

    presetColorComboBox
            .addItem(new GradientItem(new Color[] { Color.RED, UI.colorAKABENI, Color.BLACK, Color.BLACK },
                    new float[] { 0f, 0.05f, 0.051f, 1f }, "P.05", 0d, 1d, "P-value @ 0.05, Red to Black"));

    presetColorComboBox.setToolTipText(((GradientItem) presetColorComboBox.getSelectedItem()).getToolTip());

    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 1;
    //        button = new JButton("Apply");
    //        
    //        button.setToolTipText("Apply preset data ranges");
    //        button.addActionListener(new ActionListener() {
    //
    //            @Override
    //            public void actionPerformed(ActionEvent e) {
    //                try {
    //                    MinMaxItem item = (MinMaxItem) (presetRangeComboBox.getSelectedItem());
    //                    minValueField.setText(item.getMinMax().lowerEndpoint().toString());
    //                    maxValueField.setText(item.getMinMax().upperEndpoint().toString());
    //                } catch (Exception ex) {
    //                    minValueField.setText("-1");
    //                    maxValueField.setText("1");
    //                }
    //
    //                updateRenderer();
    //            }
    //        });
    //        configUI.add(button, c);
    configUI.add(new JLabel("Preset range:"), c);

    c.gridx = 1;
    c.gridwidth = 1;
    presetRangeComboBox = new JComboBox();
    configUI.add(presetRangeComboBox, c);
    presetRangeComboBox.addItem(new DataMinMaxItem());
    presetRangeComboBox.addItem(new DefinedMinMaxItem(-1, 1));
    presetRangeComboBox.addItem(new DefinedMinMaxItem(0, 1));
    presetRangeComboBox.addItem(new DefinedMinMaxItem(-1, 0));
    presetRangeComboBox.addItem(new DefinedMinMaxItem(0, 100));

    presetRangeComboBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            try {
                MinMaxItem item = (MinMaxItem) (presetRangeComboBox.getSelectedItem());
                minValueField.setText(item.getMinMax().lowerEndpoint().toString());
                maxValueField.setText(item.getMinMax().upperEndpoint().toString());
            } catch (Exception ex) {
                minValueField.setText("-1");
                maxValueField.setText("1");
            }
        }
    });

    ////////////////////////////////////////////////////////////////////////////////
    //        c.weightx = 0.2;
    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 1;
    configUI.add(new JLabel("Min value: "), c);
    c.gridx = 1;
    //        c.weightx = 0.3;
    configUI.add(minValueField, c);

    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 1;
    configUI.add(new JLabel("Max value: "), c);
    c.gridx = 1;
    configUI.add(maxValueField, c);

    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 1;
    JLabel label = Tools.createJLabel("Draw Sub-heatmap:", null,
            "Draw sub-heatmaps for collapsed ontology nodes", null);
    configUI.add(label, c);

    c.gridx = 1;
    drawSubMap = new JCheckBox();
    configUI.add(drawSubMap, c);

    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 3;

    JButton button = new JButton("Update", UI.getImageIcon("refresh"));
    configUI.add(button, c);
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //hit button, redraw!

            updateRenderer();
        }
    });

    //        editor.applyButton.addActionListener(new ActionListener() {
    //
    //            @Override
    //            public void actionPerformed(ActionEvent e) {
    //                updateRenderer();
    //            }
    //        });
    toolTipLabel = new JLabel();
    toolTipLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    toolTipLabel.setBackground(UI.colorGrey3);
    toolTipLabel.setOpaque(true);
    toolTipLabel.setForeground(UI.colorBlack2);
    toolTipLabel.setFont(UI.fontPlain.deriveFont(12f));
}

From source file:edu.uci.ics.jung.samples.LensDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the zoomand hyperbolic features.
 * /*from   w w  w  .ja  v  a 2  s .  co  m*/
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public LensDemo() {

    // create a simple graph for the demo
    graph = TestGraphs.getOneComponentGraph();

    graphLayout = new FRLayout<String, Number>(graph);
    ((FRLayout) graphLayout).setMaxIterations(1000);

    Dimension preferredSize = new Dimension(600, 600);
    Map<String, Point2D> map = new HashMap<String, Point2D>();
    Transformer<String, Point2D> vlf = TransformerUtils.mapTransformer(map);
    grid = this.generateVertexGrid(map, preferredSize, 25);
    gridLayout = new StaticLayout<String, Number>(grid, vlf, preferredSize);

    final VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>(
            graphLayout, preferredSize);
    vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);

    PickedState<String> ps = vv.getPickedVertexState();
    PickedState<Number> pes = vv.getPickedEdgeState();
    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(ps, Color.red, Color.yellow));
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.cyan));
    vv.setBackground(Color.white);

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());

    final Transformer<String, Shape> ovals = vv.getRenderContext().getVertexShapeTransformer();
    final Transformer<String, Shape> squares = new ConstantTransformer(new Rectangle2D.Float(-10, -10, 20, 20));

    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller());

    Container content = getContentPane();
    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    content.add(gzsp);

    /**
     * the regular graph mouse for the normal view
     */
    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    hyperbolicViewSupport = new ViewLensSupport<String, Number>(vv,
            new HyperbolicShapeTransformer(vv,
                    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)),
            new ModalLensGraphMouse());
    hyperbolicLayoutSupport = new LayoutLensSupport<String, Number>(vv,
            new HyperbolicTransformer(vv,
                    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)),
            new ModalLensGraphMouse());
    magnifyViewSupport = new ViewLensSupport<String, Number>(vv,
            new MagnifyShapeTransformer(vv,
                    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)),
            new ModalLensGraphMouse(new LensMagnificationGraphMousePlugin(1.f, 6.f, .2f)));
    magnifyLayoutSupport = new LayoutLensSupport<String, Number>(vv,
            new MagnifyTransformer(vv,
                    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)),
            new ModalLensGraphMouse(new LensMagnificationGraphMousePlugin(1.f, 6.f, .2f)));
    hyperbolicLayoutSupport.getLensTransformer()
            .setLensShape(hyperbolicViewSupport.getLensTransformer().getLensShape());
    magnifyViewSupport.getLensTransformer()
            .setLensShape(hyperbolicLayoutSupport.getLensTransformer().getLensShape());
    magnifyLayoutSupport.getLensTransformer()
            .setLensShape(magnifyViewSupport.getLensTransformer().getLensShape());

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    ButtonGroup radio = new ButtonGroup();
    JRadioButton normal = new JRadioButton("None");
    normal.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                if (hyperbolicViewSupport != null) {
                    hyperbolicViewSupport.deactivate();
                }
                if (hyperbolicLayoutSupport != null) {
                    hyperbolicLayoutSupport.deactivate();
                }
                if (magnifyViewSupport != null) {
                    magnifyViewSupport.deactivate();
                }
                if (magnifyLayoutSupport != null) {
                    magnifyLayoutSupport.deactivate();
                }
            }
        }
    });

    final JRadioButton hyperView = new JRadioButton("Hyperbolic View");
    hyperView.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    final JRadioButton hyperModel = new JRadioButton("Hyperbolic Layout");
    hyperModel.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            hyperbolicLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    final JRadioButton magnifyView = new JRadioButton("Magnified View");
    magnifyView.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            magnifyViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    final JRadioButton magnifyModel = new JRadioButton("Magnified Layout");
    magnifyModel.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            magnifyLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    JLabel modeLabel = new JLabel("     Mode Menu >>");
    modeLabel.setUI(new VerticalLabelUI(false));
    radio.add(normal);
    radio.add(hyperModel);
    radio.add(hyperView);
    radio.add(magnifyModel);
    radio.add(magnifyView);
    normal.setSelected(true);

    graphMouse.addItemListener(hyperbolicLayoutSupport.getGraphMouse().getModeListener());
    graphMouse.addItemListener(hyperbolicViewSupport.getGraphMouse().getModeListener());
    graphMouse.addItemListener(magnifyLayoutSupport.getGraphMouse().getModeListener());
    graphMouse.addItemListener(magnifyViewSupport.getGraphMouse().getModeListener());

    ButtonGroup graphRadio = new ButtonGroup();
    JRadioButton graphButton = new JRadioButton("Graph");
    graphButton.setSelected(true);
    graphButton.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                visualizationModel.setGraphLayout(graphLayout);
                vv.getRenderContext().setVertexShapeTransformer(ovals);
                vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
                vv.repaint();
            }
        }
    });
    JRadioButton gridButton = new JRadioButton("Grid");
    gridButton.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                visualizationModel.setGraphLayout(gridLayout);
                vv.getRenderContext().setVertexShapeTransformer(squares);
                vv.getRenderContext().setVertexLabelTransformer(new ConstantTransformer(null));
                vv.repaint();
            }
        }
    });
    graphRadio.add(graphButton);
    graphRadio.add(gridButton);

    JPanel modePanel = new JPanel(new GridLayout(3, 1));
    modePanel.setBorder(BorderFactory.createTitledBorder("Display"));
    modePanel.add(graphButton);
    modePanel.add(gridButton);

    JMenuBar menubar = new JMenuBar();
    menubar.add(graphMouse.getModeMenu());
    gzsp.setCorner(menubar);

    Box controls = Box.createHorizontalBox();
    JPanel zoomControls = new JPanel(new GridLayout(2, 1));
    zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom"));
    JPanel hyperControls = new JPanel(new GridLayout(3, 2));
    hyperControls.setBorder(BorderFactory.createTitledBorder("Examiner Lens"));
    zoomControls.add(plus);
    zoomControls.add(minus);

    hyperControls.add(normal);
    hyperControls.add(new JLabel());

    hyperControls.add(hyperModel);
    hyperControls.add(magnifyModel);

    hyperControls.add(hyperView);
    hyperControls.add(magnifyView);

    controls.add(zoomControls);
    controls.add(hyperControls);
    controls.add(modePanel);
    controls.add(modeLabel);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:geovista.network.gui.ClusteringDemo.java

private void setUpView() throws IOException {

    /*/*w ww.  j  av a 2s  .c om*/
     * Factory<Integer> vertexFactory = new Factory<Integer>() { int n = 0;
     * public Integer create() { return n++; } }; Factory<Number>
     * edgeFactory = new Factory<Number>() { int n = 0; public Number
     * create() { return n++; } };
     */

    /*
     * PajekNetReader<Graph<Integer, Number>, Integer,Number> pnr = new
     * PajekNetReader<Graph<Integer, Number>, Integer,Number>(vertexFactory,
     * edgeFactory);
     * 
     * final Graph<Integer,Number> graph = new SparseMultigraph<Integer,
     * Number>();
     * 
     * pnr.load(br, graph);
     */

    // Create a simple layout frame
    // specify the Fruchterman-Rheingold layout algorithm
    layout = new AggregateLayout<Integer, Number>(new FRLayout<Integer, Number>(g));

    vv = new VisualizationViewer<Integer, Number>(layout);
    vv.setBackground(Color.white);
    // Tell the renderer to use our own customized color rendering
    vv.getRenderContext()
            .setVertexFillPaintTransformer(MapTransformer.<Integer, Paint>getInstance(vertexPaints));
    vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<Integer, Paint>() {
        public Paint transform(Integer v) {
            if (vv.getPickedVertexState().isPicked(v)) {
                return Color.blue;
            } else {
                return Color.BLACK;
            }
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(MapTransformer.<Number, Paint>getInstance(edgePaints));

    vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Number, Stroke>() {
        protected final Stroke THIN = new BasicStroke(1);
        protected final Stroke THICK = new BasicStroke(2);

        public Stroke transform(Number e) {
            Paint c = edgePaints.get(e);
            if (c == Color.LIGHT_GRAY) {
                return THIN;
            } else {
                return THICK;
            }
        }
    });

    /*
     * //add restart button JButton scramble = new JButton("Restart");
     * scramble.addActionListener(new ActionListener() { public void
     * actionPerformed(ActionEvent arg0) { Layout layout =
     * vv.getGraphLayout(); layout.initialize(); Relaxer relaxer =
     * vv.getModel().getRelaxer(); if(relaxer != null) { relaxer.stop();
     * relaxer.prerelax(); relaxer.relax(); } }
     * 
     * });
     * 
     * DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
     * vv.setGraphMouse(gm);
     */

    final JToggleButton groupVertices = new JToggleButton("Group Clusters");

    // Create slider to adjust the number of edges to remove when clustering
    final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL);
    edgeBetweennessSlider.setBackground(Color.WHITE);
    edgeBetweennessSlider.setPreferredSize(new Dimension(210, 50));
    edgeBetweennessSlider.setPaintTicks(true);
    edgeBetweennessSlider.setMaximum(g.getEdgeCount());
    edgeBetweennessSlider.setMinimum(0);
    edgeBetweennessSlider.setValue(0);
    edgeBetweennessSlider.setMajorTickSpacing(10);
    edgeBetweennessSlider.setPaintLabels(true);
    edgeBetweennessSlider.setPaintTicks(true);

    // edgeBetweennessSlider.setBorder(BorderFactory.createLineBorder(Color.black));
    // TO DO: edgeBetweennessSlider.add(new
    // JLabel("Node Size (PageRank With Priors):"));
    // I also want the slider value to appear
    final JPanel eastControls = new JPanel();
    /*
     * eastControls.setOpaque(true); eastControls.setLayout(new
     * BoxLayout(eastControls, BoxLayout.Y_AXIS));
     * eastControls.add(Box.createVerticalGlue());
     */
    // eastControls.add(edgeBetweennessSlider);

    final Box cluster_panel = Box.createVerticalBox();
    cluster_panel.setBorder(BorderFactory.createTitledBorder("Cluster"));
    cluster_panel.add(edgeBetweennessSlider);

    final String COMMANDSTRING = "Edges removed for clusters: ";
    final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue();

    final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize);
    /*
     * eastControls.setBorder(sliderBorder); //eastControls.add(eastSize);
     * eastControls.add(Box.createVerticalGlue());
     */

    groupVertices.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            clusterAndRecolor(layout, edgeBetweennessSlider.getValue(), similarColors,
                    e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });

    clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected());

    edgeBetweennessSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                int numEdgesToRemove = source.getValue();
                clusterAndRecolor(layout, numEdgesToRemove, similarColors, groupVertices.isSelected());
                sliderBorder.setTitle(COMMANDSTRING + edgeBetweennessSlider.getValue());
                eastControls.repaint();
                vv.validate();
                vv.repaint();
            }
        }
    });

    cluster_panel.add(groupVertices);
    Container content = getContentPane();
    content.add(new GraphZoomScrollPane(vv));
    JPanel south = new JPanel();
    JPanel grid = new JPanel(new GridLayout(2, 1));
    // grid.add(scramble);
    grid.add(cluster_panel);
    // south.add
    south.add(grid);
    south.add(eastControls);
    JPanel p = new JPanel();
    // p.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    // p.add(gm.getModeComboBox());
    south.add(p);

    content.add(south, BorderLayout.SOUTH);
}

From source file:org.openmicroscopy.shoola.agents.imviewer.util.proj.ProjSavingDialog.java

/**
 * Initializes the components./*from  w  ww  .j  a  v a 2 s  .  c om*/
 * 
 * @param imageName   The name of the image.
 * @param type      The type of projection.
 * @param maxZ      The maximum number of z-sections.
 * @param startZ   The lower bound of the z-section interval.
 * @param endZ      The upper bound of the z-section interval.
 */
private void initComponents(String imageName, String type, int maxZ, int startZ, int endZ) {
    parentsBox = new JComboBox();

    parentsBoxListener = new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                DataNode node = (DataNode) parentsBox.getSelectedItem();
                if (!node.isDefaultNode() && !node.getDataObject().canLink()) {
                    selectedContainer = null;
                    parentsBox.setSelectedIndex(0);
                }
                populateDatasetsBox(null);
            }
        }
    };
    parentsBox.removeItemListener(parentsBoxListener);
    datasetsBox = new JComboBox();
    datasetsBoxListener = new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                DataNode node = (DataNode) datasetsBox.getSelectedItem();
                if (node != null) {
                    if (!node.isDefaultNode() && !node.getDataObject().canLink()) {
                        //Determine the first dataset that be picked.
                        datasetsBox.setSelectedIndex(0);
                        node = (DataNode) datasetsBox.getSelectedItem();
                        selectedDataset = (DatasetData) node.getDataObject();
                    } else
                        selectedDataset = (DatasetData) node.getDataObject();
                }
            }

        }
    };
    datasetsBox.removeItemListener(datasetsBoxListener);
    rndSettingsBox = new JCheckBox("Apply same rendering settings");
    rndSettingsBox.setToolTipText(
            UIUtilities.formatToolTipText("Apply the rendering settings to " + "the projected image."));
    rndSettingsBox.setSelected(true);

    zrangeSelection = new TextualTwoKnobsSlider(1, maxZ, startZ, endZ);
    zrangeSelection.layoutComponents(TextualTwoKnobsSlider.LAYOUT_FIELDS);

    timeSelection = new TextualTwoKnobsSlider(1, maxT, 1, maxT);
    timeSelection.layoutComponents(TextualTwoKnobsSlider.LAYOUT_FIELDS);
    timeSelection.setEnabled(maxT > 1);

    Map<String, String> map = EditorUtil.PIXELS_TYPE_DESCRIPTION;
    String[] data = new String[map.size()];
    Set set = map.entrySet();
    Entry entry;
    Iterator i = set.iterator();
    int index = 0;
    //String originalType = type;
    String key;
    int selectedIndex = 0;
    while (i.hasNext()) {
        entry = (Entry) i.next();
        key = (String) entry.getKey();
        data[index] = (String) entry.getValue();
        if (key.equals(type))
            selectedIndex = index;
        index++;
    }
    pixelsType = new JComboBox(data);
    pixelsType.setSelectedIndex(selectedIndex);
    pixelsType.setEnabled(algorithm == ProjectionParam.SUM_INTENSITY);

    selectionPane = new JPanel();
    selectionPane.setLayout(new BoxLayout(selectionPane, BoxLayout.Y_AXIS));

    closeButton = new JButton("Cancel");
    closeButton.setToolTipText(UIUtilities.formatToolTipText("Close the window."));
    closeButton.setActionCommand("" + CLOSE);
    closeButton.addActionListener(this);
    projectButton = new JButton("Save");
    projectButton.setToolTipText(UIUtilities.formatToolTipText("Project the image."));
    projectButton.setActionCommand("" + PROJECT);
    projectButton.addActionListener(this);
    newFolderButton = new JButton("New Dataset...");
    newFolderButton.setToolTipText(UIUtilities.formatToolTipText("Create a new Dataset."));
    newFolderButton.setActionCommand("" + NEWFOLDER);
    newFolderButton.addActionListener(this);
    nameField = new JTextField();

    StringBuffer buffer = new StringBuffer();
    buffer.append(UIUtilities.removeFileExtension(imageName));
    buffer.append(DEFAULT_EXTENSION);
    nameField.setText(buffer.toString());
    nameField.getDocument().addDocumentListener(this);
    //Display datasets
    getRootPane().setDefaultButton(projectButton);

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            close();
        }
    });
}

From source file:grisu.frontend.view.swing.files.preview.fileViewers.JobStatusGridFileViewer.java

private JCheckBox getChckbxShowMinutes() {
    if (chckbxShowMinutes == null) {
        chckbxShowMinutes = new JCheckBox("Display minutes");
        chckbxShowMinutes.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (chckbxShowMinutes.isSelected()) {
                    showMinutes = true;/* w  w  w.  j av  a2s.c  o  m*/
                } else {
                    showMinutes = false;
                }

                new Thread() {
                    @Override
                    public void run() {
                        chckbxShowMinutes.setEnabled(false);
                        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        generateGraph();
                        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                        chckbxShowMinutes.setEnabled(true);
                    }
                }.start();

            }
        });
    }
    return chckbxShowMinutes;
}

From source file:hr.restart.util.chart.ChartXY.java

public void initFrame() throws Exception {

    if (isInstanciated()) {
        if (chartPanel != null)
            mainPanel.remove(chartPanel);
        chartPanel = initGraph();//from  w ww.j av a  2  s . c  om
        mainPanel.add(chartPanel, BorderLayout.CENTER);
        return;
    }

    setInstanciated(true);

    verifyDialog();

    charts = new ArrayList();
    charts.add(BAR_CHART);
    charts.add(PIE_CHART);

    mainPanel = new JPanel(new BorderLayout());

    buttonsPanel = new JPanel(new FlowLayout());

    JPanel actionsPanel = new JPanel(new BorderLayout());
    JPanel savePanel = new JPanel();

    //adding combobox
    comboBox = new JComboBox(charts.toArray());
    comboBox.addActionListener(this);

    buttonsPanel.add(comboBox);

    //adding filechooser
    JButton btSave = new JButton("Snimi");
    btSave.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ev) {

            try {
                chartPanel.doSaveAs();
            } catch (IOException e) {
                // 
                e.printStackTrace();
                System.out.println(e);
            }
        }
    });
    savePanel.add(btSave);

    //adding printing button
    JButton btPrint = new JButton("Ispis");
    btPrint.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            chartPanel.createChartPrintJob();
        }
    });
    savePanel.add(btPrint);

    //creates datasets
    barDataset = createDataSet();
    pieDataset = DatasetUtilities.createPieDatasetForRow(barDataset, 0);

    String value;
    if (jcb == null)
        value = getAxisY();
    else
        value = colNamesY[jcb.getSelectedIndex()];

    PlotOrientation orientation = PlotOrientation.VERTICAL;

    pieChart = createPieChart(pieDataset, value);
    barChart = createBarChart(barDataset, value, orientation);

    //adding orientation box
    String[] orientations = { "Vertikalni", "Horizontalni" };
    comboBoxOrientation = new JComboBox(orientations);
    comboBoxOrientation.setVisible(false);
    comboBoxOrientation.addItemListener(new ItemListener() {

        /* (non-Javadoc)
           * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
           */
        public void itemStateChanged(ItemEvent e) {
            // TODO Auto-generated method stub
            if (comboBoxOrientation.getSelectedItem() == "Vertikalni")
                selectionChanged(PlotOrientation.VERTICAL);
            else
                selectionChanged(PlotOrientation.HORIZONTAL);
        }
    });

    buttonsPanel.add(comboBoxOrientation);

    // adding combobox
    String[] quantity = { "5", "10", "15" };
    comboBoxQuantity = new JComboBox(quantity);
    comboBoxQuantity.setEditable(true);
    comboBoxQuantity.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            try {
                mainPanel.remove(chartPanel);
            } catch (RuntimeException e1) {
                //e1.printStackTrace();               
            }

            selectionChanged(PlotOrientation.VERTICAL);
        }

    });

    comboBoxQuantity.setSelectedItem(new Integer(getNumberOfElements()).toString());
    buttonsPanel.add(comboBoxQuantity);

    if (jcb != null) {
        if (getDefaultSelectedItem() != null) {
            if (getDefaultSelectedItem().compareTo("") != 0)
                jcb.setSelectedItem(getDefaultSelectedItem());
        }

        buttonsPanel.add(jcb);
    }

    // adding OKPanel
    final OKpanel okPanel = new OKpanel() {
        public void jBOK_actionPerformed() {
            //ok_action();
            chartPanel.createChartPrintJob();
        }

        public void jPrekid_actionPerformed() {
            //            firstESC();
            cancelPressed();

        }
    };

    okPanel.addAncestorListener(new AncestorListener() {
        public void ancestorAdded(AncestorEvent e) {
            //                register the keys action

            okPanel.registerOKPanelKeys(getJdialog());
        }

        public void ancestorMoved(AncestorEvent e) {

        }

        public void ancestorRemoved(AncestorEvent e) {
            okPanel.unregisterOKPanelKeys(getJdialog());
        }
    });

    okPanel.jBOK.setText("Ispis");
    okPanel.jBOK.setIcon(raImages.getImageIcon(raImages.IMGPRINT));

    JButton btSnimi = new JButton("Snimi");
    btSnimi.setIcon(raImages.getImageIcon(raImages.IMGSAVE));
    btSnimi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                chartPanel.doSaveAs();
            } catch (IOException e) {
                // 
                e.printStackTrace();
                System.out.println(e);
            }
        }

    });
    okPanel.add(btSnimi, BorderLayout.WEST);
    mainPanel.add(okPanel, BorderLayout.SOUTH);

    actionsPanel.add(buttonsPanel, BorderLayout.CENTER);
    //actionsPanel.add(savePanel,BorderLayout.SOUTH);   
    actionsPanel.add(okPanel, BorderLayout.SOUTH);
    mainPanel.add(actionsPanel, BorderLayout.SOUTH);

    chartPanel = initGraph();
    mainPanel.add(chartPanel, BorderLayout.CENTER);

    this.getContentPane().add(mainPanel);
}