Example usage for javax.swing BorderFactory createTitledBorder

List of usage examples for javax.swing BorderFactory createTitledBorder

Introduction

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

Prototype

public static TitledBorder createTitledBorder(Border border) 

Source Link

Document

Creates a new titled border with an empty title, the specified border object, the default text position (determined by the current look and feel), the default justification (leading), and the default font and text color (determined by the current look and feel).

Usage

From source file:com.adito.upgrade.GUIUpgrader.java

public void upgrade() throws Exception {
    if (JOptionPane.showConfirmDialog(this,
            "All selected resources will be now upgrade from the source installation to the target. Are you sure you wish to continue?",
            "Run Upgrade", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
        ///*from www .  j a va 2s . co  m*/
        final List l = new ArrayList();
        for (int i = 0; i < upgradeSelectionPanel.getComponentCount(); i++) {
            JCheckBox b = (JCheckBox) upgradeSelectionPanel.getComponent(i);
            if (b.isSelected()) {
                l.add(b.getClientProperty("upgrade"));
            }
        }

        removeUpgradeSelectionComponent();
        invalidate();
        removeAll();

        // Progress panel
        JPanel progressPanel = new JPanel(new BorderLayout());
        progressPanel.setBorder(BorderFactory.createTitledBorder("Progress"));
        final JProgressBar b = new JProgressBar(0, l.size());
        b.setStringPainted(true);
        progressPanel.add(b, BorderLayout.CENTER);
        add(progressPanel, BorderLayout.NORTH);

        // Console panel
        JPanel consolePanel = new JPanel(new BorderLayout());
        consolePanel.setBorder(BorderFactory.createTitledBorder("Output"));
        console = new JTextPane();
        JScrollPane scrollPane = new JScrollPane(console);
        consolePanel.add(scrollPane, BorderLayout.CENTER);
        add(consolePanel, BorderLayout.CENTER);

        //

        validate();
        repaint();

        //

        Thread t = new Thread() {
            public void run() {
                try {
                    for (Iterator i = l.iterator(); i.hasNext();) {
                        AbstractDatabaseUpgrade upgrade = (AbstractDatabaseUpgrade) i.next();
                        b.setValue(b.getValue() + 1);
                        upgrade.upgrade(GUIUpgrader.this);
                        try {
                            Thread.sleep(750);
                        } catch (InterruptedException ie) {
                        }
                    }
                    info("Complete");
                    Toolkit.getDefaultToolkit().beep();
                } catch (Exception e) {
                    error("Failed to upgrade.", e);
                }
            }
        };
        t.start();

    }

}

From source file:BasicDnD.java

public JPanel createPanelForComponent(JComponent comp, String title) {
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(comp, BorderLayout.CENTER);
    if (title != null) {
        panel.setBorder(BorderFactory.createTitledBorder(title));
    }// w  ww .  j a va2 s . c  o m
    return panel;
}

From source file:cloud.gui.CloudGUI.java

private void createDiagramPanel(JFreeChart chart) {
    if (null != chart) {
        if (diagramPanel != null)
            requestEnginePanel.remove(diagramPanel);
        diagramPanel = new ChartPanel(chart);
        diagramPanel.setBorder(BorderFactory.createTitledBorder("Diagram"));
        requestEnginePanel.add(diagramPanel);
        requestEnginePanel.revalidate();
    } else {/*from  ww  w  . ja  va2 s.  c  o m*/
        logger.error("chart can not be null");
    }
}

From source file:mazewar.Mazewar.java

/**
 * The place where all the pieces are put together.
 *///from  ww w .  j  a  v  a 2  s .  c  o m
public Mazewar(String zkServer, int zkPort, int port, String name, String game, boolean robot) {
    super("ECE419 Mazewar");
    consolePrintLn("ECE419 Mazewar started!");

    /* Set up parent */
    ZK_PARENT += game;

    // Throw up a dialog to get the GUIClient name.
    if (name != null) {
        clientId = name;
    } else {
        clientId = JOptionPane.showInputDialog("Enter your name");
    }
    if ((clientId == null) || (clientId.length() == 0)) {
        Mazewar.quit();
    }

    /* Connect to ZooKeeper and get sequencer details */
    List<ClientNode> nodeList = null;
    try {
        zkWatcher = new ZkWatcher();
        zkConnected = new CountDownLatch(1);
        zooKeeper = new ZooKeeper(zkServer + ":" + zkPort, ZK_TIMEOUT, new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                /* Release Lock if ZooKeeper is connected */
                if (event.getState() == SyncConnected) {
                    zkConnected.countDown();
                } else {
                    System.err.println("Could not connect to ZooKeeper!");
                    System.exit(0);
                }
            }
        });
        zkConnected.await();

        /* Successfully connected, now create our node on ZooKeeper */
        zooKeeper.create(Joiner.on('/').join(ZK_PARENT, clientId),
                Joiner.on(':').join(InetAddress.getLocalHost().getHostAddress(), port).getBytes(),
                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);

        /* Get Seed from Parent */
        mazeSeed = Long.parseLong(new String(zooKeeper.getData(ZK_PARENT, false, null)));

        /* Initialize Sequence Number */
        sequenceNumber = new AtomicInteger(zooKeeper.exists(ZK_PARENT, false).getVersion());

        /* Get list of nodes */
        nodeList = ClientNode.sortList(zooKeeper.getChildren(ZK_PARENT, false));
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    // Create the maze
    maze = new MazeImpl(new Point(mazeWidth, mazeHeight), mazeSeed);
    assert (maze != null);

    // Have the ScoreTableModel listen to the maze to find
    // out how to adjust scores.
    ScoreTableModel scoreModel = new ScoreTableModel();
    assert (scoreModel != null);
    maze.addMazeListener(scoreModel);

    /* Initialize packet queue */
    packetQueue = new ArrayBlockingQueue<MazePacket>(QUEUE_SIZE);
    sequencedQueue = new PriorityBlockingQueue<MazePacket>(QUEUE_SIZE, new Comparator<MazePacket>() {
        @Override
        public int compare(MazePacket o1, MazePacket o2) {
            return o1.sequenceNumber.compareTo(o2.sequenceNumber);
        }
    });

    /* Inject Event Bus into Client */
    Client.setEventBus(eventBus);

    /* Initialize ZMQ Context */
    context = ZMQ.context(2);

    /* Set up publisher */
    publisher = context.socket(ZMQ.PUB);
    publisher.bind("tcp://*:" + port);
    System.out.println("ZeroMQ Publisher Bound On: " + port);

    try {
        Thread.sleep(100);
    } catch (Exception e) {
        e.printStackTrace();
    }

    /* Set up subscriber */
    subscriber = context.socket(ZMQ.SUB);
    subscriber.subscribe(ArrayUtils.EMPTY_BYTE_ARRAY);

    clients = new ConcurrentHashMap<String, Client>();
    try {
        for (ClientNode client : nodeList) {
            if (client.getName().equals(clientId)) {
                clientPath = ZK_PARENT + "/" + client.getPath();
                guiClient = robot ? new RobotClient(clientId) : new GUIClient(clientId);
                clients.put(clientId, guiClient);
                maze.addClient(guiClient);
                eventBus.register(guiClient);
                subscriber.connect("tcp://" + new String(zooKeeper.getData(clientPath, false, null)));
            } else {
                addRemoteClient(client);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    checkNotNull(guiClient, "Should have received our clientId in CLIENTS list!");

    // Create the GUIClient and connect it to the KeyListener queue
    this.addKeyListener(guiClient);
    this.isRobot = robot;

    // Use braces to force constructors not to be called at the beginning of the
    // constructor.
    /*{
    maze.addClient(new RobotClient("Norby"));
    maze.addClient(new RobotClient("Robbie"));
    maze.addClient(new RobotClient("Clango"));
    maze.addClient(new RobotClient("Marvin"));
    }*/

    // Create the panel that will display the maze.
    overheadPanel = new OverheadMazePanel(maze, guiClient);
    assert (overheadPanel != null);
    maze.addMazeListener(overheadPanel);

    // Don't allow editing the console from the GUI
    console.setEditable(false);
    console.setFocusable(false);
    console.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder()));

    // Allow the console to scroll by putting it in a scrollpane
    JScrollPane consoleScrollPane = new JScrollPane(console);
    assert (consoleScrollPane != null);
    consoleScrollPane
            .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Console"));

    // Create the score table
    scoreTable = new JTable(scoreModel);
    assert (scoreTable != null);
    scoreTable.setFocusable(false);
    scoreTable.setRowSelectionAllowed(false);

    // Allow the score table to scroll too.
    JScrollPane scoreScrollPane = new JScrollPane(scoreTable);
    assert (scoreScrollPane != null);
    scoreScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Scores"));

    // Create the layout manager
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    getContentPane().setLayout(layout);

    // Define the constraints on the components.
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 3.0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    layout.setConstraints(overheadPanel, c);
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.weightx = 2.0;
    c.weighty = 1.0;
    layout.setConstraints(consoleScrollPane, c);
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;
    layout.setConstraints(scoreScrollPane, c);

    // Add the components
    getContentPane().add(overheadPanel);
    getContentPane().add(consoleScrollPane);
    getContentPane().add(scoreScrollPane);

    // Pack everything neatly.
    pack();

    // Let the magic begin.
    setVisible(true);
    overheadPanel.repaint();
    this.requestFocusInWindow();
}

From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java

@Override
protected JPanel createPanel() {

    // add search textfield
    final JPanel inputPanel = new JPanel();
    inputPanel.setBorder(lineBorder(Color.black));
    inputPanel.setLayout(new GridBagLayout());

    inputPanel.add(itemNameFilter.getPanel(), constraints(0, 0).anchorWest().noResizing().end());

    importMarketLogButton.addActionListener(new ActionListener() {

        @Override//from  w w  w . ja  v  a 2 s . c  o  m
        public void actionPerformed(ActionEvent e) {
            importMarketLogs();
        }

    });

    inputPanel.add(importMarketLogButton, constraints(0, 1).anchorWest().noResizing().end());

    // add item description text area
    selectedItemDescription.setEditable(false);
    selectedItemDescription.setWrapStyleWord(true);
    selectedItemDescription.setLineWrap(true);

    final JScrollPane selectedItemDescPanel = new JScrollPane(selectedItemDescription);
    selectedItemDescPanel.setBorder(BorderFactory.createTitledBorder("Selected item"));

    // setup table
    tableModel.setViewFilter(this.itemNameFilter.getViewFilter());
    table.setModel(tableModel);
    table.setRowSorter(tableModel.getRowSorter());
    table.setDefaultRenderer(String.class, new StalePriceInfoHighlighter());
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {

            if (!e.getValueIsAdjusting()) {
                final int viewRow = table.getSelectedRow();
                if (viewRow != -1) {
                    final int modelRow = table.convertRowIndexToModel(viewRow);
                    updateItemDescriptionDisplay(modelRow);
                }
            }
        }

    });

    table.setFillsViewportHeight(true);
    table.addMouseListener(popupListener);

    table.setFillsViewportHeight(true);

    // setup split pane
    final JPanel result = new JPanel();

    final JPanel topPanel = new JPanel();

    new GridLayoutBuilder().add(new GridLayoutBuilder.HorizontalGroup(new GridLayoutBuilder.Cell(inputPanel),
            new GridLayoutBuilder.Cell(selectedItemDescPanel))).addTo(topPanel);

    final JSplitPane pane = new ImprovedSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, tablePane);

    pane.setDividerLocation(0.3d); // only works because of the splitpane
    // hack
    pane.setContinuousLayout(true);

    result.setLayout(new GridBagLayout());
    result.add(pane, constraints().resizeBoth().useRemainingSpace().end());

    return result;
}

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

