📄 nodeview.java
字号:
if (this.isLeft()) { v = ((RootNodeView)getParentView()).getLeft(); } else { v = ((RootNodeView)getParentView()).getRight(); } } else { v = getParentView().getChildrenViews(); } NodeView sibling; if (v.indexOf(this) <= 0) {//this is first, return last// sibling = (NodeView)v.getLast(); // loop sibling = this; } else { sibling = (NodeView)v.get(v.indexOf(this)-1); } return sibling; } // // Update from Model // void insert() { ListIterator it = getModel().childrenFolded(); while(it.hasNext()) { insert((MindMapNode)it.next()); } } /** * Create views for the newNode and all his descendants, set their * isLeft attribute according to this view. Observe that views know * about their parents only through their models. */ void insert(MindMapNode newNode) { NodeView newView = NodeView.newNodeView(newNode,getMap()); newView.setLeft(this.isLeft()); ListIterator it = newNode.childrenFolded(); while (it.hasNext()) { MindMapNode child = (MindMapNode)it.next(); newView.insert(child); } } /** * This is a bit problematic, because getChildrenViews() only works if * model is not yet removed. (So do not _really_ delete the model before the view * removed (it needs to stay in memory) */ void remove() { removeFromMap(); if (getEdge()!=null) { getEdge().remove(); } getModel().setViewer(null); // Let the model know he is invisible for(ListIterator e = getChildrenViews().listIterator();e.hasNext();) { ((NodeView)e.next()).remove(); }} void update() { //System.err.println("update"); // 1) Set color Color color = getModel().getColor(); if (color==null) { color = standardNodeColor; } setForeground(color); // 2) icons left or right? setHorizontalTextPosition((getModel().isOneLeftSideOfRoot())?SwingConstants.LEADING:SwingConstants.TRAILING); // 3) Create the icons: MultipleImage iconImages = new MultipleImage(map.getZoom()); boolean iconPresent = false; /* fc, 06.10.2003: images?*/ FreeMindMain frame = map.getController().getFrame(); Map stateIcons = (getModel()).getStateIcons(); for (Iterator i = stateIcons.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); iconPresent = true; ImageIcon myIcon = (ImageIcon) stateIcons.get(key); iconImages.addImage(myIcon); } List icons = (getModel()).getIcons(); for (Iterator i = icons.iterator(); i.hasNext();) { MindIcon myIcon = (MindIcon) i.next(); iconPresent = true; //System.out.println("print the icon " + myicon.toString()); iconImages.addImage(myIcon.getIcon(frame)); } String link = ((NodeAdapter)getModel()).getLink(); if ( link != null ) { iconPresent = true; ImageIcon icon = new ImageIcon(frame.getResource (link.startsWith("mailto:") ? "images/Mail.png" : (Tools.executableByExtension(link) ? "images/Executable.png" : "images/Link.png"))); iconImages.addImage(icon); }// /* Folded icon by Matthias Schade (mascha2), fc, 20.12.2003*/// if (((NodeAdapter)getModel()).isFolded()) {// iconPresent = true;// ImageIcon icon = new ImageIcon(((NodeAdapter)getModel()).getFrame().getResource("images/Folded.png"));// iconImages.addImage(icon); // } // DanielPolansky: set icon only if icon is present, because // we don't want to insert any additional white space. setIcon(iconPresent?iconImages:null); // 4) Determine font Font font = getModel().getFont(); font = font == null ? map.getController().getDefaultFont() : font; if (font != null) { if (map.getZoom() != 1F) { font = font.deriveFont(font.getSize()*map.getZoom()); } setFont(font); } else { // We can survive this trouble. System.err.println("NodeView.update(): default font is null."); } // 5) Set the text // Right now, this implementation is quite logical, although it allows // for nonconvex feature of nodes starting with <html>.// String nodeText = getModel().toString(); String nodeText = getModel().toString(); // Tell if node is long and its width has to be restricted // boolean isMultiline = nodeText.indexOf("\n") >= 0; String[] lines = nodeText.split("\n"); boolean widthMustBeRestricted = false; lines = nodeText.split("\n"); for (int line = 0; line < lines.length; line++) { // Compute the width the node would spontaneously take, // by preliminarily setting the text. setText(lines[line]); widthMustBeRestricted = getPreferredSize().width > map .getZoomed(map.getMaxNodeWidth()); if (widthMustBeRestricted) { break; } } isLong = widthMustBeRestricted || lines.length > 1; if (nodeText.startsWith("<html>")) { // Make it possible to use relative img references in HTML using tag <base>. if (nodeText.indexOf("<img")>=0 && nodeText.indexOf("<base ") < 0 ) { try { nodeText = "<html><base href=\""+ map.getModel().getURL()+"\">"+nodeText.substring(6); } catch (MalformedURLException e) {} } setText(nodeText); } else if (nodeText.startsWith("<table>")) { lines[0] = lines[0].substring(7); // remove <table> tag int startingLine = lines[0].matches("\\s*") ? 1 : 0; // ^ If the remaining first line is empty, do not draw it String text = "<html><table border=1 style=\"border-color: white\">"; //String[] lines = nodeText.split("\n"); for (int line = startingLine; line < lines.length; line++) { text += "<tr><td style=\"border-color: white;\">"+ Tools.toXMLEscapedText(lines[line]).replaceAll("\t","<td style=\"border-color: white\">"); } setText(text); } else if (isLong) { String text = "<tr><td>"; int maximumLineLength = 0; for (int line = 0; line < lines.length; line++) { text += Tools.toXMLEscapedTextWithNBSPizedSpaces(lines[line]) + "<p>"; if (lines[line].length() > maximumLineLength) { maximumLineLength = lines[line].length(); }} text += "</td></tr>"; setText("<html><table"+ (!widthMustBeRestricted?">":" width=\""+map.getZoomed(map.getMaxNodeWidth())+"\">")+ text+"</table></html>"); } // 6) ToolTips: updateToolTip(); // 7) Complete repaint(); // Because of zoom? } /** * Updates the tool tip of the node. */ public void updateToolTip() { Map tooltips = getModel().getToolTip(); if(tooltips.size() == 1) { setToolTipText((String) tooltips.values().iterator().next()); } else if (tooltips.size()==0) { setToolTipText(null); } else { // html table StringBuffer text = new StringBuffer("<html><table>"); Set keySet = tooltips.keySet(); TreeSet sortedKeySet = new TreeSet(); sortedKeySet.addAll(keySet); for (Iterator i = sortedKeySet.iterator(); i.hasNext();) { String key = (String) i.next(); String value = (String) tooltips.get(key); text.append("<tr><td>"); text.append(value); text.append("</td></tr>"); } text.append("</table></html>"); setToolTipText(text.toString()); } } void updateAll() { update(); for(ListIterator e = getChildrenViews().listIterator();e.hasNext();) { NodeView child = (NodeView)e.next(); child.updateAll(); } } protected void setRendering(Graphics2D g) { if (map.getController().getAntialiasAll()) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); }// else// g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } abstract String getStyle() ; /** * @return the shift of the tree root node * relative to the middle of the tree * because of the light shift of the children nodes */ public int getTreeHeight() { return treeHeight; } /** * sets the shift of the tree root node * relative to the middle of the tree * because of the light shift of the children nodes. */ public void setTreeHeight(int i) { treeHeight = i; } public int getTreeWidth() { return treeWidth; } public void setTreeWidth(int i) { treeWidth = i; } public int getZoomedFoldingSymbolHalfWidth() { int preferredFoldingSymbolHalfWidth = map.getZoomedFoldingSymbolHalfWidth(); return Math.min(preferredFoldingSymbolHalfWidth, super.getPreferredSize().height / 2); } /** * @return returns the color that should used to select the node. */ protected Color getSelectedColor() {// Color backgroundColor = getModel().getBackgroundColor();//// if(backgroundColor != null) {//// Color backBrighter = backgroundColor.brighter();//// // white?//// if(backBrighter.getRGB() == Color.WHITE.getRGB()) {//// return standardSelectColor;//// }//// // == standard??//// if (backBrighter.equals (standardSelectColor) ) {//// return backgroundColor.darker();//// }//// return backBrighter;//// }// // == standard??// if (backgroundColor != null /*&& backgroundColor.equals(standardSelectColor)*/ ) {// // bad hack:// return getAntiColor1(backgroundColor);//// return new Color(0xFFFFFF - backgroundColor.getRGB());// } return standardSelectColor; }/* http://groups.google.de/groups?hl=de&lr=&ie=UTF-8&threadm=9i5bbo%24h1kmi%243%40ID-77081.news.dfncis.de&rnum=1&prev=/groups%3Fq%3Djava%2520komplement%25C3%25A4rfarbe%2520helligkeit%26hl%3Dde%26lr%3D%26ie%3DUTF-8%26sa%3DN%26as_qdr%3Dall%26tab%3Dwg */ /** * Ermittelt zu einer Farbe eine andere Farbe, die sich m鰃lichst gut von * dieser abhebt. * Diese Farbe unterscheidet sich auch von {@link #getAntiColor2}. * @since PPS 1.1.1 */ protected static Color getAntiColor1(Color c) { float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); hsb[0] += 0.40; if (hsb[0] > 1) hsb[0]--; hsb[1] = 1; hsb[2] = 0.7f; return Color.getHSBColor(hsb[0], hsb[1], hsb[2]); } /** * Ermittelt zu einer Farbe eine andere Farbe, die sich m鰃lichst gut von * dieser abhebt. * Diese Farbe unterscheidet sich von {@link #getAntiColor1}. * @since PPS 1.1.1 */ protected static Color getAntiColor2(Color c) { float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); hsb[0] -= 0.40; if (hsb[0] < 0) hsb[0]++; hsb[1] = 1; hsb[2] = (float)0.8; return Color.getHSBColor(hsb[0], hsb[1], hsb[2]); } /** * @return Returns the sHIFT. */ public int getShift() { return map.getZoomed(model.calcShiftY());} /** * @return Returns the VGAP. */ public int getVGap() { return map.getZoomed(model.calcVGap()); // TODO } public int getHGap() { return map.getZoomed(model.getHGap()); } public int getUpperChildShift() { return upperChildShift; } public void setUpperChildShift(int treeShift) { this.upperChildShift = treeShift; } public NodeMotionListenerView getMotionListenerView() { return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -