Example usage for javax.swing JPanel setBackground

List of usage examples for javax.swing JPanel setBackground

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.")
public void setBackground(Color bg) 

Source Link

Document

Sets the background color of this component.

Usage

From source file:org.zaproxy.zap.extension.tlsdebug.TlsDebugPanel.java

@SuppressWarnings("deprecation")
private void initialize() {

    this.setIcon(TLSDEBUG_ICON);
    this.setDefaultAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,
            // TODO Remove warn suppression and use View.getMenuShortcutKeyStroke with
            // newer ZAP (or use getMenuShortcutKeyMaskEx() with Java 10+)
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | KeyEvent.ALT_DOWN_MASK, false));
    this.setLayout(new BorderLayout());

    JPanel panelContent = new JPanel(new GridBagLayout());
    this.add(panelContent, BorderLayout.NORTH);

    panelContent.setBackground(Color.white);
    panelContent.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));

    panelContent.add(new JLabel(Constant.messages.getString("tlsdebug.label.url")),
            LayoutHelper.getGBC(0, 0, 1, 0.0D, new Insets(5, 5, 5, 5)));

    JPanel urlSelectPanel = new JPanel(new GridBagLayout());
    JButton selectButton = new JButton(Constant.messages.getString("all.button.select"));
    selectButton.setIcon(/*from  w w w  . java  2 s .co m*/
            DisplayUtils.getScaledIcon(new ImageIcon(View.class.getResource("/resource/icon/16/094.png")))); // Globe
    // icon
    selectButton.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            NodeSelectDialog nsd = new NodeSelectDialog(View.getSingleton().getMainFrame());
            SiteNode node = null;
            try {
                node = Model.getSingleton().getSession().getSiteTree()
                        .findNode(new URI(getUrlField().getText(), false));
            } catch (Exception e2) {
                // Ignore
            }
            node = nsd.showDialog(node);
            if (node != null && node.getHistoryReference() != null) {
                try {
                    getUrlField().setText(node.getHistoryReference().getURI().toString());
                } catch (Exception e1) {
                    // Ignore
                }
            }
        }
    });

    urlSelectPanel.add(this.getUrlField(), LayoutHelper.getGBC(0, 0, 1, 1.0D));
    urlSelectPanel.add(selectButton, LayoutHelper.getGBC(1, 0, 1, 0.0D));
    panelContent.add(urlSelectPanel, LayoutHelper.getGBC(1, 0, 3, 0.25D));

    panelContent.add(this.getCheckButton(), LayoutHelper.getGBC(0, 1, 1, 0.0D));

    JPanel outputPanel = new JPanel(new BorderLayout());
    outputPanel.add(new JLabel(Constant.messages.getString("tlsdebug.label.console")), BorderLayout.NORTH);
    JScrollPane jScrollPane = new JScrollPane();
    jScrollPane.add(getOutputArea(), LayoutHelper.getGBC(0, 0, 4, 1.D, 1.0D)); // Padding
    // at
    // bottom
    jScrollPane.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 11));
    jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    jScrollPane.setViewportView(getOutputArea());
    outputPanel.add(jScrollPane, BorderLayout.CENTER);

    this.add(outputPanel, BorderLayout.CENTER);
}

From source file:pcgen.gui2.dialog.AboutDialog.java

/**
 * Construct the awards panel. This panel shows each award
 * the pcgen project has been awarded//  www.  j  a  v a  2  s.  co  m
 *
 * @return The awards panel.
 */
private JPanel buildAwardsPanel() {
    JScrollPane sp = new JScrollPane();
    JPanel panel = new JPanel();

    JPanel aPanel = new JPanel();
    aPanel.setLayout(new GridBoxLayout(2, 2));
    aPanel.setBackground(Color.WHITE);
    Icon goldIcon = Icons.createImageIcon("gold200x200-2005.gif");
    if (goldIcon != null) {
        JLabel e2005 = new JLabel(goldIcon);
        aPanel.add(e2005);

        JTextArea title = new JTextArea();
        title.setLineWrap(true);
        title.setWrapStyleWord(true);
        title.setEditable(false);
        title.setText(LanguageBundle.getString("in_abt_awards_2005_ennie"));
        aPanel.add(title);
    }

    Icon bronzeIcon = Icons.createImageIcon("bronze200x200-2003.gif");
    if (bronzeIcon != null) {
        JLabel e2003 = new JLabel(bronzeIcon);
        aPanel.add(e2003);

        JTextArea title = new JTextArea();
        title.setLineWrap(true);
        title.setWrapStyleWord(true);
        title.setEditable(false);
        title.setText(LanguageBundle.getString("in_abt_awards_2003_ennie"));
        aPanel.add(title);
    }

    sp.setViewportView(aPanel);
    panel.add(sp, BorderLayout.CENTER);
    return panel;
}

