List of usage examples for java.awt KeyboardFocusManager FORWARD_TRAVERSAL_KEYS
int FORWARD_TRAVERSAL_KEYS
To view the source code for java.awt KeyboardFocusManager FORWARD_TRAVERSAL_KEYS.
Click Source Link
From source file:forge.itemmanager.views.ItemListView.java
/** * ItemTable Constructor.// w ww . j a va 2 s . co m * * @param itemManager0 * @param model0 */ public ItemListView(final ItemManager<T> itemManager0, final ItemManagerModel<T> model0) { super(itemManager0, model0); this.tableModel = new ItemTableModel(model0); this.setAllowMultipleSelections(false); this.getPnlOptions().setVisible(false); //hide options panel by default // use different selection highlight colors for focused vs. unfocused tables this.table.addMouseListener(new FMouseAdapter() { @Override public void onLeftDoubleClick(final MouseEvent e) { if (e.isConsumed()) { return; } //don't activate if inline button double clicked final int clickedIndex = table.rowAtPoint(e.getPoint()); itemManager.activateSelectedItems(); if (clickedIndex >= table.getRowCount()) { FMouseAdapter.forceMouseUp(); //prevent mouse getting stuck if final row removed from double click handling } } @Override public void onRightClick(final MouseEvent e) { itemManager.showContextMenu(e); } }); // prevent tables from intercepting tab focus traversals this.table.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null); this.table.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null); }
From source file:eu.ggnet.dwoss.receipt.unit.UnitView.java
public UnitView(Window window) { super(window); initComponents();//from w w w . ja v a 2 s . c o m setModalityType(ModalityType.APPLICATION_MODAL); setLocationRelativeTo(window); Client.lookup(UserPreferences.class).loadLocation(this); // Setting the change also in the subcomponent. FocusListener does not work completely. mfgDateChooser.addPropertyChangeListener(mfgProperty); mfgDateChooser.getDateEditor().getUiComponent().addPropertyChangeListener(mfgProperty); warrantyTillChooser.addPropertyChangeListener(warrantyProperty); warrantyTillChooser.getDateEditor().getUiComponent().addPropertyChangeListener(warrantyProperty); editRefurbishedIdButton.setEnabled(false); equipmentTable.setModel(equipmentModel); equipmentModel.setTable(equipmentTable); commentTable.setModel(commentModel); commentModel.setTable(commentTable); internalCommentTable.setModel(internalCommentModel); internalCommentModel.setTable(internalCommentTable); conditionController = new ComboBoxController<>(unitStateBox, UniqueUnit.Condition.values()); warrantyController = new ComboBoxController<>(warrantyTypeChooser, Warranty.values()); warrantyTypeChooser.setRenderer(new NamedEnumCellRenderer()); unitStateBox.setRenderer(new NamedEnumCellRenderer()); unitStateBox.setModel(new DefaultComboBoxModel(UniqueUnit.Condition.values())); refurbishedIdField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, new HashSet<>( Arrays.asList(KeyStroke.getKeyStroke("pressed ENTER"), KeyStroke.getKeyStroke("pressed TAB")))); serialField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, new HashSet<>( Arrays.asList(KeyStroke.getKeyStroke("pressed ENTER"), KeyStroke.getKeyStroke("pressed TAB")))); UiUtil.forwardTab(partNoField, unitStateBox, internalCommentArea, commentArea); UiUtil.backwardTab(refurbishedIdField, serialField, partNoField, unitStateBox); UiUtil.spaceSelection(equipmentTable); UiUtil.spaceSelection(internalCommentTable); UiUtil.spaceSelection(commentTable); refurbishedIdField.requestFocus(); contractorBox.setRenderer(new NamedEnumCellRenderer()); contractorBox.setModel(new DefaultComboBoxModel(TradeName.getManufacturers().toArray())); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java
/** * Adds Up/Down Focus Traversal Keys to the form. */// w w w . ja v a 2s . co m protected void addArrowTraversalKeys() { Set<AWTKeyStroke> set = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); KeyStroke forward = KeyStroke.getKeyStroke("DOWN"); set = new HashSet<AWTKeyStroke>(set); set.add(forward); setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set); set = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); KeyStroke backward = KeyStroke.getKeyStroke("UP"); set = new HashSet<AWTKeyStroke>(set); set.add(backward); setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set); }
From source file:net.sf.jabref.EntryEditor.java
/** * NOTE: This method is only used for the source panel, not for the * other tabs. Look at EntryEditorTab for the setup of text components * in the other tabs./*from w ww.ja va 2 s . c o m*/ */ private void setupJTextFieldForSourceArea(JTextComponent ta) { setupSwingComponentKeyBindings(ta); // HashSet<AWTKeyStroke> keys = new HashSet<AWTKeyStroke>(ta.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); HashSet<AWTKeyStroke> keys = new HashSet<AWTKeyStroke>(); keys.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB")); ta.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys); // keys = new HashSet<AWTKeyStroke>(ta.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); keys = new HashSet<AWTKeyStroke>(); keys.add(KeyStroke.getKeyStroke("shift pressed TAB")); ta.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys); ta.addFocusListener(new FieldListener()); }
From source file:net.sf.jabref.gui.entryeditor.EntryEditor.java
/** * NOTE: This method is only used for the source panel, not for the * other tabs. Look at EntryEditorTab for the setup of text components * in the other tabs./*w ww . ja v a2 s . c om*/ */ private void setupJTextComponent(JTextComponent textComponent) { // Set up key bindings and focus listener for the FieldEditor. InputMap inputMap = textComponent.getInputMap(JComponent.WHEN_FOCUSED); ActionMap actionMap = textComponent.getActionMap(); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store"); actionMap.put("store", getStoreFieldAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL), "right"); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL_2), "right"); actionMap.put("right", getSwitchRightAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL), "left"); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL_2), "left"); actionMap.put("left", getSwitchLeftAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help"); actionMap.put("help", getHelpAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE), "save"); actionMap.put("save", getSaveDatabaseAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB), "nexttab"); actionMap.put("nexttab", frame.nextTab); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_TAB), "prevtab"); actionMap.put("prevtab", frame.prevTab); Set<AWTKeyStroke> keys = new HashSet<>( textComponent.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); keys.clear(); keys.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB")); textComponent.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys); keys = new HashSet<>(textComponent.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); keys.clear(); keys.add(KeyStroke.getKeyStroke("shift pressed TAB")); textComponent.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys); textComponent.addFocusListener(new FieldListener()); }
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
public JPanel createDetailsView() { final VFSJFileChooser chooser = getFileChooser(); JPanel p = new JPanel(new BorderLayout()); final JTable detailsTable = new JTable(getDetailsTableModel()) { // Handle Escape key events here @Override// ww w . j a v a2 s. co m protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) && (getCellEditor() == null)) { // We are not editing, forward to filechooser. chooser.dispatchEvent(e); return true; } return super.processKeyBinding(ks, e, condition, pressed); } @Override public void tableChanged(TableModelEvent e) { super.tableChanged(e); if (e.getFirstRow() == TableModelEvent.HEADER_ROW) { // update header with possibly changed column set updateDetailsColumnModel(this); } } }; // detailsTable.setRowSorter(getRowSorter()); detailsTable.setAutoCreateColumnsFromModel(false); detailsTable.setComponentOrientation(chooser.getComponentOrientation()); //detailsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); detailsTable.setShowGrid(false); detailsTable.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); // detailsTable.addKeyListener(detailsKeyListener); Font font = list.getFont(); detailsTable.setFont(font); detailsTable.setIntercellSpacing(new Dimension(0, 0)); TableCellRenderer headerRenderer = new AlignableTableHeaderRenderer( detailsTable.getTableHeader().getDefaultRenderer()); detailsTable.getTableHeader().setDefaultRenderer(headerRenderer); TableCellRenderer cellRenderer = new DetailsTableCellRenderer(chooser); detailsTable.setDefaultRenderer(Object.class, cellRenderer); // So that drag can be started on a mouse press detailsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); detailsTable.addMouseListener(getMouseHandler()); // No need to addListSelectionListener because selections are forwarded // to our JList. // 4835633 : tell BasicTableUI that this is a file list detailsTable.putClientProperty("Table.isFileList", Boolean.TRUE); if (listViewWindowsStyle) { detailsTable.addFocusListener(repaintListener); } JTableHeader header = detailsTable.getTableHeader(); header.setUpdateTableInRealTime(true); header.addMouseListener(detailsTableModel.new ColumnListener()); header.setReorderingAllowed(true); // TAB/SHIFT-TAB should transfer focus and ENTER should select an item. // We don't want them to navigate within the table ActionMap am = SwingUtilities.getUIActionMap(detailsTable); am.remove("selectNextRowCell"); am.remove("selectPreviousRowCell"); am.remove("selectNextColumnCell"); am.remove("selectPreviousColumnCell"); detailsTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null); detailsTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null); JScrollPane scrollpane = new JScrollPane(detailsTable); scrollpane.setComponentOrientation(chooser.getComponentOrientation()); LookAndFeel.installColors(scrollpane.getViewport(), "Table.background", "Table.foreground"); // Adjust width of first column so the table fills the viewport when // first displayed (temporary listener). scrollpane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { JScrollPane sp = (JScrollPane) e.getComponent(); fixNameColumnWidth(sp.getViewport().getSize().width); sp.removeComponentListener(this); } }); // 4835633. // If the mouse is pressed in the area below the Details view table, the // event is not dispatched to the Table MouseListener but to the // scrollpane. Listen for that here so we can clear the selection. scrollpane.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { JScrollPane jsp = ((JScrollPane) e.getComponent()); JTable table = (JTable) jsp.getViewport().getView(); if (!e.isShiftDown() || (table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) { clearSelection(); TableCellEditor tce = table.getCellEditor(); if (tce != null) { tce.stopCellEditing(); } } } }); detailsTable.setForeground(list.getForeground()); detailsTable.setBackground(list.getBackground()); if (listViewBorder != null) { scrollpane.setBorder(listViewBorder); } p.add(scrollpane, BorderLayout.CENTER); detailsTableModel.fireTableStructureChanged(); return p; }
From source file:com.osparking.osparking.Settings_System.java
private void makeEnterActAsTab() { KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); KeyStroke ctrlTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK); Set<KeyStroke> keys = new HashSet<>(); keys.add(enter);/*from w w w .ja v a2 s .com*/ keys.add(tab); keys.add(ctrlTab); KeyboardFocusManager.getCurrentKeyboardFocusManager() .setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys); }
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 .ja v a 2 s . c o m 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:visolate.Main.java
public static void main(final String[] argv) { CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("x", "flip-x", false, "flip around x axis"); options.addOption("y", "flip-y", false, "flip around y axis"); options.addOption("a", "absolute", false, "use absolute cooridnates"); options.addOption("d", "dpi", true, "dpi to use for rastering"); options.addOption("A", "auto", false, "auto-mode (run, save and exit)"); options.addOption("o", "outfile", true, "name of output file"); options.addOption("h", "help", false, "display this help and exit"); options.addOption("V", "version", false, "output version information and exit"); CommandLine commandline;/* w w w . j a va 2 s .com*/ try { commandline = parser.parse(options, argv); } catch (ParseException e) { System.err.println(e.getLocalizedMessage()); System.exit(1); return; // make it clear to the compiler that the following code is not run } if (commandline.hasOption("version")) { System.out.println(APPNAME); return; } if (commandline.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("visolate [options] [filename]", options); return; } if (commandline.getArgs().length >= 2) { System.err.println("Error: Too many arguments."); System.exit(1); } try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //TODO: Make look and feel options } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { // TODO Auto-generated catch block e.printStackTrace(); } final JFrame frame = new JFrame(APPNAME); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(DEF_LOC_X, DEF_LOC_Y); // Add the Enter key to the forward traversal keys, so fields loose focus // when using it in a field and we don't need to set up both, an ActionListener // and a FocusListener for each text/number field. Set<AWTKeyStroke> forwardKeys = new HashSet<AWTKeyStroke>( frame.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); Set<AWTKeyStroke> newForwardKeys = new HashSet<AWTKeyStroke>(forwardKeys); newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); frame.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys); final Visolate visolate = new Visolate(); visolate.commandline = commandline; Container contentPane = frame.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(visolate, "Center"); contentPane.setBackground(Color.WHITE); SwingUtilities.invokeLater(new Runnable() { public void run() { frame.pack(); frame.setVisible(true); if (visolate.commandline.getArgs().length == 1) { visolate.loadFile(new File(visolate.commandline.getArgs()[0])); } else { visolate.loadDemo(); } if (visolate.commandline.hasOption("auto")) { System.out.println("Automatic processing enabled! Files will be overwritten without asking!"); visolate.auto_mode = true; } if (visolate.commandline.hasOption("dpi")) { visolate.getDisplay().setDPI(Integer.parseInt(visolate.commandline.getOptionValue("dpi"))); } if (visolate.commandline.hasOption("flip-x")) { visolate.model.setFlipX(true); } if (visolate.commandline.hasOption("flip-y")) { visolate.model.setFlipY(true); } if (visolate.commandline.hasOption("absolute")) { visolate.setAbsoluteCoordinates(true); } if (visolate.commandline.hasOption("outfile")) { visolate.setGcodeFile(visolate.commandline.getOptionValue("outfile")); } if (visolate.commandline.hasOption("auto")) { System.out.println("now starting fixing topology due to automatic mode"); visolate.processstatus = 1; visolate.fixTopology(); // fix.Topology() calls visolate.processFinished after its done. Also, the Toolpathprocessor does so. processstatus discriminates this. } visolate.model.rebuild(); } }); }