/**
 * create an instance of a simple graph with controls to
 * demo the zoom features.//from w w  w  .  j  a  va 2s  .  c  o  m
 * 
 */
@Override
public void init() {
    super.init();
    // create a simple graph for the demo
    fetchUserGraph();
    final Collection<? extends Entity<FieldEnum, ConnectionEnum>> vertices = graph.getVertices();

    // a Map for the labels
    Map<Entity<FieldEnum, ConnectionEnum>, String> map = new HashMap<Entity<FieldEnum, ConnectionEnum>, String>();
    Iterator<? extends Entity<FieldEnum, ConnectionEnum>> iterator = vertices.iterator();
    while (iterator.hasNext()) {
        Entity<FieldEnum, ConnectionEnum> entity = iterator.next();
        map.put(entity, entity.getLabel());
    }

    FRLayout<Entity<FieldEnum, ConnectionEnum>, EdgeAdapter<ConnectionEnum>> layout = new FRLayout<Entity<FieldEnum, ConnectionEnum>, EdgeAdapter<ConnectionEnum>>(
            (Graph<Entity<FieldEnum, ConnectionEnum>, EdgeAdapter<ConnectionEnum>>) graph);
    layout.setMaxIterations(100);
    vv = new VisualizationViewer<Entity<FieldEnum, ConnectionEnum>, EdgeAdapter<ConnectionEnum>>(layout,
            new Dimension(2000, 2000));

    Transformer<Entity<FieldEnum, ConnectionEnum>, Paint> vpf = new PickableVertexPaintTransformer<Entity<FieldEnum, ConnectionEnum>>(
            vv.getPickedVertexState(), Color.white, Color.yellow);
    vv.getRenderContext().setVertexFillPaintTransformer(vpf);
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<EdgeAdapter<ConnectionEnum>>(vv.getPickedEdgeState(), Color.black,
                    Color.cyan));

    vv.setBackground(Color.white);

    // a Map for the Icons
    final Map<Entity<FieldEnum, ConnectionEnum>, Icon> iconMap = new HashMap<Entity<FieldEnum, ConnectionEnum>, Icon>();
    new Thread(new Runnable() {
        public void run() {
            Iterator<? extends Entity<FieldEnum, ConnectionEnum>> iterator = vertices.iterator();
            while (iterator.hasNext()) {
                try {
                    Entity<FieldEnum, ConnectionEnum> entity = iterator.next();
                    //                     Icon icon = 
                    //                        new LayeredIcon(new ImageIcon("http://facebookgraph.appspot.com/proxy?url=" + entity.getPicture(PictureType.SQUARE), "Profile Picture").getImage());
                    //                       iconMap.put(entity, icon);

                    Image image = getImageFromEntity(entity);
                    if (image != null && image.getWidth(null) > 0 && image.getHeight(null) > 0) {
                        Icon icon = new LayeredIcon(image);
                        iconMap.put(entity, icon);
                        if ((iconMap.size() % 5) == 0) {
                            vv.repaint();
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            vv.repaint();
        }

    }).start();

    final Transformer<Entity<FieldEnum, ConnectionEnum>, String> vertexStringerImpl = new VertexStringerImpl<Entity<FieldEnum, ConnectionEnum>>(
            map);
    Transformer<EdgeAdapter<ConnectionEnum>, String> edgeStringerImpl = new Transformer<EdgeAdapter<ConnectionEnum>, String>() {
        public String transform(EdgeAdapter<ConnectionEnum> edge) {
            return edge.toString();
        }
    };
    vv.getRenderContext().setEdgeLabelTransformer(edgeStringerImpl);
    vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl);
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));

    // features on and off. For a real application, use VertexIconAndShapeFunction instead.
    final VertexIconShapeTransformer<Entity<FieldEnum, ConnectionEnum>> vertexImageShapeFunction = new VertexIconShapeTransformer<Entity<FieldEnum, ConnectionEnum>>(
            new EllipseVertexShapeTransformer<Entity<FieldEnum, ConnectionEnum>>());

    final DefaultVertexIconTransformer<Entity<FieldEnum, ConnectionEnum>> vertexIconFunction = new DefaultVertexIconTransformer<Entity<FieldEnum, ConnectionEnum>>();

    vertexImageShapeFunction.setIconMap(iconMap);
    vertexIconFunction.setIconMap(iconMap);

    vv.getRenderContext().setVertexShapeTransformer(vertexImageShapeFunction);
    vv.getRenderContext().setVertexIconTransformer(vertexIconFunction);

    // Get the pickedState and add a listener that will decorate the
    // Vertex images with a checkmark icon when they are picked
    PickedState<Entity<FieldEnum, ConnectionEnum>> ps = vv.getPickedVertexState();
    ps.addItemListener(new PickWithIconListener(vertexIconFunction));

    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new Transformer<Entity<FieldEnum, ConnectionEnum>, String>() {
        @Override
        public String transform(Entity<FieldEnum, ConnectionEnum> entity) {
            return entity.getDescription();
        }
    });

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

    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();
    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());
        }
    });

    JComboBox modeBox = graphMouse.getModeComboBox();
    JPanel modePanel = new JPanel();
    modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modePanel.add(modeBox);

    JPanel scaleGrid = new JPanel(new GridLayout(1, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));
    JPanel controls = new JPanel();
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(scaleGrid);

    controls.add(modePanel);
    content.add(controls, BorderLayout.SOUTH);

    this.viewSupport = new MagnifyImageLensSupport<Entity<FieldEnum, ConnectionEnum>, EdgeAdapter<ConnectionEnum>>(
            vv);
    //           new ViewLensSupport<Number,Number>(vv, new HyperbolicShapeTransformer(vv, 
    //              vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), 
    //                new ModalLensGraphMouse());

    this.modelSupport = new LayoutLensSupport<Entity<FieldEnum, ConnectionEnum>, EdgeAdapter<ConnectionEnum>>(
            vv);

    graphMouse.addItemListener(modelSupport.getGraphMouse().getModeListener());
    graphMouse.addItemListener(viewSupport.getGraphMouse().getModeListener());

    ButtonGroup radio = new ButtonGroup();
    JRadioButton none = new JRadioButton("None");
    none.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (viewSupport != null) {
                viewSupport.deactivate();
            }
            if (modelSupport != null) {
                modelSupport.deactivate();
            }
        }
    });
    none.setSelected(true);

    JRadioButton hyperView = new JRadioButton("View");
    hyperView.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            viewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    JRadioButton hyperModel = new JRadioButton("Layout");
    hyperModel.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            modelSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    radio.add(none);
    radio.add(hyperView);
    radio.add(hyperModel);

    JMenuBar menubar = new JMenuBar();
    JMenu modeMenu = graphMouse.getModeMenu();
    menubar.add(modeMenu);

    JPanel lensPanel = new JPanel(new GridLayout(2, 0));
    lensPanel.setBorder(BorderFactory.createTitledBorder("Lens"));
    lensPanel.add(none);
    lensPanel.add(hyperView);
    lensPanel.add(hyperModel);
    controls.add(lensPanel);
}

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

public VertexImageShaperDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseGraph<Number, Number>();
    createGraph(VERTEX_COUNT);/*from   w ww .ja  va 2  s .  c  o  m*/

    // a Map for the labels
    Map<Number, String> map = new HashMap<Number, String>();
    for (int i = 0; i < VERTEX_COUNT; i++) {
        map.put(i, iconNames[i % iconNames.length]);
    }

    // a Map for the Icons
    Map<Number, Icon> iconMap = new HashMap<Number, Icon>();
    for (int i = 0; i < VERTEX_COUNT; i++) {
        String name = "/images/topic" + iconNames[i] + ".gif";
        try {
            Icon icon = new LayeredIcon(
                    new ImageIcon(VertexImageShaperDemo.class.getResource(name)).getImage());
            iconMap.put(i, icon);
        } catch (Exception ex) {
            System.err.println("You need slashdoticons.jar in your classpath to see the image " + name);
        }
    }

    FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph);
    layout.setMaxIterations(100);
    layout.setInitializer(new RandomLocationTransformer<Number>(new Dimension(400, 400), 0));
    vv = new VisualizationViewer<Number, Number>(layout, new Dimension(400, 400));

    // This demo uses a special renderer to turn outlines on and off.
    // you do not need to do this in a real application.
    // Instead, just let vv use the Renderer it already has
    vv.getRenderer().setVertexRenderer(new DemoRenderer<Number, Number>());

    Transformer<Number, Paint> vpf = new PickableVertexPaintTransformer<Number>(vv.getPickedVertexState(),
            Color.white, Color.yellow);
    vv.getRenderContext().setVertexFillPaintTransformer(vpf);
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan));

    vv.setBackground(Color.white);

    final Transformer<Number, String> vertexStringerImpl = new VertexStringerImpl<Number, String>(map);
    vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl);
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));
    //        vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Number,String>() {
    //           URL url = getClass().getResource("/images/lightning-s.gif");
    //         public String transform(Number input) {
    //            
    //            return "<html><img src="+url+" height=10 width=21>"+input.toString();
    //         }});

    // For this demo only, I use a special class that lets me turn various
    // features on and off. For a real application, use VertexIconShapeTransformer instead.
    final DemoVertexIconShapeTransformer<Number> vertexIconShapeTransformer = new DemoVertexIconShapeTransformer<Number>(
            new EllipseVertexShapeTransformer<Number>());

    final DemoVertexIconTransformer<Number> vertexIconTransformer = new DemoVertexIconTransformer<Number>();

    vertexIconShapeTransformer.setIconMap(iconMap);
    vertexIconTransformer.setIconMap(iconMap);

    vv.getRenderContext().setVertexShapeTransformer(vertexIconShapeTransformer);
    vv.getRenderContext().setVertexIconTransformer(vertexIconTransformer);

    // un-comment for RStar Tree visual testing
    //vv.addPostRenderPaintable(new BoundingRectanglePaintable(vv.getRenderContext(), vv.getGraphLayout()));

    // Get the pickedState and add a listener that will decorate the
    // Vertex images with a checkmark icon when they are picked
    PickedState<Number> ps = vv.getPickedVertexState();
    ps.addItemListener(new PickWithIconListener<Number>(vertexIconTransformer));

    vv.addPostRenderPaintable(new VisualizationViewer.Paintable() {
        int x;
        int y;
        Font font;
        FontMetrics metrics;
        int swidth;
        int sheight;
        String str = "Thank You, slashdot.org, for the images!";

        public void paint(Graphics g) {
            Dimension d = vv.getSize();
            if (font == null) {
                font = new Font(g.getFont().getName(), Font.BOLD, 20);
                metrics = g.getFontMetrics(font);
                swidth = metrics.stringWidth(str);
                sheight = metrics.getMaxAscent() + metrics.getMaxDescent();
                x = (d.width - swidth) / 2;
                y = (int) (d.height - sheight * 1.5);
            }
            g.setFont(font);
            Color oldColor = g.getColor();
            g.setColor(Color.lightGray);
            g.drawString(str, x, y);
            g.setColor(oldColor);
        }

        public boolean useTransform() {
            return false;
        }
    });

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

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

    final DefaultModalGraphMouse<Number, Number> graphMouse = new DefaultModalGraphMouse<Number, Number>();
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());
    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());
        }
    });

    JCheckBox shape = new JCheckBox("Shape");
    shape.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            vertexIconShapeTransformer.setShapeImages(e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });
    shape.setSelected(true);

    JCheckBox fill = new JCheckBox("Fill");
    fill.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            vertexIconTransformer.setFillImages(e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });
    fill.setSelected(true);

    JCheckBox drawOutlines = new JCheckBox("Outline");
    drawOutlines.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            vertexIconTransformer.setOutlineImages(e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });

    JComboBox modeBox = graphMouse.getModeComboBox();
    JPanel modePanel = new JPanel();
    modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modePanel.add(modeBox);

    JPanel scaleGrid = new JPanel(new GridLayout(1, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));
    JPanel labelFeatures = new JPanel(new GridLayout(1, 0));
    labelFeatures.setBorder(BorderFactory.createTitledBorder("Image Effects"));
    JPanel controls = new JPanel();
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(scaleGrid);
    labelFeatures.add(shape);
    labelFeatures.add(fill);
    labelFeatures.add(drawOutlines);

    controls.add(labelFeatures);
    controls.add(modePanel);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:demo.VertexImageShaperDemo.java

public VertexImageShaperDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseGraph<Number, Number>();
    createGraph(VERTEX_COUNT);/* ww w  . ja  v  a2s .co  m*/

    // a Map for the labels
    Map<Number, String> map = new HashMap<Number, String>();
    for (int i = 0; i < VERTEX_COUNT; i++) {
        map.put(i, iconNames[i % iconNames.length]);
    }

    // a Map for the Icons
    Map<Number, Icon> iconMap = new HashMap<Number, Icon>();
    for (int i = 0; i < VERTEX_COUNT; i++) {
        String name = "/images/topic" + iconNames[i] + ".gif";
        try {
            Icon icon = new LayeredIcon(
                    new ImageIcon(VertexImageShaperDemo.class.getResource(name)).getImage());
            //iconMap.put(i, icon);
            iconMap.put(i, new ImageIcon("transferir.png"));
        } catch (Exception ex) {
            System.err.println("You need slashdoticons.jar in your classpath to see the image " + name);
        }
    }

    FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph);
    layout.setMaxIterations(100);
    layout.setInitializer(new RandomLocationTransformer<Number>(new Dimension(400, 400), 0));
    vv = new VisualizationViewer<Number, Number>(layout, new Dimension(400, 400));

    // This demo uses a special renderer to turn outlines on and off.
    // you do not need to do this in a real application.
    // Instead, just let vv use the Renderer it already has
    vv.getRenderer().setVertexRenderer(new DemoRenderer<Number, Number>());

    Transformer<Number, Paint> vpf = new PickableVertexPaintTransformer<Number>(vv.getPickedVertexState(),
            Color.white, Color.yellow);
    vv.getRenderContext().setVertexFillPaintTransformer(vpf);
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan));

    vv.setBackground(Color.white);

    final Transformer<Number, String> vertexStringerImpl = new VertexStringerImpl<Number, String>(map);
    vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl);
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));
    //        vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Number,String>() {
    //           URL url = getClass().getResource("/images/lightning-s.gif");
    //         public String transform(Number input) {
    //            
    //            return "<html><img src="+url+" height=10 width=21>"+input.toString();
    //         }});

    // For this demo only, I use a special class that lets me turn various
    // features on and off. For a real application, use VertexIconShapeTransformer instead.
    final DemoVertexIconShapeTransformer<Number> vertexIconShapeTransformer = new DemoVertexIconShapeTransformer<Number>(
            new EllipseVertexShapeTransformer<Number>());

    final DemoVertexIconTransformer<Number> vertexIconTransformer = new DemoVertexIconTransformer<Number>();

    vertexIconShapeTransformer.setIconMap(iconMap);
    vertexIconTransformer.setIconMap(iconMap);

    vv.getRenderContext().setVertexShapeTransformer(vertexIconShapeTransformer);
    vv.getRenderContext().setVertexIconTransformer(vertexIconTransformer);

    // un-comment for RStar Tree visual testing
    //vv.addPostRenderPaintable(new BoundingRectanglePaintable(vv.getRenderContext(), vv.getGraphLayout()));

    // Get the pickedState and add a listener that will decorate the
    // Vertex images with a checkmark icon when they are picked
    PickedState<Number> ps = vv.getPickedVertexState();
    ps.addItemListener(new PickWithIconListener<Number>(vertexIconTransformer));

    vv.addPostRenderPaintable(new VisualizationViewer.Paintable() {
        int x;
        int y;
        Font font;
        FontMetrics metrics;
        int swidth;
        int sheight;
        String str = "Thank You, slashdot.org, for the images!";

        public void paint(Graphics g) {
            Dimension d = vv.getSize();
            if (font == null) {
                font = new Font(g.getFont().getName(), Font.BOLD, 20);
                metrics = g.getFontMetrics(font);
                swidth = metrics.stringWidth(str);
                sheight = metrics.getMaxAscent() + metrics.getMaxDescent();
                x = (d.width - swidth) / 2;
                y = (int) (d.height - sheight * 1.5);
            }
            g.setFont(font);
            Color oldColor = g.getColor();
            g.setColor(Color.lightGray);
            g.drawString(str, x, y);
            g.setColor(oldColor);
        }

        public boolean useTransform() {
            return false;
        }
    });

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

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

    final DefaultModalGraphMouse<Number, Number> graphMouse = new DefaultModalGraphMouse<Number, Number>();
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());
    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());
        }
    });

    JCheckBox shape = new JCheckBox("Shape");
    shape.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            vertexIconShapeTransformer.setShapeImages(e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });
    shape.setSelected(true);

    JCheckBox fill = new JCheckBox("Fill");
    fill.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            vertexIconTransformer.setFillImages(e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });
    fill.setSelected(true);

    JCheckBox drawOutlines = new JCheckBox("Outline");
    drawOutlines.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            vertexIconTransformer.setOutlineImages(e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });

    JComboBox modeBox = graphMouse.getModeComboBox();
    JPanel modePanel = new JPanel();
    modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modePanel.add(modeBox);

    JPanel scaleGrid = new JPanel(new GridLayout(1, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));
    JPanel labelFeatures = new JPanel(new GridLayout(1, 0));
    labelFeatures.setBorder(BorderFactory.createTitledBorder("Image Effects"));
    JPanel controls = new JPanel();
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(scaleGrid);
    labelFeatures.add(shape);
    labelFeatures.add(fill);
    labelFeatures.add(drawOutlines);

    controls.add(labelFeatures);
    controls.add(modePanel);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:cloud.gui.CloudGUI.java

