List of usage examples for javax.swing BorderFactory createTitledBorder
public static TitledBorder createTitledBorder(Border border)
From source file:com.neurotec.samples.panels.EnrollFromScanner.java
@Override protected void initGUI() { panelMain = new JPanel(); panelScanners = new JPanel(); scrollPaneList = new JScrollPane(); scannerList = new JList(); panelButtons = new JPanel(); btnRefresh = new JButton(); btnScan = new JButton(); btnCancel = new JButton(); btnForce = new JButton(); cbAutomatic = new JCheckBox(); scrollPane = new JScrollPane(); panelSouth = new JPanel(); panelInfo = new JPanel(); lblInfo = new JLabel(); panelSave = new JPanel(); btnIdentifyPatient = new JButton(); btnRegisterPatient = new JButton(); cbShowProcessed = new JCheckBox(); setLayout(new BorderLayout()); panelMain.setLayout(new BorderLayout()); panelScanners.setBorder(BorderFactory.createTitledBorder("Scanners list")); panelScanners.setLayout(new BorderLayout()); scrollPaneList.setPreferredSize(new Dimension(0, 90)); scannerList.setModel(new DefaultListModel()); scannerList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); scannerList.setBorder(LineBorder.createBlackLineBorder()); scrollPaneList.setViewportView(scannerList); panelScanners.add(scrollPaneList, BorderLayout.CENTER); panelButtons.setLayout(new FlowLayout(FlowLayout.LEADING)); btnRefresh.setText("Refresh list"); panelButtons.add(btnRefresh);//w w w . j av a2s. com btnScan.setText("Scan"); panelButtons.add(btnScan); btnCancel.setText("Cancel"); btnCancel.setEnabled(false); panelButtons.add(btnCancel); btnForce.setText("Force"); panelButtons.add(btnForce); cbAutomatic.setSelected(true); cbAutomatic.setText("Scan automatically"); panelButtons.add(cbAutomatic); panelScanners.add(panelButtons, BorderLayout.SOUTH); panelMain.add(panelScanners, BorderLayout.NORTH); panelMain.add(scrollPane, BorderLayout.CENTER); panelSouth.setLayout(new BorderLayout()); panelInfo.setBorder(new SoftBevelBorder(BevelBorder.LOWERED)); panelInfo.setLayout(new GridLayout(1, 1)); lblInfo.setText(" "); panelInfo.add(lblInfo); panelSouth.add(panelInfo, BorderLayout.NORTH); panelSave.setLayout(new FlowLayout(FlowLayout.LEADING)); btnIdentifyPatient.setText("Identify Patient"); btnIdentifyPatient.setEnabled(false); panelSave.add(btnIdentifyPatient); btnRegisterPatient.setText("Register Patient"); btnRegisterPatient.setEnabled(false); panelSave.add(btnRegisterPatient); cbShowProcessed.setSelected(true); cbShowProcessed.setText("Show processed image"); panelSave.add(cbShowProcessed); panelSouth.add(panelSave, BorderLayout.SOUTH); panelMain.add(panelSouth, BorderLayout.SOUTH); add(panelMain, BorderLayout.CENTER); panelLicensing = new LicensingPanel(requiredLicenses, optionalLicenses); add(panelLicensing, java.awt.BorderLayout.NORTH); fcImage = new JFileChooser(); fcImage.setFileFilter(new Utils.ImageFileFilter(NImages.getSaveFileFilter())); fcTemplate = new JFileChooser(); view = new NFingerView(); view.setShownImage(ShownImage.RESULT); view.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent ev) { super.mouseClicked(ev); if (ev.getButton() == MouseEvent.BUTTON3) { cbShowProcessed.doClick(); } } }); scrollPane.setViewportView(view); btnRefresh.addActionListener(this); btnScan.addActionListener(this); btnCancel.addActionListener(this); btnForce.addActionListener(this); btnIdentifyPatient.addActionListener(this); btnRegisterPatient.addActionListener(this); cbShowProcessed.addActionListener(this); scannerList.addListSelectionListener(new ScannerSelectionListener()); }
From source file:econtroller.gui.ControllerGUI.java
private void createChartPanels() { cpuLoadPanel = new JPanel(); cpuLoadPanel.setLayout(new GridLayout(1, 1)); cpuLoadPanel.setBorder(BorderFactory.createTitledBorder("")); bandwidthPanel = new JPanel(); bandwidthPanel.setLayout(new GridLayout(1, 1)); bandwidthPanel.setBorder(BorderFactory.createTitledBorder("")); responseTimePanel = new JPanel(); responseTimePanel.setLayout(new GridLayout(1, 1)); responseTimePanel.setBorder(BorderFactory.createTitledBorder("")); costPanel = new JPanel(); costPanel.setLayout(new GridLayout(1, 1)); costPanel.setBorder(BorderFactory.createTitledBorder("")); nrInstancePanel = new JPanel(); nrInstancePanel.setLayout(new GridLayout(1, 1)); nrInstancePanel.setBorder(BorderFactory.createTitledBorder("")); throughputPanel = new JPanel(); throughputPanel.setLayout(new GridLayout(1, 1)); throughputPanel.setBorder(BorderFactory.createTitledBorder("")); }
From source file:com.google.code.facebook.graph.sna.applet.VertexCollapseDemo.java
public VertexCollapseDemo() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); collapser = new GraphCollapser(graph); layout = new FRLayout(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize); vv = new VisualizationViewer(visualizationModel, preferredSize); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance(); final Set exclusions = new HashSet(); eif.setPredicate(new Predicate() { public boolean evaluate(Object e) { return exclusions.contains(e); }//from ww w . ja v a 2 s . c om }); vv.getRenderContext().setParallelEdgeIndexFunction(eif); vv.setBackground(Color.white); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller() { /* (non-Javadoc) * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object) */ @Override public String transform(Object v) { if (v instanceof Graph) { return ((Graph) v).getVertices().toString(); } return super.transform(v); } }); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); 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 collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() > 1) { Graph inGraph = layout.getGraph(); Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); Graph g = collapser.collapse(layout.getGraph(), clusterGraph); double sumx = 0; double sumy = 0; for (Object v : picked) { Point2D p = (Point2D) layout.transform(v); sumx += p.getX(); sumy += p.getY(); } Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size()); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); layout.setLocation(clusterGraph, cp); vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton compressEdges = new JButton("Compress Edges"); compressEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.addAll(edges); vv.repaint(); } } }); JButton expandEdges = new JButton("Expand Edges"); expandEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.removeAll(edges); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); for (Object v : picked) { if (v instanceof Graph) { Graph g = collapser.expand(layout.getGraph(), (Graph) v); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton reset = new JButton("Reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { layout.setGraph(graph); exclusions.clear(); vv.repaint(); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((JComponent) e.getSource(), instructions, "Help", JOptionPane.PLAIN_MESSAGE); } }); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); JPanel collapseControls = new JPanel(new GridLayout(3, 1)); collapseControls.setBorder(BorderFactory.createTitledBorder("Picked")); collapseControls.add(collapse); collapseControls.add(expand); collapseControls.add(compressEdges); collapseControls.add(expandEdges); collapseControls.add(reset); controls.add(collapseControls); controls.add(modeBox); controls.add(help); content.add(controls, BorderLayout.SOUTH); }
From source file:demos.MinimumSpanningTreeDemo.java
/** * create an instance of a simple graph in two views with controls to demo * the zoom features.// w ww . jav a 2 s . c om * */ public MinimumSpanningTreeDemo() { // create a simple graph for the demo // both models will share one graph graph = TestGraphs.getDemoGraph(); MinimumSpanningForest2<String, Number> prim = new MinimumSpanningForest2<String, Number>(graph, new DelegateForest<String, Number>(), DelegateTree.<String, Number>getFactory(), new ConstantTransformer(1.0)); tree = prim.getForest(); // create two layouts for the one graph, one layout for each model Layout<String, Number> layout0 = new KKLayout<String, Number>(graph); layout0.setSize(preferredLayoutSize); Layout<String, Number> layout1 = new TreeLayout<String, Number>(tree); Layout<String, Number> layout2 = new StaticLayout<String, Number>(graph, layout1); // create the two models, each with a different layout VisualizationModel<String, Number> vm0 = new DefaultVisualizationModel<String, Number>(layout0, preferredSize); VisualizationModel<String, Number> vm1 = new DefaultVisualizationModel<String, Number>(layout1, preferredSizeRect); VisualizationModel<String, Number> vm2 = new DefaultVisualizationModel<String, Number>(layout2, preferredSizeRect); // create the two views, one for each model // they share the same renderer vv0 = new VisualizationViewer<String, Number>(vm0, preferredSize); vv1 = new VisualizationViewer<String, Number>(vm1, preferredSizeRect); vv2 = new VisualizationViewer<String, Number>(vm2, preferredSizeRect); // vv1.setRenderContext(vv2.getRenderContext()); vv1.getRenderContext().setMultiLayerTransformer(vv0.getRenderContext().getMultiLayerTransformer()); vv2.getRenderContext().setMultiLayerTransformer(vv0.getRenderContext().getMultiLayerTransformer()); vv1.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv0.addChangeListener(vv1); vv1.addChangeListener(vv2); vv0.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv2.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); Color back = Color.decode("0xffffbb"); vv0.setBackground(back); vv1.setBackground(back); vv2.setBackground(back); vv0.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv0.setForeground(Color.darkGray); vv1.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv1.setForeground(Color.darkGray); vv2.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv2.setForeground(Color.darkGray); // share one PickedState between the two views PickedState<String> ps = new MultiPickedState<String>(); vv0.setPickedVertexState(ps); vv1.setPickedVertexState(ps); vv2.setPickedVertexState(ps); PickedState<Number> pes = new MultiPickedState<Number>(); vv0.setPickedEdgeState(pes); vv1.setPickedEdgeState(pes); vv2.setPickedEdgeState(pes); // set an edge paint function that will show picking for edges vv0.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv0.getPickedEdgeState(), Color.black, Color.red)); vv0.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(vv0.getPickedVertexState(), Color.red, Color.yellow)); vv1.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv1.getPickedEdgeState(), Color.black, Color.red)); vv1.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(vv1.getPickedVertexState(), Color.red, Color.yellow)); // add default listeners for ToolTips vv0.setVertexToolTipTransformer(new ToStringLabeller()); vv1.setVertexToolTipTransformer(new ToStringLabeller()); vv2.setVertexToolTipTransformer(new ToStringLabeller()); vv0.setLayout(new BorderLayout()); vv1.setLayout(new BorderLayout()); vv2.setLayout(new BorderLayout()); Font font = vv0.getFont().deriveFont(Font.BOLD, 16); JLabel vv0Label = new JLabel("<html>Original Graph<p>using KKLayout"); vv0Label.setFont(font); JLabel vv1Label = new JLabel("Minimum Spanning Trees"); vv1Label.setFont(font); JLabel vv2Label = new JLabel("Original Graph using TreeLayout"); vv2Label.setFont(font); JPanel flow0 = new JPanel(); flow0.setOpaque(false); JPanel flow1 = new JPanel(); flow1.setOpaque(false); JPanel flow2 = new JPanel(); flow2.setOpaque(false); flow0.add(vv0Label); flow1.add(vv1Label); flow2.add(vv2Label); vv0.add(flow0, BorderLayout.NORTH); vv1.add(flow1, BorderLayout.NORTH); vv2.add(flow2, BorderLayout.NORTH); // vv2.getRenderContext().setEdgeDrawPaintTransformer(new // Transformer<Number,Paint>() { // // public Paint transform(Number e) { // if(tree.getEdges().contains(e) == false) return Color.lightGray; // return Color.black; // }}); Container content = getContentPane(); JPanel grid = new JPanel(new GridLayout(0, 1)); JPanel panel = new JPanel(new BorderLayout()); panel.add(new GraphZoomScrollPane(vv0), BorderLayout.WEST); grid.add(new GraphZoomScrollPane(vv1)); grid.add(new GraphZoomScrollPane(vv2)); // panel.add(new GraphZoomScrollPane(vv3), BorderLayout.EAST); panel.add(grid); content.add(panel); // create a GraphMouse for each view DefaultModalGraphMouse gm0 = new DefaultModalGraphMouse(); DefaultModalGraphMouse gm1 = new DefaultModalGraphMouse(); DefaultModalGraphMouse gm2 = new DefaultModalGraphMouse(); DefaultModalGraphMouse gm3 = new DefaultModalGraphMouse(); vv0.setGraphMouse(gm0); vv1.setGraphMouse(gm1); vv2.setGraphMouse(gm2); // vv3.setGraphMouse(gm3); // create zoom buttons for scaling the transformer that is // shared between the two models. final ScalingControl scaler = new CrossoverScalingControl(); vv0.scaleToLayout(scaler); vv1.scaleToLayout(scaler); vv2.scaleToLayout(scaler); // vv3.scaleToLayout(scaler); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv1, 1.1f, vv1.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv1, 1 / 1.1f, vv1.getCenter()); } }); JPanel zoomPanel = new JPanel(new GridLayout(1, 2)); zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel modePanel = new JPanel(); modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); gm1.getModeComboBox().addItemListener(gm2.getModeListener()); gm1.getModeComboBox().addItemListener(gm0.getModeListener()); gm1.getModeComboBox().addItemListener(gm3.getModeListener()); modePanel.add(gm1.getModeComboBox()); JPanel controls = new JPanel(); zoomPanel.add(plus); zoomPanel.add(minus); controls.add(zoomPanel); controls.add(modePanel); content.add(controls, BorderLayout.SOUTH); }
From source file:edu.ku.brc.af.ui.forms.formatters.UIFormatterEditorDlg.java
@Override public void createUI() { super.createUI(); CellConstraints cc = new CellConstraints(); orderUpBtn = createIconBtn("ReorderUp", "TCGD_MOVE_UP", new ActionListener() { public void actionPerformed(ActionEvent ae) { int inx = fieldsTbl.getSelectedRow(); UIFieldFormatterField item = (UIFieldFormatterField) fields.get(inx); fields.remove(inx);//from w w w .j ava 2 s . co m fields.insertElementAt(item, inx - 1); fieldsTbl.getSelectionModel().setSelectionInterval(inx - 1, inx - 1); selectedFormat.resetLength(); updateEnabledState(); updateUIEnabled(); } }); orderDwnBtn = createIconBtn("ReorderDown", "TCGD_MOVE_DOWN", new ActionListener() { public void actionPerformed(ActionEvent ae) { int inx = fieldsTbl.getSelectedRow(); UIFieldFormatterField item = (UIFieldFormatterField) fields.get(inx); fields.remove(inx); fields.insertElementAt(item, inx + 1); fieldsTbl.getSelectionModel().setSelectionInterval(inx + 1, inx + 1); selectedFormat.resetLength(); updateEnabledState(); updateUIEnabled(); } }); // get formatters for field List<UIFieldFormatterIFace> fmtrs = new Vector<UIFieldFormatterIFace>(uiFieldFormatterMgrCache .getFormatterList(fieldInfo.getTableInfo().getClassObj(), fieldInfo.getName())); Collections.sort(fmtrs, new Comparator<UIFieldFormatterIFace>() { public int compare(UIFieldFormatterIFace o1, UIFieldFormatterIFace o2) { return o1.toPattern().compareTo(o2.toPattern()); } }); // table and field titles PanelBuilder tblInfoPB = new PanelBuilder( new FormLayout("r:p,2px,f:p:g", "p,2px,p,2px,p,10px")/*, new FormDebugPanel()*/); String typeStr = fieldInfo.getType(); typeStr = typeStr.indexOf('.') > -1 ? StringUtils.substringAfterLast(fieldInfo.getType(), ".") : typeStr; JLabel tableTitleLbl = createI18NFormLabel("FFE_TABLE"); JLabel tableTitleValueLbl = createLabel(fieldInfo.getTableInfo().getTitle()); tableTitleValueLbl.setBackground(Color.WHITE); tableTitleValueLbl.setOpaque(true); JLabel fieldTitleLbl = createI18NFormLabel("FFE_FIELD"); JLabel fieldTitleValueLbl = createLabel(fieldInfo.getTitle()); fieldTitleValueLbl.setBackground(Color.WHITE); fieldTitleValueLbl.setOpaque(true); JLabel fieldLengthLbl = createI18NFormLabel("FFE_LENGTH"); JLabel fieldLengthValueLbl = createLabel(Integer.toString(fieldInfo.getLength())); fieldLengthValueLbl.setBackground(Color.WHITE); fieldLengthValueLbl.setOpaque(true); int y = 1; tblInfoPB.add(tableTitleLbl, cc.xy(1, y)); tblInfoPB.add(tableTitleValueLbl, cc.xy(3, y)); y += 2; tblInfoPB.add(fieldTitleLbl, cc.xy(1, y)); tblInfoPB.add(fieldTitleValueLbl, cc.xy(3, y)); y += 2; tblInfoPB.add(fieldLengthLbl, cc.xy(1, y)); tblInfoPB.add(fieldLengthValueLbl, cc.xy(3, y)); y += 2; // sample panel sampleLabel = createLabel("", SwingConstants.LEFT); JPanel samplePanel = new JPanel(); samplePanel.setBorder(BorderFactory.createTitledBorder(getResourceString("FFE_SAMPLE"))); //$NON-NLS-1$ samplePanel.add(sampleLabel); // name text field nameTF = createTextField(20); // title text field titleTF = createTextField(20); byYearCB = createCheckBox(getResourceString("FFE_BY_YEAR_CHECKBOX")); //$NON-NLS-1$ hookByYearCheckBoxListener(); fieldsPanel = new EditDeleteAddPanel(getSaveAL(), getDelAL(), getAddAL()); fieldsTbl = new JTable(fieldsModel = new FieldsTableModel()); fieldTypeCbx = new JComboBox(FieldType.values()); // I18N fieldTxt = createTextField(20); fieldsPanel.getAddBtn().setEnabled(true); fieldsPanel.getEditBtn().setIcon(IconManager.getIcon("Green Arrow Up", IconManager.IconSize.Std16)); UIHelper.makeTableHeadersCentered(fieldsTbl, true); fieldTxt.setDocument(new FieldDocument()); fieldsTbl.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); int width = fieldTypeCbx.getPreferredSize().width; y = 1; PanelBuilder subPB = new PanelBuilder(new FormLayout("r:p,2px,p", "p,4px, p,4px, p,4px, p,4px")); subPB.add(createI18NFormLabel("FFE_NAME"), cc.xy(1, y)); subPB.add(nameTF, cc.xy(3, y)); y += 2; subPB.add(createI18NFormLabel("FFE_TITLE"), cc.xy(1, y)); subPB.add(titleTF, cc.xy(3, y)); y += 2; subPB.add(byYearCB, cc.xy(3, y)); y += 2; // CardLayout for Editor Panels SpinnerModel retModel = new SpinnerNumberModel(1, //initial value 1, //min fieldInfo.getLength(), //max 1); //step sizeSpinner = new JSpinner(retModel); isIncChk = new JCheckBox("Is Incrementer"); // I18N String colDefs = "f:p:g,p,2px," + width + "px,2px,p"; closeBtn = createClose(0); PanelBuilder numPB = new PanelBuilder(new FormLayout(colDefs, "p,2px,p,2px,p")); numPB.add(createI18NFormLabel("FFE_LENGTH"), cc.xy(2, 1)); numPB.add(sizeSpinner, cc.xy(4, 1)); //numPB.add(closeBtn, cc.xy(6, 1)); numPB.add(isIncChk, cc.xy(4, 3)); sepCbx = new JComboBox(new String[] { "-", ".", "/", "(space)", "_" }); closeBtn = createClose(1); PanelBuilder sepPB = new PanelBuilder(new FormLayout(colDefs, "p,2px,p")); sepPB.add(createI18NFormLabel("FFE_SEP"), cc.xy(2, 1)); sepPB.add(sepCbx, cc.xy(4, 1)); //sepPB.add(closeBtn, cc.xy(6, 1)); closeBtn = createClose(2); PanelBuilder txtPB = new PanelBuilder(new FormLayout(colDefs, "p,2px,p")); txtPB.add(createI18NFormLabel("FFE_TEXT"), cc.xy(2, 1)); txtPB.add(fieldTxt, cc.xy(4, 1)); cardPanel = new JPanel(cardLayout); cardPanel.add("size", numPB.getPanel()); cardPanel.add("text", txtPB.getPanel()); cardPanel.add("sep", sepPB.getPanel()); cardPanel.add("none", new JLabel(" ")); y = 1; PanelBuilder leftPB = new PanelBuilder(new FormLayout("f:p:g", "t:p,10px,p,f:p:g")); leftPB.add(tblInfoPB.getPanel(), cc.xy(1, y)); y += 2; leftPB.add(subPB.getPanel(), cc.xy(1, y)); y += 2; PanelBuilder upDownPanel = new PanelBuilder(new FormLayout("p", "f:p:g, p, 2px, p, f:p:g")); upDownPanel.add(orderUpBtn, cc.xy(1, 2)); upDownPanel.add(orderDwnBtn, cc.xy(1, 4)); totLenLbl = createLabel("XXXXX"); y = 1; PanelBuilder rightPB = new PanelBuilder(new FormLayout("p:g,2px,p,2px,p", "200px,2px,p,2px,p,2px,p")); rightPB.add(createScrollPane(fieldsTbl), cc.xywh(1, y, 3, 1)); rightPB.add(upDownPanel.getPanel(), cc.xywh(5, y, 1, 1)); y += 2; rightPB.add(totLenLbl, cc.xy(1, y)); rightPB.add(fieldsPanel, cc.xywh(3, y, 1, 1)); y += 2; rightPB.add(fieldTypeLbl = createI18NFormLabel("FFE_TYPE"), cc.xy(1, y)); rightPB.add(fieldTypeCbx, cc.xy(3, y)); rightPB.add(closeBtn, cc.xy(5, y)); y += 2; rightPB.add(cardPanel, cc.xyw(1, y, 3)); y += 2; y = 1; PanelBuilder pb = new PanelBuilder(new FormLayout("p:g,10px,p,10px,p:g,10px,p", "f:p:g,10px,p")); Color bg = getBackground(); pb.add(new VerticalSeparator(bg.darker(), bg.brighter()), cc.xywh(3, 1, 1, 1)); pb.add(leftPB.getPanel(), cc.xy(1, y)); pb.add(rightPB.getPanel(), cc.xy(5, y)); //pb.add(keyPanel, cc.xy(7, y)); y += 2; pb.add(samplePanel, cc.xyw(1, y, 7)); y += 2; setByYearSelected(selectedFormat); nameTF.setEditable(isNew); nameTF.setText(selectedFormat.getName()); titleTF.setText(selectedFormat.getTitle()); updateSample(); hookTextChangeListener(nameTF, "FFE_NO_NAME", 32); hookTextChangeListener(titleTF, "FFE_NO_TITLE", 32); pb.setDefaultDialogBorder(); contentPanel = pb.getPanel(); mainPanel.add(contentPanel, BorderLayout.CENTER); updateUIEnabled(); pack(); enabledEditorUI(false); hookFieldsTblSelectionListener(); fieldTypeCbx.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { typeChanged(); } }); sepCbx.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { fieldHasChanged = true; updateEnabledState(); hasChanged = true; updateUIEnabled(); } }); fieldTxt.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { fieldHasChanged = true; updateEnabledState(); hasChanged = true; updateUIEnabled(); } }); sizeSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { fieldHasChanged = true; updateEnabledState(); hasChanged = true; updateUIEnabled(); } }); isIncChk.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fieldHasChanged = true; if (!isIncChk.isSelected()) { byYearCB.setSelected(false); } updateEntry(); updateUIEnabled(); updateEnabledState(); fieldsTbl.repaint(); } }); fieldTypeCbx.setSelectedIndex(-1); fieldHasChanged = false; updateEnabledState(); }
From source file:gui.WikiCorpusClusteringView.java
/** * * @param br// www.j a v a 2 s . c o m * @throws IOException */ private void setUpView(Graph graph) throws IOException { //Create a simple layout frame //specify the Fruchterman-Rheingold layout algorithm // final AggregateLayout<Number, Number> layout = // new AggregateLayout<Number, Number>(new FRLayout<Number, Number>(graph)); //layout = new TreeLayout<String,Integer>(graph); Layout<Number, Number> layout = new KKLayout<Number, Number>(graph); layout.setSize(new Dimension(900, 900)); vv = new VisualizationViewer<Number, Number>(layout); vv.setBackground(Color.white); //Tell the renderer to use our own customized color rendering vv.getRenderContext() .setVertexFillPaintTransformer(MapTransformer.<Number, Paint>getInstance(vertexPaints)); vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<Number, Paint>() { public Paint transform(Number v) { if (vv.getPickedVertexState().isPicked(v)) { return Color.cyan; } else { return Color.BLACK; } } }); vv.getRenderContext().setEdgeDrawPaintTransformer(MapTransformer.<Number, Paint>getInstance(edgePaints)); vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Number, Stroke>() { protected final Stroke THIN = new BasicStroke(1); protected final Stroke THICK = new BasicStroke(2); public Stroke transform(Number e) { Paint c = edgePaints.get(e); if (c == Color.LIGHT_GRAY) { return THIN; } else { return THICK; } } }); //add restart button JButton scramble = new JButton("Restart"); scramble.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Layout layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if (relaxer != null) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); DefaultModalGraphMouse gm = new DefaultModalGraphMouse(); vv.setGraphMouse(gm); final JToggleButton groupVertices = new JToggleButton("Group Clusters"); //Create slider to adjust the number of edges to remove when clustering final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL); edgeBetweennessSlider.setBackground(Color.WHITE); edgeBetweennessSlider.setPreferredSize(new Dimension(210, 50)); edgeBetweennessSlider.setPaintTicks(true); edgeBetweennessSlider.setMaximum(graph.getEdgeCount()); edgeBetweennessSlider.setMinimum(0); edgeBetweennessSlider.setValue(0); edgeBetweennessSlider.setMajorTickSpacing(10); edgeBetweennessSlider.setPaintLabels(true); edgeBetweennessSlider.setPaintTicks(true); // edgeBetweennessSlider.setBorder(BorderFactory.createLineBorder(Color.black)); //TO DO: edgeBetweennessSlider.add(new JLabel("Node Size (PageRank With Priors):")); //I also want the slider value to appear final JPanel eastControls = new JPanel(); eastControls.setOpaque(true); eastControls.setLayout(new BoxLayout(eastControls, BoxLayout.Y_AXIS)); eastControls.add(Box.createVerticalGlue()); eastControls.add(edgeBetweennessSlider); final String COMMANDSTRING = "Edges removed for clusters: "; final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue(); final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize); eastControls.setBorder(sliderBorder); //eastControls.add(eastSize); eastControls.add(Box.createVerticalGlue()); groupVertices.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { //clusterAndRecolor(layout, edgeBetweennessSlider.getValue(), // similarColors, e.getStateChange() == ItemEvent.SELECTED); vv.repaint(); } }); //clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected()); edgeBetweennessSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (!source.getValueIsAdjusting()) { int numEdgesToRemove = source.getValue(); //clusterAndRecolor(layout, numEdgesToRemove, similarColors, // groupVertices.isSelected()); sliderBorder.setTitle(COMMANDSTRING + edgeBetweennessSlider.getValue()); eastControls.repaint(); vv.validate(); vv.repaint(); } } }); Container content = getContentPane(); content.add(new GraphZoomScrollPane(vv)); JPanel south = new JPanel(); JPanel grid = new JPanel(new GridLayout(2, 1)); grid.add(scramble); grid.add(groupVertices); south.add(grid); south.add(eastControls); JPanel p = new JPanel(); p.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); p.add(gm.getModeComboBox()); south.add(p); content.add(south, BorderLayout.SOUTH); }
From source file:com.google.code.facebook.graph.sna.applet.MinimumSpanningTreeDemo.java
/** * create an instance of a simple graph in two views with controls to * demo the zoom features.//from ww w . j av a 2s.co m * */ public MinimumSpanningTreeDemo() { // create a simple graph for the demo // both models will share one graph graph = TestGraphs.getDemoGraph(); MinimumSpanningForest2<String, Number> prim = new MinimumSpanningForest2<String, Number>(graph, new DelegateForest<String, Number>(), DelegateTree.<String, Number>getFactory(), new ConstantTransformer(1.0)); tree = prim.getForest(); // create two layouts for the one graph, one layout for each model Layout<String, Number> layout0 = new KKLayout<String, Number>(graph); layout0.setSize(preferredLayoutSize); Layout<String, Number> layout1 = new TreeLayout<String, Number>(tree); Layout<String, Number> layout2 = new StaticLayout<String, Number>(graph, layout1); // create the two models, each with a different layout VisualizationModel<String, Number> vm0 = new DefaultVisualizationModel<String, Number>(layout0, preferredSize); VisualizationModel<String, Number> vm1 = new DefaultVisualizationModel<String, Number>(layout1, preferredSizeRect); VisualizationModel<String, Number> vm2 = new DefaultVisualizationModel<String, Number>(layout2, preferredSizeRect); // create the two views, one for each model // they share the same renderer vv0 = new VisualizationViewer<String, Number>(vm0, preferredSize); vv1 = new VisualizationViewer<String, Number>(vm1, preferredSizeRect); vv2 = new VisualizationViewer<String, Number>(vm2, preferredSizeRect); // vv1.setRenderContext(vv2.getRenderContext()); vv1.getRenderContext().setMultiLayerTransformer(vv0.getRenderContext().getMultiLayerTransformer()); vv2.getRenderContext().setMultiLayerTransformer(vv0.getRenderContext().getMultiLayerTransformer()); vv1.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv0.addChangeListener(vv1); vv1.addChangeListener(vv2); vv0.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv2.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); Color back = Color.decode("0xffffbb"); vv0.setBackground(back); vv1.setBackground(back); vv2.setBackground(back); vv0.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv0.setForeground(Color.darkGray); vv1.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv1.setForeground(Color.darkGray); vv2.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv2.setForeground(Color.darkGray); // share one PickedState between the two views PickedState<String> ps = new MultiPickedState<String>(); vv0.setPickedVertexState(ps); vv1.setPickedVertexState(ps); vv2.setPickedVertexState(ps); PickedState<Number> pes = new MultiPickedState<Number>(); vv0.setPickedEdgeState(pes); vv1.setPickedEdgeState(pes); vv2.setPickedEdgeState(pes); // set an edge paint function that will show picking for edges vv0.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv0.getPickedEdgeState(), Color.black, Color.red)); vv0.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(vv0.getPickedVertexState(), Color.red, Color.yellow)); vv1.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv1.getPickedEdgeState(), Color.black, Color.red)); vv1.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(vv1.getPickedVertexState(), Color.red, Color.yellow)); // add default listeners for ToolTips vv0.setVertexToolTipTransformer(new ToStringLabeller()); vv1.setVertexToolTipTransformer(new ToStringLabeller()); vv2.setVertexToolTipTransformer(new ToStringLabeller()); vv0.setLayout(new BorderLayout()); vv1.setLayout(new BorderLayout()); vv2.setLayout(new BorderLayout()); Font font = vv0.getFont().deriveFont(Font.BOLD, 16); JLabel vv0Label = new JLabel("<html>Original Graph<p>using KKLayout"); vv0Label.setFont(font); JLabel vv1Label = new JLabel("Minimum Spanning Trees"); vv1Label.setFont(font); JLabel vv2Label = new JLabel("Original Graph using TreeLayout"); vv2Label.setFont(font); JPanel flow0 = new JPanel(); flow0.setOpaque(false); JPanel flow1 = new JPanel(); flow1.setOpaque(false); JPanel flow2 = new JPanel(); flow2.setOpaque(false); flow0.add(vv0Label); flow1.add(vv1Label); flow2.add(vv2Label); vv0.add(flow0, BorderLayout.NORTH); vv1.add(flow1, BorderLayout.NORTH); vv2.add(flow2, BorderLayout.NORTH); // vv2.getRenderContext().setEdgeDrawPaintTransformer(new Transformer<Number,Paint>() { // // public Paint transform(Number e) { // if(tree.getEdges().contains(e) == false) return Color.lightGray; // return Color.black; // }}); Container content = getContentPane(); JPanel grid = new JPanel(new GridLayout(0, 1)); JPanel panel = new JPanel(new BorderLayout()); panel.add(new GraphZoomScrollPane(vv0), BorderLayout.WEST); grid.add(new GraphZoomScrollPane(vv1)); grid.add(new GraphZoomScrollPane(vv2)); // panel.add(new GraphZoomScrollPane(vv3), BorderLayout.EAST); panel.add(grid); content.add(panel); // create a GraphMouse for each view DefaultModalGraphMouse gm0 = new DefaultModalGraphMouse(); DefaultModalGraphMouse gm1 = new DefaultModalGraphMouse(); DefaultModalGraphMouse gm2 = new DefaultModalGraphMouse(); DefaultModalGraphMouse gm3 = new DefaultModalGraphMouse(); vv0.setGraphMouse(gm0); vv1.setGraphMouse(gm1); vv2.setGraphMouse(gm2); // vv3.setGraphMouse(gm3); // create zoom buttons for scaling the transformer that is // shared between the two models. final ScalingControl scaler = new CrossoverScalingControl(); vv0.scaleToLayout(scaler); vv1.scaleToLayout(scaler); vv2.scaleToLayout(scaler); // vv3.scaleToLayout(scaler); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv1, 1.1f, vv1.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv1, 1 / 1.1f, vv1.getCenter()); } }); JPanel zoomPanel = new JPanel(new GridLayout(1, 2)); zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel modePanel = new JPanel(); modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); gm1.getModeComboBox().addItemListener(gm2.getModeListener()); gm1.getModeComboBox().addItemListener(gm0.getModeListener()); gm1.getModeComboBox().addItemListener(gm3.getModeListener()); modePanel.add(gm1.getModeComboBox()); JPanel controls = new JPanel(); zoomPanel.add(plus); zoomPanel.add(minus); controls.add(zoomPanel); controls.add(modePanel); content.add(controls, BorderLayout.SOUTH); }
From source file:edu.uci.ics.jung.samples.MinimumSpanningTreeDemo.java
/** * create an instance of a simple graph in two views with controls to * demo the zoom features./* ww w .j a v a2 s . c o m*/ * */ @SuppressWarnings({ "unchecked", "rawtypes" }) public MinimumSpanningTreeDemo() { // create a simple graph for the demo // both models will share one graph graph = TestGraphs.getDemoGraph(); MinimumSpanningForest2<String, Number> prim = new MinimumSpanningForest2<String, Number>(graph, new DelegateForest<String, Number>(), DelegateTree.<String, Number>getFactory(), new ConstantTransformer(1.0)); tree = prim.getForest(); // create two layouts for the one graph, one layout for each model Layout<String, Number> layout0 = new KKLayout<String, Number>(graph); layout0.setSize(preferredLayoutSize); Layout<String, Number> layout1 = new TreeLayout<String, Number>(tree); Layout<String, Number> layout2 = new StaticLayout<String, Number>(graph, layout1); // create the two models, each with a different layout VisualizationModel<String, Number> vm0 = new DefaultVisualizationModel<String, Number>(layout0, preferredSize); VisualizationModel<String, Number> vm1 = new DefaultVisualizationModel<String, Number>(layout1, preferredSizeRect); VisualizationModel<String, Number> vm2 = new DefaultVisualizationModel<String, Number>(layout2, preferredSizeRect); // create the two views, one for each model // they share the same renderer vv0 = new VisualizationViewer<String, Number>(vm0, preferredSize); vv1 = new VisualizationViewer<String, Number>(vm1, preferredSizeRect); vv2 = new VisualizationViewer<String, Number>(vm2, preferredSizeRect); // vv1.setRenderContext(vv2.getRenderContext()); vv1.getRenderContext().setMultiLayerTransformer(vv0.getRenderContext().getMultiLayerTransformer()); vv2.getRenderContext().setMultiLayerTransformer(vv0.getRenderContext().getMultiLayerTransformer()); vv1.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv0.addChangeListener(vv1); vv1.addChangeListener(vv2); vv0.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv2.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); Color back = Color.decode("0xffffbb"); vv0.setBackground(back); vv1.setBackground(back); vv2.setBackground(back); vv0.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv0.setForeground(Color.darkGray); vv1.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv1.setForeground(Color.darkGray); vv2.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv2.setForeground(Color.darkGray); // share one PickedState between the two views PickedState<String> ps = new MultiPickedState<String>(); vv0.setPickedVertexState(ps); vv1.setPickedVertexState(ps); vv2.setPickedVertexState(ps); PickedState<Number> pes = new MultiPickedState<Number>(); vv0.setPickedEdgeState(pes); vv1.setPickedEdgeState(pes); vv2.setPickedEdgeState(pes); // set an edge paint function that will show picking for edges vv0.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv0.getPickedEdgeState(), Color.black, Color.red)); vv0.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(vv0.getPickedVertexState(), Color.red, Color.yellow)); vv1.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv1.getPickedEdgeState(), Color.black, Color.red)); vv1.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(vv1.getPickedVertexState(), Color.red, Color.yellow)); // add default listeners for ToolTips vv0.setVertexToolTipTransformer(new ToStringLabeller()); vv1.setVertexToolTipTransformer(new ToStringLabeller()); vv2.setVertexToolTipTransformer(new ToStringLabeller()); vv0.setLayout(new BorderLayout()); vv1.setLayout(new BorderLayout()); vv2.setLayout(new BorderLayout()); Font font = vv0.getFont().deriveFont(Font.BOLD, 16); JLabel vv0Label = new JLabel("<html>Original Graph<p>using KKLayout"); vv0Label.setFont(font); JLabel vv1Label = new JLabel("Minimum Spanning Trees"); vv1Label.setFont(font); JLabel vv2Label = new JLabel("Original Graph using TreeLayout"); vv2Label.setFont(font); JPanel flow0 = new JPanel(); flow0.setOpaque(false); JPanel flow1 = new JPanel(); flow1.setOpaque(false); JPanel flow2 = new JPanel(); flow2.setOpaque(false); flow0.add(vv0Label); flow1.add(vv1Label); flow2.add(vv2Label); vv0.add(flow0, BorderLayout.NORTH); vv1.add(flow1, BorderLayout.NORTH); vv2.add(flow2, BorderLayout.NORTH); // vv2.getRenderContext().setEdgeDrawPaintTransformer(new Transformer<Number,Paint>() { // // public Paint transform(Number e) { // if(tree.getEdges().contains(e) == false) return Color.lightGray; // return Color.black; // }}); Container content = getContentPane(); JPanel grid = new JPanel(new GridLayout(0, 1)); JPanel panel = new JPanel(new BorderLayout()); panel.add(new GraphZoomScrollPane(vv0), BorderLayout.WEST); grid.add(new GraphZoomScrollPane(vv1)); grid.add(new GraphZoomScrollPane(vv2)); // panel.add(new GraphZoomScrollPane(vv3), BorderLayout.EAST); panel.add(grid); content.add(panel); // create a GraphMouse for each view DefaultModalGraphMouse gm0 = new DefaultModalGraphMouse(); DefaultModalGraphMouse gm1 = new DefaultModalGraphMouse(); DefaultModalGraphMouse gm2 = new DefaultModalGraphMouse(); DefaultModalGraphMouse gm3 = new DefaultModalGraphMouse(); vv0.setGraphMouse(gm0); vv1.setGraphMouse(gm1); vv2.setGraphMouse(gm2); // vv3.setGraphMouse(gm3); // create zoom buttons for scaling the transformer that is // shared between the two models. final ScalingControl scaler = new CrossoverScalingControl(); vv0.scaleToLayout(scaler); vv1.scaleToLayout(scaler); vv2.scaleToLayout(scaler); // vv3.scaleToLayout(scaler); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv1, 1.1f, vv1.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv1, 1 / 1.1f, vv1.getCenter()); } }); JPanel zoomPanel = new JPanel(new GridLayout(1, 2)); zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel modePanel = new JPanel(); modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); gm1.getModeComboBox().addItemListener(gm2.getModeListener()); gm1.getModeComboBox().addItemListener(gm0.getModeListener()); gm1.getModeComboBox().addItemListener(gm3.getModeListener()); modePanel.add(gm1.getModeComboBox()); JPanel controls = new JPanel(); zoomPanel.add(plus); zoomPanel.add(minus); controls.add(zoomPanel); controls.add(modePanel); content.add(controls, BorderLayout.SOUTH); }
From source file:edu.uci.ics.jung.samples.PerspectiveVertexImageShaperDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features.//from w ww .j a va 2s.c o m * */ @SuppressWarnings("serial") public PerspectiveVertexImageShaperDemo() { // create a simple graph for the demo graph = new DirectedSparseMultigraph<Number, Number>(); Number[] vertices = createVertices(11); // a Map for the labels Map<Number, String> map = new HashMap<Number, String>(); for (int i = 0; i < vertices.length; i++) { map.put(vertices[i], iconNames[i % iconNames.length]); } // a Map for the Icons Map<Number, Icon> iconMap = new HashMap<Number, Icon>(); for (int i = 0; i < vertices.length; i++) { String name = "/images/topic" + iconNames[i] + ".gif"; try { Icon icon = new LayeredIcon( new ImageIcon(PerspectiveVertexImageShaperDemo.class.getResource(name)).getImage()); iconMap.put(vertices[i], icon); } catch (Exception ex) { System.err.println("You need slashdoticons.jar in your classpath to see the image " + name); } } createEdges(vertices); final VertexStringerImpl<Number> vertexStringerImpl = new VertexStringerImpl<Number>(map); final VertexIconShapeTransformer<Number> vertexImageShapeFunction = new VertexIconShapeTransformer<Number>( new EllipseVertexShapeTransformer<Number>()); FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph); layout.setMaxIterations(100); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(400, 400)); vv.setBackground(Color.decode("0xffffdd")); final DefaultVertexIconTransformer<Number> vertexIconFunction = new DefaultVertexIconTransformer<Number>(); vertexImageShapeFunction.setIconMap(iconMap); vertexIconFunction.setIconMap(iconMap); vv.getRenderContext().setVertexShapeTransformer(vertexImageShapeFunction); vv.getRenderContext().setVertexIconTransformer(vertexIconFunction); vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl); PickedState<Number> ps = vv.getPickedVertexState(); ps.addItemListener(new PickWithIconListener(vertexIconFunction)); vv.addPostRenderPaintable(new VisualizationServer.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); this.viewSupport = new PerspectiveImageLensSupport<Number, Number>(vv); this.layoutSupport = new PerspectiveLayoutTransformSupport<Number, Number>(vv); 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, 0.9f, vv.getCenter()); } }); final JSlider horizontalSlider = new JSlider(-120, 120, 0) { /* (non-Javadoc) * @see javax.swing.JComponent#getPreferredSize() */ @Override public Dimension getPreferredSize() { return new Dimension(80, super.getPreferredSize().height); } }; final JSlider verticalSlider = new JSlider(-120, 120, 0) { /* (non-Javadoc) * @see javax.swing.JComponent#getPreferredSize() */ @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, 80); } }; verticalSlider.setOrientation(JSlider.VERTICAL); final ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent e) { int vval = -verticalSlider.getValue(); int hval = horizontalSlider.getValue(); Dimension d = vv.getSize(); PerspectiveTransform pt = null; pt = PerspectiveTransform.getQuadToQuad(vval, hval, d.width - vval, -hval, d.width + vval, d.height + hval, -vval, d.height - hval, 0, 0, d.width, 0, d.width, d.height, 0, d.height); viewSupport.getPerspectiveTransformer().setPerspectiveTransform(pt); layoutSupport.getPerspectiveTransformer().setPerspectiveTransform(pt); vv.repaint(); } }; horizontalSlider.addChangeListener(changeListener); verticalSlider.addChangeListener(changeListener); JPanel perspectivePanel = new JPanel(new BorderLayout()); JPanel perspectiveCenterPanel = new JPanel(new BorderLayout()); perspectivePanel.setBorder(BorderFactory.createTitledBorder("Perspective Controls")); final JButton center = new JButton("Center"); center.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { horizontalSlider.setValue(0); verticalSlider.setValue(0); } }); final JCheckBox noText = new JCheckBox("No Text"); noText.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { JCheckBox cb = (JCheckBox) e.getSource(); vertexStringerImpl.setEnabled(!cb.isSelected()); vv.repaint(); } }); JPanel centerPanel = new JPanel(); centerPanel.add(noText); ButtonGroup radio = new ButtonGroup(); JRadioButton none = new JRadioButton("None"); none.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean selected = e.getStateChange() == ItemEvent.SELECTED; if (selected) { if (viewSupport != null) { viewSupport.deactivate(); } if (layoutSupport != null) { layoutSupport.deactivate(); } } center.setEnabled(!selected); horizontalSlider.setEnabled(!selected); verticalSlider.setEnabled(!selected); } }); 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) { layoutSupport.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); panel.setCorner(menubar); JPanel scaleGrid = new JPanel(new GridLayout(2, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(new BorderLayout()); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(scaleGrid, BorderLayout.WEST); JPanel lensPanel = new JPanel(new GridLayout(2, 0)); lensPanel.add(none); lensPanel.add(hyperView); lensPanel.add(hyperModel); perspectivePanel.add(lensPanel, BorderLayout.WEST); perspectiveCenterPanel.add(horizontalSlider, BorderLayout.SOUTH); perspectivePanel.add(verticalSlider, BorderLayout.EAST); perspectiveCenterPanel.add(center); perspectivePanel.add(perspectiveCenterPanel); controls.add(perspectivePanel, BorderLayout.EAST); controls.add(centerPanel); content.add(controls, BorderLayout.SOUTH); }
From source file:App.java
/** * Initialize the contents of the frame. *//*from w ww. ja v a2 s . co m*/ private void initialize() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1000, 750); frame.getContentPane().setLayout(null); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png"); fc = new JFileChooser(); fc.setFileFilter(filter); frame.getContentPane().add(fc); stepOne = new JLabel(""); stepOne.setToolTipText("here comes something"); stepOne.setIcon(new ImageIcon("img/stepOne.png")); stepOne.setBounds(266, -4, 67, 49); frame.getContentPane().add(stepOne); btnBrowse = new JButton("Browse"); btnBrowse.setBounds(66, 6, 117, 29); frame.getContentPane().add(btnBrowse); btnTurnWebcamOn = new JButton("Take a picture with webcam"); btnTurnWebcamOn.setBounds(66, 34, 212, 29); frame.getContentPane().add(btnTurnWebcamOn); JButton btnTakePictureWithWebcam = new JButton("Take a picture"); btnTakePictureWithWebcam.setBounds(430, 324, 117, 29); frame.getContentPane().add(btnTakePictureWithWebcam); btnTakePictureWithWebcam.setVisible(false); JButton btnCancel = new JButton("Cancel"); btnCancel.setBounds(542, 324, 117, 29); frame.getContentPane().add(btnCancel); btnCancel.setVisible(false); JButton btnSaveImage = new JButton("Save image"); btnSaveImage.setBounds(497, 357, 117, 29); frame.getContentPane().add(btnSaveImage); btnSaveImage.setVisible(false); urlField = new JTextField(); urlField.setBounds(66, 67, 220, 26); frame.getContentPane().add(urlField); urlField.setColumns(10); originalImageLabel = new JLabel(); originalImageLabel.setHorizontalAlignment(SwingConstants.CENTER); originalImageLabel.setBounds(33, 98, 300, 300); frame.getContentPane().add(originalImageLabel); stepTwo = new JLabel(""); stepTwo.setToolTipText("here comes something else"); stepTwo.setIcon(new ImageIcon("img/stepTwo.png")); stepTwo.setBounds(266, 413, 67, 49); frame.getContentPane().add(stepTwo); btnAnalyse = new JButton("Analyse image"); btnAnalyse.setBounds(68, 423, 196, 29); frame.getContentPane().add(btnAnalyse); tagsField = new JTextArea(); tagsField.setBounds(23, 479, 102, 89); tagsField.setLineWrap(true); tagsField.setWrapStyleWord(true); frame.getContentPane().add(tagsField); tagsField.setColumns(10); lblTags = new JLabel("Tags:"); lblTags.setBounds(46, 451, 61, 16); frame.getContentPane().add(lblTags); descriptionField = new JTextArea(); descriptionField.setLineWrap(true); descriptionField.setWrapStyleWord(true); descriptionField.setBounds(137, 479, 187, 89); frame.getContentPane().add(descriptionField); descriptionField.setColumns(10); lblDescription = new JLabel("Description:"); lblDescription.setBounds(163, 451, 77, 16); frame.getContentPane().add(lblDescription); stepThree = new JLabel(""); stepThree.setToolTipText("here comes something different"); stepThree.setIcon(new ImageIcon("img/stepThree.png")); stepThree.setBounds(266, 685, 67, 49); frame.getContentPane().add(stepThree); JLabel lblImageType = new JLabel("Image type"); lblImageType.setBounds(23, 580, 102, 16); frame.getContentPane().add(lblImageType); String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" }; JComboBox imageTypeBox = new JComboBox(imageTypes); imageTypeBox.setBounds(137, 580, 187, 23); frame.getContentPane().add(imageTypeBox); JLabel lblSizeType = new JLabel("Size"); lblSizeType.setBounds(23, 608, 102, 16); frame.getContentPane().add(lblSizeType); String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" }; JComboBox sizeBox = new JComboBox(sizeTypes); sizeBox.setBounds(137, 608, 187, 23); frame.getContentPane().add(sizeBox); JLabel lblLicenseType = new JLabel("License"); lblLicenseType.setBounds(23, 636, 102, 16); frame.getContentPane().add(lblLicenseType); String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" }; JComboBox licenseBox = new JComboBox(licenseTypes); licenseBox.setBounds(137, 636, 187, 23); frame.getContentPane().add(licenseBox); JLabel lblSafeSearchType = new JLabel("Safe search"); lblSafeSearchType.setBounds(23, 664, 102, 16); frame.getContentPane().add(lblSafeSearchType); String[] safeSearchTypes = { "Strict", "Moderate", "Off" }; JComboBox safeSearchBox = new JComboBox(safeSearchTypes); safeSearchBox.setBounds(137, 664, 187, 23); frame.getContentPane().add(safeSearchBox); btnSearchForSimilar = new JButton("Search for similar images"); btnSearchForSimilar.setVisible(true); btnSearchForSimilar.setBounds(66, 695, 189, 29); frame.getContentPane().add(btnSearchForSimilar); // label to try urls to display images, not shown on the main frame labelTryLinks = new JLabel(); labelTryLinks.setBounds(0, 0, 100, 100); foundImagesLabel1 = new JLabel(); foundImagesLabel1.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel1.setBounds(400, 49, 250, 250); frame.getContentPane().add(foundImagesLabel1); foundImagesLabel2 = new JLabel(); foundImagesLabel2.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel2.setBounds(400, 313, 250, 250); frame.getContentPane().add(foundImagesLabel2); foundImagesLabel3 = new JLabel(); foundImagesLabel3.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel3.setBounds(673, 49, 250, 250); frame.getContentPane().add(foundImagesLabel3); foundImagesLabel4 = new JLabel(); foundImagesLabel4.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel4.setBounds(673, 313, 250, 250); frame.getContentPane().add(foundImagesLabel4); progressBar = new JProgressBar(); progressBar.setIndeterminate(true); progressBar.setStringPainted(true); progressBar.setBounds(440, 602, 440, 29); Border border = BorderFactory .createTitledBorder("We are checking every image, pixel by pixel, it may take a while..."); progressBar.setBorder(border); frame.getContentPane().add(progressBar); progressBar.setVisible(false); btnHelp = new JButton(""); btnHelp.setBorderPainted(false); ImageIcon btnIcon = new ImageIcon("img/helpRed.png"); btnHelp.setIcon(btnIcon); btnHelp.setBounds(917, 4, 77, 59); frame.getContentPane().add(btnHelp); // all action listeners btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { openFilechooser(); } } }); btnTurnWebcamOn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setAllFoundImagesLabelsAndPreviewsToNull(); btnTakePictureWithWebcam.setVisible(true); btnCancel.setVisible(true); turnCameraOn(); } }); btnTakePictureWithWebcam.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnSaveImage.setVisible(true); // take a photo with web camera imageWebcam = webcam.getImage(); originalImage = imageWebcam; // to mirror the image we create a temporary file, flip it // horizontally and then delete // get user's name to store file in the user directory String user = System.getProperty("user.home"); String fileName = user + "/webCamPhoto.jpg"; File newFile = new File(fileName); try { ImageIO.write(originalImage, "jpg", newFile); } catch (IOException e1) { e1.printStackTrace(); } try { originalImage = (BufferedImage) ImageIO.read(newFile); } catch (IOException e1) { e1.printStackTrace(); } newFile.delete(); originalImage = mirrorImage(originalImage); icon = scaleBufferedImage(originalImage, originalImageLabel); originalImageLabel.setIcon(icon); } }); btnSaveImage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { try { file = fc.getSelectedFile(); File output = new File(file.toString()); // check if image already exists if (output.exists()) { int response = JOptionPane.showConfirmDialog(null, // "Do you want to replace the existing file?", // "Confirm", JOptionPane.YES_NO_OPTION, // JOptionPane.QUESTION_MESSAGE); if (response != JOptionPane.YES_OPTION) { return; } } ImageIO.write(toBufferedImage(originalImage), "jpg", output); System.out.println("Your image has been saved in the folder " + file.getPath()); } catch (IOException e1) { e1.printStackTrace(); } } } }); btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { btnTakePictureWithWebcam.setVisible(false); btnCancel.setVisible(false); btnSaveImage.setVisible(false); webcam.close(); panel.setVisible(false); } }); urlField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (urlField.getText().length() > 0) { String linkNew = urlField.getText(); getImageFromHttp(linkNew, originalImageLabel); originalImage = imageResponses; } } }); btnAnalyse.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Token computerVisionToken = new Token(); String computerVisionTokenFileName = "APIToken.txt"; try { computerVisionImageToken = computerVisionToken.getApiToken(computerVisionTokenFileName); try { analyse(); } catch (NullPointerException e1) { // if user clicks on "analyze" button without uploading // image or posts a broken link JOptionPane.showMessageDialog(null, "Please choose an image"); e1.printStackTrace(); } } catch (NullPointerException e1) { e1.printStackTrace(); } } }); btnSearchForSimilar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // clear labels in case there were results of previous search setAllFoundImagesLabelsAndPreviewsToNull(); System.out.println("=========================================="); System.out.println("new search"); System.out.println("=========================================="); Token bingImageToken = new Token(); String bingImageTokenFileName = "SearchApiToken.txt"; bingToken = bingImageToken.getApiToken(bingImageTokenFileName); // in case user edited description or tags, update it and // replace new line character, spaces and breaks with %20 text = descriptionField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); String tagsString = tagsField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); imageTypeString = imageTypeBox.getSelectedItem().toString(); sizeTypeString = sizeBox.getSelectedItem().toString(); licenseTypeString = licenseBox.getSelectedItem().toString(); safeSearchTypeString = safeSearchBox.getSelectedItem().toString(); searchParameters = tagsString + text; System.out.println("search parameters: " + searchParameters); if (searchParameters.length() != 0) { // add new thread for searching, so that progress bar and // searching could run simultaneously Thread t1 = new Thread(new Runnable() { @Override public void run() { progressBar.setVisible(true); searchForSimilarImages(searchParameters, imageTypeString, sizeTypeString, licenseTypeString, safeSearchTypeString); } }); // start searching for similar images in a separate thread t1.start(); } else { JOptionPane.showMessageDialog(null, "Please choose first an image to analyse or insert search parameters"); } } }); foundImagesLabel1.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel1.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(firstImageUrl); } } } }); foundImagesLabel2.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel2.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(secondImageUrl); } } } }); foundImagesLabel3.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel3.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(thirdImageUrl); } } } }); foundImagesLabel4.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel4.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(fourthImageUrl); } } } }); btnHelp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO write help HelpFrame help = new HelpFrame(); } }); }