List of usage examples for javax.swing JScrollPane setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:org.o3project.optsdn.don.frame.NeFrame.java
/** * Create a pane that displays Information Model ID list. * //from w w w . j a v a 2s.c o m * @param portList Ports * @return The pane that displays Information Model ID list */ private JScrollPane createInformationModelIdListPane(List<Port> portList) { Collections.sort(portList, new PortComparator()); Object[] columnNames = INFORMATION_MODEL_ID_COLNAME_LIST.toArray(); DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0); for (Port port : portList) { Port[] column = { port, port }; tableModel.addRow(column); } JTable informationModeldTable = new JTable(tableModel); informationModeldTable.getTableHeader().setBackground(Color.WHITE); DefaultTableCellRenderer renderer = new InformationModelIdRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); informationModeldTable.setDefaultRenderer(Object.class, renderer); JScrollPane informationModelIdPane = new JScrollPane(); informationModelIdPane.getViewport().setView(informationModeldTable); informationModelIdPane .setPreferredSize(new Dimension(informationModelIdPane.getPreferredSize().width, TABLE_HEIGHT)); return informationModelIdPane; }
From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java
private JComponent createConsolePanel() { JTextArea consoleArea = new JTextArea(); consoleArea.setToolTipText("General progress information"); consoleArea.setEditable(false);/*from w w w . ja v a 2 s . c o m*/ Console console = new Console(); console.setTextArea(consoleArea); System.setOut(new PrintStream(console)); System.setErr(new PrintStream(console)); JScrollPane consoleScrollPane = new JScrollPane(consoleArea); consoleScrollPane.setBorder(BorderFactory.createTitledBorder("Console")); consoleScrollPane.setPreferredSize(new Dimension(800, 200)); consoleScrollPane.setAutoscrolls(true); ObjectExchange.console = console; return consoleScrollPane; }
From source file:org.onebusaway.phone.client.SimplePhoneClient.java
private static void setupGui(AgiClientScriptImpl script) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); KeyPressHandler handler = new KeyPressHandler(script); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.addKeyListener(handler);/* w w w .ja va2 s.co m*/ JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(4, 3)); panel.add(buttonPanel, BorderLayout.CENTER); String buttons = "123456789*0#"; for (int i = 0; i < buttons.length(); i++) addButton(buttonPanel, script, handler, buttons.charAt(i)); Document document = script.getDocument(); final JTextArea textArea = new JTextArea(document); textArea.setEditable(false); textArea.addKeyListener(handler); document.addDocumentListener(new ScrollDocumentToEnd(textArea)); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(300, 100)); scrollPane.addKeyListener(handler); panel.add(scrollPane, BorderLayout.SOUTH); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); }
From source file:org.openconcerto.erp.core.humanresources.payroll.element.VariablePayeSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private ValidState validVarName; private JRadioButton radioVal = new JRadioButton("Valeur"); private JRadioButton radioFormule = new JRadioButton("Formule"); private final JTextField textValeur = new JTextField(); // private final ITextArea textFormule = new ITextArea(); private final VariableTree treeVariable = new VariableTree(); private final JTextField textNom = new JTextField(); private final JLabel labelWarningBadVar = new JLabelWarning(); private ElementComboBox comboSelSal; private EditFrame edit = null; private final SQLJavaEditor textFormule = new SQLJavaEditor(getMapTree()); public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); this.validVarName = null; this.textFormule.setEditable(false); // Arbre des variables JScrollPane sc = new JScrollPane(this.treeVariable); sc.setPreferredSize(new Dimension(150, sc.getPreferredSize().height)); this.treeVariable.addMouseListener(new MouseAdapter() { public void mousePressed(final MouseEvent mE) { if (mE.getButton() == MouseEvent.BUTTON3) { JPopupMenu menuDroit = new JPopupMenu(); TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); final Object obj = path.getLastPathComponent(); if ((obj == null) || !(obj instanceof VariableRowTreeNode)) { return; }//from ww w . ja v a2 s. co m menuDroit.add(new AbstractAction("Editer") { public void actionPerformed(ActionEvent e) { if (edit == null) { edit = new EditFrame(getElement(), EditFrame.MODIFICATION); } System.err.println("Action performed"); if (obj != null) { System.err.println("Object not null --> " + obj.toString()); if (obj instanceof VariableRowTreeNode) { System.err.println("Object VariableRowTreeNode"); VariableRowTreeNode varNode = (VariableRowTreeNode) obj; edit.selectionId(varNode.getID(), 1); edit.setVisible(true); } } } }); menuDroit.show((Component) mE.getSource(), mE.getPoint().x, mE.getPoint().y); } else { if (mE.getClickCount() == 2) { TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); Object obj = path.getLastPathComponent(); if (obj != null) { if (obj instanceof FormuleTreeNode) { final FormuleTreeNode n = (FormuleTreeNode) obj; int start = textFormule.getSelectionStart(); String tmp = textFormule.getText(); textFormule.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length())); } } } } } }); JPanel panelDroite = new JPanel(); panelDroite.setLayout(new GridBagLayout()); // Categorie JTextField textCategorie = new JTextField(); c.fill = GridBagConstraints.HORIZONTAL; c.gridheight = 1; c.gridx = 1; c.gridy = 0; JLabel labelCategorie = new JLabel("Catgorie"); panelDroite.add(labelCategorie, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(textCategorie, c); c.gridwidth = 1; // Nom c.fill = GridBagConstraints.HORIZONTAL; c.gridheight = 1; c.gridx = 1; c.gridy++; JLabel labelNom = new JLabel("Nom"); panelDroite.add(labelNom, c); c.gridx++; c.weightx = 1; panelDroite.add(this.textNom, c); this.textNom.getDocument().addDocumentListener(new SimpleDocumentListener() { @Override public void update(DocumentEvent e) { updateValidVarName(); } }); c.gridx++; c.weightx = 0; panelDroite.add(this.labelWarningBadVar, c); // Description JLabel labelInfos = new JLabel(getLabelFor("INFOS")); ITextArea textInfos = new ITextArea(); c.gridy++; c.gridx = 1; c.gridwidth = 1; c.weightx = 0; panelDroite.add(labelInfos, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.weighty = 0; panelDroite.add(textInfos, c); // Valeur c.gridx = 1; c.gridy++; c.gridwidth = 1; c.weightx = 0; panelDroite.add(this.radioVal, c); c.gridx++; c.weightx = 1; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(this.textValeur, c); c.gridwidth = 1; c.gridx = 1; c.gridy++; panelDroite.add(this.radioFormule, c); c.gridx++; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(this.textFormule, c); c.gridwidth = 1; ButtonGroup group = new ButtonGroup(); group.add(this.radioVal); group.add(this.radioFormule); this.radioVal.setSelected(true); setFormuleEnabled(false); this.radioVal.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFormuleEnabled(false); } }); this.radioFormule.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFormuleEnabled(true); } }); c.gridy++; c.gridx = 1; c.weighty = 0; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.comboSelSal = new ElementComboBox(false); this.comboSelSal.init(getDirectory().getElement(SalarieSQLElement.class)); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; panelDroite.add(this.comboSelSal, c); c.gridwidth = 1; JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sc, panelDroite); c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; this.add(split, c); this.addRequiredSQLObject(this.textNom, "NOM"); this.addSQLObject(this.textValeur, "VALEUR"); this.addSQLObject(this.textFormule, "FORMULE"); this.addSQLObject(textCategorie, "CATEGORIE"); this.addSQLObject(textInfos, "INFOS"); this.comboSelSal.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // TODO Auto-generated method stub textFormule.setSalarieID(comboSelSal.getSelectedId()); } }); } @Override public synchronized ValidState getValidState() { return super.getValidState().and(this.validVarName); } private void setFormuleEnabled(boolean b) { if (b) { this.textValeur.setText(""); } else { this.textFormule.setText(""); } this.textValeur.setEditable(!b); this.textValeur.setEnabled(!b); this.textFormule.setEditable(b); this.textFormule.setEnabled(b); this.treeVariable.setEnabled(b); this.treeVariable.setEditable(b); } private void setValidVarName(ValidState s) { if (!s.equals(this.validVarName)) { this.validVarName = s; final boolean warningVisible = !s.isValid(); if (warningVisible) this.labelWarningBadVar.setText(s.getValidationText()); this.labelWarningBadVar.setVisible(warningVisible); this.fireValidChange(); } } private void updateValidVarName() { this.setValidVarName(this.computeValidVarName()); } private ValidState computeValidVarName() { // on vrifie si la syntaxe de la variable est correct (chiffre lettre et _) final String varName = this.textNom.getText().trim(); System.err.println("Verification de la validit du nom de la variable."); if (varName.length() == 0) { return VAR_NO_NAME; } // ne contient que des chiffre lettre et _ et ne commence pas par un chiffre if (!isJavaVar(varName)) { return VAR_NAME_NOT_CORRECT; } // on vrifie que la variable n'existe pas dja SQLSelect selAllVarName = new SQLSelect(getTable().getBase()); selAllVarName.addSelect(VariablePayeSQLElement.this.getTable().getField("ID")); Where w = new Where(VariablePayeSQLElement.this.getTable().getField("NOM"), "=", varName); w = w.and(new Where(VariablePayeSQLElement.this.getTable().getKey(), "!=", getSelectedID())); selAllVarName.setWhere(w); String reqAllVarName = selAllVarName.asString();// + " AND '" + varName.trim() + "' // REGEXP VARIABLE_PAYE.NOM"; Object[] objKeysRowName = ((List) getTable().getBase().getDataSource().execute(reqAllVarName, new ArrayListHandler())).toArray(); if (objKeysRowName.length > 0) { return VAR_ALREADY_EXIST; } else { // Impossible de crer une variable du meme nom qu'un champ du salarie if (isForbidden(varName)) return VAR_ALREADY_EXIST; this.textFormule.setVarAssign(varName); return ValidState.getTrueInstance(); } } private boolean isJavaVar(String s) { if ((s.charAt(0) >= '0') && ((s.charAt(0) <= '9'))) { System.err.println("Erreur la variable commence par un chiffre!!"); return false; } else { for (int i = 0; i < s.length(); i++) { if (!(((s.charAt(i) >= '0') && (s.charAt(i) <= '9')) || (s.charAt(i) >= 'a') && (s.charAt(i) <= 'z') || (s.charAt(i) >= 'A') && (s.charAt(i) <= 'Z') || (s.charAt(i) == '_'))) { System.err.println("Erreur la variable contient un caractere incorrect!!"); return false; } } return (!CTokenMarker.getKeywords().isExisting(s)); } } @Override public void select(SQLRowAccessor r) { super.select(r); // System.err.println("Select RowAccess -------> " + r.getID() + " For Object " + // this.hashCode()); if (r != null) { if (r.getString("FORMULE").trim().length() == 0) { this.radioVal.setSelected(true); setFormuleEnabled(false); } else { this.radioFormule.setSelected(true); setFormuleEnabled(true); } this.textFormule.setVarAssign(r.getString("NOM")); } this.updateValidVarName(); } }; }
From source file:org.opendatakit.briefcase.ui.ScrollingStatusListDialog.java
private ScrollingStatusListDialog(Frame frame, String title, IFormDefinition form, String statusHtml) { super(frame, title + form.getFormName(), true); this.form = form; AnnotationProcessor.process(this); // Create and initialize the buttons. JButton cancelButton = new JButton("Close"); cancelButton.addActionListener(this); getRootPane().setDefaultButton(cancelButton); editorArea = new JEditorPane("text/plain", statusHtml); editorArea.setEditable(false);/* ww w . ja v a 2s . co m*/ //Put the editor pane in a scroll pane. JScrollPane editorScrollPane = new JScrollPane(editorArea); editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(400, 300)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); // Create a container so that we can add a title around // the scroll pane. Can't add a title directly to the // scroll pane because its background would be white. // Lay out the label and scroll pane from top to bottom. JPanel listPane = new JPanel(); listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); listPane.add(Box.createRigidArea(new Dimension(0, 5))); listPane.add(editorScrollPane); listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // Lay out the buttons from left to right. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(cancelButton); // Put everything together, using the content pane's BorderLayout. Container contentPane = getContentPane(); contentPane.add(listPane, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.PAGE_END); // Initialize values. pack(); setLocationRelativeTo(null); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.ChannelAcquisitionComponent.java
/** * Sets the plane info for the specified channel. * //ww w. j a v a 2 s . com * @param index The index of the channel. */ void setPlaneInfo(int index) { if (channel.getIndex() != index) return; Collection result = model.getChannelPlaneInfo(index); String[][] values = new String[2][result.size() + 1]; String[] names = new String[result.size() + 1]; int i = 0; Iterator j = result.iterator(); PlaneInfo info; Map<String, Object> details; List<String> notSet; names[0] = "t"; values[0][i] = "Delta T"; values[1][i] = "Exposure"; i++; while (j.hasNext()) { info = (PlaneInfo) j.next(); details = EditorUtil.transformPlaneInfo(info); notSet = (List<String>) details.get(EditorUtil.NOT_SET); if (!notSet.contains(EditorUtil.DELTA_T)) { if (details.get(EditorUtil.DELTA_T) instanceof BigResult) { MetadataViewerAgent.logBigResultExeption(this, details.get(EditorUtil.DELTA_T), EditorUtil.DELTA_T); values[0][i] = "N/A"; } else { double tInS = ((Double) details.get(EditorUtil.DELTA_T)); values[0][i] = getReadableTime(tInS); } } else values[0][i] = "--"; if (!notSet.contains(EditorUtil.EXPOSURE_TIME)) { if (details.get(EditorUtil.EXPOSURE_TIME) instanceof BigResult) { MetadataViewerAgent.logBigResultExeption(this, details.get(EditorUtil.EXPOSURE_TIME), EditorUtil.EXPOSURE_TIME); values[1][i] = "N/A"; } else { double tInS = ((Double) details.get(EditorUtil.EXPOSURE_TIME)); values[1][i] = getReadableTime(tInS); } } else values[1][i] = "--"; names[i] = "t=" + i; i++; } if (i > 1) { JTable table = new JTable(values, names); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setShowGrid(true); table.setGridColor(Color.LIGHT_GRAY); JScrollPane pane = new JScrollPane(table); Dimension d = table.getPreferredSize(); Dimension de = exposureTask.getPreferredSize(); pane.setPreferredSize(new Dimension(de.width - 10, 4 * d.height)); exposureTask.add(pane); exposureTask.setVisible(true); } else { exposureTask.setVisible(false); } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java
/** * Creates the menu hosting the users belonging to the specified group. * Returns <code>true</code> if the group is selected, <code>false</code> * otherwise.// w ww.j a va 2s . co m * * @param groupItem The item hosting the group. * @param size The number of groups. * @return See above. */ private boolean createGroupMenu(GroupItem groupItem, int size) { long loggedUserID = model.getUserDetails().getId(); GroupData group = groupItem.getGroup(); //Determine the user already added to the display Browser browser = model.getBrowser(Browser.PROJECTS_EXPLORER); TreeImageDisplay refNode = null; List<TreeImageDisplay> nodes; ExperimenterVisitor visitor; List<Long> users = new ArrayList<Long>(); //Find the group already displayed if (group != null && size > 0) { visitor = new ExperimenterVisitor(browser, group.getId()); browser.accept(visitor); nodes = visitor.getNodes(); if (nodes.size() == 1) { refNode = nodes.get(0); } visitor = new ExperimenterVisitor(browser, -1, -1); if (refNode != null) refNode.accept(visitor); else if (size == 1) browser.accept(visitor); nodes = visitor.getNodes(); TreeImageDisplay n; if (CollectionUtils.isNotEmpty(nodes)) { Iterator<TreeImageDisplay> j = nodes.iterator(); while (j.hasNext()) { n = j.next(); if (n.getUserObject() instanceof ExperimenterData) { users.add(((ExperimenterData) n.getUserObject()).getId()); } } if (size == 1) { groupItem.setMenuSelected(true, false); } } } //now add the users List<DataMenuItem> items = new ArrayList<DataMenuItem>(); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); List l = null; if (group != null) l = sorter.sort(group.getLeaders()); Iterator i; ExperimenterData exp; DataMenuItem item, allUser; JPanel list; boolean view = true; if (group != null) { int level = group.getPermissions().getPermissionsLevel(); if (level == GroupData.PERMISSIONS_PRIVATE) { view = model.isAdministrator() || model.isGroupOwner(group); } } list = new JPanel(); list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS)); allUser = new DataMenuItem(DataMenuItem.ALL_USERS_TEXT, true); items.add(allUser); if (view) list.add(allUser); p.add(UIUtilities.buildComponentPanel(list)); int count = 0; int total = 0; if (CollectionUtils.isNotEmpty(l)) { total += l.size(); i = l.iterator(); list = new JPanel(); list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS)); while (i.hasNext()) { exp = (ExperimenterData) i.next(); if (view || exp.getId() == loggedUserID) { item = new DataMenuItem(exp, true); item.setSelected(users.contains(exp.getId())); if (item.isSelected()) count++; item.addPropertyChangeListener(groupItem); items.add(item); list.add(item); } } if (list.getComponentCount() > 0) { p.add(formatHeader("Group owners")); p.add(UIUtilities.buildComponentPanel(list)); } } if (group != null) l = sorter.sort(group.getMembersOnly()); if (CollectionUtils.isNotEmpty(l)) { total += l.size(); i = l.iterator(); list = new JPanel(); list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS)); while (i.hasNext()) { exp = (ExperimenterData) i.next(); if (view || exp.getId() == loggedUserID) { item = new DataMenuItem(exp, true); item.setSelected(users.contains(exp.getId())); if (item.isSelected()) count++; item.addPropertyChangeListener(groupItem); items.add(item); list.add(item); } } if (list.getComponentCount() > 0) { p.add(formatHeader("Members")); p.add(UIUtilities.buildComponentPanel(list)); } } allUser.setSelected(total != 0 && total == count); allUser.addPropertyChangeListener(groupItem); JScrollPane pane = new JScrollPane(p); Dimension d = p.getPreferredSize(); int max = 500; if (d.height > max) { Insets insets = pane.getInsets(); pane.setPreferredSize(new Dimension(d.width + insets.left + insets.right + 20, max)); } groupItem.add(pane); groupItem.setUsersItem(items); groupItem.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); if (GroupItem.USER_SELECTION_PROPERTY.equals(name)) handleSelection(); else if (GroupItem.ALL_GROUPS_SELECTION_PROPERTY.equals(name)) handleAllGroupsSelection(true); else if (GroupItem.ALL_GROUPS_DESELECTION_PROPERTY.equals(name)) handleAllGroupsSelection(false); else if (GroupItem.ALL_USERS_SELECTION_PROPERTY.equals(name)) handleAllUsersSelection((Boolean) evt.getNewValue()); } }); return groupItem.isMenuSelected(); }
From source file:org.optaplanner.mes.common.swingui.SolverAndPersistenceFrame.java
private JComponent createScoreFieldPanel() { scoreFieldPanel = new JPanel(); scoreTextArea = new JTextArea(); scoreFieldPanel.add(scoreTextArea);// w w w. j ava 2 s .com scoreFieldPanel.setLayout(new BoxLayout(scoreFieldPanel, BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(scoreFieldPanel); scrollPane.getVerticalScrollBar().setUnitIncrement(25); scrollPane.setMinimumSize(new Dimension(100, 80)); // Size fits into screen resolution 1024*768 scrollPane.setPreferredSize(new Dimension(180, 200)); scoreFieldTitlePanel = new JPanel(new BorderLayout()); scoreFieldTitlePanel.add(scrollPane, BorderLayout.CENTER); scoreFieldTitlePanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(2, 2, 2, 2), BorderFactory.createTitledBorder("Score"))); return scoreFieldTitlePanel; }
From source file:org.pgptool.gui.ui.tools.UiUtils.java
private static JScrollPane getScrollableMessage(String msg) { JTextArea textArea = new JTextArea(msg); textArea.setLineWrap(true);//ww w . j a v a2 s . com textArea.setWrapStyleWord(true); textArea.setEditable(false); textArea.setMargin(new Insets(5, 5, 5, 5)); textArea.setFont(new JTextField().getFont()); // dirty fix to use better font JScrollPane scrollPane = new JScrollPane(); scrollPane.setPreferredSize(new Dimension(700, 150)); scrollPane.getViewport().setView(textArea); return scrollPane; }
From source file:org.photovault.swingui.BrowserWindow.java
protected void createUI(PhotoCollection collection) { window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); tabPane = new JTabbedPane(); queryPane = new QueryPane(); PhotoFolderTreeController treeCtrl = new PhotoFolderTreeController(window, this); viewCtrl = new PhotoViewController(window, this); treePane = treeCtrl.folderTree;//from w w w . j a v a 2s. com viewPane = viewCtrl.getThumbPane(); previewPane = viewCtrl.getPreviewPane(); tabPane.addTab("Query", queryPane); tabPane.addTab("Folders", treePane); VolumeTreeController volTreeCtrl = new VolumeTreeController(this); JTree volumeTree = volTreeCtrl.getView(); JScrollPane voltreeScrollPane = new JScrollPane(volumeTree); voltreeScrollPane.setPreferredSize(new Dimension(200, 500)); tabPane.add("Volumes", voltreeScrollPane); // TODO: get rid of this!!!! EditSelectionColorsAction colorAction = (EditSelectionColorsAction) viewPane.getEditSelectionColorsAction(); colorAction.setPreviewCtrl(previewPane); // Set listeners to both query and folder tree panes /* If an actionEvent comes from query pane, swich to query results. */ queryPane.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { viewCtrl.setCollection(queryPane.getResultCollection()); } }); /* If the selected folder is changed in treePane, switch to that immediately */ treeCtrl.registerEventListener(PhotoFolderTreeEvent.class, new DefaultEventListener<PhotoCollection>() { public void handleEvent(DefaultEvent<PhotoCollection> event) { PhotoCollection c = event.getPayload(); if (c != null) { viewCtrl.setCollection(c); if (c instanceof PhotoFolder) { PhotoFolder f = (PhotoFolder) c; if (f.getExternalDir() != null) { ExternalDir ed = f.getExternalDir(); folderIndexer.updateDir(ed.getVolume(), ed.getPath()); viewCtrl.setIndexingOngoing(true); } } } } }); volTreeCtrl.registerEventListener(PhotoFolderTreeEvent.class, new DefaultEventListener<PhotoCollection>() { public void handleEvent(DefaultEvent<PhotoCollection> event) { PhotoCollection c = event.getPayload(); if (c != null) { viewCtrl.setCollection(c); if (c instanceof ExtDirPhotos) { ExtDirPhotos photos = (ExtDirPhotos) c; ExternalVolume vol = (ExternalVolume) viewCtrl.getDAOFactory().getVolumeDAO() .getVolume(photos.getVolId()); folderIndexer.updateDir(vol, photos.getDirPath()); viewCtrl.setIndexingOngoing(true); } } } }); collectionPane = viewCtrl.getCollectionPane(); JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tabPane, collectionPane); split.putClientProperty(JSplitPane.ONE_TOUCH_EXPANDABLE_PROPERTY, new Boolean(true)); Container cp = window.getContentPane(); cp.setLayout(new BorderLayout()); cp.add(split, BorderLayout.CENTER); statusBar = new StatusBar(); cp.add(statusBar, BorderLayout.SOUTH); // Create actions for BrowserWindow UI ImageIcon indexDirIcon = getIcon("index_dir.png"); DefaultAction indexDirAction = new DefaultAction("Index directory...", indexDirIcon) { public void actionPerformed(ActionEvent e) { indexDir(); } }; indexDirAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_D); indexDirAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Index all images in a directory"); this.registerAction("new_ext_vol", indexDirAction); ImageIcon importIcon = getIcon("import.png"); importAction = new AbstractAction("Import image...", importIcon) { public void actionPerformed(ActionEvent e) { importFile(); } }; importAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_O); importAction.putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); importAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Import new image into database"); ImageIcon updateIcon = getIcon("update_indexed_dirs.png"); UpdateIndexAction updateIndexAction = new UpdateIndexAction(viewCtrl, "Update indexed dirs", updateIcon, "Check for changes in previously indexed directories", KeyEvent.VK_U); this.registerAction("update_indexed_dirs", updateIndexAction); updateIndexAction.addStatusChangeListener(statusBar); ImageIcon previewTopIcon = getIcon("view_preview_top.png"); DefaultAction previewTopAction = new DefaultAction("Preview on top", previewTopIcon) { public void actionPerformed(ActionEvent e) { viewCtrl.setLayout(PhotoViewController.Layout.PREVIEW_HORIZONTAL_THUMBS); } }; previewTopAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show preview on top of thumbnails"); previewTopAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_T); this.registerAction("view_preview_top", previewTopAction); ImageIcon previewRightIcon = getIcon("view_preview_right.png"); DefaultAction previewRightAction = new DefaultAction("Preview on right", previewRightIcon) { public void actionPerformed(ActionEvent e) { viewCtrl.setLayout(PhotoViewController.Layout.PREVIEW_VERTICAL_THUMBS); } }; previewRightAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show preview on right of thumbnails"); previewRightAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_R); this.registerAction("view_preview_right", previewRightAction); ImageIcon previewNoneIcon = getIcon("view_no_preview.png"); DefaultAction previewNoneAction = new DefaultAction("No preview", previewNoneIcon) { public void actionPerformed(ActionEvent e) { viewCtrl.setLayout(PhotoViewController.Layout.ONLY_THUMBS); } }; previewNoneAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show no preview image"); previewNoneAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_O); this.registerAction("view_no_preview", previewNoneAction); DefaultAction previewLargeAction = new DefaultAction("Large", null) { public void actionPerformed(ActionEvent e) { viewCtrl.setPreviewSize(200); } }; DefaultAction previewSmallAction = new DefaultAction("Small", null) { public void actionPerformed(ActionEvent e) { viewCtrl.setPreviewSize(100); } }; JToolBar tb = createToolbar(); cp.add(tb, BorderLayout.NORTH); // Create the menu bar & menus JMenuBar menuBar = new JMenuBar(); window.setJMenuBar(menuBar); // File menu JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu); JMenuItem newWindowItem = new JMenuItem("New window", KeyEvent.VK_N); newWindowItem.setIcon(getIcon("window_new.png")); newWindowItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { BrowserWindow br = new BrowserWindow(getParentController(), null); // br.setVisible( true ); } }); fileMenu.add(newWindowItem); JMenuItem importItem = new JMenuItem(importAction); fileMenu.add(importItem); JMenuItem indexDirItem = new JMenuItem(indexDirAction); fileMenu.add(indexDirItem); fileMenu.add(new JMenuItem(viewCtrl.getActionAdapter("update_indexed_dirs"))); ExportSelectedAction exportAction = (ExportSelectedAction) viewPane.getExportSelectedAction(); JMenuItem exportItem = new JMenuItem(exportAction); exportAction.addStatusChangeListener(statusBar); fileMenu.add(exportItem); JMenu dbMenu = new JMenu("Database"); dbMenu.setMnemonic(KeyEvent.VK_B); dbMenu.setIcon(getIcon("empty_icon.png")); ExportMetadataAction exportMetadata = new ExportMetadataAction("Export as XML...", null, "Export whole database as XML file", KeyEvent.VK_E); dbMenu.add(new JMenuItem(exportMetadata)); ImportXMLAction importMetadata = new ImportXMLAction("Import XML data...", null, "Import data from other Photovault database as XML", KeyEvent.VK_I); importMetadata.addStatusChangeListener(statusBar); dbMenu.add(new JMenuItem(importMetadata)); fileMenu.add(dbMenu); JMenuItem exitItem = new JMenuItem("Exit", KeyEvent.VK_X); exitItem.setIcon(getIcon("exit.png")); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.add(exitItem); JMenu viewMenu = new JMenu("View"); viewMenu.setMnemonic(KeyEvent.VK_V); menuBar.add(viewMenu); JMenuItem vertIconsItem = new JMenuItem(previewRightAction); viewMenu.add(vertIconsItem); JMenuItem horzIconsItem = new JMenuItem(previewTopAction); viewMenu.add(horzIconsItem); JMenuItem noPreviewItem = new JMenuItem(previewNoneAction); viewMenu.add(noPreviewItem); JMenuItem nextPhotoItem = new JMenuItem(viewPane.getSelectNextAction()); viewMenu.add(nextPhotoItem); JMenuItem prevPhotoItem = new JMenuItem(viewPane.getSelectPreviousAction()); viewMenu.add(prevPhotoItem); viewMenu.add(new JMenuItem(previewSmallAction)); viewMenu.add(new JMenuItem(previewLargeAction)); JMenu sortMenu = new JMenu("Sort by"); sortMenu.setMnemonic(KeyEvent.VK_S); sortMenu.setIcon(getIcon("empty_icon.png")); JMenuItem byDateItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new ShootingDateComparator(), "Date", null, "Order photos by date", KeyEvent.VK_D)); sortMenu.add(byDateItem); JMenuItem byPlaceItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new ShootingPlaceComparator(), "Place", null, "Order photos by shooting place", KeyEvent.VK_P)); sortMenu.add(byPlaceItem); JMenuItem byQualityItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new QualityComparator(), "Quality", null, "Order photos by quality", KeyEvent.VK_Q)); sortMenu.add(byQualityItem); viewMenu.add(sortMenu); // Set default ordering by date byDateItem.getAction().actionPerformed(new ActionEvent(this, 0, "Setting default")); JMenu imageMenu = new JMenu("Image"); imageMenu.setMnemonic(KeyEvent.VK_I); menuBar.add(imageMenu); imageMenu.add(new JMenuItem(viewPane.getEditSelectionPropsAction())); imageMenu.add(new JMenuItem(viewPane.getShowSelectedPhotoAction())); imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_cw"))); imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_ccw"))); imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_180"))); imageMenu.add(new JMenuItem(previewPane.getCropAction())); imageMenu.add(new JMenuItem(viewPane.getEditSelectionColorsAction())); imageMenu.add(new JMenuItem(viewPane.getDeleteSelectedAction())); // Create the Quality submenu JMenu qualityMenu = new JMenu("Quality"); qualityMenu.setIcon(getIcon("empty_icon.png")); for (int n = 0; n < 6; n++) { Action qualityAction = viewCtrl.getActionAdapter("quality_" + n); JMenuItem qualityMenuItem = new JMenuItem(qualityAction); qualityMenu.add(qualityMenuItem); } imageMenu.add(qualityMenu); JMenu aboutMenu = new JMenu("About"); aboutMenu.setMnemonic(KeyEvent.VK_A); aboutMenu.add(new JMenuItem(new ShowAboutDlgAction("About Photovault...", null, "", null))); menuBar.add(Box.createHorizontalGlue()); menuBar.add(aboutMenu); window.pack(); window.setVisible(true); }