From source file:savant.view.swing.Savant.java

/**
 * == [[ DOCKING ]] == Components (such as frames, the Task Pane, etc.) can
 * be docked to regions of the UI//from   w w w. j  av a2  s. c o m
 */
private void initDocking() {

    JPanel masterPlaceholderPanel = new JPanel();
    masterPlaceholderPanel.setLayout(new BorderLayout());

    panel_main.setLayout(new BorderLayout());
    panel_main.add(masterPlaceholderPanel, BorderLayout.CENTER);

    auxDockingManager = new DefaultDockingManager(this, masterPlaceholderPanel);

    masterPlaceholderPanel.setBackground(ColourSettings.getColor(ColourKey.SPLITTER));
    auxDockingManager.setSidebarRollover(false);
    auxDockingManager.getWorkspace().setBackground(ColourSettings.getColor(ColourKey.SPLITTER));
    auxDockingManager.setInitSplitPriority(DockingManager.SPLIT_EAST_SOUTH_WEST_NORTH);

    JPanel trackPanel = new JPanel();
    trackPanel.setLayout(new BorderLayout());

    auxDockingManager.getWorkspace().add(trackPanel, BorderLayout.CENTER);

    trackDockingManager = new DefaultDockingManager(this, trackPanel);
    trackPanel.setBackground(ColourSettings.getColor(ColourKey.SPLITTER));
    trackDockingManager.getWorkspace().setBackground(ColourSettings.getColor(ColourKey.SPLITTER));
    trackDockingManager.getWorkspace().setBackground(Color.red);
    trackDockingManager.setInitNorthSplit(JideSplitPane.VERTICAL_SPLIT);

    auxDockingManager.setShowInitial(false);
    trackDockingManager.setShowInitial(false);
    auxDockingManager.loadLayoutData();
    trackDockingManager.loadLayoutData();

    rangeSelector = new RangeSelectionPanel();
    rangeSelector.setPreferredSize(new Dimension(10000, 23));
    rangeSelector.setMaximumSize(new Dimension(10000, 23));
    locationController.addListener(rangeSelector);
    rangeSelector.setVisible(false);

    ruler = new Ruler();
    ruler.setPreferredSize(new Dimension(10000, 23));
    ruler.setMaximumSize(new Dimension(10000, 23));
    ruler.setVisible(false);

    Box box2 = Box.createVerticalBox();
    box2.add(rangeSelector);
    box2.add(ruler);

    trackPanel.add(box2, BorderLayout.NORTH);

    trackBackground = new JPanel();
    trackBackground.setBackground(Color.darkGray);

    trackBackground.setLayout(new BorderLayout());

    trackDockingManager.getWorkspace().add(trackBackground);
    trackDockingManager.setAllowedDockSides(DockContext.DOCK_SIDE_HORIZONTAL);
}

From source file:shuffle.fwk.service.teams.EditTeamService.java

