Example usage for javax.swing JComponent setBorder

List of usage examples for javax.swing JComponent setBorder

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.")
public void setBorder(Border border) 

Source Link

Document

Sets the border of this component.

Usage

From source file:cool.pandora.modeller.ui.jpanel.base.BagInfoForm.java

private void createFormFieldsFromMap(final BagTableFormBuilder formBuilder) {
    int rowCount = 0;
    final int index = 2;

    final Set<String> keys = fieldMap.keySet();
    for (final BagInfoField field : fieldMap.values()) {
        formBuilder.row();/*w  ww . j a v a2  s .  c o m*/
        rowCount++;
        final ImageIcon imageIcon = bagView.getPropertyImage("bag.delete.image");
        JButton removeButton = new JButton(imageIcon);
        final Dimension dimension = removeButton.getPreferredSize();
        dimension.width = imageIcon.getIconWidth();
        removeButton.setMaximumSize(dimension);
        removeButton.setOpaque(false);
        removeButton.setBorderPainted(false);
        removeButton.setContentAreaFilled(false);
        removeButton.addActionListener(new RemoveFieldHandler());
        logger.debug("OrganizationInfoForm add: " + field);
        if (field.getValue() != null && field.getValue().length() > 60) {
            field.setComponentType(BagInfoField.TEXTAREA_COMPONENT);
        }
        if (field.isRequired()) {
            removeButton = new JButton();
            removeButton.setOpaque(false);
            removeButton.setBorderPainted(false);
            removeButton.setContentAreaFilled(false);
        }
        switch (field.getComponentType()) {
        case BagInfoField.TEXTAREA_COMPONENT:
            final JComponent[] tlist = formBuilder.addTextArea(field.isRequired(), field.getLabel(),
                    removeButton);
            final JComponent textarea = tlist[index];
            textarea.setEnabled(field.isEnabled());
            textarea.addFocusListener(this);
            ((NoTabTextArea) textarea).setText(field.getValue());
            textarea.setBorder(new EmptyBorder(1, 1, 1, 1));
            ((NoTabTextArea) textarea).setLineWrap(true);
            if (rowCount == 1) {
                focusField = textarea;
            }
            break;
        case BagInfoField.TEXTFIELD_COMPONENT:
            final JComponent[] flist = formBuilder.add(field.isRequired(), field.getLabel(), removeButton);
            final JComponent comp = flist[index];
            comp.setEnabled(field.isEnabled());
            comp.addFocusListener(this);
            ((JTextField) comp).setText(field.getValue());
            if (rowCount == 1) {
                focusField = comp;
            }
            break;
        case BagInfoField.LIST_COMPONENT:
            final List<String> elements = field.getElements();
            final JComponent[] llist = formBuilder.addList(field.isRequired(), field.getLabel(), elements,
                    field.getValue(), removeButton);
            final JComponent lcomp = llist[index];
            lcomp.setEnabled(field.isEnabled());
            lcomp.addFocusListener(this);
            if (field.getValue() != null) {
                ((JComboBox<?>) lcomp).setSelectedItem(field.getValue().trim());
            }
            if (rowCount == 1) {
                focusField = lcomp;
            }
            break;
        default:
        }
    }
    if (focusField != null) {
        focusField.requestFocus();
    }

}

From source file:com.projity.pm.graphic.network.rendering.FormComponent.java

public void init(BarFormat format) {
    if (format == null)
        return;//  w  w  w  .j av  a 2  s.  c o m
    FormFormat form = format.getForm();
    if (form == null)
        return;
    List boxes = form.getBoxes();
    if (boxes == null || boxes.size() == 0) {
        return;
    }
    FormBoxLayout formBoxLayout = form.getLayout(zoom);
    FormLayout layout = new FormLayout(formBoxLayout.getColumnGrid(), formBoxLayout.getRowGrid());
    ///DefaultFormBuilder builder = new DefaultFormBuilder(this,layout);
    DefaultFormBuilder builder = new DefaultFormBuilder(layout, this);
    if (formBoxLayout.getBorder() == null)
        builder.setDefaultDialogBorder();
    else
        builder.setBorder(Borders.createEmptyBorder(formBoxLayout.getBorder()));
    CellConstraints cc = new CellConstraints();
    for (Iterator i = boxes.iterator(); i.hasNext();) {
        FormBox box = (FormBox) i.next();
        if (zoom < box.getMinZoom())
            return;
        JComponent component;
        if (box.getFieldId() == null)
            component = new JLabel(Messages.getString(box.getTextId()));
        else {
            if (editor && !box.getField().isReadOnly()) {
                component = new ChangeAwareTextField();
                component.setBorder(null);
                //component.setOpaque(false);
            } else
                component = new JLabel();

            //if (box.getRow()==1&&!editor) ((JLabel)component).setHorizontalAlignment(SwingConstants.CENTER);
            //bug workaround, not possible to center with classic method when rowSpan>1

            fieldComponents.put(box.getFieldId(), component);
        }
        Font font = formBoxLayout.getFont(box.getFont());
        if (font != null)
            component.setFont(font);
        String ba = box.getAlignment();
        int bc = box.getColumn();
        int br = box.getRow();
        int bcs = box.getColumnSpan();
        int brs = box.getRowSpan();
        try {
            builder.add(component, (ba == null) ? cc.xywh(bc, br, bcs, brs) : cc.xywh(bc, br, bcs, brs, ba));
        } catch (IndexOutOfBoundsException e) {
            log.fatal("box.Column(): " + bc);
            log.fatal("box.Row(): " + br);
            log.fatal("box.ColumnSpan(): " + bcs);
            log.fatal("box.RowSpan(): " + brs);
            log.fatal("box.Alignment(): " + ba);
            log.fatal("Occur Error: ", e);
        }
    }
}

From source file:com.diversityarrays.kdxplore.field.OriginDirectionTraversalChoicePanel.java

public OriginDirectionTraversalChoicePanel(Closure<Void> onChange) {

    this.onChange = onChange;

    Border lineBorder = new LineBorder(Color.BLACK);
    JComponent topsep, leftsep, rightsep, botsep;

    topsep = new JSeparator(JSeparator.VERTICAL);
    botsep = new JSeparator(JSeparator.VERTICAL);

    topsep.setBorder(lineBorder);
    botsep.setBorder(lineBorder);//from   w  ww  . j  a  va2 s.  co m

    leftsep = new JSeparator(JSeparator.HORIZONTAL);
    rightsep = new JSeparator(JSeparator.HORIZONTAL);

    GBH gbh = new GBH(this);
    int y = 0;

    gbh.add(0, y, 1, 1, GBH.NONE, 1, 1, GBH.CENTER, corner_ul);
    gbh.add(1, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, crb_ul_right);
    //      gbh.add(2,y, 1,2, GBH.VERT, 1,1, GBH.CENTER, topsep);
    gbh.add(3, y, 1, 1, GBH.NONE, 1, 1, GBH.EAST, crb_ur_left);
    gbh.add(4, y, 1, 1, GBH.NONE, 1, 1, GBH.CENTER, corner_ur);
    ++y;

    gbh.add(0, y, 1, 1, GBH.NONE, 1, 1, GBH.CENTER, withInsets(crb_ul_down, new Insets(10, 0, 0, 0)));
    //         gbh.add(1,y, 1,1, GBH.NONE, 1,1, GBH.CENTER, xxx);
    //         gbh.add(2,y, 1,1, GBH.NONE, 1,1, GBH.CENTER, xxx);
    gbh.add(4, y, 1, 1, GBH.NONE, 1, 1, GBH.CENTER, withInsets(crb_ur_down, new Insets(10, 0, 0, 0)));
    ++y;

    gbh.add(0, y, 1, 1, GBH.HORZ, 1, 1, GBH.CENTER, leftsep);
    JLabel label = gbh.add(1, y, 3, 1, GBH.HORZ, 1, 1, GBH.CENTER, "Origin & Direction");
    gbh.add(4, y, 1, 1, GBH.HORZ, 1, 1, GBH.CENTER, rightsep);
    ++y;
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setBorder(lineBorder);

    gbh.add(0, y, 1, 1, GBH.NONE, 1, 1, GBH.CENTER, withInsets(crb_ll_up, new Insets(0, 0, 10, 0)));
    //         gbh.add(1,y, 1,1, GBH.NONE, 1,1, GBH.CENTER, xxx);
    //      gbh.add(2,y, 1,2, GBH.VERT, 1,1, GBH.CENTER, botsep);
    //         gbh.add(2,y, 1,1, GBH.NONE, 1,1, GBH.CENTER, xxx);
    gbh.add(4, y, 1, 1, GBH.NONE, 1, 1, GBH.CENTER, withInsets(crb_lr_up, new Insets(0, 0, 10, 0)));
    ++y;

    gbh.add(0, y, 1, 1, GBH.NONE, 1, 1, GBH.CENTER, corner_ll);
    gbh.add(1, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, crb_ll_right);
    gbh.add(3, y, 1, 1, GBH.NONE, 1, 1, GBH.EAST, crb_lr_left);
    gbh.add(4, y, 1, 1, GBH.NONE, 1, 1, GBH.CENTER, corner_lr);
    ++y;

    gbh.add(0, y, 5, 1, GBH.HORZ, 1, 1, GBH.CENTER, new JSeparator(JSeparator.HORIZONTAL));
    ++y;

    gbh.add(0, y, 1, 1, GBH.NONE, 1, 1, GBH.EAST, "Traversal:");
    gbh.add(1, y, 1, 1, GBH.HORZ, 2, 1, GBH.CENTER, rbPanel);
    ++y;
}

From source file:com.intellij.lang.jsgraphql.ide.project.JSGraphQLLanguageUIProjectService.java

private JComponent createToolbar(ActionGroup actionGroup) {
    final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.EDITOR_TOOLBAR,
            actionGroup, true);//from  w  w  w .j av  a 2  s .c  om
    toolbar.setReservePlaceAutoPopupIcon(false); // don't want space after the last button
    final JComponent component = toolbar.getComponent();
    component.setBorder(BorderFactory.createEmptyBorder());
    return component;
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JPasswordField createPasswordField(DocumentListener... docListeners) {
    final JPasswordField field = new JPasswordField();
    final Border oldBorder = field.getBorder();
    if (docListeners != null) {
        for (DocumentListener docListener : docListeners) {
            field.getDocument().addDocumentListener(docListener);
            field.getDocument().putProperty("owner", field);
        }/*from   w ww  . ja v a 2  s . c o  m*/
    }
    final InputVerifier verifier = new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            final JPasswordField field = (JPasswordField) input;
            char[] txt = field.getPassword();
            if (txt.length == 0) {
                // Run in EDT to avoid deadlock in case this gets called
                // from not swing thread
                Util.runInEDT(new Runnable() {
                    @Override
                    public void run() {
                        field.setToolTipText(UILabels.STL50084_CANT_BE_BLANK.getDescription());
                        input.setBackground(UIConstants.INTEL_LIGHT_RED);
                        input.setBorder(BorderFactory.createLineBorder(UIConstants.INTEL_RED, 2));
                        // show tooltip immediately
                        ToolTipManager.sharedInstance()
                                .mouseMoved(new MouseEvent(field, 0, 0, 0, 0, 0, 0, false));
                    }
                });
                return false;
            } else {
                Util.runInEDT(new Runnable() {
                    @Override
                    public void run() {
                        input.setBackground(UIConstants.INTEL_WHITE);
                        input.setBorder(oldBorder);
                    }
                });
                return true;
            }
        }

    };

    DocumentListener dynamicChecker = new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

    };
    field.getDocument().addDocumentListener(dynamicChecker);

    // Add the input verifier
    field.setInputVerifier(verifier);

    return field;
}

From source file:net.sf.taverna.t2.workbench.ui.impl.UserRegistrationForm.java

/**
 * Adds a light gray or etched border to the top or bottom of a JComponent.
 * /*from   w  ww  .j  a  v  a  2 s .  c o  m*/
 * @author David Withers
 * @param component
 */
protected void addDivider(JComponent component, final int position, final boolean etched) {
    component.setBorder(new Border() {
        private final Color borderColor = new Color(.6f, .6f, .6f);

        @Override
        public Insets getBorderInsets(Component c) {
            if (position == TOP)
                return new Insets(5, 0, 0, 0);
            else
                return new Insets(0, 0, 5, 0);
        }

        @Override
        public boolean isBorderOpaque() {
            return false;
        }

        @Override
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            if (position == TOP) {
                if (etched) {
                    g.setColor(borderColor);
                    g.drawLine(x, y, x + width, y);
                    g.setColor(WHITE);
                    g.drawLine(x, y + 1, x + width, y + 1);
                } else {
                    g.setColor(LIGHT_GRAY);
                    g.drawLine(x, y, x + width, y);
                }
            } else {
                if (etched) {
                    g.setColor(borderColor);
                    g.drawLine(x, y + height - 2, x + width, y + height - 2);
                    g.setColor(WHITE);
                    g.drawLine(x, y + height - 1, x + width, y + height - 1);
                } else {
                    g.setColor(LIGHT_GRAY);
                    g.drawLine(x, y + height - 1, x + width, y + height - 1);
                }
            }
        }
    });
}

From source file:com.brainflow.application.toplevel.Brainflow.java

private void initializeWorkspace() throws Exception {
    log.info("initializing workspace");
    brainFrame.getDockingManager().getWorkspace().setLayout(new BorderLayout());
    brainFrame.getDockingManager().getWorkspace().add(documentPane, "Center");

    JComponent canvas = DisplayManager.getInstance().getSelectedCanvas().getComponent();
    canvas.setRequestFocusEnabled(true);
    canvas.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

    documentPane.setTabPlacement(DocumentPane.BOTTOM);
    documentPane.openDocument(new DocumentComponent(new JScrollPane(canvas), "Canvas-1"));
    documentPane.setActiveDocument("Canvas-1");

    log.info("initializing loading dock");
    initLoadingDock();/* w ww . j  a  v  a 2  s.c  o  m*/
    log.info("initializing project view");
    initProjectView();
    log.info("initializing image table view");
    initLoadableImageTableView();
    log.info("initializing control panel");
    initControlPanel();
    log.info("initializing event monitor");
    initEventBusMonitor();
    log.info("initializing log monitor");
    initLogMonitor();

    brainFrame.getDockingManager().beginLoadLayoutData();
    brainFrame.getDockingManager().setInitSplitPriority(DefaultDockingManager.SPLIT_EAST_WEST_SOUTH_NORTH);
    brainFrame.getDockingManager().loadLayoutData();

    brainFrame.toFront();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    brainFrame.setSize((int) screenSize.getWidth(), (int) screenSize.getHeight() - 50);
    brainFrame.setVisible(true);

    CanvasBar2 cbar = new CanvasBar2();

    /// TODO add automatic updating of canvas to Canvas Bar via EventBus
    //cbar.setImageCanvas(canvas);
    ////////////////////////////////////////////////////////////////////
    canvas.add(cbar.getComponent(), BorderLayout.NORTH);

}

