Example usage for javax.swing JComboBox JComboBox

List of usage examples for javax.swing JComboBox JComboBox

Introduction

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

Prototype

public JComboBox() 

Source Link

Document

Creates a JComboBox with a default data model.

Usage

From source file:org.jax.maanova.fit.gui.ResidualPlotPanel.java

/**
 * Constructor//w ww  .  ja va  2s  .  co m
 * @param parent
 *          the parent frame
 * @param fitMaanovaResult
 *          the fitmaanova result that we'll plot residuals for
 */
public ResidualPlotPanel(JFrame parent, FitMaanovaResult fitMaanovaResult) {
    this.chartConfigurationDialog = new SimpleChartConfigurationDialog(parent);
    this.chartConfigurationDialog.addOkActionListener(new ActionListener() {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            ResidualPlotPanel.this.updateDataPoints();
        }
    });

    this.fitMaanovaResult = fitMaanovaResult;
    this.dyeCount = this.fitMaanovaResult.getParentExperiment().getDyeCount();
    this.arrayCount = this.fitMaanovaResult.getParentExperiment().getMicroarrayCount();

    this.setLayout(new BorderLayout());

    JPanel chartAndControlPanel = new JPanel(new BorderLayout());
    this.add(chartAndControlPanel, BorderLayout.CENTER);

    this.chartPanel = new MaanovaChartPanel();
    this.chartPanel.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    this.chartPanel.addComponentListener(this.chartComponentListener);
    this.chartPanel.addAreaSelectionListener(this.areaSelectionListener);
    this.chartPanel.addMouseListener(this.chartMouseListener);
    this.chartPanel.addMouseMotionListener(this.myMouseMotionListener);
    this.chartPanel.setLayout(null);
    chartAndControlPanel.add(this.chartPanel, BorderLayout.CENTER);

    ItemListener updateDataItemListener = new ItemListener() {
        /**
         * {@inheritDoc}
         */
        public void itemStateChanged(ItemEvent e) {
            ResidualPlotPanel.this.forgetGraphState();
            ResidualPlotPanel.this.updateDataPoints();
        }
    };

    if (this.dyeCount <= 1) {
        this.controlPanel = null;
        this.dyeComboBox = null;
    } else {
        this.dyeComboBox = new JComboBox();
        for (int i = 0; i < this.dyeCount; i++) {
            this.dyeComboBox.addItem("Dye #" + (i + 1));
        }
        this.dyeComboBox.addItemListener(updateDataItemListener);

        this.controlPanel = new JPanel(new FlowLayout());
        this.controlPanel.add(this.dyeComboBox);
        chartAndControlPanel.add(this.controlPanel, BorderLayout.NORTH);
    }

    this.add(this.createMenu(), BorderLayout.NORTH);

    this.forgetGraphState();
    this.updateDataPoints();

    this.toolTip = new JToolTip();
}

From source file:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java

/**
 * @throws HeadlessException//from w  w w  .ja  v  a2s  .c o  m
 */