private Component createTeamComponent(Species s) {
    Team curTeam = getCurrentTeam();//from w  w w .  j  a  va 2 s  .c o m
    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = 2;
    Indicator<SpeciesPaint> ind = new Indicator<SpeciesPaint>(this);
    boolean isMega = megaProgress >= megaThreshold && s.getName().equals(curTeam.getMegaSlotName());
    SpeciesPaint paint = new SpeciesPaint(s, s.equals(Species.FREEZE), isMega);
    ind.setVisualized(paint);
    ret.add(ind, c);
    c.gridy += 1;
    c.gridwidth = 1;
    JButton removeButton = new JButton(getString(KEY_REMOVE));
    removeButton.setToolTipText(getString(KEY_REMOVE_TOOLTIP));
    removeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            removeSpeciesFromTeam(s.getName());
            updateTeamPanel();
        }
    });
    removeButton.setEnabled(
            s.getEffect(getUser().getRosterManager()).isPickable() && !s.getType().equals(PkmType.NONE));
    ret.add(removeButton, c);

    c.gridx += 1;
    JComboBox<Character> keybindsComboBox = new JComboBox<Character>();
    Character curBinding = curTeam.getBinding(s);
    LinkedHashSet<Character> allBindingsFor = new LinkedHashSet<Character>(Arrays.asList(curBinding));
    LinkedHashSet<Character> availableBindings = myData.getAllAvailableBindingsFor(s.getName(), curTeam);
    allBindingsFor.addAll(availableBindings);
    for (Character ch : allBindingsFor) {
        keybindsComboBox.addItem(ch);
    }
    keybindsComboBox.setSelectedItem(curBinding);
    final ItemListener bindingListener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            JComboBox<?> source = (JComboBox<?>) e.getSource();
            int selectedIndex = source.getSelectedIndex();
            Character selected = (Character) source.getItemAt(selectedIndex);
            setBinding(s, selected);
            updateKeybindComboBoxes();
        }
    };
    nameToKeybindComboboxMap.put(s.getName(), keybindsComboBox);
    nameToItemListenerMap.put(s.getName(), bindingListener);
    keybindsComboBox.addItemListener(bindingListener);
    keybindsComboBox.setToolTipText(getString(KEY_KEYBINDS_TOOLTIP));
    ret.add(keybindsComboBox, c);

    MouseAdapter ma = new PressToggleMouseAdapter() {

        @Override
        protected void onRight(MouseEvent e) {
            doToggle();
        }

        @Override
        protected void onLeft(MouseEvent e) {
            doToggle();
        }

        private void doToggle() {
            toggleSupport(s);
            updateTeamPanel();
        }
    };
    ret.addMouseListener(ma);

    setBorderFor(ret, false, false);
    if (!Species.FIXED_SPECIES.contains(s)) {
        boolean isSupport = !curTeam.isNonSupport(s);
        Color indColor = isSupport ? Color.GREEN : Color.RED;
        ret.setBackground(indColor);
        ret.setOpaque(true);
    }
    return ret;
}

From source file:sk.stuba.fiit.kvasnicka.topologyvisual.gui.components.DropDownButton.java

private void init(boolean searchFieldEnabled) {

    setIcon(ImageResourceHelper/*  w  w  w.  j ava 2  s .  co m*/
            .loadImage("/sk/stuba/fiit/kvasnicka/topologyvisual/resources/files/arrow_down.gif"));
    setHorizontalTextPosition(JButton.LEFT);
    setFocusPainted(false);
    addActionListener(this);
    mainPanel.setLayout(new BorderLayout());

    JPanel northPanel = new JPanel(new BorderLayout());
    if (searchFieldEnabled) {
        addSearchField(northPanel);
    }
    final JCheckBox chSelectAll = new JCheckBox("All");
    chSelectAll.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectAll(chSelectAll.isSelected());
        }
    });
    chSelectAll.setAlignmentX(LEFT_ALIGNMENT);

    northPanel.add(chSelectAll, BorderLayout.CENTER);
    northPanel.setAlignmentX(LEFT_ALIGNMENT);
    northPanel.setBackground(Color.red);
    mainPanel.add(northPanel, BorderLayout.NORTH);

    checkPanel.setLayout(new BoxLayout(checkPanel, BoxLayout.PAGE_AXIS));
    scrollPane.setViewportView(checkPanel);
    scrollPane.setPreferredSize(new Dimension(200, 100));

    mainPanel.add(scrollPane, BorderLayout.CENTER);
    popup.add(mainPanel);

    popup.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            fireDropDownHiddenEvent(new DropDownHiddenEvent(this, getSelectedCheckBoxItems()));
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        }
    });

}

From source file:ui.panel.UIAccessKeySelect.java

