/** * Opens a project. * * @param directory Where the project is stored. * @return the BProject that describes the newly opened project or null if it cannot be opened. */ public final BProject openProject(File directory) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); // Yes somebody may just call it with null, for fun.. if (directory == null) return null; Project openProj = Project.openProject(directory.getAbsolutePath(), null); if (openProj == null) return null; // a hack, since bluej does not handle "opening" of projects correctly. // this code should really be into openProject or it should not be possible to open // a project is the initial package name is not there. Package pkg = openProj.getCachedPackage(openProj.getInitialPackageName()); if (pkg == null) return null; // I make a new identifier out of this Identifier aProject = new Identifier(openProj, pkg); // This will make the frame if not already there. should not be needed... try { aProject.getPackageFrame(); } catch (ExtensionException exc) { } // Note: the previous Identifier is not used here. return openProj.getBProject(); }
private void jMenuItemViewDocumentsActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemViewDocumentsActionPerformed if (this.docFrameTableModel == null) { this.docFrameTableModel = new DocumentFrameTableModel(theProject.getDocumentCollection()); } DocumentFrame d = new DocumentFrame(this.docFrameTableModel, theDesktop, theProject.getDocumentCollection()); d.setVisible(true); theDesktop.add(d); } // GEN-LAST:event_jMenuItemViewDocumentsActionPerformed
private void jMenuItemPerformLSAActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemPerformLSAActionPerformed Thread t = new LSAThread( theProject.getDocumentCollection(), theProject.getDocumentClassCollection(), thePrefs.get("lsa-regex"), this); t.start(); } // GEN-LAST:event_jMenuItemPerformLSAActionPerformed
/** * Opens the project denoted by the given file. * * @param aFile the project file to open, cannot be <code>null</code>. * @throws IOException in case of I/O problems. */ public void openProjectFile(final File aFile) throws IOException { FileInputStream fis = new FileInputStream(aFile); this.projectManager.loadProject(fis); final Project project = this.projectManager.getCurrentProject(); project.setFilename(aFile); zoomToFit(); }
/** * Saves an OLS data file to the given file. * * @param aFile the file to save the OLS data to, cannot be <code>null</code>. * @throws IOException in case of I/O problems. */ public void saveDataFile(final File aFile) throws IOException { final FileWriter writer = new FileWriter(aFile); try { final Project tempProject = this.projectManager.createTemporaryProject(); tempProject.setCapturedData(this.dataContainer); OlsDataHelper.write(tempProject, writer); } finally { writer.flush(); writer.close(); } }
/** * Saves the current project to the given file. * * @param aFile the file to save the project information to, cannot be <code>null</code>. * @throws IOException in case of I/O problems. */ public void saveProjectFile(final String aName, final File aFile) throws IOException { FileOutputStream out = null; try { final Project project = this.projectManager.getCurrentProject(); project.setFilename(aFile); project.setName(aName); out = new FileOutputStream(aFile); this.projectManager.saveProject(out); } finally { HostUtils.closeResource(out); } }
/** * Returns all currently open projects. Returns an empty array if no projects are open. * * @return The openProjects value */ public BProject[] getOpenProjects() { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); Collection projects = Project.getProjects(); BProject[] result = new BProject[projects.size()]; Iterator iter; int index; for (iter = projects.iterator(), index = 0; iter.hasNext(); index++) { Project prj = (Project) iter.next(); result[index] = prj.getBProject(); } return result; }
private void jMenuItemImportActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemImportActionPerformed JFileChooser jfc = new JFileChooser(); jfc.setMultiSelectionEnabled(true); if (lastPath != null) { jfc.setCurrentDirectory(lastPath); } int fileDialogReturnVal = jfc.showOpenDialog(this); // now select the file if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) { // add code here to allow selection of a document class DocumentClassDialog d = DocumentClassDialog.showClassDialog(this, this.theProject); DocumentClass selectedClass = d.getSelectedDocumentClass(); File[] selected = jfc.getSelectedFiles(); for (int i = 0; i < selected.length; i++) { theProject.addNewDocument(selected[i], 1.0f, selected[i].toString(), selectedClass); } docFrameTableModel.fireTableDataChanged(); lastPath = new File(jfc.getSelectedFile().getPath()); } } // GEN-LAST:event_jMenuItemImportActionPerformed
/** * Draws the entity on the map editor. * * @param g graphic context * @param zoom zoom of the image (for example, 1: unchanged, 2: zoom of 200%) * @param showTransparency true to make transparent pixels, false to replace them by a background * color */ public void paint(Graphics g, double zoom, boolean showTransparency) { if (resizableImage == null) { resizableImage = Project.getEditorImageOrEmpty("entity_sensor_resizable.png"); } Rectangle positionInMap = getPositionInMap(); int x = (int) (positionInMap.x * zoom); int y = (int) (positionInMap.y * zoom); int w = (int) (positionInMap.width * zoom); int h = (int) (positionInMap.height * zoom); g.setColor(new Color(200, 224, 96)); g.fillRect(x, y, w, h); int dx1 = (int) ((positionInMap.x + positionInMap.width / 2 - 8) * zoom); int dy1 = (int) ((positionInMap.y + positionInMap.height / 2 - 8) * zoom); int dx2 = (int) (dx1 + 16 * zoom); int dy2 = (int) (dy1 + 16 * zoom); int sx1 = 0; int sx2 = sx1 + 32; g.drawImage(resizableImage, dx1, dy1, dx2, dy2, sx1, 0, sx2, 32, null); drawEntityOutline(g, zoom, new Color(184, 200, 96)); }
public static void main(String[] args) throws ProjectFileParsingException, EquationException { Project testProj = Project.loadProject( new File("examples/Ex5-Networks/Ex5-Networks.neuro.xml"), new ProjectEventListener() { public void tableDataModelUpdated(String tableModelName) {}; public void tabUpdated(String tabName) {}; public void cellMechanismUpdated() {}; }); SynapticProperties sp = new SynapticProperties("Syn1"); sp.setDelayGenerator(new NumberGenerator(33)); WeightGenerator wg = new WeightGenerator("r*r", true); sp.setWeightsGenerator(wg); SynapticPropertiesDialog dlg = new SynapticPropertiesDialog(new Frame(), sp, testProj); // Dimension dlgSize = dlg.getPreferredSize(); dlg.setModal(true); dlg.pack(); dlg.setVisible(true); System.out.println("wg: " + sp.getWeightsGenerator()); }
/** * Loads an OLS data file from the given file. * * @param aFile the file to load as OLS data, cannot be <code>null</code>. * @throws IOException in case of I/O problems. */ public void openDataFile(final File aFile) throws IOException { final FileReader reader = new FileReader(aFile); try { final Project tempProject = this.projectManager.createTemporaryProject(); OlsDataHelper.read(tempProject, reader); setChannelLabels(tempProject.getChannelLabels()); setCapturedData(tempProject.getCapturedData()); setCursorData(tempProject.getCursorPositions(), tempProject.isCursorsEnabled()); } finally { reader.close(); zoomToFit(); updateActions(); } }
/** * Creates a new BlueJ project. * * @param directory where you want the project be placed, it must be writable. * @param projectType the type of project, such as ME or SE. * @return the newly created BProject if successful, null otherwise. */ public BProject newProject(File directory, int projectType) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); String pathString = directory.getAbsolutePath(); if (!pathString.endsWith(File.separator)) pathString += File.separator; if (!Project.createNewProject(pathString, projectType == ME_PROJECT)) return null; return openProject(directory); }
/** * Constructor. * * @param title the title of the tab component * @param editor the editor of the tab (used to close the tab) */ public TabComponent(final AbstractEditorPanel editor) { setLayout(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); setOpaque(false); // title title = new JLabel(editor.getTitle()); title.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); add(title, BorderLayout.WEST); // close final JButton close = new JButton(Project.getEditorImageIconOrEmpty("icon_cross.png")); close.setPreferredSize(new Dimension(16, 16)); close.setUI(new BasicButtonUI()); close.setBorderPainted(false); close.setOpaque(false); close.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { removeEditor(editor, true); } }); close.addMouseListener( new MouseListener() { @Override public void mouseClicked(MouseEvent me) {} @Override public void mousePressed(MouseEvent me) {} @Override public void mouseReleased(MouseEvent me) {} @Override public void mouseEntered(MouseEvent me) { close.setBorderPainted(true); } @Override public void mouseExited(MouseEvent me) { close.setBorderPainted(false); } }); add(close, BorderLayout.EAST); }
private void jMenuItemLoadProjectActionPerformed( java.awt.event.ActionEvent evt) // GEN-FIRST:event_jMenuItemLoadProjectActionPerformed { // GEN-HEADEREND:event_jMenuItemLoadProjectActionPerformed JFileChooser jfc = new JFileChooser(); if (lastPath != null) { jfc.setCurrentDirectory(lastPath); } int fileDialogReturnVal = jfc.showOpenDialog(this); if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) { try { File inputFile = jfc.getSelectedFile(); FileInputStream fis = new FileInputStream(inputFile); ObjectInputStream ois = new ObjectInputStream(fis); this.theProject = (Project) ois.readObject(); this.currentResults = (LSAResults) ois.readObject(); lastPath = new File(jfc.getSelectedFile().getPath()); } catch (IOException e) { if (this.theProject == null) { log.log(Log.ERROR, "Failed to load project"); } if (this.currentResults == null) { log.log(Log.WARNING, "Failed to load results"); } log.log(Log.WARNING, e.getMessage()); } catch (ClassNotFoundException e) { log.log(Log.ERROR, "Class not found error, version mismatch"); } } if (this.theProject != null) { jMenuItemViewDocuments.setEnabled(true); jMenuItemSaveProject.setEnabled(true); this.setTitle(theProject.getProjectName()); log.log(Log.INFO, "Project Loaded"); } if (this.currentResults != null) { log.log(Log.INFO, "Results loaded"); } } // GEN-LAST:event_jMenuItemLoadProjectActionPerformed
/** * Returns the id of any tileset editor that edits the specified tileset. * * @param tilesetId Id of a tileset. * @return Id of an editor that edits this tileset. */ public static String getEditorId(String tilesetId) { return Project.getTilesetFile(tilesetId).getAbsolutePath(); }
/** Display a frame for browsing issues. */ private JPanel constructView() { // sort the original issues list final SortedList<Issue> issuesSortedList = new SortedList<Issue>(issuesEventList, null); // filter the sorted issues FilterList<Issue> filteredIssues = new FilterList<Issue>(issuesSortedList, filterPanel.getMatcherEditor()); SeparatorList<Issue> separatedIssues = new SeparatorList<Issue>( filteredIssues, GlazedLists.beanPropertyComparator(Issue.class, "subcomponent"), 0, Integer.MAX_VALUE); EventList<Issue> separatedIssuesProxyList = GlazedListsSwing.swingThreadProxyList(separatedIssues); // build the issues table issuesTableModel = GlazedListsSwing.eventTableModel(separatedIssuesProxyList, new IssueTableFormat()); final TableColumnModel issuesTableColumnModel = new EventTableColumnModel<TableColumn>(new BasicEventList<TableColumn>()); JSeparatorTable issuesJTable = new JSeparatorTable(issuesTableModel, issuesTableColumnModel); issuesJTable.setAutoCreateColumnsFromModel(true); issuesJTable.setSeparatorRenderer(new IssueSeparatorTableCell(separatedIssues)); issuesJTable.setSeparatorEditor(new IssueSeparatorTableCell(separatedIssues)); issuesSelectionModel = GlazedListsSwing.eventSelectionModel(separatedIssuesProxyList); issuesSelectionModel.setSelectionMode( ListSelection .MULTIPLE_INTERVAL_SELECTION_DEFENSIVE); // multi-selection best demos our awesome // selection management issuesSelectionModel.addListSelectionListener(new IssuesSelectionListener()); issuesJTable.setSelectionModel(issuesSelectionModel); issuesJTable.getColumnModel().getColumn(0).setPreferredWidth(150); issuesJTable.getColumnModel().getColumn(1).setPreferredWidth(400); issuesJTable.getColumnModel().getColumn(2).setPreferredWidth(300); issuesJTable.getColumnModel().getColumn(3).setPreferredWidth(300); issuesJTable.getColumnModel().getColumn(4).setPreferredWidth(250); issuesJTable.getColumnModel().getColumn(5).setPreferredWidth(300); issuesJTable.getColumnModel().getColumn(6).setPreferredWidth(300); issuesJTable.getColumnModel().getColumn(7).setPreferredWidth(1000); // turn off cell focus painting issuesJTable.setDefaultRenderer( String.class, new NoFocusRenderer(issuesJTable.getDefaultRenderer(String.class))); issuesJTable.setDefaultRenderer( Integer.class, new NoFocusRenderer(issuesJTable.getDefaultRenderer(Integer.class))); issuesJTable.setDefaultRenderer( Priority.class, new NoFocusRenderer(new PriorityTableCellRenderer())); LookAndFeelTweaks.tweakTable(issuesJTable); TableComparatorChooser.install( issuesJTable, issuesSortedList, TableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); JScrollPane issuesTableScrollPane = new JScrollPane( issuesJTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); issuesTableScrollPane.getViewport().setBackground(UIManager.getColor("EditorPane.background")); issuesTableScrollPane.setBorder(BorderFactory.createEmptyBorder()); issueDetails = new IssueDetailsComponent(filteredIssues); // projects EventList<Project> projects = Project.getProjects(); TransformedList<Project, Project> projectsProxyList = GlazedListsSwing.swingThreadProxyList(projects); // project select combobox DefaultEventComboBoxModel projectsComboModel = new DefaultEventComboBoxModel<Project>(projectsProxyList); JComboBox projectsCombo = new JComboBox(projectsComboModel); projectsCombo.setEditable(false); projectsCombo.setOpaque(false); projectsCombo.addItemListener(new ProjectChangeListener()); projectsComboModel.setSelectedItem(new Project(null, "Select a Java.net project...")); // build a label to display the number of issues in the issue table issueCounter = new IssueCounterLabel(filteredIssues); issueCounter.setHorizontalAlignment(SwingConstants.CENTER); issueCounter.setForeground(Color.WHITE); // throbber throbber = new JLabel(THROBBER_STATIC); throbber.setHorizontalAlignment(SwingConstants.RIGHT); // header bar JPanel iconBar = new GradientPanel(GLAZED_LISTS_MEDIUM_BROWN, GLAZED_LISTS_DARK_BROWN, true); iconBar.setLayout(new GridLayout(1, 3)); iconBar.add(projectsCombo); iconBar.add(issueCounter); iconBar.add(throbber); iconBar.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); // assemble all data components on a common panel JPanel dataPanel = new JPanel(); JComponent issueDetailsComponent = issueDetails; dataPanel.setLayout(new GridLayout(2, 1)); dataPanel.add(issuesTableScrollPane); dataPanel.add(issueDetailsComponent); // draw lines between components JComponent filtersPanel = filterPanel.getComponent(); filtersPanel.setBorder(BorderFactory.createEmptyBorder()); // filtersPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, // IssuesBrowser.GLAZED_LISTS_DARK_BROWN)); issueDetailsComponent.setBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, GLAZED_LISTS_DARK_BROWN)); // the outermost panel to layout the icon bar with the other panels final JPanel mainPanel = new JPanel(new GridBagLayout()); mainPanel.add( iconBar, new GridBagConstraints( 0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); mainPanel.add( filtersPanel, new GridBagConstraints( 0, 1, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); mainPanel.add( Box.createHorizontalStrut(240), new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); mainPanel.add( dataPanel, new GridBagConstraints( 1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); return mainPanel; }
public void itemStateChanged(ItemEvent e) { if (e.getStateChange() != ItemEvent.SELECTED) return; final Project selectedProject = (Project) e.getItem(); if (selectedProject.isValid()) issueLoader.setProject(selectedProject); }