public AgentDebuggerFrame(final boolean isStandalone, String serviceUrl) throws HeadlessException {
    super("Intuit Tank Agent Debugger");
    workingDir = PanelBuilder.createWorkingDir(this, serviceUrl);
    setSize(new Dimension(1024, 800));
    setBounds(new Rectangle(getSize()));
    setPreferredSize(getSize());
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setLayout(new BorderLayout());
    this.standalone = isStandalone;
    addWindowListener(new WindowAdapter() {
        public void windowClosed(WindowEvent e) {
            quit();
        }
    });
    errorIcon = ActionProducer.getIcon("bullet_error.png", IconSize.SMALL);
    modifiedIcon = ActionProducer.getIcon("bullet_code_change.png", IconSize.SMALL);
    skippedIcon = ActionProducer.getIcon("skip.png", IconSize.SMALL);

    this.glassPane = new InfiniteProgressPanel();
    setGlassPane(glassPane);
    debuggerActions = new ActionProducer(this, serviceUrl);
    requestResponsePanel = new RequestResponsePanel(this);
    requestResponsePanel.init();
    testPlanChooser = new JComboBox();
    testPlanChooser.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getItem() != null) {
                HDTestPlan selected = (HDTestPlan) event.getItem();
                if (!selected.equals(currentTestPlan)) {
                    setCurrentTestPlan(selected);
                }
            }

        }
    });

    tankClientChooser = new JComboBox<TankClientChoice>();
    debuggerActions.setChoiceComboBoxOptions(tankClientChooser);

    actionComponents = new ActionComponents(standalone, testPlanChooser, tankClientChooser, debuggerActions);
    addScriptChangedListener(actionComponents);
    setJMenuBar(actionComponents.getMenuBar());

    Component topPanel = PanelBuilder.createTopPanel(actionComponents);
    Component bottomPanel = PanelBuilder.createBottomPanel(this);
    Component contentPanel = PanelBuilder.createContentPanel(this);

    final JPopupMenu popup = actionComponents.getPopupMenu();
    scriptEditorTA.setPopupMenu(null);

    scriptEditorTA.addMouseListener(new MouseAdapter() {
        int lastHash;

        @Override
        public void mousePressed(MouseEvent e) {
            maybeShow(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            maybeShow(e);
        }

        private void maybeShow(MouseEvent e) {
            if (lastHash == getHash(e)) {
                return;
            }
            if (e.isPopupTrigger()) {
                // select the line
                try {
                    int offset = scriptEditorTA.viewToModel(e.getPoint());
                    Rectangle modelToView = scriptEditorTA.modelToView(offset);
                    Point point = new Point(modelToView.x + 1, e.getPoint().y);
                    if (modelToView.contains(point)) {
                        if (!multiSelect) {
                            int line = scriptEditorTA.getLineOfOffset(offset);
                            scriptEditorTA.setCurrentLine(line);
                        }
                        popup.show(e.getComponent(), e.getX(), e.getY());
                    }
                } catch (BadLocationException e1) {
                    e1.printStackTrace();
                }
            } else if (e.isShiftDown()) {
                int line = scriptEditorTA.getCaretLineNumber();
                int start = Math.min(line, lastLine);
                int end = Math.max(line, lastLine);
                multiSelect = end - start > 1;
                if (multiSelect) {
                    multiSelectStart = start;
                    multiSelectEnd = end;
                    try {
                        scriptEditorTA.setEnabled(true);
                        scriptEditorTA.select(scriptEditorTA.getLineStartOffset(start),
                                scriptEditorTA.getLineEndOffset(end));
                        scriptEditorTA.setEnabled(false);
                    } catch (BadLocationException e1) {
                        e1.printStackTrace();
                        multiSelect = false;
                    }
                }
            } else {
                multiSelect = false;
                lastLine = scriptEditorTA.getCaretLineNumber();
            }
            lastHash = getHash(e);
        }

        private int getHash(MouseEvent e) {
            return new HashCodeBuilder().append(e.getButton()).append(e.getSource().hashCode())
                    .append(e.getPoint()).toHashCode();
        }

    });

    JSplitPane mainSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    mainSplit.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    mainSplit.setTopComponent(contentPanel);
    mainSplit.setBottomComponent(bottomPanel);
    mainSplit.setDividerLocation(600);
    mainSplit.setResizeWeight(0.8D);
    mainSplit.setDividerSize(5);

    add(topPanel, BorderLayout.NORTH);
    add(mainSplit, BorderLayout.CENTER);

    WindowUtil.centerOnScreen(this);
    pack();

    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();

    manager.addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED) {
                handleKeyEvent(e);
            }
            return false;
        }
    });
}

From source file:com.idealista.solrmeter.view.statistic.CacheHistoryPanel.java

/**
 * Creates the controlers to select hit ratio or caches
 * @return//from w  w w.  j  a  v a2s .co m
 */
private List<Component> createControlPanel() {
    List<Component> components = new LinkedList<Component>();
    whatToShowBoxCache = new JComboBox();
    whatToShowBoxCache.addItem(I18n.get("statistic.cacheStatistic.showHitRatio"));
    whatToShowBoxCache.addItem(I18n.get("statistic.cacheStatistic.showSpecificData"));
    whatToShowBoxCache.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            setShowingSpecificData(!whatToShowBoxCache.getSelectedItem()
                    .equals(I18n.get("statistic.cacheStatistic.showHitRatio")));
            refreshView();
        }

    });
    components.add(whatToShowBoxCache);
    components.add(Box.createRigidArea(new Dimension(3, 3)));

    comboBoxCache = new JComboBox();
    comboBoxCache.addItem("documentCache");
    comboBoxCache.addItem("fieldValueCache");
    comboBoxCache.addItem("filterCache");
    comboBoxCache.addItem("queryResultCache");
    comboBoxCache.addActionListener(new ActionListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void actionPerformed(ActionEvent arg0) {
            changeChartTitle("title" + comboBoxCache.getSelectedItem().toString());
            refreshSeries(Collections.EMPTY_MAP);
            refreshView();
        }

    });
    components.add(comboBoxCache);
    return components;
}