public void runaccessKeySelect() {
    getAccessKeyData();/*  w ww  .j  a va  2 s  .c om*/
    Panel p = new Panel();
    Button b = new Button();
    Label l = new Label();

    setLayout(new BorderLayout());

    JPanel pnlInstruction = p.createPanel(Layouts.flow);
    JLabel lblInstruction = l.createLabel("Access Keys");
    pnlInstruction.setBackground(CustomColor.LightBlue.returnColor());
    lblInstruction.setForeground(Color.white);
    lblInstruction.setFont(new Font("San Serif", Font.PLAIN, 18));
    pnlInstruction.add(lblInstruction);

    JPanel pnlBucketList = p.createPanel(Layouts.border);

    listBucket.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane scrollBucket = new JScrollPane(listBucket);
    Component[] BucketListComponents = { scrollBucket };
    pnlBucketList.add(scrollBucket, BorderLayout.CENTER);

    JPanel pnlButtons = p.createPanel(Layouts.flow);

    JButton btnBack = b.createButton("Back");
    JButton btnSelectElements = b.createButton("Next");
    JButton btnAdd = b.createButton("Generate Access Key");
    JButton btnRefresh = b.createButton("Refresh");

    pnlButtons.add(btnBack);
    pnlButtons.add(btnAdd);
    pnlButtons.add(btnRefresh);
    pnlButtons.add(btnSelectElements);

    add(pnlInstruction, BorderLayout.NORTH);
    add(pnlBucketList, BorderLayout.CENTER);
    add(pnlButtons, BorderLayout.SOUTH);

    btnBack.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Data.mainFrame.showPanel("license");
        }
    });

    btnRefresh.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            getAccessKeyData();
        }
    });
    btnAdd.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Data.mainFrame.uiGenerateKey = new UIGenerateKey();
            Data.mainFrame.addPanel(Data.mainFrame.uiGenerateKey, "generateKey");
            Data.mainFrame.pack();
            Data.mainFrame.showPanel("generateKey");
        }
    });

    btnSelectElements.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() {
                @Override
                protected Void doInBackground() throws Exception {
                    int selected = listBucket.getSelectedRow();

                    if (selected != -1) {
                        Data.accessKey = (String) listBucket.getModel().getValueAt(selected, 0);
                        Data.mainFrame.qrGenerator = new JavaQR();
                        Data.mainFrame.pack();
                        Data.mainFrame.addPanel(Data.mainFrame.qrGenerator, "generateQR");
                        Data.mainFrame.showPanel("generateQR");
                    } else {
                        JOptionPane.showMessageDialog(Data.mainFrame, "Please Select Access Key", "Error",
                                JOptionPane.ERROR_MESSAGE);
                    }

                    return null;
                }
            };

            Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource());
            final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL);

            mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (evt.getPropertyName().equals("state")) {
                        if (evt.getNewValue() == SwingWorker.StateValue.DONE) {
                            dialog.dispose();
                        }
                    }
                }
            });
            mySwingWorker.execute();

            JProgressBar progressBar = new JProgressBar();
            progressBar.setIndeterminate(true);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(progressBar, BorderLayout.CENTER);
            panel.add(new JLabel("Generating QR Code......."), BorderLayout.PAGE_START);
            dialog.add(panel);
            dialog.pack();
            dialog.setBounds(50, 50, 300, 100);
            dialog.setLocationRelativeTo(Data.mainFrame);
            dialog.setVisible(true);
        }
    });
}

From source file:ui.panel.UIBucketSelect.java

public void runBucketSelect() {
    Panel p = new Panel();
    Button b = new Button();
    Label l = new Label();

    setLayout(new BorderLayout());

    JPanel pnlInstruction = p.createPanel(Layouts.flow);
    JLabel lblInstruction = l.createLabel("Bucket List");
    pnlInstruction.setBackground(CustomColor.LightBlue.returnColor());
    lblInstruction.setForeground(Color.white);
    lblInstruction.setFont(new Font("San Serif", Font.PLAIN, 18));
    pnlInstruction.add(lblInstruction);/*from   www  .jav  a 2s. com*/

    JPanel pnlBucketList = p.createPanel(Layouts.border);

    listBucket.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane scrollBucket = new JScrollPane(listBucket);
    scrollBucket.setPreferredSize(new Dimension(300, 150));
    pnlBucketList.add(scrollBucket, BorderLayout.CENTER);

    JPanel pnlButtons = p.createPanel(Layouts.flow);
    JButton btnBack = b.createButton("Back");
    JButton btnSelectElements = b.createButton("Next");
    JButton btnRefresh = b.createButton("Refresh Bucket List");

    pnlButtons.add(btnBack);
    pnlButtons.add(btnRefresh);
    pnlButtons.add(btnSelectElements);

    add(pnlInstruction, BorderLayout.NORTH);
    add(pnlBucketList, BorderLayout.CENTER);
    add(pnlButtons, BorderLayout.SOUTH);
    setVisible(true);

    btnRefresh.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            getBucketData();
        }
    });
    btnSelectElements.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() {
                @Override
                protected Void doInBackground() throws Exception {

                    int selected = listBucket.getSelectedRow();
                    if (selected == -1) {
                        JOptionPane.showMessageDialog(Data.mainFrame, "Please Select a Bucket", "Error",
                                JOptionPane.ERROR_MESSAGE);
                    } else {
                        Data.bucketID = (int) listBucket.getModel().getValueAt(selected, 0);
                        Data.mainFrame.addPanel(Data.mainFrame.uiLicenseDetail = new UILicenseDetail(),
                                "license");
                        Data.mainFrame.pack();
                        Data.mainFrame.showPanel("license");
                    }
                    return null;
                }
            };

            Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource());
            final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL);

            mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (evt.getPropertyName().equals("state")) {
                        if (evt.getNewValue() == SwingWorker.StateValue.DONE) {
                            dialog.dispose();
                        }
                    }
                }
            });
            mySwingWorker.execute();

            JProgressBar progressBar = new JProgressBar();
            progressBar.setIndeterminate(true);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(progressBar, BorderLayout.CENTER);
            panel.add(new JLabel("Retrieving Licenses......."), BorderLayout.PAGE_START);
            dialog.add(panel);
            dialog.pack();
            dialog.setBounds(50, 50, 300, 100);
            dialog.setLocationRelativeTo(Data.mainFrame);
            dialog.setVisible(true);
        }
    });
    btnBack.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
            Data.mainFrame.showPanel("inventory");
        }
    });
}