From source file:com.net2plan.gui.utils.topologyPane.TopologyPanel.java

/**
 * Default constructor.//from w  w w . j  a v  a 2s .  c  o m
 *
 * @param callback               Topology callback listening plugin events
 * @param defaultDesignDirectory Default location for design {@code .n2p} files (it may be null, then default is equal to {@code net2planFolder/workspace/data/networkTopologies})
 * @param defaultDemandDirectory Default location for design {@code .n2p} files (it may be null, then default is equal to {@code net2planFolder/workspace/data/trafficMatrices})
 * @param canvasType             Canvas type (i.e. JUNG)
 * @param plugins                List of plugins to be included (it may be null)
 */
public TopologyPanel(final IVisualizationCallback callback, File defaultDesignDirectory,
        File defaultDemandDirectory, Class<? extends ITopologyCanvas> canvasType,
        List<ITopologyCanvasPlugin> plugins) {
    File currentDir = SystemUtils.getCurrentDir();

    this.callback = callback;
    this.defaultDesignDirectory = defaultDesignDirectory == null ? new File(
            currentDir + SystemUtils.getDirectorySeparator() + "workspace" + SystemUtils.getDirectorySeparator()
                    + "data" + SystemUtils.getDirectorySeparator() + "networkTopologies")
            : defaultDesignDirectory;
    this.defaultDemandDirectory = defaultDemandDirectory == null ? new File(
            currentDir + SystemUtils.getDirectorySeparator() + "workspace" + SystemUtils.getDirectorySeparator()
                    + "data" + SystemUtils.getDirectorySeparator() + "trafficMatrices")
            : defaultDemandDirectory;
    this.multilayerControlPanel = new MultiLayerControlPanel(callback);

    try {
        canvas = canvasType.getDeclaredConstructor(IVisualizationCallback.class, TopologyPanel.class)
                .newInstance(callback, this);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    if (plugins != null)
        for (ITopologyCanvasPlugin plugin : plugins)
            addPlugin(plugin);

    setLayout(new BorderLayout());

    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);
    toolbar.setFloatable(false);
    toolbar.setOpaque(false);
    toolbar.setBorderPainted(false);

    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.add(toolbar, BorderLayout.NORTH);

    add(topPanel, BorderLayout.NORTH);

    JComponent canvasComponent = canvas.getCanvasComponent();

    canvasPanel = new JPanel(new BorderLayout());
    canvasComponent.setBorder(LineBorder.createBlackLineBorder());

    JToolBar multiLayerToolbar = new JToolBar(JToolBar.VERTICAL);
    multiLayerToolbar.setRollover(true);
    multiLayerToolbar.setFloatable(false);
    multiLayerToolbar.setOpaque(false);

    canvasPanel.add(canvasComponent, BorderLayout.CENTER);
    canvasPanel.add(multiLayerToolbar, BorderLayout.WEST);
    add(canvasPanel, BorderLayout.CENTER);

    btn_load = new JButton();
    btn_load.setToolTipText("Load a network design");
    btn_loadDemand = new JButton();
    btn_loadDemand.setToolTipText("Load a traffic demand set");
    btn_save = new JButton();
    btn_save.setToolTipText("Save current state to a file");
    btn_zoomIn = new JButton();
    btn_zoomIn.setToolTipText("Zoom in");
    btn_zoomOut = new JButton();
    btn_zoomOut.setToolTipText("Zoom out");
    btn_zoomAll = new JButton();
    btn_zoomAll.setToolTipText("Zoom all");
    btn_takeSnapshot = new JButton();
    btn_takeSnapshot.setToolTipText("Take a snapshot of the canvas");
    btn_showNodeNames = new JToggleButton();
    btn_showNodeNames.setToolTipText("Show/hide node names");
    btn_showLinkIds = new JToggleButton();
    btn_showLinkIds.setToolTipText(
            "Show/hide link utilization, measured as the ratio between the total traffic in the link (including that in protection segments) and total link capacity (including that reserved by protection segments)");
    btn_showNonConnectedNodes = new JToggleButton();
    btn_showNonConnectedNodes.setToolTipText("Show/hide non-connected nodes");
    btn_increaseNodeSize = new JButton();
    btn_increaseNodeSize.setToolTipText("Increase node size");
    btn_decreaseNodeSize = new JButton();
    btn_decreaseNodeSize.setToolTipText("Decrease node size");
    btn_increaseFontSize = new JButton();
    btn_increaseFontSize.setToolTipText("Increase font size");
    btn_decreaseFontSize = new JButton();
    btn_decreaseFontSize.setToolTipText("Decrease font size");
    /* Multilayer buttons */
    btn_increaseInterLayerDistance = new JButton();
    btn_increaseInterLayerDistance
            .setToolTipText("Increase the distance between layers (when more than one layer is visible)");
    btn_decreaseInterLayerDistance = new JButton();
    btn_decreaseInterLayerDistance
            .setToolTipText("Decrease the distance between layers (when more than one layer is visible)");
    btn_showLowerLayerInfo = new JToggleButton();
    btn_showLowerLayerInfo
            .setToolTipText("Shows the links in lower layers that carry traffic of the picked element");
    btn_showLowerLayerInfo.setSelected(getVisualizationState().isShowInCanvasLowerLayerPropagation());
    btn_showUpperLayerInfo = new JToggleButton();
    btn_showUpperLayerInfo.setToolTipText(
            "Shows the links in upper layers that carry traffic that appears in the picked element");
    btn_showUpperLayerInfo.setSelected(getVisualizationState().isShowInCanvasUpperLayerPropagation());
    btn_showThisLayerInfo = new JToggleButton();
    btn_showThisLayerInfo.setToolTipText(
            "Shows the links in the same layer as the picked element, that carry traffic that appears in the picked element");
    btn_showThisLayerInfo.setSelected(getVisualizationState().isShowInCanvasThisLayerPropagation());
    btn_npChangeUndo = new JButton();
    btn_npChangeUndo.setToolTipText(
            "Navigate back to the previous state of the network (last time the network design was changed)");
    btn_npChangeRedo = new JButton();
    btn_npChangeRedo.setToolTipText(
            "Navigate forward to the next state of the network (when network design was changed");

    btn_osmMap = new JToggleButton();
    btn_osmMap.setToolTipText(
            "Toggle between on/off the OSM support. An internet connection is required in order for this to work.");
    btn_tableControlWindow = new JButton();
    btn_tableControlWindow.setToolTipText("Show the network topology control window.");

    // MultiLayer control window
    JPopupMenu multiLayerPopUp = new JPopupMenu();
    multiLayerPopUp.add(multilayerControlPanel);
    JPopUpButton btn_multilayer = new JPopUpButton("", multiLayerPopUp);

    btn_reset = new JButton("Reset");
    btn_reset.setToolTipText("Reset the user interface");
    btn_reset.setMnemonic(KeyEvent.VK_R);

    btn_load.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/loadDesign.png")));
    btn_loadDemand.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/loadDemand.png")));
    btn_save.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/saveDesign.png")));
    btn_showNodeNames
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNodeName.png")));
    btn_showLinkIds
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLinkUtilization.png")));
    btn_showNonConnectedNodes.setIcon(
            new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNonConnectedNodes.png")));
    //btn_whatIfActivated.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNonConnectedNodes.png")));
    btn_zoomIn.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomIn.png")));
    btn_zoomOut.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomOut.png")));
    btn_zoomAll.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomAll.png")));
    btn_takeSnapshot.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/takeSnapshot.png")));
    btn_increaseNodeSize
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseNode.png")));
    btn_decreaseNodeSize
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseNode.png")));
    btn_increaseFontSize
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseFont.png")));
    btn_decreaseFontSize
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseFont.png")));
    btn_increaseInterLayerDistance.setIcon(
            new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseLayerDistance.png")));
    btn_decreaseInterLayerDistance.setIcon(
            new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseLayerDistance.png")));
    btn_multilayer
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerControl.png")));
    btn_showThisLayerInfo
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerPropagation.png")));
    btn_showUpperLayerInfo.setIcon(
            new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerUpperPropagation.png")));
    btn_showLowerLayerInfo.setIcon(
            new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerLowerPropagation.png")));
    btn_tableControlWindow
            .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showControl.png")));
    btn_osmMap.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showOSM.png")));
    btn_npChangeUndo.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/undoButton.png")));
    btn_npChangeRedo.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/redoButton.png")));

    btn_load.addActionListener(this);
    btn_loadDemand.addActionListener(this);
    btn_save.addActionListener(this);
    btn_showNodeNames.addActionListener(this);
    btn_showLinkIds.addActionListener(this);
    btn_showNonConnectedNodes.addActionListener(this);
    btn_zoomIn.addActionListener(this);
    btn_zoomOut.addActionListener(this);
    btn_zoomAll.addActionListener(this);
    btn_takeSnapshot.addActionListener(this);
    btn_reset.addActionListener(this);
    btn_increaseInterLayerDistance.addActionListener(this);
    btn_decreaseInterLayerDistance.addActionListener(this);
    btn_showLowerLayerInfo.addActionListener(this);
    btn_showUpperLayerInfo.addActionListener(this);
    btn_showThisLayerInfo.addActionListener(this);
    btn_increaseNodeSize.addActionListener(this);
    btn_decreaseNodeSize.addActionListener(this);
    btn_increaseFontSize.addActionListener(this);
    btn_decreaseFontSize.addActionListener(this);
    btn_npChangeUndo.addActionListener(this);
    btn_npChangeRedo.addActionListener(this);
    btn_osmMap.addActionListener(this);
    btn_tableControlWindow.addActionListener(this);

    toolbar.add(btn_load);
    toolbar.add(btn_loadDemand);
    toolbar.add(btn_save);
    toolbar.add(new JToolBar.Separator());
    toolbar.add(btn_zoomIn);
    toolbar.add(btn_zoomOut);
    toolbar.add(btn_zoomAll);
    toolbar.add(btn_takeSnapshot);
    toolbar.add(new JToolBar.Separator());
    toolbar.add(btn_showNodeNames);
    toolbar.add(btn_showLinkIds);
    toolbar.add(btn_showNonConnectedNodes);
    toolbar.add(new JToolBar.Separator());
    toolbar.add(btn_increaseNodeSize);
    toolbar.add(btn_decreaseNodeSize);
    toolbar.add(btn_increaseFontSize);
    toolbar.add(btn_decreaseFontSize);
    toolbar.add(new JToolBar.Separator());
    toolbar.add(Box.createHorizontalGlue());
    toolbar.add(btn_osmMap);
    toolbar.add(btn_tableControlWindow);
    toolbar.add(btn_reset);

    multiLayerToolbar.add(new JToolBar.Separator());
    multiLayerToolbar.add(btn_multilayer);
    multiLayerToolbar.add(btn_increaseInterLayerDistance);
    multiLayerToolbar.add(btn_decreaseInterLayerDistance);
    multiLayerToolbar.add(btn_showLowerLayerInfo);
    multiLayerToolbar.add(btn_showUpperLayerInfo);
    multiLayerToolbar.add(btn_showThisLayerInfo);
    multiLayerToolbar.add(Box.createVerticalGlue());
    multiLayerToolbar.add(btn_npChangeUndo);
    multiLayerToolbar.add(btn_npChangeRedo);

    this.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            if (e.getComponent().getSize().getHeight() != 0 && e.getComponent().getSize().getWidth() != 0) {
                canvas.zoomAll();
            }
        }
    });

    List<Component> children = SwingUtils.getAllComponents(this);
    for (Component component : children)
        if (component instanceof AbstractButton)
            component.setFocusable(false);

    if (ErrorHandling.isDebugEnabled()) {
        canvas.getCanvasComponent().addMouseMotionListener(new MouseMotionAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                Point point = e.getPoint();
                position.setText("view = " + point + ", NetPlan coord = "
                        + canvas.getCanvasPointFromNetPlanPoint(point));
            }
        });

        position = new JLabel();
        add(position, BorderLayout.SOUTH);
    } else {
        position = null;
    }

    new FileDrop(canvasComponent, new LineBorder(Color.BLACK), new FileDrop.Listener() {
        @Override
        public void filesDropped(File[] files) {
            for (File file : files) {
                try {
                    if (!file.getName().toLowerCase(Locale.getDefault()).endsWith(".n2p"))
                        return;
                    loadDesignFromFile(file);
                    break;
                } catch (Throwable e) {
                    break;
                }
            }
        }
    });

    btn_showNodeNames.setSelected(getVisualizationState().isCanvasShowNodeNames());
    btn_showLinkIds.setSelected(getVisualizationState().isCanvasShowLinkLabels());
    btn_showNonConnectedNodes.setSelected(getVisualizationState().isCanvasShowNonConnectedNodes());

    final ITopologyCanvasPlugin popupPlugin = new PopupMenuPlugin(callback, this.canvas);
    addPlugin(new PanGraphPlugin(callback, canvas, MouseEvent.BUTTON1_MASK));
    if (callback.getVisualizationState().isNetPlanEditable() && getCanvas() instanceof JUNGCanvas)
        addPlugin(new AddLinkGraphPlugin(callback, canvas, MouseEvent.BUTTON1_MASK,
                MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK));
    addPlugin(popupPlugin);
    if (callback.getVisualizationState().isNetPlanEditable())
        addPlugin(new MoveNodePlugin(callback, canvas, MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK));

    setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.BLACK), "Network topology"));
    //        setAllowLoadTrafficDemand(callback.allowLoadTrafficDemands());
}

