List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction(String name)
From source file:org.interreg.docexplore.DocExploreTool.java
@SuppressWarnings("serial") protected static File askForHome(String text) { final File[] file = { null }; final JDialog dialog = new JDialog((Frame) null, XMLResourceBundle.getBundledString("homeLabel"), true); JPanel content = new JPanel(new LooseGridLayout(0, 1, 10, 10, true, false, SwingConstants.CENTER, SwingConstants.TOP, true, false)); content.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); JLabel message = new JLabel(text, ImageUtils.getIcon("free-64x64.png"), SwingConstants.LEFT); message.setIconTextGap(20);/*www .j a v a 2s . c o m*/ //message.setFont(Font.decode(Font.SANS_SERIF)); content.add(message); final JPanel pathPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10)); pathPanel.add(new JLabel("<html><b>" + XMLResourceBundle.getBundledString("homeLabel") + ":</b></html>")); final JTextField pathField = new JTextField(System.getProperty("user.home") + File.separator + "DocExplore", 40); pathPanel.add(pathField); pathPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("browseLabel")) { JNativeFileDialog nfd = null; public void actionPerformed(ActionEvent arg0) { if (nfd == null) { nfd = new JNativeFileDialog(); nfd.acceptFiles = false; nfd.acceptFolders = true; nfd.multipleSelection = false; nfd.title = XMLResourceBundle.getBundledString("homeLabel"); } nfd.setCurrentFile(new File(pathField.getText())); if (nfd.showOpenDialog()) pathField.setText(nfd.getSelectedFile().getAbsolutePath()); } })); content.add(pathPanel); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10)); buttonPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgOkLabel")) { public void actionPerformed(ActionEvent e) { File res = new File(pathField.getText()); if (res.exists() && !res.isDirectory() || !res.exists() && !res.mkdirs()) JOptionPane.showMessageDialog(dialog, XMLResourceBundle.getBundledString("homeErrorMessage"), XMLResourceBundle.getBundledString("errorLabel"), JOptionPane.ERROR_MESSAGE); else { file[0] = res; dialog.setVisible(false); } } })); buttonPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgCancelLabel")) { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } })); content.add(buttonPanel); dialog.getContentPane().add(content); dialog.pack(); dialog.setResizable(false); GuiUtils.centerOnScreen(dialog); dialog.setVisible(true); return file[0]; }
From source file:org.interreg.docexplore.ServerConfigPanel.java
public ServerConfigPanel(final File config, final File serverDir) throws Exception { super(new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); this.serverDir = serverDir; this.books = new Vector<Book>(); this.bookList = new JList(new DefaultListModel()); JPanel listPanel = new JPanel(new BorderLayout()); listPanel.setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBooksLabel"))); bookList.setOpaque(false);/*from w ww .j av a 2 s. c o m*/ bookList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); bookList.setCellRenderer(new ListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Book book = (Book) value; JLabel label = new JLabel("<html><b>" + book.name + "</b> - " + book.nPages + " pages</html>"); label.setOpaque(true); if (isSelected) { label.setBackground(TextToolbar.styleHighLightedBackground); label.setForeground(Color.white); } if (book.deleted) label.setForeground(Color.red); else if (!book.used) label.setForeground(Color.gray); return label; } }); bookList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; setFields((Book) bookList.getSelectedValue()); } }); JScrollPane scrollPane = new JScrollPane(bookList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setPreferredSize(new Dimension(500, 300)); scrollPane.getVerticalScrollBar().setUnitIncrement(10); listPanel.add(scrollPane, BorderLayout.CENTER); JPanel importPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); importPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgImportLabel")) { public void actionPerformed(ActionEvent e) { final File inFile = DocExploreTool.getFileDialogs().openFile(DocExploreTool.getIBookCategory()); if (inFile == null) return; try { final File tmpDir = new File(serverDir, "tmp"); tmpDir.mkdir(); GuiUtils.blockUntilComplete(new ProgressRunnable() { float[] progress = { 0 }; public void run() { try { ZipUtils.unzip(inFile, tmpDir, progress); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } public float getProgress() { return (float) progress[0]; } }, ServerConfigPanel.this); File tmpFile = new File(tmpDir, "index.tmp"); ObjectInputStream input = new ObjectInputStream(new FileInputStream(tmpFile)); String bookFile = input.readUTF(); String bookName = input.readUTF(); String bookDesc = input.readUTF(); input.close(); new PresentationImporter().doImport(ServerConfigPanel.this, bookName, bookDesc, new File(tmpDir, bookFile)); FileUtils.cleanDirectory(tmpDir); FileUtils.deleteDirectory(tmpDir); updateBooks(); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } })); listPanel.add(importPanel, BorderLayout.SOUTH); add(listPanel); JPanel setupPanel = new JPanel( new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); setupPanel.setBorder( BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBookInfoLabel"))); usedBox = new JCheckBox(XMLResourceBundle.getBundledString("cfgUseLabel")); usedBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book != null) { book.used = usedBox.isSelected(); bookList.repaint(); } } }); setupPanel.add(usedBox); JPanel fieldPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTitleLabel"))); nameField = new JTextField(50); nameField.getDocument().addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { changedUpdate(e); } public void insertUpdate(DocumentEvent e) { changedUpdate(e); } public void changedUpdate(DocumentEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book == null) return; book.name = nameField.getText(); bookList.repaint(); } }); fieldPanel.add(nameField); fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgDescriptionLabel"))); descField = new JTextPane(); //descField.setWrapStyleWord(true); descField.getDocument().addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { changedUpdate(e); } public void insertUpdate(DocumentEvent e) { changedUpdate(e); } public void changedUpdate(DocumentEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book == null) return; book.desc = descField.getText(); } }); scrollPane = new JScrollPane(descField, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setPreferredSize(new Dimension(420, 50)); scrollPane.getVerticalScrollBar().setUnitIncrement(10); fieldPanel.add(scrollPane); setupPanel.add(fieldPanel); exportButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgExportLabel")) { public void actionPerformed(ActionEvent e) { File file = DocExploreTool.getFileDialogs().saveFile(DocExploreTool.getIBookCategory()); if (file == null) return; final Book book = (Book) bookList.getSelectedValue(); final File indexFile = new File(serverDir, "index.tmp"); try { final File outFile = file; ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(indexFile)); out.writeUTF(book.bookFile.getName()); out.writeUTF(book.name); out.writeUTF(book.desc); out.close(); GuiUtils.blockUntilComplete(new ProgressRunnable() { float[] progress = { 0 }; public void run() { try { ZipUtils.zip(serverDir, new File[] { indexFile, book.bookFile, book.bookDir }, outFile, progress, 0, 1, 9); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } public float getProgress() { return (float) progress[0]; } }, ServerConfigPanel.this); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } if (indexFile.exists()) indexFile.delete(); } }); deleteButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgDeleteRestoreLabel")) { public void actionPerformed(ActionEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book == null) return; book.deleted = !book.deleted; bookList.repaint(); } }); JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); actionsPanel.add(exportButton); actionsPanel.add(deleteButton); setupPanel.add(actionsPanel); add(setupPanel); JPanel optionsPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); optionsPanel .setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgOptionsLabel"))); JPanel timeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); timeoutField = new JTextField(5); timeoutPanel.add(timeoutField); timeoutPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTimeoutLabel"))); optionsPanel.add(timeoutPanel); add(optionsPanel); updateBooks(); setFields(null); final String xml = config.exists() ? StringUtils.readFile(config) : "<config></config>"; String idle = StringUtils.getTagContent(xml, "idle"); if (idle != null) try { timeoutField.setText("" + Integer.parseInt(idle)); } catch (Throwable e) { } }
From source file:org.openconcerto.erp.model.FamilleArticleTree.java
public void mousePressed(MouseEvent e) { Object o = this.getSelectionPath().getLastPathComponent(); int id = 1;//from w w w . j a va2 s .c o m if (e.getButton() == MouseEvent.BUTTON3) { if (o instanceof FamilleTreeNode) { final FamilleTreeNode nodeSelect = (FamilleTreeNode) o; id = nodeSelect.getId(); } final int idSelect = id; // Ajouter, supprimer, modifier une famille JPopupMenu menu = new JPopupMenu(); menu.add(new AbstractAction("Ajouter une famille") { public void actionPerformed(ActionEvent e) { EditFrame frameAddFamille = new EditFrame(familleElt, EditFrame.CREATION); SQLRowValues rowVals = new SQLRowValues(familleElt.getTable()); rowVals.put("ID_FAMILLE_ARTICLE_PERE", idSelect); frameAddFamille.getSQLComponent().select(rowVals); frameAddFamille.setVisible(true); } }); if (idSelect > 1) { menu.add(new AbstractAction("Modifier") { public void actionPerformed(ActionEvent e) { EditFrame frameModFamille = new EditFrame(familleElt, EditFrame.MODIFICATION); frameModFamille.selectionId(idSelect, 1); frameModFamille.setVisible(true); } }); menu.add(new AbstractAction("Supprimer") { public void actionPerformed(ActionEvent e) { try { familleElt.archive(idSelect); } catch (SQLException e1) { e1.printStackTrace(); } } }); } menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y); } }
From source file:org.geopublishing.atlasStyler.swing.AtlasStylerGUI.java
/** * Creates a nre {@link JMenuBar} instance *//*from w w w. j a v a 2s . c o m*/ private JMenuBar createMenuBar() { JMenuBar jMenuBar = new JMenuBar(); JMenu fileMenu = new JMenu(AsSwingUtil.R("MenuBar.FileMenu")); jMenuBar.add(fileMenu); { // Import WIzard JMenuItem mi = new JMenuItem(new AbstractAction(AsSwingUtil.R("MenuBar.FileMenu.ImportWizard")) { @Override public void actionPerformed(ActionEvent e) { ImportWizard.showWizard(AtlasStylerGUI.this, AtlasStylerGUI.this); } }); mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.CTRL_MASK, true)); fileMenu.add(mi); } fileMenu.add(SwingUtil.createChangeLog4JLevelJMenu()); /** * MenuItem to create a new language */ JMenuItem manageLanguageJMenuitem = new JMenuItem( new AbstractAction(ASUtil.R("TranslateSoftwareDialog.Title"), Icons.ICON_FLAGS_SMALL) { @Override public void actionPerformed(ActionEvent e) { String resPath = IOUtil .escapePath(System.getProperty("user.home") + File.separator + ".Geopublishing"); ResourceProviderManagerFrame manLanguagesFrame = new ResourceProviderManagerFrame( AtlasStylerGUI.this, true, AsSwingUtil.R("TranslateSoftwareDialog.Explanation.Html", resPath, SystemUtils.IS_OS_WINDOWS ? "bat" : "sh")); manLanguagesFrame.setRootPath(new File(resPath)); manLanguagesFrame.setTitle(ASUtil.R("TranslateSoftwareDialog.Title")); manLanguagesFrame.setPreferredSize(new Dimension(780, 450)); manLanguagesFrame.setVisible(true); } }); fileMenu.add(manageLanguageJMenuitem); AbstractAction optionsButton = new AbstractAction(AtlasStylerVector.R("Options.ButtonLabel")) { @Override public void actionPerformed(ActionEvent e) { new ASOptionsDialog(AtlasStylerGUI.this, AtlasStylerGUI.this); } }; fileMenu.add(optionsButton); { // Exit JMenuItem mi = new JMenuItem(new AbstractAction( GpCoreUtil.R("AtlasViewer.FileMenu.ExitMenuItem.exit_application"), Icons.ICON_EXIT_SMALL) { @Override public void actionPerformed(ActionEvent e) { exitAS(0); } }); fileMenu.add(mi); } return jMenuBar; }
From source file:edu.mit.fss.examples.visual.gui.WorldWindVisualization.java
/** * Instantiates a new world wind visualization. * * @throws OrekitException the orekit exception *///w w w. j ava 2 s. c o m public WorldWindVisualization() throws OrekitException { logger.trace("Creating Orekit reference frames."); eme = ReferenceFrame.EME2000.getOrekitFrame(); itrf = ReferenceFrame.ITRF2008.getOrekitFrame(); // world wind frame is a fixed rotation from Earth inertial frame wwj = new Frame(itrf, new Transform(date, new Rotation(RotationOrder.ZXZ, 0, -Math.PI / 2, -Math.PI / 2)), "World Wind"); logger.trace("Creating World Window GL canvas and adding to panel."); wwd = new WorldWindowGLCanvas(); wwd.setModel(new BasicModel()); wwd.setPreferredSize(new Dimension(800, 600)); setLayout(new BorderLayout()); add(wwd, BorderLayout.CENTER); logger.trace("Creating and adding a renderable layer."); displayLayer = new RenderableLayer(); wwd.getModel().getLayers().add(displayLayer); logger.trace("Creating and adding a marker layer."); markerLayer = new MarkerLayer(); // allow markers above/below surface markerLayer.setOverrideMarkerElevation(false); wwd.getModel().getLayers().add(markerLayer); logger.trace("Creating and adding a sun renderable."); Vector3D position = sun.getPVCoordinates(date, wwj).getPosition(); sunShape = new Ellipsoid(wwd.getModel().getGlobe().computePositionFromPoint(convert(position)), 696000000., 696000000., 696000000.); ShapeAttributes sunAttributes = new BasicShapeAttributes(); sunAttributes.setInteriorMaterial(Material.YELLOW); sunAttributes.setInteriorOpacity(1.0); sunShape.setAttributes(sunAttributes); displayLayer.addRenderable(sunShape); logger.trace("Creating and adding a terminator."); LatLon antiSun = LatLon.fromRadians(-sunShape.getCenterPosition().getLatitude().radians, FastMath.PI + sunShape.getCenterPosition().getLongitude().radians); // set radius to a quarter Earth chord at the anti-sun position less // a small amount (100 m) to avoid graphics problems terminatorShape = new SurfaceCircle(antiSun, wwd.getModel().getGlobe().getRadiusAt(antiSun) * FastMath.PI / 2 - 100); ShapeAttributes nightAttributes = new BasicShapeAttributes(); nightAttributes.setInteriorMaterial(Material.BLACK); nightAttributes.setInteriorOpacity(0.5); terminatorShape.setAttributes(nightAttributes); displayLayer.addRenderable(terminatorShape); logger.trace("Creating and adding a panel for buttons."); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); buttonPanel.add(new JCheckBox(new AbstractAction("Inertial Frame") { private static final long serialVersionUID = 2287109397693524964L; @Override public void actionPerformed(ActionEvent e) { setInertialFrame(((JCheckBox) e.getSource()).isSelected()); } })); buttonPanel.add(new JButton(editOptionsAction)); add(buttonPanel, BorderLayout.SOUTH); logger.trace( "Creating a timer to rotate the sun renderable, " + "terminator surface circle, and stars layer."); Timer rotationTimer = new Timer(15, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { wwd.redraw(); try { BasicOrbitView wwdView; if (wwd.getView() instanceof BasicOrbitView) { wwdView = (BasicOrbitView) wwd.getView(); } else { return; } // rotate camera to simulate inertial frame if (wwd.getView().isAnimating() || !inertialFrame.get()) { // update eme datum rotationDatum = wwj.getTransformTo(eme, date) .transformPosition(convert(wwdView.getCenterPoint())); } else if (inertialFrame.get()) { Position newCenter = wwd.getModel().getGlobe().computePositionFromPoint( convert(eme.getTransformTo(wwj, date).transformPosition(rotationDatum))); // move to eme datum wwdView.setCenterPosition(newCenter); } // rotate stars layer for (Layer layer : wwd.getModel().getLayers()) { if (layer instanceof StarsLayer) { StarsLayer stars = (StarsLayer) layer; // find the EME coordinates of (0,0) Vector3D emeDatum = wwj.getTransformTo(eme, date).transformPosition(convert( wwd.getModel().getGlobe().computePointFromLocation(LatLon.fromDegrees(0, 0)))); // find the WWJ coordinates the equivalent point in ITRF Vector3D wwjDatum = itrf.getTransformTo(wwj, date).transformPosition(emeDatum); // set the longitude offset to the opposite of // the difference in longitude (i.e. from 0) stars.setLongitudeOffset(wwd.getModel().getGlobe() .computePositionFromPoint(convert(wwjDatum)).getLongitude().multiply(-1)); } } } catch (OrekitException ex) { logger.error(ex); } } }); // set initial 2-second delay for initialization rotationTimer.setInitialDelay(2000); rotationTimer.start(); }
From source file:com.diversityarrays.kdxplore.trials.SampleGroupViewer.java
private void showPopupMenu(Component c, Point pt, List<Integer> rowIndices) { selectedModelRows = rowIndices;// www . j av a 2 s . c o m if (popupMenu == null) { popupMenu = new JPopupMenu(); popupMenu.add(new AbstractAction("View") { @Override public void actionPerformed(ActionEvent e) { tiChoiceTableModel.changeChosen(selectedModelRows, true); } }); popupMenu.add(new AbstractAction("Hide") { @Override public void actionPerformed(ActionEvent e) { tiChoiceTableModel.changeChosen(selectedModelRows, false); } }); } popupMenu.show(c, pt.x, pt.y); }
From source file:com.github.benchdoos.weblocopener.weblocOpener.gui.EditDialog.java
private void initTextField(String pathToEditingFile) { textField.addMouseListener(new ClickListener() { @Override/*w w w. j a v a 2 s.c o m*/ public void doubleClick(MouseEvent e) { textField.selectAll(); } }); textField.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { } @Override public void insertUpdate(DocumentEvent e) { updateTextFont(); } @Override public void removeUpdate(DocumentEvent e) { updateTextFont(); } private void updateTextFont() { UrlValidator urlValidator = new UrlValidator(); if (urlValidator.isValid(textField.getText())) { if (textField != null) { setTextFieldFont(textField.getFont(), TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); textField.setForeground(Color.BLUE); } } else { if (textField != null) { setTextFieldFont(textField.getFont(), TextAttribute.UNDERLINE, -1); textField.setForeground(Color.BLACK); } } } }); UndoManager undoManager = new UndoManager(); textField.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { undoManager.addEdit(evt.getEdit()); } }); textField.getActionMap().put("Undo", new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { try { if (undoManager.canUndo()) { undoManager.undo(); } } catch (CannotUndoException e) { } } }); textField.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); textField.getActionMap().put("Redo", new AbstractAction("Redo") { public void actionPerformed(ActionEvent evt) { try { if (undoManager.canRedo()) { undoManager.redo(); } } catch (CannotRedoException e) { } } }); textField.getInputMap().put(KeyStroke.getKeyStroke("control shift Z"), "Redo"); fillTextField(pathToEditingFile); }
From source file:be.nbb.demetra.dfm.output.simulation.RealTimePerspGraphView.java
private JMenu buildMenu() { JMenu menu = new JMenu(); JMenuItem back = new JMenuItem(new AbstractAction("Show complete data...") { @Override/* ww w . j a v a 2s . c o m*/ public void actionPerformed(ActionEvent e) { showMain(); indexSelected = -1; } }); menu.add(back); JMenuItem item = new JMenuItem(new CopyDetailAction()); item.setText("Copy current data"); menu.add(item); return menu; }
From source file:gate.corpora.CSVImporter.java
@Override protected List<Action> buildActions(final NameBearerHandle handle) { List<Action> actions = new ArrayList<Action>(); if (!(handle.getTarget() instanceof Corpus)) return actions; actions.add(new AbstractAction("Populate from CSV File") { @Override//from w ww .j ava 2s . c o m public void actionPerformed(ActionEvent e) { // display the populater dialog and return if it is cancelled if (JOptionPane.showConfirmDialog(null, dialog, "Populate From CSV File", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) != JOptionPane.OK_OPTION) return; // we want to run the population in a separate thread so we don't lock // up the GUI Thread thread = new Thread(Thread.currentThread().getThreadGroup(), "CSV Corpus Populater") { public void run() { try { // unescape the strings that define the format of the file and // get the actual chars char separator = StringEscapeUtils.unescapeJava(txtSeparator.getText()).charAt(0); char quote = StringEscapeUtils.unescapeJava(txtQuoteChar.getText()).charAt(0); // see if we can convert the URL to a File instance File file = null; try { file = Files.fileFromURL(new URL(txtURL.getText())); } catch (IllegalArgumentException iae) { // this will happen if someone enters an actual URL, but we // handle that later so we can just ignore the exception for // now and keep going } if (file != null && file.isDirectory()) { // if we have a File instance and that points at a directory // then.... // get all the CSV files in the directory structure File[] files = Files.listFilesRecursively(file, CSV_FILE_FILTER); for (File f : files) { // for each file... // skip directories as we don't want to handle those if (f.isDirectory()) continue; if (cboDocuments.isSelected()) { // if we are creating lots of documents from a single // file // then call the populate method passing through all the // options from the GUI populate((Corpus) handle.getTarget(), f.toURI().toURL(), txtEncoding.getText(), (Integer) textColModel.getValue(), cboFeatures.isSelected(), separator, quote); } else { // if we are creating a single document from a single // file // then call the createDoc method passing through all // the // options from the GUI createDoc((Corpus) handle.getTarget(), f.toURI().toURL(), txtEncoding.getText(), (Integer) textColModel.getValue(), cboFeatures.isSelected(), separator, quote); } } } else { // we have a single URL to process so... if (cboDocuments.isSelected()) { // if we are creating lots of documents from a single file // then call the populate method passing through all the // options from the GUI populate((Corpus) handle.getTarget(), new URL(txtURL.getText()), txtEncoding.getText(), (Integer) textColModel.getValue(), cboFeatures.isSelected(), separator, quote); } else { // if we are creating a single document from a single file // then call the createDoc method passing through all the // options from the GUI createDoc((Corpus) handle.getTarget(), new URL(txtURL.getText()), txtEncoding.getText(), (Integer) textColModel.getValue(), cboFeatures.isSelected(), separator, quote); } } } catch (Exception e) { // TODO give a sensible error message e.printStackTrace(); } } }; // let's leave the GUI nice and responsive thread.setPriority(Thread.MIN_PRIORITY); // lets get to it and do some actual work! thread.start(); } }); return actions; }
From source file:com.diversityarrays.dal.server.ServerGui.java
public ServerGui(Image serverIconImage, IDalServer svr, DalServerFactory factory, File wwwRoot, DalServerPreferences prefs) {// w w w . ja va 2s . c o m this.serverIconImage = serverIconImage; this.dalServerFactory = factory; this.wwwRoot = wwwRoot; this.preferences = prefs; JMenuBar menuBar = new JMenuBar(); JMenu serverMenu = new JMenu("Server"); menuBar.add(serverMenu); serverMenu.add(serverStartAction); serverMenu.add(serverStopAction); serverMenu.add(exitAction); JMenu commandMenu = new JMenu("Command"); menuBar.add(commandMenu); commandMenu.add(doSql); JMenu urlMenu = new JMenu("URL"); menuBar.add(urlMenu); urlMenu.add(new JMenuItem(copyDalUrlAction)); urlMenu.add(new JMenuItem(showDalUrlQRcodeAction)); setJMenuBar(menuBar); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); messages.setFont(GuiUtil.createMonospacedFont(12)); messages.setEditable(false); setServer(svr); quietOption.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean q = quietOption.isSelected(); if (server != null) { server.setQuiet(q); } } }); JScrollPane scrollPane = new JScrollPane(messages, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar(); JButton clear = new JButton(new AbstractAction("Clear") { @Override public void actionPerformed(ActionEvent e) { messages.setText(""); } }); final boolean[] follow = new boolean[] { true }; final JCheckBox followTail = new JCheckBox("Follow", follow[0]); followTail.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { follow[0] = followTail.isSelected(); } }); final OutputStream os = new OutputStream() { @Override public void write(int b) throws IOException { char ch = (char) b; messages.append(new Character(ch).toString()); if (ch == '\n' && follow[0]) { verticalScrollBar.setValue(verticalScrollBar.getMaximum()); } } }; TeePrintStream pso = new TeePrintStream(System.out, os); TeePrintStream pse = new TeePrintStream(System.err, os); System.setErr(pse); System.setOut(pso); Box box = Box.createHorizontalBox(); box.add(clear); box.add(followTail); box.add(quietOption); box.add(Box.createHorizontalGlue()); JPanel bottom = new JPanel(new BorderLayout()); bottom.add(BorderLayout.NORTH, box); bottom.add(BorderLayout.SOUTH, statusInfoLine); Container cp = getContentPane(); cp.add(BorderLayout.CENTER, scrollPane); cp.add(BorderLayout.SOUTH, bottom); pack(); setSize(640, 480); final MemoryUsageMonitor mum = new MemoryUsageMonitor(); mum.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { statusInfoLine.setMessage(mum.getMemoryUsage()); } }); if (server == null) { // If initial server is null, allow user to specify addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { removeWindowListener(this); serverStartAction.actionPerformed(null); } }); } else { addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { removeWindowListener(this); ensureDatabaseInitialisedThenStartServer(); } }); } }