From source file:uk.ac.liverpool.narrative.SolutionGraphics.java

public void createVisualStateGraph(boolean dynamic, int iterations) {

    KKLayout<STRIPSState, Action> layout = new KKLayout<STRIPSState, Action>(sg.ggraph);// , new SDist<STRIPSState, Action>(ggraph));

    layout.setLengthFactor(1.7);/*from  ww  w. j  a  va 2  s .  co  m*/
    layout.setAdjustForGravity(false);
    // layout.setDisconnectedDistanceMultiplier(1.5);
    // layout.setExchangeVertices(true);
    layout.setSize(new Dimension(2000, 1200)); // sets the initial size of
    int i = 0;
    if (!dynamic) {
        layout.setMaxIterations(iterations);
        while (!layout.done() && i++ < iterations) {
            layout.step();
        }
        layout.lock(true);
    }
    final VisualizationViewer<STRIPSState, Action> vv = new VisualizationViewer<STRIPSState, Action>(layout);
    vvv = vv;
    vv.setPreferredSize(new Dimension(2000, 1200)); // Sets the viewing area

    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    vv.setGraphMouse(graphMouse);

    vv.setBackground(Color.white);
    vv.getRenderContext().setVertexLabelTransformer(new ConstantTransformer(""));
    vv.getRenderContext().setEdgeFontTransformer(new Transformer<Action, Font>() {
        @Override
        public Font transform(Action s) {

            Action ra = sg.realActions.get(s);
            Collection<Action> set = sg.actionToEdges.get(template.apply_template(ra));
            if (set != null && set.size() > 1)
                return DERIVE_FONT;
            return DERIVE_FONT2;
        }
    });

    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Action, String>() {
        @Override
        public String transform(Action a) {
            try {
                return sg.actionToString(template, a);
            } catch (IOException e) {
                e.printStackTrace();
                return "";
            }
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(new Transformer<Action, Paint>() {
        @Override
        public Paint transform(Action s) {
            sg.realActions.get(s);
            EdgeColor v = sg.edgeColors.get(s);
            if (v == null)
                return Color.yellow;
            if (v == EdgeColor.black)
                return Color.red;
            else
                return Color.lightGray;
        }
    });
    vv.getRenderContext().setVertexStrokeTransformer(new ConstantTransformer(new BasicStroke(0)));
    vv.getRenderContext().setVertexFillPaintTransformer(new Transformer<STRIPSState, Paint>() {

        @Override
        public Paint transform(STRIPSState s) {
            if (vv.getPickedVertexState().isPicked(s))
                return new Color(250, 250, 0, 207);
            Color c = cm.get(s);
            if (c != null)
                return c;

            if (sg.start.equals(s))
                return new Color(10, 200, 10, 197);
            else if (sg.ends.contains(s))
                return new Color(220, 10, 10, 197);
            return new Color(255, 210, 40, 197);
        }
    });
    vv.getRenderContext().setVertexShapeTransformer(new StoryStateTransformer());
    vv.getRenderContext()
            .setEdgeArrowTransformer(new DirectionalEdgeArrowTransformer<STRIPSState, Action>(10, 8, 1) {
                @Override
                public Shape transform(Context<Graph<STRIPSState, Action>, Action> context) {
                    if (sg.frequency.get(sg.ggraph.getEndpoints(context.element).getFirst()) != null) {
                        double c = Math.log(
                                sg.frequency.get(sg.ggraph.getEndpoints(context.element).getFirst())) * 0.8;
                        if (c > 1) {
                            Shape ss = AffineTransform.getScaleInstance(c, c)
                                    .createTransformedShape(super.transform(context));
                            return ss;
                        }
                    }

                    return super.transform(context);
                }

            });

    vv.setRenderer(new LabelsLastRenderer());

    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.AUTO);
    vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Action, Stroke>() {

        @Override
        public Stroke transform(Action a) {
            if (false)
                return new BasicStroke(
                        (sg.actionToEdges.get(template.apply_template(sg.realActions.get(a))).size()),
                        BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
            if (sg.frequency.get(sg.ggraph.getEndpoints(a).getFirst()) != null)
                return new BasicStroke(
                        (float) (Math.log(sg.frequency.get(sg.ggraph.getEndpoints(a).getFirst())) * 6.0),
                        BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
            else
                return new BasicStroke(1);
        }
    });
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.gray, false));
    vv.getRenderContext().setLabelOffset(20);
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));

    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);

    JPanel jp = new JPanel();
    jp.setBackground(Color.WHITE);
    jp.setLayout(new BorderLayout());
    jp.add(panel, BorderLayout.CENTER);
    JPanel top = new JPanel(new FlowLayout());

    jp.add(top, BorderLayout.NORTH);
    JFrame frame = new JFrame("Story state graph");
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.getContentPane().add(jp);
    frame.pack();
    frame.setVisible(true);

}

