/** If there's anything to print, initiate a print job */ public synchronized void actionPerformed(ActionEvent ae) { if (isPrintUnderway) { out("ignoring [" + ae.getActionCommand() + "]; print already underway."); return; } LWMap map = VUE.getActiveMap(); Rectangle2D bounds = map.getBounds(); if (bounds.isEmpty()) { out("nothing to print in " + map); return; } boolean viewerPrint = false; if (ae.getActionCommand() != null && ae.getActionCommand().indexOf("Visible") >= 0) viewerPrint = true; // if any tool windows open in W2K/1.4.2 when start this thread, // the print dialog get's obscured! isPrintUnderway = true; setEnabled(false); try { new PrintJob(VUE.getActiveViewer(), viewerPrint).start(); // if (DEBUG.Enabled) // new PrintJob(VUE.getActiveViewer(), viewerPrint).start(); // else // new PrintJob(VUE.getActiveViewer(), viewerPrint).runPrint(); } catch (Throwable t) { out("exception creating or running PrintJob: " + t); t.printStackTrace(); isPrintUnderway = false; setEnabled(true); } }
public void activeChanged(tufts.vue.ActiveEvent<tufts.vue.LWMap> e) { this.lWMap = e.active; if (lWMap != null) { lWMap.getMapFilterModel().addListener(this); elementsModel.setElements(lWMap.getMapFilterModel().getKeyVector()); } }
/** Creates a new instance of NodeFilterEditor */ public NodeFilterEditor(NodeFilter nodeFilter, boolean editable) { this.nodeFilter = nodeFilter; tufts.vue.LWMap map = tufts.vue.VUE.getActiveMap(); if (map != null) map.getMapFilterModel().addListener(this); tufts.vue.VUE.addActiveListener(tufts.vue.LWMap.class, this); questionLabel.setToolTipText(NodeFilterEditor.NODE_FILTER_INFO); setNodeFilterPanel(); }
private PrintJob(MapViewer viewer, boolean viewerPrint) { super("PrintJob#" + JobCount++); this.map = viewer.getMap(); this.focal = viewerPrint ? viewer.getFocal() : map; this.jobName = map.getDisplayLabel(); this.isPrintingView = viewerPrint; // be sure to grab bounds info now -- sometimes it's possible // that the viewer bounds go negative once the model print dialog // boxes go active and VUE is hung without being able to reshape // or repaint itself. (That's not a problem when we run this // in a thread, but there's a java bug with that right now, tho // it's safer to do it this way anyway). if (isPrintingView()) { if (focal == map) this.bounds = viewer.getVisibleMapBounds(); else this.bounds = focal.getBorderBounds(); } else this.bounds = map.getBounds(); out(viewerPrint ? "printing: viewer contents" : "printing: whole map"); out("requested map bounds: " + bounds); }
public int print(Graphics gc, PageFormat format, int pageIndex) throws java.awt.print.PrinterException { if (pageIndex > 0) { out("page " + pageIndex + " requested, ending print job."); return Printable.NO_SUCH_PAGE; } Dimension page = new Dimension( (int) format.getImageableWidth() - 1, (int) format.getImageableHeight() - 1); Graphics2D g = (Graphics2D) gc; out( "asked to render page " + pageIndex + " in " + outpf(format) + " w/transform " + g.getTransform()); // note: supposedly, perhaps on Windows with JVM's 1.5 and newer, the // transform scale provided can actually allow us to derive the DPI of the // print device, which we could use for image rendering optimization's // during prints. Mac OS X Snow Leopard w/JVM 1.6 always reports a 1.0 // scale though. And operations like "print preview" or "print to PDF" // wouldn't have a fixed DPI anyway. if (DEBUG.CONTAINMENT) { g.setColor(Color.lightGray); g.fillRect(0, 0, 9999, 9999); } g.translate(format.getImageableX(), format.getImageableY()); // Don't need to clip if printing whole map, as computed zoom // should have made sure everything is within page size // if (!isPrintingView()) // g.clipRect(0, 0, page.width, page.height); if (DEBUG.CONTAINMENT) { // g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); // draw border outline of page g.setColor(Color.gray); g.setStroke(VueConstants.STROKE_TWO); g.drawRect(0, 0, page.width, page.height); // g.setComposite(AlphaComposite.Src); } // compute zoom & offset for visible map components Point2D.Float offset = new Point2D.Float(); // center vertically only if landscape mode // if (format.getOrientation() == PageFormat.LANDSCAPE) // TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit) double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true); out("rendering at scale " + scale); // set up the DrawContext DrawContext dc = new DrawContext( g, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle focal, false); // todo: absolute links shouldn't be spec'd here dc.setMapDrawing(); dc.setPrintQuality(); if (isPrintingView() && map == focal) g.clipRect( (int) Math.floor(bounds.getX()), (int) Math.floor(bounds.getY()), (int) Math.ceil(bounds.getWidth()), (int) Math.ceil(bounds.getHeight())); if (DEBUG.CONTAINMENT) { g.setColor(Color.red); g.setStroke(VueConstants.STROKE_TWO); g.draw(bounds); } // render the map if (map == focal) map.draw(dc); else focal.draw(dc); out("page " + pageIndex + " rendered."); return Printable.PAGE_EXISTS; }
private void setNodeFilterPanel() { lWMap = tufts.vue.VUE.getActiveMap(); addButton.setToolTipText(VueResources.getString("nodefilter.addfilter.tooltip")); deleteButton.setToolTipText(VueResources.getString("nodefilter.deletefilter.tooltip")); elementsModel = new ElementComboBoxModel(); elementsModel.setElements(lWMap.getMapFilterModel().getKeyVector()); elements = new JComboBox(elementsModel); Font f = elements.getFont(); Font menuFont = new Font(f.getFontName(), f.getStyle(), f.getSize() - 2); elements.setFont(menuFont); // elements.setPreferredSize(new Dimension(150,20)); /// this is not user friendly may want to fix later. /** * elements.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { * if(e.getStateChange() == ItemEvent.SELECTED) { if(e.getItem().toString() == ADD_ELEMENT) { } * else if(e.getItem() instanceof Key) { Statement stmt = new Statement(); * stmt.setKey((Key)e.getItem()); nodeFilter.addStatement(stmt); * nodeFilter.fireTableDataChanged(); } else { System.out.println("Not Supported"); } } } }); */ nodeFilterTable = new JTable(nodeFilter); nodeFilterTable.addFocusListener( new FocusListener() { public void focusLost(FocusEvent e) { if (nodeFilterTable.isEditing()) { nodeFilterTable .getCellEditor( nodeFilterTable.getEditingRow(), nodeFilterTable.getEditingColumn()) .stopCellEditing(); } nodeFilterTable.removeEditor(); } public void focusGained(FocusEvent e) {} }); nodeFilterTable.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (nodeFilterTable.getSelectedRow() == (nodeFilterTable.getRowCount() - 1) && e.getKeyCode() == e.VK_ENTER) { addButtonListener.addStatement(); } } }); nodeFilterTable.setPreferredScrollableViewportSize(new Dimension(240, 100)); JScrollPane nodeFilterScrollPane = new JScrollPane(nodeFilterTable); nodeFilterScrollPane.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); JPanel nodeFilterPanel = new JPanel(); nodeFilterPanel.setLayout(new BorderLayout()); nodeFilterPanel.add(nodeFilterScrollPane, BorderLayout.CENTER); addButtonListener = new AddButtonListener(nodeFilter); addButton.addActionListener(addButtonListener); deleteButton.setEnabled(false); sListener = new NodeFilterSelectionListener(deleteButton, -1); nodeFilterTable.getSelectionModel().addListSelectionListener(sListener); deleteButtonListener = new DeleteButtonListener(nodeFilterTable, sListener); deleteButton.addActionListener(deleteButtonListener); // keyEditor = new KeyCellEditor(); // nodeFilterTable.getColumnModel().getColumn(NodeFilter.KEY_COL).setCellEditor(keyEditor); JPanel innerPanel = new JPanel(); innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.Y_AXIS)); JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 0)); // bottomPanel.setBorder(BorderFactory.createEmptyBorder(3,6,3,6)); bottomPanel.add(elementLabel); bottomPanel.add(elements); bottomPanel.add(addButton); bottomPanel.add(deleteButton); bottomPanel.add(questionLabel); // innerPanel.add(labelPanel); innerPanel.add(bottomPanel); innerPanel.add(nodeFilterPanel); setLayout(new BorderLayout()); add(innerPanel, BorderLayout.CENTER); validate(); }