From source file:net.sf.taverna.t2.workbench.views.results.workflow.RenderedResultComponent.java

/**
 * Creates the component.//from w  w w . j  a  v  a 2 s.  c o m
 */
public RenderedResultComponent(RendererRegistry rendererRegistry, List<SaveIndividualResultSPI> saveActions) {
    this.rendererRegistry = rendererRegistry;
    setLayout(new BorderLayout());

    // Results type combo box
    renderersComboBox = new JComboBox<>();
    renderersComboBox.setModel(new DefaultComboBoxModel<String>()); // initially empty

    renderersComboBox.setRenderer(new ColorCellRenderer());
    renderersComboBox.setEditable(false);
    renderersComboBox.setEnabled(false); // initially disabled

    // Set the new listener - listen for changes in the currently selected renderer
    renderersComboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED && !ERROR_DOCUMENT.equals(e.getItem()))
                // render the result using the newly selected renderer
                renderResult();
        }
    });

    JPanel resultsTypePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    resultsTypePanel.add(new JLabel("Value type"));
    resultsTypePanel.add(renderersComboBox);

    // Refresh (re-render) button
    refreshButton = new JButton("Refresh", refreshIcon);
    refreshButton.setEnabled(false);
    refreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            renderResult();
            refreshButton.getParent().requestFocusInWindow();
            /*
             * so that the button does not stay focused after it is clicked
             * on and did its action
             */
        }
    });
    resultsTypePanel.add(refreshButton);

    // Check box for wrapping text if result is of type "text/plain"
    wrapTextCheckBox = new JCheckBox(WRAP_TEXT);
    wrapTextCheckBox.setVisible(false);
    wrapTextCheckBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            // Should have only one child component holding the rendered result
            // Check for empty just as well
            if (renderedResultPanel.getComponents().length == 0)
                return;
            Component component = renderedResultPanel.getComponent(0);
            if (component instanceof DialogTextArea) {
                nodeToWrapSelection.put(path, e.getStateChange() == SELECTED);
                renderResult();
            }
        }
    });

    resultsTypePanel.add(wrapTextCheckBox);

    // 'Save result' buttons panel
    saveButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    for (SaveIndividualResultSPI action : saveActions) {
        action.setResultReference(null);
        final JButton saveButton = new JButton(action.getAction());
        saveButton.setEnabled(false);
        saveButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveButton.getParent().requestFocusInWindow();
                /*
                 * so that the button does not stay focused after it is
                 * clicked on and did its action
                 */
            }
        });
        saveButtonsPanel.add(saveButton);
    }

    // Top panel contains result type combobox and various save buttons
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, LINE_AXIS));
    topPanel.add(resultsTypePanel);
    topPanel.add(saveButtonsPanel);

    // Rendered results panel - initially empty
    renderedResultPanel = new JPanel(new BorderLayout());

    // Add all components
    add(topPanel, NORTH);
    add(new JScrollPane(renderedResultPanel), CENTER);
}

From source file:com.midas.classify.gui.DecisionTreeViewer.java

