List of usage examples for java.awt.event ComponentEvent getComponent
public Component getComponent()
From source file:org.metacsp.utility.UI.ConstraintNetworkFrame.java
public ConstraintNetworkFrame(ObservableGraph<Variable, Constraint> graph, String title, final Callback cb) { super(title); this.g = graph; g.addGraphEventListener(new GraphEventListener<Variable, Constraint>() { @Override//from w ww . java 2 s. c o m public void handleGraphEvent(GraphEvent<Variable, Constraint> evt) { vv.getRenderContext().getPickedVertexState().clear(); vv.getRenderContext().getPickedEdgeState().clear(); try { layout.initialize(); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { e.printStackTrace(); } StaticLayout<Variable, Constraint> staticLayout = new StaticLayout<Variable, Constraint>(g, layout); lt = new LayoutTransition<Variable, Constraint>(vv, vv.getGraphLayout(), staticLayout); animator = new MyAnimator(lt); animator.start(); //vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } catch (Exception e) { e.printStackTrace(); } } }); //create a graphdraw //layout = new FRLayout<Variable,Constraint>(g); //layout = new SpringLayout<Variable,Constraint>(g); //layout = new StaticLayout<Variable,Constraint>(g,new STNTransformer()); layout = new FRLayout2<Variable, Constraint>(g); //layout = new CircleLayout<Variable,Constraint>(g); //layout = new ISOMLayout<Variable,Constraint>(g); //layout = new KKLayout<Variable,Constraint>(g); layout.setSize(new Dimension(600, 600)); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { e.printStackTrace(); } Layout<Variable, Constraint> staticLayout = new StaticLayout<Variable, Constraint>(g, layout); vv = new VisualizationViewer<Variable, Constraint>(staticLayout, new Dimension(600, 600)); 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, 12)); vv.setGraphMouse(new DefaultModalGraphMouse<Variable, Constraint>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Variable>()); vv.setForeground(Color.black); //draw edge labels Transformer<Constraint, String> stringer = new Transformer<Constraint, String>() { @Override public String transform(Constraint e) { try { return e.getEdgeLabel(); } catch (NullPointerException ex) { return ""; } } }; Transformer<Variable, Paint> vertexPaint = new Transformer<Variable, Paint>() { public Paint transform(Variable v) { return v.getColor(); } }; Transformer<Constraint, Paint> constraintPaint = new Transformer<Constraint, Paint>() { public Paint transform(Constraint c) { return c.getColor(); } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); // vv.getRenderContext().setEdgeFillPaintTransformer(constraintPaint); vv.getRenderContext().setEdgeLabelTransformer(stringer); // vv.getRenderContext().setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Constraint>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.getRenderContext().setEdgeDrawPaintTransformer(constraintPaint); 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); performOperation = new JButton("Perform operation"); if (cb == null) performOperation.setEnabled(false); else performOperation.setEnabled(true); performOperation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (cb != null) cb.performOperation(); } }); switchLayout = new JButton("Switch to SpringLayout"); switchLayout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { Dimension d = vv.getSize();//new Dimension(600,600); if (switchLayout.getText().indexOf("Spring") > 0) { switchLayout.setText("Switch to FRLayout"); //layout = new SpringLayout<Variable,Constraint>(g, new ConstantTransformer(EDGE_LENGTH)); layout = new SpringLayout<Variable, Constraint>(g); layout.setSize(d); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { e.printStackTrace(); } StaticLayout<Variable, Constraint> staticLayout = new StaticLayout<Variable, Constraint>(g, layout); lt = new LayoutTransition<Variable, Constraint>(vv, vv.getGraphLayout(), staticLayout); Animator animator = new MyAnimator(lt); animator.start(); // vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } else { switchLayout.setText("Switch to SpringLayout"); layout = new FRLayout<Variable, Constraint>(g, d); layout.setSize(d); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } StaticLayout<Variable, Constraint> staticLayout = new StaticLayout<Variable, Constraint>(g, layout); lt = new LayoutTransition<Variable, Constraint>(vv, vv.getGraphLayout(), staticLayout); Animator animator = new MyAnimator(lt); animator.start(); //vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } } }); getContentPane().add(performOperation, BorderLayout.SOUTH); //getContentPane().add(switchLayout, BorderLayout.SOUTH); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.pack(); this.setVisible(true); }
From source file:org.metacsp.utility.UI.FiniteStateAutomatonFrame.java
public FiniteStateAutomatonFrame(ObservableGraph<String[], Interval> graph) { super("Constraint Network"); g = graph;//from w ww . j ava 2 s.co m g.addGraphEventListener(new GraphEventListener<String[], Interval>() { public void handleGraphEvent(GraphEvent<String[], Interval> evt) { System.err.println("got " + evt); /****/ vv.getRenderContext().getPickedVertexState().clear(); vv.getRenderContext().getPickedEdgeState().clear(); try { layout.initialize(); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } StaticLayout<String[], Interval> staticLayout = new StaticLayout<String[], Interval>(g, layout); LayoutTransition<String[], Interval> lt = new LayoutTransition<String[], Interval>(vv, vv.getGraphLayout(), staticLayout); Animator animator = new Animator(lt); animator.start(); // vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } catch (Exception e) { System.out.println(e); } /****/ } }); //create a graphdraw //layout = new FRLayout<State,Interval>(g); //layout = new SpringLayout<State,Interval>(g); //layout = new StaticLayout<State,Interval>(g,new STNTransformer()); layout = new FRLayout2<String[], Interval>(g); //layout = new CircleLayout<State,Interval>(g); //layout = new ISOMLayout<State,Interval>(g); //layout = new KKLayout<State,Interval>(g); layout.setSize(new Dimension(600, 600)); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } Layout<String[], Interval> staticLayout = new StaticLayout<String[], Interval>(g, layout); vv = new VisualizationViewer<String[], Interval>(staticLayout, new Dimension(600, 600)); 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, 12)); vv.setGraphMouse(new DefaultModalGraphMouse<String[], Interval>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String[]>()); vv.setForeground(Color.black); //draw edge labels Transformer<Interval, String> stringer = new Transformer<Interval, String>() { public String transform(Interval e) { return e.toString(); } }; vv.getRenderContext().setEdgeLabelTransformer(stringer); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Interval>(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); System.err.println("resized"); layout.setSize(arg0.getComponent().getSize()); } }); getContentPane().add(vv); switchLayout = new JButton("Switch to SpringLayout"); switchLayout.addActionListener(new ActionListener() { @SuppressWarnings("unchecked") public void actionPerformed(ActionEvent ae) { Dimension d = vv.getSize();//new Dimension(600,600); if (switchLayout.getText().indexOf("Spring") > 0) { switchLayout.setText("Switch to FRLayout"); //layout = new SpringLayout<State,Interval>(g, new ConstantTransformer(EDGE_LENGTH)); layout = new SpringLayout<String[], Interval>(g); layout.setSize(d); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } StaticLayout<String[], Interval> staticLayout = new StaticLayout<String[], Interval>(g, layout); LayoutTransition<String[], Interval> lt = new LayoutTransition<String[], Interval>(vv, vv.getGraphLayout(), staticLayout); Animator animator = new Animator(lt); animator.start(); // vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } else { switchLayout.setText("Switch to SpringLayout"); layout = new FRLayout<String[], Interval>(g, d); layout.setSize(d); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } StaticLayout<String[], Interval> staticLayout = new StaticLayout<String[], Interval>(g, layout); LayoutTransition<String[], Interval> lt = new LayoutTransition<String[], Interval>(vv, vv.getGraphLayout(), staticLayout); Animator animator = new Animator(lt); animator.start(); // vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.repaint(); } } }); getContentPane().add(switchLayout, BorderLayout.SOUTH); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); this.setVisible(true); }
From source file:org.spiderplan.tools.visulization.GraphFrame.java
/** * @param graph/*w w w .j a va 2s . co m*/ * @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); }
From source file:savant.view.swing.NavigationBar.java
NavigationBar() { this.setOpaque(false); this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); String buttonStyle = "segmentedCapsule"; String shortcutMod = MiscUtils.MAC ? "Cmd" : "Ctrl"; add(getRigidPadding());//from w w w. j ava 2 s . c om JButton loadGenomeButton = (JButton) add(new JButton("")); loadGenomeButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.GENOME)); loadGenomeButton.setToolTipText("Load or change genome"); loadGenomeButton.setFocusable(false); loadGenomeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Savant.getInstance().showOpenGenomeDialog(); } }); loadGenomeButton.putClientProperty("JButton.buttonType", buttonStyle); loadGenomeButton.putClientProperty("JButton.segmentPosition", "first"); loadGenomeButton.setPreferredSize(ICON_SIZE); loadGenomeButton.setMinimumSize(ICON_SIZE); loadGenomeButton.setMaximumSize(ICON_SIZE); JButton loadTrackButton = (JButton) add(new JButton("")); loadTrackButton.setFocusable(false); loadTrackButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.TRACK)); loadTrackButton.setToolTipText("Load a track"); loadTrackButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Savant.getInstance().openTrack(); } }); loadTrackButton.putClientProperty("JButton.buttonType", buttonStyle); loadTrackButton.putClientProperty("JButton.segmentPosition", "last"); loadTrackButton.setPreferredSize(ICON_SIZE); loadTrackButton.setMinimumSize(ICON_SIZE); loadTrackButton.setMaximumSize(ICON_SIZE); if (!Savant.getInstance().isStandalone()) { add(loadGenomeButton); add(loadTrackButton); add(getRigidPadding()); add(getRigidPadding()); } else { loadGenomeButton.setVisible(false); loadTrackButton.setVisible(false); } JLabel rangeText = new JLabel("Location "); add(rangeText); String[] a = { " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }; locationField = new JComboBox(a); locationField.setEditable(true); locationField.setRenderer(new ReferenceListRenderer()); // When the item is chosen from the menu, navigate to the given feature/reference. locationField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (!currentlyPopulating) { if (ae.getActionCommand().equals("comboBoxChanged")) { // Assumes that combo-box items created by populateCombo() are of the form "GENE (chrX:1-1000)". String itemText = locationField.getSelectedItem().toString(); int lastBracketPos = itemText.lastIndexOf('('); if (lastBracketPos > 0) { itemText = itemText.substring(lastBracketPos + 1, itemText.length() - 1); } setRangeFromText(itemText); } } } }); // When the combo-box is popped open, we may want to repopulate the menu. locationField.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent pme) { String text = (String) locationField.getEditor().getItem(); if (!text.equals(lastPoppedUp)) { try { // Building the menu could take a while. setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); populateCombo(); } finally { setCursor(Cursor.getDefaultCursor()); } } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent pme) { } @Override public void popupMenuCanceled(PopupMenuEvent pme) { } }); // Add our special keystroke-handling to the JComboBox' text-field. // We have to turn off default tab-handling so that tab can pop up our list. Component textField = locationField.getEditor().getEditorComponent(); textField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_TAB) { locationField.showPopup(); } else if (evt.getModifiers() == KeyEvent.SHIFT_MASK) { switch (evt.getKeyCode()) { case KeyEvent.VK_LEFT: locationController.shiftRangeLeft(); evt.consume(); break; case KeyEvent.VK_RIGHT: locationController.shiftRangeRight(); evt.consume(); break; case KeyEvent.VK_UP: locationController.zoomIn(); evt.consume(); break; case KeyEvent.VK_DOWN: locationController.zoomOut(); evt.consume(); break; case KeyEvent.VK_HOME: locationController.shiftRangeFarLeft(); evt.consume(); break; case KeyEvent.VK_END: locationController.shiftRangeFarRight(); evt.consume(); break; } } } }); add(locationField); locationField.setToolTipText("Current display range"); locationField.setPreferredSize(LOCATION_SIZE); locationField.setMaximumSize(LOCATION_SIZE); locationField.setMinimumSize(LOCATION_SIZE); add(getRigidPadding()); JButton goButton = (JButton) add(new JButton(" Go ")); goButton.putClientProperty("JButton.buttonType", buttonStyle); goButton.putClientProperty("JButton.segmentPosition", "only"); goButton.setToolTipText("Go to specified range (Enter)"); goButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setRangeFromText(locationField.getEditor().getItem().toString()); } }); add(getRigidPadding()); JLabel l = new JLabel("Length: "); add(l); lengthLabel = (JLabel) add(new JLabel()); lengthLabel.setToolTipText("Length of the current range"); lengthLabel.setPreferredSize(LENGTH_SIZE); lengthLabel.setMaximumSize(LENGTH_SIZE); lengthLabel.setMinimumSize(LENGTH_SIZE); add(Box.createGlue()); double screenwidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); JButton afterGo = null; //if (screenwidth > 800) { final JButton undoButton = (JButton) add(new JButton("")); afterGo = undoButton; undoButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.UNDO)); undoButton.setToolTipText("Undo range change (" + shortcutMod + "+Z)"); undoButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.undoLocationChange(); } }); undoButton.putClientProperty("JButton.buttonType", buttonStyle); undoButton.putClientProperty("JButton.segmentPosition", "first"); undoButton.setPreferredSize(ICON_SIZE); undoButton.setMinimumSize(ICON_SIZE); undoButton.setMaximumSize(ICON_SIZE); final JButton redo = (JButton) add(new JButton("")); redo.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.REDO)); redo.setToolTipText("Redo range change (" + shortcutMod + "+Y)"); redo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.redoLocationChange(); } }); redo.putClientProperty("JButton.buttonType", buttonStyle); redo.putClientProperty("JButton.segmentPosition", "last"); redo.setPreferredSize(ICON_SIZE); redo.setMinimumSize(ICON_SIZE); redo.setMaximumSize(ICON_SIZE); //} add(getRigidPadding()); add(getRigidPadding()); final JButton zoomInButton = (JButton) add(new JButton()); if (afterGo == null) { afterGo = zoomInButton; } zoomInButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.ZOOMIN)); zoomInButton.putClientProperty("JButton.buttonType", buttonStyle); zoomInButton.putClientProperty("JButton.segmentPosition", "first"); zoomInButton.setPreferredSize(ICON_SIZE); zoomInButton.setMinimumSize(ICON_SIZE); zoomInButton.setMaximumSize(ICON_SIZE); zoomInButton.setToolTipText("Zoom in (Shift+Up)"); zoomInButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.zoomIn(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "zoomed"), new NameValuePair("navigation-direction", "in"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton zoomOut = (JButton) add(new JButton("")); zoomOut.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.ZOOMOUT)); zoomOut.setToolTipText("Zoom out (Shift+Down)"); zoomOut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.zoomOut(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "zoomed"), new NameValuePair("navigation-direction", "out"), new NameValuePair("navigation-modality", "navbar") }); } }); zoomOut.putClientProperty("JButton.buttonType", buttonStyle); zoomOut.putClientProperty("JButton.segmentPosition", "last"); zoomOut.setPreferredSize(ICON_SIZE); zoomOut.setMinimumSize(ICON_SIZE); zoomOut.setMaximumSize(ICON_SIZE); add(getRigidPadding()); add(getRigidPadding()); final JButton shiftFarLeft = (JButton) add(new JButton()); shiftFarLeft.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_FARLEFT)); shiftFarLeft.putClientProperty("JButton.buttonType", buttonStyle); shiftFarLeft.putClientProperty("JButton.segmentPosition", "first"); shiftFarLeft.setToolTipText("Move to the beginning of the genome (Shift+Home)"); shiftFarLeft.setPreferredSize(ICON_SIZE); shiftFarLeft.setMinimumSize(ICON_SIZE); shiftFarLeft.setMaximumSize(ICON_SIZE); shiftFarLeft.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeFarLeft(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "left"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton shiftLeft = (JButton) add(new JButton()); shiftLeft.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_LEFT)); shiftLeft.putClientProperty("JButton.buttonType", buttonStyle); shiftLeft.putClientProperty("JButton.segmentPosition", "middle"); shiftLeft.setToolTipText("Move left (Shift+Left)"); shiftLeft.setPreferredSize(ICON_SIZE); shiftLeft.setMinimumSize(ICON_SIZE); shiftLeft.setMaximumSize(ICON_SIZE); shiftLeft.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeLeft(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "left"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton shiftRight = (JButton) add(new JButton()); shiftRight.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_RIGHT)); shiftRight.putClientProperty("JButton.buttonType", buttonStyle); shiftRight.putClientProperty("JButton.segmentPosition", "middle"); shiftRight.setToolTipText("Move right (Shift+Right)"); shiftRight.setPreferredSize(ICON_SIZE); shiftRight.setMinimumSize(ICON_SIZE); shiftRight.setMaximumSize(ICON_SIZE); shiftRight.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeRight(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "right"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton shiftFarRight = (JButton) add(new JButton()); shiftFarRight .setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_FARRIGHT)); shiftFarRight.putClientProperty("JButton.buttonType", buttonStyle); shiftFarRight.putClientProperty("JButton.segmentPosition", "last"); shiftFarRight.setToolTipText("Move to the end of the genome (Shift+End)"); shiftFarRight.setPreferredSize(ICON_SIZE); shiftFarRight.setMinimumSize(ICON_SIZE); shiftFarRight.setMaximumSize(ICON_SIZE); shiftFarRight.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeFarRight(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "right"), new NameValuePair("navigation-modality", "navbar") }); } }); add(getRigidPadding()); locationController.addListener(new Listener<LocationChangedEvent>() { @Override public void handleEvent(LocationChangedEvent event) { updateLocation(event.getReference(), (Range) event.getRange()); } }); // When the genome changes, we may need to invalidate our menu. GenomeController.getInstance().addListener(new Listener<GenomeChangedEvent>() { @Override public void handleEvent(GenomeChangedEvent event) { lastPoppedUp = "INVALID"; } }); this.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent ce) { int width = ce.getComponent().getWidth(); undoButton.setVisible(true); redo.setVisible(true); zoomInButton.setVisible(true); zoomOut.setVisible(true); shiftFarLeft.setVisible(true); shiftLeft.setVisible(true); shiftRight.setVisible(true); shiftFarRight.setVisible(true); // hide some components if the window isn't wide enough if (width < 1200) { undoButton.setVisible(false); redo.setVisible(false); } if (width < 1000) { shiftFarLeft.setVisible(false); shiftFarRight.setVisible(false); shiftRight.putClientProperty("JButton.segmentPosition", "last"); shiftLeft.putClientProperty("JButton.segmentPosition", "first"); } else { shiftRight.putClientProperty("JButton.segmentPosition", "middle"); shiftLeft.putClientProperty("JButton.segmentPosition", "middle"); } } public void componentMoved(ComponentEvent ce) { } @Override public void componentShown(ComponentEvent ce) { } @Override public void componentHidden(ComponentEvent ce) { } }); }
From source file:studio.ui.Studio.java
public Studio(AppConfig config, String... args) { super(AppInformation.getInformation().getTitle()); setIconImage(IconsItem.IMAGE_APP);/*from ww w .j a v a2s . c o m*/ enableEvents(AWTEvent.WINDOW_EVENT_MASK); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setSize((int) (0.9 * screenSize.width), (int) (0.9 * screenSize.height)); setLocation(((int) Math.max(0, (screenSize.width - getWidth()) / 2.0)), (int) (Math.max(0, (screenSize.height - getHeight()) / 2.0))); this.studioConfig = config; if (studioConfig.isMaximized()) { setExtendedState(JFrame.MAXIMIZED_BOTH); //Maximizing the frame } addWindowStateListener(this); registerForMacOSXEvents(); splitViewer = new JSplitPane(); splitTopViewer = new JSplitPane(); tabConsoles = new ConsolesTabbedPane(); tabConsoles.addFireDataListener(this); tabEditors = new EditorsTabbedPane(tabConsoles); tabEditors.addFireDataListener(this); if (tabConsoles instanceof DataListener) { tabEditors.addFireDataListener((DataListener) tabConsoles); } tools = new ToolsPanel(); splitViewer.setOrientation(JSplitPane.VERTICAL_SPLIT); splitViewer.setDividerSize(0); splitViewer.setTopComponent(splitTopViewer); splitViewer.setBottomComponent(tabConsoles); splitViewer.setOneTouchExpandable(true); splitTopViewer.setOrientation(JSplitPane.HORIZONTAL_SPLIT); splitTopViewer.setDividerSize(9); splitTopViewer.setTopComponent(tools); splitTopViewer.setBottomComponent(tabEditors); splitTopViewer.setOneTouchExpandable(true); createConnectionsTree(); createProjectsTree(); rebuildMenus(null); getContentPane().add(splitViewer, BorderLayout.CENTER); splitViewer.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent event) { if (event.getComponent() instanceof JSplitPane) { if (((JSplitPane) event.getComponent()).getDividerSize() == 0) { ((JSplitPane) event.getComponent()).setDividerLocation(1d); } } } }); this.setVisible(true); splitTopViewer.setDividerLocation(.2d); splitViewer.setDividerLocation(1d); NewFileAction newAction = null; OpenFileAction openAction = null; ToolBarActions toolbar = appToolbar != null ? appToolbar.getToolBar("File") : null; if (toolbar != null) { for (int count = 0; count < toolbar.getComponentCount(); count++) { if (toolbar.getComponent(count) instanceof JButton) { if (((JButton) toolbar.getComponent(count)).getAction().getClass() == OpenFileAction.class) { openAction = (OpenFileAction) ((JButton) toolbar.getComponent(count)).getAction(); } else { if (((JButton) toolbar.getComponent(count)).getAction().getClass() == NewFileAction.class) { newAction = (NewFileAction) ((JButton) toolbar.getComponent(count)).getAction(); } } if (openAction != null && newAction != null) { break; } } } } EditorFile last = null; if (config.getLastFiles() != null && !config.getLastFiles().isEmpty()) { for (EditorFile file : config.getLastFiles()) { if (file.isActive()) { last = file; } try { openAction.initDocument(file); } catch (FileException ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "File", JOptionPane.WARNING_MESSAGE); } } } else { if (args == null || args.length == 0) { newAction.actionPerformed(null); } } if (args != null && args.length > 0) { for (String arg : args) { File file = new File(arg); if (file.exists() && file.canRead()) { try { openAction.initDocument(new EditorFile(file)); } catch (FileException ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "File", JOptionPane.WARNING_MESSAGE); } } } } if (tabEditors.getTabCount() > 0) { if (last == null) { tabEditors.setSelectedIndex(0); } else { for (int count = 0; count < tabEditors.getTabCount(); count++) { if (tabEditors.getEditor(count).getFile().equals(last)) { tabEditors.setSelectedIndex(count); } } } tabEditors.getEditor().requestFocusInWindow(); } ActionBase action = new ActionBase(null, (char) 0, null, null, null, null) { private static final long serialVersionUID = -1752094455650906542L; @Override public void actionPerformed(ActionEvent event) { treeConnections.requestFocus(); } }; splitViewer.registerKeyboardAction(action, KeyStroke.getKeyStroke("F5"), JComponent.WHEN_IN_FOCUSED_WINDOW); splitViewer.registerKeyboardAction(action, KeyStroke.getKeyStroke("control F5"), JComponent.WHEN_IN_FOCUSED_WINDOW); action = new ActionBase(null, (char) 0, null, null, null, null) { private static final long serialVersionUID = -1752094455650906542L; @Override public void actionPerformed(ActionEvent event) { if (tabEditors.getTabCount() > 0) { tabEditors.requestFocus(); tabEditors.getEditor().requestFocus(); } } }; splitViewer.registerKeyboardAction(action, KeyStroke.getKeyStroke("F3"), JComponent.WHEN_IN_FOCUSED_WINDOW); splitViewer.registerKeyboardAction(action, KeyStroke.getKeyStroke("control F3"), JComponent.WHEN_IN_FOCUSED_WINDOW); action = new ActionBase(null, (char) 0, null, null, null, null) { private static final long serialVersionUID = -7472441241172668338L; @Override public void actionPerformed(ActionEvent event) { treeProjects.requestFocus(); } }; splitViewer.registerKeyboardAction(action, KeyStroke.getKeyStroke("F6"), JComponent.WHEN_IN_FOCUSED_WINDOW); splitViewer.registerKeyboardAction(action, KeyStroke.getKeyStroke("control F6"), JComponent.WHEN_IN_FOCUSED_WINDOW); action = new ActionBase(null, (char) 0, null, null, null, null) { private static final long serialVersionUID = -1752094455650906542L; @Override public void actionPerformed(ActionEvent event) { if (tabConsoles.getTabCount() > 0) { tabConsoles.requestFocus(); if (tabConsoles.getSelectedIndex() != -1) { tabConsoles.getComponentAt(tabConsoles.getSelectedIndex()).requestFocus(); } } } }; splitViewer.registerKeyboardAction(action, KeyStroke.getKeyStroke("F4"), JComponent.WHEN_IN_FOCUSED_WINDOW); splitViewer.registerKeyboardAction(action, KeyStroke.getKeyStroke("control F4"), JComponent.WHEN_IN_FOCUSED_WINDOW); action = new WindowsListAction(tabEditors); splitViewer.registerKeyboardAction(action, action.getAccelerator(), JComponent.WHEN_IN_FOCUSED_WINDOW); }