List of usage examples for java.awt.event WindowListener WindowListener
WindowListener
From source file:fi.elfcloud.client.dialog.UploadDialog.java
public UploadDialog(BeaverGUI gui, ClusterNode root) { setTitle(Messages.getString("UploadDialog.window_title_init")); //$NON-NLS-1$ progressBar.setIndeterminate(true);/* ww w .ja va 2 s . c om*/ task = new UploadTask(); task.addPropertyChangeListener(this); task.setup(gui, root); cancel.addActionListener(this); addWindowListener(new WindowListener() { @Override public void windowActivated(WindowEvent arg0) { } @Override public void windowClosed(WindowEvent arg0) { } @Override public void windowClosing(WindowEvent arg0) { task.cancel(true); } @Override public void windowDeactivated(WindowEvent arg0) { } @Override public void windowDeiconified(WindowEvent arg0) { } @Override public void windowIconified(WindowEvent arg0) { } @Override public void windowOpened(WindowEvent arg0) { } }); setVisible(true); }
From source file:ru.apertum.qsystem.client.forms.FAdmin.java
/** * Creates new form FAdmin/*ww w . j a v a2 s .c o m*/ */ public FAdmin() { addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { timer.stop(); } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { Uses.closeSplash(); } @Override public void windowDeactivated(WindowEvent e) { } }); initComponents(); setTitle(getTitle() + " " + Uses.getLocaleMessage("project.name" + FAbout.getCMRC_SUFF())); try { setIconImage( ImageIO.read(FAdmin.class.getResource("/ru/apertum/qsystem/client/forms/resources/admin.png"))); } catch (IOException ex) { System.err.println(ex); } // final Toolkit kit = Toolkit.getDefaultToolkit(); setLocation((Math.round(kit.getScreenSize().width - getWidth()) / 2), (Math.round(kit.getScreenSize().height - getHeight()) / 2)); // ? ? final JFrame fr = this; tray = QTray.getInstance(fr, "/ru/apertum/qsystem/client/forms/resources/admin.png", getLocaleMessage("tray.caption")); tray.addItem(getLocaleMessage("tray.caption"), (ActionEvent e) -> { setVisible(true); setState(JFrame.NORMAL); }); tray.addItem("-", (ActionEvent e) -> { }); tray.addItem(getLocaleMessage("tray.exit"), (ActionEvent e) -> { dispose(); System.exit(0); }); int ii = 1; final ButtonGroup bg = new ButtonGroup(); final String currLng = Locales.getInstance().getLangCurrName(); for (String lng : Locales.getInstance().getAvailableLocales()) { final JRadioButtonMenuItem item = new JRadioButtonMenuItem( org.jdesktop.application.Application.getInstance(ru.apertum.qsystem.QSystem.class).getContext() .getActionMap(FAdmin.class, fr).get("setCurrentLang")); bg.add(item); item.setSelected(lng.equals(currLng)); item.setText(lng); // NOI18N item.setName("QRadioButtonMenuItem" + (ii++)); // NOI18N menuLangs.add(item); } // ?? ??. listUsers.addListSelectionListener((ListSelectionEvent e) -> { userListChange(); }); // ?? ??. listResponse.addListSelectionListener((ListSelectionEvent e) -> { responseListChange(); }); listSchedule.addListSelectionListener((ListSelectionEvent e) -> { scheduleListChange(); }); listCalendar.addListSelectionListener(new ListSelectionListener() { private int oldSelectedValue = 0; private int tmp = 0; public int getOldSelectedValue() { return oldSelectedValue; } public void setOldSelectedValue(int oldSelectedValue) { this.oldSelectedValue = tmp; this.tmp = oldSelectedValue; } private boolean canceled = false; @Override public void valueChanged(ListSelectionEvent e) { if (canceled) { canceled = false; } else { if (tableCalendar.getModel() instanceof CalendarTableModel) { final CalendarTableModel model = (CalendarTableModel) tableCalendar.getModel(); if (!model.isSaved()) { final int res = JOptionPane.showConfirmDialog(null, getLocaleMessage("calendar.change.title"), getLocaleMessage("calendar.change.caption"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (res) { case 0: // ? ?? model.save(); calendarListChange(); setOldSelectedValue(listCalendar.getSelectedIndex()); break; case 1: // ?? ?? calendarListChange(); setOldSelectedValue(listCalendar.getSelectedIndex()); break; case 2: // ?? ??? canceled = true; listCalendar.setSelectedIndex(getOldSelectedValue()); break; } } else { calendarListChange(); setOldSelectedValue(listCalendar.getSelectedIndex()); } } else { calendarListChange(); setOldSelectedValue(listCalendar.getSelectedIndex()); } } } }); // ?? ? ??. treeServices.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); treeInfo.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); /* treeServices.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); setText(((Element) value).attributeValue(Uses.TAG_NAME)); return this; } });*/ treeServices.addTreeSelectionListener((TreeSelectionEvent e) -> { serviceListChange(); }); treeInfo.addTreeSelectionListener((TreeSelectionEvent e) -> { infoListChange(); }); textFieldStartTime.setInputVerifier(DateVerifier); textFieldFinishTime.setInputVerifier(DateVerifier); // ? loadSettings(); // ? ?. startTimer(); // loadConfig(); spinnerPropServerPort.getModel().addChangeListener(new ChangeNet()); spinnerPropClientPort.getModel().addChangeListener(new ChangeNet()); spinnerWebServerPort.getModel().addChangeListener(new ChangeNet()); spinnerServerPort.getModel().addChangeListener(new ChangeSettings()); spinnerClientPort.getModel().addChangeListener(new ChangeSettings()); spinnerUserRS.getModel().addChangeListener(new ChangeUser()); //? . final Helper helper = Helper.getHelp("ru/apertum/qsystem/client/help/admin.hs"); helper.setHelpListener(menuItemHelp); helper.enableHelpKey(jPanel1, "introduction"); helper.enableHelpKey(jPanel3, "monitoring"); helper.enableHelpKey(jPanel4, "configuring"); helper.enableHelpKey(jPanel8, "net"); helper.enableHelpKey(jPanel17, "schedulers"); helper.enableHelpKey(jPanel19, "calendars"); helper.enableHelpKey(jPanel2, "infoSystem"); helper.enableHelpKey(jPanel13, "responses"); helper.enableHelpKey(jPanel18, "results"); treeServices.setTransferHandler(new TransferHandler() { @Override public boolean canImport(TransferHandler.TransferSupport info) { final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation(); if (dl.getChildIndex() == -1) { return false; } // Get the string that is being dropped. final Transferable t = info.getTransferable(); final QService data; try { data = (QService) t.getTransferData(DataFlavor.stringFlavor); return (data.getParent().getId() .equals(((QService) dl.getPath().getLastPathComponent()).getId())); } catch (UnsupportedFlavorException | IOException e) { return false; } } @Override public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } final QService data; try { data = (QService) info.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException | IOException e) { System.err.println(e); return false; } final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation(); final TreePath tp = dl.getPath(); final QService parent = (QService) tp.getLastPathComponent(); ((QServiceTree) treeServices.getModel()).moveNode(data, parent, dl.getChildIndex()); return true; } @Override public int getSourceActions(JComponent c) { return MOVE; } @Override protected Transferable createTransferable(JComponent c) { return (QService) ((JTree) c).getLastSelectedPathComponent(); } }); treeServices.setDropMode(DropMode.INSERT); // ? final AnnotationSessionFactoryBean as = (AnnotationSessionFactoryBean) Spring.getInstance().getFactory() .getBean("conf"); if (as.getServers().size() > 1) { final JMenu menu = new JMenu(getLocaleMessage("admin.servers")); as.getServers().stream().map((ser) -> { final JMenuItem mi1 = new JMenuItem(as); mi1.setText(ser.isCurrent() ? "<html><u><i>" + ser.getName() + "</i></u>" : ser.getName()); return mi1; }).forEach((mi1) -> { menu.add(mi1); }); jMenuBar1.add(menu, 4); jMenuBar1.add(new JLabel( "<html><span style='font-size:13.0pt;color:red'> [" + as.getName() + "]")); } comboBoxVoices.setVisible(false); }
From source file:Proiect.uploadFTP.java
public void actionFTP() { adressf.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { InetAddress thisIp;//from w w w . j a v a 2 s . c om try { thisIp = InetAddress.getLocalHost(); titleFTP.setText("Connection: " + thisIp.getHostAddress() + " -> " + adressf.getText()); } catch (UnknownHostException e1) { e1.printStackTrace(); } } }); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { saveState(); uploadFTP.dispose(); tree.dispose(); } }); connect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FTPClient client = new FTPClient(); FileInputStream fis = null; String pass = String.valueOf(passf.getPassword()); try { if (filename == null) { status.setText("File does not exist!"); } else { // Server address client.connect(adressf.getText()); // Login credentials client.login(userf.getText(), pass); if (client.isConnected()) { status.setText("Succesfull transfer!"); // File type client.setFileType(FTP.BINARY_FILE_TYPE); // File location File file = new File(filepath); fis = new FileInputStream(file); // Change the folder on the server client.changeWorkingDirectory(folderf.getText()); // Save the file on the server client.storeFile(filename, fis); } else { status.setText("Transfer failed!"); } } client.logout(); } catch (IOException e1) { Encrypter.printException(e1); } finally { try { if (fis != null) { fis.close(); } client.disconnect(); } catch (IOException e1) { Encrypter.printException(e1); } } } }); browsef.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int retval = chooserf.showOpenDialog(chooserf); if (retval == JFileChooser.APPROVE_OPTION) { status.setText(""); filename = chooserf.getSelectedFile().getName().toString(); filepath = chooserf.getSelectedFile().getPath(); filenf.setText(chooserf.getSelectedFile().getName().toString()); } } }); adv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tree.setSize(220, uploadFTP.getHeight()); tree.setLocation(uploadFTP.getX() + 405, uploadFTP.getY()); tree.setResizable(false); tree.setIconImage(Toolkit.getDefaultToolkit() .getImage(getClass().getClassLoader().getResource("assets/ico.png"))); tree.setUndecorated(true); tree.getRootPane().setBorder(BorderFactory.createLineBorder(Encrypter.color_black, 2)); tree.setVisible(true); tree.setLayout(new BorderLayout()); JLabel labeltree = new JLabel("Server documents"); labeltree.setOpaque(true); labeltree.setBackground(Encrypter.color_light); labeltree.setBorder(BorderFactory.createMatteBorder(8, 10, 10, 0, Encrypter.color_light)); labeltree.setForeground(Encrypter.color_blue); labeltree.setFont(Encrypter.font16); JButton refresh = new JButton(""); ImageIcon refresh_icon = getImageIcon("assets/icons/refresh.png"); refresh.setIcon(refresh_icon); refresh.setBackground(Encrypter.color_light); refresh.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); refresh.setForeground(Encrypter.color_black); refresh.setFont(Encrypter.font16); refresh.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); final FTPClient client = new FTPClient(); DefaultMutableTreeNode top = new DefaultMutableTreeNode(adressf.getText()); DefaultMutableTreeNode files = null; DefaultMutableTreeNode leaf = null; final JTree tree_view = new JTree(top); tree_view.setForeground(Encrypter.color_black); tree_view.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); tree_view.putClientProperty("JTree.lineStyle", "None"); tree_view.setBackground(Encrypter.color_light); JScrollPane scrolltree = new JScrollPane(tree_view); scrolltree.setBackground(Encrypter.color_light); scrolltree.getVerticalScrollBar().setPreferredSize(new Dimension(0, 0)); UIManager.put("Tree.textBackground", Encrypter.color_light); UIManager.put("Tree.selectionBackground", Encrypter.color_blue); UIManager.put("Tree.selectionBorderColor", Encrypter.color_blue); tree_view.updateUI(); final String pass = String.valueOf(passf.getPassword()); try { client.connect(adressf.getText()); client.login(userf.getText(), pass); client.enterLocalPassiveMode(); if (client.isConnected()) { try { FTPFile[] ftpFiles = client.listFiles(); for (FTPFile ftpFile : ftpFiles) { files = new DefaultMutableTreeNode(ftpFile.getName()); top.add(files); if (ftpFile.getType() == FTPFile.DIRECTORY_TYPE) { FTPFile[] ftpFiles1 = client.listFiles(ftpFile.getName()); for (FTPFile ftpFile1 : ftpFiles1) { leaf = new DefaultMutableTreeNode(ftpFile1.getName()); files.add(leaf); } } } } catch (IOException e1) { Encrypter.printException(e1); } client.disconnect(); } else { status.setText("Failed connection!"); } } catch (IOException e1) { Encrypter.printException(e1); } finally { try { client.disconnect(); } catch (IOException e1) { Encrypter.printException(e1); } } tree.add(labeltree, BorderLayout.NORTH); tree.add(scrolltree, BorderLayout.CENTER); tree.add(refresh, BorderLayout.SOUTH); uploadFTP.addComponentListener(new ComponentListener() { public void componentMoved(ComponentEvent e) { tree.setLocation(uploadFTP.getX() + 405, uploadFTP.getY()); } public void componentShown(ComponentEvent e) { } public void componentResized(ComponentEvent e) { } public void componentHidden(ComponentEvent e) { } }); uploadFTP.addWindowListener(new WindowListener() { public void windowActivated(WindowEvent e) { tree.toFront(); } public void windowOpened(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } public void windowClosing(WindowEvent e) { } public void windowClosed(WindowEvent e) { } }); refresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tree.dispose(); tree.setVisible(true); } }); } }); }
From source file:se.llbit.chunky.renderer.ui.RenderControls.java
private void buildUI() { setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); setModalityType(ModalityType.MODELESS); if (!ShutdownAlert.canShutdown()) { // disable the computer shutdown checkbox if we can't shutdown shutdownWhenDoneCB.setEnabled(false); }/* w w w. jav a 2 s . c om*/ addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { sceneMan.interrupt(); RenderControls.this.dispose(); } @Override public void windowClosed(WindowEvent e) { // halt rendering renderMan.interrupt(); // dispose of the 3D view view.setVisible(false); view.dispose(); } @Override public void windowActivated(WindowEvent e) { } }); updateTitle(); addTab("General", Icon.wrench, buildGeneralPane()); addTab("Lighting", Icon.light, buildLightingPane()); addTab("Sky", Icon.sky, buildSkyPane()); addTab("Water", Icon.water, buildWaterPane()); addTab("Camera", Icon.camera, buildCameraPane()); addTab("Post-processing", Icon.gear, buildPostProcessingPane()); addTab("Advanced", Icon.advanced, buildAdvancedPane()); addTab("Help", Icon.question, buildHelpPane()); JLabel sppTargetLbl = new JLabel("SPP Target: "); sppTargetLbl.setToolTipText("The render will be paused at this SPP count"); JButton setDefaultBtn = new JButton("Make Default"); setDefaultBtn.setToolTipText("Make the current SPP target the default"); setDefaultBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PersistentSettings.setSppTargetDefault(renderMan.scene().getTargetSPP()); } }); targetSPP.update(); JLabel renderLbl = new JLabel("Render: "); setViewVisible(false); showPreviewBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (view.isViewVisible()) { view.hideView(); } else { showPreviewWindow(); } } }); startRenderBtn.setText("START"); startRenderBtn.setIcon(Icon.play.imageIcon()); startRenderBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { switch (renderMan.scene().getRenderState()) { case PAUSED: renderMan.scene().resumeRender(); break; case PREVIEW: renderMan.scene().startRender(); break; case RENDERING: renderMan.scene().pauseRender(); break; } stopRenderBtn.setEnabled(true); } }); stopRenderBtn.setText("RESET"); stopRenderBtn.setIcon(Icon.stop.imageIcon()); stopRenderBtn.setToolTipText("<html>Warning: this will discard the " + "current rendered image!<br>Make sure to save your image " + "before stopping the renderer!"); stopRenderBtn.setEnabled(false); stopRenderBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { renderMan.scene().haltRender(); } }); saveFrameBtn.setText("Save Current Frame"); saveFrameBtn.addActionListener(saveFrameListener); sppLbl.setToolTipText("SPP = Samples Per Pixel, SPS = Samples Per Second"); setRenderTime(0); setSamplesPerSecond(0); setSPP(0); setProgress("Progress:", 0, 0, 1); progressLbl.setText("Progress:"); etaLbl.setText("ETA:"); sceneNameLbl.setText("Scene name: "); sceneNameField.setColumns(15); AbstractDocument document = (AbstractDocument) sceneNameField.getDocument(); document.setDocumentFilter(new SceneNameFilter()); document.addDocumentListener(sceneNameListener); sceneNameField.addActionListener(sceneNameActionListener); updateSceneNameField(); saveSceneBtn.setText("Save"); saveSceneBtn.setIcon(Icon.disk.imageIcon()); saveSceneBtn.addActionListener(saveSceneListener); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup() .addGroup(layout.createSequentialGroup().addComponent(sceneNameLbl).addComponent(sceneNameField) .addPreferredGap(ComponentPlacement.RELATED).addComponent(saveSceneBtn)) .addComponent(tabbedPane) .addGroup(layout.createSequentialGroup().addGroup(targetSPP.horizontalGroup(layout)) .addPreferredGap(ComponentPlacement.RELATED).addComponent(setDefaultBtn)) .addGroup(layout.createSequentialGroup().addComponent(renderLbl) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(startRenderBtn) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(stopRenderBtn)) .addGroup( layout.createSequentialGroup().addComponent(saveFrameBtn) .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(showPreviewBtn)) .addGroup( layout.createSequentialGroup().addComponent(renderTimeLbl) .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(sppLbl)) .addGroup( layout.createSequentialGroup().addComponent(progressLbl) .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(etaLbl)) .addComponent(progressBar)).addContainerGap()); layout.setVerticalGroup( layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(sceneNameLbl) .addComponent(sceneNameField).addComponent(saveSceneBtn)) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(tabbedPane) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addGroup(targetSPP.verticalGroup(layout)).addComponent(setDefaultBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(renderLbl) .addComponent(startRenderBtn).addComponent(stopRenderBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup().addComponent(saveFrameBtn) .addComponent(showPreviewBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup().addComponent(renderTimeLbl).addComponent(sppLbl)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup().addComponent(progressLbl).addComponent(etaLbl)) .addComponent(progressBar).addContainerGap()); final JScrollPane scrollPane = new JScrollPane(panel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); setContentPane(scrollPane); scrollPane.getViewport().addChangeListener(new ChangeListener() { private boolean resized = false; @Override public void stateChanged(ChangeEvent e) { if (!resized && scrollPane.getVerticalScrollBar().isVisible()) { Dimension vsbPrefSize = new JScrollPane().getVerticalScrollBar().getPreferredSize(); Dimension size = getSize(); setSize(size.width + vsbPrefSize.width, size.height); resized = true; } } }); pack(); setLocationRelativeTo(chunky.getFrame()); setVisible(true); }
From source file:org.revager.gui.findings_list.FindingsListFrame.java
public FindingsListFrame(boolean fullscreen) { super();/*from w ww.ja va2s .c o m*/ this.fullscreen = fullscreen; this.nativeFullscrSupported = gd.isFullScreenSupported(); /* * Because of some problems do not use the native fullscreen * functionality */ if (UI.getInstance().getPlatform() == UI.Platform.WINDOWS || UI.getInstance().getPlatform() == UI.Platform.MAC) { nativeFullscrSupported = false; } UI.getInstance().getProtocolClockWorker().addPropertyChangeListener(evt -> { Object value = evt.getNewValue(); if (value instanceof Integer) { updateClock((int) value); updateCurrentTime(); } }); setTitle(translate("List of Findings")); setStatusMessage(translate("List of findings successfully loaded."), false); getContentPane().setLayout(new BorderLayout()); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); /* * Format bottom panel in org tab */ bottomOrgPanel.setBackground(UI.TABLE_ALT_COLOR); bottomOrgPanel.setBorder(new EmptyBorder(20, 0, 30, 0)); GUITools.addComponent(tabPanelOrg, gbl, attPanel, 0, 0, 1, 1, 1.0, 1.0, 0, 0, 20, 0, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelOrg, gbl, new JSeparator(), 0, 1, 1, 1, 1.0, 0.0, 0, 0, 0, 0, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelOrg, gbl, bottomOrgPanel, 0, 2, 1, 1, 1.0, 0.0, 0, 0, 0, 0, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); createToolBar(); setLocationToCenter(); if (fullscreen) { setUndecorated(true); if (!nativeFullscrSupported) { setMinimumSize(Toolkit.getDefaultToolkit().getScreenSize()); setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize()); setSize(Toolkit.getDefaultToolkit().getScreenSize()); setLocation(0, 0); setResizable(false); setAlwaysOnTop(true); } toFront(); // Dimension screenSize = // Toolkit.getDefaultToolkit().getScreenSize(); // setPreferredSize(screenSize); } else { setMinimumSize(new Dimension(900, 710)); setPreferredSize(new Dimension(900, 710)); pack(); } setExtendedState(Frame.MAXIMIZED_BOTH); createHints(); addWindowListener(new WindowListener() { @Override public void windowActivated(WindowEvent e) { } @Override public void windowClosed(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { if (StringUtils.isBlank(protCommTxtArea.getText())) { currentProt.setComments(""); } GUITools.executeSwingWorker(new ImageEditorWriteWorker(currentProt)); setVisible(false); } @Override public void windowDeactivated(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { if (isFullscreen()) { setExtendedState(MAXIMIZED_BOTH); } } @Override public void windowOpened(WindowEvent e) { } }); GUITools.executeSwingWorker(updateWorker); }
From source file:org.jets3t.apps.uploader.Uploader.java
/** * Run the Uploader as a stand-alone application. * * @param args// w ww .j ava 2s .c o m * @throws Exception */ public static void main(String args[]) throws Exception { JFrame ownerFrame = new JFrame("JetS3t Uploader"); ownerFrame.addWindowListener(new WindowListener() { public void windowOpened(WindowEvent e) { } public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } public void windowClosed(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } }); // Read arguments as properties of the form: <propertyName>'='<propertyValue> Properties argumentProperties = new Properties(); if (args.length > 0) { for (int i = 0; i < args.length; i++) { String arg = args[i]; int delimIndex = arg.indexOf("="); if (delimIndex >= 0) { String name = arg.substring(0, delimIndex); String value = arg.substring(delimIndex + 1); argumentProperties.put(name, value); } else { System.out.println("Ignoring property argument with incorrect format: " + arg); } } } new Uploader(ownerFrame, argumentProperties); }
From source file:com.maxl.java.amikodesk.AMiKoDesk.java
private static void createAndShowLightGUI() { // Create and setup window final JFrame jframe = new JFrame(Constants.APP_NAME); int min_width = CML_OPT_WIDTH; int min_height = CML_OPT_HEIGHT; jframe.setPreferredSize(new Dimension(min_width, min_height)); jframe.setMinimumSize(new Dimension(min_width, min_height)); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screen.width - min_width) / 2; int y = (screen.height - min_height) / 2; jframe.setBounds(x, y, min_width, min_height); // Action listeners jframe.addWindowListener(new WindowListener() { // Use WindowAdapter! @Override//w w w . j ava2 s.c o m public void windowOpened(WindowEvent e) { } @Override public void windowClosed(WindowEvent e) { m_web_panel.dispose(); Runtime.getRuntime().exit(0); } @Override public void windowClosing(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); // Container final Container container = jframe.getContentPane(); container.setBackground(Color.WHITE); container.setLayout(new BorderLayout()); // ==== Light panel ==== JPanel light_panel = new JPanel(); light_panel.setBackground(Color.WHITE); light_panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(2, 2, 2, 2); // ---- Section titles ---- m_section_titles = null; if (Utilities.appLanguage().equals("de")) { m_section_titles = new IndexPanel(SectionTitle_DE); } else if (Utilities.appLanguage().equals("fr")) { m_section_titles = new IndexPanel(SectionTitle_FR); } gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 8; gbc.weightx = gbc.weighty = 0.0; // --> container.add(m_section_titles, gbc); if (m_section_titles != null) light_panel.add(m_section_titles, gbc); // ---- Fachinformation ---- m_web_panel = new WebPanel2(); gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 1; gbc.gridy = 0; gbc.gridwidth = 3; gbc.gridheight = 20; gbc.weightx = 2.0; gbc.weighty = 1.0; gbc.anchor = GridBagConstraints.EAST; // --> container.add(m_web_panel, gbc); light_panel.add(m_web_panel, gbc); // ---- Add panel to main container ---- container.add(light_panel, BorderLayout.CENTER); // Display window jframe.pack(); // jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // jframe.setAlwaysOnTop(true); jframe.setVisible(true); // If command line options are provided start app with a particular // title or eancode if (commandLineOptionsProvided()) { final JToggleButton but_dummy = new JToggleButton("dummy_button"); if (!CML_OPT_TITLE.isEmpty()) startAppWithTitle(but_dummy); else if (!CML_OPT_EANCODE.isEmpty()) startAppWithEancode(but_dummy); else if (!CML_OPT_REGNR.isEmpty()) startAppWithRegnr(but_dummy); else if (CML_OPT_SERVER == true) { // Start thread that reads data from TCP server Thread server_thread = new Thread() { public void run() { while (true) { String tcpServerInput = ""; // Wait until new data is available from input stream // Note: the TCP client defines the update rate! // System.out.print("Waiting for input..."); while ((tcpServerInput = mTcpServer.getInput()).isEmpty()) ; /* * Important note: we use invokeLater to post a "job" to Swing, which will then be run on the * event dispatch thread at Swing's next convenience. Failing to do so will freeze the main thread. */ // Detect type of search (t=title, e=eancode, r=regnr) char typeOfSearch = tcpServerInput.charAt(0); if (typeOfSearch == 't') { // Extract title from received string CML_OPT_TITLE = tcpServerInput.substring(2); // System.out.println(" title -> " + // CML_OPT_TITLE); // Post a "job" to Swing, which will be run on // the event dispatch thread // at its next convenience. SwingUtilities.invokeLater(new Runnable() { public void run() { startAppWithTitle(but_dummy); } }); } else if (typeOfSearch == 'e') { // Extract ean code from received string CML_OPT_EANCODE = tcpServerInput.substring(2); // System.out.println(" eancode -> " + // CML_OPT_EANCODE); // Post a "job" to Swing, which will be run on // the event dispatch thread // at its next convenience. SwingUtilities.invokeLater(new Runnable() { public void run() { startAppWithEancode(but_dummy); } }); } else if (typeOfSearch == 'r') { // Extract registration number from received // string CML_OPT_REGNR = tcpServerInput.substring(2); // System.out.println(" regnr -> " + // CML_OPT_REGNR); // Post a "job" to Swing, which will be run on // the event dispatch thread // at its next convenience. SwingUtilities.invokeLater(new Runnable() { public void run() { startAppWithRegnr(but_dummy); } }); } } } }; server_thread.start(); } } }
From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java
/** * Shows a dialog that enales the user to convert the lat/lon formats. *///from w ww .j a va 2 s .c o m protected void showGeoRefConvertDialog() { if (geoRefConvertDlg != null) { geoRefConvertDlg.toFront(); return; } UsageTracker.incrUsageCount("WB.ShowGeoRefConverter"); JStatusBar statusBar = UIRegistry.getStatusBar(); if (!workbench.containsGeoRefData()) { statusBar.setErrorMessage(getResourceString("NoGeoRefColumns")); return; } List<String> outputFormats = new Vector<String>(); String dddddd = getResourceString("DDDDDD"); String ddmmmm = getResourceString("DDMMMM"); String ddmmss = getResourceString("DDMMSS"); String ddddddnsew = getResourceString("DDDDDDNSEW"); String ddmmmmnsew = getResourceString("DDMMMMNSEW"); String ddmmssnsew = getResourceString("DDMMSSNSEW"); outputFormats.add(dddddd); outputFormats.add(ddmmmm); outputFormats.add(ddmmss); outputFormats.add(ddddddnsew); outputFormats.add(ddmmmmnsew); outputFormats.add(ddmmssnsew); final int locTabId = DBTableIdMgr.getInstance().getIdByClassName(Locality.class.getName()); final int latColIndex = workbench.getColumnIndex(locTabId, "latitude1"); final int lonColIndex = workbench.getColumnIndex(locTabId, "longitude1"); final int lat2ColIndex = workbench.getColumnIndex(locTabId, "latitude2"); final int lon2ColIndex = workbench.getColumnIndex(locTabId, "longitude2"); JFrame mainFrame = (JFrame) UIRegistry.getTopWindow(); String title = UIRegistry.getResourceString("GeoRefConv"); String description = UIRegistry.getResourceString("GeoRefConvDesc"); final ToggleButtonChooserPanel<String> toggle = new ToggleButtonChooserPanel<String>(outputFormats, description, Type.RadioButton); final JCheckBox symbolCkBx = UIHelper.createCheckBox(UIRegistry.getResourceString("GEOREF_USE_SYMBOLS")); JPanel pane = new JPanel(new BorderLayout()); pane.add(toggle, BorderLayout.CENTER); pane.add(symbolCkBx, BorderLayout.SOUTH); geoRefConvertDlg = new CustomDialog(mainFrame, title, false, CustomDialog.OKCANCEL, pane) { @Override public void setVisible(boolean visible) { super.setVisible(visible); Dimension prefSize = this.getPreferredSize(); prefSize.width += 60; this.setSize(prefSize); } @Override protected void cancelButtonPressed() { geoRefConvertDlg = null; super.cancelButtonPressed(); } @Override protected void okButtonPressed() { checkCurrentEditState(); // figure out which rows the user is working with int[] selection = spreadSheet.getSelectedRowModelIndexes(); if (selection.length == 0) { // if none are selected, map all of them int rowCnt = spreadSheet.getRowCount(); selection = new int[rowCnt]; for (int i = 0; i < rowCnt; ++i) { selection[i] = spreadSheet.convertRowIndexToModel(i); } } // since Arrays.copyOf() isn't in Java SE 5... int[] selRows = new int[selection.length]; for (int i = 0; i < selection.length; ++i) { selRows[i] = selection[i]; } // don't call super.okButtonPressed() b/c it will close the window isCancelled = false; btnPressed = OK_BTN; LatLonConverter.DEGREES_FORMAT degFmt = symbolCkBx.isSelected() ? LatLonConverter.DEGREES_FORMAT.Symbol : LatLonConverter.DEGREES_FORMAT.None; Vector<CellPosition> unconverted = new Vector<CellPosition>(); switch (toggle.getSelectedIndex()) { case 0: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } case 1: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } case 2: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_PLUS_MINUS.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } case 3: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.D_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } case 4: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DM_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } case 5: { unconverted.addAll(convertColumnContents(latColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lonColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); unconverted.addAll(convertColumnContents(lat2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Latitude, degFmt)); unconverted.addAll(convertColumnContents(lon2ColIndex, selRows, new GeoRefConverter(), GeoRefFormat.DMS_NSEW.name(), LatLonConverter.LATLON.Longitude, degFmt)); break; } } if (unconverted.size() != 0) { UIRegistry.displayLocalizedStatusBarError("WB_UNCONVERTED_GEOREFS", unconverted.size()); final JList<?> unconvertedcells = UIHelper.createList(unconverted); unconvertedcells.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent arg0) { CellPosition rowCol = (CellPosition) unconvertedcells.getSelectedValue(); spreadSheet.scrollCellToVisible(rowCol.getFirst(), rowCol.getSecond()); } }); JLabel lbl = UIHelper.createLabel(UIRegistry.getResourceString("WB_UNCONVERTED_GEOREFS_MSG")); JPanel innerPane = new JPanel(new BorderLayout()); innerPane.add(lbl, BorderLayout.NORTH); innerPane.add(unconvertedcells, BorderLayout.CENTER); CustomDialog cd = new CustomDialog((Frame) UIRegistry.getTopWindow(), UIRegistry.getResourceString("WB_UNCONVERTED_GEOREFS_TITLE"), false, CustomDialog.OKHELP, innerPane); cd.setHelpContext("UnconvertableGeoCoords"); UIHelper.centerAndShow(cd); } } }; geoRefConvertDlg.setModal(false); toggle.setSelectedIndex(0); toggle.setOkBtn(geoRefConvertDlg.getOkBtn()); toggle.createUI(); geoRefConvertDlg.addWindowListener(new WindowListener() { /* (non-Javadoc) * @see java.awt.event.WindowStateListener#windowStateChanged(java.awt.event.WindowEvent) */ @Override public void windowClosed(WindowEvent e) { geoRefConvertDlg = null; } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent) */ @Override public void windowActivated(WindowEvent arg0) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent) */ @Override public void windowClosing(WindowEvent arg0) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent) */ @Override public void windowDeactivated(WindowEvent arg0) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent) */ @Override public void windowDeiconified(WindowEvent arg0) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent) */ @Override public void windowIconified(WindowEvent arg0) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent) */ @Override public void windowOpened(WindowEvent arg0) { // TODO Auto-generated method stub } }); geoRefConvertDlg.setOkLabel(getResourceString("APPLY")); geoRefConvertDlg.setCancelLabel(getResourceString("CLOSE")); geoRefConvertDlg.setVisible(true); }
From source file:com.maxl.java.amikodesk.AMiKoDesk.java
private static void createAndShowFullGUI() { // Create and setup window final JFrame jframe = new JFrame(Constants.APP_NAME); jframe.setName(Constants.APP_NAME + ".main"); int min_width = CML_OPT_WIDTH; int min_height = CML_OPT_HEIGHT; jframe.setPreferredSize(new Dimension(min_width, min_height)); jframe.setMinimumSize(new Dimension(min_width, min_height)); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screen.width - min_width) / 2; int y = (screen.height - min_height) / 2; jframe.setBounds(x, y, min_width, min_height); // Set application icon if (Utilities.appCustomization().equals("ywesee")) { ImageIcon img = new ImageIcon(Constants.AMIKO_ICON); jframe.setIconImage(img.getImage()); } else if (Utilities.appCustomization().equals("desitin")) { ImageIcon img = new ImageIcon(Constants.DESITIN_ICON); jframe.setIconImage(img.getImage()); } else if (Utilities.appCustomization().equals("meddrugs")) { ImageIcon img = new ImageIcon(Constants.MEDDRUGS_ICON); jframe.setIconImage(img.getImage()); } else if (Utilities.appCustomization().equals("zurrose")) { ImageIcon img = new ImageIcon(Constants.AMIKO_ICON); jframe.setIconImage(img.getImage()); }//from ww w . j a v a2 s .co m // ------ Setup menubar ------ JMenuBar menu_bar = new JMenuBar(); // menu_bar.add(Box.createHorizontalGlue()); // --> aligns menu items to the right! // -- Menu "Datei" -- JMenu datei_menu = new JMenu("Datei"); if (Utilities.appLanguage().equals("fr")) datei_menu.setText("Fichier"); menu_bar.add(datei_menu); JMenuItem print_item = new JMenuItem("Drucken..."); JMenuItem settings_item = new JMenuItem(m_rb.getString("settings") + "..."); JMenuItem quit_item = new JMenuItem("Beenden"); if (Utilities.appLanguage().equals("fr")) { print_item.setText("Imprimer"); quit_item.setText("Terminer"); } datei_menu.add(print_item); datei_menu.addSeparator(); datei_menu.add(settings_item); datei_menu.addSeparator(); datei_menu.add(quit_item); // -- Menu "Aktualisieren" -- JMenu update_menu = new JMenu("Aktualisieren"); if (Utilities.appLanguage().equals("fr")) update_menu.setText("Mise jour"); menu_bar.add(update_menu); final JMenuItem updatedb_item = new JMenuItem("Aktualisieren via Internet..."); updatedb_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); JMenuItem choosedb_item = new JMenuItem("Aktualisieren via Datei..."); update_menu.add(updatedb_item); update_menu.add(choosedb_item); if (Utilities.appLanguage().equals("fr")) { updatedb_item.setText("Tlcharger la banque de donnes..."); updatedb_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK)); choosedb_item.setText("Ajourner la banque de donnes..."); } // -- Menu "Hilfe" -- JMenu hilfe_menu = new JMenu("Hilfe"); if (Utilities.appLanguage().equals("fr")) hilfe_menu.setText("Aide"); menu_bar.add(hilfe_menu); JMenuItem about_item = new JMenuItem("ber " + Constants.APP_NAME + "..."); JMenuItem ywesee_item = new JMenuItem(Constants.APP_NAME + " im Internet"); if (Utilities.appCustomization().equals("meddrugs")) ywesee_item.setText("med-drugs im Internet"); JMenuItem report_item = new JMenuItem("Error Report..."); JMenuItem contact_item = new JMenuItem("Kontakt..."); if (Utilities.appLanguage().equals("fr")) { // Extrawunsch med-drugs if (Utilities.appCustomization().equals("meddrugs")) about_item.setText(Constants.APP_NAME); else about_item.setText("A propos de " + Constants.APP_NAME + "..."); contact_item.setText("Contact..."); if (Utilities.appCustomization().equals("meddrugs")) ywesee_item.setText("med-drugs sur Internet"); else ywesee_item.setText(Constants.APP_NAME + " sur Internet"); report_item.setText("Rapport d'erreur..."); } hilfe_menu.add(about_item); hilfe_menu.add(ywesee_item); hilfe_menu.addSeparator(); hilfe_menu.add(report_item); hilfe_menu.addSeparator(); hilfe_menu.add(contact_item); // Menu "Abonnieren" (only for ywesee) JMenu subscribe_menu = new JMenu("Abonnieren"); if (Utilities.appLanguage().equals("fr")) subscribe_menu.setText("Abonnement"); if (Utilities.appCustomization().equals("ywesee")) { menu_bar.add(subscribe_menu); } jframe.setJMenuBar(menu_bar); // ------ Setup toolbar ------ JToolBar toolBar = new JToolBar("Database"); toolBar.setPreferredSize(new Dimension(jframe.getWidth(), 64)); final JToggleButton selectAipsButton = new JToggleButton( new ImageIcon(Constants.IMG_FOLDER + "aips32x32_bright.png")); final JToggleButton selectFavoritesButton = new JToggleButton( new ImageIcon(Constants.IMG_FOLDER + "favorites32x32_bright.png")); final JToggleButton selectInteractionsButton = new JToggleButton( new ImageIcon(Constants.IMG_FOLDER + "interactions32x32_bright.png")); final JToggleButton selectShoppingCartButton = new JToggleButton( new ImageIcon(Constants.IMG_FOLDER + "shoppingcart32x32_bright.png")); final JToggleButton selectComparisonCartButton = new JToggleButton( new ImageIcon(Constants.IMG_FOLDER + "comparisoncart32x32_bright.png")); final JToggleButton list_of_buttons[] = { selectAipsButton, selectFavoritesButton, selectInteractionsButton, selectShoppingCartButton, selectComparisonCartButton }; if (Utilities.appLanguage().equals("de")) { setupButton(selectAipsButton, "Kompendium", "aips32x32_gray.png", "aips32x32_dark.png"); setupButton(selectFavoritesButton, "Favoriten", "favorites32x32_gray.png", "favorites32x32_dark.png"); setupButton(selectInteractionsButton, "Interaktionen", "interactions32x32_gray.png", "interactions32x32_dark.png"); setupButton(selectShoppingCartButton, "Warenkorb", "shoppingcart32x32_gray.png", "shoppingcart32x32_dark.png"); setupButton(selectComparisonCartButton, "Preisvergleich", "comparisoncart32x32_gray.png", "comparisoncart32x32_dark.png"); } else if (Utilities.appLanguage().equals("fr")) { setupButton(selectAipsButton, "Compendium", "aips32x32_gray.png", "aips32x32_dark.png"); setupButton(selectFavoritesButton, "Favorites", "favorites32x32_gray.png", "favorites32x32_dark.png"); setupButton(selectInteractionsButton, "Interactions", "interactions32x32_gray.png", "interactions32x32_dark.png"); setupButton(selectShoppingCartButton, "Panier", "shoppingcart32x32_gray.png", "shoppingcart32x32_dark.png"); setupButton(selectComparisonCartButton, "Preisvergleich", "comparisoncart32x32_gray.png", "comparisoncart32x32_dark.png"); } // Add to toolbar and set up toolBar.setBackground(m_toolbar_bg); toolBar.add(selectAipsButton); toolBar.addSeparator(); toolBar.add(selectFavoritesButton); toolBar.addSeparator(); toolBar.add(selectInteractionsButton); if (!Utilities.appCustomization().equals("zurrose")) { toolBar.addSeparator(); toolBar.add(selectShoppingCartButton); } if (Utilities.appCustomization().equals("zurrorse")) { toolBar.addSeparator(); toolBar.add(selectComparisonCartButton); } toolBar.setRollover(true); toolBar.setFloatable(false); // Progress indicator (not working...) toolBar.addSeparator(new Dimension(32, 32)); toolBar.add(m_progress_indicator); // ------ Setup settingspage ------ final SettingsPage settingsPage = new SettingsPage(jframe, m_rb); // Attach observer to it settingsPage.addObserver(new Observer() { public void update(Observable o, Object arg) { System.out.println(arg); if (m_shopping_cart != null) { // Refresh some stuff m_shopping_basket.clear(); int index = m_shopping_cart.getCartIndex(); if (index > 0) m_web_panel.saveShoppingCartWithIndex(index); m_web_panel.updateShoppingHtml(); } } }); jframe.addWindowListener(new WindowListener() { // Use WindowAdapter! @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosed(WindowEvent e) { m_web_panel.dispose(); Runtime.getRuntime().exit(0); } @Override public void windowClosing(WindowEvent e) { // Save shopping cart int index = m_shopping_cart.getCartIndex(); if (index > 0 && m_web_panel != null) m_web_panel.saveShoppingCartWithIndex(index); } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); print_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { m_web_panel.print(); } }); settings_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { settingsPage.display(); } }); quit_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { try { // Save shopping cart int index = m_shopping_cart.getCartIndex(); if (index > 0 && m_web_panel != null) m_web_panel.saveShoppingCartWithIndex(index); // Save settings WindowSaver.saveSettings(); m_web_panel.dispose(); Runtime.getRuntime().exit(0); } catch (Exception e) { System.out.println(e); } } }); subscribe_menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent event) { if (Utilities.appCustomization().equals("ywesee")) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI( "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3UM84Z6WLFKZE")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } } @Override public void menuDeselected(MenuEvent event) { // do nothing } @Override public void menuCanceled(MenuEvent event) { // do nothing } }); contact_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (Utilities.appCustomization().equals("ywesee")) { if (Desktop.isDesktopSupported()) { try { URI mail_to_uri = URI .create("mailto:zdavatz@ywesee.com?subject=AmiKo%20Desktop%20Feedback"); Desktop.getDesktop().mail(mail_to_uri); } catch (IOException e) { // TODO: } } else { AmiKoDialogs cd = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()); cd.ContactDialog(); } } else if (Utilities.appCustomization().equals("desitin")) { if (Desktop.isDesktopSupported()) { try { URI mail_to_uri = URI .create("mailto:info@desitin.ch?subject=AmiKo%20Desktop%20Desitin%20Feedback"); Desktop.getDesktop().mail(mail_to_uri); } catch (IOException e) { // TODO: } } else { AmiKoDialogs cd = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()); cd.ContactDialog(); } } else if (Utilities.appCustomization().equals("meddrugs")) { if (Desktop.isDesktopSupported()) { try { URI mail_to_uri = URI.create( "mailto:med-drugs@just-medical.com?subject=med-drugs%20desktop%20Feedback"); Desktop.getDesktop().mail(mail_to_uri); } catch (IOException e) { // TODO: } } else { AmiKoDialogs cd = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()); cd.ContactDialog(); } } else if (Utilities.appCustomization().equals("zurrose")) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI("www.zurrose.ch/amiko")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } } }); report_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { // Check first m_application_folder otherwise resort to // pre-installed report String report_file = m_application_data_folder + "\\" + Constants.DEFAULT_AMIKO_REPORT_BASE + Utilities.appLanguage() + ".html"; if (!(new File(report_file)).exists()) report_file = System.getProperty("user.dir") + "/dbs/" + Constants.DEFAULT_AMIKO_REPORT_BASE + Utilities.appLanguage() + ".html"; // Open report file in browser if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new File(report_file).toURI()); } catch (IOException e) { // TODO: } } } }); ywesee_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (Utilities.appCustomization().equals("ywesee")) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI("http://www.ywesee.com/AmiKo/Desktop")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } else if (Utilities.appCustomization().equals("desitin")) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse( new URI("http://www.desitin.ch/produkte/arzneimittel-kompendium-apps/")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } else if (Utilities.appCustomization().equals("meddrugs")) { if (Desktop.isDesktopSupported()) { try { if (Utilities.appLanguage().equals("de")) Desktop.getDesktop().browse(new URI("http://www.med-drugs.ch")); else if (Utilities.appLanguage().equals("fr")) Desktop.getDesktop() .browse(new URI("http://www.med-drugs.ch/index.cfm?&newlang=fr")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } else if (Utilities.appCustomization().equals("zurrose")) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI("www.zurrose.ch/amiko")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } } }); about_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { AmiKoDialogs ad = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()); ad.AboutDialog(); } }); // Container final Container container = jframe.getContentPane(); container.setBackground(Color.WHITE); container.setLayout(new BorderLayout()); // ==== Toolbar ===== container.add(toolBar, BorderLayout.NORTH); // ==== Left panel ==== JPanel left_panel = new JPanel(); left_panel.setBackground(Color.WHITE); left_panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(2, 2, 2, 2); // ---- Search field ---- final SearchField searchField = new SearchField("Suche Prparat"); if (Utilities.appLanguage().equals("fr")) searchField.setText("Recherche Specialit"); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(searchField, gbc); left_panel.add(searchField, gbc); // ---- Buttons ---- // Names String l_title = "Prparat"; String l_author = "Inhaberin"; String l_atccode = "Wirkstoff / ATC Code"; String l_regnr = "Zulassungsnummer"; String l_ingredient = "Wirkstoff"; String l_therapy = "Therapie"; String l_search = "Suche"; if (Utilities.appLanguage().equals("fr")) { l_title = "Spcialit"; l_author = "Titulaire"; l_atccode = "Principe Active / Code ATC"; l_regnr = "Nombre Enregistration"; l_ingredient = "Principe Active"; l_therapy = "Thrapie"; l_search = "Recherche"; } ButtonGroup bg = new ButtonGroup(); JToggleButton but_title = new JToggleButton(l_title); setupToggleButton(but_title); bg.add(but_title); gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(but_title, gbc); left_panel.add(but_title, gbc); JToggleButton but_auth = new JToggleButton(l_author); setupToggleButton(but_auth); bg.add(but_auth); gbc.gridx = 0; gbc.gridy += 1; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(but_auth, gbc); left_panel.add(but_auth, gbc); JToggleButton but_atccode = new JToggleButton(l_atccode); setupToggleButton(but_atccode); bg.add(but_atccode); gbc.gridx = 0; gbc.gridy += 1; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(but_atccode, gbc); left_panel.add(but_atccode, gbc); JToggleButton but_regnr = new JToggleButton(l_regnr); setupToggleButton(but_regnr); bg.add(but_regnr); gbc.gridx = 0; gbc.gridy += 1; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(but_regnr, gbc); left_panel.add(but_regnr, gbc); JToggleButton but_therapy = new JToggleButton(l_therapy); setupToggleButton(but_therapy); bg.add(but_therapy); gbc.gridx = 0; gbc.gridy += 1; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(but_therapy, gbc); left_panel.add(but_therapy, gbc); // ---- Card layout ---- final CardLayout cardl = new CardLayout(); cardl.setHgap(-4); // HACK to make things look better!! final JPanel p_results = new JPanel(cardl); m_list_titles = new ListPanel(); m_list_auths = new ListPanel(); m_list_regnrs = new ListPanel(); m_list_atccodes = new ListPanel(); m_list_ingredients = new ListPanel(); m_list_therapies = new ListPanel(); // Contraints gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy += 1; gbc.gridwidth = 1; gbc.gridheight = 10; gbc.weightx = 1.0; gbc.weighty = 1.0; // p_results.add(m_list_titles, l_title); p_results.add(m_list_auths, l_author); p_results.add(m_list_regnrs, l_regnr); p_results.add(m_list_atccodes, l_atccode); p_results.add(m_list_ingredients, l_ingredient); p_results.add(m_list_therapies, l_therapy); // --> container.add(p_results, gbc); left_panel.add(p_results, gbc); left_panel.setBorder(null); // First card to show cardl.show(p_results, l_title); // ==== Right panel ==== JPanel right_panel = new JPanel(); right_panel.setBackground(Color.WHITE); right_panel.setLayout(new GridBagLayout()); // ---- Section titles ---- m_section_titles = null; if (Utilities.appLanguage().equals("de")) { m_section_titles = new IndexPanel(SectionTitle_DE); } else if (Utilities.appLanguage().equals("fr")) { m_section_titles = new IndexPanel(SectionTitle_FR); } m_section_titles.setMinimumSize(new Dimension(150, 150)); m_section_titles.setMaximumSize(new Dimension(320, 1000)); // ---- Fachinformation ---- m_web_panel = new WebPanel2(); m_web_panel.setMinimumSize(new Dimension(320, 150)); // Add JSplitPane on the RIGHT final int Divider_location = 150; final int Divider_size = 10; final JSplitPane split_pane_right = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, m_section_titles, m_web_panel); split_pane_right.setOneTouchExpandable(true); split_pane_right.setDividerLocation(Divider_location); split_pane_right.setDividerSize(Divider_size); // Add JSplitPane on the LEFT JSplitPane split_pane_left = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left_panel, split_pane_right /* right_panel */); split_pane_left.setOneTouchExpandable(true); split_pane_left.setDividerLocation(320); // Sets the pane divider location split_pane_left.setDividerSize(Divider_size); container.add(split_pane_left, BorderLayout.CENTER); // Add status bar on the bottom JPanel statusPanel = new JPanel(); statusPanel.setPreferredSize(new Dimension(jframe.getWidth(), 16)); statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); container.add(statusPanel, BorderLayout.SOUTH); final JLabel m_status_label = new JLabel(""); m_status_label.setHorizontalAlignment(SwingConstants.LEFT); statusPanel.add(m_status_label); // Add mouse listener searchField.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { searchField.setText(""); } }); final String final_title = l_title; final String final_author = l_author; final String final_atccode = l_atccode; final String final_regnr = l_regnr; final String final_therapy = l_therapy; final String final_search = l_search; // Internal class that implements switching between buttons final class Toggle { public void toggleButton(JToggleButton jbn) { for (int i = 0; i < list_of_buttons.length; ++i) { if (jbn == list_of_buttons[i]) list_of_buttons[i].setSelected(true); else list_of_buttons[i].setSelected(false); } } } ; // ------ Add toolbar action listeners ------ selectAipsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new Toggle().toggleButton(selectAipsButton); // Set state 'aips' if (!m_curr_uistate.getUseMode().equals("aips")) { m_curr_uistate.setUseMode("aips"); // Show middle pane split_pane_right.setDividerSize(Divider_size); split_pane_right.setDividerLocation(Divider_location); m_section_titles.setVisible(true); // SwingUtilities.invokeLater(new Runnable() { @Override public void run() { m_start_time = System.currentTimeMillis(); m_query_str = searchField.getText(); int num_hits = retrieveAipsSearchResults(false); m_status_label.setText(med_search.size() + " Suchresultate in " + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek."); // if (med_index < 0 && prev_med_index >= 0) med_index = prev_med_index; m_web_panel.updateText(); if (num_hits == 0) { m_web_panel.emptyPage(); } } }); } } }); selectFavoritesButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new Toggle().toggleButton(selectFavoritesButton); // Set state 'favorites' if (!m_curr_uistate.getUseMode().equals("favorites")) { m_curr_uistate.setUseMode("favorites"); // Show middle pane split_pane_right.setDividerSize(Divider_size); split_pane_right.setDividerLocation(Divider_location); m_section_titles.setVisible(true); // SwingUtilities.invokeLater(new Runnable() { @Override public void run() { m_start_time = System.currentTimeMillis(); // m_query_str = searchField.getText(); // Clear the search container med_search.clear(); for (String regnr : favorite_meds_set) { List<Medication> meds = m_sqldb.searchRegNr(regnr); if (!meds.isEmpty()) { // Add med database ID med_search.add(meds.get(0)); } } // Sort list of meds Collections.sort(med_search, new Comparator<Medication>() { @Override public int compare(final Medication m1, final Medication m2) { return m1.getTitle().compareTo(m2.getTitle()); } }); sTitle(); cardl.show(p_results, final_title); m_status_label.setText(med_search.size() + " Suchresultate in " + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek."); } }); } } }); selectInteractionsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new Toggle().toggleButton(selectInteractionsButton); // Set state 'interactions' if (!m_curr_uistate.getUseMode().equals("interactions")) { m_curr_uistate.setUseMode("interactions"); // Show middle pane split_pane_right.setDividerSize(Divider_size); split_pane_right.setDividerLocation(Divider_location); m_section_titles.setVisible(true); // SwingUtilities.invokeLater(new Runnable() { @Override public void run() { m_query_str = searchField.getText(); retrieveAipsSearchResults(false); // Switch to interaction mode m_web_panel.updateInteractionsCart(); m_web_panel.repaint(); m_web_panel.validate(); } }); } } }); selectShoppingCartButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String email_adr = m_prefs.get("emailadresse", ""); if (email_adr != null && email_adr.length() > 2) // Two chars is the minimum lenght for an email address m_preferences_ok = true; if (m_preferences_ok) { m_preferences_ok = false; // Check always new Toggle().toggleButton(selectShoppingCartButton); // Set state 'shopping' if (!m_curr_uistate.getUseMode().equals("shopping")) { m_curr_uistate.setUseMode("shopping"); // Show middle pane split_pane_right.setDividerSize(Divider_size); split_pane_right.setDividerLocation(Divider_location); m_section_titles.setVisible(true); // Set right panel title m_web_panel.setTitle(m_rb.getString("shoppingCart")); // Switch to shopping cart int index = 1; if (m_shopping_cart != null) { index = m_shopping_cart.getCartIndex(); m_web_panel.loadShoppingCartWithIndex(index); // m_shopping_cart.printShoppingBasket(); } // m_web_panel.updateShoppingHtml(); m_web_panel.updateListOfPackages(); if (m_first_pass == true) { m_first_pass = false; if (Utilities.appCustomization().equals("ywesee")) med_search = m_sqldb.searchAuth("ibsa"); else if (Utilities.appCustomization().equals("desitin")) med_search = m_sqldb.searchAuth("desitin"); sAuth(); cardl.show(p_results, final_author); } } } else { selectShoppingCartButton.setSelected(false); settingsPage.display(); } } }); selectComparisonCartButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new Toggle().toggleButton(selectComparisonCartButton); // Set state 'comparison' if (!m_curr_uistate.getUseMode().equals("comparison")) { m_curr_uistate.setUseMode("comparison"); // Hide middle pane m_section_titles.setVisible(false); split_pane_right.setDividerLocation(0); split_pane_right.setDividerSize(0); // SwingUtilities.invokeLater(new Runnable() { @Override public void run() { m_start_time = System.currentTimeMillis(); // Set right panel title m_web_panel.setTitle(getTitle("priceComp")); if (med_index >= 0) { if (med_id != null && med_index < med_id.size()) { Medication m = m_sqldb.getMediWithId(med_id.get(med_index)); String atc_code = m.getAtcCode(); if (atc_code != null) { String atc = atc_code.split(";")[0]; m_web_panel.fillComparisonBasket(atc); m_web_panel.updateComparisonCartHtml(); // Update pane on the left retrieveAipsSearchResults(false); } } } m_status_label.setText(rose_search.size() + " Suchresultate in " + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek."); } }); } } }); // ------ Add keylistener to text field (type as you go feature) ------ searchField.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { // keyReleased(KeyEvent e) // invokeLater potentially in the wrong place... more testing // required SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); m_start_time = System.currentTimeMillis(); m_query_str = searchField.getText(); // Queries for SQLite DB if (!m_query_str.isEmpty()) { if (m_query_type == 0) { if (m_curr_uistate.isComparisonMode()) { rose_search = m_rosedb.searchTitle(m_query_str); } else { med_search = m_sqldb.searchTitle(m_query_str); if (m_curr_uistate.databaseUsed().equals("favorites")) retrieveFavorites(); } sTitle(); cardl.show(p_results, final_title); } else if (m_query_type == 1) { if (m_curr_uistate.isComparisonMode()) { rose_search = m_rosedb.searchSupplier(m_query_str); } else { med_search = m_sqldb.searchAuth(m_query_str); if (m_curr_uistate.databaseUsed().equals("favorites")) retrieveFavorites(); } sAuth(); cardl.show(p_results, final_author); } else if (m_query_type == 2) { if (m_curr_uistate.isComparisonMode()) { rose_search = m_rosedb.searchATC(m_query_str); } else { med_search = m_sqldb.searchATC(m_query_str); if (m_curr_uistate.databaseUsed().equals("favorites")) retrieveFavorites(); } sATC(); cardl.show(p_results, final_atccode); } else if (m_query_type == 3) { if (m_curr_uistate.isComparisonMode()) { rose_search = m_rosedb.searchEan(m_query_str); } else { med_search = m_sqldb.searchRegNr(m_query_str); if (m_curr_uistate.databaseUsed().equals("favorites")) retrieveFavorites(); } sRegNr(); cardl.show(p_results, final_regnr); } else if (m_query_type == 4) { if (m_curr_uistate.isComparisonMode()) { rose_search = m_rosedb.searchTherapy(m_query_str); } else { med_search = m_sqldb.searchApplication(m_query_str); if (m_curr_uistate.databaseUsed().equals("favorites")) retrieveFavorites(); } sTherapy(); cardl.show(p_results, final_therapy); } else { // do nothing } int num_hits = 0; if (m_curr_uistate.isComparisonMode()) num_hits = rose_search.size(); else num_hits = med_search.size(); m_status_label.setText(num_hits + " Suchresultate in " + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek."); } } }); } }); // Add actionlisteners but_title.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); searchField.setText(final_search + " " + final_title); m_curr_uistate.setQueryType(m_query_type = 0); sTitle(); cardl.show(p_results, final_title); } }); but_auth.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); searchField.setText(final_search + " " + final_author); m_curr_uistate.setQueryType(m_query_type = 1); sAuth(); cardl.show(p_results, final_author); } }); but_atccode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); searchField.setText(final_search + " " + final_atccode); m_curr_uistate.setQueryType(m_query_type = 2); sATC(); cardl.show(p_results, final_atccode); } }); but_regnr.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); searchField.setText(final_search + " " + final_regnr); m_curr_uistate.setQueryType(m_query_type = 3); sRegNr(); cardl.show(p_results, final_regnr); } }); but_therapy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); searchField.setText(final_search + " " + final_therapy); m_curr_uistate.setQueryType(m_query_type = 4); sTherapy(); cardl.show(p_results, final_therapy); } }); // Display window jframe.pack(); // jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // jframe.setAlwaysOnTop(true); jframe.setVisible(true); // Check if user has selected an alternative database /* * NOTE: 21/11/2013: This solution is put on ice. Favored is a solution * where the database selected by the user is saved in a default folder * (see variable "m_application_data_folder") */ /* * try { WindowSaver.loadSettings(jframe); String database_path = * WindowSaver.getDbPath(); if (database_path!=null) * m_sqldb.loadDBFromPath(database_path); } catch(IOException e) { * e.printStackTrace(); } */ // Load AIPS database selectAipsButton.setSelected(true); selectFavoritesButton.setSelected(false); m_curr_uistate.setUseMode("aips"); med_search = m_sqldb.searchTitle(""); sTitle(); // Used instead of sTitle (which is slow) cardl.show(p_results, final_title); // Add menu item listeners updatedb_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (m_mutex_update == false) { m_mutex_update = true; String db_file = m_maindb_update.doIt(jframe, Utilities.appLanguage(), Utilities.appCustomization(), m_application_data_folder, m_full_db_update); // ... and update time if (m_full_db_update == true) { DateTime dT = new DateTime(); m_prefs.put("updateTime", dT.now().toString()); } // if (!db_file.isEmpty()) { // Save db path (can't hurt) WindowSaver.setDbPath(db_file); } } } }); choosedb_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String db_file = m_maindb_update.chooseFromFile(jframe, Utilities.appLanguage(), Utilities.appCustomization(), m_application_data_folder); // ... and update time DateTime dT = new DateTime(); m_prefs.put("updateTime", dT.now().toString()); // if (!db_file.isEmpty()) { // Save db path (can't hurt) WindowSaver.setDbPath(db_file); } } }); /** * Observers */ // Attach observer to 'm_update' m_maindb_update.addObserver(new Observer() { @Override public void update(Observable o, Object arg) { System.out.println(arg); // Reset flag m_full_db_update = true; m_mutex_update = false; // Refresh some stuff after update loadAuthors(); m_emailer.loadMap(); settingsPage.load_gln_codes(); if (m_shopping_cart != null) { m_shopping_cart.load_conditions(); m_shopping_cart.load_glns(); } // Empty shopping basket if (m_curr_uistate.isShoppingMode()) { m_shopping_basket.clear(); int index = m_shopping_cart.getCartIndex(); if (index > 0) m_web_panel.saveShoppingCartWithIndex(index); m_web_panel.updateShoppingHtml(); } if (m_curr_uistate.isComparisonMode()) m_web_panel.setTitle(getTitle("priceComp")); } }); // Attach observer to 'm_emailer' m_emailer.addObserver(new Observer() { @Override public void update(Observable o, Object arg) { System.out.println(arg); // Empty shopping basket m_shopping_basket.clear(); int index = m_shopping_cart.getCartIndex(); if (index > 0) m_web_panel.saveShoppingCartWithIndex(index); m_web_panel.updateShoppingHtml(); } }); // Attach observer to "m_comparison_cart" m_comparison_cart.addObserver(new Observer() { @Override public void update(Observable o, Object arg) { System.out.println(arg); m_web_panel.setTitle(getTitle("priceComp")); m_comparison_cart.clearUploadList(); m_web_panel.updateComparisonCartHtml(); new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()).UploadDialog((String) arg); } }); // If command line options are provided start app with a particular title or eancode if (commandLineOptionsProvided()) { if (!CML_OPT_TITLE.isEmpty()) startAppWithTitle(but_title); else if (!CML_OPT_EANCODE.isEmpty()) startAppWithEancode(but_regnr); else if (!CML_OPT_REGNR.isEmpty()) startAppWithRegnr(but_regnr); } // Start timer Timer global_timer = new Timer(); // Time checks all 2 minutes (120'000 milliseconds) global_timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { checkIfUpdateRequired(updatedb_item); } }, 2 * 60 * 1000, 2 * 60 * 1000); }
From source file:org.jets3t.apps.cockpitlite.CockpitLite.java
/** * Runs Cockpit as a stand-alone application. * @param args/*ww w.ja va 2 s. c o m*/ * @throws Exception */ public static void main(String args[]) throws Exception { JFrame ownerFrame = new JFrame("JetS3t Cockpit-Lite"); ownerFrame.addWindowListener(new WindowListener() { public void windowOpened(WindowEvent e) { } public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } public void windowClosed(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } }); // Read arguments as properties of the form: <propertyName>'='<propertyValue> Properties argumentProperties = new Properties(); if (args.length > 0) { for (int i = 0; i < args.length; i++) { String arg = args[i]; int delimIndex = arg.indexOf("="); if (delimIndex >= 0) { String name = arg.substring(0, delimIndex); String value = arg.substring(delimIndex + 1); argumentProperties.put(name, value); } else { System.out.println("Ignoring property argument with incorrect format: " + arg); } } } new CockpitLite(ownerFrame, argumentProperties); }