public DecisionTreeViewer(DelegateTree<TreeNode, TreeEdge> tr, String[] cls) {
    setLayout(new BorderLayout());

    // ---------------------------------------------- //
    // INICIALIZACION DE COMPONENTES DE VISUALIZACION //
    // ---------------------------------------------- //
    tree = tr;//w w w .  j a  va2s .  co  m
    classNames = cls;
    classColors = new TreeMap();

    nodeColor = Color.BLUE;
    for (int i = 0; i < cls.length; ++i) {
        classColors.put(cls[i], Color.RED);
    }

    leafNodes = new TreeSet();
    for (TreeNode n : tr.getVertices()) {
        if (tr.isLeaf(n)) {
            for (String s : cls) {
                if (n.toString().startsWith(s)) {
                    leafNodes.add(s);
                    break;
                }
            }
        }
    }

    TreeLayout<TreeNode, TreeEdge> layout = new TreeLayout(tr);

    vv = new VisualizationViewer(layout);
    vv.setBackground(Color.white);

    vv.getRenderContext().setEdgeFontTransformer(new EdgeFontTransformer());
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<TreeNode, TreeEdge>());

    PickedState<TreeNode> picked_state = vv.getPickedVertexState();

    vv.getRenderContext().setVertexFillPaintTransformer(new VertexFillColorTransformer<TreeNode>(picked_state));
    vv.getRenderContext().setVertexDrawPaintTransformer(new VertexDrawColorTransformer<TreeNode>(picked_state));
    vv.getRenderContext().setVertexFontTransformer(new VertexFontTransformer());

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

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

    final ScalingControl scaler = new CrossoverScalingControl();

    // ---------------------------------------- //
    // INICIALIZACION DE COMPONENTES DE CONTROL //
    // ---------------------------------------- //

    fontChooser = new JFontChooser();

    JPanel pControl = new JPanel(new GridLayout(7, 1, 4, 2));

    JPanel pZoom = new JPanel(new GridLayout(1, 2, 2, 2));
    pZoom.setBorder(new TitledBorder("Zoom"));

    bZoomIn = new JButton("+");
    bZoomIn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });

    bZoomOut = new JButton("-");
    bZoomOut.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });
    pZoom.add(bZoomIn);
    pZoom.add(bZoomOut);

    JPanel pFont = new JPanel(new GridLayout(1, 2, 2, 2));
    pFont.setBorder(new TitledBorder("Fonts"));

    bNodeFont = new JButton("Node Font");
    bNodeFont.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int r = fontChooser.showDialog(null);
            if (r == JFontChooser.OK_OPTION) {
                nodeFont = fontChooser.getSelectedFont();
                vv.repaint();
            }
        }
    });

    bEdgeFont = new JButton("Edge Font");
    bEdgeFont.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int r = fontChooser.showDialog(null);
            if (r == JFontChooser.OK_OPTION) {
                edgeFont = fontChooser.getSelectedFont();
                vv.repaint();
            }
        }
    });

    pFont.add(bNodeFont);
    pFont.add(bEdgeFont);

    bNodeColor = new JButton("Node Color");
    bNodeColor.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            nodeColor = JColorChooser.showDialog(null, "Select color for intern nodes", Color.RED);
            vv.repaint();
        }
    });

    JPanel pMode = new JPanel();
    pMode.setBorder(new TitledBorder("Mode"));

    cbMode = new JComboBox();
    cbMode.addItem(ModalGraphMouse.Mode.TRANSFORMING);
    cbMode.addItem(ModalGraphMouse.Mode.PICKING);
    cbMode.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            gm.setMode((ModalGraphMouse.Mode) e.getItem());
        }
    });

    pMode.add(cbMode);

    JPanel pColors = new JPanel(new GridLayout(1, 2, 2, 2));
    pColors.setBorder(new TitledBorder("Node Colors"));

    cbClasses = new JComboBox(classNames);
    cbClasses.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color c = JColorChooser.showDialog(null, "Select class color for " + cbClasses.getSelectedItem(),
                    Color.RED);
            classColors.put(cbClasses.getSelectedItem().toString(), c);
            vv.repaint();
        }
    });
    pColors.add(cbClasses);
    pColors.add(bNodeColor);

    JPanel pLabelPosition = new JPanel();
    pLabelPosition.setBorder(new TitledBorder("Label Position"));

    cbLabelPosition = new JComboBox();
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.N);
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.NE);
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.E);
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.SE);
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.S);
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.SW);
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.W);
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.NW);
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.N);
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.CNTR);
    cbLabelPosition.addItem(Renderer.VertexLabel.Position.AUTO);

    cbLabelPosition.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            Renderer.VertexLabel.Position position = (Renderer.VertexLabel.Position) e.getItem();
            vv.getRenderer().getVertexLabelRenderer().setPosition(position);
            vv.repaint();
        }
    });
    cbLabelPosition.setSelectedItem(Renderer.VertexLabel.Position.SE);

    pLabelPosition.add(cbLabelPosition);

    chkShowEdgeNames = new JCheckBox("Show Edge Name");
    chkShowEdgeNames.addActionListener(new ActionListener() {
        ToStringLabeller strLabeller = new ToStringLabeller();
        ConstantTransformer none = new ConstantTransformer(null);

        @Override
        public void actionPerformed(ActionEvent e) {
            AbstractButton src = (AbstractButton) e.getSource();
            if (src.isSelected()) {
                vv.getRenderContext().setEdgeLabelTransformer(strLabeller);
            } else {
                vv.getRenderContext().setEdgeLabelTransformer(none);
            }
            vv.repaint();
        }
    });
    chkShowEdgeNames.setSelected(true);

    chkShowNodeNames = new JCheckBox("Show Node Name");
    chkShowNodeNames.addActionListener(new ActionListener() {
        ToStringLabeller strLabeller = new ToStringLabeller();
        ConstantTransformer none = new ConstantTransformer(null);

        @Override
        public void actionPerformed(ActionEvent e) {
            AbstractButton src = (AbstractButton) e.getSource();
            if (src.isSelected()) {
                vv.getRenderContext().setVertexLabelTransformer(strLabeller);
            } else {
                vv.getRenderContext().setVertexLabelTransformer(none);
            }
            vv.repaint();
        }
    });
    chkShowNodeNames.setSelected(true);

    pControl.add(pZoom);
    pControl.add(pFont);
    pControl.add(pMode);
    pControl.add(pLabelPosition);
    pControl.add(pColors);
    pControl.add(chkShowNodeNames);
    pControl.add(chkShowEdgeNames);

    // Agregar componentes al panel
    add(scrollPane);

    JPanel p = new JPanel(new FlowLayout());
    p.add(pControl);
    add(p, BorderLayout.EAST);
}