From source file:net.sf.taverna.t2.activities.spreadsheet.views.SpreadsheetImportConfigView.java

/**
 * Adds a light gray or etched border to the top or bottom of a JComponent.
 *
 * @param component/*from  w  w  w . j a  v a  2s. c o m*/
 */
protected void addDivider(JComponent component, final int position, final boolean etched) {
    component.setBorder(new Border() {
        private final Color borderColor = new Color(.6f, .6f, .6f);

        public Insets getBorderInsets(Component c) {
            if (position == SwingConstants.TOP) {
                return new Insets(5, 0, 0, 0);
            } else {
                return new Insets(0, 0, 5, 0);
            }
        }

        public boolean isBorderOpaque() {
            return false;
        }

        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            if (position == SwingConstants.TOP) {
                if (etched) {
                    g.setColor(borderColor);
                    g.drawLine(x, y, x + width, y);
                    g.setColor(Color.WHITE);
                    g.drawLine(x, y + 1, x + width, y + 1);
                } else {
                    g.setColor(Color.LIGHT_GRAY);
                    g.drawLine(x, y, x + width, y);
                }
            } else {
                if (etched) {
                    g.setColor(borderColor);
                    g.drawLine(x, y + height - 2, x + width, y + height - 2);
                    g.setColor(Color.WHITE);
                    g.drawLine(x, y + height - 1, x + width, y + height - 1);
                } else {
                    g.setColor(Color.LIGHT_GRAY);
                    g.drawLine(x, y + height - 1, x + width, y + height - 1);
                }
            }
        }

    });
}