From source file:UNUSED.JUNGsamples.ShowLayouts.java

private static JPanel getGraphPanel() {
    g_array = (Graph<? extends Object, ? extends Object>[]) new Graph<?, ?>[graph_names.length];

    Factory<Graph<Integer, Number>> graphFactory = new Factory<Graph<Integer, Number>>() {
        public Graph<Integer, Number> create() {
            return new SparseMultigraph<Integer, Number>();
        }/*from  w w w. j av a 2s  .  c  o m*/
    };

    Factory<Integer> vertexFactory = new Factory<Integer>() {
        int count;

        public Integer create() {
            return count++;
        }
    };
    Factory<Number> edgeFactory = new Factory<Number>() {
        int count;

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

    g_array[0] = TestGraphs.createTestGraph(false);
    g_array[1] = MixedRandomGraphGenerator.generateMixedRandomGraph(graphFactory, vertexFactory, edgeFactory,
            new HashMap<Number, Number>(), 20, true, new HashSet<Integer>());
    g_array[2] = TestGraphs.getDemoGraph();
    g_array[3] = TestGraphs.createDirectedAcyclicGraph(6, 40, 0.3);
    g_array[4] = TestGraphs.getOneComponentGraph();
    g_array[5] = TestGraphs.createChainPlusIsolates(60, 5);
    g_array[6] = TestGraphs.createChainPlusIsolates(0, 40);

    Graph<? extends Object, ? extends Object> g = g_array[4]; // initial graph

    final VisualizationViewer<Integer, Number> vv = new VisualizationViewer<Integer, Number>(new FRLayout(g));

    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.red, Color.yellow));

    final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>();
    vv.setGraphMouse(graphMouse);

    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());
        }
    });
    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Layout<Integer, Number> layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                //            if(layout instanceof IterativeContext) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }
    });

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener());

    JPanel jp = new JPanel();
    jp.setBackground(Color.WHITE);
    jp.setLayout(new BorderLayout());
    jp.add(vv, BorderLayout.CENTER);
    Class[] combos = getCombos();
    final JComboBox jcb = new JComboBox(combos);
    // use a renderer to shorten the layout name presentation
    jcb.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            String valueString = value.toString();
            valueString = valueString.substring(valueString.lastIndexOf('.') + 1);
            return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus);
        }
    });
    jcb.addActionListener(new LayoutChooser(jcb, vv));
    jcb.setSelectedItem(FRLayout.class);

    JPanel control_panel = new JPanel(new GridLayout(2, 1));
    JPanel topControls = new JPanel();
    JPanel bottomControls = new JPanel();
    control_panel.add(topControls);
    control_panel.add(bottomControls);
    jp.add(control_panel, BorderLayout.NORTH);

    final JComboBox graph_chooser = new JComboBox(graph_names);

    graph_chooser.addActionListener(new GraphChooser(jcb));

    topControls.add(jcb);
    topControls.add(graph_chooser);
    bottomControls.add(plus);
    bottomControls.add(minus);
    bottomControls.add(modeBox);
    bottomControls.add(reset);
    return jp;
}