private JPanel createCurrentInstancesPanel() {
    JPanel currentInstancesPanel = new JPanel();
    currentInstancesPanel.setBorder(BorderFactory.createTitledBorder("Current Instances"));
    currentInstancesPanel.setLayout(new BoxLayout(currentInstancesPanel, BoxLayout.Y_AXIS));
    Box layout = Box.createVerticalBox();

    createNumberOfInstancesStatus(layout);
    createTotalCost(layout);/*from   ww  w  . j  a v  a 2  s  .co m*/
    createInstanceTable(layout);

    removeInstanceButton = new JButton("Remove instance");

    layout.add(removeInstanceButton);
    currentInstancesPanel.add(layout);
    return currentInstancesPanel;
}

From source file:davmail.ui.SettingsFrame.java

protected JPanel getDelaysPanel() {
    JPanel delaysPanel = new JPanel(new GridLayout(4, 2));
    delaysPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_DELAYS")));

    keepDelayField = new JTextField(Settings.getProperty("davmail.keepDelay"), 4);
    sentKeepDelayField = new JTextField(Settings.getProperty("davmail.sentKeepDelay"), 4);
    caldavPastDelayField = new JTextField(Settings.getProperty("davmail.caldavPastDelay"), 4);
    imapIdleDelayField = new JTextField(Settings.getProperty("davmail.imapIdleDelay"), 4);

    addSettingComponent(delaysPanel, BundleMessage.format("UI_KEEP_DELAY"), keepDelayField,
            BundleMessage.format("UI_KEEP_DELAY_HELP"));
    addSettingComponent(delaysPanel, BundleMessage.format("UI_SENT_KEEP_DELAY"), sentKeepDelayField,
            BundleMessage.format("UI_SENT_KEEP_DELAY_HELP"));
    addSettingComponent(delaysPanel, BundleMessage.format("UI_CALENDAR_PAST_EVENTS"), caldavPastDelayField,
            BundleMessage.format("UI_CALENDAR_PAST_EVENTS_HELP"));
    addSettingComponent(delaysPanel, BundleMessage.format("UI_IMAP_IDLE_DELAY"), imapIdleDelayField,
            BundleMessage.format("UI_IMAP_IDLE_DELAY_HELP"));
    return delaysPanel;
}