From source file:com.rapidminer.gui.graphs.GraphViewer.java

public GraphViewer(final GraphCreator<V, E> graphCreator) {
    try {/*from   w w w .  j  ava 2  s .c om*/
        if (!RapidMiner.getExecutionMode().isHeadless()) {
            graphMouse = new DefaultModalGraphMouse(1 / 1.1f, 1.1f);
        }
    } catch (HeadlessException e) {
    }

    this.graphCreator = graphCreator;

    setLayout(new BorderLayout());

    Graph<V, E> graph = graphCreator.createGraph();
    this.layoutSelection = new LayoutSelection<>(this, graph);
    this.layout = new ISOMLayout<>(graph);
    vv = new VisualizationViewer<V, E>(layout) {

        private static final long serialVersionUID = 8247229781249216143L;

        private boolean initialized = false;

        /**
         * Necessary in order to re-change layout after first painting (starting position and
         * size).
         */
        @Override
        public void paint(Graphics g) {
            super.paint(g);
            if (!initialized) {
                initialized = true;
                updateLayout();
                if (objectViewerSplitPane != null) {
                    objectViewerSplitPane.setDividerLocation(0.9);
                }
            }
        }
    };
    vv.setBorder(BorderFactory.createEmptyBorder());
    vv.setBackground(Color.white);

    // === design ===

    // ## edge layout ##
    // EDGE SHAPE
    int edgeShapeType = graphCreator.getEdgeShape();
    switch (edgeShapeType) {
    case GraphCreator.EDGE_SHAPE_LINE:
        vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<V, E>());
        break;
    case GraphCreator.EDGE_SHAPE_QUAD_CURVE:
        vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<V, E>());
        break;
    case GraphCreator.EDGE_SHAPE_CUBIC_CURVE:
        vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.CubicCurve<V, E>());
        break;
    case GraphCreator.EDGE_SHAPE_BENT_LINE:
        vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.BentLine<V, E>());
        break;
    case GraphCreator.EDGE_SHAPE_WEDGE:
        vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Wedge<V, E>(5));
        break;
    default:
        vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<V, E>());
        break;
    }

    // EDGE FONT
    vv.getRenderContext().setEdgeFontTransformer(new Transformer<E, Font>() {

        @Override
        public Font transform(E arg0) {
            return EDGE_FONT;
        }
    });

    // EDGE COLORS
    vv.getRenderContext().setEdgeDrawPaintTransformer(new Transformer<E, Paint>() {

        @Override
        public Paint transform(E edge) {
            double edgeStrength = graphCreator.getEdgeStrength(edge);
            int value = (int) Math.max(140, Math.min(230, 230 - edgeStrength * 90));
            return new Color(value, value, value);
        }
    });
    vv.getRenderContext().setArrowDrawPaintTransformer(new Transformer<E, Paint>() {

        @Override
        public Paint transform(E edge) {
            double edgeStrength = graphCreator.getEdgeStrength(edge);
            int value = (int) Math.max(140, Math.min(230, 230 - edgeStrength * 90));
            return new Color(value, value, value).darker();
        }
    });
    vv.getRenderContext().setArrowFillPaintTransformer(new Transformer<E, Paint>() {

        @Override
        public Paint transform(E edge) {
            double edgeStrength = graphCreator.getEdgeStrength(edge);
            int value = (int) Math.max(140, Math.min(230, 230 - edgeStrength * 90));
            return new Color(value, value, value);
        }
    });

    // EDGE LABEL POSITION
    vv.getRenderContext()
            .setEdgeLabelClosenessTransformer(new ConstantDirectionalEdgeValueTransformer<V, E>(0.5d, 0.5d));
    int labelOffset = graphCreator.getLabelOffset();
    if (labelOffset >= 0) {
        vv.getRenderContext().setLabelOffset(labelOffset);
    }

    // EDGE LABELS
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<E, String>() {

        @Override
        public String transform(E object) {
            return graphCreator.getEdgeName(object);
        }
    });
    // EDGE LABEL RENDERER
    Renderer.EdgeLabel<V, E> edgeLabelRenderer = graphCreator.getEdgeLabelRenderer();
    if (edgeLabelRenderer != null) {
        vv.getRenderer().setEdgeLabelRenderer(edgeLabelRenderer); // renderer...
    }
    vv.getRenderContext().setEdgeLabelRenderer(new EdgeLabelRenderer() { // ...context!

        private JLabel renderer = new JLabel();

        @Override
        public <T> Component getEdgeLabelRendererComponent(JComponent parent, Object value, Font font,
                boolean isSelected, T edge) {
            this.renderer.setFont(font);
            if (graphCreator.isEdgeLabelDecorating()) {
                this.renderer.setOpaque(true);
                renderer.setBackground(Color.WHITE);
                // use this for a more fancy look and feel
                // renderer.setBackground(SwingTools.TRANSPARENT_YELLOW);
                // this.renderer.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(SwingTools.DARK_BLUE),
                // BorderFactory.createEmptyBorder(1,1,1,1)));
            }
            this.renderer.setText(value.toString());
            return this.renderer;
        }

        /** Let the graph model decide. */
        @Override
        public boolean isRotateEdgeLabels() {
            return graphCreator.isRotatingEdgeLabels();
        }

        /** Does nothing. */
        @Override
        public void setRotateEdgeLabels(boolean rotate) {
        }
    });

    // ## vertex layout ##

    // VERTEX FONT
    vv.getRenderContext().setVertexFontTransformer(new Transformer<V, Font>() {

        @Override
        public Font transform(V vertex) {
            if (graphCreator.isBold(vertex)) {
                return VERTEX_BOLD_FONT;
            } else {
                return VERTEX_PLAIN_FONT;
            }
        }
    });
    // VERTEX NAME
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<V, String>() {

        @Override
        public String transform(V object) {
            return graphCreator.getVertexName(object);
        }
    });
    // VERTEX FILL PAINT
    Transformer<V, Paint> paintTransformer = graphCreator.getVertexPaintTransformer(vv);
    if (paintTransformer == null) {
        paintTransformer = new Transformer<V, Paint>() {

            @Override
            public Paint transform(V vertex) {
                if (vv.getPickedVertexState().isPicked(vertex)) {
                    return SwingTools.LIGHT_YELLOW;
                } else {
                    return SwingTools.LIGHT_BLUE;
                }
            }
        };
    }
    vv.getRenderContext().setVertexFillPaintTransformer(paintTransformer);

    // VERTEX DRAW PAINT
    vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<V, Paint>() {

        @Override
        public Paint transform(V vertex) {
            if (vv.getPickedVertexState().isPicked(vertex)) {
                return SwingTools.DARKEST_YELLOW.darker();
            } else {
                return SwingTools.DARKEST_BLUE.darker();
            }
        }
    });
    // VERTEX TOOL TIP
    this.vv.setVertexToolTipTransformer(new Transformer<V, String>() {

        @Override
        public String transform(V vertex) {
            return graphCreator.getVertexToolTip(vertex);
        }
    });
    // VERTEX SHAPE
    vv.getRenderContext().setVertexShapeTransformer(new ExtendedVertexShapeTransformer<>(graphCreator));

    // VERTEX RENDERER
    Renderer.Vertex<V, E> vertexRenderer = graphCreator.getVertexRenderer();
    if (vertexRenderer != null) {
        vv.getRenderer().setVertexRenderer(vertexRenderer);
    }

    // VERTEX LABEL RENDERER
    setDefaultLabelPosition();
    // custom renderer?
    Renderer.VertexLabel<V, E> customVertexLabelRenderer = graphCreator.getVertexLabelRenderer();
    if (customVertexLabelRenderer != null) {
        vv.getRenderer().setVertexLabelRenderer(customVertexLabelRenderer);
    }

    // context
    vv.getRenderContext().setVertexLabelRenderer(new VertexLabelRenderer() {

        private JLabel label = new JLabel();

        @Override
        public <T> Component getVertexLabelRendererComponent(JComponent parent, Object object, Font font,
                boolean isSelection, T vertex) {
            label.setFont(font);
            if (object != null) {
                label.setText(object.toString());
            } else {
                label.setText("");
            }
            return label;
        }

    });

    // === end of design ===

    // === main panel ===

    if (graphCreator.getObjectViewer() == null) {
        add(vv, BorderLayout.CENTER);
    } else {
        JComponent viewer = graphCreator.getObjectViewer().getViewerComponent();
        if (viewer != null) {
            viewer.setBorder(null);
            objectViewerSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
            objectViewerSplitPane.setResizeWeight(1);
            objectViewerSplitPane.add(vv, 0);
            objectViewerSplitPane.add(viewer, 1);
            add(objectViewerSplitPane, BorderLayout.CENTER);
        } else {
            add(vv, BorderLayout.CENTER);
        }
    }

    // === control panel ===

    Component controlPanel = createControlPanel();
    add(new ExtendedJScrollPane(controlPanel), BorderLayout.WEST);

    this.showEdgeLabels = !graphCreator.showEdgeLabelsDefault();
    togglePaintEdgeLabels();
    this.showVertexLabels = !graphCreator.showVertexLabelsDefault();
    togglePaintVertexLabels();

    this.layoutSelection.setLayout();
}