From source file:EditorPaneExample20.java

public EditorPaneExample20() {
    super("JEditorPane Example 20");

    pane = new JEditorPane();
    pane.setEditable(true); // Editable
    getContentPane().add(new JScrollPane(pane), "Center");

    // Add a menu bar
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);/* w ww.ja  v  a  2  s.c o m*/

    // Populate it
    createMenuBar();

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);
    c.gridy = 3;
    panel.add(new JLabel(LOAD_TIME), c);

    c.gridy = 4;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    onlineLoad = new JCheckBox("Online Load");
    panel.add(onlineLoad, c);
    onlineLoad.setSelected(true);
    onlineLoad.setForeground(typeLabel.getForeground());

    c.gridy = 5;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    editableBox = new JCheckBox("Editable JEditorPane");
    panel.add(editableBox, c);
    editableBox.setSelected(true);
    editableBox.setForeground(typeLabel.getForeground());

    c.gridy = 6;
    c.weightx = 0.0;
    JButton saveButton = new JButton("Save");
    panel.add(saveButton, c);
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            EditorKit kit = pane.getEditorKit();
            try {
                if (kit instanceof RTFEditorKit) {
                    kit.write(System.out, pane.getDocument(), 0, pane.getDocument().getLength());
                    System.out.flush();
                } else {
                    if (writer == null) {
                        writer = new OutputStreamWriter(System.out);
                        pane.write(writer);
                        writer.flush();
                    }
                    kit.write(writer, pane.getDocument(), 0, pane.getDocument().getLength());
                    writer.flush();
                }
            } catch (Exception e) {
                System.out.println("Write failed");
            }
        }
    });

    c.gridx = 1;
    insertButton = new JButton("Insert HTML");
    panel.add(insertButton, c);
    insertButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (insertFrame == null) {
                insertFrame = new HTMLInsertFrame("HTML Insertion", pane);
                Point pt = EditorPaneExample20.this.getLocationOnScreen();
                Dimension d = EditorPaneExample20.this.getSize();
                insertFrame.setLocation(pt.x + d.width, pt.y);
                insertFrame.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent evt) {
                        insertFrame.dispose();
                        insertFrame = null;
                        setInsertButtonState();
                    }
                });
                insertButton.setEnabled(false);
                insertFrame.setVisible(true);
            }
        }
    });
    insertButton.setEnabled(false);

    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;

    urlCombo = new JComboBox();
    panel.add(urlCombo, c);
    urlCombo.setEditable(true);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);
    timeLabel = new JLabel("");
    c.gridy = 3;
    panel.add(timeLabel, c);

    getContentPane().add(panel, "South");

    // Register a custom EditorKit for HTML
    ClassLoader loader = getClass().getClassLoader();
    if (loader != null) {
        // Java 2
        JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.EnhancedHTMLEditorKit",
                loader);
    } else {
        // JDK 1.1
        JEditorPane.registerEditorKitForContentType("text/html",
                "AdvancedSwing.Chapter4.EnhancedHTMLEditorKit");
    }

    // Allocate the empty tree model
    DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty");
    emptyModel = new DefaultTreeModel(emptyRootNode);

    // Create and place the heading tree
    tree = new JTree(emptyModel);
    tree.setPreferredSize(new Dimension(200, 200));
    getContentPane().add(new JScrollPane(tree), "East");

    // Change page based on combo selection
    urlCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (populatingCombo == true) {
                return;
            }
            Object selection = urlCombo.getSelectedItem();
            loadNewPage(selection);
        }
    });

    // Change editability based on the checkbox
    editableBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pane.setEditable(editableBox.isSelected());
            pane.revalidate();
            pane.repaint();
        }
    });

    // Listen for page load to complete
    pane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("page")) {
                loadComplete();
                displayLoadTime();
                populateCombo(findLinks(pane.getDocument(), null));
                TreeNode node = buildHeadingTree(pane.getDocument());
                tree.setModel(new DefaultTreeModel(node));

                createMenuBar();
                enableMenuBar(true);
                getRootPane().revalidate();

                enableInput();
                loadingPage = false;
            }
        }
    });

    // Listener for tree selection
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            TreePath path = evt.getNewLeadSelectionPath();
            if (path != null) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                Object userObject = node.getUserObject();
                if (userObject instanceof Heading) {
                    Heading heading = (Heading) userObject;
                    try {
                        Rectangle textRect = pane.modelToView(heading.getOffset());
                        textRect.y += 3 * textRect.height;
                        pane.scrollRectToVisible(textRect);
                    } catch (BadLocationException e) {
                    }
                }
            }
        }
    });

    // Listener for hypertext events
    pane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            // Ignore hyperlink events if the frame is busy
            if (loadingPage == true) {
                return;
            }
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                JEditorPane sp = (JEditorPane) evt.getSource();
                if (evt instanceof HTMLFrameHyperlinkEvent) {
                    HTMLDocument doc = (HTMLDocument) sp.getDocument();
                    doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt);
                } else {
                    loadNewPage(evt.getURL());
                }
            } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                pane.setCursor(handCursor);
            } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {
                pane.setCursor(defaultCursor);
            }
        }
    });
}

