List of usage examples for java.awt.event ActionEvent consume
protected void consume()
From source file:org.jannocessor.ui.RenderPreviewDialog.java
private void initialize() { logger.debug("Initializing UI..."); DefaultSyntaxKit.initKit();/*from w w w .ja v a 2s . com*/ JEditorPane.registerEditorKitForContentType("text/java_template", "org.jannocessor.syntax.JavaTemplateKit", getClass().getClassLoader()); JEditorPane.registerEditorKitForContentType("text/java_output", "org.jannocessor.syntax.JavaOutputKit", getClass().getClassLoader()); setTitle("JAnnocessor - Java Annotation Processor"); setLayout(new BorderLayout(5, 5)); listFiles(); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); double width = screenSize.getWidth() * 0.9; double height = screenSize.getHeight() * 0.8; // Font font = new Font("Courier New", Font.PLAIN, 14); input = createInput(); JScrollPane scroll1 = new JScrollPane(input, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); input.setContentType("text/java_template"); input.setText(""); scroll1.setMinimumSize(new Dimension(200, 200)); scroll1.setPreferredSize(new Dimension((int) (width * 0.5), (int) height)); add(scroll1, BorderLayout.CENTER); output = Box.createVerticalBox(); scroll2 = new JScrollPane(output, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll2.setMinimumSize(new Dimension(200, 200)); scroll2.setPreferredSize(new Dimension((int) (width * 0.5), (int) height)); add(scroll2, BorderLayout.EAST); combo = createCombo(); combo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { load((File) combo.getSelectedItem()); } }); add(combo, BorderLayout.NORTH); JLabel help = new JLabel( " Choose a template from the drop-down box to edit it. Navigation: Alt + Left & Alt + Right; Refresh = F5, Close = Esc", JLabel.CENTER); help.setForeground(Color.WHITE); help.setBackground(Color.BLACK); help.setOpaque(true); help.setFont(new Font("Courier New", Font.BOLD, 14)); add(help, BorderLayout.SOUTH); keyListener = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_F5) { e.consume(); processElements(); refresh(); } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { e.consume(); dispose(); } else if (e.getKeyCode() == KeyEvent.VK_LEFT && e.isAltDown()) { e.consume(); moveBackward(); } else if (e.getKeyCode() == KeyEvent.VK_RIGHT && e.isAltDown()) { e.consume(); moveForward(); } else if (e.getKeyCode() == KeyEvent.VK_S && e.isControlDown()) { e.consume(); save(); } else if (e.getKeyCode() == KeyEvent.VK_I && e.isControlDown()) { e.consume(); increase(); } else if (e.getKeyCode() == KeyEvent.VK_D && e.isControlDown()) { e.consume(); decrease(); } } }; input.addKeyListener(keyListener); combo.addKeyListener(keyListener); setActive(0); pack(); setModal(true); setLocationRelativeTo(null); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); input.requestFocus(); logger.debug("Initialized UI."); }
From source file:adams.gui.tools.TelnetPanel.java
/** * For initializing the GUI.//from w ww . ja va 2 s . com */ @Override protected void initGUI() { JPanel topPanel; JPanel bottomPanel; JLabel label; super.initGUI(); setLayout(new BorderLayout()); // connection topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); add(topPanel, BorderLayout.NORTH); m_TextRemote = new BaseTextField(20); label = new JLabel("Remote"); label.setDisplayedMnemonic('R'); label.setLabelFor(m_TextRemote); topPanel.add(label); topPanel.add(m_TextRemote); m_PortModel = new SpinnerNumberModel(); m_PortModel.setMinimum(1); m_PortModel.setMaximum(65536); m_PortModel.setStepSize(1); m_PortModel.setValue(23); m_SpinnerPort = new JSpinner(m_PortModel); label = new JLabel("Port"); label.setDisplayedMnemonic('P'); label.setLabelFor(m_SpinnerPort); topPanel.add(label); topPanel.add(m_SpinnerPort); m_ButtonConnection = new BaseButton(); m_ButtonConnection.setMnemonic('n'); m_ButtonConnection.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleConnectionEvent(); } }); topPanel.add(m_ButtonConnection); // output m_ButtonClear = new BaseButton("Clear", GUIHelper.getIcon("new.gif")); m_ButtonClear.setMnemonic('l'); m_ButtonClear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { m_TextOutput.setText(""); } }); m_ButtonCopy = new BaseButton("Copy", GUIHelper.getIcon("copy.gif")); m_ButtonCopy.setMnemonic('C'); m_ButtonCopy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (m_TextOutput.getSelectedText().length() > 0) ClipboardHelper.copyToClipboard(m_TextOutput.getSelectedText()); else if (m_TextOutput.getText().length() > 0) ClipboardHelper.copyToClipboard(m_TextOutput.getText()); } }); m_TextOutput = new BaseTextAreaWithButtons(10, 40); m_TextOutput.setTextFont(Fonts.getMonospacedFont()); m_TextOutput.addToButtonsPanel(m_ButtonClear); m_TextOutput.addToButtonsPanel(m_ButtonCopy); add(m_TextOutput, BorderLayout.CENTER); // commands bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); add(bottomPanel, BorderLayout.SOUTH); m_TextCommand = new BaseTextField(40); m_TextCommand.setFont(Fonts.getMonospacedFont()); m_TextCommand.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_ENTER: e.consume(); execCommand(); break; case KeyEvent.VK_UP: e.consume(); previousCommand(); break; case KeyEvent.VK_DOWN: e.consume(); nextCommand(); break; } } }); label = new JLabel("Command"); label.setDisplayedMnemonic('m'); label.setLabelFor(m_TextCommand); bottomPanel.add(label); bottomPanel.add(m_TextCommand); m_ButtonCommand = new BaseButton(GUIHelper.getIcon("run.gif")); m_ButtonCommand.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { execCommand(); } }); bottomPanel.add(m_ButtonCommand); }
From source file:org.openuat.apps.BedaApp.java
/** * Creates a new instance of this class and launches the * actual application./*from w w w. j ava 2 s .c om*/ */ public BedaApp() { random = new SecureRandom(); devices = new RemoteDevice[0]; currentPeerUrl = null; currentChannel = null; isInitiator = false; // Initialize the logger. Use a wrapper around the log4j framework. /*LogFactory.init(new Log4jFactory()); logger = LogFactory.getLogger(BedaApp.class.getName()); logger.finer("Logger initiated!");*/ mainWindow = new JFrame("Beda App"); mainWindow.setSize(new Dimension(FRAME_WIDTH, FRAME_HIGHT)); mainWindow.setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HIGHT)); mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainWindow.getContentPane().setLayout(new FlowLayout()); URL imgURL = getClass().getResource("/resources/Button_Icon_Blue_beda.png"); ImageIcon icon = imgURL != null ? new ImageIcon(imgURL) : new ImageIcon("resources/Button_Icon_Blue_beda.png"); mainWindow.setIconImage(icon.getImage()); // prepare the button channels ActionListener abortHandler = new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getID() == ActionEvent.ACTION_PERFORMED) { logger.warning("Protocol run aborted by user"); BluetoothRFCOMMChannel.shutdownAllChannels(); alertError("Protocol run aborted."); } } }; buttonChannels = new HashMap<String, OOBChannel>(); ButtonChannelImpl impl = new AWTButtonChannelImpl(mainWindow.getContentPane(), abortHandler); OOBChannel c = new ButtonToButtonChannel(impl); buttonChannels.put(c.toString(), c); c = new FlashDisplayToButtonChannel(impl, false); buttonChannels.put(c.toString(), c); c = new TrafficLightToButtonChannel(impl); buttonChannels.put(c.toString(), c); c = new ProgressBarToButtonChannel(impl); buttonChannels.put(c.toString(), c); c = new PowerBarToButtonChannel(impl); buttonChannels.put(c.toString(), c); c = new ShortVibrationToButtonChannel(impl); buttonChannels.put(c.toString(), c); c = new LongVibrationToButtonChannel(impl); buttonChannels.put(c.toString(), c); // set up the menu bar menuBar = new JMenuBar(); JMenu menu = new JMenu("Menu"); final JMenuItem homeEntry = new JMenuItem("Home"); final JMenuItem testEntry = new JMenuItem("Test channels"); ActionListener menuListener = new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JMenuItem menuItem = (JMenuItem) event.getSource(); if (menuItem == homeEntry) { showHomeScreen(); } else if (menuItem == testEntry) { showTestScreen(); } } }; homeEntry.addActionListener(menuListener); testEntry.addActionListener(menuListener); menu.add(homeEntry); menu.add(testEntry); menuBar.add(menu); mainWindow.setJMenuBar(menuBar); // set up channel list OOBChannel[] channels = { new ButtonToButtonChannel(impl), new FlashDisplayToButtonChannel(impl, false), new TrafficLightToButtonChannel(impl), new ProgressBarToButtonChannel(impl), new PowerBarToButtonChannel(impl), new ShortVibrationToButtonChannel(impl), new LongVibrationToButtonChannel(impl) }; channelList = new JList(channels); channelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); channelList.setVisibleRowCount(15); channelList.setPreferredSize(new Dimension(LIST_WIDTH, LIST_HIGHT)); // set up device list deviceList = new JList(); deviceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); deviceList.setVisibleRowCount(15); deviceList.setPreferredSize(new Dimension(LIST_WIDTH, LIST_HIGHT)); // enable double clicks on the two lists doubleClickListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent event) { // react on double clicks if (event.getButton() == MouseEvent.BUTTON1 && event.getClickCount() == 2) { JList source = (JList) event.getSource(); if (source == channelList && channelList.isEnabled()) { currentChannel = (OOBChannel) channelList.getSelectedValue(); startAuthentication(); } else if (source == deviceList) { int index = deviceList.getSelectedIndex(); if (index > -1) { String peerAddress = devices[index].getBluetoothAddress(); searchForService(peerAddress); } } } event.consume(); } }; deviceList.addMouseListener(doubleClickListener); // note: this listener will be set on the channelList in the showHomeScreen method ListSelectionListener selectionListener = new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent event) { channelList.setEnabled(false); } }; deviceList.addListSelectionListener(selectionListener); // create refresh button refreshButton = new JButton("Refresh list"); ActionListener buttonListener = new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if ((JButton) event.getSource() == refreshButton) { refreshButton.setEnabled(false); statusLabel.setText("Please wait... scanning for devices..."); peerManager.startInquiry(false); } } }; refreshButton.addActionListener(buttonListener); // set up the bluetooth peer manager BluetoothPeerManager.PeerEventsListener listener = new BluetoothPeerManager.PeerEventsListener() { public void inquiryCompleted(Vector newDevices) { refreshButton.setEnabled(true); statusLabel.setText(""); updateDeviceList(); } public void serviceSearchCompleted(RemoteDevice remoteDevice, Vector services, int errorReason) { // ignore } }; try { peerManager = new BluetoothPeerManager(); peerManager.addListener(listener); } catch (IOException e) { logger.log(Level.SEVERE, "Could not initiate BluetoothPeerManager.", e); } // set up the bluetooth rfcomm server try { btServer = new BluetoothRFCOMMServer(null, SERVICE_UUID, SERVICE_NAME, 30000, true, false); btServer.addAuthenticationProgressHandler(this); btServer.start(); if (logger.isLoggable(Level.INFO)) { logger.info("Finished starting SDP service at " + btServer.getRegisteredServiceURL()); } } catch (IOException e) { logger.log(Level.SEVERE, "Could not create bluetooth server.", e); } ProtocolCommandHandler inputProtocolHandler = new ProtocolCommandHandler() { @Override public boolean handleProtocol(String firstLine, RemoteConnection remote) { if (logger.isLoggable(Level.FINER)) { logger.finer("Handle protocol command: " + firstLine); } if (firstLine.equals(UACAPProtocolConstants.PRE_AUTH)) { inputProtocol(false, remote, null); return true; } return false; } }; btServer.addProtocolCommandHandler(UACAPProtocolConstants.PRE_AUTH, inputProtocolHandler); // build staus bar statusLabel = new JLabel(""); statusLabel.setPreferredSize(new Dimension(FRAME_WIDTH - 40, LABEL_HIGHT)); // build initial screen (the home screen) showHomeScreen(); // launch window mainWindow.pack(); mainWindow.setVisible(true); }
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();/*w ww .ja v a2 s .c o m*/ 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:view.QuestionLab.java
/** * Creates new form QuestionLab/* w w w . jav a 2 s . c o m*/ */ public QuestionLab(java.awt.Frame parent, boolean modal) { super(parent, modal); try { initComponents(); submitButton.setVisible(false); jCheckBox1.setEnabled(false); jCheckBox3.setEnabled(false); jCheckBox4.setEnabled(false); jCheckBox5.setEnabled(false); jCheckBox7.setEnabled(false); jCheckBox8.setEnabled(false); jCheckBox9.setEnabled(false); jCheckBox10.setEnabled(false); submitButton.setEnabled(false); backButton.setEnabled(false); controller = ServerConnector.getServerConnector().getStudentController(); studentObserverImpl = new StudentObserverImpl(this); controller.addObserve(studentObserverImpl); //controller.onlineNow(); //displayMessage(Integer.toString(onlineNow)); muteButton.setEnabled(false); setSize(Toolkit.getDefaultToolkit().getScreenSize()); UIManager.setLookAndFeel(new GraphiteLookAndFeel()); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); date = new Date(); System.out.println(dateFormat.format(date)); newDate = dateFormat.format(date); JButton buttonArrayListOne[][] = { { jButton1, jButton2, jButton3, jButton4, jButton5 }, { jButton6, jButton7, jButton8, jButton9, jButton10 }, { jButton11, jButton12, jButton13, jButton14, jButton15 }, { jButton16, jButton17, jButton18, jButton19, jButton20 }, { jButton21, jButton22, jButton23, jButton24, jButton25 }, { jButton26, jButton27, jButton28, jButton29, jButton30 }, { jButton31, jButton32, jButton33, jButton34, jButton35 }, { jButton36, jButton37, jButton38, jButton39, jButton40 }, { jButton41, jButton42, jButton43, jButton44, jButton45 }, { jButton46, jButton47, jButton48, jButton49, jButton50 }, { jButton51, jButton52, jButton53, jButton54, jButton55 }, { jButton56, jButton57, jButton58, jButton59, jButton60 } }; this.buttonArrayList = buttonArrayListOne; System.out.println("MyNIc" + PracticeExamLogIn.studentNic); new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int hour = secondsLeft / 3600; int min = secondsLeft / 60 - hour * 60; int second = secondsLeft % 60; if (hour == 0) { int seconds = secondsLeft % 60; jLabel7.setText(Integer.toString(seconds)); jLabel8.setText("Minutes"); // jLabel5.setText("Seconds"); jLabel6.setText(Integer.toString(min)); } else { jLabel6.setText(Integer.toString(hour)); jLabel7.setText(Integer.toString(min)); jLabel8.setText(Integer.toString(second)); } secondsLeft--; if ("0".equals(jLabel6.getText()) && "0".equals(jLabel7.getText())) { //check(); System.out.println("true"); } } }).start(); submitTextField.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (!((c >= 'a') && (c <= 'g') || (c == KeyEvent.VK_SPACE) || (c == KeyEvent.VK_TAB) || (c == KeyEvent.VK_SPACE))) { getToolkit().beep(); e.consume(); } } }); try { try { Exam exam = new Exam(PracticeExamLogIn.studentNic, date, anxCount); // ExamController examController = ServerConnector.getServerConnector().getExamController(); try { boolean addMarks = ServerConnector.getServerConnector().getExamController().addMarks(exam); // Exam exam = examController.addMarks(PracticeExamLogIn.studentNic, newDate, anxCount); // if (addMarks) { // JOptionPane.showMessageDialog(QuestionLab.this, "Student Registered successfully !!"); // this.dispose(); // new LogIn(null, true).setVisible(true); // } else { // JOptionPane.showMessageDialog(QuestionLab.this, "Student Registered failed !!"); // } } catch (ClassNotFoundException | SQLException ex) { Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex); } } catch (NotBoundException | MalformedURLException ex) { Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex); } } catch (RemoteException ex) { Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex); } } catch (UnsupportedLookAndFeelException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (NotBoundException | MalformedURLException | RemoteException ex) { Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.diversityarrays.kdxplore.trialmgr.trait.TraitExplorerPanel.java
public TraitExplorerPanel(MessagePrinter mp, OfflineData od, DALClientProvider clientProvider, // KdxUploadHandler uploadHandler, BackgroundRunner backgroundRunner, ImageIcon addBarcodeIcon, Transformer<Trial, Boolean> checkIfEditorActive) { super(new BorderLayout()); this.backgroundRunner = backgroundRunner; this.clientProvider = clientProvider; // this.uploadHandler = uploadHandler; this.messagePrinter = mp; this.offlineData = od; this.checkIfEditorActive = checkIfEditorActive; offlineData.addOfflineDataChangeListener(offlineDataListener); editingLocked.setIcon(KDClientUtils.getIcon(ImageId.LOCKED)); editingLocked.addActionListener(new ActionListener() { @Override/* w ww . j a v a2s . c o m*/ public void actionPerformed(ActionEvent e) { changeEditable(editingLocked.isSelected(), DONT_OVERRIDE); } }); changeManager.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { updateUndoRedoActions(); } }); KDClientUtils.initAction(ImageId.TRASH_24, deleteTraitsAction, "Remove Trait"); deleteTraitsAction.setEnabled(false); KDClientUtils.initAction(ImageId.REFRESH_24, refreshAction, "Refresh Data"); KDClientUtils.initAction(ImageId.PLUS_BLUE_24, addNewTraitAction, "Add Trait"); KDClientUtils.initAction(ImageId.UPLOAD_24, uploadTraitsAction, "Upload Traits"); KDClientUtils.initAction(ImageId.ADD_TRIALS_24, importTraitsAction, "Import Traits"); KDClientUtils.initAction(ImageId.EXPORT_24, exportTraitsAction, "Export Traits"); try { Class.forName("com.diversityarrays.kdxplore.upload.TraitUploadTask"); } catch (ClassNotFoundException e1) { uploadTraitsAction.setEnabled(false); if (RunMode.getRunMode().isDeveloper()) { new Toast((JComponent) null, "<HTML>Developer Warning<BR>" + "Trait Upload currently unavailable<BR>", 4000) .showAsError(); } } traitPropertiesTable .setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(traitPropertiesTable, true)); traitPropertiesTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (traitPropertiesTableModel.getRowCount() > 0) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GuiUtil.initialiseTableColumnWidths(traitPropertiesTable); } }); traitPropertiesTableModel.removeTableModelListener(this); } } }); traitTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { showCorrectCard(); } }); TrialManagerPreferences preferences = TrialManagerPreferences.getInstance(); preferences.addChangeListener(TrialManagerPreferences.BAD_FOR_CALC, badForCalcColorChangeListener); badForCalc.setForeground(preferences.getBadForCalcColor()); badForCalc.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { KdxPreference<Color> pref = TrialManagerPreferences.BAD_FOR_CALC; String title = pref.getName(); KdxplorePreferenceEditor.startEditorDialog(TraitExplorerPanel.this, title, pref); } } }); traitsTable.setAutoCreateRowSorter(true); int index = traitTableModel.getTraitNameColumnIndex(); if (index >= 0) { traitsTable.getColumnModel().getColumn(index).setCellRenderer(traitNameCellRenderer); } traitsTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && 2 == e.getClickCount()) { e.consume(); int vrow = traitsTable.rowAtPoint(e.getPoint()); if (vrow >= 0) { int mrow = traitsTable.convertRowIndexToModel(vrow); if (mrow >= 0) { Trait trait = traitTableModel.getTraitAtRow(mrow); Integer selectViewRow = null; if (!traitTrialsTableModel.isSelectedTrait(trait)) { selectViewRow = vrow; } if (traitsEditable) { startEditingTraitInternal(trait, selectViewRow, null); } else { warnEditingLocked(); } } } } } }); traitsTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); traitsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { List<Trait> selectedTraits = getSelectedTraits(); traitTrialsTableModel.setSelectedTraits(selectedTraits); if (selectedTraits.size() == 1) { Trait trait = null; int vrow = traitsTable.getSelectedRow(); if (vrow >= 0) { int mrow = traitsTable.convertRowIndexToModel(vrow); if (mrow >= 0) { trait = traitTableModel.getEntityAt(mrow); } } showTraitDetails(trait); } deleteTraitsAction.setEnabled(selectedTraits.size() > 0); showCorrectCard(); } } }); TraitTableModel.initValidationExpressionRenderer(traitsTable); if (RunMode.getRunMode().isDeveloper()) { TraitTableModel.initTableForRawExpression(traitsTable); } cardPanel.add(noTraitsComponent, CARD_NO_TRAITS); cardPanel.add(selectTraitComponent, CARD_SELECT_TO_EDIT); cardPanel.add(new JScrollPane(traitPropertiesTable), CARD_TRAIT_EDITOR); JButton undoButton = initAction(undoAction, ImageId.UNDO_24, "Undo", KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); JButton redoButton = initAction(redoAction, ImageId.REDO_24, "Redo", KeyStroke.getKeyStroke('Y', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); Box undoRedoButtons = Box.createHorizontalBox(); undoRedoButtons.add(undoButton); undoRedoButtons.add(redoButton); JPanel detailsPanel = new JPanel(new BorderLayout()); detailsPanel.add(GuiUtil.createLabelSeparator("Details", undoRedoButtons), BorderLayout.NORTH); detailsPanel.add(cardPanel, BorderLayout.CENTER); detailsPanel.add(legendPanel, BorderLayout.SOUTH); PromptScrollPane scrollPane = new PromptScrollPane(traitsTable, "Drag/Drop Traits CSV file or use 'Import Traits'"); TableTransferHandler tth = TableTransferHandler.initialiseForCopySelectAll(traitsTable, true); traitsTable.setTransferHandler(new ChainingTransferHandler(flth, tth)); scrollPane.setTransferHandler(flth); if (addBarcodeIcon == null) { barcodesMenuAction.putValue(Action.NAME, "Barcodes..."); } else { barcodesMenuAction.putValue(Action.SMALL_ICON, addBarcodeIcon); } italicsForProtectedCheckbox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { traitNameCellRenderer.setUseItalicsForProtected(italicsForProtectedCheckbox.isSelected()); traitsTable.repaint(); } }); Box leftTopControls = Box.createHorizontalBox(); leftTopControls.add(importTraitsButton); leftTopControls.add(barcodesMenuButton); leftTopControls.add(new JButton(addNewTraitAction)); leftTopControls.add(new JButton(uploadTraitsAction)); leftTopControls.add(new JButton(exportTraitsAction)); leftTopControls.add(Box.createHorizontalGlue()); leftTopControls.add(editingLocked); leftTopControls.add(fixTraitLevelsButton); leftTopControls.add(refreshButton); leftTopControls.add(Box.createHorizontalStrut(8)); leftTopControls.add(new JButton(deleteTraitsAction)); // leftTopControls.add(Box.createHorizontalStrut(4)); Box explanations = Box.createHorizontalBox(); explanations.add(italicsForProtectedCheckbox); explanations.add(badForCalc); explanations.add(Box.createHorizontalGlue()); fixTraitLevelsButton.setToolTipText("Fix Traits with " + TraitLevel.UNDECIDABLE.visible + " 'Level'"); fixTraitLevelsButton.setVisible(false); JPanel leftTop = new JPanel(new BorderLayout()); leftTop.add(leftTopControls, BorderLayout.NORTH); leftTop.add(scrollPane, BorderLayout.CENTER); leftTop.add(explanations, BorderLayout.SOUTH); JPanel leftBot = new JPanel(new BorderLayout()); leftBot.add(GuiUtil.createLabelSeparator("Used by Trials"), BorderLayout.NORTH); leftBot.add(new PromptScrollPane(traitTrialsTable, "Any Trials using selected Traits appear here")); JSplitPane leftSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, leftTop, leftBot); leftSplit.setResizeWeight(0.5); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftSplit, detailsPanel); splitPane.setOneTouchExpandable(true); splitPane.setResizeWeight(0.5); add(splitPane, BorderLayout.CENTER); }
From source file:fi.hoski.remote.ui.Admin.java
private void editReservations(final EventType eventType) { final Event event = chooseEvent(eventType, "CHOOSE"); if (event != null) { final String eventTitle = TextUtil.getText(event.getEventType().name()) + " " + event.get(Event.EventDate); safeTitle = frame.getTitle();/*w ww .j av a 2s. c om*/ frame.setTitle(eventTitle); reservationList = dss.getReservations(event); selectedReservations = new ArrayList<Reservation>(); unSelectedReservations = new ArrayList<Reservation>(); if (Event.isInspection(eventType)) { for (Reservation reservation : reservationList) { Boolean inspected = (Boolean) reservation.get(Reservation.INSPECTED); if (inspected != null && inspected) { selectedReservations.add(reservation); } else { unSelectedReservations.add(reservation); } } } else { for (Reservation reservation : reservationList) { Long order = (Long) reservation.get(Reservation.ORDER); if (order != null && order != 0) { selectedReservations.add(reservation); } else { unSelectedReservations.add(reservation); } } } DataObjectModel baseModel = Reservation.getModel(eventType); DataObjectModel unorderedModel = null; DataObjectModel orderedModel = null; switch (eventType) { case LAUNCH: case LIFT: case HULL_INSPECTION: unorderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR); orderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR); break; case INSPECTION: unorderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR, Reservation.EMAIL, Reservation.MOBILEPHONE, Reservation.DOCK, Reservation.DOCKNUMBER, Reservation.INSPECTION_GASS, Reservation.INSPECTOR); orderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR, Reservation.EMAIL, Reservation.MOBILEPHONE, Reservation.DOCK, Reservation.DOCKNUMBER, Reservation.NOTES); break; } final DataObjectListTableModel<Reservation> unorderedTableModel = new DataObjectListTableModel<Reservation>( unorderedModel, unSelectedReservations); final JTable unorderedtable = new FitTable(unorderedTableModel); TableSelectionHandler tsh1 = new TableSelectionHandler(unorderedtable); unorderedtable.setDefaultRenderer(String.class, new StringTableCellRenderer()); unorderedtable.setDefaultRenderer(Text.class, new TextTableCellRenderer()); unorderedtable.addKeyListener(unorderedTableModel.getRemover(dss)); unorderedtable.setDragEnabled(true); unorderedtable.setDropMode(DropMode.INSERT_ROWS); TransferHandler unorderedTransferHandler = new DataObjectTransferHandler<Reservation>( unorderedTableModel); unorderedtable.setTransferHandler(unorderedTransferHandler); final DataObjectListTableModel<Reservation> orderedTableModel = new DataObjectListTableModel<Reservation>( orderedModel, selectedReservations); orderedTableModel.setEditable(Reservation.INSPECTION_CLASS, Reservation.INSPECTION_GASS, Reservation.BASICINSPECTION, Reservation.INSPECTOR); final JTable orderedtable = new FitTable(orderedTableModel); TableSelectionHandler tsh2 = new TableSelectionHandler(orderedtable); orderedtable.setDefaultRenderer(String.class, new StringTableCellRenderer()); orderedtable.setDefaultRenderer(Text.class, new TextTableCellRenderer()); orderedtable.addKeyListener(orderedTableModel.getRemover(dss)); orderedtable.setDragEnabled(true); orderedtable.setDropMode(DropMode.INSERT_ROWS); TransferHandler orderedTransferHandler = new DataObjectTransferHandler<Reservation>(orderedTableModel); orderedtable.setTransferHandler(orderedTransferHandler); if (Event.isInspection(eventType)) { unorderedtable.setAutoCreateRowSorter(true); orderedtable.setAutoCreateRowSorter(true); } leftPane = new JScrollPane(); leftPane.setViewport(new InfoViewport(TextUtil.getText(eventType.name() + "-leftPane"))); leftPane.setViewportView(unorderedtable); leftPane.setTransferHandler(unorderedTransferHandler); rightPane = new JScrollPane(); rightPane.setViewport(new InfoViewport(TextUtil.getText(eventType.name() + "-rightPane"))); rightPane.setViewportView(orderedtable); rightPane.setTransferHandler(orderedTransferHandler); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, rightPane); splitPane.setDividerLocation(0.5); menuReservation.setEnabled(false); safeContainer = frame.getContentPane(); JPanel contentPane = new JPanel(new BorderLayout()); contentPane.add(splitPane, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout()); contentPane.add(buttonPanel, BorderLayout.SOUTH); JButton saveButton = new JButton(); TextUtil.populate(saveButton, "SAVE"); saveButton.setEnabled(!Event.isInspection(eventType)); ActionListener saveAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveReservations(); } }; saveButton.addActionListener(saveAction); buttonPanel.add(saveButton); switch (eventType) { case INSPECTION: { if (privileged) { JButton inspectButton = new JButton(); TextUtil.populate(inspectButton, "SET INSPECTED"); ActionListener inspectAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { TableCellEditor cellEditor = orderedtable.getCellEditor(); if (cellEditor != null) { cellEditor.stopCellEditing(); } try { setAsInspected(); } catch (SQLException | ClassNotFoundException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; inspectButton.addActionListener(inspectAction); buttonPanel.add(inspectButton); } JButton addBoat = new JButton(); TextUtil.populate(addBoat, "ADD BOAT"); ActionListener addBoatAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Reservation reservation = reservate(eventType, event); if (reservation != null) { reservationList.add(reservation); unSelectedReservations.add(reservation); unorderedTableModel.fireTableDataChanged(); } } }; addBoat.addActionListener(addBoatAction); buttonPanel.add(addBoat); JButton printTypeButton = new JButton(); TextUtil.populate(printTypeButton, "PRINT"); ActionListener printTypeAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { printNameBoatTypeOrder(eventTitle); } catch (PrinterException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; printTypeButton.addActionListener(printTypeAction); buttonPanel.add(printTypeButton); JButton printDockButton = new JButton(); TextUtil.populate(printDockButton, "PRINT DOCK ORDER"); ActionListener printDockAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { printDockOrder(eventTitle); } catch (PrinterException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; printDockButton.addActionListener(printDockAction); buttonPanel.add(printDockButton); } break; case HULL_INSPECTION: { JButton print = new JButton(); TextUtil.populate(print, "PRINT"); ActionListener printAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { printAlphaOrder(eventTitle); } catch (PrinterException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; print.addActionListener(printAction); buttonPanel.add(print); } break; case LAUNCH: case LIFT: { JButton addBoat = new JButton(); TextUtil.populate(addBoat, "ADD BOAT"); ActionListener addBoatAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Reservation reservation = reservate(eventType, event); if (reservation != null) { reservationList.add(reservation); unSelectedReservations.add(reservation); unorderedTableModel.fireTableDataChanged(); } } }; addBoat.addActionListener(addBoatAction); buttonPanel.add(addBoat); JButton printBrief = new JButton(); TextUtil.populate(printBrief, "BRIEF PRINT"); ActionListener printBriefAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { printOrderBrief(eventTitle); } catch (PrinterException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; printBrief.addActionListener(printBriefAction); buttonPanel.add(printBrief); JButton print = new JButton(); TextUtil.populate(print, "PRINT"); ActionListener printAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { if (eventType == EventType.LAUNCH) { printLaunchOrder(eventTitle); } else { printLiftOrder(eventTitle); } } catch (PrinterException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.getMessage()); } } }; print.addActionListener(printAction); buttonPanel.add(print); } break; } JButton cancelButton = new JButton(); TextUtil.populate(cancelButton, "CANCEL"); ActionListener cancelAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cancel(); } }; cancelButton.addActionListener(cancelAction); buttonPanel.add(cancelButton); frame.setContentPane(contentPane); frame.pack(); frame.setVisible(true); KeyListener keyListener = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == 10) { int selectedRow = unorderedtable.getSelectedRow(); if (selectedRow != -1) { RowSorter<? extends TableModel> rowSorter = unorderedtable.getRowSorter(); if (rowSorter != null) { selectedRow = rowSorter.convertRowIndexToModel(selectedRow); } Reservation reservation = unorderedTableModel.getObject(selectedRow); orderedTableModel.add(reservation); unorderedTableModel.remove(reservation); e.consume(); unorderedtable.changeSelection(selectedRow, 0, false, false); } } } }; unorderedtable.addKeyListener(keyListener); unorderedtable.requestFocusInWindow(); } }