List of usage examples for java.awt.event KeyEvent VK_RIGHT
int VK_RIGHT
To view the source code for java.awt.event KeyEvent VK_RIGHT.
Click Source Link
From source file:oct.analysis.application.OCTAnalysisUI.java
private void octAnalysisPanelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_octAnalysisPanelKeyPressed OCTSelection sel = null;// w ww . j ava 2 s.c o m //determine direction to move the selection switch (evt.getKeyCode()) { case KeyEvent.VK_RIGHT: switch (analysisMngr.getAnalysisMode()) { case MIRROR: sel = selectionLRPManager.getSelectedSelection(); if (sel.getSelectionName().equals("Left")) { //move left selection to the right and right selection to the left (i.e. move them closer to fovea selection) selectionLRPManager.moveSelectionRight(sel); sel = selectionLRPManager.getSelections().stream() .filter(s -> s.getSelectionName().equals("Right")).findFirst().get(); selectionLRPManager.moveSelectionLeft(sel); } else { //move left selection to the left and right selection to the right (i.e. move them away from the fovea selection) selectionLRPManager.moveSelectionRight(sel); sel = selectionLRPManager.getSelections().stream() .filter(s -> s.getSelectionName().equals("Left")).findFirst().get(); selectionLRPManager.moveSelectionLeft(sel); } break; case SINGLE: case EZ: sel = selectionLRPManager.getSelectedSelection(); if (sel.isMoveable()) { selectionLRPManager.moveSelectionRight(sel); } break; default: break; } break; case KeyEvent.VK_LEFT: switch (analysisMngr.getAnalysisMode()) { case MIRROR: sel = selectionLRPManager.getSelectedSelection(); if (sel.getSelectionName().equals("Right")) { //move left selection to the right and right selection to the left (i.e. move them closer to fovea selection) selectionLRPManager.moveSelectionLeft(sel); sel = selectionLRPManager.getSelections().stream() .filter(s -> s.getSelectionName().equals("Left")).findFirst().get(); selectionLRPManager.moveSelectionRight(sel); } else { //move left selection to the left and right selection to the right (i.e. move them away from the fovea selection) selectionLRPManager.moveSelectionLeft(sel); sel = selectionLRPManager.getSelections().stream() .filter(s -> s.getSelectionName().equals("Right")).findFirst().get(); selectionLRPManager.moveSelectionRight(sel); } break; case SINGLE: case EZ: sel = selectionLRPManager.getSelectedSelection(); if (sel.isMoveable()) { selectionLRPManager.moveSelectionRight(sel); } break; default: break; } break; default: break; } //refresh the OCT analysis panel with the updated selection information octAnalysisPanel.repaint(); }
From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowser.java
/** * Sets the properties and adds the listeners for the Message Table. No data is loaded at this * point.//from w ww.j a va2 s.c o m */ private void makeMessageTable() { messageTreeTable.setDragEnabled(true); messageTreeTable.setSortable(false); messageTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); messageTreeTable.setColumnFactory(new MessageBrowserTableColumnFactory()); messageTreeTable.setLeafIcon(null); messageTreeTable.setOpenIcon(null); messageTreeTable.setClosedIcon(null); messageTreeTable.setAutoCreateColumnsFromModel(false); messageTreeTable.setMirthColumnControlEnabled(true); messageTreeTable.setShowGrid(true, true); messageTreeTable.setHorizontalScrollEnabled(true); messageTreeTable.setPreferredScrollableViewportSize(messageTreeTable.getPreferredSize()); messageTreeTable.setMirthTransferHandlerEnabled(true); tableModel = new MessageBrowserTableModel(columnMap.size()); // Add a blank column to the column initially, otherwise it return an exception on load // Columns will be re-generated when the message browser is viewed tableModel.setColumnIdentifiers(Arrays.asList(new String[] { "" })); messageTreeTable.setTreeTableModel(tableModel); // Sets the alternating highlighter for the table if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR); messageTreeTable.setHighlighters(highlighter); } // Add the listener for when the table selection changes messageTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { MessageListSelected(evt); } }); // Add the mouse listener messageTreeTable.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { checkMessageSelectionAndPopupMenu(evt); } public void mouseReleased(java.awt.event.MouseEvent evt) { checkMessageSelectionAndPopupMenu(evt); } // Opens the send message dialog when a message is double clicked. // If the root message or source connector is selected, select all destination connectors initially // If a destination connector is selected, select only that destination connector initially public void mouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() >= 2) { int row = getSelectedMessageIndex(); if (row >= 0) { MessageBrowserTableNode messageNode = (MessageBrowserTableNode) messageTreeTable .getPathForRow(row).getLastPathComponent(); if (messageNode.isNodeActive()) { Long messageId = messageNode.getMessageId(); Integer metaDataId = messageNode.getMetaDataId(); Message currentMessage = messageCache.get(messageId); ConnectorMessage connectorMessage = currentMessage.getConnectorMessages() .get(metaDataId); List<Integer> selectedMetaDataIds = new ArrayList<Integer>(); Map<String, Object> sourceMap = new HashMap<String, Object>(); if (connectorMessage.getSourceMap() != null) { sourceMap.putAll(connectorMessage.getSourceMap()); // Remove the destination set if it exists, because that will be determined by the selected metadata IDs sourceMap.remove("destinationSet"); } if (metaDataId == 0) { selectedMetaDataIds = null; } else { selectedMetaDataIds.add(metaDataId); } if (connectorMessage.getRaw() != null) { parent.editMessageDialog.setPropertiesAndShow( connectorMessage.getRaw().getContent(), connectorMessage.getRaw().getDataType(), channelId, parent.dashboardPanel.getDestinationConnectorNames(channelId), selectedMetaDataIds, sourceMap); } } } } } }); // Key Listener trigger for DEL messageTreeTable.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int row = getSelectedMessageIndex(); if (row >= 0) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { MessageBrowserTableNode messageNode = (MessageBrowserTableNode) messageTreeTable .getPathForRow(row).getLastPathComponent(); if (messageNode.isNodeActive()) { parent.doRemoveMessage(); } } else if (descriptionTabbedPane.getTitleAt(descriptionTabbedPane.getSelectedIndex()) .equals("Messages")) { if (e.getKeyCode() == KeyEvent.VK_LEFT) { List<AbstractButton> buttons = Collections.list(messagesGroup.getElements()); boolean passedSelected = false; for (int i = buttons.size() - 1; i >= 0; i--) { AbstractButton button = buttons.get(i); if (passedSelected && button.isShowing()) { lastUserSelectedMessageType = buttons.get(i).getText(); updateMessageRadioGroup(); break; } else if (button.isSelected()) { passedSelected = true; } } } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { List<AbstractButton> buttons = Collections.list(messagesGroup.getElements()); boolean passedSelected = false; for (int i = 0; i < buttons.size(); i++) { AbstractButton button = buttons.get(i); if (passedSelected && button.isShowing()) { lastUserSelectedMessageType = buttons.get(i).getText(); updateMessageRadioGroup(); break; } else if (button.isSelected()) { passedSelected = true; } } } } } } }); }
From source file:Report_PRCR_New_EPF_Excel_File_Generator.java
private void monthfield1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_monthfield1KeyPressed if (monthfield1.getText().equals("Jan")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Dec"); int yr = Integer.parseInt(yearfield.getText()); yearfield1.setText("" + (yr - 1)); monthfield1.selectAll();/*ww w. j ava 2 s .com*/ } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Feb"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("Feb")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Jan"); int yr = Integer.parseInt(yearfield.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Mar"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("Mar")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Feb"); int yr = Integer.parseInt(yearfield1.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Apr"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("Apr")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Mar"); int yr = Integer.parseInt(yearfield1.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("May"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("May")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Apr"); int yr = Integer.parseInt(yearfield1.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Jun"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("Jun")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("May"); int yr = Integer.parseInt(yearfield1.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Jul"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("Jul")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Jun"); int yr = Integer.parseInt(yearfield1.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Aug"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("Aug")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Jul"); int yr = Integer.parseInt(yearfield1.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Sep"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("Sep")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Aug"); int yr = Integer.parseInt(yearfield1.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Oct"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("Oct")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Sep"); int yr = Integer.parseInt(yearfield1.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Nov"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("Nov")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Oct"); int yr = Integer.parseInt(yearfield1.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Dec"); monthfield1.selectAll(); } } else if (monthfield1.getText().equals("Dec")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield1.setText("Nov"); int yr = Integer.parseInt(yearfield1.getText()); monthfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield1.setText("Jan"); int yr = Integer.parseInt(yearfield1.getText()); yearfield1.setText("" + (yr + 1)); monthfield1.selectAll(); } } if (evt.getKeyCode() == KeyEvent.VK_LEFT) { dayfield.requestFocus(); dayfield.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_RIGHT) { yearfield1.requestFocus(); yearfield1.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_ENTER) { ////// ChaNGE focus on enter//////////////// // recieptNo.requestFocus(); } }
From source file:Report_PRCR_New_EPF_Excel_File_Generator.java
private void dayfieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dayfieldKeyPressed /////////////////////////////////////////////////// Days Decrement///////////////////////////////////////////////////////////////////////////// if (dayfield.getText().equals("1")) { // Jumping to 31 and 30 from 1st if (evt.getKeyCode() == KeyEvent.VK_DOWN) { if (monthfield.getText().equals("Feb") || monthfield.getText().equals("Apr") || monthfield.getText().equals("Jun") || monthfield.getText().equals("Aug") || monthfield.getText().equals("Sep") || monthfield.getText().equals("Nov") || monthfield.getText().equals("Feb")) { dayfield.setText("31"); int mnth = datechooser.return_index(monthfield.getText()); monthfield.setText(datechooser.Return_month(mnth - 1)); } else if (monthfield.getText().equals("May") || monthfield.getText().equals("Jul") || monthfield.getText().equals("Oct") || monthfield.getText().equals("Dec")) { dayfield.setText("30"); int mnth = datechooser.return_index(monthfield.getText()); monthfield.setText(datechooser.Return_month(mnth - 1)); } else if (monthfield.getText().equals("Mar")) { // from march 1st jump to 28th or 29th checking leap years int yr = Integer.parseInt(yearfield.getText()); if (yr % 4 == 0) { if (yr % 100 == 0) { if (yr % 400 == 0) { dayfield.setText("29"); // Leap Year }//from ww w. ja v a2s . c o m } if (yr % 100 == 0) { if (yr % 400 != 0) { dayfield.setText("28"); // not a leap year } } dayfield.setText("29"); // leap year } if (yr % 4 != 0) { dayfield.setText("28"); // not a leap year } int mnth = datechooser.return_index(monthfield.getText()); monthfield.setText(datechooser.Return_month(mnth - 1)); } else if (monthfield.getText().equals("Jan")) { // From jan 1st jump to december 31st decrementing year dayfield.setText("31"); int yr = Integer.parseInt(yearfield.getText()); monthfield.setText("Dec"); yearfield.setText("" + (yr - 1)); // year } dayfield.selectAll(); } // /// decrementing normal values } else if (dayfield.getText().equals("2") || dayfield.getText().equals("3") || dayfield.getText().equals("4") || dayfield.getText().equals("5") || dayfield.getText().equals("6") || dayfield.getText().equals("7") || dayfield.getText().equals("8") || dayfield.getText().equals("9") || dayfield.getText().equals("10") || dayfield.getText().equals("11") || dayfield.getText().equals("12") || dayfield.getText().equals("13") || dayfield.getText().equals("14") || dayfield.getText().equals("15") || dayfield.getText().equals("16") || dayfield.getText().equals("17") || dayfield.getText().equals("18") || dayfield.getText().equals("19") || dayfield.getText().equals("20") || dayfield.getText().equals("21") || dayfield.getText().equals("22") || dayfield.getText().equals("23") || dayfield.getText().equals("24") || dayfield.getText().equals("25") || dayfield.getText().equals("26") || dayfield.getText().equals("27") || dayfield.getText().equals("28") || dayfield.getText().equals("29") || dayfield.getText().equals("30") || dayfield.getText().equals("31")) { if (evt.getKeyCode() == KeyEvent.VK_DOWN) { dayfield.setText("" + (Integer.parseInt(dayfield.getText()) - 1)); dayfield.selectAll(); } } ///////////////////////////////////////////////// Days Increment/////////////////////////////////////////////////////////////////////////////////////////////////// if (dayfield.getText().equals("30")) { // from 30th to 1st of next month if (evt.getKeyCode() == KeyEvent.VK_UP) { if (monthfield.getText().equals("Apr") || monthfield.getText().equals("Jun") || monthfield.getText().equals("Sep") || monthfield.getText().equals("Nov")) { dayfield.setText("0"); int mnth = datechooser.return_index(monthfield.getText()); monthfield.setText(datechooser.Return_month(mnth + 1)); } dayfield.setText("" + (Integer.parseInt(dayfield.getText()) + 1)); dayfield.selectAll(); } } else if (dayfield.getText().equals("31")) { // from 31st to 1st of next month if (evt.getKeyCode() == KeyEvent.VK_UP) { if (monthfield.getText().equals("Jan") || monthfield.getText().equals("Mar") || monthfield.getText().equals("May") || monthfield.getText().equals("Jul") || monthfield.getText().equals("Aug") || monthfield.getText().equals("Oct")) { dayfield.setText("1"); int mnth = datechooser.return_index(monthfield.getText()); monthfield.setText(datechooser.Return_month(mnth + 1)); } else if (monthfield.getText().equals("Dec")) { // December to january incrementing the year dayfield.setText("1"); int yr = Integer.parseInt(yearfield.getText()); monthfield.setText("Jan"); yearfield.setText("" + (yr + 1)); } dayfield.selectAll(); } } else if (monthfield.getText().equals("Feb")) { // for february if (evt.getKeyCode() == KeyEvent.VK_UP) { if (dayfield.getText().equals("28")) { // at 28 check for leap year int yr = Integer.parseInt(yearfield.getText()); if (yr % 4 == 0) { if (yr % 100 == 0) { if (yr % 400 == 0) { dayfield.setText("29"); // Leap Year // increment to 29 } } if (yr % 100 == 0) { if (yr % 400 != 0) { dayfield.setText("1"); int mnth = datechooser.return_index(monthfield.getText()); monthfield.setText(datechooser.Return_month(mnth + 1)); // not a leap year // jump to next month } } dayfield.setText("29"); // leap year // increment to 29th } if (yr % 4 != 0) { dayfield.setText("1"); int mnth = datechooser.return_index(monthfield.getText()); monthfield.setText(datechooser.Return_month(mnth + 1)); // not a leap year } } else if (dayfield.getText().equals("29")) { // at 29 jump to next month normally dayfield.setText("1"); int mnth = datechooser.return_index(monthfield.getText()); monthfield.setText(datechooser.Return_month(mnth + 1)); // incrementing normal values/////////////////////// for february separately } else if (dayfield.getText().equals("1") || dayfield.getText().equals("2") || dayfield.getText().equals("3") || dayfield.getText().equals("4") || dayfield.getText().equals("5") || dayfield.getText().equals("6") || dayfield.getText().equals("7") || dayfield.getText().equals("8") || dayfield.getText().equals("9") || dayfield.getText().equals("10") || dayfield.getText().equals("11") || dayfield.getText().equals("12") || dayfield.getText().equals("13") || dayfield.getText().equals("14") || dayfield.getText().equals("15") || dayfield.getText().equals("16") || dayfield.getText().equals("17") || dayfield.getText().equals("18") || dayfield.getText().equals("19") || dayfield.getText().equals("20") || dayfield.getText().equals("21") || dayfield.getText().equals("22") || dayfield.getText().equals("23") || dayfield.getText().equals("24") || dayfield.getText().equals("25") || dayfield.getText().equals("26") || dayfield.getText().equals("27") || dayfield.getText().equals("28") || dayfield.getText().equals("29") || dayfield.getText().equals("30") || dayfield.getText().equals("31")) { dayfield.setText("" + (Integer.parseInt(dayfield.getText()) + 1)); } dayfield.selectAll(); } // incrementing normal values } else if (dayfield.getText().equals("1") || dayfield.getText().equals("2") || dayfield.getText().equals("3") || dayfield.getText().equals("4") || dayfield.getText().equals("5") || dayfield.getText().equals("6") || dayfield.getText().equals("7") || dayfield.getText().equals("8") || dayfield.getText().equals("9") || dayfield.getText().equals("10") || dayfield.getText().equals("11") || dayfield.getText().equals("12") || dayfield.getText().equals("13") || dayfield.getText().equals("14") || dayfield.getText().equals("15") || dayfield.getText().equals("16") || dayfield.getText().equals("17") || dayfield.getText().equals("18") || dayfield.getText().equals("19") || dayfield.getText().equals("20") || dayfield.getText().equals("21") || dayfield.getText().equals("22") || dayfield.getText().equals("23") || dayfield.getText().equals("24") || dayfield.getText().equals("25") || dayfield.getText().equals("26") || dayfield.getText().equals("27") || dayfield.getText().equals("28") || dayfield.getText().equals("29") || dayfield.getText().equals("30") || dayfield.getText().equals("31")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { dayfield.setText("" + (Integer.parseInt(dayfield.getText()) + 1)); dayfield.selectAll(); } } if (evt.getKeyCode() == KeyEvent.VK_RIGHT) { monthfield.requestFocus(); monthfield.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_ENTER) { } }
From source file:org.forester.archaeopteryx.TreePanel.java
final private void keyPressedCalls(final KeyEvent e) { if (isOvOn() && (getMousePosition() != null) && (getMousePosition().getLocation() != null)) { if (inOvVirtualRectangle(getMousePosition().x, getMousePosition().y)) { if (!isInOvRect()) { setInOvRect(true);/*from www . ja v a 2 s .c o m*/ } } else if (isInOvRect()) { setInOvRect(false); } } if (e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK) { if ((e.getKeyCode() == KeyEvent.VK_DELETE) || (e.getKeyCode() == KeyEvent.VK_HOME) || (e.getKeyCode() == KeyEvent.VK_F)) { getMainPanel().getTreeFontSet().mediumFonts(); getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(true); } else if ((e.getKeyCode() == KeyEvent.VK_SUBTRACT) || (e.getKeyCode() == KeyEvent.VK_MINUS)) { getMainPanel().getTreeFontSet().decreaseFontSize(); getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(true); } else if (plusPressed(e.getKeyCode())) { getMainPanel().getTreeFontSet().increaseFontSize(); getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(true); } } else { if ((e.getKeyCode() == KeyEvent.VK_DELETE) || (e.getKeyCode() == KeyEvent.VK_HOME) || (e.getKeyCode() == KeyEvent.VK_F)) { getControlPanel().showWhole(); } else if ((e.getKeyCode() == KeyEvent.VK_UP) || (e.getKeyCode() == KeyEvent.VK_DOWN) || (e.getKeyCode() == KeyEvent.VK_LEFT) || (e.getKeyCode() == KeyEvent.VK_RIGHT)) { if (e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK) { if (e.getKeyCode() == KeyEvent.VK_UP) { getMainPanel().getControlPanel().zoomInY(Constants.WHEEL_ZOOM_IN_FACTOR); getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false); } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { getMainPanel().getControlPanel().zoomOutY(Constants.WHEEL_ZOOM_OUT_FACTOR); getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false); } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { getMainPanel().getControlPanel().zoomOutX(Constants.WHEEL_ZOOM_OUT_FACTOR, Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR); getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false); } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { getMainPanel().getControlPanel().zoomInX(Constants.WHEEL_ZOOM_IN_FACTOR, Constants.WHEEL_ZOOM_IN_FACTOR); getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false); } } else { final int d = 80; int dx = 0; int dy = -d; if (e.getKeyCode() == KeyEvent.VK_DOWN) { dy = d; } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { dx = -d; dy = 0; } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { dx = d; dy = 0; } final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport() .getViewPosition(); scroll_position.x = scroll_position.x + dx; scroll_position.y = scroll_position.y + dy; if (scroll_position.x <= 0) { scroll_position.x = 0; } else { final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar() .getMaximum() - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount(); if (scroll_position.x >= max_x) { scroll_position.x = max_x; } } if (scroll_position.y <= 0) { scroll_position.y = 0; } else { final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum() - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount(); if (scroll_position.y >= max_y) { scroll_position.y = max_y; } } repaint(); getMainPanel().getCurrentScrollPane().getViewport().setViewPosition(scroll_position); } } else if ((e.getKeyCode() == KeyEvent.VK_SUBTRACT) || (e.getKeyCode() == KeyEvent.VK_MINUS)) { getMainPanel().getControlPanel().zoomOutY(Constants.WHEEL_ZOOM_OUT_FACTOR); getMainPanel().getControlPanel().zoomOutX(Constants.WHEEL_ZOOM_OUT_FACTOR, Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR); getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false); } else if (plusPressed(e.getKeyCode())) { getMainPanel().getControlPanel().zoomInX(Constants.WHEEL_ZOOM_IN_FACTOR, Constants.WHEEL_ZOOM_IN_FACTOR); getMainPanel().getControlPanel().zoomInY(Constants.WHEEL_ZOOM_IN_FACTOR); getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false); } else if (e.getKeyCode() == KeyEvent.VK_S) { if ((getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)) { setStartingAngle((getStartingAngle() % TWO_PI) + ANGLE_ROTATION_UNIT); getControlPanel().displayedPhylogenyMightHaveChanged(false); } } else if (e.getKeyCode() == KeyEvent.VK_A) { if ((getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)) { setStartingAngle((getStartingAngle() % TWO_PI) - ANGLE_ROTATION_UNIT); if (getStartingAngle() < 0) { setStartingAngle(TWO_PI + getStartingAngle()); } getControlPanel().displayedPhylogenyMightHaveChanged(false); } } else if (e.getKeyCode() == KeyEvent.VK_D) { boolean selected = false; if (getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL) { getOptions().setNodeLabelDirection(NODE_LABEL_DIRECTION.RADIAL); selected = true; } else { getOptions().setNodeLabelDirection(NODE_LABEL_DIRECTION.HORIZONTAL); } if (getMainPanel().getMainFrame() == null) { // Must be "E" applet version. final ArchaeopteryxE ae = (ArchaeopteryxE) ((MainPanelApplets) getMainPanel()).getApplet(); if (ae.getlabelDirectionCbmi() != null) { ae.getlabelDirectionCbmi().setSelected(selected); } } else { getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected(selected); } repaint(); } else if (e.getKeyCode() == KeyEvent.VK_X) { switchDisplaygetPhylogenyGraphicsType(); repaint(); } else if (e.getKeyCode() == KeyEvent.VK_C) { cycleColors(); repaint(); } else if (getOptions().isShowOverview() && isOvOn() && (e.getKeyCode() == KeyEvent.VK_O)) { MainFrame.cycleOverview(getOptions(), this); repaint(); } else if (getOptions().isShowOverview() && isOvOn() && (e.getKeyCode() == KeyEvent.VK_I)) { increaseOvSize(); } else if (getOptions().isShowOverview() && isOvOn() && (e.getKeyCode() == KeyEvent.VK_U)) { decreaseOvSize(); } e.consume(); } }
From source file:net.sf.jabref.gui.BasePanel.java
private void createMainTable() { database.registerListener(tableModel.getListSynchronizer()); database.registerListener(SpecialFieldDatabaseChangeListener.getInstance()); tableFormat = new MainTableFormat(database); tableFormat.updateTableFormat();/*from w ww . j av a 2 s .c om*/ mainTable = new MainTable(tableFormat, tableModel, frame, this); selectionListener = new MainTableSelectionListener(this, mainTable); mainTable.updateFont(); mainTable.addSelectionListener(selectionListener); mainTable.addMouseListener(selectionListener); mainTable.addKeyListener(selectionListener); mainTable.addFocusListener(selectionListener); // Add the listener that will take care of highlighting groups as the selection changes: groupsHighlightListener = listEvent -> { HighlightMatchingGroupPreferences highlightMatchingGroupPreferences = new HighlightMatchingGroupPreferences( Globals.prefs); if (highlightMatchingGroupPreferences.isAny()) { getGroupSelector().showMatchingGroups(mainTable.getSelectedEntries(), false); } else if (highlightMatchingGroupPreferences.isAll()) { getGroupSelector().showMatchingGroups(mainTable.getSelectedEntries(), true); } else { // no highlight getGroupSelector().showMatchingGroups(null, true); } }; mainTable.addSelectionListener(groupsHighlightListener); mainTable.getActionMap().put(Actions.CUT, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { runCommand(Actions.CUT); } catch (Throwable ex) { LOGGER.warn("Could not cut", ex); } } }); mainTable.getActionMap().put(Actions.COPY, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { runCommand(Actions.COPY); } catch (Throwable ex) { LOGGER.warn("Could not copy", ex); } } }); mainTable.getActionMap().put(Actions.PASTE, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { runCommand(Actions.PASTE); } catch (Throwable ex) { LOGGER.warn("Could not paste", ex); } } }); mainTable.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { final int keyCode = e.getKeyCode(); final TreePath path = frame.getGroupSelector().getSelectionPath(); final GroupTreeNodeViewModel node = path == null ? null : (GroupTreeNodeViewModel) path.getLastPathComponent(); if (e.isControlDown()) { switch (keyCode) { // The up/down/left/rightkeystrokes are displayed in the // GroupSelector's popup menu, so if they are to be changed, // edit GroupSelector.java accordingly! case KeyEvent.VK_UP: e.consume(); if (node != null) { frame.getGroupSelector().moveNodeUp(node, true); } break; case KeyEvent.VK_DOWN: e.consume(); if (node != null) { frame.getGroupSelector().moveNodeDown(node, true); } break; case KeyEvent.VK_LEFT: e.consume(); if (node != null) { frame.getGroupSelector().moveNodeLeft(node, true); } break; case KeyEvent.VK_RIGHT: e.consume(); if (node != null) { frame.getGroupSelector().moveNodeRight(node, true); } break; case KeyEvent.VK_PAGE_DOWN: frame.nextTab.actionPerformed(null); e.consume(); break; case KeyEvent.VK_PAGE_UP: frame.prevTab.actionPerformed(null); e.consume(); break; default: break; } } else if (keyCode == KeyEvent.VK_ENTER) { e.consume(); try { runCommand(Actions.EDIT); } catch (Throwable ex) { LOGGER.warn("Could not run action based on key press", ex); } } } }); }
From source file:Demo3D.java
/** * Override Behavior's stimulus method to handle the event. This method is * called when a key on the keyboard has been pressed and operates on the * specified transform group to move the camera. * // w w w.jav a 2 s . c o m * @param Enumeration * criteria - all pressed keys in a list. This will be passed by * the system. */ public void processStimulus(Enumeration criteria) { WakeupOnAWTEvent eventToWakeUp; AWTEvent[] events; if (criteria.hasMoreElements()) { // Decode the wakeup criteria eventToWakeUp = (WakeupOnAWTEvent) criteria.nextElement(); events = eventToWakeUp.getAWTEvent(); keyEvent = (KeyEvent) events[0]; int keyCode = keyEvent.getKeyCode(); // Perform our processing // Get the initial transformation from target and put it into // myKeyNavTransf3D target_trGr.getTransform(myKeyNavTransf3D); // Set the translational components of myKeyNavTransf3D in // translation myKeyNavTransf3D.get(translation); // Not any of the 8 motions (6 translations and 2 rotations) // don't act simultaneously. switch (keyCode) { case KeyEvent.VK_UP: // Up Arrow - to move forward trans_rot.set(new Vector3f(0.0f, 0.0f, -step)); break; case KeyEvent.VK_DOWN: // Down Arrow - to move backwards trans_rot.set(new Vector3f(0.0f, 0.0f, step)); break; case KeyEvent.VK_LEFT: // Left Arrow -to turn left or move left if (keyEvent.isShiftDown()) trans_rot.set(new Vector3f(-step, 0.0f, 0.0f)); else trans_rot.rotY(angle); break; case KeyEvent.VK_RIGHT: // Right Arrow - to turn right or move right if (keyEvent.isShiftDown()) trans_rot.set(new Vector3f(step, 0.0f, 0.0f)); else trans_rot.rotY(-angle); break; case KeyEvent.VK_PAGE_DOWN: // Page Down - to move down trans_rot.set(new Vector3f(0.0f, -step, 0.0f)); break; case KeyEvent.VK_PAGE_UP: // Page Up - to move up trans_rot.set(new Vector3f(0.0f, step, 0.0f)); break; default: trans_rot.set(new Vector3f(0.0f, 0.0f, 0.0f)); } myKeyNavTransf3D.mul(trans_rot); // Return the final transformation myKeyNavTransf3D to target target_trGr.setTransform(myKeyNavTransf3D); } // Set wakeup criteria for next time. wakeupOn(wakeUp); }
From source file:com.willwinder.universalgcodesender.MainWindow.java
private void initProgram() { Localization.initialize(this.settings.getLanguage()); try {//from ww w . j a va2 s .c o m backend.applySettings(settings); } catch (Exception e) { displayErrorDialog(e.getMessage()); } this.setLocalLabels(); this.loadPortSelector(); this.checkScrollWindow(); this.loadFirmwareSelector(); this.setTitle( Localization.getString("title") + " (" + Localization.getString("version") + " " + VERSION + ")"); // Command History this.manualCommandHistory = new ArrayList<>(); // Add keyboard listener for manual controls. KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { // Check context. if (((arrowMovementEnabled.isSelected()) && e.getID() == KeyEvent.KEY_PRESSED) && xPlusButton.isEnabled()) { switch (e.getKeyCode()) { case KeyEvent.VK_RIGHT: case KeyEvent.VK_KP_RIGHT: case KeyEvent.VK_NUMPAD6: xPlusButtonActionPerformed(null); e.consume(); return true; case KeyEvent.VK_LEFT: case KeyEvent.VK_KP_LEFT: case KeyEvent.VK_NUMPAD4: xMinusButtonActionPerformed(null); e.consume(); return true; case KeyEvent.VK_UP: case KeyEvent.VK_KP_UP: case KeyEvent.VK_NUMPAD8: yPlusButtonActionPerformed(null); e.consume(); return true; case KeyEvent.VK_DOWN: case KeyEvent.VK_KP_DOWN: case KeyEvent.VK_NUMPAD2: yMinusButtonActionPerformed(null); e.consume(); return true; case KeyEvent.VK_PAGE_UP: case KeyEvent.VK_NUMPAD9: zPlusButtonActionPerformed(null); e.consume(); return true; case KeyEvent.VK_PAGE_DOWN: case KeyEvent.VK_NUMPAD3: zMinusButtonActionPerformed(null); e.consume(); return true; case KeyEvent.VK_ADD: increaseStepActionPerformed(null); e.consume(); return true; case KeyEvent.VK_SUBTRACT: decreaseStepActionPerformed(null); e.consume(); return true; case KeyEvent.VK_DIVIDE: divideStepActionPerformed(null); e.consume(); return true; case KeyEvent.VK_MULTIPLY: multiplyStepActionPerformed(null); e.consume(); return true; case KeyEvent.VK_INSERT: case KeyEvent.VK_NUMPAD0: resetCoordinatesButtonActionPerformed(null); e.consume(); return true; default: break; } } return false; } }); }
From source file:org.apache.log4j.chainsaw.LogUI.java
/** * Activates itself as a viewer by configuring Size, and location of itself, * and configures the default Tabbed Pane elements with the correct layout, * table columns, and sets itself viewable. *//*from ww w . j a va2 s. c o m*/ public void activateViewer() { LoggerRepository repo = LogManager.getLoggerRepository(); if (repo instanceof LoggerRepositoryEx) { this.pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry(); } initGUI(); initPrefModelListeners(); /** * We add a simple appender to the MessageCenter logger * so that each message is displayed in the Status bar */ MessageCenter.getInstance().getLogger().addAppender(new AppenderSkeleton() { protected void append(LoggingEvent event) { getStatusBar().setMessage(event.getMessage().toString()); } public void close() { } public boolean requiresLayout() { return false; } }); initSocketConnectionListener(); if (pluginRegistry.getPlugins(Receiver.class).size() == 0) { noReceiversDefined = true; } getFilterableColumns().add(ChainsawConstants.LEVEL_COL_NAME); getFilterableColumns().add(ChainsawConstants.LOGGER_COL_NAME); getFilterableColumns().add(ChainsawConstants.THREAD_COL_NAME); getFilterableColumns().add(ChainsawConstants.NDC_COL_NAME); getFilterableColumns().add(ChainsawConstants.PROPERTIES_COL_NAME); getFilterableColumns().add(ChainsawConstants.CLASS_COL_NAME); getFilterableColumns().add(ChainsawConstants.METHOD_COL_NAME); getFilterableColumns().add(ChainsawConstants.FILE_COL_NAME); getFilterableColumns().add(ChainsawConstants.NONE_COL_NAME); JPanel panePanel = new JPanel(); panePanel.setLayout(new BorderLayout(2, 2)); getContentPane().setLayout(new BorderLayout()); getTabbedPane().addChangeListener(getToolBarAndMenus()); getTabbedPane().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { LogPanel thisLogPanel = getCurrentLogPanel(); if (thisLogPanel != null) { thisLogPanel.updateStatusBar(); } } }); KeyStroke ksRight = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); KeyStroke ksLeft = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); KeyStroke ksGotoLine = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksRight, "MoveRight"); getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksLeft, "MoveLeft"); getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksGotoLine, "GotoLine"); Action moveRight = new AbstractAction() { public void actionPerformed(ActionEvent e) { int temp = getTabbedPane().getSelectedIndex(); ++temp; if (temp != getTabbedPane().getTabCount()) { getTabbedPane().setSelectedTab(temp); } } }; Action moveLeft = new AbstractAction() { public void actionPerformed(ActionEvent e) { int temp = getTabbedPane().getSelectedIndex(); --temp; if (temp > -1) { getTabbedPane().setSelectedTab(temp); } } }; Action gotoLine = new AbstractAction() { public void actionPerformed(ActionEvent e) { String inputLine = JOptionPane.showInputDialog(LogUI.this, "Enter the line number to go:", "Goto Line", -1); try { int lineNumber = Integer.parseInt(inputLine); int row = getCurrentLogPanel().setSelectedEvent(lineNumber); if (row == -1) { JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid line number", "Error", 0); } } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid line number", "Error", 0); } } }; getTabbedPane().getActionMap().put("MoveRight", moveRight); getTabbedPane().getActionMap().put("MoveLeft", moveLeft); getTabbedPane().getActionMap().put("GotoLine", gotoLine); /** * We listen for double clicks, and auto-undock currently selected Tab if * the mouse event location matches the currently selected tab */ getTabbedPane().addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if ((e.getClickCount() > 1) && ((e.getModifiers() & InputEvent.BUTTON1_MASK) > 0)) { int tabIndex = getTabbedPane().getSelectedIndex(); if ((tabIndex != -1) && (tabIndex == getTabbedPane().getSelectedIndex())) { LogPanel logPanel = getCurrentLogPanel(); if (logPanel != null) { logPanel.undock(); } } } } }); panePanel.add(getTabbedPane()); addWelcomePanel(); getContentPane().add(toolbar, BorderLayout.NORTH); getContentPane().add(statusBar, BorderLayout.SOUTH); mainReceiverSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panePanel, receiversPanel); dividerSize = mainReceiverSplitPane.getDividerSize(); mainReceiverSplitPane.setDividerLocation(-1); getContentPane().add(mainReceiverSplitPane, BorderLayout.CENTER); /** * We need to make sure that all the internal GUI components have been added to the * JFrame so that any plugns that get activated during initPlugins(...) method * have access to inject menus */ initPlugins(pluginRegistry); mainReceiverSplitPane.setResizeWeight(1.0); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { exit(); } }); preferencesFrame.setTitle("'Application-wide Preferences"); preferencesFrame.setIconImage(((ImageIcon) ChainsawIcons.ICON_PREFERENCES).getImage()); preferencesFrame.getContentPane().add(applicationPreferenceModelPanel); preferencesFrame.setSize(750, 520); Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); preferencesFrame.setLocation(new Point((screenDimension.width / 2) - (preferencesFrame.getSize().width / 2), (screenDimension.height / 2) - (preferencesFrame.getSize().height / 2))); pack(); final JPopupMenu tabPopup = new JPopupMenu(); final Action hideCurrentTabAction = new AbstractAction("Hide") { public void actionPerformed(ActionEvent e) { Component selectedComp = getTabbedPane().getSelectedComponent(); if (selectedComp instanceof LogPanel) { displayPanel(getCurrentLogPanel().getIdentifier(), false); tbms.stateChange(); } else { getTabbedPane().remove(selectedComp); } } }; final Action hideOtherTabsAction = new AbstractAction("Hide Others") { public void actionPerformed(ActionEvent e) { Component selectedComp = getTabbedPane().getSelectedComponent(); String currentName; if (selectedComp instanceof LogPanel) { currentName = getCurrentLogPanel().getIdentifier(); } else if (selectedComp instanceof WelcomePanel) { currentName = ChainsawTabbedPane.WELCOME_TAB; } else { currentName = ChainsawTabbedPane.ZEROCONF; } int count = getTabbedPane().getTabCount(); int index = 0; for (int i = 0; i < count; i++) { String name = getTabbedPane().getTitleAt(index); if (getPanelMap().keySet().contains(name) && !name.equals(currentName)) { displayPanel(name, false); tbms.stateChange(); } else { index++; } } } }; Action showHiddenTabsAction = new AbstractAction("Show All Hidden") { public void actionPerformed(ActionEvent e) { for (Iterator iter = getPanels().entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); Boolean docked = (Boolean) entry.getValue(); if (docked.booleanValue()) { String identifier = (String) entry.getKey(); int count = getTabbedPane().getTabCount(); boolean found = false; for (int i = 0; i < count; i++) { String name = getTabbedPane().getTitleAt(i); if (name.equals(identifier)) { found = true; break; } } if (!found) { displayPanel(identifier, true); tbms.stateChange(); } } } } }; tabPopup.add(hideCurrentTabAction); tabPopup.add(hideOtherTabsAction); tabPopup.addSeparator(); tabPopup.add(showHiddenTabsAction); final PopupListener tabPopupListener = new PopupListener(tabPopup); getTabbedPane().addMouseListener(tabPopupListener); this.handler.addPropertyChangeListener("dataRate", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { double dataRate = ((Double) evt.getNewValue()).doubleValue(); statusBar.setDataRate(dataRate); } }); getSettingsManager().addSettingsListener(this); getSettingsManager().addSettingsListener(MRUFileListPreferenceSaver.getInstance()); getSettingsManager().addSettingsListener(receiversPanel); try { //if an uncaught exception is thrown, allow the UI to continue to load getSettingsManager().loadSettings(); } catch (Exception e) { e.printStackTrace(); } //app preferences have already been loaded (and configuration url possibly set to blank if being overridden) //but we need a listener so the settings will be saved on exit (added after loadsettings was called) getSettingsManager().addSettingsListener(new ApplicationPreferenceModelSaver(applicationPreferenceModel)); setVisible(true); if (applicationPreferenceModel.isReceivers()) { showReceiverPanel(); } else { hideReceiverPanel(); } removeSplash(); synchronized (initializationLock) { isGUIFullyInitialized = true; initializationLock.notifyAll(); } if (noReceiversDefined && applicationPreferenceModel.isShowNoReceiverWarning()) { SwingHelper.invokeOnEDT(new Runnable() { public void run() { showReceiverConfigurationPanel(); } }); } Container container = tutorialFrame.getContentPane(); final JEditorPane tutorialArea = new JEditorPane(); tutorialArea.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); tutorialArea.setEditable(false); container.setLayout(new BorderLayout()); try { tutorialArea.setPage(ChainsawConstants.TUTORIAL_URL); JTextComponentFormatter.applySystemFontAndSize(tutorialArea); container.add(new JScrollPane(tutorialArea), BorderLayout.CENTER); } catch (Exception e) { MessageCenter.getInstance().getLogger().error("Error occurred loading the Tutorial", e); } tutorialFrame.setIconImage(new ImageIcon(ChainsawIcons.HELP).getImage()); tutorialFrame.setSize(new Dimension(640, 480)); final Action startTutorial = new AbstractAction("Start Tutorial", new ImageIcon(ChainsawIcons.ICON_RESUME_RECEIVER)) { public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(null, "This will start 3 \"Generator\" receivers for use in the Tutorial. Is that ok?", "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { new Thread(new Tutorial()).start(); putValue("TutorialStarted", Boolean.TRUE); } else { putValue("TutorialStarted", Boolean.FALSE); } } }; final Action stopTutorial = new AbstractAction("Stop Tutorial", new ImageIcon(ChainsawIcons.ICON_STOP_RECEIVER)) { public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(null, "This will stop all of the \"Generator\" receivers used in the Tutorial, but leave any other Receiver untouched. Is that ok?", "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { new Thread(new Runnable() { public void run() { LoggerRepository repo = LogManager.getLoggerRepository(); if (repo instanceof LoggerRepositoryEx) { PluginRegistry pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry(); List list = pluginRegistry.getPlugins(Generator.class); for (Iterator iter = list.iterator(); iter.hasNext();) { Plugin plugin = (Plugin) iter.next(); pluginRegistry.stopPlugin(plugin.getName()); } } } }).start(); setEnabled(false); startTutorial.putValue("TutorialStarted", Boolean.FALSE); } } }; stopTutorial.putValue(Action.SHORT_DESCRIPTION, "Removes all of the Tutorials Generator Receivers, leaving all other Receivers untouched"); startTutorial.putValue(Action.SHORT_DESCRIPTION, "Begins the Tutorial, starting up some Generator Receivers so you can see Chainsaw in action"); stopTutorial.setEnabled(false); final SmallToggleButton startButton = new SmallToggleButton(startTutorial); PropertyChangeListener pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { stopTutorial.setEnabled(((Boolean) startTutorial.getValue("TutorialStarted")).equals(Boolean.TRUE)); startButton.setSelected(stopTutorial.isEnabled()); } }; startTutorial.addPropertyChangeListener(pcl); stopTutorial.addPropertyChangeListener(pcl); pluginRegistry.addPluginListener(new PluginListener() { public void pluginStarted(PluginEvent e) { } public void pluginStopped(PluginEvent e) { List list = pluginRegistry.getPlugins(Generator.class); if (list.size() == 0) { startTutorial.putValue("TutorialStarted", Boolean.FALSE); } } }); final SmallButton stopButton = new SmallButton(stopTutorial); final JToolBar tutorialToolbar = new JToolBar(); tutorialToolbar.setFloatable(false); tutorialToolbar.add(startButton); tutorialToolbar.add(stopButton); container.add(tutorialToolbar, BorderLayout.NORTH); tutorialArea.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (e.getDescription().equals("StartTutorial")) { startTutorial.actionPerformed(null); } else if (e.getDescription().equals("StopTutorial")) { stopTutorial.actionPerformed(null); } else { try { tutorialArea.setPage(e.getURL()); } catch (IOException e1) { MessageCenter.getInstance().getLogger() .error("Failed to change the URL for the Tutorial", e1); } } } } }); /** * loads the saved tab settings and if there are hidden tabs, * hide those tabs out of currently loaded tabs.. */ if (!getTabbedPane().tabSetting.isWelcome()) { displayPanel(ChainsawTabbedPane.WELCOME_TAB, false); } if (!getTabbedPane().tabSetting.isZeroconf()) { displayPanel(ChainsawTabbedPane.ZEROCONF, false); } tbms.stateChange(); }
From source file:org.genedb.jogra.plugins.TermRationaliser.java
/** * Return a new JFrame which is the main interface to the Rationaliser. *///from ww w . ja v a2 s . co m public JFrame getMainPanel() { /* JFRAME */ frame.setTitle(WINDOW_TITLE); frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); frame.setLayout(new BorderLayout()); /* MENU */ JMenuBar menuBar = new JMenuBar(); JMenu actions_menu = new JMenu("Actions"); JMenuItem actions_mitem_1 = new JMenuItem("Refresh lists"); actions_mitem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { initModels(); } }); actions_menu.add(actions_mitem_1); JMenu about_menu = new JMenu("About"); JMenuItem about_mitem_1 = new JMenuItem("About"); about_mitem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JOptionPane.showMessageDialog(null, "Term Rationaliser \n" + "Wellcome Trust Sanger Institute, UK \n" + "2009", "Term Rationaliser", JOptionPane.PLAIN_MESSAGE); } }); about_menu.add(about_mitem_1); menuBar.add(about_menu); menuBar.add(actions_menu); frame.add(menuBar, BorderLayout.NORTH); /* MAIN BOX */ Box center = Box.createHorizontalBox(); //A box that displays contents from left to right center.add(Box.createHorizontalStrut(5)); //Invisible fixed-width component /* FROM LIST AND PANEL */ fromList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); //Allow multiple products to be selected fromList.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) { synchroniseLists(fromList, toList); //synchronise from left to right } } @Override public void keyReleased(KeyEvent arg0) { } @Override public void keyTyped(KeyEvent arg0) { } }); Box fromPanel = this.createRationaliserPanel(FROM_LIST_NAME, fromList); //Box on left hand side fromPanel.add(Box.createVerticalStrut(55)); //Add some space center.add(fromPanel); //Add to main box center.add(Box.createHorizontalStrut(3)); //Add some space /* MIDDLE PANE */ Box middlePane = Box.createVerticalBox(); ClassLoader classLoader = this.getClass().getClassLoader(); //Needed to access the images later on ImageIcon leftButtonIcon = new ImageIcon(classLoader.getResource("left_arrow.gif")); ImageIcon rightButtonIcon = new ImageIcon(classLoader.getResource("right_arrow.gif")); leftButtonIcon = new ImageIcon(leftButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon! rightButtonIcon = new ImageIcon(rightButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon! JButton rightSynch = new JButton(rightButtonIcon); rightSynch.setToolTipText("Synchronise TO list. \n Shortcut: Right-arrow key"); rightSynch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { synchroniseLists(fromList, toList); } }); JButton leftSynch = new JButton(leftButtonIcon); leftSynch.setToolTipText("Synchronise FROM list. \n Shortcut: Left-arrow key"); leftSynch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { synchroniseLists(toList, fromList); } }); middlePane.add(rightSynch); middlePane.add(leftSynch); center.add(middlePane); //Add middle pane to main box center.add(Box.createHorizontalStrut(3)); /* TO LIST AND PANEL */ toList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //Single product selection in TO list toList.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_LEFT) { synchroniseLists(toList, fromList); //synchronise from right to left } } @Override public void keyReleased(KeyEvent arg0) { } @Override public void keyTyped(KeyEvent arg0) { } }); Box toPanel = this.createRationaliserPanel(TO_LIST_NAME, toList); Box newTerm = Box.createVerticalBox(); textField = new JTextArea(1, 1); //textfield to let the user edit the name of an existing term textField.setMaximumSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize().height, 10)); textField.setForeground(Color.BLUE); JScrollPane jsp = new JScrollPane(textField); //scroll pane so that there is a horizontal scrollbar jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); newTerm.add(jsp); TitledBorder editBorder = BorderFactory.createTitledBorder("Edit term name"); editBorder.setTitleColor(Color.DARK_GRAY); newTerm.setBorder(editBorder); toPanel.add(newTerm); //add textfield to panel center.add(toPanel); //add panel to main box center.add(Box.createHorizontalStrut(5)); frame.add(center); //add the main panel to the frame initModels(); //load the lists with data /* BOTTOM HALF OF FRAME */ Box main = Box.createVerticalBox(); TitledBorder border = BorderFactory.createTitledBorder("Information"); border.setTitleColor(Color.DARK_GRAY); /* INFORMATION BOX */ Box info = Box.createVerticalBox(); Box scope = Box.createHorizontalBox(); scope.add(Box.createHorizontalStrut(5)); scope.add(scopeLabel); //label showing the scope of the terms scope.add(Box.createHorizontalGlue()); Box productCount = Box.createHorizontalBox(); productCount.add(Box.createHorizontalStrut(5)); productCount.add(productCountLabel); //display the label showing the number of terms productCount.add(Box.createHorizontalGlue()); info.add(scope); info.add(productCount); info.setBorder(border); /* ACTION BUTTONS */ Box actionButtons = Box.createHorizontalBox(); actionButtons.add(Box.createHorizontalGlue()); actionButtons.add(Box.createHorizontalStrut(10)); JButton findFix = new JButton(new FindClosestMatchAction()); actionButtons.add(findFix); actionButtons.add(Box.createHorizontalStrut(10)); RationaliserAction ra = new RationaliserAction(); // RationaliserAction2 ra2 = new RationaliserAction2(); JButton go = new JButton(ra); actionButtons.add(go); actionButtons.add(Box.createHorizontalGlue()); /* MORE INFORMATION TOGGLE */ Box buttonBox = Box.createHorizontalBox(); final JButton toggle = new JButton("Hide information <<"); buttonBox.add(Box.createHorizontalStrut(5)); buttonBox.add(toggle); buttonBox.add(Box.createHorizontalGlue()); Box textBox = Box.createHorizontalBox(); final JScrollPane scrollPane = new JScrollPane(information); scrollPane.setPreferredSize(new Dimension(frame.getWidth(), 100)); scrollPane.setVisible(true); textBox.add(Box.createHorizontalStrut(5)); textBox.add(scrollPane); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (toggle.getText().equals("Show information >>")) { scrollPane.setVisible(true); toggle.setText("Hide information <<"); frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() + 100)); frame.pack(); } else if (toggle.getText().equals("Hide information <<")) { scrollPane.setVisible(false); toggle.setText("Show information >>"); frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() - 100)); frame.pack(); } } }; toggle.addActionListener(actionListener); main.add(Box.createVerticalStrut(5)); main.add(info); main.add(Box.createVerticalStrut(5)); main.add(Box.createVerticalStrut(5)); main.add(actionButtons); main.add(Box.createVerticalStrut(10)); main.add(buttonBox); main.add(textBox); frame.add(main, BorderLayout.SOUTH); frame.pack(); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setVisible(true); //initModels(); return frame; }