From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java

public OpenBSTGUI() {
    instance = this;
    UIManager.put("OptionPane.errorIcon", new ImageIcon(Icons.getImage("Cancel", 48)));
    UIManager.put("OptionPane.informationIcon", new ImageIcon(Icons.getImage("About", 48)));
    UIManager.put("OptionPane.questionIcon", new ImageIcon(Icons.getImage("Rename", 48)));
    UIManager.put("OptionPane.warningIcon", new ImageIcon(Icons.getImage("Error", 48)));

    BorderLayout borderLayout = new BorderLayout();
    borderLayout.setVgap(4);//from w ww  . jav a  2s  .com
    getContentPane().setLayout(borderLayout);
    setIconImage(Icons.getImage("Logo", 48));
    setTitle("OpenBST " + OpenBST.VERSION);
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            boolean cancelled = false;
            int i = 0;
            for (Component c : container.getComponents()) {
                if (c instanceof StoryPanel) {
                    i++;
                } else if (c instanceof StoryEditor) {
                    container.setSelectedComponent(c);
                    if (((StoryEditor) c).askClose()) {
                        continue;
                    } else {
                        cancelled = true;
                        break;
                    }
                }
            }
            if (!cancelled) {
                if (i > 0) {
                    int j = Messagers.showConfirm(OpenBSTGUI.this,
                            "You are about to close " + i + " file(s). Are you sure you wish to exit OpenBST?",
                            Messagers.OPTIONS_YES_NO, Messagers.TYPE_WARNING, "Closing OpenBST");
                    if (j != Messagers.OPTION_YES)
                        cancelled = true;
                }
                if (!cancelled)
                    System.exit(0);
            }
        }

    });

    JMenuBar jmb = new JMenuBar();
    jmb.setBackground(OPENBST_BLUE);
    jmb.add(Box.createHorizontalGlue());
    jmb.add(createShortMenu());
    jmb.add(Box.createHorizontalGlue());
    this.setJMenuBar(jmb);

    addDarkModeCallback(b -> {
        jmb.setBackground(b ? OPENBST_BLUE.darker().darker() : OPENBST_BLUE);
    });

    container = new JTabbedPane();
    container.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    container.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (SwingUtilities.isMiddleMouseButton(e)) {
                final int i = container.indexAtLocation(e.getX(), e.getY());
                System.out.println(i);
                if (i > -1) {
                    Component c = container.getComponentAt(i);
                    if (c instanceof StoryPanel) {
                        container.setSelectedComponent(c);
                        ((StoryPanel) c).askClose();
                    } else if (c instanceof StoryEditor) {
                        container.setSelectedComponent(c);
                        ((StoryEditor) c).askClose();
                    }
                }
            }
        }
    });
    getContentPane().add(container, BorderLayout.CENTER);

    final JBackgroundPanel welcomeContentPanel = new JBackgroundPanel(Icons.getRandomBackground(),
            Image.SCALE_FAST);
    background = welcomeContentPanel;

    welcomeContentPanel.setLayout(new MigLayout("hidemode 2", "[grow,center]", "[][grow][]"));
    container.add(welcomeContentPanel);
    container.setTitleAt(0, Lang.get("welcome"));

    bannersPanel = new JPanel(new MigLayout("hidemode 2, gap 0px, fill, wrap 1, ins 0"));
    bannersPanel.setBackground(new Color(0, 0, 0, 0));
    welcomeContentPanel.add(bannersPanel, "cell 0 0,grow");

    if (OpenBST.VERSION.endsWith("u")) {
        JButton btnReportBugs = new JButton(Lang.get("welcome.reportbugs"));
        btnReportBugs.addActionListener(e -> {
            VisualsUtils.browse("https://github.com/utybo/BST/issues");
        });
        bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Experiment", 32)), Color.YELLOW,
                Lang.get("welcome.ontheedge"), btnReportBugs, false), "grow");
    } else if (OpenBST.VERSION.contains("SNAPSHOT")) {
        bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Experiment", 32)), Color.ORANGE,
                Lang.get("welcome.snapshot"), null, false), "grow");
    }

    if (System.getProperty("java.specification.version").equals("9")) {
        bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Attention", 32)),
                new Color(255, 50, 50), Lang.get("welcome.java9warning"), null, false), "grow");
    }
    if (System.getProperty("java.specification.version").equals("10")) {
        bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Attention", 32)),
                new Color(255, 50, 50), Lang.get("welcome.java10warning"), null, false), "grow");
    }

    JButton btnJoinDiscord = new JButton(Lang.get("openbst.discordjoin"));
    btnJoinDiscord.addActionListener(e -> {
        VisualsUtils.browse("https://discord.gg/6SVDCMM");
    });
    bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Discord", 48)), DISCORD_COLOR,
            Lang.get("openbst.discord"), btnJoinDiscord, true), "grow");

    JPanel panel = new JPanel();
    panel.setBackground(new Color(0, 0, 0, 0));
    welcomeContentPanel.add(panel, "flowx,cell 0 1,growx,aligny center");
    panel.setLayout(new MigLayout("", "[40%][][][][60%,growprio 50]", "[][grow]"));

    final JLabel lblOpenbst = new JLabel(new ImageIcon(Icons.getImage("FullLogo", 48)));
    addDarkModeCallback(b -> lblOpenbst
            .setIcon(new ImageIcon(b ? Icons.getImage("FullLogoWhite", 48) : Icons.getImage("FullLogo", 48))));
    panel.add(lblOpenbst, "flowx,cell 0 0 1 2,alignx trailing,aligny center");

    JSeparator separator = new JSeparator();
    separator.setOrientation(SwingConstants.VERTICAL);
    panel.add(separator, "cell 2 0 1 2,growy");

    final JLabel lblWelcomeToOpenbst = new JLabel("<html>" + Lang.get("welcome.intro"));
    lblWelcomeToOpenbst.setMaximumSize(new Dimension(350, 999999));
    panel.add(lblWelcomeToOpenbst, "cell 4 0");

    Component horizontalStrut = Box.createHorizontalStrut(10);
    panel.add(horizontalStrut, "cell 1 1");

    Component horizontalStrut_1 = Box.createHorizontalStrut(10);
    panel.add(horizontalStrut_1, "cell 3 1");

    final JButton btnOpenAFile = new JButton(Lang.get("welcome.open"));
    panel.add(btnOpenAFile, "flowx,cell 4 1");
    btnOpenAFile.setIcon(new ImageIcon(Icons.getImage("Open", 40)));
    btnOpenAFile.addActionListener(e -> {
        openStory(VisualsUtils.askForFile(this, Lang.get("file.title")));
    });

    final JButton btnOpenEditor = new JButton(Lang.get("welcome.openeditor"));
    panel.add(btnOpenEditor, "cell 4 1");
    btnOpenEditor.setIcon(new ImageIcon(Icons.getImage("Edit Property", 40)));
    btnOpenEditor.addActionListener(e -> {
        openEditor(VisualsUtils.askForFile(this, Lang.get("file.title")));
    });

    JButton btnChangeBackground = new JButton(Lang.get("welcome.changebackground"),
            new ImageIcon(Icons.getImage("Change Theme", 16)));
    btnChangeBackground.addActionListener(e -> {
        BufferedImage prev = background.getImage();
        BufferedImage next;
        do {
            next = Icons.getRandomBackground();
        } while (prev == next);
        background.setImage(next);
    });
    welcomeContentPanel.add(btnChangeBackground, "flowx,cell 0 2,alignx left");

    JButton btnWelcomepixabay = new JButton(Lang.get("welcome.pixabay"),
            new ImageIcon(Icons.getImage("External Link", 16)));
    btnWelcomepixabay.addActionListener(e -> {
        VisualsUtils.browse("https://pixabay.com");

    });
    welcomeContentPanel.add(btnWelcomepixabay, "cell 0 2");

    JLabel creds = new JLabel(Lang.get("welcome.credits"));
    creds.setEnabled(false);
    welcomeContentPanel.add(creds, "cell 0 2, gapbefore 10px");

    setSize((int) (830 * Icons.getScale()), (int) (480 * Icons.getScale()));
    setLocationRelativeTo(null);
}