Hallo,
ich bin noch neu in dem Programmieren in schönen sich vererbenden Klassen. ich will gerade erreichen, dass in einer Subclass eine Funktion aus der Superclass überschrieben wird.
Diese Funktion ist in der Superklasse in Zeile 159, Name: paintDescTopArea.
ich habe protected gewählt, weil sie damit ja auch in subklassen sichtbar ist... private ist ja nicht in subklassen sichtbar.
Der Fehler, der auftritt, lautet: Cannot reduce the visibility of the inherited method from Graph ModifiedGraph.java line 16
Habt ihr den entscheidenden Tipp für mich? Danke schonmal!
Superklasse:
Subklasse:
ich bin noch neu in dem Programmieren in schönen sich vererbenden Klassen. ich will gerade erreichen, dass in einer Subclass eine Funktion aus der Superclass überschrieben wird.
Diese Funktion ist in der Superklasse in Zeile 159, Name: paintDescTopArea.
ich habe protected gewählt, weil sie damit ja auch in subklassen sichtbar ist... private ist ja nicht in subklassen sichtbar.
Der Fehler, der auftritt, lautet: Cannot reduce the visibility of the inherited method from Graph ModifiedGraph.java line 16
Habt ihr den entscheidenden Tipp für mich? Danke schonmal!
Superklasse:
Java:
package org.jcryptool.analysis.freqanalysis.ui.graphtools;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
/**
* @author Simon
*
*/
public class Graph{
// ## superclass implementation related fields
//Sequences of bars (contain order of painting, too)
//private Bar[][] barrows;
//height and width of the painting area
protected int areaWidth;
protected int areaHeight;
// the graphical context
protected GC gc;
// ## Parameters that has to be fields
//the length of the longest Bar[] array
protected int maxCount;
// ## Parameters that could be local but would be nice to adjust in a subclass
// ## without overkilling a procedures parameter list or overwriting the function
// Distance of the bar area to top, bottom, etc
// This values define the description areas
protected int distTop, distBottom, distLeft, distRight;
//distance of the real bar space to top, left, ...
protected int marginLeft, marginRight, marginTop, marginBottom;
//Rectangles for the different painting areas
protected Rectangle barAreaRect, descTopRect, descBottomRect, descRightRect, descLeftRect;
//Color for labels
protected MColor descTopFontColor, descBottomFontColor;
//Color for description Areas and main paint Area
protected MColor descTopBGColor, descBottomBGColor, descLeftBGColor, descRightBGColor, barAreaBGColor;
/**
* Creates the Graph Element with the absolutely required components
* @param pGc The drawing context
* @param pAreaWidth The Width of the painting area
* @param pAreaHeight The height of the painting area
*/
public Graph(GC pGc, int pAreaWidth, int pAreaHeight)
{
areaHeight = pAreaHeight; areaWidth = pAreaWidth;
gc = pGc;
distTop = 0; distBottom = 20; distLeft = 0; distRight = 0;
marginTop = 20; marginBottom = 0; marginLeft = 20; marginRight = 20;
calcAreas();
descTopFontColor = new MColor(0, 0, 0, 255);
descBottomFontColor = new MColor(0, 0, 0, 255);
descTopBGColor = new MColor("A3D3FA", 255);
descBottomBGColor = new MColor("A3D3FA", 255);
descLeftBGColor = new MColor("A3D3FA", 255);
descRightBGColor = new MColor("A3D3FA", 255);
barAreaBGColor = new MColor("306A90", 255);
}
public void setGC(GC pGc){
gc = pGc;
}
public void updateBounds(int pAreaWidth, int pAreaHeight)
{
areaHeight = pAreaHeight; areaWidth = pAreaWidth;
calcAreas();
}
public void setFullAreaParams(int pDistTop, int pDistBottom, int pDistLeft, int pDistRight, int pMarginLeft, int pMarginRight, int pMarginTop, int pMarginBottom)
{
distTop = pDistTop; distBottom = pDistBottom; distLeft = pDistLeft; distRight = pDistRight;
marginLeft = pMarginLeft; marginRight = pMarginRight; marginTop = pMarginTop; marginBottom = pMarginBottom;
calcAreas();
}
public void setBarAreaParams(MColor bg)
{ barAreaBGColor = bg; }
public void setDescLeftAreaParams(MColor bg)
{ descLeftBGColor = bg; }
public void setDescRightAreaParams(MColor bg)
{ descRightBGColor = bg; }
public void setDescTopAreaParams(MColor bg, MColor fontColor)
{ descTopBGColor = bg; descTopFontColor = fontColor;}
public void setDescBottomAreaParams(MColor bg, MColor fontColor)
{ descBottomBGColor = bg; descBottomFontColor = fontColor;}
protected void calcAreas()
{
descTopRect = new Rectangle(0, 0, areaWidth, distTop);
descBottomRect = new Rectangle(0, areaHeight-distBottom, areaWidth, distBottom);
descLeftRect = new Rectangle(0, distTop, distLeft, areaHeight-distTop-distBottom);
descRightRect = new Rectangle(areaWidth-distRight, distTop, distRight, areaHeight-distTop-distBottom);
barAreaRect = new Rectangle(distLeft, distTop, areaWidth-distLeft-distRight, areaHeight-distTop-distBottom);
}
// ################# PAINTING #################
// ################# -------- #################
/**
* Paint procedure for the whole painting Area. Calls the painting procedures for the
* other paint areas. \nOverride this only if you have structural changes to make e. g. concerning
* the number of painting areas or adding parameters to an area's painting procedure.
*/
public void paintArea()
{
paintBarArea();
paintDescTopArea();
paintDescBottomArea();
paintDescLeftArea();
paintDescRightArea();
}
// -------------------------- Actual graph painting area -----------------------------------
/**
* Draws the actual graph area <br />
* Used to call the function without the parameters (they already exist as fields)
*/
protected void paintBarArea() {paintBarArea(barAreaRect, barAreaBGColor);}
/**
* Draws the actual graph area <br />
* @param thisArea Rectangle defining the painting area
* @param thisBGColor the background color
*/
protected void paintBarArea(Rectangle thisArea, MColor thisBGColor)
{
//The Position the actual drawn bar is painted to (point is on the bottom of the bar, horizontally centered)
double actBarX, actBarY;
//The horizontal and vertical available space for the bar
double actBarHorizspace, actBarVertSpace;
maxCount = 1234;
thisBGColor.setColor(gc); thisBGColor.setBGColor(gc);
gc.fillRectangle(thisArea);
}
// -------------------------- Top description area -----------------------------------------
/**
* Draws the top description area <br />
* Used to call the function without the parameters (they already exist as fields)
*/
protected void paintDescTopArea() {paintDescTopArea(descTopRect, descTopBGColor, descTopFontColor);}
/**
* Draws the top description area
* @param thisArea Rectangle defining the painting area
* @param thisBGColor the background color
* @param thisfontcolor the Color for text labels in this description area
*/
private void paintDescTopArea(Rectangle thisArea, MColor thisBGColor, MColor thisFontColor)
{
thisBGColor.setColor(gc); thisBGColor.setBGColor(gc);
gc.fillRectangle(thisArea);
}
// -------------------------- Bottom description area -----------------------------------------
/**
* Draws the bottom description area <br />
* Used to call the function without the parameters (they already exist as fields)
*/
protected void paintDescBottomArea() {paintDescBottomArea(descBottomRect, descBottomBGColor, descBottomFontColor);}
/**
* Draws the bottom description area
* @param thisArea Rectangle defining the painting area
* @param thisBGColor the background color
* @param thisfontcolor the Color for text labels in this description area
*/
protected void paintDescBottomArea(Rectangle thisArea, MColor thisBGColor, MColor thisFontColor)
{
thisBGColor.setColor(gc); thisBGColor.setBGColor(gc);
gc.fillRectangle(thisArea);
}
// -------------------------- Right description area -----------------------------------------
/**
* Draws the right description area <br />
* Used to call the function without the parameters (they already exist as fields)
*/
protected void paintDescRightArea() {paintDescRightArea(descRightRect, descRightBGColor);}
/**
* Draws the right description area
* @param thisArea Rectangle defining the painting area
* @param thisBGColor the background color
*/
protected void paintDescRightArea(Rectangle thisArea, MColor thisBGColor)
{
thisBGColor.setColor(gc); thisBGColor.setBGColor(gc);
gc.fillRectangle(thisArea);
}
// -------------------------- Left description area -----------------------------------------
/**
* Draws the left description area <br />
* Used to call the function without the parameters (they already exist as fields)
*/
protected void paintDescLeftArea() {paintDescLeftArea(descLeftRect, descLeftBGColor);}
/**
* Draws the left description area
* @param thisArea Rectangle defining the painting area
* @param thisBGColor the background color
*/
protected void paintDescLeftArea(Rectangle thisArea, MColor thisBGColor)
{
thisBGColor.setColor(gc); thisBGColor.setBGColor(gc);
gc.fillRectangle(thisArea);
}
/**
* Helps you to calculate the GC.drawText() position for a text you want to center on a given point
* @param myText is the String you want to draw
* @param midX where do you want the text to center?
* @param topMidY where do you want the text to center? (defines the text's top border)
* @param metrics the fontMetrics, e. g. by your GC parameter
* @return a point which coordinates you can use directly in your drawText() call
*/
protected Point calcTextXY(String myText, int midX, int topMidY, FontMetrics metrics)
{
int leftX = midX - (myText.length()*metrics.getAverageCharWidth()) / 2;
int leftY = topMidY;
return new Point(leftX, leftY);
}
}
Subklasse:
Java:
package org.jcryptool.analysis.freqanalysis.ui.graphtools;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
public class ModifiedGraph extends Graph
{
public ModifiedGraph(GC gc, int areaWidth, int areaHeight) {
super(gc, areaWidth, areaHeight);
// TODO Auto-generated constructor stub
}
@Override
private void paintDescTopArea(Rectangle thisArea, MColor thisBGColor, MColor thisFontColor)
{
thisBGColor.setColor(gc); thisBGColor.setBGColor(gc);
gc.fillRectangle(thisArea);
Point test = calcTextXY("haha override xP", areaWidth/2, 1, gc.getFontMetrics());
gc.drawText("haha override xP", 30, 1);
}
}