From source file:sim.util.media.chart.TimeSeriesAttributes.java

public void buildAttributes() {
    // The following three variables aren't defined until AFTER construction if
    // you just define them above.  So we define them below here instead.

    dashPattern = 0; // dashPatterns[0];
    stretch = 1.0f;// w  ww  .  jav  a  2 s .c om
    thickness = 2.0f;

    // strokeColor = Color.black;  // rebuildGraphicsDefinitions will get called by our caller afterwards
    XYItemRenderer renderer = (((XYPlot) getPlot()).getRenderer());

    // NOTE:
    // Paint paint = renderer.getSeriesPaint(getSeriesIndex());        
    // In JFreeChart 1.0.6 getSeriesPaint returns null!!!
    // You need lookupSeriesPaint(), but that's not backward compatible.
    // The only thing consistent in all versions is getItemPaint 
    // (which looks like a gross miss-use, but gets the job done)

    Paint paint = renderer.getItemPaint(getSeriesIndex(), -1);

    strokeColor = (Color) paint;

    strokeColorWell = new ColorWell(strokeColor) {
        public Color changeColor(Color c) {
            strokeColor = c;
            rebuildGraphicsDefinitions();
            return c;
        }
    };
    addLabelled("Color", strokeColorWell);

    thicknessField = new NumberTextField(2.0, true) {
        public double newValue(double newValue) {
            if (newValue < 0.0)
                newValue = currentValue;
            thickness = (float) newValue;
            rebuildGraphicsDefinitions();
            return newValue;
        }
    };
    addLabelled("Width", thicknessField);

    dashPatternList = new JComboBox();
    dashPatternList.setEditable(false);
    dashPatternList.setModel(new DefaultComboBoxModel(
            new java.util.Vector(Arrays.asList(new String[] { "Solid", "__  __  __", "_  _  _  _", "_ _ _ _ _",
                    "_ _ . _ _ .", "_ . _ . _ .", "_ . . _ . .", ". . . . . . .", ".  .  .  .  ." }))));
    dashPatternList.setSelectedIndex(0);
    dashPatternList.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dashPattern = dashPatternList.getSelectedIndex(); // dashPatterns[dashPatternList.getSelectedIndex()];
            rebuildGraphicsDefinitions();
        }
    });
    addLabelled("Dash", dashPatternList);
    stretchField = new NumberTextField(1.0, true) {
        public double newValue(double newValue) {
            if (newValue < 0.0)
                newValue = currentValue;
            stretch = (float) newValue;
            rebuildGraphicsDefinitions();
            return newValue;
        }
    };
    addLabelled("Stretch", stretchField);
}