List of usage examples for javax.swing JPanel setOpaque
@BeanProperty(expert = true, description = "The component's opacity") public void setOpaque(boolean isOpaque)
From source file:test.visualization.ClusteringDemo.java
private void setUpView(BufferedReader br) throws IOException { Factory<Number> vertexFactory = new Factory<Number>() { int n = 0; public Number create() { return n++; }// ww w .ja v a 2 s .c o m }; Factory<Number> edgeFactory = new Factory<Number>() { int n = 0; public Number create() { return n++; } }; PajekNetReader<Graph<Number, Number>, Number, Number> pnr = new PajekNetReader<Graph<Number, Number>, Number, Number>( vertexFactory, edgeFactory); final Graph<Number, Number> graph = new SparseMultigraph<Number, Number>(); pnr.load(br, graph); //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)); 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:test.visualization.PluggableRendererDemo.java
/** * @param jp panel to which controls will be added *//*ww w.j av a 2 s .c o m*/ @SuppressWarnings("serial") protected void addBottomControls(final JPanel jp) { final JPanel control_panel = new JPanel(); jp.add(control_panel, BorderLayout.EAST); control_panel.setLayout(new BorderLayout()); final Box vertex_panel = Box.createVerticalBox(); vertex_panel.setBorder(BorderFactory.createTitledBorder("Vertices")); final Box edge_panel = Box.createVerticalBox(); edge_panel.setBorder(BorderFactory.createTitledBorder("Edges")); final Box both_panel = Box.createVerticalBox(); control_panel.add(vertex_panel, BorderLayout.NORTH); control_panel.add(edge_panel, BorderLayout.SOUTH); control_panel.add(both_panel, BorderLayout.CENTER); // set up vertex controls v_color = new JCheckBox("seed highlight"); v_color.addActionListener(this); v_stroke = new JCheckBox("stroke highlight on selection"); v_stroke.addActionListener(this); v_labels = new JCheckBox("show voltage values"); v_labels.addActionListener(this); v_shape = new JCheckBox("shape by degree"); v_shape.addActionListener(this); v_size = new JCheckBox("size by voltage"); v_size.addActionListener(this); v_size.setSelected(true); v_aspect = new JCheckBox("stretch by degree ratio"); v_aspect.addActionListener(this); v_small = new JCheckBox("filter when degree < " + VertexDisplayPredicate.MIN_DEGREE); v_small.addActionListener(this); vertex_panel.add(v_color); vertex_panel.add(v_stroke); vertex_panel.add(v_labels); vertex_panel.add(v_shape); vertex_panel.add(v_size); vertex_panel.add(v_aspect); vertex_panel.add(v_small); // set up edge controls JPanel gradient_panel = new JPanel(new GridLayout(1, 0)); gradient_panel.setBorder(BorderFactory.createTitledBorder("Edge paint")); no_gradient = new JRadioButton("Solid color"); no_gradient.addActionListener(this); no_gradient.setSelected(true); // gradient_absolute = new JRadioButton("Absolute gradient"); // gradient_absolute.addActionListener(this); gradient_relative = new JRadioButton("Gradient"); gradient_relative.addActionListener(this); ButtonGroup bg_grad = new ButtonGroup(); bg_grad.add(no_gradient); bg_grad.add(gradient_relative); //bg_grad.add(gradient_absolute); gradient_panel.add(no_gradient); //gradientGrid.add(gradient_absolute); gradient_panel.add(gradient_relative); JPanel shape_panel = new JPanel(new GridLayout(3, 2)); shape_panel.setBorder(BorderFactory.createTitledBorder("Edge shape")); e_line = new JRadioButton("line"); e_line.addActionListener(this); e_line.setSelected(true); // e_bent = new JRadioButton("bent line"); // e_bent.addActionListener(this); e_wedge = new JRadioButton("wedge"); e_wedge.addActionListener(this); e_quad = new JRadioButton("quad curve"); e_quad.addActionListener(this); e_cubic = new JRadioButton("cubic curve"); e_cubic.addActionListener(this); e_ortho = new JRadioButton("orthogonal"); e_ortho.addActionListener(this); ButtonGroup bg_shape = new ButtonGroup(); bg_shape.add(e_line); // bg.add(e_bent); bg_shape.add(e_wedge); bg_shape.add(e_quad); bg_shape.add(e_ortho); bg_shape.add(e_cubic); shape_panel.add(e_line); // shape_panel.add(e_bent); shape_panel.add(e_wedge); shape_panel.add(e_quad); shape_panel.add(e_cubic); shape_panel.add(e_ortho); fill_edges = new JCheckBox("fill edge shapes"); fill_edges.setSelected(false); fill_edges.addActionListener(this); shape_panel.add(fill_edges); shape_panel.setOpaque(true); e_color = new JCheckBox("highlight edge weights"); e_color.addActionListener(this); e_labels = new JCheckBox("show edge weight values"); e_labels.addActionListener(this); e_uarrow_pred = new JCheckBox("undirected"); e_uarrow_pred.addActionListener(this); e_darrow_pred = new JCheckBox("directed"); e_darrow_pred.addActionListener(this); e_darrow_pred.setSelected(true); JPanel arrow_panel = new JPanel(new GridLayout(1, 0)); arrow_panel.setBorder(BorderFactory.createTitledBorder("Show arrows")); arrow_panel.add(e_uarrow_pred); arrow_panel.add(e_darrow_pred); e_show_d = new JCheckBox("directed"); e_show_d.addActionListener(this); e_show_d.setSelected(true); e_show_u = new JCheckBox("undirected"); e_show_u.addActionListener(this); e_show_u.setSelected(true); JPanel show_edge_panel = new JPanel(new GridLayout(1, 0)); show_edge_panel.setBorder(BorderFactory.createTitledBorder("Show edges")); show_edge_panel.add(e_show_u); show_edge_panel.add(e_show_d); shape_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(shape_panel); gradient_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(gradient_panel); show_edge_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(show_edge_panel); arrow_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(arrow_panel); e_color.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(e_color); e_labels.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(e_labels); // set up zoom controls zoom_at_mouse = new JCheckBox("<html><center>zoom at mouse<p>(wheel only)</center></html>"); zoom_at_mouse.addActionListener(this); zoom_at_mouse.setSelected(true); 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()); } }); JPanel zoomPanel = new JPanel(); zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom")); plus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(plus); minus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(minus); zoom_at_mouse.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(zoom_at_mouse); JPanel fontPanel = new JPanel(); // add font and zoom controls to center panel font = new JCheckBox("bold text"); font.addActionListener(this); font.setAlignmentX(Component.CENTER_ALIGNMENT); fontPanel.add(font); both_panel.add(zoomPanel); both_panel.add(fontPanel); JComboBox modeBox = gm.getModeComboBox(); modeBox.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel modePanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return getPreferredSize(); } }; modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modePanel.add(modeBox); JPanel comboGrid = new JPanel(new GridLayout(0, 1)); comboGrid.add(modePanel); fontPanel.add(comboGrid); JComboBox cb = new JComboBox(); cb.addItem(Renderer.VertexLabel.Position.N); cb.addItem(Renderer.VertexLabel.Position.NE); cb.addItem(Renderer.VertexLabel.Position.E); cb.addItem(Renderer.VertexLabel.Position.SE); cb.addItem(Renderer.VertexLabel.Position.S); cb.addItem(Renderer.VertexLabel.Position.SW); cb.addItem(Renderer.VertexLabel.Position.W); cb.addItem(Renderer.VertexLabel.Position.NW); cb.addItem(Renderer.VertexLabel.Position.N); cb.addItem(Renderer.VertexLabel.Position.CNTR); cb.addItem(Renderer.VertexLabel.Position.AUTO); cb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { Renderer.VertexLabel.Position position = (Renderer.VertexLabel.Position) e.getItem(); vv.getRenderer().getVertexLabelRenderer().setPosition(position); vv.repaint(); } }); cb.setSelectedItem(Renderer.VertexLabel.Position.SE); JPanel positionPanel = new JPanel(); positionPanel.setBorder(BorderFactory.createTitledBorder("Label Position")); positionPanel.add(cb); comboGrid.add(positionPanel); }
From source file:tvbrowser.ui.mainframe.MainFrame.java
private MainFrame() { super(TVBrowser.MAINWINDOW_TITLE); mIsVisible = false;//from w ww . j a v a2 s. c om mSettingsWillBeOpened = false; mAutoDownloadTimer = -1; mLastTimerMinutesAfterMidnight = -1; mLastAutoUpdateRun = System.currentTimeMillis(); mChannelDateArr = null; mOnAirRowProgramsArr = null; mStatusBar = new StatusBar(); if (OperatingSystem.isMacOs()) { /* create the menu bar for MacOS X */ try { Class<?> impl = Class.forName("tvbrowser.ui.mainframe.macosx.MacOSXMenuBar"); Class<? extends MainFrame> mainFrameClass = this.getClass(); Class<?> jlabelClass = Class.forName("javax.swing.JLabel"); Constructor<?> cons = impl.getConstructor(new Class[] { mainFrameClass, jlabelClass }); mMenuBar = (MenuBar) cons.newInstance(new Object[] { this, mStatusBar.getLabel() }); } catch (Exception e) { if (TVBrowser.isTransportable()) { mLog.info("Using default menu bar (instead of MacOSXMenuBar) for transportable version."); } mLog.warning("Could not instantiate MacOSXMenuBar\n" + e.toString()); if (e.getCause() != null) { StringWriter sw = new StringWriter(); e.getCause().printStackTrace(new PrintWriter(sw)); mLog.warning(sw.toString()); } mMenuBar = new DefaultMenuBar(this, mStatusBar.getLabel()); mLog.info("Using default menu bar"); } } else { mMenuBar = new DefaultMenuBar(this, mStatusBar.getLabel()); } // create content jcontentPane = (JPanel) getContentPane(); jcontentPane.setLayout(new BorderLayout()); JPanel skinPanel = new JPanel(); skinPanel.setLayout(new BorderLayout()); JPanel centerPanel = new JPanel(new BorderLayout()); centerPanel.setOpaque(false); centerPanel.setBorder(BorderFactory.createEmptyBorder()); mFilterPanel = new FilterPanel(); mFilterPanel.setVisible(false); mTimeChooserPanel = new TimeChooserPanel(this); centerPanel.add(mFilterPanel, BorderLayout.NORTH); Channel[] channelArr = ChannelList.getSubscribedChannels(); int startOfDay = Settings.propProgramTableStartOfDay.getInt(); int endOfDay = Settings.propProgramTableEndOfDay.getInt(); mProgramTableModel = new DefaultProgramTableModel(channelArr, startOfDay, endOfDay); mProgramTableScrollPane = new ProgramTableScrollPane(mProgramTableModel); centerPanel.add(mProgramTableScrollPane); createDateSelector(); skinPanel.add(centerPanel, BorderLayout.CENTER); mChannelChooser = new ChannelChooserPanel(this); /* create structure */ mRootNode = new Node(null); if (Settings.propPluginViewIsLeft.getBoolean()) { mPluginsNode = new Node(mRootNode); } else { mNavigationNode = new Node(mRootNode); } mMainframeNode = new Node(mRootNode); Node programtableNode = new Node(mMainframeNode); if (Settings.propPluginViewIsLeft.getBoolean()) { mNavigationNode = new Node(mMainframeNode); } else { mPluginsNode = new Node(mMainframeNode); } mTimebuttonsNode = new Node(mNavigationNode); mDateChannelNode = new Node(mNavigationNode); mDateNode = new Node(mDateChannelNode); mChannelNode = new Node(mDateChannelNode); mRootNode.setProperty(Settings.propViewRoot); mMainframeNode.setProperty(Settings.propViewMainframe); mNavigationNode.setProperty(Settings.propViewNavigation); mDateChannelNode.setProperty(Settings.propViewDateChannel); /* create views */ programtableNode.setLeaf(skinPanel); this.setShowPluginOverview(Settings.propShowPluginView.getBoolean()); this.setShowTimeButtons(Settings.propShowTimeButtons.getBoolean()); this.setShowDatelist(Settings.propShowDatelist.getBoolean()); this.setShowChannellist(Settings.propShowChannels.getBoolean()); updateToolbar(); dateChanged(new devplugin.Date(), null, null); mCenterComponent = mRootNode.getComponent(); if (mCenterComponent != null) { jcontentPane.add(mCenterComponent, BorderLayout.CENTER); } if (Settings.propIsStatusbarVisible.getBoolean()) { jcontentPane.add(mStatusBar, BorderLayout.SOUTH); } setJMenuBar(mMenuBar); addContextMenuMouseListener(mMenuBar); // set program filter FilterList filterList = FilterList.getInstance(); ProgramFilter filter = filterList.getFilterByName(Settings.propLastUsedFilter.getString()); if (filter == null) { filter = FilterManagerImpl.getInstance().getDefaultFilter(); } setProgramFilter(filter); // set channel group filter String channelGroupName = Settings.propLastUsedChannelGroup.getString(); if (channelGroupName != null) { FilterComponent component = FilterComponentList.getInstance() .getFilterComponentByName(channelGroupName); if (component != null && component instanceof ChannelFilterComponent) { setChannelGroup((ChannelFilterComponent) component); } } addKeyboardAction(); mTimer = new Timer(10000, new ActionListener() { public void actionPerformed(ActionEvent evt) { handleTimerEvent(); } }); mTimer.start(); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); //create the drop target for installation of Plugins with Drag'N'Drop on MainFrame DropTarget target = new DropTarget(); try { target.addDropTargetListener(this); } catch (TooManyListenersException e1) { //ignore } this.setDropTarget(target); }
From source file:uk.ac.liverpool.narrative.SolutionGraphics.java
public void paintMinSpanningTree() { MinimumSpanningForest2<STRIPSState, Action> f = new MinimumSpanningForest2<STRIPSState, Action>(sg.ggraph, new DelegateForest<STRIPSState, Action>(), DelegateTree.<STRIPSState, Action>getFactory(), new ConstantTransformer(1.0)); Forest<STRIPSState, Action> tree = f.getForest(); Set<STRIPSState> toRemove = new SetWrapper<STRIPSState>(); DFSVisit(sg.start, tree, toRemove);/* ww w . ja v a2 s . c o m*/ for (STRIPSState s : toRemove) { tree.removeVertex(s); } TreeLayout<STRIPSState, Action> layout1 = new TreeLayout<STRIPSState, Action>(tree, 220, 60); VisualizationModel<STRIPSState, Action> vm1 = new DefaultVisualizationModel<STRIPSState, Action>(layout1, new Dimension(1600, 1200)); final VisualizationViewer<STRIPSState, Action> vv1 = new VisualizationViewer<STRIPSState, Action>(vm1, new Dimension(1600, 1200)); vv1.setVertexToolTipTransformer(new ToStringLabeller()); vv1.getRenderContext().setEdgeLabelTransformer(new Transformer<Action, String>() { @Override public String transform(Action a) { return "" + template.apply_template(sg.realActions.get(a)); } }); vv1.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); vv1.setEdgeToolTipTransformer(new Transformer<Action, String>() { @Override public String transform(Action a) { try { return "" + sg.realActions.get(a).toString(); } catch (Exception z) { System.out.println(z); return ""; } } }); vv1.setBackground(Color.white); vv1.getRenderContext().setVertexLabelTransformer(new Transformer<STRIPSState, String>() { @Override public String transform(STRIPSState s) { return "";// +Integer.toHexString(s.hashCode()); } }); vv1.getRenderContext().setEdgeFontTransformer(new Transformer<Action, Font>() { @Override public Font transform(Action s) { Action ra = sg.realActions.get(s); Collection<Action> set = sg.actionToEdges.get(template.apply_template(ra)); if (set != null && set.size() > 1) return DERIVE_FONT; return DERIVE_FONT2; } }); vv1.getRenderContext().setVertexFillPaintTransformer(new Transformer<STRIPSState, Paint>() { @Override public Paint transform(STRIPSState s) { if (vv1.getPickedVertexState().isPicked(s)) return new Color(250, 250, 0, 207); if (sg.start.equals(s)) return new Color(10, 200, 10, 197); else if (sg.ends.contains(s)) return new Color(220, 10, 10, 197); return new Color(255, 210, 40, 197); } }); vv1.getRenderContext().setVertexShapeTransformer(new StoryStateTransformer()); vv1.setRenderer(new LabelsLastRenderer()); vv1.getRenderer().getVertexLabelRenderer().setPosition(Position.AUTO); vv1.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.gray, false)); // vv1.getRenderContext().setLabelOffset(0); vv1.setLayout(new BorderLayout()); Font font = vv1.getFont().deriveFont(Font.BOLD, 16); JLabel vv1Label = new JLabel("Minimum Spanning Trees"); vv1Label.setFont(font); JPanel flow1 = new JPanel(); flow1.setOpaque(false); flow1.add(vv1Label); vv1.add(flow1, BorderLayout.NORTH); vv1.setGraphMouse(new DefaultModalGraphMouse()); JFrame f2 = new JFrame(); f2.add(vv1); f2.pack(); f2.setVisible(true); }