📄 gpdocument.java
字号:
/* Sets the attributes of the selected cells. */
public void setFontStyleForSelection(int style) {
Object[] cells =
DefaultGraphModel
.getDescendants(graph.getModel(), graph.getSelectionCells())
.toArray();
//Filter ports out
java.util.List list = new ArrayList();
for (int i = 0; i < cells.length; i++)
if (!graph.isPort(cells[i]))
list.add(cells[i]);
cells = list.toArray();
Map nested = new Hashtable();
for (int i = 0; i < cells.length; i++) {
CellView view = graph.getGraphLayoutCache().getMapping(cells[i], false);
if (view != null) {
Font font = GraphConstants.getFont(view.getAllAttributes());
Map attr = GraphConstants.createMap();
GraphConstants.setFont(attr, font.deriveFont(style));
nested.put(cells[i], attr);
}
}
graph.getGraphLayoutCache().edit(nested, null, null, null);
}
/* Sets the attributes of the selected cells. */
public void setFontNameForSelection(String name) {
Object[] cells =
DefaultGraphModel
.getDescendants(graph.getModel(), graph.getSelectionCells())
.toArray();
//Filter ports out
java.util.List list = new ArrayList();
for (int i = 0; i < cells.length; i++)
if (!graph.isPort(cells[i]))
list.add(cells[i]);
cells = list.toArray();
Map nested = new Hashtable();
for (int i = 0; i < cells.length; i++) {
CellView view = graph.getGraphLayoutCache().getMapping(cells[i], false);
if (view != null) {
Font font = GraphConstants.getFont(view.getAllAttributes());
Map attr = GraphConstants.createMap();
GraphConstants.setFont(attr, new Font(name, font.getStyle(), font.getSize()));
nested.put(cells[i], attr);
}
}
graph.getGraphLayoutCache().edit(nested, null, null, null);
}
//-----------------------------------------------------------------
// Component Listener
//-----------------------------------------------------------------
public void setResizeAction(AbstractAction e) {
fitAction = e;
}
public void componentHidden(ComponentEvent e) {
}
public void componentMoved(ComponentEvent e) {
}
public void componentResized(ComponentEvent e) {
if (fitAction != null)
fitAction.actionPerformed(null);
}
public void componentShown(ComponentEvent e) {
componentResized(e);
}
public void setScale(double scale) {
scale = Math.max(Math.min(scale, 16), .01);
graph.setScale(scale);
componentResized(null);
}
//----------------------------------------------------------------------
// Printable
//----------------------------------------------------------------------
/** not from Printable interface, but related
*/
public void updatePageFormat() {
PageFormat f = graph.getPageFormat();
columnRule.setActiveOffset((int) (f.getImageableX()));
rowRule.setActiveOffset((int) (f.getImageableY()));
columnRule.setActiveLength((int) (f.getImageableWidth()));
rowRule.setActiveLength((int) (f.getImageableHeight()));
if (graph.isPageVisible()) {
int w = (int) (f.getWidth());
int h = (int) (f.getHeight());
graph.setMinimumSize(new Dimension(w + 5, h + 5));
} else
graph.setMinimumSize(null);
invalidate();
// Execute fitAction...
componentResized(null);
graph.repaint();
}
public int print(Graphics g, PageFormat pF, int page) {
int pw = (int) pF.getImageableWidth();
int ph = (int) pF.getImageableHeight();
int cols = (int) (graph.getWidth() / pw) + 1;
int rows = (int) (graph.getHeight() / ph) + 1;
int pageCount = cols * rows;
if (page >= pageCount)
return NO_SUCH_PAGE;
int col = page % cols;
int row = page % rows;
g.translate(-col*pw, -row*ph);
g.setClip(col*pw, row*ph, pw, ph);
graph.paint(g);
g.translate(col*pw, row*ph);
return PAGE_EXISTS;
}
//
// Listeners
//
// PropertyChangeListener
public void propertyChange(PropertyChangeEvent evt) {
if (graphpad != null)
update();
}
// GraphSelectionListener
public void valueChanged(GraphSelectionEvent e) {
if (!graph.isSelectionEmpty())
touch.setDamper(0);
update();
}
// View Observer
public void update(Observable obs, Object arg) {
modified = true;
touch.resetDamper();
update();
}
// GraphModelListener
public void graphChanged(GraphModelEvent e) {
modified = true;
touch.resetDamper();
update();
//System.out.println("Change:\n"+buttonEdge.getChange().getStoredAttributeMap());
}
protected void update() {
updateFrameTitle();
graphpad.update();
graphpad.getStatusBar().setMessage(this.getDocumentStatus());
graphpad.getStatusBar().setScale(this.getDocumentScale());
}
/**
* Returns the graphUndoManager.
* @return GraphUndoManager
*/
public GraphUndoManager getGraphUndoManager() {
return graphUndoManager;
}
/**
* Sets the graphUndoManager.
* @param graphUndoManager The graphUndoManager to set
*/
public void setGraphUndoManager(GraphUndoManager graphUndoManager) {
this.graphUndoManager = graphUndoManager;
}
/** Resets the Graph undo manager
*/
public void resetGraphUndoManager() {
graphUndoManager.discardAllEdits();
}
/**
* Returns the graphpad.
* @return GPGraphpad
*/
public GPGraphpad getGraphpad() {
return graphpad;
}
/**
* Sets the graphpad.
* @param graphpad The graphpad to set
*/
public void setGraphpad(GPGraphpad graphpad) {
this.graphpad = graphpad;
}
/**
* Returns the touch.
* @return Touch
*/
public Touch getTouch() {
return touch;
}
/**
* Sets the touch.
* @param touch The touch to set
*/
public void setTouch(Touch touch) {
this.touch = touch;
}
/**
* Returns true if the user really wants to close.
* Gives chance to save work.
*/
public boolean close(boolean showConfirmDialog) {
// set default to save on close
int r = JOptionPane.YES_OPTION;
if (modified){
if (showConfirmDialog)
r = JOptionPane.showConfirmDialog(
graphpad.getFrame(),
Translator.getString("SaveChangesDialog"),
Translator.getString("Title"),
JOptionPane.YES_NO_CANCEL_OPTION);
// if yes, then save and close
if (r == JOptionPane.YES_OPTION) {
graphpad
.getCurrentActionMap()
.get(Utilities.getClassNameWithoutPackage(FileSave.class))
.actionPerformed(null);
return true;
}
// if no, then don't save and just close
else if (r == JOptionPane.NO_OPTION) {
return true;
}
// all other conditions (cancel and dialog's 'X' button)
// don't save and don't close
else
return false;
}
else
// if not modified just close
return true;
}
public GPLibraryPanel getLibraryPanel() {
return null; // change#1 libraryPanel;
}
/** This will change the source of the actionevent to graph.
* */
protected class EventRedirector implements ActionListener {
protected Action action;
public EventRedirector(Action a) {
this.action = a;
}
public void actionPerformed(ActionEvent e) {
JComponent source = graph;
// if (libraryPanel.hasFocus())
// source = libraryPanel;
e =
new ActionEvent(
source,
e.getID(),
e.getActionCommand(),
e.getModifiers());
action.actionPerformed(e);
}
}
/**
* Returns the findPattern.
* @return String
*/
public String getFindPattern() {
return findPattern;
}
/**
* Sets the findPattern.
* @param findPattern The findPattern to set
*/
public void setFindPattern(String findPattern) {
this.findPattern = findPattern;
}
/**
* Returns the lastFound.
* @return Object
*/
public Object getLastFound() {
return lastFound;
}
/**
* Sets the lastFound.
* @param lastFound The lastFound to set
*/
public void setLastFound(Object lastFound) {
this.lastFound = lastFound;
}
/**
* Returns the overviewDialog.
* @return JDialog
*/
public JDialog getOverviewDialog() {
return overviewDialog;
}
/**
* Sets the overviewDialog.
* @param overviewDialog The overviewDialog to set
*/
public void setOverviewDialog(JDialog overviewDialog) {
this.overviewDialog = overviewDialog;
}
/**
* Returns the splitPane.
* @return JSplitPane
*/
public GPSplitPane getSplitPane() {
return splitPane;
}
/**
* Sets the splitPane.
* @param splitPane The splitPane to set
*/
public void setSplitPane(GPSplitPane splitPane) {
this.splitPane = splitPane;
}
/**
* Returns the scrollPane.
* @return JScrollPane
*/
public JScrollPane getScrollPane() {
return scrollPane;
}
/**
* Sets the scrollPane.
* @param scrollPane The scrollPane to set
*/
public void setScrollPane(JScrollPane scrollPane) {
this.scrollPane = scrollPane;
}
/**
* Returns the columnRule.
* @return Rule
*/
public Rule getColumnRule() {
return columnRule;
}
/**
* Returns the rowRule.
* @return Rule
*/
public Rule getRowRule() {
return rowRule;
}
/**
* Sets the columnRule.
* @param columnRule The columnRule to set
*/
public void setColumnRule(Rule columnRule) {
this.columnRule = columnRule;
}
/**
* Sets the rowRule.
* @param rowRule The rowRule to set
*/
public void setRowRule(Rule rowRule) {
this.rowRule = rowRule;
}
/**
* Returns the enableTooltips.
* @return boolean
*/
public boolean isEnableTooltips() {
return enableTooltips;
}
/**
* Sets the enableTooltips.
* @param enableTooltips The enableTooltips to set
*/
public void setEnableTooltips(boolean enableTooltips) {
this.enableTooltips = enableTooltips;
if (this.enableTooltips)
ToolTipManager.sharedInstance().registerComponent(graph);
else
ToolTipManager.sharedInstance().unregisterComponent(graph);
}
/**
* Returns the internalFrame.
* @return GPInternalFrame
*/
public GPInternalFrame getInternalFrame() {
return internalFrame;
}
/**
* Sets the internalFrame.
* @param internalFrame The internalFrame to set
*/
protected void setInternalFrame(GPInternalFrame internalFrame) {
this.internalFrame = internalFrame;
}
protected void updateFrameTitle() {
if (this.internalFrame != null) {
this.internalFrame.setTitle(getFrameTitle());
}
}
public String getFrameTitle() {
return (
this.file == null
? Translator.getString("NewGraph")
: file.toString())
+ (modified ? "*" : "");
}
/**
* Returns the graphModelProvider.
* @return GraphModelProvider
*/
public GraphModelProvider getGraphModelProvider() {
return graphModelProvider;
}
/**
* Returns the networkModel.
* @return GraphNetworkModel
*/
public GraphNetworkModel getNetworkModel() {
return networkModel;
}
/**
* Sets the networkModel.
* @param networkModel The networkModel to set
*/
public void setNetworkModel(GraphNetworkModel networkModel) {
this.networkModel = networkModel;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -