List of usage examples for java.awt Container setFont
public void setFont(Font f)
From source file:Main.java
public static void setFont(Container container, Font font) { container.setFont(font); trySetBorderFont(font, container);//from w w w .j av a 2s . c o m Component[] components = container.getComponents(); for (Component component : components) { component.setFont(font); if (component instanceof Container) { setFont((Container) component, font); } trySetBorderFont(font, component); if (component instanceof JTable) { JTable table = (JTable) component; table.getTableHeader().setFont(font); } } if (container instanceof JMenu) { JMenu jMenu = (JMenu) container; for (int i = 0; i < jMenu.getItemCount(); i++) { JMenuItem mi = jMenu.getItem(i); mi.setFont(font); } } }
From source file:Main.java
public static void setComponentsFont(Container container, Font font) { Component[] components = container.getComponents(); container.setFont(font); for (Component component : components) { component.setFont(font);/* w w w . j ava 2 s . c o m*/ if (component instanceof JMenu) { setComponentsFont((Container) component, font); } } }
From source file:model.DrawTopologyDiagram.java
@Override public void init() { //create a graph Graph<VertexTopology, Number> ig = Graphs.<VertexTopology, Number>synchronizedDirectedGraph( new DirectedSparseMultigraph<VertexTopology, Number>()); ObservableGraph<VertexTopology, Number> og = new ObservableGraph<VertexTopology, Number>(ig); og.addGraphEventListener(new GraphEventListener<VertexTopology, Number>() { public void handleGraphEvent(GraphEvent<VertexTopology, Number> evt) { System.err.println("got " + evt); }/* w ww .jav a 2 s .c om*/ }); this.g = og; //layouts //create a graphdraw // layout = new FRLayout2<String,Number>(g); // layout = new SpringLayout<String,Number>(g); // ((FRLayout)layout).setMaxIterations(200); layout = new KKLayout<VertexTopology, Number>(g); vv = new VisualizationViewer<VertexTopology, Number>(layout, new Dimension(600, 600)); createGraph(); Container content = getContentPane(); JPanel totalCasesPanel = new JPanel(); final JPanel scaleGrids = new JPanel(new GridLayout(0, 2)); scaleGrids.add(new JLabel(" Test Cases ")); scaleGrids.add(new JLabel(" ")); totalCasesPanel.add(scaleGrids); JPanel filteredCasesPanel = new JPanel(); final JPanel filteredGrids = new JPanel(new GridLayout(0, 2)); filteredGrids.add(new JLabel(" Filtered Cases ")); filteredGrids.add(new JLabel(" ")); filteredCasesPanel.add(filteredGrids); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); content.setLayout(new BorderLayout()); content.setBackground(java.awt.Color.lightGray); content.setFont(new Font("Serif", Font.PLAIN, 12)); vv.getModel().getRelaxer().setSleepTime(500); vv.setGraphMouse(new DefaultModalGraphMouse<VertexTopology, Number>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.setForeground(Color.white); FontMetrics fm = vv.getFontMetrics(vv.getFont()); int width = fm.stringWidth(g.toString()); Transformer<VertexTopology, Shape> vertexSize = new Transformer<VertexTopology, Shape>() { public Shape transform(VertexTopology i) { Ellipse2D circle = new Ellipse2D.Double(-20, -20, 40, 40); // in this case, the vertex is twice as large return circle; } }; vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller() { @Override public String transform(Object v) { return ((VertexTopology) v).getScreenName(); } }); vv.getRenderContext().setVertexShapeTransformer(vertexSize); //Get picked states final PickedState<VertexTopology> pickedState = vv.getPickedVertexState(); pickedState.addItemListener(new ItemListener() { ArrayList<TestCase> outputTestCase = new ArrayList<TestCase>(); final Map<String, JButton> createdBtns = new HashMap<String, JButton>(); Map<String, Integer> deviceSelected = new HashMap<String, Integer>(); // not useful ArrayList<String> endPointList = new ArrayList<String>(); @Override public void itemStateChanged(ItemEvent e) { // TODO Auto-generated method stub Object subject = e.getItem(); if (e.getStateChange() != 1) { scaleGrids.removeAll(); filteredGrids.removeAll(); endPointList.remove(getScreenName(subject)); outputTestCase.clear(); filteredGrids.repaint(); filteredGrids.add(new JLabel(" Filtered Cases ")); filteredGrids.add(new JLabel(" ")); scaleGrids.repaint(); scaleGrids.add(new JLabel(" Test Cases ")); scaleGrids.add(new JLabel(" ")); deviceSelected.clear(); } if (e.getStateChange() == 1) { for (TestCase testCase : outputTestCase) { scaleGrids.removeAll(); scaleGrids.add(new JLabel(" Test Cases ")); scaleGrids.add(new JLabel(" ")); filteredGrids.removeAll(); filteredGrids.add(new JLabel(" Filtered Cases ")); filteredGrids.add(new JLabel(" ")); } if (subject instanceof VertexTopology) { final VertexTopology edgePicked = (VertexTopology) subject; if (pickedState.isPicked(edgePicked)) { for (TestCase testCase : edgePicked.getTestCaseList()) { if (!outputTestCase.contains(testCase)) outputTestCase.add(testCase); System.out.println("The size for reference is " + testCase.inputReferenceMap.size() + testCase.getName()); System.out.println("The size for target is " + testCase.inputTargetMap.size() + testCase.getName()); } if (deviceSelected.get(edgePicked.getScreenName()) != null) deviceSelected.put(edgePicked.getScreenName(), deviceSelected.get(edgePicked.getScreenName()) + 1); else deviceSelected.put(edgePicked.getScreenName(), 1); endPointList.add(edgePicked.getScreenName()); } } } for (TestCase testCase : outputTestCase) { JButton btnCase = new JButton(testCase.getName()); scaleGrids.add(btnCase); if (testCase.getInputDeviceList().size() <= endPointList.size()) if (testCaseSelected(testCase, endPointList)) { JButton btnCaseFiltered = new JButton(testCase.getName()); filteredGrids.add(btnCaseFiltered); } ; } scaleGrids.revalidate(); scaleGrids.setVisible(true); } }); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); content.setPreferredSize(new Dimension(1400, 900)); content.add(vv); switchLayout = new JButton("Switch to SpringLayout"); // switchLayout.addActionListener(new ActionListener() { // // @SuppressWarnings("unchecked") // public void actionPerformed(ActionEvent ae) { // Dimension d = new Dimension(600,600); // if (switchLayout.getText().indexOf("Spring") > 0) { // switchLayout.setText("Switch to FRLayout"); // layout = new SpringLayout<String,Number>(g, // new ConstantTransformer(EDGE_LENGTH)); // layout.setSize(d); // vv.getModel().setGraphLayout(layout, d); // } else { // switchLayout.setText("Switch to SpringLayout"); // layout = new FRLayout<String,Number>(g, d); // vv.getModel().setGraphLayout(layout, d); // } // } // }); JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, totalCasesPanel, filteredCasesPanel); jSplitPane.setResizeWeight(.5d); content.add(switchLayout, BorderLayout.SOUTH); content.add(jSplitPane, BorderLayout.EAST); }
From source file:org.spiderplan.tools.visulization.GraphFrame.java
/** * @param graph// w w w. j a v a 2 s. c om * @param history optional history of the graph * @param title * @param lC the layout * @param edgeLabels map from edges to string labels * @param w width of the window * @param h height of the window */ @SuppressWarnings({ "rawtypes", "unchecked" }) public GraphFrame(AbstractTypedGraph<V, E> graph, Vector<AbstractTypedGraph<V, E>> history, String title, LayoutClass lC, Map<E, String> edgeLabels, int w, int h) { super(title); this.edgeLabels = edgeLabels; this.g = new ObservableGraph<V, E>(graph); this.g.addGraphEventListener(this); this.defaultEdgeType = this.g.getDefaultEdgeType(); this.layoutClass = lC; this.history = history; this.setLayout(lC); layout.setSize(new Dimension(w, h)); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } // Layout<V,E> staticLayout = new StaticLayout<V,E>(g, layout); // Layout<V,E> staticLayout = new SpringLayout<V, E>(g); vv = new VisualizationViewer<V, E>(layout, new Dimension(w, h)); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); getContentPane().setLayout(new BorderLayout()); getContentPane().setBackground(java.awt.Color.lightGray); getContentPane().setFont(new Font("Serif", Font.PLAIN, 10)); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<V>()); vv.setForeground(Color.black); graphMouse = new EditingModalGraphMouse<V, E>(vv.getRenderContext(), null, null); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); // vv.getRenderContext().setEd vv.getRenderContext().setEdgeLabelTransformer(this); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<E>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.addComponentListener(new ComponentAdapter() { /** * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent) */ @Override public void componentResized(ComponentEvent arg0) { super.componentResized(arg0); layout.setSize(arg0.getComponent().getSize()); } }); getContentPane().add(vv); /** * Create simple container for stuff on SOUTH border of this JFrame */ Container c = new Container(); c.setLayout(new FlowLayout()); c.setBackground(java.awt.Color.lightGray); c.setFont(new Font("Serif", Font.PLAIN, 10)); /** * Button to dump jpeg */ dumpJPEG = new JButton("Dump"); dumpJPEG.addActionListener(this); dumpJPEG.setName("Dump"); c.add(dumpJPEG); /** * Button that creates offspring frame for selected vertices */ subGraphButton = new JButton("Subgraph"); subGraphButton.addActionListener(this); subGraphButton.setName("Subgraph"); c.add(subGraphButton); subGraphDepthLabel = new JLabel("Depth"); c.add(subGraphDepthLabel); subGraphDepth = new JTextField("0", 2); subGraphDepth.setHorizontalAlignment(SwingConstants.CENTER); subGraphDepth.setToolTipText("Depth of sub-graph created from selected nodes."); c.add(subGraphDepth); /** * Button that switches mouse mode */ switchMode = new JButton("Transformation"); switchMode.addActionListener(this); switchMode.setName("SwitchMode"); c.add(switchMode); /** * ComboBox for Layout selection: */ JComboBox layoutList; if (graph instanceof Forest) { String[] layoutStrings = { "Static", "Circle", "DAG", "Spring", "Spring2", "FR", "FR2", "Baloon", "ISOM", "KK", "PolarPoint", "RadialTree", "Tree" }; layoutList = new JComboBox(layoutStrings); } else { String[] layoutStrings = { "Static", "Circle", "DAG", "Spring", "Spring2", "FR", "FR2", "ISOM", "KK", "PolarPoint" }; layoutList = new JComboBox(layoutStrings); } layoutList.setSelectedIndex(5); layoutList.addActionListener(this); layoutList.setName("SelectLayout"); c.add(layoutList); /** * Add container to layout */ c.setVisible(true); getContentPane().add(c, BorderLayout.SOUTH); /** * Setup history scroll bar */ if (history != null) { historySlider = new JSlider(0, history.size() - 1, history.size() - 1); historySlider.addChangeListener(this); historySlider.setMajorTickSpacing(10); historySlider.setMinorTickSpacing(1); historySlider.setPaintTicks(true); historySlider.setPaintLabels(true); historySlider.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); Font font = new Font("Serif", Font.ITALIC, 15); historySlider.setFont(font); getContentPane().add(historySlider, BorderLayout.NORTH); } this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.pack(); this.setVisible(true); }