⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editoractions.java

📁 经典的java图像处理程序源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					catch (Exception ex)					{						ex.printStackTrace();					}					editorPane.requestFocus();					editorPane.select(start, ende);				}				else				{					mxIGraphModel model = graphComponent.getGraph().getModel();					model.beginUpdate();					try					{						graphComponent.stopEditing(false);						graphComponent.getGraph().toggleCellStyleFlags(								mxConstants.STYLE_FONTSTYLE,								(bold) ? mxConstants.FONT_BOLD										: mxConstants.FONT_ITALIC);					}					finally					{						model.endUpdate();					}				}			}		}	}	/**	 *	 */	public static class WarningAction extends AbstractAction	{		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			if (e.getSource() instanceof mxGraphComponent)			{				mxGraphComponent graphComponent = (mxGraphComponent) e						.getSource();				Object[] cells = graphComponent.getGraph().getSelectionCells();				if (cells != null && cells.length > 0)				{					String warning = JOptionPane.showInputDialog(mxResources							.get("enterWarningMessage"));					for (int i = 0; i < cells.length; i++)					{						graphComponent.setCellWarning(cells[i], warning);					}				}				else				{					JOptionPane.showMessageDialog(graphComponent, mxResources							.get("noCellSelected"));				}			}		}	}	/**	 *	 */	public static class NewAction extends AbstractAction	{		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			BasicGraphEditor editor = getEditor(e);			if (editor != null)			{				if (!editor.isModified()						|| JOptionPane.showConfirmDialog(editor, mxResources								.get("loseChanges")) == JOptionPane.YES_OPTION)				{					mxGraph graph = editor.getGraphComponent().getGraph();					// Check modified flag and display save dialog					mxCell root = new mxCell();					root.insert(new mxCell());					graph.getModel().setRoot(root);					editor.setModified(false);					editor.setCurrentFile(null);				}			}		}	}	/**	 *	 */	public static class OpenAction extends AbstractAction	{		/**		 * 		 */		protected String lastDir;		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			BasicGraphEditor editor = getEditor(e);			if (editor != null)			{				if (!editor.isModified()						|| JOptionPane.showConfirmDialog(editor, mxResources								.get("loseChanges")) == JOptionPane.YES_OPTION)				{					mxGraph graph = mxGraphActions.getGraph(e);					if (graph != null)					{						String wd = (lastDir != null) ? lastDir : System								.getProperty("user.dir");						JFileChooser fc = new JFileChooser(wd);						// Adds file filter for supported file format						FileFilter defaultFilter = new DefaultFileFilter(								".mxe", "mxGraph Editor "										+ mxResources.get("file") + " (.mxe)");						fc.addChoosableFileFilter(defaultFilter);						int rc = fc.showDialog(null, mxResources								.get("openFile"));						if (rc == JFileChooser.APPROVE_OPTION)						{							lastDir = fc.getSelectedFile().getParent();							try							{								Document document = mxUtils.parse(mxUtils										.readFile(fc.getSelectedFile()												.getAbsolutePath()));								mxCodec codec = new mxCodec(document);								codec.decode(document.getDocumentElement(),										graph.getModel());								editor.setModified(false);								editor.setCurrentFile(fc.getSelectedFile());							}							catch (IOException e1)							{								e1.printStackTrace();							}						}					}				}			}		}	}	/**	 *	 */	public static class ToggleAction extends AbstractAction	{		/**		 * 		 */		protected String key;		/**		 * 		 */		protected boolean defaultValue;		/**		 * 		 * @param key		 */		public ToggleAction(String key)		{			this(key, false);		}		/**		 * 		 * @param key		 */		public ToggleAction(String key, boolean defaultValue)		{			this.key = key;			this.defaultValue = defaultValue;		}		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			mxGraph graph = mxGraphActions.getGraph(e);			if (graph != null)			{				graph.toggleCellStyles(key, defaultValue);			}		}	}	/**	 *	 */	public static class SetLabelPositionAction extends AbstractAction	{		/**		 * 		 */		protected String labelPosition, alignment;		/**		 * 		 * @param key		 */		public SetLabelPositionAction(String labelPosition, String alignment)		{			this.labelPosition = labelPosition;			this.alignment = alignment;		}		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			mxGraph graph = mxGraphActions.getGraph(e);			if (graph != null && !graph.isSelectionEmpty())			{				graph.getModel().beginUpdate();				try				{					// Checks the orientation of the alignment to use the correct constants					if (labelPosition.equals(mxConstants.ALIGN_LEFT)							|| labelPosition.equals(mxConstants.ALIGN_CENTER)							|| labelPosition.equals(mxConstants.ALIGN_RIGHT))					{						graph.setCellStyles(mxConstants.STYLE_LABEL_POSITION,								labelPosition);						graph.setCellStyles(mxConstants.STYLE_ALIGN, alignment);					}					else					{						graph.setCellStyles(								mxConstants.STYLE_VERTICAL_LABEL_POSITION,								labelPosition);						graph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN,								alignment);					}				}				finally				{					graph.getModel().endUpdate();				}			}		}	}	/**	 *	 */	public static class SetStyleAction extends AbstractAction	{		/**		 * 		 */		protected String value;		/**		 * 		 * @param key		 */		public SetStyleAction(String value)		{			this.value = value;		}		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			mxGraph graph = mxGraphActions.getGraph(e);			if (graph != null && !graph.isSelectionEmpty())			{				graph.setCellStyle(value);			}		}	}	/**	 *	 */	public static class KeyValueAction extends AbstractAction	{		/**		 * 		 */		protected String key, value;		/**		 * 		 * @param key		 */		public KeyValueAction(String key)		{			this(key, null);		}		/**		 * 		 * @param key		 */		public KeyValueAction(String key, String value)		{			this.key = key;			this.value = value;		}		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			mxGraph graph = mxGraphActions.getGraph(e);			if (graph != null && !graph.isSelectionEmpty())			{				graph.setCellStyles(key, value);			}		}	}	/**	 *	 */	public static class PromptValueAction extends AbstractAction	{		/**		 * 		 */		protected String key, message;		/**		 * 		 * @param key		 */		public PromptValueAction(String key, String message)		{			this.key = key;			this.message = message;		}		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			if (e.getSource() instanceof Component)			{				mxGraph graph = mxGraphActions.getGraph(e);				if (graph != null && !graph.isSelectionEmpty())				{					String value = (String) JOptionPane.showInputDialog(							(Component) e.getSource(),							mxResources.get("value"), message,							JOptionPane.PLAIN_MESSAGE, null, null, "");					if (value != null)					{						if (value.equals(mxConstants.NONE))						{							value = null;						}						graph.setCellStyles(key, value);					}				}			}		}	}	/**	 *	 */	public static class AlignCellsAction extends AbstractAction	{		/**		 * 		 */		protected String align;		/**		 * 		 * @param key		 */		public AlignCellsAction(String align)		{			this.align = align;		}		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			mxGraph graph = mxGraphActions.getGraph(e);			if (graph != null && !graph.isSelectionEmpty())			{				graph.alignCells(align);			}		}	}	/**	 *	 */	public static class AutosizeAction extends AbstractAction	{		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			mxGraph graph = mxGraphActions.getGraph(e);			if (graph != null && !graph.isSelectionEmpty())			{				graph.updateCellSize(graph.getSelectionCell());			}		}	}	/**	 *	 */	public static class ColorAction extends AbstractAction	{		/**		 * 		 */		protected String name, key;		/**		 * 		 * @param key		 */		public ColorAction(String name, String key)		{			this.name = name;			this.key = key;		}		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			if (e.getSource() instanceof mxGraphComponent)			{				mxGraphComponent graphComponent = (mxGraphComponent) e						.getSource();				mxGraph graph = graphComponent.getGraph();				if (!graph.isSelectionEmpty())				{					Color newColor = JColorChooser.showDialog(graphComponent,							name, null);					if (newColor != null)					{						graph.setCellStyles(key, mxUtils.hexString(newColor));					}				}			}		}	}	/**	 *	 */	public static class BackgroundImageAction extends AbstractAction	{		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			if (e.getSource() instanceof mxGraphComponent)			{				mxGraphComponent graphComponent = (mxGraphComponent) e						.getSource();				String value = (String) JOptionPane.showInputDialog(						graphComponent, mxResources.get("backgroundImage"),						"URL", JOptionPane.PLAIN_MESSAGE, null, null,						"http://www.callatecs.com/images/background2.JPG");				if (value != null)				{					if (value.length() == 0)					{						graphComponent.setBackgroundImage(null);					}					else					{						graphComponent.setBackgroundImage(new ImageIcon(mxUtils								.loadImage(value)));					}					// Forces a repaint of the outline					graphComponent.getGraph().repaint();				}			}		}	}	/**	 *	 */	public static class BackgroundAction extends AbstractAction	{		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			if (e.getSource() instanceof mxGraphComponent)			{				mxGraphComponent graphComponent = (mxGraphComponent) e						.getSource();				Color newColor = JColorChooser.showDialog(graphComponent,						mxResources.get("background"), null);				if (newColor != null)				{					graphComponent.getViewport().setOpaque(false);					graphComponent.setBackground(newColor);				}				// Forces a repaint of the outline				graphComponent.getGraph().repaint();			}		}	}	/**	 *	 */	public static class PageBackgroundAction extends AbstractAction	{		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			if (e.getSource() instanceof mxGraphComponent)			{				mxGraphComponent graphComponent = (mxGraphComponent) e						.getSource();				Color newColor = JColorChooser.showDialog(graphComponent,						mxResources.get("pageBackground"), null);				if (newColor != null)				{					graphComponent.setPageBackgroundColor(newColor);				}				// Forces a repaint of the component				graphComponent.repaint();			}		}	}	/**	 *	 */	public static class StyleAction extends AbstractAction	{		/**		 * 		 */		public void actionPerformed(ActionEvent e)		{			if (e.getSource() instanceof mxGraphComponent)			{				mxGraphComponent graphComponent = (mxGraphComponent) e						.getSource();				mxGraph graph = graphComponent.getGraph();				String initial = graph.getModel().getStyle(						graph.getSelectionCell());				String value = (String) JOptionPane.showInputDialog(						graphComponent, mxResources.get("style"), mxResources								.get("style"), JOptionPane.PLAIN_MESSAGE, null,						null, initial);				if (value != null)				{					graph.setCellStyle(value);				}			}		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -